Changeset View
Changeset View
Standalone View
Standalone View
containments/desktop/package/contents/ui/FolderView.qml
Show First 20 Lines • Show All 54 Lines • ▼ Show 20 Line(s) | 32 | FocusScope { | |||
---|---|---|---|---|---|
55 | property alias cellWidth: gridView.cellWidth | 55 | property alias cellWidth: gridView.cellWidth | ||
56 | property alias cellHeight: gridView.cellHeight | 56 | property alias cellHeight: gridView.cellHeight | ||
57 | property alias overflowing: gridView.overflowing | 57 | property alias overflowing: gridView.overflowing | ||
58 | property alias scrollLeft: gridView.scrollLeft | 58 | property alias scrollLeft: gridView.scrollLeft | ||
59 | property alias scrollRight: gridView.scrollRight | 59 | property alias scrollRight: gridView.scrollRight | ||
60 | property alias scrollUp: gridView.scrollUp | 60 | property alias scrollUp: gridView.scrollUp | ||
61 | property alias scrollDown: gridView.scrollDown | 61 | property alias scrollDown: gridView.scrollDown | ||
62 | property alias hoveredItem: gridView.hoveredItem | 62 | property alias hoveredItem: gridView.hoveredItem | ||
63 | property alias mouseListener: listener | ||||
63 | property var history: [] | 64 | property var history: [] | ||
64 | property var lastPosition: null | 65 | property var lastPosition: null | ||
65 | property bool goingBack: false | 66 | property bool goingBack: false | ||
66 | property Item backButton: null | 67 | property Item backButton: null | ||
67 | property var dialog: null | 68 | property var dialog: null | ||
68 | property Item editor: null | 69 | property Item editor: null | ||
69 | 70 | | |||
70 | function positionViewAtBeginning() { | 71 | function positionViewAtBeginning() { | ||
▲ Show 20 Lines • Show All 180 Lines • ▼ Show 20 Line(s) | 251 | onPressXChanged: { | |||
251 | cPress = mapToItem(gridView.contentItem, pressX, pressY); | 252 | cPress = mapToItem(gridView.contentItem, pressX, pressY); | ||
252 | } | 253 | } | ||
253 | 254 | | |||
254 | onPressYChanged: { | 255 | onPressYChanged: { | ||
255 | cPress = mapToItem(gridView.contentItem, pressX, pressY); | 256 | cPress = mapToItem(gridView.contentItem, pressX, pressY); | ||
256 | } | 257 | } | ||
257 | 258 | | |||
258 | onPressed: { | 259 | onPressed: { | ||
259 | // Ignore press events outside the viewport (i.e. on scrollbars). | 260 | console.log("FolderView MouseEventListener::onPressed: hoveredItem=",hoveredItem, " is rootview=",isRootView); | ||
260 | if (!scrollArea.viewport.contains(Qt.point(mouse.x,mouse.y))) { | 261 | if (press (mouse.x, mouse.y, mouse.buttons, mouse.modifiers)) { | ||
261 | return; | | |||
262 | } | | |||
263 | | ||||
264 | scrollArea.focus = true; | | |||
265 | | ||||
266 | if (mouse.buttons & Qt.BackButton) { | | |||
267 | if (root.isPopup && dir.resolvedUrl !== dir.resolve(plasmoid.configuration.url)) { | | |||
268 | doBack(); | | |||
269 | mouse.accepted = true; | | |||
270 | } | | |||
271 | | ||||
272 | return; | | |||
273 | } | | |||
274 | | ||||
275 | if (editor && childAt(mouse.x, mouse.y) !== editor) { | | |||
276 | editor.commit(); | | |||
277 | } | | |||
278 | | ||||
279 | pressX = mouse.x; | | |||
280 | pressY = mouse.y; | | |||
281 | | ||||
282 | if (!hoveredItem || hoveredItem.blank) { | | |||
283 | if (!gridView.ctrlPressed) { | | |||
284 | gridView.currentIndex = -1; | | |||
285 | dir.clearSelection(); | | |||
286 | } | | |||
287 | | ||||
288 | if (mouse.buttons & Qt.RightButton) { | | |||
289 | clearPressState(); | | |||
290 | dir.openContextMenu(null, mouse.modifiers); | | |||
291 | mouse.accepted = true; | | |||
292 | } | | |||
293 | } else { | | |||
294 | pressedItem = hoveredItem; | | |||
295 | | ||||
296 | var pos = mapToItem(hoveredItem.actionsOverlay, mouse.x, mouse.y); | | |||
297 | | ||||
298 | if (!(pos.x <= hoveredItem.actionsOverlay.width && pos.y <= hoveredItem.actionsOverlay.height)) { | | |||
299 | if (gridView.shiftPressed && gridView.currentIndex != -1) { | | |||
300 | positioner.setRangeSelected(gridView.anchorIndex, hoveredItem.index); | | |||
301 | } else { | | |||
302 | // FIXME TODO: Clicking one item with others selected should deselect the others, | | |||
303 | // which doesn't happen right now because initiating a drag after the press should | | |||
304 | // still drag all of them: The deselect needs to happen on release instead so we | | |||
305 | // can distinguish. | | |||
306 | if (!gridView.ctrlPressed && !dir.isSelected(positioner.map(hoveredItem.index))) { | | |||
307 | dir.clearSelection(); | | |||
308 | } | | |||
309 | | ||||
310 | if (gridView.ctrlPressed) { | | |||
311 | dir.toggleSelected(positioner.map(hoveredItem.index)); | | |||
312 | } else { | | |||
313 | dir.setSelected(positioner.map(hoveredItem.index)); | | |||
314 | } | | |||
315 | } | | |||
316 | | ||||
317 | gridView.currentIndex = hoveredItem.index; | | |||
318 | | ||||
319 | if (mouse.buttons & Qt.RightButton) { | | |||
320 | if (pressedItem.toolTip && pressedItem.toolTip.active) { | | |||
321 | pressedItem.toolTip.hideToolTip(); | | |||
322 | } | | |||
323 | | ||||
324 | clearPressState(); | | |||
325 | | ||||
326 | dir.openContextMenu(null, mouse.modifiers); | | |||
327 | mouse.accepted = true; | 262 | mouse.accepted = true; | ||
328 | } | 263 | } | ||
329 | } | | |||
330 | } | | |||
331 | | ||||
332 | main.pressed(); | 264 | main.pressed(); | ||
333 | } | 265 | } | ||
334 | 266 | | |||
335 | onCanceled: pressCanceled() | 267 | onCanceled: pressCanceled() | ||
336 | onReleased: pressCanceled() | 268 | onReleased: pressCanceled() | ||
337 | 269 | | |||
338 | onClicked: { | 270 | onClicked: { | ||
271 | console.log("FolderView MouseEventListener::onClicked: hoveredItem=",hoveredItem," hoveredItem.touchTap=",hoveredItem ? hoveredItem.touchTap : false); | ||||
339 | clearPressState(); | 272 | clearPressState(); | ||
340 | 273 | | |||
341 | if (mouse.button === Qt.RightButton || | 274 | if (mouse.button === Qt.RightButton || | ||
342 | (editor && childAt(mouse.x, mouse.y) === editor)) { | 275 | (editor && childAt(mouse.x, mouse.y) === editor)) { | ||
343 | return; | 276 | return; | ||
344 | } | 277 | } | ||
345 | 278 | | |||
346 | if (!hoveredItem || hoveredItem.blank || gridView.currentIndex == -1 || gridView.ctrlPressed || gridView.shiftPressed) { | 279 | if (!hoveredItem || hoveredItem.blank || gridView.currentIndex == -1 || gridView.ctrlPressed || gridView.shiftPressed) { | ||
347 | // Bug 357367: Replay mouse event, so containment actions assigned to left mouse button work. | 280 | // Bug 357367: Replay mouse event, so containment actions assigned to left mouse button work. | ||
348 | eventGenerator.sendMouseEvent(plasmoid, EventGenerator.MouseButtonPress, mouse.x, mouse.y, mouse.button, mouse.buttons, mouse.modifiers); | 281 | eventGenerator.sendMouseEvent(plasmoid, EventGenerator.MouseButtonPress, mouse.x, mouse.y, mouse.button, mouse.buttons, mouse.modifiers); | ||
349 | return; | 282 | return; | ||
350 | } | 283 | } | ||
351 | 284 | | |||
352 | var pos = mapToItem(hoveredItem, mouse.x, mouse.y); | 285 | //don't handle tap on touchscreen on this point, we call click direct from MouseArea on touch release | ||
353 | 286 | if (!hoveredItem.touchTap) { | |||
354 | // Moving from an item to its preview popup dialog doesn't unset hoveredItem | 287 | click (mouse.x, mouse.y, mouse.button); | ||
355 | // even though the cursor has left it, so we need to check whether the click | | |||
356 | // actually occurred inside the item we expect it in before going ahead. If it | | |||
357 | // didn't, clean up (e.g. dismissing the dialog as a side-effect of unsetting | | |||
358 | // hoveredItem) and abort. | | |||
359 | if (pos.x < 0 || pos.x > hoveredItem.width || pos.y < 0 || pos.y > hoveredItem.height) { | | |||
360 | hoveredItem = null; | | |||
361 | dir.clearSelection(); | | |||
362 | | ||||
363 | return; | | |||
364 | // If the hoveredItem is clicked while having a preview popup dialog open, | | |||
365 | // only dismiss the dialog and abort. | | |||
366 | } else if (hoveredItem.popupDialog) { | | |||
367 | hoveredItem.closePopup(); | | |||
368 | | ||||
369 | return; | | |||
370 | } | | |||
371 | | ||||
372 | pos = mapToItem(hoveredItem.actionsOverlay, mouse.x, mouse.y); | | |||
373 | | ||||
374 | if (!(pos.x <= hoveredItem.actionsOverlay.width && pos.y <= hoveredItem.actionsOverlay.height)) { | | |||
375 | if (Qt.styleHints.singleClickActivation || doubleClickInProgress) { | | |||
376 | var func = root.useListViewMode && (mouse.button === Qt.LeftButton) && hoveredItem.isDir ? doCd : dir.run; | | |||
377 | func(positioner.map(gridView.currentIndex)); | | |||
378 | | ||||
379 | hoveredItem = null; | | |||
380 | } else { | | |||
381 | doubleClickInProgress = true; | | |||
382 | doubleClickTimer.interval = Qt.styleHints.mouseDoubleClickInterval; | | |||
383 | doubleClickTimer.start(); | | |||
384 | } | | |||
385 | } | 288 | } | ||
386 | } | 289 | } | ||
387 | 290 | | |||
388 | onPositionChanged: { | 291 | onPositionChanged: { | ||
389 | gridView.ctrlPressed = (mouse.modifiers & Qt.ControlModifier); | 292 | gridView.ctrlPressed = (mouse.modifiers & Qt.ControlModifier); | ||
390 | gridView.shiftPressed = (mouse.modifiers & Qt.ShiftModifier); | 293 | gridView.shiftPressed = (mouse.modifiers & Qt.ShiftModifier); | ||
391 | 294 | | |||
392 | var cPos = mapToItem(gridView.contentItem, mouse.x, mouse.y); | 295 | var cPos = mapToItem(gridView.contentItem, mouse.x, mouse.y); | ||
▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Line(s) | 322 | if (main.rubberBand) { | |||
442 | rB.width = Math.max(1, rB.width); | 345 | rB.width = Math.max(1, rB.width); | ||
443 | rB.height = Math.max(1, rB.height); | 346 | rB.height = Math.max(1, rB.height); | ||
444 | 347 | | |||
445 | gridView.rectangleSelect(rB.x, rB.y, rB.width, rB.height); | 348 | gridView.rectangleSelect(rB.x, rB.y, rB.width, rB.height); | ||
446 | 349 | | |||
447 | return; | 350 | return; | ||
448 | } | 351 | } | ||
449 | 352 | | |||
353 | //if touch start drag only if touch left item | ||||
354 | if (hoveredItem ? hoveredItem.touchTap : false) { | ||||
355 | console.log ("FolderView MouseEventListener::onPositionChanged hoveredItem.touchTap = true -> return"); | ||||
356 | return; | ||||
357 | } | ||||
358 | | ||||
450 | // Drag initiation. | 359 | // Drag initiation. | ||
451 | if (pressX != -1 && root.isDrag(pressX, pressY, mouse.x, mouse.y)) { | 360 | if (pressX != -1 && root.isDrag(pressX, pressY, mouse.x, mouse.y)) { | ||
452 | if (pressedItem != null && dir.isSelected(positioner.map(pressedItem.index))) { | 361 | if (pressedItem != null && dir.isSelected(positioner.map(pressedItem.index))) { | ||
362 | console.log("FolderView MouseEventListener::onPositionChanged: start Drag Qt.styleHints.startDragDistance=",Qt.styleHints.startDragDistance); | ||||
453 | pressedItem.toolTip.hideToolTip(); | 363 | pressedItem.toolTip.hideToolTip(); | ||
454 | dragX = mouse.x; | 364 | dragX = mouse.x; | ||
455 | dragY = mouse.y; | 365 | dragY = mouse.y; | ||
456 | gridView.verticalDropHitscanOffset = pressedItem.iconArea.y + (pressedItem.iconArea.height / 2) | 366 | gridView.verticalDropHitscanOffset = pressedItem.iconArea.y + (pressedItem.iconArea.height / 2) | ||
457 | dir.dragSelected(mouse.x, mouse.y); | 367 | dir.dragSelected(mouse.x, mouse.y); | ||
458 | dragX = -1; | 368 | dragX = -1; | ||
459 | dragY = -1; | 369 | dragY = -1; | ||
460 | clearPressState(); | 370 | clearPressState(); | ||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Line(s) | |||||
507 | } | 417 | } | ||
508 | 418 | | |||
509 | function clearPressState() { | 419 | function clearPressState() { | ||
510 | pressedItem = null; | 420 | pressedItem = null; | ||
511 | pressX = -1; | 421 | pressX = -1; | ||
512 | pressY = -1; | 422 | pressY = -1; | ||
513 | } | 423 | } | ||
514 | 424 | | |||
425 | function press(mouseX, mouseY, mouseButtons, mouseModifiers) { | ||||
426 | console.log("FolderView MouseEventListener::press() hoveredItem=",hoveredItem); | ||||
427 | var mouseAccepted = false; | ||||
428 | // Ignore press events outside the viewport (i.e. on scrollbars). | ||||
429 | if (!scrollArea.viewport.contains(Qt.point(mouseX,mouseY))) { | ||||
430 | return mouseAccepted; | ||||
431 | } | ||||
432 | | ||||
433 | scrollArea.focus = true; | ||||
434 | | ||||
435 | if (mouseButtons & Qt.BackButton) { | ||||
436 | if (root.isPopup && dir.resolvedUrl !== dir.resolve(plasmoid.configuration.url)) { | ||||
437 | doBack(); | ||||
438 | mouseAccepted = true; | ||||
439 | } | ||||
440 | | ||||
441 | return mouseAccepted; | ||||
442 | } | ||||
443 | | ||||
444 | if (editor && childAt(mouseX, mouseY) !== editor) { | ||||
445 | editor.commit(); | ||||
446 | } | ||||
447 | | ||||
448 | pressX = mouseX; | ||||
449 | pressY = mouseY; | ||||
450 | | ||||
451 | if (!hoveredItem || hoveredItem.blank) { | ||||
452 | if (!gridView.ctrlPressed) { | ||||
453 | gridView.currentIndex = -1; | ||||
454 | dir.clearSelection(); | ||||
455 | } | ||||
456 | | ||||
457 | if (mouseButtons & Qt.RightButton) { | ||||
458 | clearPressState(); | ||||
459 | dir.openContextMenu(null, mouseModifiers); | ||||
460 | mouseAccepted = true; | ||||
461 | } | ||||
462 | } else { | ||||
463 | pressedItem = hoveredItem; | ||||
464 | | ||||
465 | var pos = mapToItem(hoveredItem.actionsOverlay, mouseX, mouseY); | ||||
466 | | ||||
467 | if (!(pos.x <= hoveredItem.actionsOverlay.width && pos.y <= hoveredItem.actionsOverlay.height)) { | ||||
468 | | ||||
469 | if (gridView.shiftPressed && gridView.currentIndex != -1) { | ||||
470 | positioner.setRangeSelected(gridView.anchorIndex, hoveredItem.index); | ||||
471 | } else { | ||||
472 | // FIXME TODO: Clicking one item with others selected should deselect the others, | ||||
473 | // which doesn't happen right now because initiating a drag after the press should | ||||
474 | // still drag all of them: The deselect needs to happen on release instead so we | ||||
475 | // can distinguish. | ||||
476 | if (!gridView.ctrlPressed && !dir.isSelected(positioner.map(hoveredItem.index)) && !hoveredItem.tapAndHold) { | ||||
477 | dir.clearSelection(); | ||||
478 | } | ||||
479 | | ||||
480 | if (gridView.ctrlPressed) { | ||||
481 | dir.toggleSelected(positioner.map(hoveredItem.index)); | ||||
482 | } else { | ||||
483 | dir.setSelected(positioner.map(hoveredItem.index)); | ||||
484 | } | ||||
485 | } | ||||
486 | | ||||
487 | gridView.currentIndex = hoveredItem.index; | ||||
488 | | ||||
489 | if (mouseButtons & Qt.RightButton) { | ||||
490 | if (pressedItem.toolTip && pressedItem.toolTip.active) { | ||||
491 | pressedItem.toolTip.hideToolTip(); | ||||
492 | } | ||||
493 | | ||||
494 | clearPressState(); | ||||
495 | | ||||
496 | dir.openContextMenu(null, mouseModifiers); | ||||
497 | mouseAccepted = true; | ||||
498 | } | ||||
499 | } | ||||
500 | } | ||||
501 | return mouseAccepted; | ||||
502 | } | ||||
503 | | ||||
504 | function click (mouseX, mouseY, mouseButton) { | ||||
505 | console.log("FolderView MouseEventListener::click() hoveredItem=",hoveredItem,"hoveredItem.touchTap=",hoveredItem ? hoveredItem.touchTap : false); | ||||
506 | var pos = mapToItem(hoveredItem, mouseX, mouseY); | ||||
507 | // Moving from an item to its preview popup dialog doesn't unset hoveredItem | ||||
508 | // even though the cursor has left it, so we need to check whether the click | ||||
509 | // actually occured inside the item we expect it in before going ahead. If it | ||||
510 | // didn't, clean up (e.g. dismissing the dialog as a side-effect of unsetting | ||||
511 | // hoveredItem) and abort. | ||||
512 | if (pos.x < 0 || pos.x > hoveredItem.width || pos.y < 0 || pos.y > hoveredItem.height) { | ||||
513 | hoveredItem = null; | ||||
514 | dir.clearSelection(); | ||||
515 | return; | ||||
516 | // If the hoveredItem is clicked while having a preview popup dialog open, | ||||
517 | // only dismiss the dialog and abort. | ||||
518 | } else if (hoveredItem.popupDialog) { | ||||
519 | hoveredItem.closePopup(); | ||||
520 | return; | ||||
521 | } | ||||
522 | | ||||
523 | pos = mapToItem(hoveredItem.actionsOverlay, mouseX, mouseY); | ||||
524 | if (!(pos.x <= hoveredItem.actionsOverlay.width && pos.y <= hoveredItem.actionsOverlay.height)) { | ||||
525 | if (Qt.styleHints.singleClickActivation || doubleClickInProgress || hoveredItem.touchTap) { | ||||
526 | var func = root.useListViewMode && (mouseButton == Qt.LeftButton) && hoveredItem.isDir ? doCd : dir.run; | ||||
527 | func(positioner.map(gridView.currentIndex)); | ||||
528 | hoveredItem = null; | ||||
529 | } else { | ||||
530 | doubleClickInProgress = true; | ||||
531 | doubleClickTimer.interval = Qt.styleHints.mouseDoubleClickInterval; | ||||
532 | doubleClickTimer.start(); | ||||
533 | } | ||||
534 | } | ||||
535 | } | ||||
536 | | ||||
515 | Timer { | 537 | Timer { | ||
516 | id: doubleClickTimer | 538 | id: doubleClickTimer | ||
517 | 539 | | |||
518 | onTriggered: { | 540 | onTriggered: { | ||
519 | listener.doubleClickInProgress = false; | 541 | listener.doubleClickInProgress = false; | ||
520 | } | 542 | } | ||
521 | } | 543 | } | ||
522 | 544 | | |||
▲ Show 20 Lines • Show All 865 Lines • Show Last 20 Lines |