diff --git a/avogadro/qtplugins/navigator/navigator.cpp b/avogadro/qtplugins/navigator/navigator.cpp index d901615a6..331aaf2a8 100644 --- a/avogadro/qtplugins/navigator/navigator.cpp +++ b/avogadro/qtplugins/navigator/navigator.cpp @@ -13,12 +13,13 @@ #include #include -#include +#include +#include #include +#include #include #include #include -#include #include #include @@ -42,11 +43,49 @@ Navigator::Navigator(QObject* parent_) "Left Mouse: \tClick and drag to rotate the view.\n" "Middle Mouse: \tClick and drag to zoom in or out.\n" "Right Mouse: \tClick and drag to move the view.\n")); - + QSettings settings; m_zoomDirection = settings.value("navigator/zoom", 1).toInt(); } +void Navigator::registerCommands() +{ + emit registerCommand("rotateScene", + tr("Rotate the scene along the x, y, or z axes.")); + emit registerCommand("zoomScene", tr("Zoom the scene.")); + emit registerCommand("translateScene", tr("Translate the scene.")); +} + +bool Navigator::handleCommand(const QString& command, + const QVariantMap& options) +{ + if (m_renderer == nullptr) + return false; // No camera + + if (command == "rotateScene") { + float x = options.value("x").toFloat(); + float y = options.value("y").toFloat(); + float z = options.value("z").toFloat(); + rotate(m_renderer->camera().focus(), x, y, z); + + m_glWidget->requestUpdate(); + } else if (command == "zoomScene") { + float d = options.value("delta").toFloat(); + zoom(m_renderer->camera().focus(), d); + m_glWidget->requestUpdate(); + } else if (command == "translateScene") { + float x = options.value("x").toFloat(); + float y = options.value("y").toFloat(); + translate(m_renderer->camera().focus(), x, y); + m_glWidget->requestUpdate(); + } else { + qDebug() << "Unknown command: " << command; + return false; + } + + return true; +} + Navigator::~Navigator() {} QWidget* Navigator::toolWidget() const @@ -55,8 +94,7 @@ QWidget* Navigator::toolWidget() const m_toolWidget = new QWidget(qobject_cast(parent())); auto* layout = new QVBoxLayout; - auto* swapZoom = - new QCheckBox(tr("Reverse Direction of Zoom on Scroll")); + auto* swapZoom = new QCheckBox(tr("Reverse Direction of Zoom on Scroll")); swapZoom->setToolTip( tr("Default:\t Scroll down to shrink, scroll up to zoom\n" "Reversed:\t Scroll up to shrink, scroll down to zoom")); @@ -169,7 +207,8 @@ QUndoCommand* Navigator::wheelEvent(QWheelEvent* e) QPoint numDegrees = e->angleDelta() * 0.125; // see https://doc.qt.io/qt-5/qwheelevent.html#pixelDelta - if (!numPixels.isNull() && QGuiApplication::platformName().toStdString().compare("xcb")) + if (!numPixels.isNull() && + QGuiApplication::platformName().toStdString().compare("xcb")) d = numPixels.y(); // use pixelDelta() when available, except on X11 else if (!numDegrees.isNull()) d = numDegrees.y(); // fall back to angleDelta() @@ -299,4 +338,4 @@ inline void Navigator::translate(const Vector3f& ref, const Vector2f& fromScr, m_renderer->camera().translate(to - from); } -} // namespace Avogadro +} // namespace Avogadro::QtPlugins diff --git a/avogadro/qtplugins/navigator/navigator.h b/avogadro/qtplugins/navigator/navigator.h index ee1d1ec05..8a1cd7344 100644 --- a/avogadro/qtplugins/navigator/navigator.h +++ b/avogadro/qtplugins/navigator/navigator.h @@ -49,6 +49,11 @@ class Navigator : public QtGui::ToolPlugin QUndoCommand* keyPressEvent(QKeyEvent* e) override; QUndoCommand* keyReleaseEvent(QKeyEvent* e) override; + bool handleCommand(const QString& command, + const QVariantMap& options) override; + + void registerCommands() override; + protected slots: void swapZoomDirection(bool checked);