Changeset View
Changeset View
Standalone View
Standalone View
applets/notifications/notificationapplet.cpp
Show All 19 Lines | |||||
20 | */ | 20 | */ | ||
21 | 21 | | |||
22 | #include "notificationapplet.h" | 22 | #include "notificationapplet.h" | ||
23 | 23 | | |||
24 | #include <QClipboard> | 24 | #include <QClipboard> | ||
25 | #include <QDrag> | 25 | #include <QDrag> | ||
26 | #include <QGuiApplication> | 26 | #include <QGuiApplication> | ||
27 | #include <QMimeData> | 27 | #include <QMimeData> | ||
28 | #include <QMimeDatabase> | ||||
29 | #include <QMimeType> | ||||
28 | #include <QQuickItem> | 30 | #include <QQuickItem> | ||
29 | #include <QQuickWindow> | 31 | #include <QQuickWindow> | ||
30 | #include <QScreen> | 32 | #include <QScreen> | ||
31 | #include <QStyleHints> | 33 | #include <QStyleHints> | ||
32 | 34 | | |||
33 | #include <PlasmaQuick/Dialog> | 35 | #include <PlasmaQuick/Dialog> | ||
34 | 36 | | |||
35 | #include "filemenu.h" | 37 | #include "filemenu.h" | ||
Show All 28 Lines | |||||
64 | 66 | | |||
65 | } | 67 | } | ||
66 | 68 | | |||
67 | bool NotificationApplet::dragActive() const | 69 | bool NotificationApplet::dragActive() const | ||
68 | { | 70 | { | ||
69 | return m_dragActive; | 71 | return m_dragActive; | ||
70 | } | 72 | } | ||
71 | 73 | | |||
74 | int NotificationApplet::dragPixmapSize() const | ||||
75 | { | ||||
76 | return m_dragPixmapSize; | ||||
77 | } | ||||
78 | | ||||
79 | void NotificationApplet::setDragPixmapSize(int dragPixmapSize) | ||||
80 | { | ||||
81 | if (m_dragPixmapSize != dragPixmapSize) { | ||||
82 | m_dragPixmapSize = dragPixmapSize; | ||||
83 | emit dragPixmapSizeChanged(); | ||||
84 | } | ||||
85 | } | ||||
86 | | ||||
72 | bool NotificationApplet::isDrag(int oldX, int oldY, int newX, int newY) const | 87 | bool NotificationApplet::isDrag(int oldX, int oldY, int newX, int newY) const | ||
73 | { | 88 | { | ||
74 | return ((QPoint(oldX, oldY) - QPoint(newX, newY)).manhattanLength() >= qApp->styleHints()->startDragDistance()); | 89 | return ((QPoint(oldX, oldY) - QPoint(newX, newY)).manhattanLength() >= qApp->styleHints()->startDragDistance()); | ||
75 | } | 90 | } | ||
76 | 91 | | |||
92 | void NotificationApplet::startDrag(QQuickItem *item, const QUrl &url, const QString &iconName) | ||||
93 | { | ||||
94 | startDrag(item, url, QIcon::fromTheme(iconName).pixmap(m_dragPixmapSize, m_dragPixmapSize)); | ||||
95 | } | ||||
96 | | ||||
77 | void NotificationApplet::startDrag(QQuickItem *item, const QUrl &url, const QPixmap &pixmap) | 97 | void NotificationApplet::startDrag(QQuickItem *item, const QUrl &url, const QPixmap &pixmap) | ||
78 | { | 98 | { | ||
79 | // This allows the caller to return, making sure we don't crash if | 99 | // This allows the caller to return, making sure we don't crash if | ||
80 | // the caller is destroyed mid-drag | 100 | // the caller is destroyed mid-drag | ||
81 | 101 | | |||
82 | QMetaObject::invokeMethod(this, "doDrag", Qt::QueuedConnection, | 102 | QMetaObject::invokeMethod(this, "doDrag", Qt::QueuedConnection, | ||
83 | Q_ARG(QQuickItem*, item), Q_ARG(QUrl, url), Q_ARG(QPixmap, pixmap)); | 103 | Q_ARG(QQuickItem*, item), Q_ARG(QUrl, url), Q_ARG(QPixmap, pixmap)); | ||
84 | } | 104 | } | ||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Line(s) | 148 | { | |||
130 | if (!screen) { | 150 | if (!screen) { | ||
131 | return false; | 151 | return false; | ||
132 | } | 152 | } | ||
133 | 153 | | |||
134 | // HACK | 154 | // HACK | ||
135 | return rect == screen->geometry(); | 155 | return rect == screen->geometry(); | ||
136 | } | 156 | } | ||
137 | 157 | | |||
158 | QString NotificationApplet::iconNameForUrl(const QUrl &url) const | ||||
159 | { | ||||
160 | QMimeType mime = QMimeDatabase().mimeTypeForUrl(url); | ||||
161 | if (mime.isDefault()) { | ||||
162 | return QString(); | ||||
163 | } | ||||
164 | | ||||
165 | return mime.iconName(); | ||||
166 | } | ||||
167 | | ||||
138 | K_EXPORT_PLASMA_APPLET_WITH_JSON(icon, NotificationApplet, "metadata.json") | 168 | K_EXPORT_PLASMA_APPLET_WITH_JSON(icon, NotificationApplet, "metadata.json") | ||
139 | 169 | | |||
140 | #include "notificationapplet.moc" | 170 | #include "notificationapplet.moc" |