/** Copyright 2018 Roman Gilg <subdiff@gmail.com>* Copyright 2018 Furkan Tokac <furkantokac34@gmail.com>** This program is free software; you can redistribute it and/or modify* it under the terms of the GNU General Public License as published by* the Free Software Foundation; either version 2 of the License, 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 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.7import QtQuick.Controls 2.0 as Controlsimport QtQuick.Layouts 1.3 as Layoutsimport org.kde.kcm 1.1 as KCMimport org.kde.kirigami 2.4 as Kirigamiimport "components"// TODO: Change ScrollablePage as KCM.SimpleKCM// after rewrite the KCM in KConfigModule.Kirigami.ScrollablePage {id: rootspacing: Kirigami.Units.smallSpacingproperty size sizeHint: Qt.size(formLayout.width, Math.round(1.3 * formLayout.height))property size minimumSizeHint: Qt.size(formLayout.width/2, Math.round(1.3 * formLayout.height))property alias deviceIndex: deviceSelector.currentIndexsignal changeSignal()property QtObject deviceproperty int deviceCount: backend.deviceCountproperty bool loading: falseenabled: deviceCount > 0function resetModel(index) {deviceCount = backend.deviceCountformLayout.enabled = deviceCountdeviceSelector.enabled = deviceCount > 1loading = trueif (deviceCount) {device = deviceModel[index]deviceSelector.model = deviceModeldeviceSelector.currentIndex = indexconsole.log("Configuration of device '" +(index + 1) + " : " + device.name + "' opened")} else {deviceSelector.model = [""]console.log("No device found")}loading = false}function syncValuesFromBackend() {loading = truedeviceEnabled.load()leftHanded.load()middleEmulation.load()accelSpeed.load()accelProfile.load()naturalScroll.load()scrollFactor.load()loading = false}Kirigami.FormLayout {id: formLayoutenabled: deviceCount// DeviceControls.ComboBox {Kirigami.FormData.label: i18nd("kcmmouse", "Device:")id: deviceSelectorenabled: deviceCount > 1Layouts.Layout.fillWidth: truemodel: deviceModeltextRole: "name"onCurrentIndexChanged: {if (deviceCount) {device = deviceModel[currentIndex]if (!loading) {changeSignal()}console.log("Configuration of device '" +(currentIndex+1) + " : " + device.name + "' opened")}root.syncValuesFromBackend()}}Item {Kirigami.FormData.isSection: false}// GeneralControls.CheckBox {Kirigami.FormData.label: i18nd("kcmmouse", "General:")id: deviceEnabledtext: i18nd("kcmmouse", "Device enabled")function load() {if (!formLayout.enabled) {checked = falsereturn}enabled = device.supportsDisableEventschecked = enabled && device.enabled}onCheckedChanged: {if (enabled && !root.loading) {device.enabled = checkedroot.changeSignal()}}ToolTip {text: i18nd("kcmmouse", "Accept input through this device.")}}Controls.CheckBox {id: leftHandedtext: i18nd("kcmmouse", "Left handed mode")function load() {if (!formLayout.enabled) {checked = falsereturn}enabled = device.supportsLeftHandedchecked = enabled && device.leftHanded}onCheckedChanged: {if (enabled && !root.loading) {device.leftHanded = checkedroot.changeSignal()}}ToolTip {text: i18nd("kcmmouse", "Swap left and right buttons.")}}Controls.CheckBox {id: middleEmulationtext: i18nd("kcmmouse", "Press left and right buttons for middle-click")function load() {if (!formLayout.enabled) {checked = falsereturn}enabled = device.supportsMiddleEmulationchecked = enabled && device.middleEmulation}onCheckedChanged: {if (enabled && !root.loading) {device.middleEmulation = checkedroot.changeSignal()}}ToolTip {text: i18nd("kcmmouse", "Clicking left and right button simultaneously sends middle button click.")}}Item {Kirigami.FormData.isSection: false}// AccelerationControls.Slider {Kirigami.FormData.label: i18nd("kcmmouse", "Pointer speed:")id: accelSpeedfrom: 1to: 11stepSize: 1function load() {enabled = device.supportsPointerAccelerationif (!enabled) {value = 0.2return}// transform libinput's pointer acceleration range [-1, 1] to slider range [1, 11]//value = 4.5 * device.pointerAcceleration + 5.5value = 6 + device.pointerAcceleration / 0.2}onValueChanged: {if (device != undefined && enabled && !root.loading) {// transform slider range [1, 10] to libinput's pointer acceleration range [-1, 1]// by *10 and /10, we ignore the floating points after 1 digit. This prevents from// having a libinput value like 0.60000001device.pointerAcceleration = Math.round(((value-6) * 0.2) * 10) / 10root.changeSignal()}}}Layouts.ColumnLayout {id: accelProfilespacing: Kirigami.Units.smallSpacingKirigami.FormData.label: i18nd("kcmmouse", "Acceleration profile:")Kirigami.FormData.buddyFor: accelProfileFlatfunction load() {enabled = device.supportsPointerAccelerationProfileAdaptiveif (!enabled) {accelProfileAdaptive.checked = falseaccelProfileFlat.checked = falsereturn}if(device.pointerAccelerationProfileAdaptive) {accelProfileAdaptive.checked = trueaccelProfileFlat.checked = false} else {accelProfileAdaptive.checked = falseaccelProfileFlat.checked = true}}function syncCurrent() {if (enabled && !root.loading) {device.pointerAccelerationProfileFlat = accelProfileFlat.checkeddevice.pointerAccelerationProfileAdaptive = accelProfileAdaptive.checkedroot.changeSignal()}}Controls.RadioButton {id: accelProfileFlattext: i18nd("kcmmouse", "Flat")ToolTip {text: i18nd("kcmmouse", "Cursor moves the same distance as the mouse movement.")}onCheckedChanged: accelProfile.syncCurrent()}Controls.RadioButton {id: accelProfileAdaptivetext: i18nd("kcmmouse", "Adaptive")ToolTip {text: i18nd("kcmmouse", "Cursor travel distance depends on the mouse movement speed.")}onCheckedChanged: accelProfile.syncCurrent()}}Item {Kirigami.FormData.isSection: false}// ScrollingControls.CheckBox {Kirigami.FormData.label: i18nd("kcmmouse", "Scrolling:")id: naturalScrolltext: i18nd("kcmmouse", "Invert scroll direction")function load() {enabled = device.supportsNaturalScrollchecked = enabled && device.naturalScroll}onCheckedChanged: {if (enabled && !root.loading) {device.naturalScroll = checkedroot.changeSignal()}}ToolTip {text: i18nd("kcmmouse", "Touchscreen like scrolling.")}}// Scroll Speed aka scroll FactorLayouts.GridLayout {Kirigami.FormData.label: i18nd("kcm_touchpad", "Scrolling speed:")Kirigami.FormData.buddyFor: scrollFactorcolumns: 3Controls.Slider {id: scrollFactorfrom: 0to: 14stepSize: 1property variant values : [0.1,0.3,0.5,0.75,1, // default1.5,2,3,4,5,7,9,12,15,20]Layouts.Layout.columnSpan: 3function load() {let index = values.indexOf(device.scrollFactor)if (index === -1) {index = values.indexOf(1);}value = index}onMoved: {device.scrollFactor = values[value]root.changeSignal()}}//row 2Controls.Label {text: i18nc("Slower Scroll", "Slower")}Item {Layouts.Layout.fillWidth: true}Controls.Label {text: i18nc("Faster Scroll Speed", "Faster")}}}}