Line | Source | Count |
1 | | - |
2 | | - |
3 | | - |
4 | | - |
5 | | - |
6 | | - |
7 | | - |
8 | | - |
9 | | - |
10 | | - |
11 | | - |
12 | | - |
13 | | - |
14 | | - |
15 | | - |
16 | | - |
17 | | - |
18 | | - |
19 | | - |
20 | | - |
21 | | - |
22 | | - |
23 | | - |
24 | | - |
25 | | - |
26 | | - |
27 | | - |
28 | | - |
29 | | - |
30 | | - |
31 | | - |
32 | | - |
33 | | - |
34 | | - |
35 | | - |
36 | | - |
37 | | - |
38 | | - |
39 | | - |
40 | #include "qplatformdefs.h" | - |
41 | | - |
42 | #include "qbitmap.h" | - |
43 | #include "qdrag.h" | - |
44 | #include "qpixmap.h" | - |
45 | #include "qevent.h" | - |
46 | #include "qfile.h" | - |
47 | #include "qtextcodec.h" | - |
48 | #include "qguiapplication.h" | - |
49 | #include "qpoint.h" | - |
50 | #include "qbuffer.h" | - |
51 | #include "qimage.h" | - |
52 | #include "qpainter.h" | - |
53 | #include "qregexp.h" | - |
54 | #include "qdir.h" | - |
55 | #include "qdnd_p.h" | - |
56 | #include "qimagereader.h" | - |
57 | #include "qimagewriter.h" | - |
58 | #include "qdebug.h" | - |
59 | #include <ctype.h> | - |
60 | #include <qpa/qplatformintegration.h> | - |
61 | #include <qpa/qplatformdrag.h> | - |
62 | | - |
63 | #include <private/qguiapplication_p.h> | - |
64 | | - |
65 | #ifndef QT_NO_DRAGANDDROP | - |
66 | | - |
67 | QT_BEGIN_NAMESPACE | - |
68 | | - |
69 | | - |
70 | QDragManager *QDragManager::m_instance = 0; | - |
71 | | - |
72 | | - |
73 | QDragManager::QDragManager() | - |
74 | : QObject(qApp), m_platformDropData(0), m_currentDropTarget(0), | - |
75 | m_platformDrag(QGuiApplicationPrivate::platformIntegration()->drag()), | - |
76 | m_object(0) | - |
77 | { | - |
78 | Q_ASSERT(!m_instance); | - |
79 | | - |
80 | if (m_platformDrag)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
81 | m_platformDropData = m_platformDrag->platformDropData(); never executed: m_platformDropData = m_platformDrag->platformDropData(); | 0 |
82 | } never executed: end of block | 0 |
83 | | - |
84 | | - |
85 | QDragManager::~QDragManager() | - |
86 | { | - |
87 | m_instance = 0; | - |
88 | } never executed: end of block | 0 |
89 | | - |
90 | QDragManager *QDragManager::self() | - |
91 | { | - |
92 | if (!m_instance && !QGuiApplication::closingDown())TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
93 | m_instance = new QDragManager; never executed: m_instance = new QDragManager; | 0 |
94 | return m_instance; never executed: return m_instance; | 0 |
95 | } | - |
96 | | - |
97 | QObject *QDragManager::source() const | - |
98 | { | - |
99 | if (m_object)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
100 | return m_object->source(); never executed: return m_object->source(); | 0 |
101 | return 0; never executed: return 0; | 0 |
102 | } | - |
103 | | - |
104 | void QDragManager::setCurrentTarget(QObject *target, bool dropped) | - |
105 | { | - |
106 | if (m_currentDropTarget == target)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
107 | return; never executed: return; | 0 |
108 | | - |
109 | m_currentDropTarget = target; | - |
110 | if (!dropped && m_object) {TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
111 | m_object->d_func()->target = target; | - |
112 | emit m_object->targetChanged(target); | - |
113 | } never executed: end of block | 0 |
114 | } never executed: end of block | 0 |
115 | | - |
116 | QObject *QDragManager::currentTarget() const | - |
117 | { | - |
118 | return m_currentDropTarget; never executed: return m_currentDropTarget; | 0 |
119 | } | - |
120 | | - |
121 | Qt::DropAction QDragManager::drag(QDrag *o) | - |
122 | { | - |
123 | if (!o || m_object == o)TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
124 | return Qt::IgnoreAction; never executed: return Qt::IgnoreAction; | 0 |
125 | | - |
126 | if (!m_platformDrag || !o->source()) {TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
127 | o->deleteLater(); | - |
128 | return Qt::IgnoreAction; never executed: return Qt::IgnoreAction; | 0 |
129 | } | - |
130 | | - |
131 | if (m_object) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
132 | qWarning("QDragManager::drag in possibly invalid state"); | - |
133 | return Qt::IgnoreAction; never executed: return Qt::IgnoreAction; | 0 |
134 | } | - |
135 | | - |
136 | m_object = o; | - |
137 | | - |
138 | m_object->d_func()->target = 0; | - |
139 | | - |
140 | QGuiApplicationPrivate::instance()->notifyDragStarted(o); | - |
141 | const Qt::DropAction result = m_platformDrag->drag(m_object); | - |
142 | m_object = 0; | - |
143 | if (!m_platformDrag->ownsDragObject())TRUE | never evaluated | FALSE | never evaluated |
| 0 |
144 | o->deleteLater(); never executed: o->deleteLater(); | 0 |
145 | return result; never executed: return result; | 0 |
146 | } | - |
147 | | - |
148 | #endif // QT_NO_DRAGANDDROP | - |
149 | | - |
150 | #if !(defined(QT_NO_DRAGANDDROP) && defined(QT_NO_CLIPBOARD)) | - |
151 | | - |
152 | static QStringList imageReadMimeFormats() | - |
153 | { | - |
154 | QStringList formats; | - |
155 | QList<QByteArray> imageFormats = QImageReader::supportedImageFormats(); | - |
156 | const int numImageFormats = imageFormats.size(); | - |
157 | formats.reserve(numImageFormats); | - |
158 | for (int i = 0; i < numImageFormats; ++i) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
159 | QString format = QLatin1String("image/"); | - |
160 | format += QString::fromLatin1(imageFormats.at(i).toLower()); | - |
161 | formats.append(format); | - |
162 | } never executed: end of block | 0 |
163 | | - |
164 | | - |
165 | int pngIndex = formats.indexOf(QLatin1String("image/png")); | - |
166 | if (pngIndex != -1 && pngIndex != 0)TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
167 | formats.move(pngIndex, 0); never executed: formats.move(pngIndex, 0); | 0 |
168 | | - |
169 | return formats; never executed: return formats; | 0 |
170 | } | - |
171 | | - |
172 | | - |
173 | static QStringList imageWriteMimeFormats() | - |
174 | { | - |
175 | QStringList formats; | - |
176 | QList<QByteArray> imageFormats = QImageWriter::supportedImageFormats(); | - |
177 | const int numImageFormats = imageFormats.size(); | - |
178 | formats.reserve(numImageFormats); | - |
179 | for (int i = 0; i < numImageFormats; ++i) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
180 | QString format = QLatin1String("image/"); | - |
181 | format += QString::fromLatin1(imageFormats.at(i).toLower()); | - |
182 | formats.append(format); | - |
183 | } never executed: end of block | 0 |
184 | | - |
185 | | - |
186 | int pngIndex = formats.indexOf(QLatin1String("image/png")); | - |
187 | if (pngIndex != -1 && pngIndex != 0)TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
188 | formats.move(pngIndex, 0); never executed: formats.move(pngIndex, 0); | 0 |
189 | | - |
190 | return formats; never executed: return formats; | 0 |
191 | } | - |
192 | | - |
193 | QInternalMimeData::QInternalMimeData() | - |
194 | : QMimeData() | - |
195 | { | - |
196 | } never executed: end of block | 0 |
197 | | - |
198 | QInternalMimeData::~QInternalMimeData() | - |
199 | { | - |
200 | } | - |
201 | | - |
202 | bool QInternalMimeData::hasFormat(const QString &mimeType) const | - |
203 | { | - |
204 | bool foundFormat = hasFormat_sys(mimeType); | - |
205 | if (!foundFormat && mimeType == QLatin1String("application/x-qt-image")) {TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
206 | QStringList imageFormats = imageReadMimeFormats(); | - |
207 | for (int i = 0; i < imageFormats.size(); ++i) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
208 | if ((foundFormat = hasFormat_sys(imageFormats.at(i))))TRUE | never evaluated | FALSE | never evaluated |
| 0 |
209 | break; never executed: break; | 0 |
210 | } never executed: end of block | 0 |
211 | } never executed: end of block | 0 |
212 | return foundFormat; never executed: return foundFormat; | 0 |
213 | } | - |
214 | | - |
215 | QStringList QInternalMimeData::formats() const | - |
216 | { | - |
217 | QStringList realFormats = formats_sys(); | - |
218 | if (!realFormats.contains(QLatin1String("application/x-qt-image"))) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
219 | QStringList imageFormats = imageReadMimeFormats(); | - |
220 | for (int i = 0; i < imageFormats.size(); ++i) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
221 | if (realFormats.contains(imageFormats.at(i))) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
222 | realFormats += QLatin1String("application/x-qt-image"); | - |
223 | break; never executed: break; | 0 |
224 | } | - |
225 | } never executed: end of block | 0 |
226 | } never executed: end of block | 0 |
227 | return realFormats; never executed: return realFormats; | 0 |
228 | } | - |
229 | | - |
230 | QVariant QInternalMimeData::retrieveData(const QString &mimeType, QVariant::Type type) const | - |
231 | { | - |
232 | QVariant data = retrieveData_sys(mimeType, type); | - |
233 | if (mimeType == QLatin1String("application/x-qt-image")) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
234 | if (data.isNull() || (data.type() == QVariant::ByteArray && data.toByteArray().isEmpty())) {TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
235 | | - |
236 | QStringList imageFormats = imageReadMimeFormats(); | - |
237 | for (int i = 0; i < imageFormats.size(); ++i) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
238 | data = retrieveData_sys(imageFormats.at(i), type); | - |
239 | if (data.isNull() || (data.type() == QVariant::ByteArray && data.toByteArray().isEmpty()))TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
240 | continue; never executed: continue; | 0 |
241 | break; never executed: break; | 0 |
242 | } | - |
243 | } never executed: end of block | 0 |
244 | | - |
245 | if (data.type() == QVariant::ByteArrayTRUE | never evaluated | FALSE | never evaluated |
| 0 |
246 | && (type == QVariant::Image || type == QVariant::Pixmap || type == QVariant::Bitmap))TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
247 | data = QImage::fromData(data.toByteArray()); never executed: data = QImage::fromData(data.toByteArray()); | 0 |
248 | | - |
249 | } else if (mimeType == QLatin1String("application/x-color") && data.type() == QVariant::ByteArray) { never executed: end of block TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
250 | QColor c; | - |
251 | QByteArray ba = data.toByteArray(); | - |
252 | if (ba.size() == 8) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
253 | ushort * colBuf = (ushort *)ba.data(); | - |
254 | c.setRgbF(qreal(colBuf[0]) / qreal(0xFFFF), | - |
255 | qreal(colBuf[1]) / qreal(0xFFFF), | - |
256 | qreal(colBuf[2]) / qreal(0xFFFF), | - |
257 | qreal(colBuf[3]) / qreal(0xFFFF)); | - |
258 | data = c; | - |
259 | } else { never executed: end of block | 0 |
260 | qWarning("Qt: Invalid color format"); | - |
261 | } never executed: end of block | 0 |
262 | } else if (data.type() != type && data.type() == QVariant::ByteArray) {TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
263 | | - |
264 | QInternalMimeData *that = const_cast<QInternalMimeData *>(this); | - |
265 | that->setData(mimeType, data.toByteArray()); | - |
266 | data = QMimeData::retrieveData(mimeType, type); | - |
267 | that->clear(); | - |
268 | } never executed: end of block | 0 |
269 | return data; never executed: return data; | 0 |
270 | } | - |
271 | | - |
272 | bool QInternalMimeData::canReadData(const QString &mimeType) | - |
273 | { | - |
274 | return imageReadMimeFormats().contains(mimeType); never executed: return imageReadMimeFormats().contains(mimeType); | 0 |
275 | } | - |
276 | | - |
277 | | - |
278 | QStringList QInternalMimeData::formatsHelper(const QMimeData *data) | - |
279 | { | - |
280 | QStringList realFormats = data->formats(); | - |
281 | if (realFormats.contains(QLatin1String("application/x-qt-image"))) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
282 | | - |
283 | QStringList imageFormats = imageWriteMimeFormats(); | - |
284 | for (int i = 0; i < imageFormats.size(); ++i) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
285 | if (!realFormats.contains(imageFormats.at(i)))TRUE | never evaluated | FALSE | never evaluated |
| 0 |
286 | realFormats.append(imageFormats.at(i)); never executed: realFormats.append(imageFormats.at(i)); | 0 |
287 | } never executed: end of block | 0 |
288 | } never executed: end of block | 0 |
289 | return realFormats; never executed: return realFormats; | 0 |
290 | } | - |
291 | | - |
292 | bool QInternalMimeData::hasFormatHelper(const QString &mimeType, const QMimeData *data) | - |
293 | { | - |
294 | | - |
295 | bool foundFormat = data->hasFormat(mimeType); | - |
296 | if (!foundFormat) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
297 | if (mimeType == QLatin1String("application/x-qt-image")) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
298 | | - |
299 | QStringList imageFormats = imageWriteMimeFormats(); | - |
300 | for (int i = 0; i < imageFormats.size(); ++i) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
301 | if ((foundFormat = data->hasFormat(imageFormats.at(i))))TRUE | never evaluated | FALSE | never evaluated |
| 0 |
302 | break; never executed: break; | 0 |
303 | } never executed: end of block | 0 |
304 | } else if (mimeType.startsWith(QLatin1String("image/"))) { never executed: end of block TRUE | never evaluated | FALSE | never evaluated |
| 0 |
305 | return data->hasImage() && imageWriteMimeFormats().contains(mimeType); never executed: return data->hasImage() && imageWriteMimeFormats().contains(mimeType); | 0 |
306 | } | - |
307 | } never executed: end of block | 0 |
308 | return foundFormat; never executed: return foundFormat; | 0 |
309 | } | - |
310 | | - |
311 | QByteArray QInternalMimeData::renderDataHelper(const QString &mimeType, const QMimeData *data) | - |
312 | { | - |
313 | QByteArray ba; | - |
314 | if (mimeType == QLatin1String("application/x-color")) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
315 | | - |
316 | | - |
317 | | - |
318 | | - |
319 | | - |
320 | | - |
321 | | - |
322 | | - |
323 | | - |
324 | | - |
325 | | - |
326 | ba.resize(8); | - |
327 | ushort * colBuf = (ushort *)ba.data(); | - |
328 | QColor c = qvariant_cast<QColor>(data->colorData()); | - |
329 | colBuf[0] = ushort(c.redF() * 0xFFFF); | - |
330 | colBuf[1] = ushort(c.greenF() * 0xFFFF); | - |
331 | colBuf[2] = ushort(c.blueF() * 0xFFFF); | - |
332 | colBuf[3] = ushort(c.alphaF() * 0xFFFF); | - |
333 | } else { never executed: end of block | 0 |
334 | ba = data->data(mimeType); | - |
335 | if (ba.isEmpty()) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
336 | if (mimeType == QLatin1String("application/x-qt-image") && data->hasImage()) {TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
337 | QImage image = qvariant_cast<QImage>(data->imageData()); | - |
338 | QBuffer buf(&ba); | - |
339 | buf.open(QBuffer::WriteOnly); | - |
340 | | - |
341 | image.save(&buf, "PNG"); | - |
342 | } else if (mimeType.startsWith(QLatin1String("image/")) && data->hasImage()) { never executed: end of block TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
343 | QImage image = qvariant_cast<QImage>(data->imageData()); | - |
344 | QBuffer buf(&ba); | - |
345 | buf.open(QBuffer::WriteOnly); | - |
346 | image.save(&buf, mimeType.mid(mimeType.indexOf(QLatin1Char('/')) + 1).toLatin1().toUpper()); | - |
347 | } never executed: end of block | 0 |
348 | } never executed: end of block | 0 |
349 | } never executed: end of block | 0 |
350 | return ba; never executed: return ba; | 0 |
351 | } | - |
352 | | - |
353 | #endif // QT_NO_DRAGANDDROP && QT_NO_CLIPBOARD | - |
354 | | - |
355 | QT_END_NAMESPACE | - |
| | |