Commit d1d9a2c7 authored by Kai Uwe Broulik's avatar Kai Uwe Broulik 🍇
Browse files

[Notifications] Split draggable thumbnail area into its own component

I'm planning to use it in job notifications, too.
This should also make it easier to migrate away from a custom drag implementation to using Qt's if we were to do that.

Differential Revision: https://phabricator.kde.org/D25751
parent 4bdbd44f
/*
* Copyright 2016,2019 Kai Uwe Broulik <kde@privat.broulik.de>
*
* 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;
}
}
}
......@@ -29,7 +29,7 @@ import org.kde.kquickcontrolsaddons 2.0 as KQCAddons
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
......@@ -38,7 +38,6 @@ MouseArea {
// 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 @@ MouseArea {
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 {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment