Changeset View
Changeset View
Standalone View
Standalone View
applets/pager/package/contents/ui/main.qml
1 | /* | 1 | /* | ||
---|---|---|---|---|---|
2 | * Copyright 2012 Luís Gabriel Lima <lampih@gmail.com> | 2 | * Copyright 2012 Luís Gabriel Lima <lampih@gmail.com> | ||
3 | * Copyright 2016 Kai Uwe Broulik <kde@privat.broulik.de> | 3 | * Copyright 2016 Kai Uwe Broulik <kde@privat.broulik.de> | ||
4 | * Copyright 2016 Eike Hein <hein@kde.org> | ||||
4 | * | 5 | * | ||
5 | * This program is free software; you can redistribute it and/or | 6 | * This program is free software; you can redistribute it and/or | ||
6 | * modify it under the terms of the GNU General Public License as | 7 | * modify it under the terms of the GNU General Public License as | ||
7 | * published by the Free Software Foundation; either version 2 of | 8 | * published by the Free Software Foundation; either version 2 of | ||
8 | * the License, or (at your option) any later version. | 9 | * the License, or (at your option) any later version. | ||
9 | * | 10 | * | ||
10 | * This program is distributed in the hope that it will be useful, | 11 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
Show All 12 Lines | |||||
24 | import org.kde.kquickcontrolsaddons 2.0 as KQuickControlsAddonsComponents | 25 | import org.kde.kquickcontrolsaddons 2.0 as KQuickControlsAddonsComponents | ||
25 | import org.kde.draganddrop 2.0 | 26 | import org.kde.draganddrop 2.0 | ||
26 | import org.kde.plasma.private.pager 2.0 | 27 | import org.kde.plasma.private.pager 2.0 | ||
27 | import "utils.js" as Utils | 28 | import "utils.js" as Utils | ||
28 | 29 | | |||
29 | MouseArea { | 30 | MouseArea { | ||
30 | id: root | 31 | id: root | ||
31 | 32 | | |||
33 | property bool isActivityPager: (plasmoid.pluginName == "org.kde.plasma.activitypager") | ||||
32 | property bool vertical: (plasmoid.formFactor == PlasmaCore.Types.Vertical) | 34 | property bool vertical: (plasmoid.formFactor == PlasmaCore.Types.Vertical) | ||
35 | property var activityDataSource: null | ||||
33 | 36 | | |||
34 | Layout.minimumWidth: !root.vertical ? pager.preferredSize.width : 1 | 37 | Layout.minimumWidth: !root.vertical ? pagerItemFlow.preferredWidth : 1 | ||
35 | Layout.minimumHeight: root.vertical ? pager.preferredSize.height : 1 | 38 | Layout.minimumHeight: root.vertical ? pagerItemFlow.preferredHeight : 1 | ||
36 | 39 | | |||
37 | Layout.maximumWidth: !root.vertical ? pager.preferredSize.width : Infinity | 40 | Layout.maximumWidth: !root.vertical ? pagerItemFlow.preferredWidth : Infinity | ||
38 | Layout.maximumHeight: root.vertical ? pager.preferredSize.height : Infinity | 41 | Layout.maximumHeight: root.vertical ? pagerItemFlow.preferredHeight : Infinity | ||
39 | 42 | | |||
40 | Plasmoid.preferredRepresentation: Plasmoid.fullRepresentation | 43 | Plasmoid.preferredRepresentation: Plasmoid.fullRepresentation | ||
41 | Plasmoid.status: pager.desktopCount > 1 ? PlasmaCore.Types.ActiveStatus : PlasmaCore.Types.HiddenStatus | 44 | Plasmoid.status: pagerModel.count > 1 ? PlasmaCore.Types.ActiveStatus : PlasmaCore.Types.HiddenStatus | ||
42 | 45 | | |||
43 | Layout.fillWidth: root.vertical | 46 | Layout.fillWidth: root.vertical | ||
44 | Layout.fillHeight: !root.vertical | 47 | Layout.fillHeight: !root.vertical | ||
45 | 48 | | |||
46 | property bool dragging: false | 49 | property bool dragging: false | ||
47 | property int dragId | 50 | property int dragId | ||
48 | 51 | | |||
49 | property int dragSwitchDesktopId: -1 | 52 | property int dragSwitchDesktopId: -1 | ||
50 | 53 | | |||
51 | anchors.fill: parent | 54 | anchors.fill: parent | ||
52 | acceptedButtons: Qt.NoButton | 55 | acceptedButtons: Qt.NoButton | ||
53 | 56 | | |||
54 | function colorWithAlpha(color, alpha) { | 57 | function colorWithAlpha(color, alpha) { | ||
55 | return Qt.rgba(color.r, color.g, color.b, alpha) | 58 | return Qt.rgba(color.r, color.g, color.b, alpha) | ||
56 | } | 59 | } | ||
57 | 60 | | |||
58 | readonly property color windowActiveOnActiveDesktopColor: colorWithAlpha(theme.textColor, 0.6) | 61 | readonly property color windowActiveOnActiveDesktopColor: colorWithAlpha(theme.textColor, 0.6) | ||
59 | readonly property color windowInactiveOnActiveDesktopColor: colorWithAlpha(theme.textColor, 0.35) | 62 | readonly property color windowInactiveOnActiveDesktopColor: colorWithAlpha(theme.textColor, 0.35) | ||
60 | readonly property color windowActiveColor: colorWithAlpha(theme.textColor, 0.5) | 63 | readonly property color windowActiveColor: colorWithAlpha(theme.textColor, 0.5) | ||
61 | readonly property color windowActiveBorderColor: theme.textColor | 64 | readonly property color windowActiveBorderColor: theme.textColor | ||
62 | readonly property color windowInactiveColor: colorWithAlpha(theme.textColor, 0.17) | 65 | readonly property color windowInactiveColor: colorWithAlpha(theme.textColor, 0.17) | ||
63 | readonly property color windowInactiveBorderColor: colorWithAlpha(theme.textColor, 0.5) | 66 | readonly property color windowInactiveBorderColor: colorWithAlpha(theme.textColor, 0.5) | ||
64 | 67 | | |||
65 | function action_addDesktop() { | 68 | function action_addDesktop() { | ||
66 | pager.slotAddDesktop(); | 69 | pagerModel.addDesktop(); | ||
67 | } | 70 | } | ||
68 | 71 | | |||
69 | function action_removeDesktop() { | 72 | function action_removeDesktop() { | ||
70 | pager.slotRemoveDesktop(); | 73 | pagerModel.removeDesktop(); | ||
71 | } | 74 | } | ||
72 | 75 | | |||
73 | function action_openKCM() { | 76 | function action_openKCM() { | ||
74 | KQuickControlsAddonsComponents.KCMShell.open("desktop") | 77 | KQuickControlsAddonsComponents.KCMShell.open("desktop"); | ||
78 | } | ||||
79 | | ||||
80 | function action_showActivityManager() { | ||||
81 | if (!activityDataSource) { | ||||
82 | activityDataSource = Qt.createQmlObject('import org.kde.plasma.core 2.0 as PlasmaCore; \ | ||||
83 | PlasmaCore.DataSource { id: dataSource; engine: "org.kde.activities"; \ | ||||
84 | connectedSources: ["Status"] }', root); | ||||
85 | } | ||||
86 | | ||||
87 | var service = activityDataSource.serviceForSource("Status") | ||||
88 | var operation = service.operationDescription("toggleActivityManager") | ||||
89 | service.startOperationCall(operation) | ||||
75 | } | 90 | } | ||
76 | 91 | | |||
77 | onWheel: { | 92 | onWheel: { | ||
78 | if (wheel.angleDelta.y > 0 || wheel.angleDelta.x > 0) { | 93 | if (wheel.angleDelta.y > 0 || wheel.angleDelta.x > 0) { | ||
79 | pager.changeDesktop((repeater.count + pager.currentDesktop - 2) % repeater.count) | 94 | pagerModel.changePage((repeater.count + pagerModel.currentPage - 2) % repeater.count); | ||
80 | } else { | 95 | } else { | ||
81 | pager.changeDesktop(pager.currentDesktop % repeater.count) | 96 | pagerModel.changePage(pagerModel.currentPage % repeater.count); | ||
82 | } | 97 | } | ||
83 | } | 98 | } | ||
84 | 99 | | |||
85 | Component.onCompleted: { | 100 | PagerModel { | ||
86 | if (KQuickControlsAddonsComponents.KCMShell.authorize("desktop.desktop").length > 0) { | 101 | id: pagerModel | ||
87 | plasmoid.setAction("addDesktop", i18n("Add Virtual Desktop"), "list-add"); | | |||
88 | plasmoid.setAction("removeDesktop", i18n("Remove Virtual Desktop"), "list-remove"); | | |||
89 | plasmoid.action("removeDesktop").enabled = Qt.binding(function() { | | |||
90 | return repeater.count > 1; | | |||
91 | }); | | |||
92 | 102 | | |||
93 | plasmoid.setAction("openKCM", i18n("Configure Desktops..."), "configure"); | 103 | enabled: root.visible | ||
104 | | ||||
105 | showDesktop: (plasmoid.configuration.currentDesktopSelected == 1) | ||||
106 | | ||||
107 | pagerType: isActivityPager ? PagerModel.Activities : PagerModel.VirtualDesktops | ||||
94 | } | 108 | } | ||
109 | | ||||
110 | Connections { | ||||
111 | target: plasmoid.configuration | ||||
112 | | ||||
113 | onShowWindowIconsChanged: { | ||||
114 | // Causes the model to reset; Component.onCompleted in the | ||||
115 | // window delegate now gets a chance to create the icon item, | ||||
116 | // which it otherwise will not do. | ||||
117 | pagerModel.refresh(); | ||||
95 | } | 118 | } | ||
96 | 119 | | |||
97 | Pager { | 120 | onDisplayedTextChanged: { | ||
98 | id: pager | 121 | // Causes the model to reset; Component.onCompleted in the | ||
99 | // don't bother updating the models when we're not visible | 122 | // desktop delegate now gets a chance to create the label item, | ||
100 | enabled: root.visible | 123 | // which it otherwise will not do. | ||
101 | orientation: plasmoid.formFactor == PlasmaCore.Types.Vertical ? Qt.Vertical : Qt.Horizontal | 124 | pagerModel.refresh(); | ||
102 | size: Qt.size(root.width, root.height) | 125 | } | ||
103 | showWindowIcons: plasmoid.configuration.showWindowIcons | 126 | } | ||
104 | currentDesktopSelected: plasmoid.configuration.currentDesktopSelected | 127 | | ||
105 | displayedText: plasmoid.configuration.displayedText | 128 | Component { | ||
129 | id: desktopLabelComponent | ||||
130 | | ||||
131 | PlasmaComponents.Label { | ||||
132 | anchors.centerIn: parent | ||||
133 | | ||||
134 | property int index: 0 | ||||
135 | property var model: null | ||||
136 | | ||||
137 | text: plasmoid.configuration.displayedText ? model.display : index + 1 | ||||
138 | } | ||||
139 | } | ||||
140 | | ||||
141 | Component { | ||||
142 | id: windowIconComponent | ||||
143 | | ||||
144 | PlasmaCore.IconItem { | ||||
145 | anchors.centerIn: parent | ||||
146 | | ||||
147 | height: parent.width / 2 | ||||
148 | width: parent.height / 2 | ||||
149 | | ||||
150 | property var model: null | ||||
151 | | ||||
152 | source: model ? model.decoration : undefined | ||||
153 | usesPlasmaTheme: false | ||||
154 | animated: false | ||||
155 | } | ||||
106 | } | 156 | } | ||
107 | 157 | | |||
108 | Timer { | 158 | Timer { | ||
109 | id: dragTimer | 159 | id: dragTimer | ||
110 | interval: 1000 | 160 | interval: 1000 | ||
111 | onTriggered: { | 161 | onTriggered: { | ||
112 | if (dragSwitchDesktopId != -1 && dragSwitchDesktopId !== pager.currentDesktop-1) { | 162 | if (dragSwitchDesktopId != -1 && dragSwitchDesktopId !== pagerModel.currentPage - 1) { | ||
113 | pager.changeDesktop(dragSwitchDesktopId); | 163 | pagerModel.changePage(dragSwitchDesktopId); | ||
164 | } | ||||
165 | } | ||||
114 | } | 166 | } | ||
167 | | ||||
168 | Flow { | ||||
169 | id: pagerItemFlow | ||||
170 | | ||||
171 | anchors.fill: parent | ||||
172 | | ||||
173 | spacing: units.devicePixelRatio | ||||
174 | | ||||
175 | property int effectiveRows: { | ||||
176 | var columns = Math.floor(repeater.count / pagerModel.layoutRows); | ||||
davidedmundson: add some readonly's over here.
It's apparently marginally faster; plus it can make things a… | |||||
hein: Will do. | |||||
177 | | ||||
178 | if (repeater.count % pagerModel.layoutRows > 0) { | ||||
179 | columns += 1; | ||||
180 | } | ||||
181 | | ||||
182 | var rows = Math.floor(repeater.count / columns); | ||||
183 | | ||||
184 | if (repeater.count % columns > 0) { | ||||
185 | rows += 1; | ||||
115 | } | 186 | } | ||
187 | | ||||
188 | return rows; | ||||
116 | } | 189 | } | ||
117 | 190 | | |||
191 | readonly property int effectiveColumns: Math.ceil(repeater.count / effectiveRows) | ||||
192 | | ||||
193 | readonly property real pagerItemSizeRatio: pagerModel.pagerItemSize.width / pagerModel.pagerItemSize.height | ||||
194 | readonly property real widthScaleFactor: columnWidth / pagerModel.pagerItemSize.width | ||||
195 | readonly property real heightScaleFactor: rowHeight / pagerModel.pagerItemSize.height | ||||
196 | | ||||
197 | readonly property int innerSpacing: ((vertical ? effectiveColumns : effectiveRows) - 1) * spacing | ||||
198 | readonly property int rowHeight: vertical ? Math.floor(columnWidth / pagerItemSizeRatio) : Math.floor((root.height - innerSpacing) / effectiveRows) | ||||
199 | readonly property int columnWidth: vertical ? Math.floor((root.width - innerSpacing) / effectiveColumns) : Math.floor(rowHeight * pagerItemSizeRatio) | ||||
200 | | ||||
201 | readonly property int preferredWidth: vertical ? width : (effectiveColumns * columnWidth) + ((effectiveColumns - 1) * spacing) | ||||
202 | readonly property int preferredHeight: vertical ? (effectiveRows * rowHeight) + ((effectiveRows - 1) * spacing) : height | ||||
203 | | ||||
118 | Repeater { | 204 | Repeater { | ||
119 | id: repeater | 205 | id: repeater | ||
120 | model: pager.model | 206 | model: pagerModel | ||
121 | 207 | | |||
122 | PlasmaCore.ToolTipArea { | 208 | PlasmaCore.ToolTipArea { | ||
123 | id: desktop | 209 | id: desktop | ||
124 | 210 | | |||
125 | property int desktopId: index | 211 | property int desktopId: index | ||
126 | property string desktopName: model.desktopName ? model.desktopName : "" | 212 | property bool active: isActivityPager ? (index == pagerModel.currentPage) : (index + 1 == pagerModel.currentPage) | ||
127 | property bool active: (desktopId === pager.currentDesktop-1) | | |||
128 | 213 | | |||
129 | mainText: desktopName | 214 | mainText: model.display | ||
130 | // our ToolTip has maximumLineCount of 8 which doesn't fit but QML doesn't | 215 | // our ToolTip has maximumLineCount of 8 which doesn't fit but QML doesn't | ||
131 | // respect that in RichText so we effectively can put in as much as we like :) | 216 | // respect that in RichText so we effectively can put in as much as we like :) | ||
132 | // it also gives us more flexibility when it comes to styling the <li> | 217 | // it also gives us more flexibility when it comes to styling the <li> | ||
133 | textFormat: Text.RichText | 218 | textFormat: Text.RichText | ||
134 | 219 | | |||
135 | function updateSubText() { | 220 | function updateSubText() { | ||
136 | var generateWindowList = function windowList(windows) { | 221 | var generateWindowList = function windowList(windows) { | ||
137 | // if we have 5 windows, we would show "4 and another one" with the | 222 | // if we have 5 windows, we would show "4 and another one" with the | ||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Line(s) | |||||
181 | if (text.length) { | 266 | if (text.length) { | ||
182 | // Get rid of the spacing <ul> would cause | 267 | // Get rid of the spacing <ul> would cause | ||
183 | text = "<style>ul { margin: 0; }</style>" + text | 268 | text = "<style>ul { margin: 0; }</style>" + text | ||
184 | } | 269 | } | ||
185 | 270 | | |||
186 | subText = text | 271 | subText = text | ||
187 | } | 272 | } | ||
188 | 273 | | |||
189 | x: model.x | 274 | width: pagerItemFlow.columnWidth | ||
190 | y: model.y | 275 | height: pagerItemFlow.rowHeight | ||
191 | width: model.width | | |||
192 | height: model.height | | |||
193 | 276 | | |||
194 | PlasmaCore.FrameSvgItem { | 277 | PlasmaCore.FrameSvgItem { | ||
195 | anchors.fill: parent | 278 | anchors.fill: parent | ||
196 | z: 1 // to make sure that the FrameSvg will be placed on top of the windows | 279 | z: 1 // to make sure that the FrameSvg will be placed on top of the windows | ||
197 | imagePath: "widgets/pager" | 280 | imagePath: "widgets/pager" | ||
198 | prefix: (desktopMouseArea.enabled && desktopMouseArea.containsMouse) || (root.dragging && root.dragId == desktopId) ? | 281 | prefix: (desktopMouseArea.enabled && desktopMouseArea.containsMouse) || (root.dragging && root.dragId == desktopId) ? | ||
199 | "hover" : (desktop.active ? "active" : "normal") | 282 | "hover" : (desktop.active ? "active" : "normal") | ||
200 | } | 283 | } | ||
201 | 284 | | |||
202 | DropArea { | 285 | DropArea { | ||
203 | id: droparea | 286 | id: droparea | ||
204 | anchors.fill: parent | 287 | anchors.fill: parent | ||
205 | preventStealing: true | 288 | preventStealing: true | ||
206 | 289 | | |||
207 | onDragEnter: { | 290 | onDragEnter: { | ||
208 | root.dragSwitchDesktopId = desktop.desktopId; | 291 | root.dragSwitchDesktopId = desktop.desktopId; | ||
209 | dragTimer.start(); | 292 | dragTimer.start(); | ||
210 | } | 293 | } | ||
211 | onDragLeave: { | 294 | onDragLeave: { | ||
212 | root.dragSwitchDesktopId = -1; | 295 | root.dragSwitchDesktopId = -1; | ||
213 | dragTimer.stop(); | 296 | dragTimer.stop(); | ||
214 | } | 297 | } | ||
215 | onDrop: { | 298 | onDrop: { | ||
216 | pager.dropMimeData(event.mimeData, desktop.desktopId); | 299 | pagerModel.drop(event.mimeData, desktop.desktopId); | ||
217 | root.dragSwitchDesktopId = -1; | 300 | root.dragSwitchDesktopId = -1; | ||
218 | dragTimer.stop(); | 301 | dragTimer.stop(); | ||
219 | } | 302 | } | ||
220 | } | 303 | } | ||
221 | 304 | | |||
222 | MouseArea { | 305 | MouseArea { | ||
223 | id: desktopMouseArea | 306 | id: desktopMouseArea | ||
224 | anchors.fill: parent | 307 | anchors.fill: parent | ||
225 | hoverEnabled : true | 308 | hoverEnabled : true | ||
226 | onClicked: pager.changeDesktop(desktopId); | 309 | onClicked: pagerModel.changePage(desktopId); | ||
227 | } | 310 | } | ||
228 | 311 | | |||
229 | Item { | 312 | Item { | ||
230 | id: clipRect | 313 | id: clipRect | ||
231 | x: Math.round(units.devicePixelRatio) | 314 | x: Math.round(units.devicePixelRatio) | ||
232 | y: Math.round(units.devicePixelRatio) | 315 | y: Math.round(units.devicePixelRatio) | ||
233 | width: desktop.width - 2 * x | 316 | width: desktop.width - 2 * x | ||
234 | height: desktop.height - 2 * y | 317 | height: desktop.height - 2 * y | ||
235 | clip: true | 318 | clip: true | ||
236 | 319 | | |||
237 | PlasmaComponents.Label { | | |||
238 | id: desktopText | | |||
239 | anchors.centerIn: parent | | |||
240 | text: pager.displayedText == Pager.Name ? desktop.desktopName | | |||
241 | : (pager.displayedText == Pager.Number ? desktop.desktopId+1 : "") | | |||
242 | | ||||
243 | } | | |||
244 | 320 | | |||
245 | Repeater { | 321 | Repeater { | ||
246 | id: windowRectRepeater | 322 | id: windowRectRepeater | ||
247 | model: windows | 323 | | ||
324 | model: TasksModel | ||||
325 | | ||||
248 | onCountChanged: desktop.updateSubText() | 326 | onCountChanged: desktop.updateSubText() | ||
249 | 327 | | |||
250 | Rectangle { | 328 | Rectangle { | ||
251 | id: windowRect | 329 | id: windowRect | ||
252 | 330 | | |||
253 | property int windowId: model.windowId | 331 | z: model.StackingOrder | ||
254 | property string visibleName: model.visibleName | 332 | | ||
255 | property bool minimized: model.minimized | 333 | property rect geometry: model.Geometry | ||
334 | property int windowId: model.LegacyWinIdList[0] | ||||
335 | property string visibleName: model.display | ||||
336 | property bool minimized: (model.IsMinimized === true) | ||||
256 | onMinimizedChanged: desktop.updateSubText() | 337 | onMinimizedChanged: desktop.updateSubText() | ||
257 | 338 | | |||
258 | /* since we move clipRect with 1, move it back */ | 339 | /* since we move clipRect with 1, move it back */ | ||
259 | x: model.x - Math.round(units.devicePixelRatio) | 340 | x: (geometry.x * pagerItemFlow.widthScaleFactor) - Math.round(units.devicePixelRatio) | ||
260 | y: model.y - Math.round(units.devicePixelRatio) | 341 | y: (geometry.y * pagerItemFlow.heightScaleFactor) - Math.round(units.devicePixelRatio) | ||
261 | width: model.width | 342 | width: geometry.width * pagerItemFlow.widthScaleFactor | ||
262 | height: model.height | 343 | height: geometry.height * pagerItemFlow.heightScaleFactor | ||
263 | visible: !model.visible && !minimized | 344 | visible: model.IsMinimized !== true | ||
264 | color: { | 345 | color: { | ||
265 | if (desktop.active) { | 346 | if (desktop.active) { | ||
266 | if (model.active) | 347 | if (model.IsActive === true) | ||
267 | return windowActiveOnActiveDesktopColor; | 348 | return windowActiveOnActiveDesktopColor; | ||
268 | else | 349 | else | ||
269 | return windowInactiveOnActiveDesktopColor; | 350 | return windowInactiveOnActiveDesktopColor; | ||
270 | } else { | 351 | } else { | ||
271 | if (model.active) | 352 | if (model.IsActive === true) | ||
272 | return windowActiveColor; | 353 | return windowActiveColor; | ||
273 | else | 354 | else | ||
274 | return windowInactiveColor; | 355 | return windowInactiveColor; | ||
275 | } | 356 | } | ||
276 | } | 357 | } | ||
277 | 358 | | |||
278 | border.width: Math.round(units.devicePixelRatio) | 359 | border.width: Math.round(units.devicePixelRatio) | ||
279 | border.color: model.active ? windowActiveBorderColor | 360 | border.color: (model.IsActive === true) ? windowActiveBorderColor | ||
280 | : windowInactiveBorderColor | 361 | : windowInactiveBorderColor | ||
281 | 362 | | |||
282 | KQuickControlsAddonsComponents.QPixmapItem { | | |||
283 | id: icon | | |||
284 | anchors.centerIn: parent | | |||
285 | pixmap: model.icon | | |||
286 | height: nativeHeight | | |||
287 | width: nativeWidth | | |||
288 | visible: pager.showWindowIcons | | |||
289 | } | | |||
290 | | ||||
291 | MouseArea { | 363 | MouseArea { | ||
292 | id: windowMouseArea | 364 | id: windowMouseArea | ||
293 | anchors.fill: parent | 365 | anchors.fill: parent | ||
366 | | ||||
294 | drag.target: windowRect | 367 | drag.target: windowRect | ||
295 | drag.axis: Drag.XandYAxis | 368 | drag.axis: Drag.XandYAxis | ||
296 | drag.minimumX: -windowRect.width/2 | 369 | drag.minimumX: -windowRect.width/2 | ||
297 | drag.maximumX: root.width - windowRect.width/2 | 370 | drag.maximumX: root.width - windowRect.width/2 | ||
298 | drag.minimumY: -windowRect.height/2 | 371 | drag.minimumY: -windowRect.height/2 | ||
299 | drag.maximumY: root.height - windowRect.height/2 | 372 | drag.maximumY: root.height - windowRect.height/2 | ||
300 | 373 | | |||
301 | // used to save the state of some properties before the dragging | | |||
302 | QtObject { | | |||
303 | id: saveState | | |||
304 | property int x: -1 | | |||
305 | property int y: -1 | | |||
306 | property variant parent | | |||
307 | property int desktop: -1 | | |||
308 | property int mouseX: -1 | | |||
309 | property int mouseY: -1 | | |||
310 | } | | |||
311 | | ||||
312 | drag.onActiveChanged: { | 374 | drag.onActiveChanged: { | ||
313 | root.dragging = drag.active; | 375 | root.dragging = drag.active; | ||
376 | root.dragId = desktop.desktopId; | ||||
314 | desktopMouseArea.enabled = !drag.active; | 377 | desktopMouseArea.enabled = !drag.active; | ||
315 | } | 378 | } | ||
316 | 379 | | |||
317 | // reparent windowRect to enable the dragging for other desktops | | |||
318 | onPressed: { | 380 | onPressed: { | ||
319 | if (windowRect.parent == root) | 381 | // Reparent to allow drags outside of this desktop. | ||
320 | return; | | |||
321 | | ||||
322 | saveState.x = windowRect.x; | | |||
323 | saveState.y = windowRect.y | | |||
324 | saveState.parent = windowRect.parent; | | |||
325 | saveState.desktop = desktop.desktopId; | | |||
326 | saveState.mouseX = mouseX; | | |||
327 | saveState.mouseY = mouseY; | | |||
328 | | ||||
329 | var value = root.mapFromItem(clipRect, windowRect.x, windowRect.y); | 382 | var value = root.mapFromItem(clipRect, windowRect.x, windowRect.y); | ||
330 | windowRect.x = value.x; | 383 | windowRect.x = value.x; | ||
331 | windowRect.y = value.y | 384 | windowRect.y = value.y | ||
332 | windowRect.parent = root; | 385 | windowRect.parent = root; | ||
333 | } | 386 | } | ||
334 | 387 | | |||
335 | onReleased: { | 388 | onReleased: { | ||
336 | if (root.dragging) { | 389 | if (root.dragging) { | ||
337 | pager.moveWindow(windowRect.windowId, windowRect.x, windowRect.y, | 390 | windowRect.visible = false; | ||
338 | root.dragId, saveState.desktop); | 391 | var windowCenter = Qt.point(windowRect.x + windowRect.width / 2, windowRect.y + windowRect.height / 2); | ||
392 | var pagerItem = pagerItemFlow.childAt(windowCenter.x, windowCenter.y); | ||||
393 | | ||||
394 | if (pagerItem) { | ||||
395 | var relativeTopLeft = root.mapToItem(pagerItem, windowRect.x, windowRect.y); | ||||
396 | | ||||
397 | pagerModel.moveWindow(windowRect.windowId, relativeTopLeft.x, relativeTopLeft.y, | ||||
398 | pagerItem.desktopId, root.dragId, | ||||
399 | pagerItemFlow.widthScaleFactor, pagerItemFlow.heightScaleFactor); | ||||
400 | } | ||||
401 | | ||||
402 | // Will reset the model, destroying the reparented drag delegate that | ||||
davidedmundson: why? | |||||
Using Quick's drag functionality on the delegate breaks the binding that will otherwise cause it to be repositioned based on the model's Geometry role. Resetting the model destroys and recreates the delegate. The old code relied on this happening implicitly (because that model would reset tens of thousands of times throughout a typical session on window state changes), in the new code it needs to be done explicitly. It would be possible to optimize this more, but it's not really worth more complicated code (or extra objects like Bindings) considering DND is rare and operation doesn't impact UX. I'll add a comment though. hein: Using Quick's drag functionality on the delegate breaks the binding that will otherwise cause… | |||||
403 | // is no longer bound to model.Geometry. | ||||
404 | pagerModel.refresh(); | ||||
339 | } else { | 405 | } else { | ||
340 | // when there is no dragging (just a click), the event is passed | 406 | // When there is no dragging (just a click), the event is passed | ||
341 | // to the desktop mousearea | 407 | // to the desktop MouseArea. | ||
342 | desktopMouseArea.clicked(mouse); | 408 | desktopMouseArea.clicked(mouse); | ||
343 | } | 409 | } | ||
344 | | ||||
345 | windowRect.x = saveState.x; | | |||
346 | windowRect.y = saveState.y; | | |||
347 | windowRect.parent = saveState.parent; | | |||
348 | } | 410 | } | ||
349 | } | 411 | } | ||
350 | 412 | | |||
351 | function checkDesktopHover() { | 413 | Component.onCompleted: { | ||
352 | if (!windowMouseArea.drag.active) | 414 | if (plasmoid.configuration.showWindowIcons) { | ||
353 | return; | 415 | windowIconComponent.createObject(windowRect, {"model": model}); | ||
354 | 416 | } | |||
355 | var mouse = root.mapFromItem(windowRect, saveState.mouseX, saveState.mouseY); | 417 | } | ||
356 | for (var i = 0; i < root.children.length; i++) { | | |||
357 | var item = root.children[i]; | | |||
358 | if (item.desktopId != undefined && Utils.contains(item, mouse)) { | | |||
359 | root.dragId = item.desktopId; | | |||
360 | return; | | |||
361 | } | 418 | } | ||
362 | } | 419 | } | ||
363 | } | 420 | } | ||
364 | 421 | | |||
365 | onXChanged: checkDesktopHover(); | 422 | Component.onCompleted: { | ||
366 | onYChanged: checkDesktopHover(); | 423 | if (plasmoid.configuration.displayedText < 2) { | ||
424 | desktopLabelComponent.createObject(desktop, {"index": index, "model": model}); | ||||
425 | } | ||||
426 | } | ||||
427 | } | ||||
367 | } | 428 | } | ||
368 | } | 429 | } | ||
430 | | ||||
431 | Component.onCompleted: { | ||||
432 | if (isActivityPager) { | ||||
433 | plasmoid.setAction("showActivityManager", i18n("Show Activity Manager..."), "preferences-activities"); | ||||
434 | } else { | ||||
435 | if (KQuickControlsAddonsComponents.KCMShell.authorize("desktop.desktop").length > 0) { | ||||
436 | plasmoid.setAction("addDesktop", i18n("Add Virtual Desktop"), "list-add"); | ||||
437 | plasmoid.setAction("removeDesktop", i18n("Remove Virtual Desktop"), "list-remove"); | ||||
438 | plasmoid.action("removeDesktop").enabled = Qt.binding(function() { | ||||
439 | return repeater.count > 1; | ||||
440 | }); | ||||
441 | | ||||
442 | plasmoid.setAction("openKCM", i18n("Configure Desktops..."), "configure"); | ||||
369 | } | 443 | } | ||
370 | } | 444 | } | ||
371 | } | 445 | } | ||
372 | } | 446 | } |
add some readonly's over here.
It's apparently marginally faster; plus it can make things a bit more readable