| 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_MANIPULATOR_H |
| 7 |
#define AVOGADRO_QTPLUGINS_MANIPULATOR_H |
| 8 |
|
| 9 |
#include <avogadro/qtgui/toolplugin.h> |
| 10 |
|
| 11 |
#include <avogadro/qtgui/molecule.h> |
| 12 |
#include <avogadro/rendering/primitive.h> |
| 13 |
|
| 14 |
#include <QtCore/QPoint> |
| 15 |
#include <QtCore/Qt> // for Qt:: namespace |
| 16 |
#include <QtWidgets/QAbstractButton> |
| 17 |
|
| 18 |
namespace Avogadro { |
| 19 |
namespace QtPlugins { |
| 20 |
|
| 21 |
class ManipulateWidget; |
| 22 |
|
| 23 |
/** |
| 24 |
* @class Manipulator manipulator.h |
| 25 |
* <avogadro/qtplugins/manipulator/manipulator.h> |
| 26 |
* @brief The Manipulator class manipulates a molecule's geometry. |
| 27 |
* @author Allison Vacanti |
| 28 |
*/ |
| 29 |
class Manipulator : public QtGui::ToolPlugin |
| 30 |
{ |
| 31 |
Q_OBJECT |
| 32 |
public: |
| 33 |
explicit Manipulator(QObject* parent_ = nullptr); |
| 34 |
~Manipulator() override; |
| 35 |
|
| 36 |
QString name() const override { return tr("Manipulate tool"); } |
| 37 |
QString description() const override { return tr("Manipulate tool"); } |
| 38 |
unsigned char priority() const override { return 30; } |
| 39 |
QAction* activateAction() const override { return m_activateAction; } |
| 40 |
QWidget* toolWidget() const override; |
| 41 |
|
| 42 |
void setIcon(bool darkTheme = false) override; |
| 43 |
|
| 44 |
void setMolecule(QtGui::Molecule* mol) override |
| 45 |
{ |
| 46 |
if (mol) |
| 47 |
m_molecule = mol->undoMolecule(); |
| 48 |
} |
| 49 |
|
| 50 |
void setEditMolecule(QtGui::RWMolecule* mol) override { m_molecule = mol; } |
| 51 |
|
| 52 |
void setGLRenderer(Rendering::GLRenderer* renderer) override |
| 53 |
{ |
| 54 |
m_renderer = renderer; |
| 55 |
} |
| 56 |
|
| 57 |
QUndoCommand* mousePressEvent(QMouseEvent* e) override; |
| 58 |
QUndoCommand* mouseReleaseEvent(QMouseEvent* e) override; |
| 59 |
QUndoCommand* mouseMoveEvent(QMouseEvent* e) override; |
| 60 |
QUndoCommand* keyPressEvent(QKeyEvent* e) override; |
| 61 |
|
| 62 |
public slots: |
| 63 |
void buttonClicked(QAbstractButton* button); |
| 64 |
|
| 65 |
private: |
| 66 |
/** |
| 67 |
* Update the currently pressed buttons, accounting for modifier keys. |
| 68 |
* \todo Account for modifier keys. |
| 69 |
*/ |
| 70 |
void updatePressedButtons(QMouseEvent*, bool release); |
| 71 |
|
| 72 |
void resetObject() { m_object = Rendering::Identifier(); } |
| 73 |
void translate(Vector3 delta, bool moveSelected = true); |
| 74 |
void rotate(Vector3 delta, Vector3 centroid, bool moveSelected = true); |
| 75 |
void axisRotate(Vector3 delta, Vector3 centroid, bool moveSelected = true); |
| 76 |
void tilt(Vector3 delta, Vector3 centroid); |
| 77 |
|
| 78 |
QAction* m_activateAction; |
| 79 |
QtGui::RWMolecule* m_molecule; |
| 80 |
Rendering::GLRenderer* m_renderer; |
| 81 |
Rendering::Identifier m_object; |
| 82 |
QPoint m_lastMousePosition; |
| 83 |
Vector3f m_lastMouse3D; |
| 84 |
Qt::MouseButtons m_pressedButtons; |
| 85 |
ManipulateWidget* m_toolWidget; |
| 86 |
|
| 87 |
enum ToolAction |
| 88 |
{ |
| 89 |
Nothing = 0, |
| 90 |
Rotation, |
| 91 |
Translation, |
| 92 |
ZoomTilt, |
| 93 |
Zoom |
| 94 |
}; |
| 95 |
ToolAction m_currentAction; |
| 96 |
}; |
| 97 |
|
| 98 |
} // namespace QtPlugins |
| 99 |
} // namespace Avogadro |
| 100 |
|
| 101 |
#endif // AVOGADRO_QTOPENGL_MANIPULATOR_H |