/usr/include/tulip/Interactor.h is in libtulip-dev 4.8.0dfsg-2build2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 | /*
*
* This file is part of Tulip (www.tulip-software.org)
*
* Authors: David Auber and the Tulip development Team
* from LaBRI, University of Bordeaux
*
* Tulip is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation, either version 3
* of the License, or (at your option) any later version.
*
* Tulip is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
*/
#ifndef _INTERACTOR_H
#define _INTERACTOR_H
#include <tulip/Plugin.h>
#include <QObject>
#include <QCursor>
#include <QMap>
#include <string>
class QAction;
namespace tlp {
static const std::string INTERACTOR_CATEGORY = "Interactor";
class View;
/**
@ingroup Plugins
@brief Interactor provides a way to handle user inputs over a view.
Basically, The interactor class is an overlay to the Qt's event filtering mechanism. It adds several features like the ability to define priorities, custom cursors, etc
When an interactor is constructed, the following methods are called in this order:
@li The constructor. This method should almost be a no-op. Interactors may be instantiated by the plugin manager system and doing unneeded operations in the constructor may lead to poor performances when the application loads up.
@li isCompatible. When creating a View, the application will check for all interactors to see if they could be installed on it. This is done using the isCompatible method.
@li construct. Initialize the interactor. Since the constructor should be a no-op, initialization code should be put here.
@li setView. Defines the view this interactor is bound to. The Interactor may keep a reference to the view object to perform specific operations on user inputs.
Methods listed above are only called once. Once the interactor is initialized, it may be installed/removed several times on different QObjects. It will then repond to user inputs via the eventFilter method
@see QObject::eventFilter()
*/
class TLP_QT_SCOPE Interactor: public QObject, public Plugin {
Q_OBJECT
Q_PROPERTY(unsigned int priority READ priority)
Q_PROPERTY(QAction* action READ action)
Q_PROPERTY(tlp::View* view READ view WRITE setView)
Q_PROPERTY(QCursor cursor READ cursor)
public:
virtual std::string category() const {
return INTERACTOR_CATEGORY;
}
std::string icon() const {
return ":/tulip/gui/icons/32/plugin_interactor.png";
}
/**
@brief Checks the compatibility between the interactor and the given view (identified by its name).
If this method returns true, it's very likely that the interactor will be installed on the associated view.
*/
virtual bool isCompatible(const std::string& viewName) const=0;
/**
@return the configuration widget used to set up the interactor.
@warning This method MUST ALWAYS return the same pointer. Doing otherwise may lead to memory leaks.
@note The configuration widget has to be instantiated from the construct method.
@note It is up to the interactor developper to delete the configuration widget
*/
virtual QWidget* configurationWidget() const=0;
/**
@return the interactor's priority.
Priority defines how interactors gets ordered when displayed in the View's toolbar.
Interactors with the top-most priority value will be displayed at the beginning of the list while lowest priority will be position at the end.
*/
virtual unsigned int priority() const=0;
/**
@return a QAction associated to this interactor.
This is used by the overleying system to associate an icon/text to the interactor.
@warning The parent (QObject::parent()) object of this QAction MUST BE the Interactor.
*/
virtual QAction* action() const=0;
/**
@return the View object associated to this Interactor.
@warning The returned object MUST be the same as the one passed down to the setView method.
*/
virtual tlp::View* view() const=0;
/**
@return The cursor associated to this interactor.
When the interactor gets active on a view, the View's cursor is changed to what this method returns.
*/
virtual QCursor cursor() const=0;
/**
@brief Builds up the interactor's internal state.
This method should be used instead of the constructor to initialize the interactor.
*/
virtual void construct()=0;
public slots:
/**
@brief Defines the view object associated to this interactor.
@warning The view() method MUST ALWAYS return the same pointer as the one passed down to this method.
*/
virtual void setView(tlp::View*)=0;
/**
@brief Install the interactor on the given target
A call to this method means thatr the interactor should start listening to the target's events and handle them.
Returning true prevents further handling of the event. Doing otherwise means that the interactor will let following filters to hand over this kind of event.
*/
virtual void install(QObject* target)=0;
/**
@brief Removes the interactor from the previously set target.
Interactors can be installed on only one target at once.
*/
virtual void uninstall()=0;
/**
@brief Informs the interactor when the undo command (Ctrl+Z) has been triggered
*/
virtual void undoIsDone()=0;
protected:
/**
@brief Provides input filtering for the interactor
@see QObject::eventFilter()
*/
inline virtual bool eventFilter(QObject* obj, QEvent* ev) {
return QObject::eventFilter(obj,ev);
}
};
/**
* @ingroup Plugins
* @brief The InteractorLister class lists compatible interactors for a given tlp::View
*/
class TLP_QT_SCOPE InteractorLister {
static QMap<std::string,QList<std::string> > _compatibilityMap;
public:
static void initInteractorsDependencies();
static QList<std::string> compatibleInteractors(const std::string& viewName);
};
/**
* @ingroup Plugins
* @def INTERACTORPLUGINVIEWEXTENSION(CLASS_NAME,STRING_CLASS_NAME,BASE_INTERACTOR_STRING_NAME,VIEW_STRING_NAME,AUTHOR,DATE,DESCRIPTION,VERSION)
*
* @brief Copy an existing Tulip interactor and sets it compatible with a given View.
*
* This macro is used when you're making your own View and want to use an existing interactor with it. Interactors are declared to be compatible with a list of View. This macro extends the compatibility of an existing interactor by subclassing it.
*
* @note: This macro used the same interactor priority as the base interactor. To define your own priority, see INTERACTORPLUGINVIEWEXTENSIONWITHPRIORITY
*
* @param CLASS_NAME The name of the interactor class to generate.
* @param STRING_CLASS_NAME The name of the interactor plugin to generate (see tlp::Plugin::name())
* @param BASE_INTERACTOR_STRING_NAME The name of the interactor to extend
* @param VIEW_STRING_NAME The name of the View to set the interactor compatible with
* @param AUTHOR see tlp::Plugin::author()
* @param DATE see tlp::Plugin::date()
* @param DESCRIPTION see tlp::Plugin::info()
* @param VERSION see tlp::Plugin::version()
*/
#define INTERACTORPLUGINVIEWEXTENSION(CLASS_NAME,STRING_CLASS_NAME,BASE_INTERACTOR_STRING_NAME,VIEW_STRING_NAME,AUTHOR,DATE,DESCRIPTION,VERSION)\
class CLASS_NAME : public tlp::Interactor {\
mutable tlp::Interactor* _component;\
public:\
std::string name() const { return std::string(STRING_CLASS_NAME); } \
std::string author() const { return std::string(AUTHOR); }\
std::string date() const { return std::string(DATE); } \
std::string info() const { return std::string(DESCRIPTION); } \
std::string release() const { return std::string(VERSION); }\
std::string tulipRelease() const { return std::string(TULIP_VERSION); }\
std::string group() const { return getComponent()->group(); }\
CLASS_NAME(const PluginContext *):_component(NULL) {}\
bool isCompatible(const std::string& viewName) const { return viewName == VIEW_STRING_NAME; }\
QWidget* configurationWidget() const { return getComponent()->configurationWidget(); }\
unsigned int priority() const { return getComponent()->priority(); }\
QAction* action() const { return getComponent()->action(); }\
tlp::View* view() const { return getComponent()->view(); }\
QCursor cursor() const { return getComponent()->cursor(); }\
void construct() { getComponent()->construct(); }\
void setView(tlp::View* v) { getComponent()->setView(v); }\
void install(QObject* target) { getComponent()->install(target); }\
void uninstall() { getComponent()->uninstall(); }\
void undoIsDone() { getComponent()->undoIsDone(); }\
tlp::Interactor* getComponent() const {\
if(!_component) {\
_component = tlp::PluginLister::instance()->getPluginObject<Interactor>(BASE_INTERACTOR_STRING_NAME,NULL); assert(_component != NULL);\
}\
return _component;\
}\
};\
PLUGIN(CLASS_NAME)
/**
* @ingroup Plugins
* @def INTERACTORPLUGINVIEWEXTENSIONWITHPRIORITY(CLASS_NAME,STRING_CLASS_NAME,BASE_INTERACTOR_STRING_NAME,VIEW_STRING_NAME,AUTHOR,DATE,DESCRIPTION,VERSION,PRIORITY)
* @brief Similar to INTERACTORPLUGINVIEWEXTENSION but allows to define the generated interactor's priority.
* @see tlp::Interactor::priority()
* @see INTERACTORPLUGINVIEWEXTENSION
*/
#define INTERACTORPLUGINVIEWEXTENSIONWITHPRIORITY(CLASS_NAME,STRING_CLASS_NAME,BASE_INTERACTOR_STRING_NAME,VIEW_STRING_NAME,AUTHOR,DATE,DESCRIPTION,VERSION,PRIORITY) \
class CLASS_NAME : public tlp::Interactor {\
mutable tlp::Interactor* _component;\
public:\
std::string name() const { return std::string(STRING_CLASS_NAME); } \
std::string author() const { return std::string(AUTHOR); }\
std::string date() const { return std::string(DATE); } \
std::string info() const { return std::string(DESCRIPTION); } \
std::string release() const { return std::string(VERSION); }\
std::string tulipRelease() const { return std::string(TULIP_VERSION); }\
std::string group() const { return getComponent()->group(); }\
CLASS_NAME(const PluginContext *):_component(NULL) {}\
bool isCompatible(const std::string& viewName) const { return viewName == VIEW_STRING_NAME; }\
QWidget* configurationWidget() const { return getComponent()->configurationWidget(); }\
unsigned int priority() const { return PRIORITY; }\
QAction* action() const { return getComponent()->action(); }\
tlp::View* view() const { return getComponent()->view(); }\
QCursor cursor() const { return getComponent()->cursor(); }\
void construct() { getComponent()->construct(); }\
void setView(tlp::View* v) { getComponent()->setView(v); }\
void install(QObject* target) { getComponent()->install(target); }\
void uninstall() { getComponent()->uninstall(); }\
void undoIsDone() { getComponent()->undoIsDone(); }\
tlp::Interactor* getComponent() const {\
if(!_component) {\
_component = tlp::PluginLister::instance()->getPluginObject<Interactor>(BASE_INTERACTOR_STRING_NAME,NULL); assert(_component != NULL);\
}\
return _component;\
}\
};\
PLUGIN(CLASS_NAME)
}
#endif
|