Debian Codegraph @

avogadro/qtplugins/templatetool/templatetool.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_QTPLUGINS_TEMPLATE_H
7 #define AVOGADRO_QTPLUGINS_TEMPLATE_H
8
9 #include <avogadro/qtgui/toolplugin.h>
10
11 #include <avogadro/core/avogadrocore.h>
12 #include <avogadro/qtgui/molecule.h>
13 #include <avogadro/qtgui/pluginlayermanager.h>
14 #include <avogadro/rendering/primitive.h>
15
16 #include <QtCore/QPoint>
17
18 namespace Avogadro {
19 namespace QtPlugins {
20 class TemplateToolWidget;
21
22 /**
23 * @class TemplateTool templatetool.h
24 <avogadro/qtplugins/templatetool/templatetool.h>
25 * @brief The Template tool inserts fragments, including metal centers.
26 * @author Geoffrey R. Hutchison, Aritz, Erkiaga
27
28 */
29 class TemplateTool : public QtGui::ToolPlugin
30 {
31 Q_OBJECT
32 public:
33 explicit TemplateTool(QObject* parent_ = nullptr);
34 ~TemplateTool() override;
35
36 QString name() const override { return tr("Template tool"); }
37 QString description() const override { return tr("Template tool"); }
38 unsigned char priority() const override { return 21; }
39 QAction* activateAction() const override { return m_activateAction; }
40 QWidget* toolWidget() const override;
41 void setIcon(bool darkTheme = false) override;
42
43 void setMolecule(QtGui::Molecule* mol) override
44 {
45 if (mol)
46 m_molecule = mol->undoMolecule();
47 }
48
49 void setEditMolecule(QtGui::RWMolecule* mol) override { m_molecule = mol; }
50
51 void setGLWidget(QtOpenGL::GLWidget* widget) override { m_glWidget = widget; }
52
53 void setGLRenderer(Rendering::GLRenderer* renderer) override
54 {
55 m_renderer = renderer;
56 }
57
58 QUndoCommand* mousePressEvent(QMouseEvent* e) override;
59 QUndoCommand* mouseReleaseEvent(QMouseEvent* e) override;
60 QUndoCommand* mouseMoveEvent(QMouseEvent* e) override;
61 QUndoCommand* keyPressEvent(QKeyEvent* e) override;
62
63 void draw(Rendering::GroupNode& node) override;
64
65 private slots:
66 void clearKeyPressBuffer() { m_keyPressBuffer.clear(); }
67
68 private:
69 /**
70 * Update the currently pressed buttons, accounting for modifier keys.
71 * @todo Account for modifier keys.
72 */
73 void updatePressedButtons(QMouseEvent*, bool release);
74
75 /**
76 * Reset all state for this tool.
77 */
78 void reset();
79
80 void emptyLeftClick(QMouseEvent* e);
81 void atomLeftClick(QMouseEvent* e);
82 void bondLeftClick(QMouseEvent* e);
83
84 void atomRightClick(QMouseEvent* e);
85 void bondRightClick(QMouseEvent* e);
86
87 void atomLeftDrag(QMouseEvent* e);
88
89 QAction* m_activateAction;
90 QtGui::RWMolecule* m_molecule;
91 QtOpenGL::GLWidget* m_glWidget;
92 Rendering::GLRenderer* m_renderer;
93 TemplateToolWidget* m_toolWidget;
94 Rendering::Identifier m_clickedObject;
95 Rendering::Identifier m_newObject;
96 Rendering::Identifier m_bondedAtom;
97 Qt::MouseButtons m_pressedButtons;
98 QPoint m_clickPosition;
99 unsigned char m_clickedAtomicNumber;
100 bool m_bondAdded;
101 bool m_fixValenceLater;
102 QString m_keyPressBuffer;
103
104 QtGui::PluginLayerManager m_layerManager;
105
106 Real m_bondDistance;
107 };
108
109 } // namespace QtPlugins
110 } // namespace Avogadro
111
112 #endif // AVOGADRO_QTPLUGINS_NAVIGATOR_H