Changeset View
Changeset View
Standalone View
Standalone View
applets/kicker/plugin/draghelper.cpp
Show First 20 Lines • Show All 48 Lines • ▼ Show 20 Line(s) | |||||
49 | } | 49 | } | ||
50 | 50 | | |||
51 | bool DragHelper::isDrag(int oldX, int oldY, int newX, int newY) const | 51 | bool DragHelper::isDrag(int oldX, int oldY, int newX, int newY) const | ||
52 | { | 52 | { | ||
53 | return ((QPoint(oldX, oldY) - QPoint(newX, newY)).manhattanLength() >= QApplication::startDragDistance()); | 53 | return ((QPoint(oldX, oldY) - QPoint(newX, newY)).manhattanLength() >= QApplication::startDragDistance()); | ||
54 | } | 54 | } | ||
55 | 55 | | |||
56 | void DragHelper::startDrag(QQuickItem *item, const QUrl &url, const QIcon &icon, | 56 | void DragHelper::startDrag(QQuickItem *item, const QUrl &url, const QIcon &icon, | ||
57 | const QString &extraMimeType, const QString &extraMimeData) | 57 | const QString &extraMimeType, const QString &extraMimeData, const bool touch) | ||
58 | { | 58 | { | ||
59 | // This allows the caller to return, making sure we don't crash if | 59 | // This allows the caller to return, making sure we don't crash if | ||
60 | // the caller is destroyed mid-drag (as can happen due to a sycoca | 60 | // the caller is destroyed mid-drag (as can happen due to a sycoca | ||
61 | // change). | 61 | // change). | ||
62 | 62 | | |||
63 | QMetaObject::invokeMethod(this, "doDrag", Qt::QueuedConnection, | 63 | QMetaObject::invokeMethod(this, "doDrag", Qt::QueuedConnection, | ||
64 | Q_ARG(QQuickItem*, item), Q_ARG(QUrl, url), Q_ARG(QIcon, icon), | 64 | Q_ARG(QQuickItem*, item), Q_ARG(QUrl, url), Q_ARG(QIcon, icon), | ||
65 | Q_ARG(QString, extraMimeType), Q_ARG(QString, extraMimeData)); | 65 | Q_ARG(QString, extraMimeType), Q_ARG(QString, extraMimeData), Q_ARG(bool, touch)); | ||
66 | } | 66 | } | ||
67 | 67 | | |||
68 | void DragHelper::doDrag(QQuickItem *item, const QUrl &url, const QIcon &icon, | 68 | void DragHelper::doDrag(QQuickItem *item, const QUrl &url, const QIcon &icon, | ||
69 | const QString &extraMimeType, const QString &extraMimeData) const | 69 | const QString &extraMimeType, const QString &extraMimeData, const bool touch) const | ||
70 | { | 70 | { | ||
71 | if (item && item->window() && item->window()->mouseGrabberItem()) { | 71 | if (item && item->window() && item->window()->mouseGrabberItem()) { | ||
72 | item->window()->mouseGrabberItem()->ungrabMouse(); | 72 | item->window()->mouseGrabberItem()->ungrabMouse(); | ||
73 | } | 73 | } | ||
74 | 74 | | |||
75 | QDrag *drag = new QDrag(item); | 75 | QDrag *drag = new QDrag(item); | ||
76 | 76 | | |||
77 | QMimeData *mimeData = new QMimeData(); | 77 | QMimeData *mimeData = new QMimeData(); | ||
78 | 78 | | |||
79 | if (!url.isEmpty()) { | 79 | if (!url.isEmpty()) { | ||
80 | mimeData->setUrls(QList<QUrl>() << url); | 80 | mimeData->setUrls(QList<QUrl>() << url); | ||
81 | } | 81 | } | ||
82 | 82 | | |||
83 | if (!extraMimeType.isEmpty() && !extraMimeData.isEmpty()) { | 83 | if (!extraMimeType.isEmpty() && !extraMimeData.isEmpty()) { | ||
84 | mimeData->setData(extraMimeType, extraMimeData.toLatin1()); | 84 | mimeData->setData(extraMimeType, extraMimeData.toLatin1()); | ||
85 | } | 85 | } | ||
86 | 86 | | |||
87 | drag->setMimeData(mimeData); | 87 | drag->setMimeData(mimeData); | ||
88 | 88 | | |||
89 | if (!icon.isNull()) { | 89 | if (!icon.isNull()) { | ||
90 | drag->setPixmap(icon.pixmap(m_dragIconSize, m_dragIconSize)); | 90 | drag->setPixmap(icon.pixmap(m_dragIconSize, m_dragIconSize)); | ||
91 | if (touch) { | ||||
hein: I'm not happy with hardcoding these values. If we decide to do touch drag this way, we're going… | |||||
92 | drag->setHotSpot(QPoint(m_dragIconSize*0.5,m_dragIconSize*0.95)); | ||||
93 | } | ||||
91 | } | 94 | } | ||
92 | 95 | | |||
93 | drag->exec(); | 96 | drag->exec(); | ||
94 | 97 | | |||
95 | emit dropped(); | 98 | emit dropped(); | ||
96 | } | 99 | } | ||
97 | 100 | |
I'm not happy with hardcoding these values. If we decide to do touch drag this way, we're going to see this being duplicated all around the codebase - with subtly different values, etc. If we want it that way we should centralize it somewhere.
We probably need to put DragHelper to plasma-framework - there's similar classes in FV and TM too we can consolidate. This isn't that much work and I'll gladly help mentoring the patch.