1/* 2 SPDX-FileCopyrightText: 2019 Roman Gilg <subdiff@gmail.com> 3 4 SPDX-License-Identifier: GPL-2.0-or-later 5*/ 6import QtQuick 2.9 7import QtQuick.Layouts 1.1 8import QtQuick.Controls 2.3 as Controls 9import org.kde.kirigami 2.4 as Kirigami 10 11import org.kde.kcm 1.2 as KCM 12import org.kde.private.kcm.kscreen 1.0 as KScreen 13 14ColumnLayout { 15 id: outputPanel 16 property var element: model 17 18 Kirigami.FormLayout { 19 twinFormLayouts: globalSettingsLayout 20 21 Controls.CheckBox { 22 text: i18n("Enabled") 23 checked: element.enabled 24 onClicked: element.enabled = checked 25 visible: kcm.outputModel.rowCount() > 1 26 } 27 28 Controls.CheckBox { 29 text: i18n("Primary") 30 checked: element.primary 31 onClicked: element.primary = checked 32 visible: kcm.primaryOutputSupported && kcm.outputModel.rowCount() > 1 33 } 34 35 Controls.ComboBox { 36 Kirigami.FormData.label: i18n("Resolution:") 37 Layout.minimumWidth: Kirigami.Units.gridUnit * 11 38 model: element.resolutions 39 currentIndex: element.resolutionIndex !== undefined ? 40 element.resolutionIndex : -1 41 onActivated: element.resolutionIndex = currentIndex 42 } 43 44 RowLayout { 45 Layout.fillWidth: true 46 // Set the same limit as the device ComboBox 47 Layout.maximumWidth: Kirigami.Units.gridUnit * 16 48 49 visible: kcm.perOutputScaling 50 Kirigami.FormData.label: i18n("Scale:") 51 52 Controls.Slider { 53 id: scaleSlider 54 55 Layout.fillWidth: true 56 from: 0.5 57 to: 3 58 stepSize: 0.25 59 live: true 60 value: element.scale 61 onMoved: element.scale = value 62 } 63 Controls.SpinBox { 64 id: spinbox 65 // Because QQC2 SpinBox doesn't natively support decimal step 66 // sizes: https://bugreports.qt.io/browse/QTBUG-67349 67 property real factor: 20.0 68 property real realValue: value / factor 69 70 from : 0.5 * factor 71 to : 3.0 * factor 72 stepSize: 0.05 * factor 73 value: element.scale * factor 74 validator: DoubleValidator { 75 bottom: Math.min(spinbox.from, spinbox.to) * spinbox.factor 76 top: Math.max(spinbox.from, spinbox.to) * spinbox.factor 77 } 78 textFromValue: function(value, locale) { 79 return i18nc("Global scale factor expressed in percentage form", "%1%", parseFloat(value * 1.0 / factor * 100.0)); 80 } 81 valueFromText: function(text, locale) { 82 return Number.fromLocaleString(locale, text.replace("%", "")) * factor / 100.0 83 } 84 onValueModified: element.scale = realValue 85 } 86 } 87 88 Orientation {} 89 90 Controls.ComboBox { 91 Kirigami.FormData.label: i18n("Refresh rate:") 92 Layout.minimumWidth: Kirigami.Units.gridUnit * 11 93 model: element.refreshRates 94 currentIndex: element.refreshRateIndex ? 95 element.refreshRateIndex : 0 96 onActivated: element.refreshRateIndex = currentIndex 97 } 98 99 Controls.ComboBox { 100 Kirigami.FormData.label: i18n("Adaptive sync:") 101 Layout.minimumWidth: Kirigami.Units.gridUnit * 11 102 model: [ 103 { label: i18n("Never"), value: KScreen.Output.VrrPolicy.Never }, 104 { label: i18n("Always"), value: KScreen.Output.VrrPolicy.Always }, 105 { label: i18n("Automatic"), value: KScreen.Output.VrrPolicy.Automatic } 106 ] 107 textRole: "label" 108 valueRole: "value" 109 visible: element.capabilities & KScreen.Output.Capability.Vrr 110 111 onActivated: element.vrrPolicy = currentValue 112 Component.onCompleted: currentIndex = indexOfValue(element.vrrPolicy); 113 } 114 115 Controls.SpinBox { 116 Kirigami.FormData.label: i18n("Overscan:") 117 from: 0 118 to: 100 119 value: element.overscan 120 onValueModified: element.overscan = value 121 visible: element.capabilities & KScreen.Output.Capability.Overscan 122 textFromValue: function(value, locale) { 123 return value + '%'; 124 } 125 valueFromText: function(text, locale) { 126 return parseInt(text.replace("%", "")) 127 } 128 } 129 130 Controls.ComboBox { 131 Kirigami.FormData.label: i18n("RGB Range:") 132 Layout.minimumWidth: Kirigami.Units.gridUnit * 11 133 model: [ 134 { label: i18n("Automatic"), value: KScreen.Output.RgbRange.Automatic }, 135 { label: i18n("Full"), value: KScreen.Output.RgbRange.Full }, 136 { label: i18n("Limited"), value: KScreen.Output.RgbRange.Limited } 137 ] 138 textRole: "label" 139 valueRole: "value" 140 visible: element.capabilities & KScreen.Output.Capability.RgbRange 141 142 onActivated: element.rgbRange = currentValue 143 Component.onCompleted: currentIndex = indexOfValue(element.rgbRange); 144 } 145 146 Controls.ComboBox { 147 Kirigami.FormData.label: i18n("Replica of:") 148 Layout.minimumWidth: Kirigami.Units.gridUnit * 11 149 model: element.replicationSourceModel 150 visible: kcm.outputReplicationSupported && kcm.outputModel && kcm.outputModel.rowCount() > 1 151 152 onModelChanged: enabled = (count > 1); 153 onCountChanged: enabled = (count > 1); 154 155 currentIndex: element.replicationSourceIndex 156 onActivated: element.replicationSourceIndex = currentIndex 157 } 158 } 159} 160