Qt 4.8
|
The QClipboard class provides access to the window system clipboard. More...
#include <qclipboard.h>
Public Types | |
enum | Mode { Clipboard, Selection, FindBuffer, LastMode = FindBuffer } |
This enum type is used to control which part of the system clipboard is used by QClipboard::mimeData(), QClipboard::setMimeData() and related functions. More... | |
Signals | |
void | changed (QClipboard::Mode mode) |
This signal is emitted when the data for the given clipboard mode is changed. More... | |
void | dataChanged () |
This signal is emitted when the clipboard data is changed. More... | |
void | findBufferChanged () |
This signal is emitted when the find buffer is changed. More... | |
void | selectionChanged () |
This signal is emitted when the selection is changed. More... | |
Signals inherited from QObject | |
void | destroyed (QObject *=0) |
This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More... | |
Public Functions | |
void | clear (Mode mode=Clipboard) |
Clear the clipboard contents. More... | |
QImage | image (Mode mode=Clipboard) const |
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. More... | |
const QMimeData * | mimeData (Mode mode=Clipboard) const |
Returns a reference to a QMimeData representation of the current clipboard data. More... | |
bool | ownsClipboard () const |
Returns true if this clipboard object owns the clipboard data; otherwise returns false. More... | |
bool | ownsFindBuffer () const |
Returns true if this clipboard object owns the find buffer data; otherwise returns false. More... | |
bool | ownsSelection () const |
Returns true if this clipboard object owns the mouse selection data; otherwise returns false. More... | |
QPixmap | pixmap (Mode mode=Clipboard) const |
Returns the clipboard pixmap, or null if the clipboard does not contain a pixmap. More... | |
void | setImage (const QImage &, Mode mode=Clipboard) |
Copies the image into the clipboard. More... | |
void | setMimeData (QMimeData *data, Mode mode=Clipboard) |
Sets the clipboard data to src. More... | |
void | setPixmap (const QPixmap &, Mode mode=Clipboard) |
Copies pixmap into the clipboard. More... | |
void | setText (const QString &, Mode mode=Clipboard) |
Copies text into the clipboard as plain text. More... | |
bool | supportsFindBuffer () const |
Returns true if the clipboard supports a separate search buffer; otherwise returns false. More... | |
bool | supportsSelection () const |
Returns true if the clipboard supports mouse selection; otherwise returns false. More... | |
QString | text (Mode mode=Clipboard) const |
Returns the clipboard text as plain text, or an empty string if the clipboard does not contain any text. More... | |
QString | text (QString &subtype, Mode mode=Clipboard) const |
Returns the clipboard text in subtype subtype, or an empty string if the clipboard does not contain any text. More... | |
Public Functions inherited from QObject | |
bool | blockSignals (bool b) |
If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More... | |
const QObjectList & | children () const |
Returns a list of child objects. More... | |
bool | connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const |
bool | disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0) |
bool | disconnect (const QObject *receiver, const char *member=0) |
void | dumpObjectInfo () |
Dumps information about signal connections, etc. More... | |
void | dumpObjectTree () |
Dumps a tree of children to the debug output. More... | |
QList< QByteArray > | dynamicPropertyNames () const |
Returns the names of all properties that were dynamically added to the object using setProperty(). More... | |
virtual bool | eventFilter (QObject *, QEvent *) |
Filters events if this object has been installed as an event filter for the watched object. More... | |
template<typename T > | |
T | findChild (const QString &aName=QString()) const |
Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More... | |
template<typename T > | |
QList< T > | findChildren (const QString &aName=QString()) const |
Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More... | |
template<typename T > | |
QList< T > | findChildren (const QRegExp &re) const |
bool | inherits (const char *classname) const |
Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More... | |
void | installEventFilter (QObject *) |
Installs an event filter filterObj on this object. More... | |
bool | isWidgetType () const |
Returns true if the object is a widget; otherwise returns false. More... | |
void | killTimer (int id) |
Kills the timer with timer identifier, id. More... | |
virtual const QMetaObject * | metaObject () const |
Returns a pointer to the meta-object of this object. More... | |
void | moveToThread (QThread *thread) |
Changes the thread affinity for this object and its children. More... | |
QString | objectName () const |
QObject * | parent () const |
Returns a pointer to the parent object. More... | |
QVariant | property (const char *name) const |
Returns the value of the object's name property. More... | |
Q_INVOKABLE | QObject (QObject *parent=0) |
Constructs an object with parent object parent. More... | |
void | removeEventFilter (QObject *) |
Removes an event filter object obj from this object. More... | |
void | setObjectName (const QString &name) |
void | setParent (QObject *) |
Makes the object a child of parent. More... | |
bool | setProperty (const char *name, const QVariant &value) |
Sets the value of the object's name property to value. More... | |
void | setUserData (uint id, QObjectUserData *data) |
bool | signalsBlocked () const |
Returns true if signals are blocked; otherwise returns false. More... | |
int | startTimer (int interval) |
Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More... | |
QThread * | thread () const |
Returns the thread in which the object lives. More... | |
QObjectUserData * | userData (uint id) const |
virtual | ~QObject () |
Destroys the object, deleting all its child objects. More... | |
Protected Functions | |
void | connectNotify (const char *) |
Internal optimization for Windows. More... | |
bool | event (QEvent *) |
Reimplemented Function More... | |
Protected Functions inherited from QObject | |
virtual void | childEvent (QChildEvent *) |
This event handler can be reimplemented in a subclass to receive child events. More... | |
virtual void | customEvent (QEvent *) |
This event handler can be reimplemented in a subclass to receive custom events. More... | |
virtual void | disconnectNotify (const char *signal) |
This virtual function is called when something has been disconnected from signal in this object. More... | |
QObject (QObjectPrivate &dd, QObject *parent=0) | |
int | receivers (const char *signal) const |
Returns the number of receivers connected to the signal. More... | |
QObject * | sender () const |
Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More... | |
int | senderSignalIndex () const |
virtual void | timerEvent (QTimerEvent *) |
This event handler can be reimplemented in a subclass to receive timer events for the object. More... | |
Private Slots | |
void | ownerDestroyed () |
Internal cleanup for Windows. More... | |
Private Functions | |
void | emitChanged (Mode mode) |
Emits the appropriate changed signal for mode. More... | |
bool | ownsMode (Mode mode) const |
Returns true if the clipboard supports the clipboard data speacified by mode; otherwise returns false. More... | |
QClipboard (QObject *parent) | |
bool | supportsMode (Mode mode) const |
Returns true if the clipboard supports the clipboard mode speacified by mode; otherwise returns false. More... | |
~QClipboard () | |
Friends | |
class | QApplication |
class | QApplicationPrivate |
class | QBaseApplication |
class | QDragManager |
class | QMimeSource |
class | QPlatformClipboard |
Additional Inherited Members | |
Public Slots inherited from QObject | |
void | deleteLater () |
Schedules this object for deletion. More... | |
Static Public Functions inherited from QObject | |
static bool | connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection) |
Creates a connection of the given type from the signal in the sender object to the method in the receiver object. More... | |
static bool | connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection) |
static bool | disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member) |
Disconnects signal in object sender from method in object receiver. More... | |
static bool | disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member) |
static uint | registerUserData () |
static QString | tr (const char *sourceText, const char *comment=0, int n=-1) |
static QString | trUtf8 (const char *sourceText, const char *comment=0, int n=-1) |
Static Public Variables inherited from QObject | |
static const QMetaObject | staticMetaObject |
This variable stores the meta-object for the class. More... | |
Protected Variables inherited from QObject | |
QScopedPointer< QObjectData > | d_ptr |
Static Protected Variables inherited from QObject | |
static const QMetaObject | staticQtMetaObject |
Related Functions inherited from QObject | |
T | qFindChildqFindChildren (const QObject *obj, const QString &name)() |
QList< T > | qFindChildrenqFindChildren (const QObject *obj, const QString &name)() |
QList< T > | qFindChildrenqFindChildren (const QObject *obj, const QRegExp ®Exp)() |
T * | qobject_cast (QObject *object) |
QObjectList | |
void * | qt_find_obj_child (QObject *parent, const char *type, const QString &name) |
Returns a pointer to the object named name that inherits type and with a given parent. More... | |
The QClipboard class provides access to the window system clipboard.
The clipboard offers a simple mechanism to copy and paste data between applications.
QClipboard supports the same data types that QDrag does, and uses similar mechanisms. For advanced clipboard usage read Drag and Drop.
There is a single QClipboard object in an application, accessible as QApplication::clipboard().
Example:
QClipboard features some convenience functions to access common data types: setText() allows the exchange of Unicode text and setPixmap() and setImage() allows the exchange of QPixmaps and QImages between applications. The setMimeData() function is the ultimate in flexibility: it allows you to add any QMimeData into the clipboard. There are corresponding getters for each of these, e.g. text(), image() and pixmap(). You can clear the clipboard by calling clear().
A typical example of the use of these functions follows:
The X11 Window System has the concept of a separate selection and clipboard. When text is selected, it is immediately available as the global mouse selection. The global mouse selection may later be copied to the clipboard. By convention, the middle mouse button is used to paste the global mouse selection.
X11 also has the concept of ownership; if you change the selection within a window, X11 will only notify the owner and the previous owner of the change, i.e. it will not notify all applications that the selection or clipboard data changed.
Lastly, the X11 clipboard is event driven, i.e. the clipboard will not function properly if the event loop is not running. Similarly, it is recommended that the contents of the clipboard are stored or retrieved in direct response to user-input events, e.g. mouse button or key presses and releases. You should not store or retrieve the clipboard contents in response to timer or non-user-input events.
Since there is no standard way to copy and paste files between applications on X11, various MIME types and conventions are currently in use. For instance, Nautilus expects files to be supplied with a x-special/gnome-copied-files
MIME type with data beginning with the cut/copy action, a newline character, and the URL of the file.
Mac OS X supports a separate find buffer that holds the current search string in Find operations. This find clipboard can be accessed by specifying the FindBuffer mode.
Windows and Mac OS X do not support the global mouse selection; they only supports the global clipboard, i.e. they only add text to the clipboard when an explicit copy or cut is made.
Windows and Mac OS X does not have the concept of ownership; the clipboard is a fully global resource so all applications are notified of changes.
Definition at line 62 of file qclipboard.h.
enum QClipboard::Mode |
This enum type is used to control which part of the system clipboard is used by QClipboard::mimeData(), QClipboard::setMimeData() and related functions.
clipboard mode
Selection
is provided only on systems with a global mouse selection (e.g. X11).Enumerator | |
---|---|
Clipboard | |
Selection | |
FindBuffer | |
LastMode |
Definition at line 71 of file qclipboard.h.
|
private |
Definition at line 430 of file qclipboard_x11.cpp.
|
private |
Definition at line 254 of file qclipboard_win.cpp.
|
signal |
This signal is emitted when the data for the given clipboard mode is changed.
Clear the clipboard contents.
The mode argument is used to control which part of the system clipboard is used. If mode is QClipboard::Clipboard, this function clears the global clipboard contents. If mode is QClipboard::Selection, this function clears the global mouse selection contents. If mode is QClipboard::FindBuffer, this function clears the search string buffer.
Definition at line 99 of file qclipboard_mac.cpp.
Referenced by clipboardData(), and ~QClipboard().
|
protectedvirtual |
Internal optimization for Windows.
Reimplemented from QObject.
Definition at line 113 of file qclipboard_mac.cpp.
Referenced by clipboardData(), and isProcessBeingDebugged().
|
signal |
This signal is emitted when the clipboard data is changed.
On Mac OS X and with Qt version 4.3 or higher, clipboard changes made by other applications will only be detected when the application is activated.
|
private |
Emits the appropriate changed signal for mode.
Definition at line 640 of file qclipboard.cpp.
Referenced by QPlatformClipboard::emitChanged(), event(), and setMimeData().
|
protectedvirtual |
Reimplemented Function
Reimplemented from QObject.
Definition at line 118 of file qclipboard_mac.cpp.
Referenced by clipboardData(), QX11Data::clipboardReadIncrementalProperty(), isProcessBeingDebugged(), and qt_x11_clipboard_event_filter().
|
signal |
This signal is emitted when the find buffer is changed.
This only applies to Mac OS X.
With Qt version 4.3 or higher, clipboard changes made by other applications will only be detected when the application is activated.
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 mode argument is used to control which part of the system clipboard is used. If mode is QClipboard::Clipboard, the image is retrieved from the global clipboard. If mode is QClipboard::Selection, the image is retrieved from the global mouse selection.
Definition at line 395 of file qclipboard.cpp.
Returns a reference to a QMimeData representation of the current clipboard data.
The mode argument is used to control which part of the system clipboard is used. If mode is QClipboard::Clipboard, the data is retrieved from the global clipboard. If mode is QClipboard::Selection, the data is retrieved from the global mouse selection. If 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.
Definition at line 134 of file qclipboard_mac.cpp.
Referenced by QTextControl::canPaste(), clipboardData(), QClipboardWatcher::getDataInFormat(), isProcessBeingDebugged(), QTextControlPrivate::mouseReleaseEvent(), QTextControl::paste(), and QMacPasteboard::setMimeData().
|
privateslot |
Internal cleanup for Windows.
Definition at line 108 of file qclipboard_mac.cpp.
Referenced by clipboardData(), and isProcessBeingDebugged().
bool QClipboard::ownsClipboard | ( | ) | const |
Returns true if this clipboard object owns the clipboard data; otherwise returns false.
Definition at line 585 of file qclipboard.cpp.
bool QClipboard::ownsFindBuffer | ( | ) | const |
Returns true if this clipboard object owns the find buffer data; otherwise returns false.
Definition at line 608 of file qclipboard.cpp.
|
private |
Returns true if the clipboard supports the clipboard data speacified by mode; otherwise returns false.
Definition at line 156 of file qclipboard_mac.cpp.
Referenced by clipboardData(), and isProcessBeingDebugged().
bool QClipboard::ownsSelection | ( | ) | const |
Returns true if this clipboard object owns the mouse selection data; otherwise returns false.
Definition at line 594 of file qclipboard.cpp.
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 mode argument is used to control which part of the system clipboard is used. If mode is QClipboard::Clipboard, the pixmap is retrieved from the global clipboard. If mode is QClipboard::Selection, the pixmap is retrieved from the global mouse selection.
Definition at line 440 of file qclipboard.cpp.
|
signal |
This signal is emitted when the selection is changed.
This only applies to windowing systems that support selections, e.g. X11. Windows and Mac OS X don't support selections.
Copies the image into the clipboard.
The mode argument is used to control which part of the system clipboard is used. If mode is QClipboard::Clipboard, the image is stored in the global clipboard. If mode is QClipboard::Selection, the data is stored in the global mouse selection.
This is shorthand for:
Definition at line 418 of file qclipboard.cpp.
Sets the clipboard data to 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 mode argument is used to control which part of the system clipboard is used. If mode is QClipboard::Clipboard, the data is stored in the global clipboard. If mode is QClipboard::Selection, the data is stored in the global mouse selection. If 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.
Definition at line 142 of file qclipboard_mac.cpp.
Referenced by QTextControlPrivate::_q_copyLink(), clear(), clipboardData(), QTextControl::copy(), QClipboardWatcher::getDataInFormat(), QTextControlPrivate::setClipboardSelection(), QMacPasteboard::sync(), and ~QClipboard().
Copies pixmap into the clipboard.
Note that this is slower than setImage() because it needs to convert the QPixmap to a QImage first.
The mode argument is used to control which part of the system clipboard is used. If mode is QClipboard::Clipboard, the pixmap is stored in the global clipboard. If mode is QClipboard::Selection, the pixmap is stored in the global mouse selection.
Definition at line 459 of file qclipboard.cpp.
Copies text into the clipboard as plain text.
The mode argument is used to control which part of the system clipboard is used. If mode is QClipboard::Clipboard, the text is stored in the global clipboard. If mode is QClipboard::Selection, the text is stored in the global mouse selection. If mode is QClipboard::FindBuffer, the text is stored in the search string buffer.
Definition at line 375 of file qclipboard.cpp.
Referenced by clipboardData(), QLineControl::copy(), QmlJSDebugger::ToolBarColorBox::copyColorToClipboard(), QAccessibleTextWidget::copyText(), QAccessibleSimpleEditableTextInterface::copyText(), QAccessibleTextWidget::cutText(), QAccessibleSimpleEditableTextInterface::cutText(), QMessageBox::keyPressEvent(), and QAbstractItemView::keyPressEvent().
bool QClipboard::supportsFindBuffer | ( | ) | const |
Returns true if the clipboard supports a separate search buffer; otherwise returns false.
Definition at line 576 of file qclipboard.cpp.
|
private |
Returns true if the clipboard supports the clipboard mode speacified by mode; otherwise returns false.
Definition at line 151 of file qclipboard_mac.cpp.
Referenced by clear(), clipboardData(), isProcessBeingDebugged(), mimeData(), and setMimeData().
bool QClipboard::supportsSelection | ( | ) | const |
Returns true if the clipboard supports mouse selection; otherwise returns false.
Definition at line 567 of file qclipboard.cpp.
Referenced by QTextControlPrivate::setClipboardSelection().
Returns the clipboard text as plain text, or an empty string if the clipboard does not contain any text.
The mode argument is used to control which part of the system clipboard is used. If mode is QClipboard::Clipboard, the text is retrieved from the global clipboard. If mode is QClipboard::Selection, the text is retrieved from the global mouse selection. If mode is QClipboard::FindBuffer, the text is retrieved from the search string buffer.
Definition at line 357 of file qclipboard.cpp.
Referenced by clipboardData(), QLineEdit::createStandardContextMenu(), QDeclarativeTextInputPrivate::init(), QLineControl::paste(), QAccessibleTextWidget::pasteText(), and QDeclarativeTextInput::q_canPasteChanged().
Returns the clipboard text in subtype subtype, or an empty string if the clipboard does not contain any text.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
If subtype is null, any subtype is acceptable, and subtype is set to the chosen subtype.
The mode argument is used to control which part of the system clipboard is used. If mode is QClipboard::Clipboard, the text is retrieved from the global clipboard. If mode is QClipboard::Selection, the text is retrieved from the global mouse selection.
Common values for subtype are "plain" and "html".
Note that calling this function repeatedly, for instance from a key event handler, may be slow. In such cases, you should use the dataChanged()
signal instead.
Definition at line 307 of file qclipboard.cpp.
|
friend |
Definition at line 110 of file qclipboard.h.
|
friend |
Definition at line 111 of file qclipboard.h.
|
friend |
Definition at line 112 of file qclipboard.h.
|
friend |
Definition at line 113 of file qclipboard.h.
|
friend |
Definition at line 114 of file qclipboard.h.
|
friend |
Definition at line 115 of file qclipboard.h.