| 1 |
/* |
| 2 |
SPDX-FileCopyrightText: 2019 Marco Martin <[email protected]> |
| 3 |
SPDX-FileCopyrightText: 2019 David Edmundson <[email protected]> |
| 4 |
SPDX-FileCopyrightText: 2019 Arjen Hiemstra <[email protected]> |
| 5 |
SPDX-FileCopyrightText: 2019 Kai Uwe Broulik <[email protected]> |
| 6 |
|
| 7 |
SPDX-License-Identifier: LGPL-2.0-or-later |
| 8 |
*/ |
| 9 |
|
| 10 |
import QtQuick |
| 11 |
import QtQuick.Controls as QQC2 |
| 12 |
import QtQuick.Layouts |
| 13 |
|
| 14 |
import org.kde.kirigami as Kirigami |
| 15 |
|
| 16 |
import org.kde.ksysguard.sensors as Sensors |
| 17 |
import org.kde.ksysguard.faces as Faces |
| 18 |
|
| 19 |
import org.kde.quickcharts as Charts |
| 20 |
import org.kde.quickcharts.controls as ChartControls |
| 21 |
|
| 22 |
Faces.CompactSensorFace { |
| 23 |
id: root |
| 24 |
|
| 25 |
readonly property bool horizontalOrientation: controller.faceConfiguration.horizontalBars |
| 26 |
|
| 27 |
readonly property real minimumBarSize: (horizontalFormFactor && !horizontalOrientation) || (verticalFormFactor && horizontalOrientation) ? Kirigami.Units.smallSpacing : 1 |
| 28 |
readonly property real minimumBarSpacing: Math.floor(minimumBarSize * 0.25) |
| 29 |
readonly property real minimumTotalSize: minimumBarSize * barChart.barCount + minimumBarSpacing * (barChart.barCount - 1) |
| 30 |
readonly property real preferredTotalSize: Kirigami.Units.largeSpacing * barChart.barCount + Kirigami.Units.largeSpacing * 0.25 * (barChart.barCount - 1) |
| 31 |
|
| 32 |
Layout.minimumWidth: (!horizontalFormFactor || horizontalOrientation) ? defaultMinimumSize : Math.max(minimumTotalSize, Kirigami.Units.largeSpacing) |
| 33 |
Layout.minimumHeight: (!verticalFormFactor || !horizontalOrientation) ? defaultMinimumSize : Math.max(minimumTotalSize, Kirigami.Units.largeSpacing) |
| 34 |
|
| 35 |
Layout.preferredWidth: { |
| 36 |
if (!horizontalFormFactor) { |
| 37 |
return -1 |
| 38 |
} |
| 39 |
|
| 40 |
return horizontalOrientation ? height * goldenRatio : preferredTotalSize |
| 41 |
} |
| 42 |
|
| 43 |
Layout.preferredHeight: { |
| 44 |
if (!verticalFormFactor) { |
| 45 |
return -1 |
| 46 |
} |
| 47 |
|
| 48 |
return horizontalOrientation ? preferredTotalSize : width |
| 49 |
} |
| 50 |
|
| 51 |
contentItem: ColumnLayout { |
| 52 |
BarChart { |
| 53 |
id: barChart |
| 54 |
Layout.fillWidth: true |
| 55 |
Layout.fillHeight: true |
| 56 |
Layout.alignment: Qt.AlignCenter |
| 57 |
updateRateLimit: root.controller.updateRateLimit |
| 58 |
controller: root.controller |
| 59 |
spacing: Math.max(Math.floor(((root.horizontalOrientation ? height : width) / barCount) * 0.25), root.minimumBarSpacing) |
| 60 |
} |
| 61 |
QQC2.Label { |
| 62 |
id: label |
| 63 |
visible: root.formFactor == Faces.SensorFace.Planar && root.controller.showTitle && text.length > 0 |
| 64 |
Layout.alignment: Qt.AlignTop |
| 65 |
Layout.fillWidth: true |
| 66 |
horizontalAlignment: Text.AlignHCenter |
| 67 |
text: root.controller.title |
| 68 |
} |
| 69 |
} |
| 70 |
} |