FullRepresentation.qml 2.96 KB
Newer Older
Marco Martin's avatar
Marco Martin committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*
 *   Copyright 2019 Marco Martin <mart@kde.org>
 *   Copyright 2019 David Edmundson <davidedmundson@kde.org>
 *   Copyright 2019 Arjen Hiemstra <ahiemstra@heimr.nl>
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU Library General Public License as
 *   published by the Free Software Foundation; either version 2, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details
 *
 *   You should have received a copy of the GNU Library General Public
 *   License along with this program; if not, write to the
 *   Free Software Foundation, Inc.,
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

import QtQuick 2.9
import QtQuick.Layouts 1.1

import org.kde.kirigami 2.8 as Kirigami

import org.kde.ksysguard.sensors 1.0 as Sensors
import org.kde.ksysguard.faces 1.0 as Faces

import org.kde.quickcharts 1.0 as Charts
import org.kde.quickcharts.controls 1.0 as ChartControls

Faces.SensorFace {
    id: root

    readonly property bool showLegend: controller.faceConfiguration.showLegend

    // Arbitrary minimumWidth to make easier to align plasmoids in a predictable way
Marco Martin's avatar
Marco Martin committed
39
    Layout.minimumWidth: Math.max(Kirigami.Units.gridUnit * compactRepresentation.barCount, Kirigami.Units.gridUnit * 8)
Marco Martin's avatar
Marco Martin committed
40
    Layout.preferredWidth: titleMetrics.width
Marco Martin's avatar
Marco Martin committed
41
42
43

    contentItem: ColumnLayout {
        Kirigami.Heading {
Marco Martin's avatar
Marco Martin committed
44
            id: heading
Marco Martin's avatar
Marco Martin committed
45
46
47
48
49
50
            Layout.fillWidth: true
            horizontalAlignment: Text.AlignHCenter
            elide: Text.ElideRight
            text: root.controller.title
            visible: text.length > 0
            level: 2
Marco Martin's avatar
Marco Martin committed
51
52
53
54
55
            TextMetrics {
                id: titleMetrics
                font: heading.font
                text: heading.text
            }
Marco Martin's avatar
Marco Martin committed
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
        }

        BarChart {
            id: compactRepresentation
            Layout.fillWidth: true
            Layout.fillHeight: true
            Layout.minimumHeight: 5 * Kirigami.Units.gridUnit
            Layout.preferredHeight: 8 * Kirigami.Units.gridUnit
            Layout.maximumHeight: Math.max(root.width, Layout.minimumHeight)
        }

        Faces.ExtendedLegend {
            Layout.fillWidth: root.width < implicitWidth * 1.5
            Layout.alignment: Qt.AlignVCenter | Qt.AlignLeft
            Layout.fillHeight: true
Marco Martin's avatar
Marco Martin committed
71
            Layout.minimumHeight: root.formFactor !== Faces.SensorFace.Planar ? implicitHeight : -1
Marco Martin's avatar
Marco Martin committed
72
73
74
            visible: root.showLegend
            chart: compactRepresentation
            sourceModel: root.showLegend ? compactRepresentation.sensorsModel : null
Marco Martin's avatar
Marco Martin committed
75
            colorSource: root.colorSource
Marco Martin's avatar
Marco Martin committed
76
77
78
79
80
81
82
83
            sensorIds: root.showLegend ? root.controller.lowPrioritySensorIds : []
        }

        Item {
            Layout.fillHeight: true
        }
    }
}