Changeset View
Changeset View
Standalone View
Standalone View
kcms/touchpadx/src/applet/qml/contents/ui/touchpad.qml
- This file was added.
1 | // -*- coding: iso-8859-1 -*- | ||||
---|---|---|---|---|---|
2 | /* | ||||
3 | * Copyright 2013 Alexander Mezin <mezin.alexander@gmail.com> | ||||
4 | * Copyright 2016 Kai Uwe Broulik <kde@privat.broulik.de> | ||||
5 | * | ||||
6 | * This program is free software; you can redistribute it and/or modify | ||||
7 | * it under the terms of the GNU Library General Public License as | ||||
8 | * published by the Free Software Foundation; either version 2 or | ||||
9 | * (at your option) any later version. | ||||
10 | * | ||||
11 | * This program is distributed in the hope that it will be useful, | ||||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
14 | * GNU General Public License for more details | ||||
15 | * | ||||
16 | * You should have received a copy of the GNU Library General Public | ||||
17 | * License along with this program; if not, write to the | ||||
18 | * Free Software Foundation, Inc., | ||||
19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||||
20 | */ | ||||
21 | | ||||
22 | import QtQuick 2.0 | ||||
23 | import QtQuick.Layouts 1.1 | ||||
24 | | ||||
25 | import org.kde.plasma.core 2.0 as PlasmaCore | ||||
26 | import org.kde.plasma.components 2.0 as PlasmaComponents | ||||
27 | | ||||
28 | import org.kde.plasma.plasmoid 2.0 | ||||
29 | | ||||
30 | Item { | ||||
31 | id: root | ||||
32 | | ||||
33 | readonly property bool hasTouchpad: typeof dataSource.data.touchpad !== "undefined" && dataSource.data.touchpad.workingTouchpadFound | ||||
34 | readonly property bool touchpadEnabled: hasTouchpad ? dataSource.data.touchpad.enabled : false | ||||
35 | readonly property bool hasMouse: hasTouchpad ? dataSource.data.touchpad.mousePluggedIn : false | ||||
36 | | ||||
37 | Plasmoid.preferredRepresentation: Plasmoid.compactRepresentation | ||||
38 | Plasmoid.icon: touchpadEnabled ? "input-touchpad-on" : "input-touchpad-off" | ||||
39 | Plasmoid.status: { | ||||
40 | if (confirmDialog.status !== PlasmaComponents.DialogStatus.Closed) { | ||||
41 | return PlasmaCore.Types.AcceptingInputStatus; | ||||
42 | } else if (hasTouchpad) { | ||||
43 | return PlasmaCore.Types.ActiveStatus; | ||||
44 | } else { | ||||
45 | return PlasmaCore.Types.HiddenStatus; | ||||
46 | } | ||||
47 | } | ||||
48 | Plasmoid.toolTipSubText: { | ||||
49 | if (!hasTouchpad) { | ||||
50 | return i18n("No touchpad was found"); | ||||
51 | } else if (touchpadEnabled) { | ||||
52 | return i18n("Touchpad is enabled"); | ||||
53 | } else { | ||||
54 | return i18n("Touchpad is disabled"); | ||||
55 | } | ||||
56 | } | ||||
57 | Plasmoid.onActivated: action_toggle() | ||||
58 | | ||||
59 | Component.onCompleted: { | ||||
60 | // the "text" argument for setAction is mandatory but we overwrite | ||||
61 | // it by a binding right away anyway | ||||
62 | plasmoid.setAction("toggle", ""); | ||||
63 | | ||||
64 | var action = plasmoid.action("toggle"); | ||||
65 | action.text = Qt.binding(function() { | ||||
66 | return root.touchpadEnabled ? i18n("Disable touchpad") : i18n("Enable touchpad"); | ||||
67 | }); | ||||
68 | action.visible = Qt.binding(function() { | ||||
69 | return root.hasTouchpad; | ||||
70 | }); | ||||
71 | } | ||||
72 | | ||||
73 | PlasmaCore.DataSource { | ||||
74 | id: dataSource | ||||
75 | engine: "touchpad" | ||||
76 | connectedSources: dataSource.sources | ||||
77 | } | ||||
78 | | ||||
79 | Plasmoid.compactRepresentation: PlasmaCore.ToolTipArea { | ||||
80 | id: toolTip | ||||
81 | | ||||
82 | Layout.minimumWidth: units.iconSizes.small | ||||
83 | Layout.minimumHeight: Layout.minimumWidth | ||||
84 | | ||||
85 | icon: plasmoid.icon | ||||
86 | mainText: plasmoid.title | ||||
87 | subText: plasmoid.toolTipSubText | ||||
88 | | ||||
89 | active: confirmDialog.status === PlasmaComponents.DialogStatus.Closed | ||||
90 | | ||||
91 | Connections { | ||||
92 | target: confirmDialog | ||||
93 | onStatusChanged: { | ||||
94 | if (confirmDialog.status === PlasmaComponents.DialogStatus.Open) { | ||||
95 | toolTip.hideToolTip() | ||||
96 | } | ||||
97 | } | ||||
98 | } | ||||
99 | | ||||
100 | MouseArea { | ||||
101 | anchors.fill: parent | ||||
102 | enabled: root.hasTouchpad | ||||
103 | onClicked: root.action_toggle() | ||||
104 | } | ||||
105 | | ||||
106 | PlasmaCore.IconItem { | ||||
107 | anchors.fill: parent | ||||
108 | source: plasmoid.icon | ||||
109 | active: parent.containsMouse | ||||
110 | enabled: root.hasTouchpad | ||||
111 | } | ||||
112 | } | ||||
113 | | ||||
114 | // This is only accessible from System Tray, when hidden in the popup | ||||
115 | // and you click the list item text instead of the icon | ||||
116 | Plasmoid.fullRepresentation: Item { | ||||
117 | | ||||
118 | PlasmaComponents.Button { | ||||
119 | readonly property QtObject action: plasmoid.action("toggle") | ||||
120 | anchors.centerIn: parent | ||||
121 | text: action.text | ||||
122 | enabled: action.visible | ||||
123 | onClicked: action.trigger() | ||||
124 | } | ||||
125 | | ||||
126 | } | ||||
127 | | ||||
128 | function action_toggle() { | ||||
129 | if (!root.hasTouchpad) { | ||||
130 | return; | ||||
131 | } | ||||
132 | | ||||
133 | if (!root.hasMouse && root.touchpadEnabled) { | ||||
134 | confirmDialog.open() | ||||
135 | return; | ||||
136 | } | ||||
137 | | ||||
138 | execOp("toggle") | ||||
139 | } | ||||
140 | | ||||
141 | function execOp(op) { | ||||
142 | var service = dataSource.serviceForSource("touchpad") | ||||
143 | service.startOperationCall(service.operationDescription(op)) | ||||
144 | } | ||||
145 | | ||||
146 | PlasmaComponents.QueryDialog { | ||||
147 | id: confirmDialog | ||||
148 | visualParent: plasmoid.compactRepresentationItem | ||||
149 | titleText: i18n("Touchpad") | ||||
150 | titleIcon: "dialog-warning" | ||||
151 | message: i18n("No mouse was detected.\nAre you sure you want to disable the touchpad?") | ||||
152 | acceptButtonText: i18n("Disable") | ||||
153 | onAccepted: execOp("disable") | ||||
154 | } | ||||
155 | } |