Warning, /plasma/plasma-mobile/components/mobileshell/qml/actiondrawer/quicksettings/BrightnessItem.qml is written in an unsupported language. File is not indexed.
0001 /*
0002 * SPDX-FileCopyrightText: 2012-2013 Daniel Nicoletti <dantti12@gmail.com>
0003 * SPDX-FileCopyrightText: 2013, 2015 Kai Uwe Broulik <kde@privat.broulik.de>
0004 * SPDX-FileCopyrightText: 2021 Devin Lin <devin@kde.org>
0005 *
0006 * SPDX-License-Identifier: LGPL-2.0-or-later
0007 */
0008
0009 import QtQuick 2.15
0010 import QtQuick.Layouts 1.1
0011 import org.kde.kirigami 2.20 as Kirigami
0012
0013 import org.kde.plasma.core as PlasmaCore
0014 import org.kde.plasma.plasma5support 2.0 as P5Support
0015 import org.kde.plasma.components 3.0 as PC3
0016
0017 Item {
0018 id: root
0019
0020 implicitHeight: brightnessRow.implicitHeight
0021
0022 property int screenBrightness
0023 property bool disableBrightnessUpdate: true
0024 readonly property int maximumScreenBrightness: pmSource.data["PowerDevil"] ? pmSource.data["PowerDevil"]["Maximum Screen Brightness"] || 0 : 0
0025
0026 property QtObject updateScreenBrightnessJob
0027
0028 function updateBrightnessUI() {
0029 if (updateScreenBrightnessJob)
0030 return;
0031
0032 root.disableBrightnessUpdate = true;
0033 root.screenBrightness = pmSource.data["PowerDevil"]["Screen Brightness"];
0034 root.disableBrightnessUpdate = false;
0035 }
0036
0037 onScreenBrightnessChanged: {
0038 if (!brightnessSlider.pressed && !brightnessTimer.running) {
0039 brightnessSlider.value = root.screenBrightness;
0040 }
0041
0042 if (!disableBrightnessUpdate) {
0043 var service = pmSource.serviceForSource("PowerDevil");
0044 var operation = service.operationDescription("setBrightness");
0045 operation.brightness = screenBrightness;
0046 operation.silent = true; // don't show OSD
0047
0048 updateScreenBrightnessJob = service.startOperationCall(operation);
0049 updateScreenBrightnessJob.finished.connect(function (job) {
0050 root.updateBrightnessUI();
0051 });
0052 }
0053 }
0054
0055 P5Support.DataSource {
0056 id: pmSource
0057 engine: "powermanagement"
0058 connectedSources: ["PowerDevil"]
0059 onSourceAdded: {
0060 if (source === "PowerDevil") {
0061 disconnectSource(source);
0062 connectSource(source);
0063 }
0064 }
0065 onDataChanged: root.updateBrightnessUI()
0066 }
0067
0068 // we want to smoothen the slider so it doesn't jump immediately after you let go
0069 Timer {
0070 id: brightnessTimer
0071 interval: 500
0072 onTriggered: {
0073 brightnessSlider.value = root.screenBrightness;
0074 }
0075 }
0076
0077 // send brightness events a maximum of 5 times a second
0078 Timer {
0079 id: sendEventTimer
0080 interval: 200
0081 onTriggered: root.screenBrightness = brightnessSlider.value
0082 }
0083
0084 RowLayout {
0085 id: brightnessRow
0086 spacing: Kirigami.Units.smallSpacing * 2
0087
0088 anchors.left: parent.left
0089 anchors.right: parent.right
0090 anchors.top: parent.top
0091
0092 Kirigami.Icon {
0093 Layout.alignment: Qt.AlignVCenter
0094 Layout.leftMargin: Kirigami.Units.smallSpacing
0095 Layout.preferredWidth: Kirigami.Units.iconSizes.smallMedium
0096 Layout.preferredHeight: width
0097 source: "low-brightness"
0098 }
0099
0100 PC3.Slider {
0101 id: brightnessSlider
0102 Layout.fillWidth: true
0103 Layout.alignment: Qt.AlignVCenter
0104 from: 1
0105 to: root.maximumScreenBrightness
0106 value: root.screenBrightness
0107
0108 onMoved: {
0109 if (!sendEventTimer.running) {
0110 root.screenBrightness = value;
0111 sendEventTimer.restart();
0112 }
0113 }
0114
0115 onPressedChanged: {
0116 if (!pressed) {
0117 brightnessTimer.restart();
0118 } else {
0119 brightnessTimer.stop();
0120 }
0121 }
0122 }
0123
0124 Kirigami.Icon {
0125 Layout.alignment: Qt.AlignVCenter
0126 Layout.rightMargin: Kirigami.Units.smallSpacing
0127 Layout.preferredWidth: Kirigami.Units.iconSizes.smallMedium
0128 Layout.preferredHeight: width
0129 source: "high-brightness"
0130 }
0131 }
0132 }