| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/gui/kernel/qdnd.cpp | 
| Switch to Source code | Preprocessed file | 
| Line | Source | Count | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||||||||
| 2 | - | |||||||||||||||||||
| 3 | - | |||||||||||||||||||
| 4 | - | |||||||||||||||||||
| 5 | - | |||||||||||||||||||
| 6 | - | |||||||||||||||||||
| 7 | - | |||||||||||||||||||
| 8 | - | |||||||||||||||||||
| 9 | - | |||||||||||||||||||
| 10 | QDragManager *QDragManager::m_instance = 0; | - | ||||||||||||||||||
| 11 | - | |||||||||||||||||||
| 12 | - | |||||||||||||||||||
| 13 | QDragManager::QDragManager() | - | ||||||||||||||||||
| 14 | : QObject((static_cast<QGuiApplication *>(QCoreApplication::instance()))), m_platformDropData(0), m_currentDropTarget(0), | - | ||||||||||||||||||
| 15 | m_platformDrag(QGuiApplicationPrivate::platformIntegration()->drag()), | - | ||||||||||||||||||
| 16 | m_object(0) | - | ||||||||||||||||||
| 17 | { | - | ||||||||||||||||||
| 18 | ((!(!m_instance)) ? qt_assert("!m_instance",__FILE__,72) : qt_noop()); | - | ||||||||||||||||||
| 19 | - | |||||||||||||||||||
| 20 |     if (m_platformDrag
  | 0 | ||||||||||||||||||
| 21 |         m_platformDropData = m_platformDrag->platformDropData(); never executed:  m_platformDropData = m_platformDrag->platformDropData(); | 0 | ||||||||||||||||||
| 22 | } never executed:  end of block | 0 | ||||||||||||||||||
| 23 | - | |||||||||||||||||||
| 24 | - | |||||||||||||||||||
| 25 | QDragManager::~QDragManager() | - | ||||||||||||||||||
| 26 | { | - | ||||||||||||||||||
| 27 | m_instance = 0; | - | ||||||||||||||||||
| 28 | } never executed:  end of block | 0 | ||||||||||||||||||
| 29 | - | |||||||||||||||||||
| 30 | QDragManager *QDragManager::self() | - | ||||||||||||||||||
| 31 | { | - | ||||||||||||||||||
| 32 |     if (!m_instance
 
  | 0 | ||||||||||||||||||
| 33 |         m_instance = new QDragManager; never executed:  m_instance = new QDragManager; | 0 | ||||||||||||||||||
| 34 |     return never executed:   m_instance;return m_instance;never executed:  return m_instance; | 0 | ||||||||||||||||||
| 35 | } | - | ||||||||||||||||||
| 36 | - | |||||||||||||||||||
| 37 | QObject *QDragManager::source() const | - | ||||||||||||||||||
| 38 | { | - | ||||||||||||||||||
| 39 |     if (m_object
  | 0 | ||||||||||||||||||
| 40 |         return never executed:   m_object->source();return m_object->source();never executed:  return m_object->source(); | 0 | ||||||||||||||||||
| 41 |     return never executed:   0;return 0;never executed:  return 0; | 0 | ||||||||||||||||||
| 42 | } | - | ||||||||||||||||||
| 43 | - | |||||||||||||||||||
| 44 | void QDragManager::setCurrentTarget(QObject *target, bool dropped) | - | ||||||||||||||||||
| 45 | { | - | ||||||||||||||||||
| 46 |     if (m_currentDropTarget == target
  | 0 | ||||||||||||||||||
| 47 |         return; never executed:  return; | 0 | ||||||||||||||||||
| 48 | - | |||||||||||||||||||
| 49 | m_currentDropTarget = target; | - | ||||||||||||||||||
| 50 |     if (!dropped
 
  | 0 | ||||||||||||||||||
| 51 | m_object->d_func()->target = target; | - | ||||||||||||||||||
| 52 | m_object->targetChanged(target); | - | ||||||||||||||||||
| 53 |     } never executed:  end of block | 0 | ||||||||||||||||||
| 54 | } never executed:  end of block | 0 | ||||||||||||||||||
| 55 | - | |||||||||||||||||||
| 56 | QObject *QDragManager::currentTarget() const | - | ||||||||||||||||||
| 57 | { | - | ||||||||||||||||||
| 58 |     return never executed:   m_currentDropTarget;return m_currentDropTarget;never executed:  return m_currentDropTarget; | 0 | ||||||||||||||||||
| 59 | } | - | ||||||||||||||||||
| 60 | - | |||||||||||||||||||
| 61 | Qt::DropAction QDragManager::drag(QDrag *o) | - | ||||||||||||||||||
| 62 | { | - | ||||||||||||||||||
| 63 |     if (!o
 
  | 0 | ||||||||||||||||||
| 64 |          return never executed:   Qt::IgnoreAction;return Qt::IgnoreAction;never executed:  return Qt::IgnoreAction; | 0 | ||||||||||||||||||
| 65 | - | |||||||||||||||||||
| 66 |     if (!m_platformDrag
 
  | 0 | ||||||||||||||||||
| 67 | o->deleteLater(); | - | ||||||||||||||||||
| 68 |         return never executed:   Qt::IgnoreAction;return Qt::IgnoreAction;never executed:  return Qt::IgnoreAction; | 0 | ||||||||||||||||||
| 69 | } | - | ||||||||||||||||||
| 70 | - | |||||||||||||||||||
| 71 |     if (m_object
  | 0 | ||||||||||||||||||
| 72 | QMessageLogger(__FILE__, 126, __PRETTY_FUNCTION__).warning("QDragManager::drag in possibly invalid state"); | - | ||||||||||||||||||
| 73 |         return never executed:   Qt::IgnoreAction;return Qt::IgnoreAction;never executed:  return Qt::IgnoreAction; | 0 | ||||||||||||||||||
| 74 | } | - | ||||||||||||||||||
| 75 | - | |||||||||||||||||||
| 76 | m_object = o; | - | ||||||||||||||||||
| 77 | - | |||||||||||||||||||
| 78 | m_object->d_func()->target = 0; | - | ||||||||||||||||||
| 79 | - | |||||||||||||||||||
| 80 | QGuiApplicationPrivate::instance()->notifyDragStarted(o); | - | ||||||||||||||||||
| 81 | const Qt::DropAction result = m_platformDrag->drag(m_object); | - | ||||||||||||||||||
| 82 | m_object = 0; | - | ||||||||||||||||||
| 83 |     if (!m_platformDrag->ownsDragObject()
  | 0 | ||||||||||||||||||
| 84 |         o->deleteLater(); never executed:  o->deleteLater(); | 0 | ||||||||||||||||||
| 85 |     return never executed:   result;return result;never executed:  return result; | 0 | ||||||||||||||||||
| 86 | } | - | ||||||||||||||||||
| 87 | - | |||||||||||||||||||
| 88 | - | |||||||||||||||||||
| 89 | - | |||||||||||||||||||
| 90 | - | |||||||||||||||||||
| 91 | - | |||||||||||||||||||
| 92 | static QStringList imageReadMimeFormats() | - | ||||||||||||||||||
| 93 | { | - | ||||||||||||||||||
| 94 | QStringList formats; | - | ||||||||||||||||||
| 95 | QList<QByteArray> imageFormats = QImageReader::supportedImageFormats(); | - | ||||||||||||||||||
| 96 | const int numImageFormats = imageFormats.size(); | - | ||||||||||||||||||
| 97 | formats.reserve(numImageFormats); | - | ||||||||||||||||||
| 98 |     for (int i = 0; i < numImageFormats
  | 0 | ||||||||||||||||||
| 99 | QString format = QLatin1String("image/"); | - | ||||||||||||||||||
| 100 | format += QString::fromLatin1(imageFormats.at(i).toLower()); | - | ||||||||||||||||||
| 101 | formats.append(format); | - | ||||||||||||||||||
| 102 |     } never executed:  end of block | 0 | ||||||||||||||||||
| 103 | - | |||||||||||||||||||
| 104 | - | |||||||||||||||||||
| 105 | int pngIndex = formats.indexOf(QLatin1String("image/png")); | - | ||||||||||||||||||
| 106 |     if (pngIndex != -1
 
  | 0 | ||||||||||||||||||
| 107 |         formats.move(pngIndex, 0); never executed:  formats.move(pngIndex, 0); | 0 | ||||||||||||||||||
| 108 | - | |||||||||||||||||||
| 109 |     return never executed:   formats;return formats;never executed:  return formats; | 0 | ||||||||||||||||||
| 110 | } | - | ||||||||||||||||||
| 111 | - | |||||||||||||||||||
| 112 | - | |||||||||||||||||||
| 113 | static QStringList imageWriteMimeFormats() | - | ||||||||||||||||||
| 114 | { | - | ||||||||||||||||||
| 115 | QStringList formats; | - | ||||||||||||||||||
| 116 | QList<QByteArray> imageFormats = QImageWriter::supportedImageFormats(); | - | ||||||||||||||||||
| 117 | const int numImageFormats = imageFormats.size(); | - | ||||||||||||||||||
| 118 | formats.reserve(numImageFormats); | - | ||||||||||||||||||
| 119 |     for (int i = 0; i < numImageFormats
  | 0 | ||||||||||||||||||
| 120 | QString format = QLatin1String("image/"); | - | ||||||||||||||||||
| 121 | format += QString::fromLatin1(imageFormats.at(i).toLower()); | - | ||||||||||||||||||
| 122 | formats.append(format); | - | ||||||||||||||||||
| 123 |     } never executed:  end of block | 0 | ||||||||||||||||||
| 124 | - | |||||||||||||||||||
| 125 | - | |||||||||||||||||||
| 126 | int pngIndex = formats.indexOf(QLatin1String("image/png")); | - | ||||||||||||||||||
| 127 |     if (pngIndex != -1
 
  | 0 | ||||||||||||||||||
| 128 |         formats.move(pngIndex, 0); never executed:  formats.move(pngIndex, 0); | 0 | ||||||||||||||||||
| 129 | - | |||||||||||||||||||
| 130 |     return never executed:   formats;return formats;never executed:  return formats; | 0 | ||||||||||||||||||
| 131 | } | - | ||||||||||||||||||
| 132 | - | |||||||||||||||||||
| 133 | QInternalMimeData::QInternalMimeData() | - | ||||||||||||||||||
| 134 | : QMimeData() | - | ||||||||||||||||||
| 135 | { | - | ||||||||||||||||||
| 136 | } never executed:  end of block | 0 | ||||||||||||||||||
| 137 | - | |||||||||||||||||||
| 138 | QInternalMimeData::~QInternalMimeData() | - | ||||||||||||||||||
| 139 | { | - | ||||||||||||||||||
| 140 | } | - | ||||||||||||||||||
| 141 | - | |||||||||||||||||||
| 142 | bool QInternalMimeData::hasFormat(const QString &mimeType) const | - | ||||||||||||||||||
| 143 | { | - | ||||||||||||||||||
| 144 | bool foundFormat = hasFormat_sys(mimeType); | - | ||||||||||||||||||
| 145 |     if (!foundFormat
 
  | 0 | ||||||||||||||||||
| 146 | QStringList imageFormats = imageReadMimeFormats(); | - | ||||||||||||||||||
| 147 |         for (int i = 0; i < imageFormats.size()
  | 0 | ||||||||||||||||||
| 148 |             if ((
 
  | 0 | ||||||||||||||||||
| 149 |                 break; never executed:  break; | 0 | ||||||||||||||||||
| 150 |         } never executed:  end of block | 0 | ||||||||||||||||||
| 151 |     } never executed:  end of block | 0 | ||||||||||||||||||
| 152 |     return never executed:   foundFormat;return foundFormat;never executed:  return foundFormat; | 0 | ||||||||||||||||||
| 153 | } | - | ||||||||||||||||||
| 154 | - | |||||||||||||||||||
| 155 | QStringList QInternalMimeData::formats() const | - | ||||||||||||||||||
| 156 | { | - | ||||||||||||||||||
| 157 | QStringList realFormats = formats_sys(); | - | ||||||||||||||||||
| 158 |     if (!realFormats.contains(QLatin1String("application/x-qt-image"))
  | 0 | ||||||||||||||||||
| 159 | QStringList imageFormats = imageReadMimeFormats(); | - | ||||||||||||||||||
| 160 |         for (int i = 0; i < imageFormats.size()
  | 0 | ||||||||||||||||||
| 161 |             if (realFormats.contains(imageFormats.at(i))
  | 0 | ||||||||||||||||||
| 162 | realFormats += QLatin1String("application/x-qt-image"); | - | ||||||||||||||||||
| 163 |                 break; never executed:  break; | 0 | ||||||||||||||||||
| 164 | } | - | ||||||||||||||||||
| 165 |         } never executed:  end of block | 0 | ||||||||||||||||||
| 166 |     } never executed:  end of block | 0 | ||||||||||||||||||
| 167 |     return never executed:   realFormats;return realFormats;never executed:  return realFormats; | 0 | ||||||||||||||||||
| 168 | } | - | ||||||||||||||||||
| 169 | - | |||||||||||||||||||
| 170 | QVariant QInternalMimeData::retrieveData(const QString &mimeType, QVariant::Type type) const | - | ||||||||||||||||||
| 171 | { | - | ||||||||||||||||||
| 172 | QVariant data = retrieveData_sys(mimeType, type); | - | ||||||||||||||||||
| 173 |     if (mimeType == QLatin1String("application/x-qt-image")
  | 0 | ||||||||||||||||||
| 174 |         if (data.isNull()
 
 
  | 0 | ||||||||||||||||||
| 175 | - | |||||||||||||||||||
| 176 | QStringList imageFormats = imageReadMimeFormats(); | - | ||||||||||||||||||
| 177 |             for (int i = 0; i < imageFormats.size()
  | 0 | ||||||||||||||||||
| 178 | data = retrieveData_sys(imageFormats.at(i), type); | - | ||||||||||||||||||
| 179 |                 if (data.isNull()
 
 
  | 0 | ||||||||||||||||||
| 180 |                     continue; never executed:  continue; | 0 | ||||||||||||||||||
| 181 |                 break; never executed:  break; | 0 | ||||||||||||||||||
| 182 | } | - | ||||||||||||||||||
| 183 |         } never executed:  end of block | 0 | ||||||||||||||||||
| 184 | - | |||||||||||||||||||
| 185 |         if (data.type() == QVariant::ByteArray
  | 0 | ||||||||||||||||||
| 186 |             && (type == QVariant::Image
 
 
  | 0 | ||||||||||||||||||
| 187 |             data = QImage::fromData(data.toByteArray()); never executed:  data = QImage::fromData(data.toByteArray()); | 0 | ||||||||||||||||||
| 188 | - | |||||||||||||||||||
| 189 |     } never executed:   else if (mimeType == QLatin1String("application/x-color")end of block
 
  | 0 | ||||||||||||||||||
| 190 | QColor c; | - | ||||||||||||||||||
| 191 | QByteArray ba = data.toByteArray(); | - | ||||||||||||||||||
| 192 |         if (ba.size() == 8
  | 0 | ||||||||||||||||||
| 193 | ushort * colBuf = (ushort *)ba.data(); | - | ||||||||||||||||||
| 194 | c.setRgbF(qreal(colBuf[0]) / qreal(0xFFFF), | - | ||||||||||||||||||
| 195 | qreal(colBuf[1]) / qreal(0xFFFF), | - | ||||||||||||||||||
| 196 | qreal(colBuf[2]) / qreal(0xFFFF), | - | ||||||||||||||||||
| 197 | qreal(colBuf[3]) / qreal(0xFFFF)); | - | ||||||||||||||||||
| 198 | data = c; | - | ||||||||||||||||||
| 199 |         } never executed:   else {end of block | 0 | ||||||||||||||||||
| 200 | QMessageLogger(__FILE__, 254, __PRETTY_FUNCTION__).warning("Qt: Invalid color format"); | - | ||||||||||||||||||
| 201 |         } never executed:  end of block | 0 | ||||||||||||||||||
| 202 |     } else if (data.type() != type
 
  | 0 | ||||||||||||||||||
| 203 | - | |||||||||||||||||||
| 204 | QInternalMimeData *that = const_cast<QInternalMimeData *>(this); | - | ||||||||||||||||||
| 205 | that->setData(mimeType, data.toByteArray()); | - | ||||||||||||||||||
| 206 | data = QMimeData::retrieveData(mimeType, type); | - | ||||||||||||||||||
| 207 | that->clear(); | - | ||||||||||||||||||
| 208 |     } never executed:  end of block | 0 | ||||||||||||||||||
| 209 |     return never executed:   data;return data;never executed:  return data; | 0 | ||||||||||||||||||
| 210 | } | - | ||||||||||||||||||
| 211 | - | |||||||||||||||||||
| 212 | bool QInternalMimeData::canReadData(const QString &mimeType) | - | ||||||||||||||||||
| 213 | { | - | ||||||||||||||||||
| 214 |     return never executed:   imageReadMimeFormats().contains(mimeType);return imageReadMimeFormats().contains(mimeType);never executed:  return imageReadMimeFormats().contains(mimeType); | 0 | ||||||||||||||||||
| 215 | } | - | ||||||||||||||||||
| 216 | - | |||||||||||||||||||
| 217 | - | |||||||||||||||||||
| 218 | QStringList QInternalMimeData::formatsHelper(const QMimeData *data) | - | ||||||||||||||||||
| 219 | { | - | ||||||||||||||||||
| 220 | QStringList realFormats = data->formats(); | - | ||||||||||||||||||
| 221 |     if (realFormats.contains(QLatin1String("application/x-qt-image"))
  | 0 | ||||||||||||||||||
| 222 | - | |||||||||||||||||||
| 223 | QStringList imageFormats = imageWriteMimeFormats(); | - | ||||||||||||||||||
| 224 |         for (int i = 0; i < imageFormats.size()
  | 0 | ||||||||||||||||||
| 225 |             if (!realFormats.contains(imageFormats.at(i))
  | 0 | ||||||||||||||||||
| 226 |                 realFormats.append(imageFormats.at(i)); never executed:  realFormats.append(imageFormats.at(i)); | 0 | ||||||||||||||||||
| 227 |         } never executed:  end of block | 0 | ||||||||||||||||||
| 228 |     } never executed:  end of block | 0 | ||||||||||||||||||
| 229 |     return never executed:   realFormats;return realFormats;never executed:  return realFormats; | 0 | ||||||||||||||||||
| 230 | } | - | ||||||||||||||||||
| 231 | - | |||||||||||||||||||
| 232 | bool QInternalMimeData::hasFormatHelper(const QString &mimeType, const QMimeData *data) | - | ||||||||||||||||||
| 233 | { | - | ||||||||||||||||||
| 234 | - | |||||||||||||||||||
| 235 | bool foundFormat = data->hasFormat(mimeType); | - | ||||||||||||||||||
| 236 |     if (!foundFormat
  | 0 | ||||||||||||||||||
| 237 |         if (mimeType == QLatin1String("application/x-qt-image")
  | 0 | ||||||||||||||||||
| 238 | - | |||||||||||||||||||
| 239 | QStringList imageFormats = imageWriteMimeFormats(); | - | ||||||||||||||||||
| 240 |             for (int i = 0; i < imageFormats.size()
  | 0 | ||||||||||||||||||
| 241 |                 if ((
 
  | 0 | ||||||||||||||||||
| 242 |                     break; never executed:  break; | 0 | ||||||||||||||||||
| 243 |             } never executed:  end of block | 0 | ||||||||||||||||||
| 244 |         } never executed:   else if (mimeType.startsWith(QLatin1String("image/"))end of block
  | 0 | ||||||||||||||||||
| 245 |             return never executed:   data->hasImage()return data->hasImage() && imageWriteMimeFormats().contains(mimeType);
 
 never executed:  return data->hasImage() && imageWriteMimeFormats().contains(mimeType); | 0 | ||||||||||||||||||
| 246 | } | - | ||||||||||||||||||
| 247 |     } never executed:  end of block | 0 | ||||||||||||||||||
| 248 |     return never executed:   foundFormat;return foundFormat;never executed:  return foundFormat; | 0 | ||||||||||||||||||
| 249 | } | - | ||||||||||||||||||
| 250 | - | |||||||||||||||||||
| 251 | QByteArray QInternalMimeData::renderDataHelper(const QString &mimeType, const QMimeData *data) | - | ||||||||||||||||||
| 252 | { | - | ||||||||||||||||||
| 253 | QByteArray ba; | - | ||||||||||||||||||
| 254 |     if (mimeType == QLatin1String("application/x-color")
  | 0 | ||||||||||||||||||
| 255 | ba.resize(8); | - | ||||||||||||||||||
| 256 | ushort * colBuf = (ushort *)ba.data(); | - | ||||||||||||||||||
| 257 | QColor c = qvariant_cast<QColor>(data->colorData()); | - | ||||||||||||||||||
| 258 | colBuf[0] = ushort(c.redF() * 0xFFFF); | - | ||||||||||||||||||
| 259 | colBuf[1] = ushort(c.greenF() * 0xFFFF); | - | ||||||||||||||||||
| 260 | colBuf[2] = ushort(c.blueF() * 0xFFFF); | - | ||||||||||||||||||
| 261 | colBuf[3] = ushort(c.alphaF() * 0xFFFF); | - | ||||||||||||||||||
| 262 |     } never executed:   else {end of block | 0 | ||||||||||||||||||
| 263 | ba = data->data(mimeType); | - | ||||||||||||||||||
| 264 |         if (ba.isEmpty()
  | 0 | ||||||||||||||||||
| 265 |             if (mimeType == QLatin1String("application/x-qt-image")
 
  | 0 | ||||||||||||||||||
| 266 | QImage image = qvariant_cast<QImage>(data->imageData()); | - | ||||||||||||||||||
| 267 | QBuffer buf(&ba); | - | ||||||||||||||||||
| 268 | buf.open(QBuffer::WriteOnly); | - | ||||||||||||||||||
| 269 | - | |||||||||||||||||||
| 270 | image.save(&buf, "PNG"); | - | ||||||||||||||||||
| 271 |             } never executed:   else if (mimeType.startsWith(QLatin1String("image/"))end of block
 
  | 0 | ||||||||||||||||||
| 272 | QImage image = qvariant_cast<QImage>(data->imageData()); | - | ||||||||||||||||||
| 273 | QBuffer buf(&ba); | - | ||||||||||||||||||
| 274 | buf.open(QBuffer::WriteOnly); | - | ||||||||||||||||||
| 275 | image.save(&buf, mimeType.mid(mimeType.indexOf(QLatin1Char('/')) + 1).toLatin1().toUpper()); | - | ||||||||||||||||||
| 276 |             } never executed:  end of block | 0 | ||||||||||||||||||
| 277 |         } never executed:  end of block | 0 | ||||||||||||||||||
| 278 |     } never executed:  end of block | 0 | ||||||||||||||||||
| 279 |     return never executed:   ba;return ba;never executed:  return ba; | 0 | ||||||||||||||||||
| 280 | } | - | ||||||||||||||||||
| 281 | - | |||||||||||||||||||
| 282 | - | |||||||||||||||||||
| 283 | - | |||||||||||||||||||
| 284 | - | |||||||||||||||||||
| Switch to Source code | Preprocessed file |