Debian Codegraph @

avogadro/qtgui/toolplugin.h

raw
1 /******************************************************************************
2 This source file is part of the Avogadro project.
3 This source code is released under the 3-Clause BSD License, (see "LICENSE").
4 ******************************************************************************/
5
6 #ifndef AVOGADRO_QTGUI_TOOLPLUGIN_H
7 #define AVOGADRO_QTGUI_TOOLPLUGIN_H
8
9 #include "avogadroqtguiexport.h"
10
11 #include <QtCore/QObject>
12
13 class QAction;
14 class QKeyEvent;
15 class QMouseEvent;
16 class QUndoCommand;
17 class QWheelEvent;
18
19 namespace Avogadro {
20
21 namespace Rendering {
22 class GroupNode;
23 class GLRenderer;
24 } // namespace Rendering
25
26 namespace QtOpenGL {
27 class GLWidget;
28 }
29
30 namespace QtGui {
31 class Molecule;
32 class RWMolecule;
33
34 /**
35 * @class ToolPlugin toolplugin.h <avogadro/qtgui/toolplugin.h>
36 * @brief The base class for plugins that interact with QtOpenGL::GLWidget.
37 * @author Allison Vacanti
38 */
39 class AVOGADROQTGUI_EXPORT ToolPlugin : public QObject
40 {
41 Q_OBJECT
42
43 public:
44 explicit ToolPlugin(QObject* parent = nullptr);
45 ~ToolPlugin() override;
46
47 /**
48 * The name of the tool, will be displayed in the user interface.
49 */
50 virtual QString name() const = 0;
51
52 /**
53 * A description of the tool, may be displayed in the user interface.
54 */
55 virtual QString description() const = 0;
56
57 /**
58 * A priority of the tool for sorting in the user interface.
59 */
60 virtual unsigned char priority() const = 0;
61
62 /**
63 * @return The QAction that will cause this tool to become active.
64 */
65 virtual QAction* activateAction() const = 0;
66
67 /**
68 * Set the tool icon (based on dark / light theme).
69 */
70 virtual void setIcon(bool darkTheme = false) = 0;
71
72 /**
73 * @return A QWidget that will be displayed to the user while this tool is
74 * active.
75 */
76 virtual QWidget* toolWidget() const = 0;
77
78 /**
79 * Respond to user-input events.
80 * @param e The QEvent object.
81 * @return A QUndoCommand that can be used to undo any changes to the
82 * molecule. If no undoable change is made, the method may return nullptr.
83 * @{
84 */
85 virtual QUndoCommand* mousePressEvent(QMouseEvent* e);
86 virtual QUndoCommand* mouseReleaseEvent(QMouseEvent* e);
87 virtual QUndoCommand* mouseMoveEvent(QMouseEvent* e);
88 virtual QUndoCommand* mouseDoubleClickEvent(QMouseEvent* e);
89 virtual QUndoCommand* wheelEvent(QWheelEvent* e);
90 virtual QUndoCommand* keyPressEvent(QKeyEvent* e);
91 virtual QUndoCommand* keyReleaseEvent(QKeyEvent* e);
92 /**@}*/
93
94 /**
95 * Override this method to add drawables to the scene graph.
96 */
97 virtual void draw(Rendering::GroupNode& node);
98
99 /**
100 * Called by the app to handle a command registered by the plugin.
101 * (e.g., "renderMovie" or "drawAtom", etc.)
102 *
103 * The app will turn the command into a string and pass it to the tool.
104 * and any options will go from a JSON dictionary to a QVariantMap.
105 *
106 * @return true if the command was handled, false otherwise.
107 */
108 virtual bool handleCommand(const QString& command,
109 const QVariantMap& options);
110
111 /**
112 * Called by the app to tell the tool to register commands.
113 * If the tool has commands, it should emit the registerCommand signals.
114 */
115 virtual void registerCommands() {}
116
117 signals:
118 /**
119 * Emitted when draw() needs to be called again due to updates.
120 */
121 void drawablesChanged();
122
123 /**
124 * Emitted when something changed (camera, etc) and the molecule should be
125 * redrawn.
126 */
127 void updateRequested();
128
129 /**
130 * Register a new command with the application. The command will be available
131 * through scripting (e.g., "renderMovie" or "generateSurface", etc.)
132 *
133 * @param command The name of the command to register.
134 * @param description A description of the command.
135 *
136 * @sa handleCommand
137 */
138 void registerCommand(QString command, QString description);
139
140 /**
141 * Request a specific display type (or types) are made active.
142 * This can be useful when loading a specific type of data that
143 * would be most readily viewed with a specialized view.
144 */
145 void requestActiveDisplayTypes(QStringList displayTypes);
146
147 /**
148 * Indicate that a particular script command is finished.
149 * (e.g., from handleCommand)
150 * @param message An optional message to the script or user
151 */
152 void commandFinished(const QString& message = QString());
153
154 public slots:
155 /**
156 * Called when the current molecule changes.
157 */
158 virtual void setMolecule(QtGui::Molecule* mol) = 0;
159 virtual void setEditMolecule(QtGui::RWMolecule*) {}
160
161 /**
162 * Set the GLWidget used by the tool.
163 */
164 virtual void setGLWidget(QtOpenGL::GLWidget*) {}
165
166 /**
167 * Set the active widget used by the tool, this can be anything derived from
168 * QWidget.
169 */
170 virtual void setActiveWidget(QWidget*) {}
171
172 /**
173 * Set the GLRenderer used by the tool.
174 */
175 virtual void setGLRenderer(Rendering::GLRenderer*) {}
176 };
177
178 /**
179 * @class ToolPluginFactory toolplugin.h <avogadro/qtgui/toolplugin.h>
180 * @brief The base class for tool plugin factories in Avogadro.
181 * @author Allison Vacanti
182 */
183 class AVOGADROQTGUI_EXPORT ToolPluginFactory
184 {
185 public:
186 virtual ~ToolPluginFactory();
187
188 virtual ToolPlugin* createInstance(QObject* parent = nullptr) = 0;
189 virtual QString identifier() const = 0;
190 virtual QString description() const = 0;
191 };
192
193 } // namespace QtGui
194 } // namespace Avogadro
195
196 Q_DECLARE_INTERFACE(Avogadro::QtGui::ToolPluginFactory,
197 "org.openchemistry.avogadro.ToolPluginFactory")
198
199 #endif // AVOGADRO_QTGUI_TOOLPLUGIN_H