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