/** Copyright 2017 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 touchpadproperty int touchpadCount: backend.touchpadCountproperty bool loading: falsefunction resetModel(index) {touchpadCount = backend.touchpadCountmaincol.enabled = touchpadCountdeviceSelector.enabled = touchpadCount > 1loading = trueif (touchpadCount) {touchpad = deviceModel[index]deviceSelector.model = deviceModeldeviceSelector.currentIndex = indexconsole.log("Touchpad configuration of device '" +(index + 1) + " : " + touchpad.name + "' opened")} else {deviceSelector.model = [""]console.log("No touchpad found")}loading = false}function syncValuesFromBackend() {loading = truedeviceEnabled.load()dwt.load()leftHanded.load()accelSpeed.load()accelProfile.load()tapToClick.load()tapAndDrag.load()tapAndDragLock.load()multiTap.load()scrollmethod.load()naturalScroll.load()// TODO:// scrollbutton.load()loading = false}Controls.ScrollView {anchors.fill: parentLayouts.ColumnLayout {id: maincolenabled: touchpadCountspacing: units.largeSpacingLayouts.RowLayout {spacing: units.largeSpacingLayouts.Layout.leftMargin: 0.1 * parent.widthLayouts.Layout.rightMargin: 0.1 * parent.widthControls.Label {text: i18n("Device:")}Controls.ComboBox {id: deviceSelectorenabled: touchpadCount > 1Layouts.Layout.fillWidth: truemodel: deviceModeltextRole: "name"onCurrentIndexChanged: {if (touchpadCount) {touchpad = deviceModel[currentIndex]if (!loading) {changeSignal()}console.log("Touchpad configuration of device '" +(currentIndex+1) + " : " + touchpad.name + "' opened")}root.syncValuesFromBackend()}}}Row {spacing: units.largeSpacing * 2Column {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 = touchpad.supportsDisableEventschecked = enabled && touchpad.enabled}onCheckedChanged: {if (enabled && !root.loading) {touchpad.enabled = checkedroot.changeSignal()}}ToolTip {text: i18n("Accept input through this device.")}}Controls.CheckBox {id: dwttext: i18n("Disable while typing")function load() {if (!maincol.enabled) {checked = falsereturn}enabled = touchpad.supportsDisableWhileTypingchecked = enabled && touchpad.disableWhileTyping}onCheckedChanged: {if (enabled && !root.loading) {touchpad.disableWhileTyping = checkedroot.changeSignal()}}ToolTip {text: i18n("Disable touchpad while typing to prevent accidental inputs.")}}Controls.CheckBox {id: leftHandedtext: i18n("Left handed mode")function load() {if (!maincol.enabled) {checked = falsereturn}enabled = touchpad.supportsLeftHandedchecked = enabled && touchpad.leftHanded}onCheckedChanged: {if (enabled && !root.loading) {touchpad.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 = touchpad.supportsMiddleEmulationchecked = enabled && touchpad.middleEmulation}onCheckedChanged: {if (enabled && !root.loading) {touchpad.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 = touchpad.supportsPointerAccelerationif (!enabled) {value = 0.1return}// transform libinput's pointer acceleration range [-1, 1] to slider range [1, 10]value = 4.5 * touchpad.pointerAcceleration + 5.5}onValueChanged: {if (touchpad != undefined && enabled && !root.loading) {// transform slider range [1, 10] to libinput's pointer acceleration range [-1, 1]touchpad.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 = touchpad.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 = touchpad.pointerAccelerationProfileAdaptive ? 1 : 0itemAt(toCheck).checked = true}onCurrentChanged: {if (enabled && !root.loading) {touchpad.pointerAccelerationProfileFlat = itemAt(0).checkedtouchpad.pointerAccelerationProfileAdaptive = itemAt(1).checkedroot.changeSignal()}}}}}}}Column {leftPadding: units.smallSpacingColumn {spacing: units.smallSpacingControls.Label {text: i18n("Tapping:")}Column {leftPadding: units.smallSpacingColumn {spacing: units.smallSpacingControls.CheckBox {id: tapToClicktext: i18n("Tap-to-click")function load() {enabled = touchpad.tapFingerCount > 0checked = enabled && touchpad.tapToClick}function updateDependents() {loading = truetapAndDrag.load()tapAndDragLock.load()multiTap.load()loading = false}onCheckedChanged: {if (enabled && !root.loading) {touchpad.tapToClick = checkedupdateDependents()root.changeSignal()}}ToolTip {text: i18n("Single tap is left button click.")}}Controls.CheckBox {id: tapAndDragtext: i18n("Tap-and-drag")function load() {enabled = touchpad.tapFingerCount > 0 && tapToClick.checkedchecked = enabled && touchpad.tapAndDrag}function updateDependents() {loading = truetapAndDragLock.load()loading = false}onCheckedChanged: {if (enabled && !root.loading) {touchpad.tapAndDrag = checkedupdateDependents()root.changeSignal()}}ToolTip {text: i18n("Sliding over touchpad directly after tap drags.")}}Controls.CheckBox {id: tapAndDragLocktext: i18n("Tap-and-drag lock")function load() {enabled = touchpad.tapFingerCount > 0 && tapAndDrag.checkedchecked = enabled && touchpad.tapDragLock}onCheckedChanged: {if (enabled && !root.loading) {touchpad.tapDragLock = checkedroot.changeSignal()}}ToolTip {text: i18n("Dragging continues after a short finger lift.")}}}}}}}Column {spacing: units.smallSpacing * 2Column {leftPadding: units.smallSpacingColumn {leftPadding: units.smallSpacingExclGroupBox {id: multiTaplabel: i18n("Multi tapping:")function load() {enabled = touchpad.supportsLmrTapButtonMap && tapToClick.checkedif (touchpad.tapFingerCount > 2) {model = [i18n("Two-tap right, three middle"), i18n("Two-tap middle, three right")]itemAt(0).tooltiptext = i18n("Tap with two fingers triggers a right click, tap with three fingers a middle click.")itemAt(1).tooltiptext = i18n("Tap with two fingers triggers a middle click, tap with three fingers a right click.")} else {model = [i18n("Two-tap right click"), i18n("Two-tap middle click")]itemAt(0).tooltiptext = i18n("Tap with two fingers triggers a right click.")itemAt(1).tooltiptext = i18n("Tap with two fingers triggers a middle click.")}if (!enabled) {itemAt(0).checked = falseitemAt(1).checked = falsereturn}var toCheck = touchpad.lmrTapButtonMap ? 1 : 0itemAt(toCheck).checked = true}onCurrentChanged: {if (enabled && !root.loading) {touchpad.lmrTapButtonMap = itemAt(1).checkedroot.changeSignal()}}}}}Column {leftPadding: units.smallSpacingColumn {spacing: units.smallSpacingControls.Label {text: i18n("Scrolling:")}Column {leftPadding: units.smallSpacingColumn {spacing: units.smallSpacingExclGroupBox {id: scrollmethodlabel: i18n("Scroll method:")model: [i18n("Two fingers"), i18n("Touchpad edges"), /*i18n("On Button down"),*/ i18n("No scroll")]property bool isNoScroll: truefunction load() {itemAt(0).enabled = touchpad.supportsScrollTwoFingeritemAt(1).enabled = touchpad.supportsScrollEdge// TODO:// itemAt(2).enabled = touchpad.supportsScrollOnButtonDownvar toCheck = 2if (itemAt(0).enabled && touchpad.scrollTwoFinger) {toCheck = 0} else if (itemAt(1).enabled && touchpad.scrollEdge) {toCheck = 1// } else if (itemAt(2).enabled && touchpad.scrollOnButtonDown) {// toCheck = 2}itemAt(0).tooltiptext = i18n("Slide with two fingers scrolls.")itemAt(1).tooltiptext = i18n("Slide on the touchpad edges scrolls.")itemAt(2).tooltiptext = i18n("All forms of touchpad scrolling are deactivated.")isNoScroll = (toCheck == 2)itemAt(toCheck).checked = maincol.enabled}onCurrentChanged: {if (enabled && !root.loading) {touchpad.scrollTwoFinger = itemAt(0).checkedtouchpad.scrollEdge = itemAt(1).checked// touchpad.scrollOnButtonDown = itemAt(2).checkedroot.changeSignal()}isNoScroll = itemAt(2).checkedloading = truenaturalScroll.load()loading = false}}Controls.CheckBox {id: naturalScrolltext: i18n("Invert scroll direction")function load() {enabled = touchpad.supportsNaturalScroll && !scrollmethod.isNoScrollchecked = enabled && touchpad.naturalScroll}onCheckedChanged: {if (enabled && !root.loading) {touchpad.naturalScroll = checkedroot.changeSignal()}}ToolTip {text: i18n("Touchscreen like scrolling.")}}}}}}}}}}}