| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/gui/kernel/qclipboard.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||
|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||
| 2 | ** | - | ||||||
| 3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||
| 4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||
| 5 | ** | - | ||||||
| 6 | ** This file is part of the QtGui module of the Qt Toolkit. | - | ||||||
| 7 | ** | - | ||||||
| 8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||
| 9 | ** Commercial License Usage | - | ||||||
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||
| 11 | ** accordance with the commercial license agreement provided with the | - | ||||||
| 12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||
| 14 | ** and conditions see http://www.qt.io/terms-conditions. For further | - | ||||||
| 15 | ** information use the contact form at http://www.qt.io/contact-us. | - | ||||||
| 16 | ** | - | ||||||
| 17 | ** GNU Lesser General Public License Usage | - | ||||||
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||
| 19 | ** General Public License version 2.1 or version 3 as published by the Free | - | ||||||
| 20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||
| 21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||
| 22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||
| 23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||
| 24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||
| 25 | ** | - | ||||||
| 26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||
| 27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||
| 28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||
| 29 | ** | - | ||||||
| 30 | ** $QT_END_LICENSE$ | - | ||||||
| 31 | ** | - | ||||||
| 32 | ****************************************************************************/ | - | ||||||
| 33 | - | |||||||
| 34 | #include "qclipboard.h" | - | ||||||
| 35 | - | |||||||
| 36 | #ifndef QT_NO_CLIPBOARD | - | ||||||
| 37 | - | |||||||
| 38 | #include "qmimedata.h" | - | ||||||
| 39 | #include "qpixmap.h" | - | ||||||
| 40 | #include "qvariant.h" | - | ||||||
| 41 | #include "qbuffer.h" | - | ||||||
| 42 | #include "qimage.h" | - | ||||||
| 43 | #include "qtextcodec.h" | - | ||||||
| 44 | - | |||||||
| 45 | #include "private/qguiapplication_p.h" | - | ||||||
| 46 | #include <qpa/qplatformintegration.h> | - | ||||||
| 47 | #include <qpa/qplatformclipboard.h> | - | ||||||
| 48 | - | |||||||
| 49 | QT_BEGIN_NAMESPACE | - | ||||||
| 50 | - | |||||||
| 51 | /*! | - | ||||||
| 52 | \class QClipboard | - | ||||||
| 53 | \brief The QClipboard class provides access to the window system clipboard. | - | ||||||
| 54 | \inmodule QtGui | - | ||||||
| 55 | - | |||||||
| 56 | The clipboard offers a simple mechanism to copy and paste data | - | ||||||
| 57 | between applications. | - | ||||||
| 58 | - | |||||||
| 59 | QClipboard supports the same data types that QDrag does, and uses | - | ||||||
| 60 | similar mechanisms. For advanced clipboard usage read \l{Drag and | - | ||||||
| 61 | Drop}. | - | ||||||
| 62 | - | |||||||
| 63 | There is a single QClipboard object in an application, accessible | - | ||||||
| 64 | as QGuiApplication::clipboard(). | - | ||||||
| 65 | - | |||||||
| 66 | Example: | - | ||||||
| 67 | \snippet code/src_gui_kernel_qclipboard.cpp 0 | - | ||||||
| 68 | - | |||||||
| 69 | QClipboard features some convenience functions to access common | - | ||||||
| 70 | data types: setText() allows the exchange of Unicode text and | - | ||||||
| 71 | setPixmap() and setImage() allows the exchange of QPixmaps and | - | ||||||
| 72 | QImages between applications. The setMimeData() function is the | - | ||||||
| 73 | ultimate in flexibility: it allows you to add any QMimeData into | - | ||||||
| 74 | the clipboard. There are corresponding getters for each of these, | - | ||||||
| 75 | e.g. text(), image() and pixmap(). You can clear the clipboard by | - | ||||||
| 76 | calling clear(). | - | ||||||
| 77 | - | |||||||
| 78 | A typical example of the use of these functions follows: | - | ||||||
| 79 | - | |||||||
| 80 | \snippet droparea.cpp 0 | - | ||||||
| 81 | - | |||||||
| 82 | \section1 Notes for X11 Users | - | ||||||
| 83 | - | |||||||
| 84 | \list | - | ||||||
| 85 | - | |||||||
| 86 | \li The X11 Window System has the concept of a separate selection | - | ||||||
| 87 | and clipboard. When text is selected, it is immediately available | - | ||||||
| 88 | as the global mouse selection. The global mouse selection may | - | ||||||
| 89 | later be copied to the clipboard. By convention, the middle mouse | - | ||||||
| 90 | button is used to paste the global mouse selection. | - | ||||||
| 91 | - | |||||||
| 92 | \li X11 also has the concept of ownership; if you change the | - | ||||||
| 93 | selection within a window, X11 will only notify the owner and the | - | ||||||
| 94 | previous owner of the change, i.e. it will not notify all | - | ||||||
| 95 | applications that the selection or clipboard data changed. | - | ||||||
| 96 | - | |||||||
| 97 | \li Lastly, the X11 clipboard is event driven, i.e. the clipboard | - | ||||||
| 98 | will not function properly if the event loop is not running. | - | ||||||
| 99 | Similarly, it is recommended that the contents of the clipboard | - | ||||||
| 100 | are stored or retrieved in direct response to user-input events, | - | ||||||
| 101 | e.g. mouse button or key presses and releases. You should not | - | ||||||
| 102 | store or retrieve the clipboard contents in response to timer or | - | ||||||
| 103 | non-user-input events. | - | ||||||
| 104 | - | |||||||
| 105 | \li Since there is no standard way to copy and paste files between | - | ||||||
| 106 | applications on X11, various MIME types and conventions are currently | - | ||||||
| 107 | in use. For instance, Nautilus expects files to be supplied with a | - | ||||||
| 108 | \c{x-special/gnome-copied-files} MIME type with data beginning with | - | ||||||
| 109 | the cut/copy action, a newline character, and the URL of the file. | - | ||||||
| 110 | - | |||||||
| 111 | \endlist | - | ||||||
| 112 | - | |||||||
| 113 | \section1 Notes for \macos Users | - | ||||||
| 114 | - | |||||||
| 115 | \macos supports a separate find buffer that holds the current | - | ||||||
| 116 | search string in Find operations. This find clipboard can be accessed | - | ||||||
| 117 | by specifying the FindBuffer mode. | - | ||||||
| 118 | - | |||||||
| 119 | \section1 Notes for Windows and \macos Users | - | ||||||
| 120 | - | |||||||
| 121 | \list | - | ||||||
| 122 | - | |||||||
| 123 | \li Windows and \macos do not support the global mouse | - | ||||||
| 124 | selection; they only supports the global clipboard, i.e. they | - | ||||||
| 125 | only add text to the clipboard when an explicit copy or cut is | - | ||||||
| 126 | made. | - | ||||||
| 127 | - | |||||||
| 128 | \li Windows and \macos does not have the concept of ownership; | - | ||||||
| 129 | the clipboard is a fully global resource so all applications are | - | ||||||
| 130 | notified of changes. | - | ||||||
| 131 | - | |||||||
| 132 | \endlist | - | ||||||
| 133 | - | |||||||
| 134 | \sa QGuiApplication | - | ||||||
| 135 | */ | - | ||||||
| 136 | - | |||||||
| 137 | /*! | - | ||||||
| 138 | \internal | - | ||||||
| 139 | - | |||||||
| 140 | Constructs a clipboard object. | - | ||||||
| 141 | - | |||||||
| 142 | Do not call this function. | - | ||||||
| 143 | - | |||||||
| 144 | Call QGuiApplication::clipboard() instead to get a pointer to the | - | ||||||
| 145 | application's global clipboard object. | - | ||||||
| 146 | - | |||||||
| 147 | There is only one clipboard in the window system, and creating | - | ||||||
| 148 | more than one object to represent it is almost certainly an error. | - | ||||||
| 149 | */ | - | ||||||
| 150 | - | |||||||
| 151 | QClipboard::QClipboard(QObject *parent) | - | ||||||
| 152 | : QObject(parent) | - | ||||||
| 153 | { | - | ||||||
| 154 | // nothing | - | ||||||
| 155 | } never executed: end of block | 0 | ||||||
| 156 | - | |||||||
| 157 | /*! | - | ||||||
| 158 | \internal | - | ||||||
| 159 | - | |||||||
| 160 | Destroys the clipboard. | - | ||||||
| 161 | - | |||||||
| 162 | You should never delete the clipboard. QGuiApplication will do this | - | ||||||
| 163 | when the application terminates. | - | ||||||
| 164 | */ | - | ||||||
| 165 | QClipboard::~QClipboard() | - | ||||||
| 166 | { | - | ||||||
| 167 | } | - | ||||||
| 168 | - | |||||||
| 169 | /*! | - | ||||||
| 170 | \fn void QClipboard::changed(QClipboard::Mode mode) | - | ||||||
| 171 | \since 4.2 | - | ||||||
| 172 | - | |||||||
| 173 | This signal is emitted when the data for the given clipboard \a | - | ||||||
| 174 | mode is changed. | - | ||||||
| 175 | - | |||||||
| 176 | \sa dataChanged(), selectionChanged(), findBufferChanged() | - | ||||||
| 177 | */ | - | ||||||
| 178 | - | |||||||
| 179 | /*! | - | ||||||
| 180 | \fn void QClipboard::dataChanged() | - | ||||||
| 181 | - | |||||||
| 182 | This signal is emitted when the clipboard data is changed. | - | ||||||
| 183 | - | |||||||
| 184 | On \macos and with Qt version 4.3 or higher, clipboard | - | ||||||
| 185 | changes made by other applications will only be detected | - | ||||||
| 186 | when the application is activated. | - | ||||||
| 187 | - | |||||||
| 188 | \sa findBufferChanged(), selectionChanged(), changed() | - | ||||||
| 189 | */ | - | ||||||
| 190 | - | |||||||
| 191 | /*! | - | ||||||
| 192 | \fn void QClipboard::selectionChanged() | - | ||||||
| 193 | - | |||||||
| 194 | This signal is emitted when the selection is changed. This only | - | ||||||
| 195 | applies to windowing systems that support selections, e.g. X11. | - | ||||||
| 196 | Windows and \macos don't support selections. | - | ||||||
| 197 | - | |||||||
| 198 | \sa dataChanged(), findBufferChanged(), changed() | - | ||||||
| 199 | */ | - | ||||||
| 200 | - | |||||||
| 201 | /*! | - | ||||||
| 202 | \fn void QClipboard::findBufferChanged() | - | ||||||
| 203 | \since 4.2 | - | ||||||
| 204 | - | |||||||
| 205 | This signal is emitted when the find buffer is changed. This only | - | ||||||
| 206 | applies to \macos. | - | ||||||
| 207 | - | |||||||
| 208 | With Qt version 4.3 or higher, clipboard changes made by other | - | ||||||
| 209 | applications will only be detected when the application is activated. | - | ||||||
| 210 | - | |||||||
| 211 | \sa dataChanged(), selectionChanged(), changed() | - | ||||||
| 212 | */ | - | ||||||
| 213 | - | |||||||
| 214 | - | |||||||
| 215 | /*! \enum QClipboard::Mode | - | ||||||
| 216 | \keyword clipboard mode | - | ||||||
| 217 | - | |||||||
| 218 | This enum type is used to control which part of the system clipboard is | - | ||||||
| 219 | used by QClipboard::mimeData(), QClipboard::setMimeData() and related functions. | - | ||||||
| 220 | - | |||||||
| 221 | \value Clipboard indicates that data should be stored and retrieved from | - | ||||||
| 222 | the global clipboard. | - | ||||||
| 223 | - | |||||||
| 224 | \value Selection indicates that data should be stored and retrieved from | - | ||||||
| 225 | the global mouse selection. Support for \c Selection is provided only on | - | ||||||
| 226 | systems with a global mouse selection (e.g. X11). | - | ||||||
| 227 | - | |||||||
| 228 | \value FindBuffer indicates that data should be stored and retrieved from | - | ||||||
| 229 | the Find buffer. This mode is used for holding search strings on \macos. | - | ||||||
| 230 | - | |||||||
| 231 | \omitvalue LastMode | - | ||||||
| 232 | - | |||||||
| 233 | \sa QClipboard::supportsSelection() | - | ||||||
| 234 | */ | - | ||||||
| 235 | - | |||||||
| 236 | - | |||||||
| 237 | /*! | - | ||||||
| 238 | \overload | - | ||||||
| 239 | - | |||||||
| 240 | Returns the clipboard text in subtype \a subtype, or an empty string | - | ||||||
| 241 | if the clipboard does not contain any text. If \a subtype is null, | - | ||||||
| 242 | any subtype is acceptable, and \a subtype is set to the chosen | - | ||||||
| 243 | subtype. | - | ||||||
| 244 | - | |||||||
| 245 | The \a mode argument is used to control which part of the system | - | ||||||
| 246 | clipboard is used. If \a mode is QClipboard::Clipboard, the | - | ||||||
| 247 | text is retrieved from the global clipboard. If \a mode is | - | ||||||
| 248 | QClipboard::Selection, the text is retrieved from the global | - | ||||||
| 249 | mouse selection. | - | ||||||
| 250 | - | |||||||
| 251 | Common values for \a subtype are "plain" and "html". | - | ||||||
| 252 | - | |||||||
| 253 | Note that calling this function repeatedly, for instance from a | - | ||||||
| 254 | key event handler, may be slow. In such cases, you should use the | - | ||||||
| 255 | \c dataChanged() signal instead. | - | ||||||
| 256 | - | |||||||
| 257 | \sa setText(), mimeData() | - | ||||||
| 258 | */ | - | ||||||
| 259 | QString QClipboard::text(QString &subtype, Mode mode) const | - | ||||||
| 260 | { | - | ||||||
| 261 | const QMimeData *const data = mimeData(mode); | - | ||||||
| 262 | if (!data)
| 0 | ||||||
| 263 | return QString(); never executed: return QString(); | 0 | ||||||
| 264 | - | |||||||
| 265 | const QStringList formats = data->formats(); | - | ||||||
| 266 | if (subtype.isEmpty()) {
| 0 | ||||||
| 267 | if (formats.contains(QLatin1String("text/plain")))
| 0 | ||||||
| 268 | subtype = QLatin1String("plain"); never executed: subtype = QLatin1String("plain"); | 0 | ||||||
| 269 | else { | - | ||||||
| 270 | for (int i = 0; i < formats.size(); ++i)
| 0 | ||||||
| 271 | if (formats.at(i).startsWith(QLatin1String("text/"))) {
| 0 | ||||||
| 272 | subtype = formats.at(i).mid(5); | - | ||||||
| 273 | break; never executed: break; | 0 | ||||||
| 274 | } | - | ||||||
| 275 | if (subtype.isEmpty())
| 0 | ||||||
| 276 | return QString(); never executed: return QString(); | 0 | ||||||
| 277 | } never executed: end of block | 0 | ||||||
| 278 | } else if (!formats.contains(QLatin1String("text/") + subtype)) {
| 0 | ||||||
| 279 | return QString(); never executed: return QString(); | 0 | ||||||
| 280 | } | - | ||||||
| 281 | - | |||||||
| 282 | const QByteArray rawData = data->data(QLatin1String("text/") + subtype); | - | ||||||
| 283 | - | |||||||
| 284 | #ifndef QT_NO_TEXTCODEC | - | ||||||
| 285 | QTextCodec* codec = QTextCodec::codecForMib(106); // utf-8 is default | - | ||||||
| 286 | if (subtype == QLatin1String("html"))
| 0 | ||||||
| 287 | codec = QTextCodec::codecForHtml(rawData, codec); never executed: codec = QTextCodec::codecForHtml(rawData, codec); | 0 | ||||||
| 288 | else | - | ||||||
| 289 | codec = QTextCodec::codecForUtfText(rawData, codec); never executed: codec = QTextCodec::codecForUtfText(rawData, codec); | 0 | ||||||
| 290 | return codec->toUnicode(rawData); never executed: return codec->toUnicode(rawData); | 0 | ||||||
| 291 | #else //QT_NO_TEXTCODEC | - | ||||||
| 292 | return rawData; | - | ||||||
| 293 | #endif //QT_NO_TEXTCODEC | - | ||||||
| 294 | } | - | ||||||
| 295 | - | |||||||
| 296 | /*! | - | ||||||
| 297 | Returns the clipboard text as plain text, or an empty string if the | - | ||||||
| 298 | clipboard does not contain any text. | - | ||||||
| 299 | - | |||||||
| 300 | The \a mode argument is used to control which part of the system | - | ||||||
| 301 | clipboard is used. If \a mode is QClipboard::Clipboard, the | - | ||||||
| 302 | text is retrieved from the global clipboard. If \a mode is | - | ||||||
| 303 | QClipboard::Selection, the text is retrieved from the global | - | ||||||
| 304 | mouse selection. If \a mode is QClipboard::FindBuffer, the | - | ||||||
| 305 | text is retrieved from the search string buffer. | - | ||||||
| 306 | - | |||||||
| 307 | \sa setText(), mimeData() | - | ||||||
| 308 | */ | - | ||||||
| 309 | QString QClipboard::text(Mode mode) const | - | ||||||
| 310 | { | - | ||||||
| 311 | const QMimeData *data = mimeData(mode); | - | ||||||
| 312 | return data ? data->text() : QString(); never executed: return data ? data->text() : QString();
| 0 | ||||||
| 313 | } | - | ||||||
| 314 | - | |||||||
| 315 | /*! | - | ||||||
| 316 | Copies \a text into the clipboard as plain text. | - | ||||||
| 317 | - | |||||||
| 318 | The \a mode argument is used to control which part of the system | - | ||||||
| 319 | clipboard is used. If \a mode is QClipboard::Clipboard, the | - | ||||||
| 320 | text is stored in the global clipboard. If \a mode is | - | ||||||
| 321 | QClipboard::Selection, the text is stored in the global | - | ||||||
| 322 | mouse selection. If \a mode is QClipboard::FindBuffer, the | - | ||||||
| 323 | text is stored in the search string buffer. | - | ||||||
| 324 | - | |||||||
| 325 | \sa text(), setMimeData() | - | ||||||
| 326 | */ | - | ||||||
| 327 | void QClipboard::setText(const QString &text, Mode mode) | - | ||||||
| 328 | { | - | ||||||
| 329 | QMimeData *data = new QMimeData; | - | ||||||
| 330 | data->setText(text); | - | ||||||
| 331 | setMimeData(data, mode); | - | ||||||
| 332 | } never executed: end of block | 0 | ||||||
| 333 | - | |||||||
| 334 | /*! | - | ||||||
| 335 | Returns the clipboard image, or returns a null image if the | - | ||||||
| 336 | clipboard does not contain an image or if it contains an image in | - | ||||||
| 337 | an unsupported image format. | - | ||||||
| 338 | - | |||||||
| 339 | The \a mode argument is used to control which part of the system | - | ||||||
| 340 | clipboard is used. If \a mode is QClipboard::Clipboard, the | - | ||||||
| 341 | image is retrieved from the global clipboard. If \a mode is | - | ||||||
| 342 | QClipboard::Selection, the image is retrieved from the global | - | ||||||
| 343 | mouse selection. | - | ||||||
| 344 | - | |||||||
| 345 | \sa setImage(), pixmap(), mimeData(), QImage::isNull() | - | ||||||
| 346 | */ | - | ||||||
| 347 | QImage QClipboard::image(Mode mode) const | - | ||||||
| 348 | { | - | ||||||
| 349 | const QMimeData *data = mimeData(mode); | - | ||||||
| 350 | if (!data)
| 0 | ||||||
| 351 | return QImage(); never executed: return QImage(); | 0 | ||||||
| 352 | return qvariant_cast<QImage>(data->imageData()); never executed: return qvariant_cast<QImage>(data->imageData()); | 0 | ||||||
| 353 | } | - | ||||||
| 354 | - | |||||||
| 355 | /*! | - | ||||||
| 356 | Copies the \a image into the clipboard. | - | ||||||
| 357 | - | |||||||
| 358 | The \a mode argument is used to control which part of the system | - | ||||||
| 359 | clipboard is used. If \a mode is QClipboard::Clipboard, the | - | ||||||
| 360 | image is stored in the global clipboard. If \a mode is | - | ||||||
| 361 | QClipboard::Selection, the data is stored in the global | - | ||||||
| 362 | mouse selection. | - | ||||||
| 363 | - | |||||||
| 364 | This is shorthand for: | - | ||||||
| 365 | - | |||||||
| 366 | \snippet code/src_gui_kernel_qclipboard.cpp 1 | - | ||||||
| 367 | - | |||||||
| 368 | \sa image(), setPixmap(), setMimeData() | - | ||||||
| 369 | */ | - | ||||||
| 370 | void QClipboard::setImage(const QImage &image, Mode mode) | - | ||||||
| 371 | { | - | ||||||
| 372 | QMimeData *data = new QMimeData; | - | ||||||
| 373 | data->setImageData(image); | - | ||||||
| 374 | setMimeData(data, mode); | - | ||||||
| 375 | } never executed: end of block | 0 | ||||||
| 376 | - | |||||||
| 377 | /*! | - | ||||||
| 378 | Returns the clipboard pixmap, or null if the clipboard does not | - | ||||||
| 379 | contain a pixmap. Note that this can lose information. For | - | ||||||
| 380 | example, if the image is 24-bit and the display is 8-bit, the | - | ||||||
| 381 | result is converted to 8 bits, and if the image has an alpha | - | ||||||
| 382 | channel, the result just has a mask. | - | ||||||
| 383 | - | |||||||
| 384 | The \a mode argument is used to control which part of the system | - | ||||||
| 385 | clipboard is used. If \a mode is QClipboard::Clipboard, the | - | ||||||
| 386 | pixmap is retrieved from the global clipboard. If \a mode is | - | ||||||
| 387 | QClipboard::Selection, the pixmap is retrieved from the global | - | ||||||
| 388 | mouse selection. | - | ||||||
| 389 | - | |||||||
| 390 | \sa setPixmap(), image(), mimeData(), QPixmap::convertFromImage() | - | ||||||
| 391 | */ | - | ||||||
| 392 | QPixmap QClipboard::pixmap(Mode mode) const | - | ||||||
| 393 | { | - | ||||||
| 394 | const QMimeData *data = mimeData(mode); | - | ||||||
| 395 | return data ? qvariant_cast<QPixmap>(data->imageData()) : QPixmap(); never executed: return data ? qvariant_cast<QPixmap>(data->imageData()) : QPixmap();
| 0 | ||||||
| 396 | } | - | ||||||
| 397 | - | |||||||
| 398 | /*! | - | ||||||
| 399 | Copies \a pixmap into the clipboard. Note that this is slower | - | ||||||
| 400 | than setImage() because it needs to convert the QPixmap to a | - | ||||||
| 401 | QImage first. | - | ||||||
| 402 | - | |||||||
| 403 | The \a mode argument is used to control which part of the system | - | ||||||
| 404 | clipboard is used. If \a mode is QClipboard::Clipboard, the | - | ||||||
| 405 | pixmap is stored in the global clipboard. If \a mode is | - | ||||||
| 406 | QClipboard::Selection, the pixmap is stored in the global | - | ||||||
| 407 | mouse selection. | - | ||||||
| 408 | - | |||||||
| 409 | \sa pixmap(), setImage(), setMimeData() | - | ||||||
| 410 | */ | - | ||||||
| 411 | void QClipboard::setPixmap(const QPixmap &pixmap, Mode mode) | - | ||||||
| 412 | { | - | ||||||
| 413 | QMimeData *data = new QMimeData; | - | ||||||
| 414 | data->setImageData(pixmap); | - | ||||||
| 415 | setMimeData(data, mode); | - | ||||||
| 416 | } never executed: end of block | 0 | ||||||
| 417 | - | |||||||
| 418 | - | |||||||
| 419 | /*! | - | ||||||
| 420 | \fn QMimeData *QClipboard::mimeData(Mode mode) const | - | ||||||
| 421 | - | |||||||
| 422 | Returns a pointer to a QMimeData representation of the current | - | ||||||
| 423 | clipboard data (can be NULL if the given \a mode is not | - | ||||||
| 424 | supported by the platform). | - | ||||||
| 425 | - | |||||||
| 426 | The \a mode argument is used to control which part of the system | - | ||||||
| 427 | clipboard is used. If \a mode is QClipboard::Clipboard, the | - | ||||||
| 428 | data is retrieved from the global clipboard. If \a mode is | - | ||||||
| 429 | QClipboard::Selection, the data is retrieved from the global | - | ||||||
| 430 | mouse selection. If \a mode is QClipboard::FindBuffer, the | - | ||||||
| 431 | data is retrieved from the search string buffer. | - | ||||||
| 432 | - | |||||||
| 433 | The text(), image(), and pixmap() functions are simpler | - | ||||||
| 434 | wrappers for retrieving text, image, and pixmap data. | - | ||||||
| 435 | - | |||||||
| 436 | \sa setMimeData() | - | ||||||
| 437 | */ | - | ||||||
| 438 | const QMimeData* QClipboard::mimeData(Mode mode) const | - | ||||||
| 439 | { | - | ||||||
| 440 | QPlatformClipboard *clipboard = QGuiApplicationPrivate::platformIntegration()->clipboard(); | - | ||||||
| 441 | if (!clipboard->supportsMode(mode)) return 0; never executed: return 0;
| 0 | ||||||
| 442 | return clipboard->mimeData(mode); never executed: return clipboard->mimeData(mode); | 0 | ||||||
| 443 | } | - | ||||||
| 444 | - | |||||||
| 445 | /*! | - | ||||||
| 446 | \fn void QClipboard::setMimeData(QMimeData *src, Mode mode) | - | ||||||
| 447 | - | |||||||
| 448 | Sets the clipboard data to \a src. Ownership of the data is | - | ||||||
| 449 | transferred to the clipboard. If you want to remove the data | - | ||||||
| 450 | either call clear() or call setMimeData() again with new data. | - | ||||||
| 451 | - | |||||||
| 452 | The \a mode argument is used to control which part of the system | - | ||||||
| 453 | clipboard is used. If \a mode is QClipboard::Clipboard, the | - | ||||||
| 454 | data is stored in the global clipboard. If \a mode is | - | ||||||
| 455 | QClipboard::Selection, the data is stored in the global | - | ||||||
| 456 | mouse selection. If \a mode is QClipboard::FindBuffer, the | - | ||||||
| 457 | data is stored in the search string buffer. | - | ||||||
| 458 | - | |||||||
| 459 | The setText(), setImage() and setPixmap() functions are simpler | - | ||||||
| 460 | wrappers for setting text, image and pixmap data respectively. | - | ||||||
| 461 | - | |||||||
| 462 | \sa mimeData() | - | ||||||
| 463 | */ | - | ||||||
| 464 | void QClipboard::setMimeData(QMimeData* src, Mode mode) | - | ||||||
| 465 | { | - | ||||||
| 466 | QPlatformClipboard *clipboard = QGuiApplicationPrivate::platformIntegration()->clipboard(); | - | ||||||
| 467 | if (!clipboard->supportsMode(mode)) {
| 0 | ||||||
| 468 | if (src != 0) {
| 0 | ||||||
| 469 | qWarning("Data set on unsupported clipboard mode. QMimeData object will be deleted."); | - | ||||||
| 470 | src->deleteLater(); | - | ||||||
| 471 | } never executed: end of block | 0 | ||||||
| 472 | } else { never executed: end of block | 0 | ||||||
| 473 | clipboard->setMimeData(src,mode); | - | ||||||
| 474 | } never executed: end of block | 0 | ||||||
| 475 | } | - | ||||||
| 476 | - | |||||||
| 477 | /*! | - | ||||||
| 478 | \fn void QClipboard::clear(Mode mode) | - | ||||||
| 479 | Clear the clipboard contents. | - | ||||||
| 480 | - | |||||||
| 481 | The \a mode argument is used to control which part of the system | - | ||||||
| 482 | clipboard is used. If \a mode is QClipboard::Clipboard, this | - | ||||||
| 483 | function clears the global clipboard contents. If \a mode is | - | ||||||
| 484 | QClipboard::Selection, this function clears the global mouse | - | ||||||
| 485 | selection contents. If \a mode is QClipboard::FindBuffer, this | - | ||||||
| 486 | function clears the search string buffer. | - | ||||||
| 487 | - | |||||||
| 488 | \sa QClipboard::Mode, supportsSelection() | - | ||||||
| 489 | */ | - | ||||||
| 490 | void QClipboard::clear(Mode mode) | - | ||||||
| 491 | { | - | ||||||
| 492 | setMimeData(0, mode); | - | ||||||
| 493 | } never executed: end of block | 0 | ||||||
| 494 | - | |||||||
| 495 | /*! | - | ||||||
| 496 | Returns \c true if the clipboard supports mouse selection; otherwise | - | ||||||
| 497 | returns \c false. | - | ||||||
| 498 | */ | - | ||||||
| 499 | bool QClipboard::supportsSelection() const | - | ||||||
| 500 | { | - | ||||||
| 501 | return supportsMode(Selection); never executed: return supportsMode(Selection); | 0 | ||||||
| 502 | } | - | ||||||
| 503 | - | |||||||
| 504 | /*! | - | ||||||
| 505 | Returns \c true if the clipboard supports a separate search buffer; otherwise | - | ||||||
| 506 | returns \c false. | - | ||||||
| 507 | */ | - | ||||||
| 508 | bool QClipboard::supportsFindBuffer() const | - | ||||||
| 509 | { | - | ||||||
| 510 | return supportsMode(FindBuffer); never executed: return supportsMode(FindBuffer); | 0 | ||||||
| 511 | } | - | ||||||
| 512 | - | |||||||
| 513 | /*! | - | ||||||
| 514 | Returns \c true if this clipboard object owns the clipboard data; | - | ||||||
| 515 | otherwise returns \c false. | - | ||||||
| 516 | */ | - | ||||||
| 517 | bool QClipboard::ownsClipboard() const | - | ||||||
| 518 | { | - | ||||||
| 519 | return ownsMode(Clipboard); never executed: return ownsMode(Clipboard); | 0 | ||||||
| 520 | } | - | ||||||
| 521 | - | |||||||
| 522 | /*! | - | ||||||
| 523 | Returns \c true if this clipboard object owns the mouse selection | - | ||||||
| 524 | data; otherwise returns \c false. | - | ||||||
| 525 | */ | - | ||||||
| 526 | bool QClipboard::ownsSelection() const | - | ||||||
| 527 | { | - | ||||||
| 528 | return ownsMode(Selection); never executed: return ownsMode(Selection); | 0 | ||||||
| 529 | } | - | ||||||
| 530 | - | |||||||
| 531 | /*! | - | ||||||
| 532 | \since 4.2 | - | ||||||
| 533 | - | |||||||
| 534 | Returns \c true if this clipboard object owns the find buffer data; | - | ||||||
| 535 | otherwise returns \c false. | - | ||||||
| 536 | */ | - | ||||||
| 537 | bool QClipboard::ownsFindBuffer() const | - | ||||||
| 538 | { | - | ||||||
| 539 | return ownsMode(FindBuffer); never executed: return ownsMode(FindBuffer); | 0 | ||||||
| 540 | } | - | ||||||
| 541 | - | |||||||
| 542 | /*! | - | ||||||
| 543 | \internal | - | ||||||
| 544 | \fn bool QClipboard::supportsMode(Mode mode) const; | - | ||||||
| 545 | Returns \c true if the clipboard supports the clipboard mode speacified by \a mode; | - | ||||||
| 546 | otherwise returns \c false. | - | ||||||
| 547 | */ | - | ||||||
| 548 | bool QClipboard::supportsMode(Mode mode) const | - | ||||||
| 549 | { | - | ||||||
| 550 | QPlatformClipboard *clipboard = QGuiApplicationPrivate::platformIntegration()->clipboard(); | - | ||||||
| 551 | return clipboard->supportsMode(mode); never executed: return clipboard->supportsMode(mode); | 0 | ||||||
| 552 | } | - | ||||||
| 553 | - | |||||||
| 554 | /*! | - | ||||||
| 555 | \internal | - | ||||||
| 556 | \fn bool QClipboard::ownsMode(Mode mode) const; | - | ||||||
| 557 | Returns \c true if the clipboard supports the clipboard data speacified by \a mode; | - | ||||||
| 558 | otherwise returns \c false. | - | ||||||
| 559 | */ | - | ||||||
| 560 | bool QClipboard::ownsMode(Mode mode) const | - | ||||||
| 561 | { | - | ||||||
| 562 | QPlatformClipboard *clipboard = QGuiApplicationPrivate::platformIntegration()->clipboard(); | - | ||||||
| 563 | return clipboard->ownsMode(mode); never executed: return clipboard->ownsMode(mode); | 0 | ||||||
| 564 | } | - | ||||||
| 565 | - | |||||||
| 566 | /*! | - | ||||||
| 567 | \internal | - | ||||||
| 568 | Emits the appropriate changed signal for \a mode. | - | ||||||
| 569 | */ | - | ||||||
| 570 | void QClipboard::emitChanged(Mode mode) | - | ||||||
| 571 | { | - | ||||||
| 572 | switch (mode) { | - | ||||||
| 573 | case Clipboard: never executed: case Clipboard: | 0 | ||||||
| 574 | emit dataChanged(); | - | ||||||
| 575 | break; never executed: break; | 0 | ||||||
| 576 | case Selection: never executed: case Selection: | 0 | ||||||
| 577 | emit selectionChanged(); | - | ||||||
| 578 | break; never executed: break; | 0 | ||||||
| 579 | case FindBuffer: never executed: case FindBuffer: | 0 | ||||||
| 580 | emit findBufferChanged(); | - | ||||||
| 581 | break; never executed: break; | 0 | ||||||
| 582 | default: never executed: default: | 0 | ||||||
| 583 | break; never executed: break; | 0 | ||||||
| 584 | } | - | ||||||
| 585 | emit changed(mode); | - | ||||||
| 586 | } never executed: end of block | 0 | ||||||
| 587 | - | |||||||
| 588 | QT_END_NAMESPACE | - | ||||||
| 589 | - | |||||||
| 590 | #endif // QT_NO_CLIPBOARD | - | ||||||
| Source code | Switch to Preprocessed file |