From d8fa3fd1de1d8e64b0bb774d7d982262ae7a9d7a Mon Sep 17 00:00:00 2001 From: Aesylwinn Date: Sun, 17 Jul 2016 19:36:33 -0400 Subject: [PATCH] Added orbit "center on selection" shortcut. --- apps/opencs/view/render/orbitcameramode.cpp | 26 +++++++++++++++++--- apps/opencs/view/render/orbitcameramode.hpp | 14 +++++++++-- apps/opencs/view/render/worldspacewidget.cpp | 2 +- 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/apps/opencs/view/render/orbitcameramode.cpp b/apps/opencs/view/render/orbitcameramode.cpp index e6f3612c6..6c4fb1f1e 100644 --- a/apps/opencs/view/render/orbitcameramode.cpp +++ b/apps/opencs/view/render/orbitcameramode.cpp @@ -2,22 +2,42 @@ #include +#include "../../model/prefs/shortcut.hpp" +#include "../../model/prefs/shortcuteventhandler.hpp" + #include "worldspacewidget.hpp" namespace CSVRender { - OrbitCameraMode::OrbitCameraMode(WorldspaceWidget* worldspaceWidget, const QIcon& icon, const QString& tooltip, - QWidget* parent) + OrbitCameraMode::OrbitCameraMode(WorldspaceWidget* worldspaceWidget, CSMPrefs::ShortcutEventHandler* handler, + const QIcon& icon, const QString& tooltip, QWidget* parent) : ModeButton(icon, tooltip, parent) , mWorldspaceWidget(worldspaceWidget) + , mShortcutHandler(handler) , mCenterOnSelection(0) { + mCenterShortcut = new CSMPrefs::Shortcut("orbit-center-selection", this); + mCenterShortcut->enable(false); + mShortcutHandler->addShortcut(mCenterShortcut); + connect(mCenterShortcut, SIGNAL(activated()), this, SLOT(centerSelection())); + } + + OrbitCameraMode::~OrbitCameraMode() + { + mShortcutHandler->removeShortcut(mCenterShortcut); } void OrbitCameraMode::activate(CSVWidget::SceneToolbar* toolbar) { - mCenterOnSelection = new QAction("Center on selected object", this); + mCenterOnSelection = new QAction("Center on selected object\t" + mCenterShortcut->toString(), this); connect(mCenterOnSelection, SIGNAL(triggered()), this, SLOT(centerSelection())); + + mCenterShortcut->enable(true); + } + + void OrbitCameraMode::deactivate(CSVWidget::SceneToolbar* toolbar) + { + mCenterShortcut->enable(false); } bool OrbitCameraMode::createContextMenu(QMenu* menu) diff --git a/apps/opencs/view/render/orbitcameramode.hpp b/apps/opencs/view/render/orbitcameramode.hpp index cd8387084..990999b22 100644 --- a/apps/opencs/view/render/orbitcameramode.hpp +++ b/apps/opencs/view/render/orbitcameramode.hpp @@ -3,6 +3,12 @@ #include "../widget/modebutton.hpp" +namespace CSMPrefs +{ + class Shortcut; + class ShortcutEventHandler; +} + namespace CSVRender { class WorldspaceWidget; @@ -13,16 +19,20 @@ namespace CSVRender public: - OrbitCameraMode(WorldspaceWidget* worldspaceWidget, const QIcon& icon, const QString& tooltip = "", - QWidget* parent = 0); + OrbitCameraMode(WorldspaceWidget* worldspaceWidget, CSMPrefs::ShortcutEventHandler* shortcutHandler, + const QIcon& icon, const QString& tooltip = "", QWidget* parent = 0); + ~OrbitCameraMode(); virtual void activate(CSVWidget::SceneToolbar* toolbar); + virtual void deactivate(CSVWidget::SceneToolbar* toolbar); virtual bool createContextMenu(QMenu* menu); private: WorldspaceWidget* mWorldspaceWidget; + CSMPrefs::ShortcutEventHandler* mShortcutHandler; QAction* mCenterOnSelection; + CSMPrefs::Shortcut* mCenterShortcut; private slots: diff --git a/apps/opencs/view/render/worldspacewidget.cpp b/apps/opencs/view/render/worldspacewidget.cpp index 782dc5354..e1706ca77 100644 --- a/apps/opencs/view/render/worldspacewidget.cpp +++ b/apps/opencs/view/render/worldspacewidget.cpp @@ -148,7 +148,7 @@ CSVWidget::SceneToolMode *CSVRender::WorldspaceWidget::makeNavigationSelector ( "
  • Hold shift to speed up movement
  • " ""); tool->addButton( - new CSVRender::OrbitCameraMode(this, QIcon(":scenetoolbar/orbiting-camera"), + new CSVRender::OrbitCameraMode(this, mShortcutHandler, QIcon(":scenetoolbar/orbiting-camera"), "Orbiting Camera" "