diff --git a/applets/notifications/package/contents/ui/DraggableFileArea.qml b/applets/notifications/package/contents/ui/DraggableFileArea.qml new file mode 100644 --- /dev/null +++ b/applets/notifications/package/contents/ui/DraggableFileArea.qml @@ -0,0 +1,71 @@ +/* + * Copyright 2016,2019 Kai Uwe Broulik + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Library General Public License for more details + * + * You should have received a copy of the GNU Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +import QtQuick 2.8 + +MouseArea { + id: area + + signal activated + signal contextMenuRequested(int x, int y) + + property Item dragParent + property url dragUrl + property var dragPixmap + + readonly property bool dragging: plasmoid.nativeInterface.dragActive + + property int _pressX: -1 + property int _pressY: -1 + + preventStealing: true + cursorShape: pressed ? Qt.ClosedHandCursor : Qt.OpenHandCursor + acceptedButtons: Qt.LeftButton | Qt.RightButton + + onClicked: { + if (mouse.button === Qt.LeftButton) { + area.activated(); + } + } + onPressed: { + if (mouse.button === Qt.LeftButton) { + _pressX = mouse.x; + _pressY = mouse.y; + } else if (mouse.button === Qt.RightButton) { + area.contextMenuRequested(mouse.x, mouse.y); + } + } + onPositionChanged: { + if (_pressX !== -1 && _pressY !== -1 && plasmoid.nativeInterface.isDrag(_pressX, _pressY, mouse.x, mouse.y)) { + plasmoid.nativeInterface.startDrag(area.dragParent, area.dragUrl, area.dragPixmap); + _pressX = -1; + _pressY = -1; + } + } + onReleased: { + _pressX = -1; + _pressY = -1; + } + onContainsMouseChanged: { + if (!containsMouse) { + _pressX = -1; + _pressY = -1; + } + } +} diff --git a/applets/notifications/package/contents/ui/ThumbnailStrip.qml b/applets/notifications/package/contents/ui/ThumbnailStrip.qml --- a/applets/notifications/package/contents/ui/ThumbnailStrip.qml +++ b/applets/notifications/package/contents/ui/ThumbnailStrip.qml @@ -29,16 +29,15 @@ import org.kde.plasma.private.notifications 2.0 as Notifications -MouseArea { +DraggableFileArea { id: thumbnailArea // The protocol supports multiple URLs but so far it's only used to show // a single preview image, so this code is simplified a lot to accommodate // this usecase and drops everything else (fallback to app icon or ListView // for multiple files) property var urls - readonly property bool dragging: plasmoid.nativeInterface.dragActive readonly property alias menuOpen: fileMenu.visible property int _pressX: -1 @@ -52,48 +51,21 @@ signal openUrl(string url) signal fileActionInvoked + dragParent: previewPixmap + dragUrl: thumbnailer.url + dragPixmap: thumbnailer.pixmap + implicitHeight: Math.max(menuButton.height + 2 * menuButton.anchors.topMargin, Math.round(Math.min(width / 3, width / thumbnailer.ratio))) + topPadding + bottomPadding - preventStealing: true - cursorShape: pressed ? Qt.ClosedHandCursor : Qt.OpenHandCursor - acceptedButtons: Qt.LeftButton | Qt.RightButton - - onClicked: { - if (mouse.button === Qt.LeftButton) { - thumbnailArea.openUrl(thumbnailer.url) - } - } - - onPressed: { - if (mouse.button === Qt.LeftButton) { - _pressX = mouse.x; - _pressY = mouse.y; - } else if (mouse.button === Qt.RightButton) { - // avoid menu button glowing if we didn't actually press it - menuButton.checked = false; + onActivated: thumbnailArea.openUrl(thumbnailer.url) + onContextMenuRequested: { + // avoid menu button glowing if we didn't actually press it + menuButton.checked = false; - fileMenu.visualParent = this; - fileMenu.open(mouse.x, mouse.y); - } - } - onPositionChanged: { - if (_pressX !== -1 && _pressY !== -1 && plasmoid.nativeInterface.isDrag(_pressX, _pressY, mouse.x, mouse.y)) { - plasmoid.nativeInterface.startDrag(previewPixmap, thumbnailer.url, thumbnailer.pixmap); - _pressX = -1; - _pressY = -1; - } - } - onReleased: { - _pressX = -1; - _pressY = -1; - } - onContainsMouseChanged: { - if (!containsMouse) { - _pressX = -1; - _pressY = -1; - } + fileMenu.visualParent = this; + fileMenu.open(x, y); } Notifications.FileMenu {