📄 qclipboard.cpp
字号:
*/void QClipboard::setText(const QString &text, Mode mode){ QMimeData *data = new QMimeData; data->setText(text); setMimeData(data, mode);}/*! Returns the clipboard image, or returns a null image if the clipboard does not contain an image or if it contains an image in an unsupported image format. The \a mode argument is used to control which part of the system clipboard is used. If \a mode is QClipboard::Clipboard, the image is retrieved from the global clipboard. If \a mode is QClipboard::Selection, the image is retrieved from the global mouse selection. \sa setImage() pixmap() mimeData(), QImage::isNull()*/QImage QClipboard::image(Mode mode) const{ const QMimeData *data = mimeData(mode); if (!data) return QImage(); return qvariant_cast<QImage>(data->imageData());}/*! Copies the \a image into the clipboard. The \a mode argument is used to control which part of the system clipboard is used. If \a mode is QClipboard::Clipboard, the image is stored in the global clipboard. If \a mode is QClipboard::Selection, the data is stored in the global mouse selection. This is shorthand for: \code QMimeData *data = new QMimeData; data->setImageData(image); clipboard->setMimeData(data, mode); \endcode \sa image(), setPixmap() setMimeData()*/void QClipboard::setImage(const QImage &image, Mode mode){ QMimeData *data = new QMimeData; data->setImageData(image); setMimeData(data, mode);}/*! Returns the clipboard pixmap, or null if the clipboard does not contain a pixmap. Note that this can lose information. For example, if the image is 24-bit and the display is 8-bit, the result is converted to 8 bits, and if the image has an alpha channel, the result just has a mask. The \a mode argument is used to control which part of the system clipboard is used. If \a mode is QClipboard::Clipboard, the pixmap is retrieved from the global clipboard. If \a mode is QClipboard::Selection, the pixmap is retrieved from the global mouse selection. \sa setPixmap() image() mimeData() QPixmap::convertFromImage()*/QPixmap QClipboard::pixmap(Mode mode) const{ const QMimeData *data = mimeData(mode); return data ? qvariant_cast<QPixmap>(data->imageData()) : QPixmap();}/*! Copies \a pixmap into the clipboard. Note that this is slower than setImage() because it needs to convert the QPixmap to a QImage first. The \a mode argument is used to control which part of the system clipboard is used. If \a mode is QClipboard::Clipboard, the pixmap is stored in the global clipboard. If \a mode is QClipboard::Selection, the pixmap is stored in the global mouse selection. \sa pixmap() setImage() setMimeData()*/void QClipboard::setPixmap(const QPixmap &pixmap, Mode mode){ QMimeData *data = new QMimeData; data->setImageData(pixmap); setMimeData(data, mode);}/*! \fn QMimeData *QClipboard::mimeData(Mode mode) const Returns a reference to a QMimeData representation of the current clipboard data. The \a mode argument is used to control which part of the system clipboard is used. If \a mode is QClipboard::Clipboard, the data is retrieved from the global clipboard. If \a mode is QClipboard::Selection, the data is retrieved from the global mouse selection. If \a mode is QClipboard::FindBuffer, the data is retrieved from the search string buffer. The text(), image(), and pixmap() functions are simpler wrappers for retrieving text, image, and pixmap data. \sa setMimeData()*//*! \fn void QClipboard::setMimeData(QMimeData *src, Mode mode) Sets the clipboard data to \a src. Ownership of the data is transferred to the clipboard. If you want to remove the data either call clear() or call setMimeData() again with new data. The \a mode argument is used to control which part of the system clipboard is used. If \a mode is QClipboard::Clipboard, the data is stored in the global clipboard. If \a mode is QClipboard::Selection, the data is stored in the global mouse selection. If \a mode is QClipboard::FindBuffer, the data is stored in the search string buffer. The setText(), setImage() and setPixmap() functions are simpler wrappers for setting text, image and pixmap data respectively. \sa mimeData()*//*! \fn void QClipboard::clear(Mode mode) Clear the clipboard contents. The \a mode argument is used to control which part of the system clipboard is used. If \a mode is QClipboard::Clipboard, this function clears the the global clipboard contents. If \a mode is QClipboard::Selection, this function clears the global mouse selection contents. If \a mode is QClipboard::FindBuffer, this function clears the search string buffer. \sa QClipboard::Mode, supportsSelection()*/#ifdef QT3_SUPPORT/*! \fn QMimeSource *QClipboard::data(Mode mode) const \compat Use mimeData() instead.*/QMimeSource *QClipboard::data(Mode mode) const{ Q_D(const QClipboard); if (supportsMode(mode) == false) return 0; if (d->compat_data[mode]) return d->compat_data[mode]; d->wrapper[mode]->data = mimeData(mode); return d->wrapper[mode];}/*! \fn void QClipboard::setData(QMimeSource *src, Mode mode) \compat Use setMimeData() instead.*/void QClipboard::setData(QMimeSource *source, Mode mode){ Q_D(QClipboard); if (supportsMode(mode) == false) return; d->compat_data[mode] = source; setMimeData(new QMimeSourceWrapper(d, mode));}#endif // QT3_SUPPORT/*! Returns true if the clipboard supports mouse selection; otherwise returns false.*/bool QClipboard::supportsSelection() const{ return supportsMode(Selection);}/*! Returns true if the clipboard supports a separate search buffer; otherwise returns false.*/bool QClipboard::supportsFindBuffer() const{ return supportsMode(FindBuffer);}/*! Returns true if this clipboard object owns the clipboard data; otherwise returns false.*/bool QClipboard::ownsClipboard() const{ return ownsMode(Clipboard);}/*! Returns true if this clipboard object owns the mouse selection data; otherwise returns false.*/bool QClipboard::ownsSelection() const{ return ownsMode(Selection);}/*! \since 4.2 Returns true if this clipboard object owns the find buffer data; otherwise returns false.*/bool QClipboard::ownsFindBuffer() const{ return ownsMode(FindBuffer);}/*! \internal \fn bool QClipboard::supportsMode(Mode mode) const; Returns true if the clipboard supports the clipboard mode speacified by \a mode; otherwise returns false.*//*! \internal \fn bool QClipboard::ownsMode(Mode mode) const; Returns true if the clipboard supports the clipboard data speacified by \a mode; otherwise returns false.*//*! \internal Emits the appropriate changed signal for \a mode.*/void QClipboard::emitChanged(Mode mode){ switch (mode) { case Clipboard: emit dataChanged(); break; case Selection: emit selectionChanged(); break; case FindBuffer: emit findBufferChanged(); break; default: break; emit changed(mode); }}const char* QMimeDataWrapper::format(int n) const{ if (formats.isEmpty()) { QStringList fmts = data->formats(); for (int i = 0; i < fmts.size(); ++i) formats.append(fmts.at(i).toLatin1()); } if (n < 0 || n >= formats.size()) return 0; return formats.at(n).data();}QByteArray QMimeDataWrapper::encodedData(const char *format) const{ return data->data(QLatin1String(format));}QVariant QMimeSourceWrapper::retrieveData(const QString &mimetype, QVariant::Type) const{ return source->encodedData(mimetype.toLatin1());}bool QMimeSourceWrapper::hasFormat(const QString &mimetype) const{ return source->provides(mimetype.toLatin1());}QStringList QMimeSourceWrapper::formats() const{ QStringList fmts; int i = 0; const char *fmt; while ((fmt = source->format(i))) { fmts.append(QLatin1String(fmt)); ++i; } return fmts;}#endif // QT_NO_CLIPBOARD
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -