Warning, /plasma/plasma-desktop/kcms/mouse/kcm/libinput/main_deviceless.qml is written in an unsupported language. File is not indexed.

0001 /*
0002     SPDX-FileCopyrightText: 2018 Roman Gilg <subdiff@gmail.com>
0003     SPDX-FileCopyrightText: 2018 Furkan Tokac <furkantokac34@gmail.com>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 import QtQuick
0009 import QtQuick.Controls as QQC2
0010 import QtQuick.Layouts
0011 
0012 import org.kde.kcmutils as KCM
0013 import org.kde.kirigami as Kirigami
0014 
0015 // TODO: Change ScrollablePage as KCM.SimpleKCM
0016 // after rewrite the KCM in KConfigModule.
0017 Kirigami.ScrollablePage {
0018     id: root
0019 
0020     spacing: Kirigami.Units.smallSpacing
0021 
0022     signal changeSignal()
0023 
0024     property QtObject device: deviceModel[0]
0025 
0026     property bool loading: false
0027 
0028     function resetModel(index) {
0029         // not implemented
0030     }
0031 
0032     function syncValuesFromBackend() {
0033         loading = true
0034 
0035         leftHanded.load()
0036         middleEmulation.load()
0037         accelSpeed.load()
0038         accelProfile.load()
0039         naturalScroll.load()
0040 
0041         loading = false
0042     }
0043 
0044     Kirigami.FormLayout {
0045         id: formLayout
0046 
0047         // General
0048         QQC2.CheckBox {
0049             id: leftHanded
0050             Kirigami.FormData.label: i18nd("kcmmouse", "General:")
0051             text: i18nd("kcmmouse", "Left handed mode")
0052 
0053             function load() {
0054                 if (!formLayout.enabled) {
0055                     checked = false
0056                     return
0057                 }
0058                 enabled = device.supportsLeftHanded
0059                 checked = enabled && device.leftHanded
0060             }
0061 
0062             onCheckedChanged: {
0063                 if (enabled && !root.loading) {
0064                     device.leftHanded = checked
0065                     root.changeSignal()
0066                 }
0067             }
0068 
0069             QQC2.ToolTip.delay: 1000
0070             QQC2.ToolTip.visible: hovered
0071             QQC2.ToolTip.text: i18nd("kcmmouse", "Swap left and right buttons.")
0072         }
0073 
0074         QQC2.CheckBox {
0075             id: middleEmulation
0076             text: i18nd("kcmmouse", "Press left and right buttons for middle-click")
0077 
0078             function load() {
0079                 if (!formLayout.enabled) {
0080                     checked = false
0081                     return
0082                 }
0083                 enabled = device.supportsMiddleEmulation
0084                 checked = enabled && device.middleEmulation
0085             }
0086 
0087             onCheckedChanged: {
0088                 if (enabled && !root.loading) {
0089                     device.middleEmulation = checked
0090                     root.changeSignal()
0091                 }
0092             }
0093 
0094             QQC2.ToolTip.delay: 1000
0095             QQC2.ToolTip.visible: hovered
0096             QQC2.ToolTip.text: i18nd("kcmmouse", "Clicking left and right button simultaneously sends middle button click.")
0097         }
0098 
0099         Item {
0100             Kirigami.FormData.isSection: false
0101         }
0102 
0103         // Acceleration
0104         QQC2.Slider {
0105             id: accelSpeed
0106             Kirigami.FormData.label: i18nd("kcmmouse", "Pointer speed:")
0107             Layout.fillWidth: true
0108 
0109             from: 1
0110             to: 11
0111             stepSize: 1
0112 
0113             function load() {
0114                 enabled = device.supportsPointerAcceleration
0115                 if (!enabled) {
0116                     value = 0.2
0117                     return
0118                 }
0119                 // transform libinput's pointer acceleration range [-1, 1] to slider range [1, 11]
0120                 //value = 4.5 * device.pointerAcceleration + 5.5
0121                 value = 6 + device.pointerAcceleration / 0.2
0122             }
0123 
0124             onValueChanged: {
0125                 if (device != undefined && enabled && !root.loading) {
0126                     // transform slider range [1, 10] to libinput's pointer acceleration range [-1, 1]
0127                     // by *10 and /10, we ignore the floating points after 1 digit. This prevents from
0128                     // having a libinput value like 0.60000001
0129                     device.pointerAcceleration = Math.round(((value - 6) * 0.2) * 10) / 10
0130                     root.changeSignal()
0131                 }
0132             }
0133         }
0134 
0135         ColumnLayout {
0136             id: accelProfile
0137             spacing: Kirigami.Units.smallSpacing
0138             Kirigami.FormData.label: i18nd("kcmmouse", "Pointer acceleration:")
0139             Kirigami.FormData.buddyFor: accelProfileFlat
0140 
0141             function load() {
0142                 enabled = device.supportsPointerAccelerationProfileAdaptive
0143 
0144                 if (!enabled) {
0145                     accelProfileAdaptive.checked = false
0146                     accelProfileFlat.checked = false
0147                     return
0148                 }
0149 
0150                 if (device.pointerAccelerationProfileAdaptive) {
0151                     accelProfileAdaptive.checked = true
0152                     accelProfileFlat.checked = false
0153                 } else {
0154                     accelProfileAdaptive.checked = false
0155                     accelProfileFlat.checked = true
0156                 }
0157             }
0158 
0159             function syncCurrent() {
0160                 if (enabled && !root.loading) {
0161                     device.pointerAccelerationProfileFlat = accelProfileFlat.checked
0162                     device.pointerAccelerationProfileAdaptive = accelProfileAdaptive.checked
0163                     root.changeSignal()
0164                 }
0165             }
0166 
0167             QQC2.RadioButton {
0168                 id: accelProfileFlat
0169                 text: i18nd("kcmmouse", "None")
0170 
0171                 QQC2.ToolTip.delay: 1000
0172                 QQC2.ToolTip.visible: hovered
0173                 QQC2.ToolTip.text: i18nd("kcmmouse", "Cursor moves the same distance as the mouse movement.")
0174                 onCheckedChanged: accelProfile.syncCurrent()
0175             }
0176 
0177             QQC2.RadioButton {
0178                 id: accelProfileAdaptive
0179                 text: i18nd("kcmmouse", "Standard")
0180 
0181                 QQC2.ToolTip.delay: 1000
0182                 QQC2.ToolTip.visible: hovered
0183                 QQC2.ToolTip.text: i18nd("kcmmouse", "Cursor travel distance depends on the mouse movement speed.")
0184                 onCheckedChanged: accelProfile.syncCurrent()
0185             }
0186         }
0187 
0188         Item {
0189             Kirigami.FormData.isSection: false
0190         }
0191 
0192         // Scrolling
0193         QQC2.CheckBox {
0194             id: naturalScroll
0195             Kirigami.FormData.label: i18nd("kcmmouse", "Scrolling:")
0196             text: i18nd("kcmmouse", "Invert scroll direction")
0197 
0198             function load() {
0199                 enabled = device.supportsNaturalScroll
0200                 checked = enabled && device.naturalScroll
0201             }
0202 
0203             onCheckedChanged: {
0204                 if (enabled && !root.loading) {
0205                     device.naturalScroll = checked
0206                     root.changeSignal()
0207                 }
0208             }
0209 
0210             QQC2.ToolTip.delay: 1000
0211             QQC2.ToolTip.visible: hovered
0212             QQC2.ToolTip.text: i18nd("kcmmouse", "Touchscreen like scrolling.")
0213         }
0214     }
0215 }