Changeset View
Changeset View
Standalone View
Standalone View
applets/kicker/package/contents/ui/ItemGridView.qml
Show First 20 Lines • Show All 64 Lines • ▼ Show 20 Line(s) | 62 | onFocusChanged: { | |||
---|---|---|---|---|---|
65 | } | 65 | } | ||
66 | } | 66 | } | ||
67 | 67 | | |||
68 | function currentRow() { | 68 | function currentRow() { | ||
69 | if (currentIndex == -1) { | 69 | if (currentIndex == -1) { | ||
70 | return -1; | 70 | return -1; | ||
71 | } | 71 | } | ||
72 | 72 | | |||
73 | return Math.floor(currentIndex / Math.floor(width / cellWidth)); | 73 | return Math.floor(currentIndex / Math.floor(width / itemGrid.cellWidth)); | ||
74 | } | 74 | } | ||
75 | 75 | | |||
76 | function currentCol() { | 76 | function currentCol() { | ||
77 | if (currentIndex == -1) { | 77 | if (currentIndex == -1) { | ||
78 | return -1; | 78 | return -1; | ||
79 | } | 79 | } | ||
80 | 80 | | |||
81 | return currentIndex - (currentRow() * Math.floor(width / cellWidth)); | 81 | return currentIndex - (currentRow() * Math.floor(width / itemGrid.cellWidth)); | ||
82 | } | 82 | } | ||
83 | 83 | | |||
84 | function lastRow() { | 84 | function lastRow() { | ||
85 | var columns = Math.floor(width / cellWidth); | 85 | var columns = Math.floor(width / itemGrid.cellWidth); | ||
86 | return Math.ceil(count / columns) - 1; | 86 | return Math.ceil(count / columns) - 1; | ||
87 | } | 87 | } | ||
88 | 88 | | |||
89 | function tryActivate(row, col) { | 89 | function tryActivate(row, col) { | ||
90 | if (count) { | 90 | if (count) { | ||
91 | var columns = Math.floor(width / cellWidth); | 91 | var columns = Math.floor(width / itemGrid.cellWidth); | ||
92 | var rows = Math.ceil(count / columns); | 92 | var rows = Math.ceil(count / columns); | ||
93 | row = Math.min(row, rows - 1); | 93 | row = Math.min(row, rows - 1); | ||
94 | col = Math.min(col, columns - 1); | 94 | col = Math.min(col, columns - 1); | ||
95 | currentIndex = Math.min(row ? ((Math.max(1, row) * columns) + col) | 95 | currentIndex = Math.min(row ? ((Math.max(1, row) * columns) + col) | ||
96 | : col, | 96 | : col, | ||
97 | count - 1); | 97 | count - 1); | ||
98 | 98 | | |||
99 | focus = true; | 99 | focus = true; | ||
Show All 13 Lines | |||||
113 | } | 113 | } | ||
114 | 114 | | |||
115 | DropArea { | 115 | DropArea { | ||
116 | id: dropArea | 116 | id: dropArea | ||
117 | 117 | | |||
118 | anchors.fill: parent | 118 | anchors.fill: parent | ||
119 | 119 | | |||
120 | onDragMove: { | 120 | onDragMove: { | ||
121 | if (!dropEnabled || gridView.animating || !kicker.dragSource) { | 121 | if (!itemGrid.dropEnabled || gridView.animating || !kicker.dragSource) { | ||
122 | return; | 122 | return; | ||
123 | } | 123 | } | ||
124 | 124 | | |||
125 | var x = Math.max(0, event.x - (width % cellWidth)); | 125 | var x = Math.max(0, event.x - (width % itemGrid.cellWidth)); | ||
126 | var cPos = mapToItem(gridView.contentItem, x, event.y); | 126 | var cPos = mapToItem(gridView.contentItem, x, event.y); | ||
127 | var item = gridView.itemAt(cPos.x, cPos.y); | 127 | var item = gridView.itemAt(cPos.x, cPos.y); | ||
128 | 128 | | |||
129 | if (item) { | 129 | if (item) { | ||
130 | if (kicker.dragSource.parent === gridView.contentItem) { | 130 | if (kicker.dragSource.parent === gridView.contentItem) { | ||
131 | if (item !== kicker.dragSource) { | 131 | if (item !== kicker.dragSource) { | ||
132 | item.GridView.view.model.moveRow(dragSource.itemIndex, item.itemIndex); | 132 | item.GridView.view.model.moveRow(dragSource.itemIndex, item.itemIndex); | ||
133 | } | 133 | } | ||
134 | } else if (kicker.dragSource.GridView.view.model.favoritesModel === model | 134 | } else if (kicker.dragSource.GridView.view.model.favoritesModel === itemGrid.model | ||
135 | && !model.isFavorite(kicker.dragSource.favoriteId)) { | 135 | && !itemGrid.model.isFavorite(kicker.dragSource.favoriteId)) { | ||
136 | var hasPlaceholder = (model.dropPlaceholderIndex !== -1); | 136 | var hasPlaceholder = (itemGrid.model.dropPlaceholderIndex !== -1); | ||
137 | 137 | | |||
138 | model.dropPlaceholderIndex = item.itemIndex; | 138 | itemGrid.model.dropPlaceholderIndex = item.itemIndex; | ||
139 | 139 | | |||
140 | if (!hasPlaceholder) { | 140 | if (!hasPlaceholder) { | ||
141 | gridView.currentIndex = (item.itemIndex - 1); | 141 | gridView.currentIndex = (item.itemIndex - 1); | ||
142 | } | 142 | } | ||
143 | } | 143 | } | ||
144 | } else if (kicker.dragSource.parent !== gridView.contentItem | 144 | } else if (kicker.dragSource.parent !== gridView.contentItem | ||
145 | && kicker.dragSource.GridView.view.model.favoritesModel === model | 145 | && kicker.dragSource.GridView.view.model.favoritesModel === itemGrid.model | ||
146 | && !model.isFavorite(kicker.dragSource.favoriteId)) { | 146 | && !itemGrid.model.isFavorite(kicker.dragSource.favoriteId)) { | ||
147 | var hasPlaceholder = (model.dropPlaceholderIndex !== -1); | 147 | var hasPlaceholder = (itemGrid.model.dropPlaceholderIndex !== -1); | ||
148 | 148 | | |||
149 | model.dropPlaceholderIndex = hasPlaceholder ? model.count - 1 : model.count; | 149 | itemGrid.model.dropPlaceholderIndex = hasPlaceholder ? itemGrid.model.count - 1 : itemGrid.model.count; | ||
150 | 150 | | |||
151 | if (!hasPlaceholder) { | 151 | if (!hasPlaceholder) { | ||
152 | gridView.currentIndex = (model.count - 1); | 152 | gridView.currentIndex = (itemGrid.model.count - 1); | ||
153 | } | 153 | } | ||
154 | } else { | 154 | } else { | ||
155 | model.dropPlaceholderIndex = -1; | 155 | itemGrid.model.dropPlaceholderIndex = -1; | ||
156 | gridView.currentIndex = -1; | 156 | gridView.currentIndex = -1; | ||
157 | } | 157 | } | ||
158 | } | 158 | } | ||
159 | 159 | | |||
160 | onDragLeave: { | 160 | onDragLeave: { | ||
161 | if ("dropPlaceholderIndex" in model) { | 161 | if ("dropPlaceholderIndex" in itemGrid.model) { | ||
162 | model.dropPlaceholderIndex = -1; | 162 | itemGrid.model.dropPlaceholderIndex = -1; | ||
163 | gridView.currentIndex = -1; | 163 | gridView.currentIndex = -1; | ||
164 | } | 164 | } | ||
165 | } | 165 | } | ||
166 | 166 | | |||
167 | onDrop: { | 167 | onDrop: { | ||
168 | if (kicker.dragSource && kicker.dragSource.parent !== gridView.contentItem && kicker.dragSource.GridView.view.model.favoritesModel === model) { | 168 | if (kicker.dragSource && kicker.dragSource.parent !== gridView.contentItem && kicker.dragSource.GridView.view.model.favoritesModel === itemGrid.model) { | ||
169 | model.addFavorite(kicker.dragSource.favoriteId, model.dropPlaceholderIndex); | 169 | itemGrid.model.addFavorite(kicker.dragSource.favoriteId, itemGrid.model.dropPlaceholderIndex); | ||
170 | gridView.currentIndex = -1; | 170 | gridView.currentIndex = -1; | ||
171 | } | 171 | } | ||
172 | } | 172 | } | ||
173 | 173 | | |||
174 | Timer { | 174 | Timer { | ||
175 | id: resetAnimationDurationTimer | 175 | id: resetAnimationDurationTimer | ||
176 | 176 | | |||
177 | interval: 120 | 177 | interval: 120 | ||
Show All 18 Lines | 194 | GridView { | |||
196 | 196 | | |||
197 | signal itemContainsMouseChanged(bool containsMouse) | 197 | signal itemContainsMouseChanged(bool containsMouse) | ||
198 | 198 | | |||
199 | property bool usesPlasmaTheme: false | 199 | property bool usesPlasmaTheme: false | ||
200 | 200 | | |||
201 | property int iconSize: units.iconSizes.huge | 201 | property int iconSize: units.iconSizes.huge | ||
202 | 202 | | |||
203 | property bool animating: false | 203 | property bool animating: false | ||
204 | property int animationDuration: dropEnabled ? resetAnimationDurationTimer.interval : 0 | 204 | property int animationDuration: itemGrid.dropEnabled ? resetAnimationDurationTimer.interval : 0 | ||
205 | 205 | | |||
206 | focus: true | 206 | focus: true | ||
207 | 207 | | |||
208 | currentIndex: -1 | 208 | currentIndex: -1 | ||
209 | 209 | | |||
210 | move: Transition { | 210 | move: Transition { | ||
211 | enabled: itemGrid.dropEnabled | 211 | enabled: itemGrid.dropEnabled | ||
212 | 212 | | |||
Show All 25 Lines | 229 | SequentialAnimation { | |||
238 | PropertyAction { target: gridView; property: "animating"; value: false } | 238 | PropertyAction { target: gridView; property: "animating"; value: false } | ||
239 | } | 239 | } | ||
240 | } | 240 | } | ||
241 | 241 | | |||
242 | keyNavigationWraps: false | 242 | keyNavigationWraps: false | ||
243 | boundsBehavior: Flickable.StopAtBounds | 243 | boundsBehavior: Flickable.StopAtBounds | ||
244 | 244 | | |||
245 | delegate: ItemGridDelegate { | 245 | delegate: ItemGridDelegate { | ||
246 | showLabel: showLabels | 246 | showLabel: itemGrid.showLabels | ||
247 | } | 247 | } | ||
248 | 248 | | |||
249 | highlight: Item { | 249 | highlight: Item { | ||
250 | property bool isDropPlaceHolder: "dropPlaceholderIndex" in model && currentIndex === model.dropPlaceholderIndex | 250 | property bool isDropPlaceHolder: "dropPlaceholderIndex" in itemGrid.model && itemGrid.currentIndex === itemGrid.model.dropPlaceholderIndex | ||
251 | 251 | | |||
252 | PlasmaComponents.Highlight { | 252 | PlasmaComponents.Highlight { | ||
253 | visible: gridView.currentItem && !isDropPlaceHolder | 253 | visible: gridView.currentItem && !isDropPlaceHolder | ||
254 | 254 | | |||
255 | anchors.fill: parent | 255 | anchors.fill: parent | ||
256 | } | 256 | } | ||
257 | 257 | | |||
258 | PlasmaCore.FrameSvgItem { | 258 | PlasmaCore.FrameSvgItem { | ||
Show All 38 Lines | 295 | onCountChanged: { | |||
297 | resetAnimationDurationTimer.start(); | 297 | resetAnimationDurationTimer.start(); | ||
298 | } | 298 | } | ||
299 | 299 | | |||
300 | onModelChanged: { | 300 | onModelChanged: { | ||
301 | currentIndex = -1; | 301 | currentIndex = -1; | ||
302 | } | 302 | } | ||
303 | 303 | | |||
304 | Keys.onLeftPressed: { | 304 | Keys.onLeftPressed: { | ||
305 | if (currentCol() !== 0) { | 305 | if (itemGrid.currentCol() !== 0) { | ||
306 | event.accepted = true; | 306 | event.accepted = true; | ||
307 | moveCurrentIndexLeft(); | 307 | moveCurrentIndexLeft(); | ||
308 | } else { | 308 | } else { | ||
309 | itemGrid.keyNavLeft(); | 309 | itemGrid.keyNavLeft(); | ||
310 | } | 310 | } | ||
311 | } | 311 | } | ||
312 | 312 | | |||
313 | Keys.onRightPressed: { | 313 | Keys.onRightPressed: { | ||
314 | var columns = Math.floor(width / cellWidth); | 314 | var columns = Math.floor(width / cellWidth); | ||
315 | 315 | | |||
316 | if (currentCol() !== columns - 1 && currentIndex != count -1) { | 316 | if (itemGrid.currentCol() !== columns - 1 && currentIndex != count -1) { | ||
317 | event.accepted = true; | 317 | event.accepted = true; | ||
318 | moveCurrentIndexRight(); | 318 | moveCurrentIndexRight(); | ||
319 | } else { | 319 | } else { | ||
320 | itemGrid.keyNavRight(); | 320 | itemGrid.keyNavRight(); | ||
321 | } | 321 | } | ||
322 | } | 322 | } | ||
323 | 323 | | |||
324 | Keys.onUpPressed: { | 324 | Keys.onUpPressed: { | ||
325 | if (currentRow() !== 0) { | 325 | if (itemGrid.currentRow() !== 0) { | ||
326 | event.accepted = true; | 326 | event.accepted = true; | ||
327 | moveCurrentIndexUp(); | 327 | moveCurrentIndexUp(); | ||
328 | positionViewAtIndex(currentIndex, GridView.Contain); | 328 | positionViewAtIndex(currentIndex, GridView.Contain); | ||
329 | } else { | 329 | } else { | ||
330 | itemGrid.keyNavUp(); | 330 | itemGrid.keyNavUp(); | ||
331 | } | 331 | } | ||
332 | } | 332 | } | ||
333 | 333 | | |||
334 | Keys.onDownPressed: { | 334 | Keys.onDownPressed: { | ||
335 | if (currentRow() < itemGrid.lastRow()) { | 335 | if (itemGrid.currentRow() < itemGrid.lastRow()) { | ||
336 | // Fix moveCurrentIndexDown()'s lack of proper spatial nav down | 336 | // Fix moveCurrentIndexDown()'s lack of proper spatial nav down | ||
337 | // into partial columns. | 337 | // into partial columns. | ||
338 | event.accepted = true; | 338 | event.accepted = true; | ||
339 | var columns = Math.floor(width / cellWidth); | 339 | var columns = Math.floor(width / cellWidth); | ||
340 | var newIndex = currentIndex + columns; | 340 | var newIndex = currentIndex + columns; | ||
341 | currentIndex = Math.min(newIndex, count - 1); | 341 | currentIndex = Math.min(newIndex, count - 1); | ||
342 | positionViewAtIndex(currentIndex, GridView.Contain); | 342 | positionViewAtIndex(currentIndex, GridView.Contain); | ||
343 | } else { | 343 | } else { | ||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Line(s) | 380 | function updatePositionProperties(x, y) { | |||
392 | var cPos = mapToItem(gridView.contentItem, x, y); | 392 | var cPos = mapToItem(gridView.contentItem, x, y); | ||
393 | var item = gridView.itemAt(cPos.x, cPos.y); | 393 | var item = gridView.itemAt(cPos.x, cPos.y); | ||
394 | 394 | | |||
395 | if (!item) { | 395 | if (!item) { | ||
396 | gridView.currentIndex = -1; | 396 | gridView.currentIndex = -1; | ||
397 | pressedItem = null; | 397 | pressedItem = null; | ||
398 | } else { | 398 | } else { | ||
399 | gridView.currentIndex = item.itemIndex; | 399 | gridView.currentIndex = item.itemIndex; | ||
400 | itemGrid.focus = (currentIndex != -1) | 400 | itemGrid.focus = (itemGrid.currentIndex != -1) | ||
401 | } | 401 | } | ||
402 | 402 | | |||
403 | return item; | 403 | return item; | ||
404 | } | 404 | } | ||
405 | 405 | | |||
406 | onPressed: { | 406 | onPressed: mouse => { | ||
407 | mouse.accepted = true; | 407 | mouse.accepted = true; | ||
408 | 408 | | |||
409 | updatePositionProperties(mouse.x, mouse.y); | 409 | updatePositionProperties(mouse.x, mouse.y); | ||
410 | 410 | | |||
411 | pressX = mouse.x; | 411 | pressX = mouse.x; | ||
412 | pressY = mouse.y; | 412 | pressY = mouse.y; | ||
413 | 413 | | |||
414 | if (mouse.button == Qt.RightButton) { | 414 | if (mouse.button == Qt.RightButton) { | ||
415 | if (gridView.currentItem) { | 415 | if (gridView.currentItem) { | ||
416 | if (gridView.currentItem.hasActionList) { | 416 | if (gridView.currentItem.hasActionList) { | ||
417 | var mapped = mapToItem(gridView.currentItem, mouse.x, mouse.y); | 417 | var mapped = mapToItem(gridView.currentItem, mouse.x, mouse.y); | ||
418 | gridView.currentItem.openActionMenu(mapped.x, mapped.y); | 418 | gridView.currentItem.openActionMenu(mapped.x, mapped.y); | ||
419 | } | 419 | } | ||
420 | } else { | 420 | } else { | ||
421 | var mapped = mapToItem(rootItem, mouse.x, mouse.y); | 421 | var mapped = mapToItem(rootItem, mouse.x, mouse.y); | ||
422 | contextMenu.open(mapped.x, mapped.y); | 422 | contextMenu.open(mapped.x, mapped.y); | ||
423 | } | 423 | } | ||
424 | } else { | 424 | } else { | ||
425 | pressedItem = gridView.currentItem; | 425 | pressedItem = gridView.currentItem; | ||
426 | } | 426 | } | ||
427 | } | 427 | } | ||
428 | 428 | | |||
429 | onReleased: { | 429 | onReleased: mouse => { | ||
430 | mouse.accepted = true; | 430 | mouse.accepted = true; | ||
431 | updatePositionProperties(mouse.x, mouse.y); | 431 | updatePositionProperties(mouse.x, mouse.y); | ||
432 | 432 | | |||
433 | if (gridView.currentItem && gridView.currentItem == pressedItem) { | 433 | if (gridView.currentItem && gridView.currentItem == pressedItem) { | ||
434 | if ("trigger" in gridView.model) { | 434 | if ("trigger" in gridView.model) { | ||
435 | gridView.model.trigger(pressedItem.itemIndex, "", null); | 435 | gridView.model.trigger(pressedItem.itemIndex, "", null); | ||
436 | root.toggle(); | 436 | root.toggle(); | ||
437 | } | 437 | } | ||
438 | 438 | | |||
439 | itemGrid.itemActivated(pressedItem.itemIndex, "", null); | 439 | itemGrid.itemActivated(pressedItem.itemIndex, "", null); | ||
440 | } else if (!dragHelper.dragging && !pressedItem && mouse.button == Qt.LeftButton) { | 440 | } else if (!dragHelper.dragging && !pressedItem && mouse.button == Qt.LeftButton) { | ||
441 | root.toggle(); | 441 | root.toggle(); | ||
442 | } | 442 | } | ||
443 | 443 | | |||
444 | pressX = -1; | 444 | pressX = -1; | ||
445 | pressY = -1; | 445 | pressY = -1; | ||
446 | pressedItem = null; | 446 | pressedItem = null; | ||
447 | } | 447 | } | ||
448 | 448 | | |||
449 | onPositionChanged: { | 449 | onPositionChanged: mouse => { | ||
450 | var item = pressedItem? pressedItem : updatePositionProperties(mouse.x, mouse.y); | 450 | var item = pressedItem? pressedItem : updatePositionProperties(mouse.x, mouse.y); | ||
451 | 451 | | |||
452 | if (gridView.currentIndex != -1) { | 452 | if (gridView.currentIndex != -1) { | ||
453 | if (dragEnabled && pressX != -1 && dragHelper.isDrag(pressX, pressY, mouse.x, mouse.y)) { | 453 | if (itemGrid.dragEnabled && pressX != -1 && dragHelper.isDrag(pressX, pressY, mouse.x, mouse.y)) { | ||
454 | if ("pluginName" in item.m) { | 454 | if ("pluginName" in item.m) { | ||
455 | dragHelper.startDrag(kicker, item.url, item.icon, | 455 | dragHelper.startDrag(kicker, item.url, item.icon, | ||
456 | "text/x-plasmoidservicename", item.m.pluginName); | 456 | "text/x-plasmoidservicename", item.m.pluginName); | ||
457 | } else { | 457 | } else { | ||
458 | dragHelper.startDrag(kicker, item.url, item.icon); | 458 | dragHelper.startDrag(kicker, item.url, item.icon); | ||
459 | } | 459 | } | ||
460 | 460 | | |||
461 | kicker.dragSource = item; | 461 | kicker.dragSource = item; | ||
Show All 9 Lines |