All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
Public Types | Public Member Functions
Qtilities::CoreGui::Interfaces::IClipboard Class Reference

Interface used to communicate with the clipboard manager. More...

#include <IClipboard.h>

Inheritance diagram for Qtilities::CoreGui::Interfaces::IClipboard:
Inheritance graph
[legend]

List of all members.

Public Types

enum  ClipboardOrigin { CopyAction, CutAction, Unspecified }
 Enumeration which is used to indicate if a copy or a cut operation caused the clipboard to change. More...

Public Member Functions

virtual void acceptMimeData ()=0
 Call this function if you accepted the mime data and want to remove the data from the clipboard. It will disable the paste action.
virtual ClipboardOrigin clipboardOrigin ()=0
 Gives information about the data which was placed in the clipboard.
virtual void initialize ()=0
 Initializes the actions associated with the clipboard manager.
virtual void setClipboardOrigin (ClipboardOrigin)=0
 Call this function after a copy or cut action call to indicate what the paste action should do.
- Public Member Functions inherited from Qtilities::Core::Interfaces::IObjectBase
virtual QObject * objectBase ()=0
 Returns the QObject* base of the interface.
virtual const QObject * objectBase () const =0
 Returns a const QObject* base of the interface.
QString objectOriginID () const
 Allows interfaces to provide some sort of source identification.
void setObjectOriginID (const QString &object_origin_id)
 Allows setting of the object source ID of this interface implementation.

Detailed Description

Interface used to communicate with the clipboard manager.

The goal of the clipboard manager is to register backends (associated with the standard context) for the Qtilities::CoreGui::Actions::qti_action_EDIT_COPY, Qtilities::CoreGui::Actions::qti_action_EDIT_CUT and Qtilities::CoreGui::Actions::qti_action_EDIT_PASTE action placeholders if they exists. This allows control over disabling and enabling these three actions in Qtilities applications. For example, the paste action should only be enabled if something exists in the the clipboard. Also, when you perform a paste operation, the paste action must become disabled again. The clipboard manager provides this functionality.

To use the Qtilities clipboard in your applications, you must register the copy and cut actions in your main function and then initialize the clipboard as shown below:

// Create the menu bar and menus in the menu bar:
bool existed;
ActionContainer* menu_bar = ACTION_MANAGER->createMenuBar(qti_action_MENUBAR_STANDARD,existed);
ActionContainer* edit_menu = ACTION_MANAGER->createMenu(qti_action_EDIT,existed);
menu_bar->addMenu(edit_menu);
// Get the standard context:
QList<int> std_context;
std_context.push_front(CONTEXT_MANAGER->contextID(qti_def_CONTEXT_STANDARD));
// Register action placeholders for the copy, cut and paste actions:
Command* command = ACTION_MANAGER->registerActionPlaceHolder(qti_action_EDIT_COPY,QObject::tr("Copy"),QKeySequence(QKeySequence::Copy));
edit_menu->addAction(command);
command = ACTION_MANAGER->registerActionPlaceHolder(qti_action_EDIT_CUT,QObject::tr("Cut"),QKeySequence(QKeySequence::Cut));
edit_menu->addAction(command);
// We want to use paste operations in this application, thus initialize the clipboard.
// It is important to do this after registering the copy, cut and paste action holders above.
// The initialization will register backends for these actions.
CLIPBOARD_MANAGER->initialize();

The operation and intended usage of the clipboard manager is best shown using an example, thus we look at a shortened version of the copy, cut and paste action handlers taken from the Qtilities::CoreGui::ObserverWidget class' sources.

First we look at the observer widget's copy action handler implementation:

ObserverMimeData *mimeData = new ObserverMimeData(selectedObjects(),current_observer_ID);
QApplication::clipboard()->setMimeData(mimeData);
CLIPBOARD_MANAGER->setClipboardOrigin(IClipboard::CopyAction);

Next we look at the observer widget's cut action handler implementation:

ObserverMimeData *mimeData = new ObserverMimeData(selectedObjects(),current_observer_ID);
QApplication::clipboard()->setMimeData(mimeData);
CLIPBOARD_MANAGER->setClipboardOrigin(IClipboard::CutAction);

Finaly we look at the observer widget's paste action handler implementation:

const ObserverMimeData* observer_mime_data = qobject_cast<const ObserverMimeData*> (QApplication::clipboard()->mimeData());
if (observer_mime_data) {
if (current_observer->canAttach(const_cast<ObserverMimeData*> (observer_mime_data)) == Qtilities::Core::Observer::Allowed) {
// Now check the proposed action of the event.
if (CLIPBOARD_MANAGER->clipboardOrigin() == IClipboard::CutAction) {
OBJECT_MANAGER->moveSubjects(observer_mime_data->subjectList(),observer_mime_data->sourceID(),current_observer_ID);
// Accept the data, thus the paste action will be disabled and the clipboard cleared.
CLIPBOARD_MANAGER->acceptMimeData();
} else if (CLIPBOARD_MANAGER->clipboardOrigin() == IClipboard::CopyAction) {
// Attempt to copy the objects
// For now we discard objects that cause problems during attachment and detachment
for (int i = 0; i < observer_mime_data->subjectList().count(); i++) {
// Attach to destination
current_observer->attachSubject(observer_mime_data->subjectList().at(i));
}
// Accept the data, thus the paste action will be disabled and the clipboard cleared.
CLIPBOARD_MANAGER->acceptMimeData();
}
}
}

Member Enumeration Documentation

Enumeration which is used to indicate if a copy or a cut operation caused the clipboard to change.

See also:
setClipboardOrigin(), clipboardOrigin()
Enumerator:
CopyAction 

A copy action changed the clipboard.

CutAction 

A cut action changed the clipboard.

Unspecified 

An unspecified action changed the clipboard.



Qtilities : Reference Documentation Back to top Copyright © 2009-2013, Jaco Naudé