/** Copyright 2018 Roman Gilg <subdiff@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 1.4 as Controlsimport QtQuick.Layouts 1.3 as Layoutsimport QtQuick.Controls.Styles 1.4 as Stylesimport org.kde.plasma.core 2.0 as PlasmaCoreimport "components"Item {id: rootproperty size sizeHint: Qt.size(maincol.width, maincol.height)property size minimumSizeHint: Qt.size(maincol.width/2, deviceSelector.height)property alias deviceIndex: deviceSelector.currentIndexsignal changeSignal()property QtObject deviceproperty int deviceCount: backend.deviceCountproperty bool loading: falsefunction resetModel(index) {deviceCount = backend.deviceCountmaincol.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()accelSpeed.load()accelProfile.load()naturalScroll.load()loading = false}Controls.ScrollView {anchors.fill: parentLayouts.ColumnLayout {id: maincolenabled: deviceCountspacing: units.largeSpacingLayouts.RowLayout {spacing: units.largeSpacingControls.Label {text: i18n("Device:")}Controls.ComboBox {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()}}}Column {spacing: units.smallSpacing * 2Column {leftPadding: units.smallSpacingColumn {spacing: units.smallSpacingControls.Label {text: i18n("General settings:")}Column {leftPadding: units.smallSpacingColumn {spacing: units.smallSpacingControls.CheckBox {id: deviceEnabledtext: i18n("Device enabled")function load() {if (!maincol.enabled) {checked = falsereturn}enabled = device.supportsDisableEventschecked = enabled && device.enabled}onCheckedChanged: {if (enabled && !root.loading) {device.enabled = checkedroot.changeSignal()}}ToolTip {text: i18n("Accept input through this device.")}}Controls.CheckBox {id: leftHandedtext: i18n("Left handed mode")function load() {if (!maincol.enabled) {checked = falsereturn}enabled = device.supportsLeftHandedchecked = enabled && device.leftHanded}onCheckedChanged: {if (enabled && !root.loading) {device.leftHanded = checkedroot.changeSignal()}}ToolTip {text: i18n("Swap left and right buttons.")}}Controls.CheckBox {id: middleEmulationtext: i18n("Emulate middle button")function load() {if (!maincol.enabled) {checked = falsereturn}enabled = device.supportsMiddleEmulationchecked = enabled && device.middleEmulation}onCheckedChanged: {if (enabled && !root.loading) {device.middleEmulation = checkedroot.changeSignal()}}ToolTip {text: i18n("Clicking left and right button simultaneously sends middle button click.")}}}}}}Column {leftPadding: units.smallSpacingColumn {spacing: units.smallSpacingControls.Label {text: i18n("Acceleration:")}Column {leftPadding: units.smallSpacingColumn {spacing: units.smallSpacing * 2Row {Controls.Slider {id: accelSpeedanchors.verticalCenter: parent.verticalCentertickmarksEnabled: trueminimumValue: 1maximumValue: 10stepSize: 1implicitWidth: units.gridUnit * 9function load() {enabled = device.supportsPointerAccelerationif (!enabled) {value = 0.1return}// transform libinput's pointer acceleration range [-1, 1] to slider range [1, 10]value = 4.5 * device.pointerAcceleration + 5.5}onValueChanged: {if (device != undefined && enabled && !root.loading) {// transform slider range [1, 10] to libinput's pointer acceleration range [-1, 1]device.pointerAcceleration = Math.round( (value - 5.5) / 4.5 * 100 ) / 100root.changeSignal()}}}}ExclGroupBox {id: accelProfilelabel: i18n("Acceleration Profile:")model: [i18n("Flat"), i18n("Adaptive")]function load() {enabled = device.supportsPointerAccelerationProfileAdaptiveif (!enabled) {itemAt(0).checked = falseitemAt(1).checked = falsereturn}itemAt(0).tooltiptext = i18n("Cursor moves the same distance as finger.")itemAt(1).tooltiptext = i18n("Cursor travel distance depends on movement speed of finger.")var toCheck = device.pointerAccelerationProfileAdaptive ? 1 : 0itemAt(toCheck).checked = true}onCurrentChanged: {if (enabled && !root.loading) {device.pointerAccelerationProfileFlat = itemAt(0).checkeddevice.pointerAccelerationProfileAdaptive = itemAt(1).checkedroot.changeSignal()}}}}}}}Column {leftPadding: units.smallSpacingColumn {spacing: units.smallSpacingControls.Label {text: i18n("Scrolling:")}Column {leftPadding: units.smallSpacingColumn {spacing: units.smallSpacingControls.CheckBox {id: naturalScrolltext: i18n("Invert scroll direction")function load() {enabled = device.supportsNaturalScrollchecked = enabled && device.naturalScroll}onCheckedChanged: {if (enabled && !root.loading) {device.naturalScroll = checkedroot.changeSignal()}}ToolTip {text: i18n("Touchscreen like scrolling.")}}}}}}}}}}