Changeset View
Changeset View
Standalone View
Standalone View
applets/notifications/package/contents/ui/ThumbnailStrip.qml
Show All 23 Lines | |||||
24 | import org.kde.plasma.core 2.0 as PlasmaCore | 24 | import org.kde.plasma.core 2.0 as PlasmaCore | ||
25 | import org.kde.plasma.components 2.0 as PlasmaComponents | 25 | import org.kde.plasma.components 2.0 as PlasmaComponents | ||
26 | import org.kde.plasma.extras 2.0 as PlasmaExtras | 26 | import org.kde.plasma.extras 2.0 as PlasmaExtras | ||
27 | 27 | | |||
28 | import org.kde.kquickcontrolsaddons 2.0 as KQCAddons | 28 | import org.kde.kquickcontrolsaddons 2.0 as KQCAddons | ||
29 | 29 | | |||
30 | import org.kde.plasma.private.notifications 2.0 as Notifications | 30 | import org.kde.plasma.private.notifications 2.0 as Notifications | ||
31 | 31 | | |||
32 | MouseArea { | 32 | DraggableFileArea { | ||
33 | id: thumbnailArea | 33 | id: thumbnailArea | ||
34 | 34 | | |||
35 | // The protocol supports multiple URLs but so far it's only used to show | 35 | // The protocol supports multiple URLs but so far it's only used to show | ||
36 | // a single preview image, so this code is simplified a lot to accommodate | 36 | // a single preview image, so this code is simplified a lot to accommodate | ||
37 | // this usecase and drops everything else (fallback to app icon or ListView | 37 | // this usecase and drops everything else (fallback to app icon or ListView | ||
38 | // for multiple files) | 38 | // for multiple files) | ||
39 | property var urls | 39 | property var urls | ||
40 | 40 | | |||
41 | readonly property bool dragging: plasmoid.nativeInterface.dragActive | | |||
42 | readonly property alias menuOpen: fileMenu.visible | 41 | readonly property alias menuOpen: fileMenu.visible | ||
43 | 42 | | |||
44 | property int _pressX: -1 | 43 | property int _pressX: -1 | ||
45 | property int _pressY: -1 | 44 | property int _pressY: -1 | ||
46 | 45 | | |||
47 | property int leftPadding: 0 | 46 | property int leftPadding: 0 | ||
48 | property int rightPadding: 0 | 47 | property int rightPadding: 0 | ||
49 | property int topPadding: 0 | 48 | property int topPadding: 0 | ||
50 | property int bottomPadding: 0 | 49 | property int bottomPadding: 0 | ||
51 | 50 | | |||
52 | signal openUrl(string url) | 51 | signal openUrl(string url) | ||
53 | signal fileActionInvoked | 52 | signal fileActionInvoked | ||
54 | 53 | | |||
54 | dragParent: previewPixmap | ||||
55 | dragUrl: thumbnailer.url | ||||
56 | dragPixmap: thumbnailer.pixmap | ||||
57 | | ||||
55 | implicitHeight: Math.max(menuButton.height + 2 * menuButton.anchors.topMargin, | 58 | implicitHeight: Math.max(menuButton.height + 2 * menuButton.anchors.topMargin, | ||
56 | Math.round(Math.min(width / 3, width / thumbnailer.ratio))) | 59 | Math.round(Math.min(width / 3, width / thumbnailer.ratio))) | ||
57 | + topPadding + bottomPadding | 60 | + topPadding + bottomPadding | ||
58 | 61 | | |||
59 | preventStealing: true | 62 | onActivated: thumbnailArea.openUrl(thumbnailer.url) | ||
60 | cursorShape: pressed ? Qt.ClosedHandCursor : Qt.OpenHandCursor | 63 | onContextMenuRequested: { | ||
61 | acceptedButtons: Qt.LeftButton | Qt.RightButton | | |||
62 | | ||||
63 | onClicked: { | | |||
64 | if (mouse.button === Qt.LeftButton) { | | |||
65 | thumbnailArea.openUrl(thumbnailer.url) | | |||
66 | } | | |||
67 | } | | |||
68 | | ||||
69 | onPressed: { | | |||
70 | if (mouse.button === Qt.LeftButton) { | | |||
71 | _pressX = mouse.x; | | |||
72 | _pressY = mouse.y; | | |||
73 | } else if (mouse.button === Qt.RightButton) { | | |||
74 | // avoid menu button glowing if we didn't actually press it | 64 | // avoid menu button glowing if we didn't actually press it | ||
75 | menuButton.checked = false; | 65 | menuButton.checked = false; | ||
76 | 66 | | |||
77 | fileMenu.visualParent = this; | 67 | fileMenu.visualParent = this; | ||
78 | fileMenu.open(mouse.x, mouse.y); | 68 | fileMenu.open(x, y); | ||
79 | } | | |||
80 | } | | |||
81 | onPositionChanged: { | | |||
82 | if (_pressX !== -1 && _pressY !== -1 && plasmoid.nativeInterface.isDrag(_pressX, _pressY, mouse.x, mouse.y)) { | | |||
83 | plasmoid.nativeInterface.startDrag(previewPixmap, thumbnailer.url, thumbnailer.pixmap); | | |||
84 | _pressX = -1; | | |||
85 | _pressY = -1; | | |||
86 | } | | |||
87 | } | | |||
88 | onReleased: { | | |||
89 | _pressX = -1; | | |||
90 | _pressY = -1; | | |||
91 | } | | |||
92 | onContainsMouseChanged: { | | |||
93 | if (!containsMouse) { | | |||
94 | _pressX = -1; | | |||
95 | _pressY = -1; | | |||
96 | } | | |||
97 | } | 69 | } | ||
98 | 70 | | |||
99 | Notifications.FileMenu { | 71 | Notifications.FileMenu { | ||
100 | id: fileMenu | 72 | id: fileMenu | ||
101 | url: thumbnailer.url | 73 | url: thumbnailer.url | ||
102 | visualParent: menuButton | 74 | visualParent: menuButton | ||
103 | onActionTriggered: thumbnailArea.fileActionInvoked() | 75 | onActionTriggered: thumbnailArea.fileActionInvoked() | ||
104 | } | 76 | } | ||
▲ Show 20 Lines • Show All 83 Lines • Show Last 20 Lines |