Merge lp:~ahayzen/ubuntu-ui-extras/tabs-add-dnd into lp:~phablet-team/ubuntu-ui-extras/tabs

Proposed by Andrew Hayzen
Status: Merged
Merged at revision: 122
Proposed branch: lp:~ahayzen/ubuntu-ui-extras/tabs-add-dnd
Merge into: lp:~phablet-team/ubuntu-ui-extras/tabs
Diff against target: 672 lines (+490/-7)
8 files modified
modules/Ubuntu/Components/Extras/TabsBar.qml (+147/-4)
modules/Ubuntu/Components/Extras/TabsBar/DragAndDropSettings.qml (+32/-0)
modules/Ubuntu/Components/Extras/TabsBar/Tab.qml (+1/-0)
modules/Ubuntu/Components/Extras/plugin/CMakeLists.txt (+5/-1)
modules/Ubuntu/Components/Extras/plugin/components.cpp (+6/-1)
modules/Ubuntu/Components/Extras/plugin/components.h (+1/-1)
modules/Ubuntu/Components/Extras/plugin/tabsbar/drag-helper.cpp (+205/-0)
modules/Ubuntu/Components/Extras/plugin/tabsbar/drag-helper.h (+93/-0)
To merge this branch: bzr merge lp:~ahayzen/ubuntu-ui-extras/tabs-add-dnd
Reviewer Review Type Date Requested Status
Florian Boucault Pending
Review via email: mp+314003@code.launchpad.net

Commit message

* Add drag and drop support to tabs component

Description of the change

* Add drag and drop support to tabs component

To post a comment you must log in.
Revision history for this message
Andrew Hayzen (ahayzen) wrote :

I wonder if it should be
visible: !Window.active || dimmed
or
visible: !Window.active || (dimmed && !dropArea.containsDrag)

For the Rectangle dimming the TabBar

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'modules/Ubuntu/Components/Extras/TabsBar.qml'
--- modules/Ubuntu/Components/Extras/TabsBar.qml 2016-12-08 14:26:41 +0000
+++ modules/Ubuntu/Components/Extras/TabsBar.qml 2017-01-06 16:37:25 +0000
@@ -1,5 +1,5 @@
1/*1/*
2 * Copyright (C) 2016 Canonical Ltd2 * Copyright (C) 2016, 2017 Canonical Ltd
3 *3 *
4 * This program is free software: you can redistribute it and/or modify4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 as5 * it under the terms of the GNU General Public License version 3 as
@@ -22,6 +22,8 @@
22import Ubuntu.Components 1.322import Ubuntu.Components 1.3
23import "TabsBar" as LocalTabs23import "TabsBar" as LocalTabs
2424
25import Ubuntu.Components.Extras 0.3
26
25Rectangle {27Rectangle {
26 id: tabsBar28 id: tabsBar
2729
@@ -35,15 +37,40 @@
35 property color highlightColor: Qt.rgba(actionColor.r, actionColor.g, actionColor.b, 0.1)37 property color highlightColor: Qt.rgba(actionColor.r, actionColor.g, actionColor.b, 0.1)
36 /* 'model' needs to have the following members:38 /* 'model' needs to have the following members:
37 property int selectedIndex39 property int selectedIndex
40 function addExistingTab(var tab)
38 function selectTab(int index)41 function selectTab(int index)
39 function removeTab(int index)42 function removeTab(int index)
43 function removeTabWithoutDestroying(int index)
40 function moveTab(int from, int to)44 function moveTab(int from, int to)
45
46 removeTabWithoutDestroying is useful when a tab is being removed due
47 to moving, so you don't want the content to be destroyed
41 */48 */
42 property var model49 property var model
43 property list<Action> actions50 property list<Action> actions
51 property bool dimmed: false
52
53 /* To enable drag and drop set to enabled
54 *
55 * Use expose to set any information you need the DropArea to access
56 * Then use drag.source.expose.myproperty
57 *
58 * Set mimeType to one of the keys in the DropArea's you want to accept
59 *
60 * Set a function for previewUrlFromIndex which is given the index
61 * and returns a url to an image, which will be shown in the handle
62 */
63 readonly property alias dragAndDrop: dragAndDropImpl
64
65 LocalTabs.DragAndDropSettings {
66 id: dragAndDropImpl
67 }
4468
45 property string fallbackIcon: ""69 property string fallbackIcon: ""
4670
71 property Component windowFactory: null
72 property var windowFactoryProperties: ({}) // any addition properties such as height, width
73
47 signal contextMenu(var tabDelegate, int index)74 signal contextMenu(var tabDelegate, int index)
4875
49 function iconNameFromModelItem(modelItem, index) {76 function iconNameFromModelItem(modelItem, index) {
@@ -106,6 +133,7 @@
106 right: tabs.overflow ? rightStepper.left : actions.left133 right: tabs.overflow ? rightStepper.left : actions.left
107 }134 }
108 interactive: false135 interactive: false
136 objectName: "tabListView"
109 orientation: ListView.Horizontal137 orientation: ListView.Horizontal
110 clip: true138 clip: true
111 highlightMoveDuration: UbuntuAnimation.FastDuration139 highlightMoveDuration: UbuntuAnimation.FastDuration
@@ -139,16 +167,21 @@
139 model: tabsBar.model167 model: tabsBar.model
140 delegate: MouseArea {168 delegate: MouseArea {
141 id: tabMouseArea169 id: tabMouseArea
170 objectName: "tabDelegate"
142171
172 acceptedButtons: Qt.LeftButton | Qt.RightButton | Qt.MiddleButton
143 width: tab.width173 width: tab.width
144 height: tab.height174 height: tab.height
145 drag {175 drag {
146 target: tabs.count > 1 && tab.isFocused ? tab : null176 target: (tabs.count > 1 || dragAndDrop.enabled) && tab.isFocused ? tab : null
147 axis: Drag.XAxis177 axis: dragAndDrop.enabled ? Drag.XAndYAxis : Drag.XAxis
148 minimumX: tab.isDragged ? -tab.width/2 : -Infinity178 minimumX: tab.isDragged ? -tab.width/2 : -Infinity
149 maximumX: tab.isDragged ? tabs.width - tab.width/2 : Infinity179 maximumX: tab.isDragged ? tabs.width - tab.width/2 : Infinity
150 }180 }
151 z: tab.isFocused ? 1 : 0181 z: tab.isFocused ? 1 : 0
182
183 readonly property int tabIndex: index // for autopilot
184
152 Binding {185 Binding {
153 target: tabsBar186 target: tabsBar
154 property: "selectedTabX"187 property: "selectedTabX"
@@ -161,6 +194,13 @@
161 value: tab.width194 value: tab.width
162 when: tab.isFocused195 when: tab.isFocused
163 }196 }
197 NumberAnimation {
198 id: resetVerticalAnimation
199 target: tab
200 duration: 250
201 property: "y"
202 to: 0
203 }
164204
165 onPressed: {205 onPressed: {
166 if (mouse.button === Qt.LeftButton) {206 if (mouse.button === Qt.LeftButton) {
@@ -171,6 +211,7 @@
171 tabsBar.model.removeTab(index)211 tabsBar.model.removeTab(index)
172 }212 }
173 }213 }
214 onReleased: resetVerticalAnimation.start()
174 onWheel: {215 onWheel: {
175 if (wheel.angleDelta.y >= 0) {216 if (wheel.angleDelta.y >= 0) {
176 tabsBar.model.selectTab(tabsBar.model.selectedIndex - 1);217 tabsBar.model.selectTab(tabsBar.model.selectedIndex - 1);
@@ -183,12 +224,17 @@
183224
184 LocalTabs.Tab {225 LocalTabs.Tab {
185 id: tab226 id: tab
227 objectName: "tabItem"
186228
187 anchors.left: tabMouseArea.left229 anchors.left: tabMouseArea.left
188 implicitWidth: tabs.availableWidth / 2230 implicitWidth: tabs.availableWidth / 2
189 width: tabs.overflow ? tabs.availableWidth / tabs.maximumTabsCount : Math.min(tabs.maximumTabWidth, implicitWidth)231 width: tabs.overflow ? tabs.availableWidth / tabs.maximumTabsCount : Math.min(tabs.maximumTabWidth, implicitWidth)
190 height: tabs.height232 height: tabs.height
191233
234 // Reference the tab and window so that the dropArea can determine what to do
235 readonly property var thisTab: tabsBar.model.get(index)
236 readonly property var thisWindow: dragAndDrop.thisWindow
237
192 property bool isDragged: tabMouseArea.drag.active238 property bool isDragged: tabMouseArea.drag.active
193 Drag.active: tab.isDragged239 Drag.active: tab.isDragged
194 Drag.source: tabMouseArea240 Drag.source: tabMouseArea
@@ -243,6 +289,67 @@
243 }289 }
244 }290 }
245 }291 }
292
293 DragHelper {
294 id: dragHelper
295 expectedAction: dragAndDrop.expectedAction
296 mimeType: dragAndDrop.mimeType
297 previewBorderWidth: dragAndDrop.previewBorderWidth
298 previewSize: dragAndDrop.previewSize
299 previewTopCrop: dragAndDrop.previewTopCrop
300 previewUrl: dragAndDrop.previewUrlFromIndex(index)
301 source: tab
302 }
303
304 onPositionChanged: {
305 if (!dragAndDrop.enabled || !tabMouseArea.drag.active) {
306 return;
307 }
308
309 // Keep the visual tab within maxYDiff of starting point when
310 // dragging vertically so that it doesn't cover other elements
311 // or appear to be detached
312 tab.y = Math.abs(tab.y) > dragAndDrop.maxYDiff ? (tab.y > 0 ? 1 : -1) * dragAndDrop.maxYDiff : tab.y
313
314 // Initiate drag and drop if mouse y has gone further than the height from the object
315 if (mouse.y > height * 2 || mouse.y < -height) {
316 // Reset visual position of tab delegate
317 resetVerticalAnimation.start();
318
319 var dropAction = dragHelper.execDrag(index);
320
321 // IgnoreAction - no DropArea accepted so New Window
322 // MoveAction - DropArea accept but different window
323 // CopyAction - DropArea accept but same window
324
325 if (dropAction === Qt.MoveAction) {
326 // Moved into another window
327
328 // Just remove from model and do not destroy
329 // as webview is used in other window
330 tabsBar.model.removeTabWithoutDestroying(index);
331 } else if (dropAction === Qt.CopyAction) {
332 // Moved into the same window
333
334 // So no action
335 } else if (dropAction === Qt.IgnoreAction) {
336 // Moved outside of any window
337
338 // Create new window and add existing tab
339 var window = windowFactory.createObject(null, windowFactoryProperties);
340 window.model.addExistingTab(tab.thisTab);
341 window.model.selectTab(window.model.count - 1);
342 window.show();
343
344 // Just remove from model and do not destroy
345 // as webview is used in other window
346 tabsBar.model.removeTabWithoutDestroying(index);
347 } else {
348 // Unknown state
349 console.debug("Unknown drop action:", dropAction);
350 }
351 }
352 }
246 }353 }
247 }354 }
248355
@@ -290,6 +397,7 @@
290 model: tabsBar.actions397 model: tabsBar.actions
291398
292 LocalTabs.TabButton {399 LocalTabs.TabButton {
400 objectName: modelData.objectName
293 iconColor: tabsBar.actionColor401 iconColor: tabsBar.actionColor
294 iconSource: modelData.iconSource402 iconSource: modelData.iconSource
295 onClicked: modelData.trigger()403 onClicked: modelData.trigger()
@@ -303,6 +411,41 @@
303 anchors.fill: parent411 anchors.fill: parent
304 color: backgroundColor412 color: backgroundColor
305 opacity: 0.4413 opacity: 0.4
306 visible: !Window.active414 visible: !Window.active || (dimmed && !dropArea.containsDrag)
415 }
416
417 DropArea {
418 id: dropArea
419 anchors {
420 fill: parent
421 }
422 keys: [dragAndDrop.mimeType]
423
424 onDropped: {
425 // IgnoreAction - no DropArea accepted so New Window
426 // MoveAction - DropArea accept but different window
427 // CopyAction - DropArea accept but same window
428 if (drag.source.thisWindow === dragAndDrop.thisWindow) {
429 // Dropped in same window
430 drop.accept(Qt.CopyAction);
431 } else {
432 // Dropped in new window, moving tab
433 tabsBar.model.addExistingTab(drag.source.thisTab);
434 tabsBar.model.selectTab(tabsBar.model.count - 1);
435
436 drop.accept(Qt.MoveAction);
437 }
438 }
439 onEntered: {
440 thisWindow.raise()
441 thisWindow.requestActivate();
442 }
443 onPositionChanged: {
444 if (drag.source.thisWindow === dragAndDrop.thisWindow) {
445 // tab drag is within same window and in chrome
446 // so reorder tabs by setting tab x position
447 drag.source.x = drag.x - (drag.source.width / 2);
448 }
449 }
307 }450 }
308}451}
309452
=== added file 'modules/Ubuntu/Components/Extras/TabsBar/DragAndDropSettings.qml'
--- modules/Ubuntu/Components/Extras/TabsBar/DragAndDropSettings.qml 1970-01-01 00:00:00 +0000
+++ modules/Ubuntu/Components/Extras/TabsBar/DragAndDropSettings.qml 2017-01-06 16:37:25 +0000
@@ -0,0 +1,32 @@
1/*
2 * Copyright (C) 2016 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored-by: Andrew Hayzen <andrew.hayzen@canonical.com>
17 */
18import QtQuick 2.4
19
20QtObject {
21 property bool enabled: false
22 property var expectedAction: Qt.IgnoreAction | Qt.CopyAction | Qt.MoveAction
23 property int maxYDiff: parent.height / 16
24 property string mimeType: "x-tabsbar/tab"
25 property real previewBorderWidth: units.gu(1)
26 property var previewSize: Qt.size(units.gu(35), units.gu(22.5))
27 property real previewTopCrop: 0
28 property var previewUrlFromIndex: function(index) {
29 return "";
30 }
31 property var thisWindow: null // Qt 5.7 retrieve from attached property
32}
033
=== modified file 'modules/Ubuntu/Components/Extras/TabsBar/Tab.qml'
--- modules/Ubuntu/Components/Extras/TabsBar/Tab.qml 2016-12-08 14:26:41 +0000
+++ modules/Ubuntu/Components/Extras/TabsBar/Tab.qml 2017-01-06 16:37:25 +0000
@@ -78,6 +78,7 @@
7878
79 MouseArea {79 MouseArea {
80 id: tabCloseButton80 id: tabCloseButton
81 objectName: "tabCloseButton"
8182
82 anchors {83 anchors {
83 top: parent.top84 top: parent.top
8485
=== modified file 'modules/Ubuntu/Components/Extras/plugin/CMakeLists.txt'
--- modules/Ubuntu/Components/Extras/plugin/CMakeLists.txt 2016-07-06 08:26:51 +0000
+++ modules/Ubuntu/Components/Extras/plugin/CMakeLists.txt 2017-01-06 16:37:25 +0000
@@ -19,12 +19,16 @@
19 photoeditor/photo-edit-thread.cpp19 photoeditor/photo-edit-thread.cpp
20 )20 )
2121
22set(TABS_BAR_PLUGIN_SRC
23 tabsbar/drag-helper.cpp
24)
25
22include_directories(26include_directories(
23 ${CMAKE_BINARY_DIR}27 ${CMAKE_BINARY_DIR}
24)28)
2529
26add_library(ubuntu-ui-extras-plugin SHARED ${PLUGIN_SRC} ${PLUGIN_HDRS}30add_library(ubuntu-ui-extras-plugin SHARED ${PLUGIN_SRC} ${PLUGIN_HDRS}
27 ${EXAMPLE_PLUGIN_SRC} ${PHOTO_EDITOR_PLUGIN_SRC})31 ${EXAMPLE_PLUGIN_SRC} ${PHOTO_EDITOR_PLUGIN_SRC} ${TABS_BAR_PLUGIN_SRC})
28qt5_use_modules(ubuntu-ui-extras-plugin Core Qml Quick Xml Widgets)32qt5_use_modules(ubuntu-ui-extras-plugin Core Qml Quick Xml Widgets)
29target_link_libraries(ubuntu-ui-extras-plugin33target_link_libraries(ubuntu-ui-extras-plugin
30 ${EXIV2_LIBRARIES}34 ${EXIV2_LIBRARIES}
3135
=== modified file 'modules/Ubuntu/Components/Extras/plugin/components.cpp'
--- modules/Ubuntu/Components/Extras/plugin/components.cpp 2015-04-29 15:48:07 +0000
+++ modules/Ubuntu/Components/Extras/plugin/components.cpp 2017-01-06 16:37:25 +0000
@@ -1,5 +1,5 @@
1/*1/*
2 * Copyright (C) 2012-2013 Canonical, Ltd.2 * Copyright (C) 2012-2013, 2016 Canonical, Ltd.
3 *3 *
4 * This program is free software; you can redistribute it and/or modify4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by5 * it under the terms of the GNU General Public License as published by
@@ -23,6 +23,8 @@
23#include "photoeditor/photo-image-provider.h"23#include "photoeditor/photo-image-provider.h"
24#include "photoeditor/file-utils.h"24#include "photoeditor/file-utils.h"
2525
26#include "tabsbar/drag-helper.h"
27
26void Components::registerTypes(const char *uri)28void Components::registerTypes(const char *uri)
27{29{
28 // Example component30 // Example component
@@ -32,6 +34,9 @@
32 qmlRegisterType<PhotoData>(uri, 0, 2, "PhotoData");34 qmlRegisterType<PhotoData>(uri, 0, 2, "PhotoData");
33 qmlRegisterSingletonType<FileUtils>(uri, 0, 2, "FileUtils",35 qmlRegisterSingletonType<FileUtils>(uri, 0, 2, "FileUtils",
34 exportFileUtilsSingleton);36 exportFileUtilsSingleton);
37
38 // TabsBar component
39 qmlRegisterType<DragHelper>(uri, 0, 3, "DragHelper");
35}40}
3641
37void Components::initializeEngine(QQmlEngine *engine, const char *uri)42void Components::initializeEngine(QQmlEngine *engine, const char *uri)
3843
=== modified file 'modules/Ubuntu/Components/Extras/plugin/components.h'
--- modules/Ubuntu/Components/Extras/plugin/components.h 2014-11-19 10:14:20 +0000
+++ modules/Ubuntu/Components/Extras/plugin/components.h 2017-01-06 16:37:25 +0000
@@ -1,5 +1,5 @@
1/*1/*
2 * Copyright (C) 2012-2013 Canonical, Ltd.2 * Copyright (C) 2012-2013, 2016 Canonical, Ltd.
3 *3 *
4 * This program is free software; you can redistribute it and/or modify4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by5 * it under the terms of the GNU General Public License as published by
66
=== added directory 'modules/Ubuntu/Components/Extras/plugin/tabsbar'
=== added file 'modules/Ubuntu/Components/Extras/plugin/tabsbar/drag-helper.cpp'
--- modules/Ubuntu/Components/Extras/plugin/tabsbar/drag-helper.cpp 1970-01-01 00:00:00 +0000
+++ modules/Ubuntu/Components/Extras/plugin/tabsbar/drag-helper.cpp 2017-01-06 16:37:25 +0000
@@ -0,0 +1,205 @@
1/*
2 * Copyright 2016 Canonical Ltd.
3 *
4 * This file is part of webbrowser-app.
5 *
6 * webbrowser-app is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * webbrowser-app is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * Authored-by: Andrew Hayzen <andrew.hayzen@canonical.com>
19 */
20
21#include "drag-helper.h"
22
23#include <QtCore/QMimeData>
24#include <QtCore/QPoint>
25#include <QtCore/QSize>
26#include <QtCore/QString>
27#include <QtGui/QDrag>
28#include <QtGui/QDropEvent>
29#include <QtGui/QPainter>
30#include <QtGui/QPen>
31#include <QtGui/QPixmap>
32#include <QtQuick/QQuickItem>
33
34DragHelper::DragHelper()
35 : QObject(),
36 m_active(false),
37 m_dragging(false),
38 m_expected_action(Qt::IgnoreAction),
39 m_mime_type(QStringLiteral("x-tabsbar/tab")),
40 m_preview_border_width(8),
41 m_preview_size(QSizeF(200, 150)),
42 m_preview_top_crop(0),
43 m_preview_url(""),
44 m_source(Q_NULLPTR)
45{
46
47}
48
49QPixmap DragHelper::drawPixmapWithBorder(QPixmap pixmap, int borderWidth, QColor color)
50{
51 // Create a transparent pixmap to draw to
52 QPixmap output(pixmap.width() + borderWidth * 2, pixmap.height() + borderWidth * 2);
53 output.fill(QColor(0, 0, 0, 0));
54
55 // Draw the pixmap with space around the edge for a border
56 QPainter borderPainter(&output);
57 borderPainter.setRenderHint(QPainter::Antialiasing);
58 borderPainter.drawPixmap(borderWidth, borderWidth, pixmap);
59
60 // Define a pen to use for the border
61 QPen borderPen;
62 borderPen.setColor(color);
63 borderPen.setJoinStyle(Qt::MiterJoin);
64 borderPen.setStyle(Qt::SolidLine);
65 borderPen.setWidth(borderWidth);
66
67 // Set the pen and draw the border
68 borderPainter.setPen(borderPen);
69 borderPainter.drawRect(borderWidth / 2, borderWidth / 2,
70 output.width() - borderWidth, output.height() - borderWidth);
71
72 return output;
73}
74
75Qt::DropAction DragHelper::execDrag(QString tabId)
76{
77 QDrag *drag = new QDrag(m_source);
78
79 // Create a mimedata object to use for the drag
80 QMimeData *mimeData = new QMimeData;
81 mimeData->setData(mimeType(), tabId.toLatin1());
82
83 // Get a bordered pixmap of the previewUrl
84 QSize size = previewSize().toSize();
85
86 QPixmap pixmap = drawPixmapWithBorder(getPreviewUrlAsPixmap(size.width(), size.height()),
87 previewBorderWidth(), QColor(205, 205, 205, 255 * 0.6)); // #cdcdcd
88
89 // Setup the drag and then execute it
90 drag->setHotSpot(QPoint(size.width() * 0.1, size.height() * 0.1));
91 drag->setMimeData(mimeData);
92 drag->setPixmap(pixmap);
93
94 setDragging(true);
95
96 Qt::DropAction action = drag->exec(expectedAction());
97
98 setDragging(false);
99
100 return action;
101}
102
103QPixmap DragHelper::getPreviewUrlAsPixmap(int width, int height)
104{
105 QSize pixmapSize(width, height);
106 QPixmap pixmap(previewUrl());
107
108 if (pixmap.isNull()) {
109 // If loading pixmap failed, draw a white rectangle
110 pixmap = QPixmap(pixmapSize);
111 QPainter painter(&pixmap);
112 painter.eraseRect(0, 0, pixmapSize.width(), pixmapSize.height());
113 painter.fillRect(0, 0, pixmapSize.width(), pixmapSize.height(), QColor(255, 255, 255, 255));
114 } else {
115 // Crop transparent part off the top of the image
116 pixmap = pixmap.copy(0, previewTopCrop(), pixmap.width(), pixmap.height() - previewTopCrop());
117
118 // Scale image to fit the expected size
119 pixmap = pixmap.scaled(pixmapSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
120 }
121
122 return pixmap;
123}
124
125void DragHelper::setActive(bool active)
126{
127 if (m_active != active) {
128 m_active = active;
129
130 Q_EMIT activeChanged();
131 }
132}
133
134void DragHelper::setDragging(bool dragging)
135{
136 if (m_dragging != dragging) {
137 m_dragging = dragging;
138
139 Q_EMIT draggingChanged();
140 }
141}
142
143void DragHelper::setExpectedAction(Qt::DropAction expectedAction)
144{
145 if (m_expected_action != expectedAction) {
146 m_expected_action = expectedAction;
147
148 Q_EMIT expectedActionChanged();
149 }
150}
151
152void DragHelper::setMimeType(QString mimeType)
153{
154 if (m_mime_type != mimeType) {
155 m_mime_type = mimeType;
156
157 Q_EMIT mimeTypeChanged();
158 }
159}
160
161void DragHelper::setPreviewBorderWidth(int previewBorderWidth)
162{
163 if (m_preview_border_width != previewBorderWidth) {
164 m_preview_border_width = previewBorderWidth;
165
166 Q_EMIT previewBorderWidthChanged();
167 }
168}
169
170void DragHelper::setPreviewSize(QSizeF previewSize)
171{
172 if (m_preview_size != previewSize) {
173 m_preview_size = previewSize;
174
175 Q_EMIT previewSizeChanged();
176 }
177}
178
179void DragHelper::setPreviewTopCrop(int previewTopCrop)
180{
181 if (m_preview_top_crop != previewTopCrop) {
182 m_preview_top_crop = previewTopCrop;
183
184 Q_EMIT previewTopCropChanged();
185 }
186}
187
188void DragHelper::setPreviewUrl(QString previewUrl)
189{
190 if (m_preview_url != previewUrl) {
191 m_preview_url = previewUrl;
192
193 Q_EMIT previewUrlChanged();
194 }
195}
196
197void DragHelper::setSource(QQuickItem *source)
198{
199 if (m_source != source) {
200 m_source = source;
201
202 Q_EMIT sourceChanged();
203 }
204}
205
0206
=== added file 'modules/Ubuntu/Components/Extras/plugin/tabsbar/drag-helper.h'
--- modules/Ubuntu/Components/Extras/plugin/tabsbar/drag-helper.h 1970-01-01 00:00:00 +0000
+++ modules/Ubuntu/Components/Extras/plugin/tabsbar/drag-helper.h 2017-01-06 16:37:25 +0000
@@ -0,0 +1,93 @@
1/*
2 * Copyright 2016 Canonical Ltd.
3 *
4 * This file is part of webbrowser-app.
5 *
6 * webbrowser-app is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * webbrowser-app is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * Authored-by: Andrew Hayzen <andrew.hayzen@canonical.com>
19 */
20
21#ifndef __DRAGHELPER_H__
22#define __DRAGHELPER_H__
23
24#include <QtCore/QSizeF>
25#include <QtCore/QObject>
26#include <QtCore/QString>
27#include <QtGui/QColor>
28#include <QtGui/QMouseEvent>
29
30class QQuickItem;
31
32class DragHelper : public QObject
33{
34 Q_OBJECT
35
36 Q_PROPERTY(bool active READ active WRITE setActive NOTIFY activeChanged)
37 Q_PROPERTY(bool dragging READ dragging NOTIFY draggingChanged)
38 Q_PROPERTY(Qt::DropAction expectedAction READ expectedAction WRITE setExpectedAction NOTIFY expectedActionChanged)
39 Q_PROPERTY(QString mimeType READ mimeType WRITE setMimeType NOTIFY mimeTypeChanged)
40 Q_PROPERTY(int previewBorderWidth READ previewBorderWidth WRITE setPreviewBorderWidth NOTIFY previewBorderWidthChanged)
41 Q_PROPERTY(QSizeF previewSize READ previewSize WRITE setPreviewSize NOTIFY previewSizeChanged)
42 Q_PROPERTY(int previewTopCrop READ previewTopCrop WRITE setPreviewTopCrop NOTIFY previewTopCropChanged)
43 Q_PROPERTY(QString previewUrl READ previewUrl WRITE setPreviewUrl NOTIFY previewUrlChanged)
44 Q_PROPERTY(QQuickItem* source READ source WRITE setSource NOTIFY sourceChanged)
45public:
46 DragHelper();
47 bool active() { return m_active; }
48 bool dragging() { return m_dragging; }
49 Qt::DropAction expectedAction() { return m_expected_action; }
50 QString mimeType() { return m_mime_type; }
51 int previewBorderWidth() { return m_preview_border_width; }
52 QSizeF previewSize() { return m_preview_size; }
53 int previewTopCrop() { return m_preview_top_crop; }
54 QString previewUrl() { return m_preview_url; }
55 QQuickItem *source() { return m_source; }
56Q_SIGNALS:
57 void activeChanged();
58 void draggingChanged();
59 void expectedActionChanged();
60 void mimeTypeChanged();
61 void previewBorderWidthChanged();
62 void previewSizeChanged();
63 void previewTopCropChanged();
64 void previewUrlChanged();
65 void sourceChanged();
66public Q_SLOTS:
67 Q_INVOKABLE Qt::DropAction execDrag(QString tabId);
68 void setActive(bool active);
69 void setExpectedAction(Qt::DropAction expectedAction);
70 void setMimeType(QString mimeType);
71 void setPreviewBorderWidth(int previewBorderWidth);
72 void setPreviewSize(QSizeF previewSize);
73 void setPreviewTopCrop(int previewTopCrop);
74 void setPreviewUrl(QString previewUrl);
75 void setSource(QQuickItem *source);
76private:
77 QPixmap drawPixmapWithBorder(QPixmap pixmap, int borderWidth, QColor color);
78 QPixmap getPreviewUrlAsPixmap(int width, int height);
79 void setDragging(bool dragging);
80
81 bool m_active;
82 bool m_dragging;
83 Qt::DropAction m_expected_action;
84 QString m_mime_type;
85 int m_preview_border_width;
86 QSizeF m_preview_size;
87 int m_preview_top_crop;
88 QString m_preview_url;
89 QQuickItem *m_source;
90};
91
92#endif // __DRAGHELPER_H__
93

Subscribers

People subscribed via source and target branches