| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
#ifndef AVOGADRO_QTPLUGINS_NAVIGATOR_H |
| 7 |
#define AVOGADRO_QTPLUGINS_NAVIGATOR_H |
| 8 |
|
| 9 |
#include <avogadro/qtgui/toolplugin.h> |
| 10 |
|
| 11 |
#include <avogadro/core/vector.h> |
| 12 |
|
| 13 |
#include <QtCore/QPoint> |
| 14 |
#include <QtCore/Qt> |
| 15 |
|
| 16 |
namespace Avogadro { |
| 17 |
namespace QtPlugins { |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
class Navigator : public QtGui::ToolPlugin |
| 25 |
{ |
| 26 |
Q_OBJECT |
| 27 |
public: |
| 28 |
explicit Navigator(QObject* parent_ = nullptr); |
| 29 |
~Navigator() override; |
| 30 |
|
| 31 |
QString name() const override { return tr("Navigate tool"); } |
| 32 |
QString description() const override { return tr("Navigate tool"); } |
| 33 |
unsigned char priority() const override { return 10; } |
| 34 |
QAction* activateAction() const override { return m_activateAction; } |
| 35 |
QWidget* toolWidget() const override; |
| 36 |
void setIcon(bool darkTheme = false) override; |
| 37 |
|
| 38 |
void setMolecule(QtGui::Molecule* mol) override { m_molecule = mol; } |
| 39 |
void setGLWidget(QtOpenGL::GLWidget* widget) override { m_glWidget = widget; } |
| 40 |
void setGLRenderer(Rendering::GLRenderer* renderer) override |
| 41 |
{ |
| 42 |
m_renderer = renderer; |
| 43 |
} |
| 44 |
|
| 45 |
QUndoCommand* mousePressEvent(QMouseEvent* e) override; |
| 46 |
QUndoCommand* mouseReleaseEvent(QMouseEvent* e) override; |
| 47 |
QUndoCommand* mouseMoveEvent(QMouseEvent* e) override; |
| 48 |
QUndoCommand* mouseDoubleClickEvent(QMouseEvent* e) override; |
| 49 |
QUndoCommand* wheelEvent(QWheelEvent* e) override; |
| 50 |
QUndoCommand* keyPressEvent(QKeyEvent* e) override; |
| 51 |
QUndoCommand* keyReleaseEvent(QKeyEvent* e) override; |
| 52 |
|
| 53 |
bool handleCommand(const QString& command, |
| 54 |
const QVariantMap& options) override; |
| 55 |
|
| 56 |
void registerCommands() override; |
| 57 |
|
| 58 |
protected slots: |
| 59 |
void swapZoomDirection(bool checked); |
| 60 |
|
| 61 |
private: |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
void updatePressedButtons(QMouseEvent*, bool release); |
| 67 |
|
| 68 |
void rotate(const Vector3f& ref, float x, float y, float z); |
| 69 |
void zoom(const Vector3f& ref, float d); |
| 70 |
void translate(const Vector3f& ref, float x, float y); |
| 71 |
void translate(const Vector3f& ref, const Vector2f& from, const Vector2f& to); |
| 72 |
|
| 73 |
QAction* m_activateAction; |
| 74 |
QtGui::Molecule* m_molecule; |
| 75 |
QtOpenGL::GLWidget* m_glWidget; |
| 76 |
mutable QWidget* m_toolWidget; |
| 77 |
Rendering::GLRenderer* m_renderer; |
| 78 |
Qt::MouseButtons m_pressedButtons; |
| 79 |
QPoint m_lastMousePosition; |
| 80 |
int m_zoomDirection; |
| 81 |
|
| 82 |
enum ToolAction |
| 83 |
{ |
| 84 |
Nothing = 0, |
| 85 |
Rotation, |
| 86 |
Translation, |
| 87 |
ZoomTilt, |
| 88 |
Zoom |
| 89 |
}; |
| 90 |
ToolAction m_currentAction; |
| 91 |
}; |
| 92 |
|
| 93 |
} |
| 94 |
} |
| 95 |
|
| 96 |
#endif |