diff --git a/src/ctrl/KeyBinding.cpp b/src/ctrl/KeyBinding.cpp index 3bedf8f4..e73e94e4 100644 --- a/src/ctrl/KeyBinding.cpp +++ b/src/ctrl/KeyBinding.cpp @@ -42,7 +42,7 @@ KeyBinding::KeyBinding(int aKeyCode, Qt::KeyboardModifiers aModifiers, int aSubK , mSubKeyCode(aSubKeyCode) , mModifiers() { - mModifiers = aModifiers & (Qt::ControlModifier | Qt::ShiftModifier | Qt::AltModifier | Qt::MetaModifier); + mModifiers = aModifiers & (Qt::ControlModifier | Qt::ShiftModifier | Qt::AltModifier | Qt::MetaModifier | Qt::KeypadModifier); } void KeyBinding::setSubKeyCode(int aSubKeyCode) @@ -53,7 +53,12 @@ void KeyBinding::setSubKeyCode(int aSubKeyCode) bool KeyBinding::isValidBinding() const { return getKeyValidity(mKeyCode) && - (mSubKeyCode == -1 || getKeyValidity(mSubKeyCode)); + (mSubKeyCode == -1 || getKeyValidity(mSubKeyCode)); +} + +bool KeyBinding::hasKeypadModifier() const +{ + return mModifiers & Qt::KeypadModifier; } bool KeyBinding::hasControlModifier() const @@ -97,6 +102,8 @@ QString KeyBinding::text() const if (hasShiftModifier()) t += "Shift + "; if (hasAltModifier()) t += "Alt + "; + if (hasKeypadModifier()) t += "Keypad + "; + if (mKeyCode != -1) { t += QKeySequence(mKeyCode).toString(); @@ -148,6 +155,7 @@ void KeyBinding::setSerialValue(const QString& aValue) if (mod & 0x01) mModifiers |= Qt::ControlModifier; if (mod & 0x02) mModifiers |= Qt::ShiftModifier; if (mod & 0x04) mModifiers |= Qt::AltModifier; + if (mod & 0x06) mModifiers |= Qt::KeypadModifier; if (mod & 0x08) mModifiers |= Qt::MetaModifier; if (!isValidBinding()) @@ -164,6 +172,7 @@ QString KeyBinding::serialValue() const mod |= mModifiers.testFlag(Qt::ControlModifier) ? 0x01 : 0x00; mod |= mModifiers.testFlag(Qt::ShiftModifier) ? 0x02 : 0x00; mod |= mModifiers.testFlag(Qt::AltModifier) ? 0x04 : 0x00; + mod |= mModifiers.testFlag(Qt::KeypadModifier) ? 0x06 : 0x00; mod |= mModifiers.testFlag(Qt::MetaModifier) ? 0x08 : 0x00; return QString::number(mKeyCode) + "," + QString::number(mod) + "," + QString::number(mSubKeyCode); } diff --git a/src/ctrl/KeyBinding.h b/src/ctrl/KeyBinding.h index 79f48d1a..acbf8e5a 100644 --- a/src/ctrl/KeyBinding.h +++ b/src/ctrl/KeyBinding.h @@ -23,6 +23,7 @@ class KeyBinding int subKeyCode() const { return mSubKeyCode; } bool hasSubKeyCode() const { return mSubKeyCode != -1; } bool isValidBinding() const; + bool hasKeypadModifier() const; bool hasControlModifier() const; bool hasShiftModifier() const; bool hasAltModifier() const; diff --git a/src/gui/KeyCommandMap.cpp b/src/gui/KeyCommandMap.cpp index dfce21ab..52c0617b 100644 --- a/src/gui/KeyCommandMap.cpp +++ b/src/gui/KeyCommandMap.cpp @@ -55,6 +55,12 @@ KeyCommandMap::KeyCommandMap(QWidget& aParent) addNewKey("RotateCanvas", view, tr("Rotate canvas"), ctrl::KeyBinding(Qt::Key_Space, Qt::ShiftModifier)); + addNewKey("RotateCanvas15Clockwise", view, tr("Rotate canvas 15° clockwise"), + ctrl::KeyBinding(Qt::Key_6, Qt::KeypadModifier)); + + addNewKey("RotateCanvas15AntiClockwise", view, tr("Rotate canvas 15° anti clockwise"), + ctrl::KeyBinding(Qt::Key_4, Qt::KeypadModifier)); + addNewKey("ResetCanvasAngle", view, tr("Reset canvas angle"), ctrl::KeyBinding(Qt::Key_Space, Qt::NoModifier, Qt::Key_F1)); diff --git a/src/gui/MainDisplayWidget.cpp b/src/gui/MainDisplayWidget.cpp index 88164835..2a72e226 100644 --- a/src/gui/MainDisplayWidget.cpp +++ b/src/gui/MainDisplayWidget.cpp @@ -97,6 +97,34 @@ MainDisplayWidget::MainDisplayWidget(ViaPoint& aViaPoint, QWidget* aParent) } } + // rotate canvas clockwise + { + auto key = mViaPoint.keyCommandMap()->get("RotateCanvas15Clockwise"); + if (key) + { + + key->invoker = [=]() + { + mCanvasMover.rotate(qDegreesToRadians(15.0f)); + updateRender(); + }; + } + } + + // rotate canvas anti-clockwise + { + auto key = mViaPoint.keyCommandMap()->get("RotateCanvas15AntiClockwise"); + if (key) + { + + key->invoker = [=]() + { + mCanvasMover.rotate(qDegreesToRadians(-15.0f)); + updateRender(); + }; + } + } + // reset canvas angle { auto key = mViaPoint.keyCommandMap()->get("ResetCanvasAngle"); @@ -161,7 +189,7 @@ void MainDisplayWidget::resetCamera() camera.setCenter(QVector2D(scrSize.width() * 0.5f, scrSize.height() * 0.5f)); if (scrSize.width() > 0 && scrSize.height() > 0 && imgSize.width() > 0 && imgSize.height() > 0) { - auto scaleX = (float)scrSize.width() / imgSize.width(); + auto scaleX = (float)scrSize.width() / imgSize.width(); auto scaleY = (float)scrSize.height() / imgSize.height(); auto minScale = scaleX < scaleY ? scaleX : scaleY; camera.setScale(minScale); @@ -490,11 +518,11 @@ void MainDisplayWidget::onViewSettingChanged(const MainViewSetting& aSetting) } else if (mViewSetting.rotateViewACW) { - mCanvasMover.rotate((float)(-M_PI / 18.0)); + mCanvasMover.rotate(qDegreesToRadians(-15.0f)); } else if (mViewSetting.rotateViewCW) { - mCanvasMover.rotate((float)(M_PI / 18.0)); + mCanvasMover.rotate(qDegreesToRadians(15.0f)); } updateRender(); diff --git a/src/gui/MainDisplayWidget.h b/src/gui/MainDisplayWidget.h index 9f7b3a53..8799e361 100644 --- a/src/gui/MainDisplayWidget.h +++ b/src/gui/MainDisplayWidget.h @@ -6,6 +6,7 @@ #include #include #include +#include #include "util/LinkPointer.h" #include "gl/Global.h" #include "gl/Root.h" diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 424f5762..90ed63e3 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -212,7 +212,7 @@ MainWindow::MainWindow(ctrl::System& aSystem, GUIResources& aResources, const Lo { dockWidget->setStyleSheet(QTextStream(&stylesheet).readAll()); } - mTool = new ToolWidget(mViaPoint, mGUIResources, QSize(192, 136), dockWidget); + mTool = new ToolWidget(mViaPoint, mGUIResources, *mKeyCommandMap, QSize(192, 136), dockWidget); dockWidget->setWidget(mTool); } diff --git a/src/gui/MainWindow.h b/src/gui/MainWindow.h index 2a50eb28..2308648b 100644 --- a/src/gui/MainWindow.h +++ b/src/gui/MainWindow.h @@ -66,7 +66,7 @@ class MainWindow : public QMainWindow ctrl::System& mSystem; GUIResources& mGUIResources; ViaPoint mViaPoint; - QScopedPointer mKeyCommandMap; + QScopedPointer mKeyCommandMap; QScopedPointer mKeyCommandInvoker; MouseSetting mMouseSetting; MainMenuBar* mMainMenuBar; diff --git a/src/gui/ToolWidget.cpp b/src/gui/ToolWidget.cpp index 3a2a79f1..6b0b2c76 100644 --- a/src/gui/ToolWidget.cpp +++ b/src/gui/ToolWidget.cpp @@ -5,11 +5,12 @@ namespace gui { -ToolWidget::ToolWidget(ViaPoint& aViaPoint, GUIResources& aResources, - const QSize& aSizeHint, QWidget* aParent) +ToolWidget::ToolWidget(ViaPoint& aViaPoint, GUIResources& aResources, KeyCommandMap &aKeyCommandMap, + const QSize& aSizeHint, QWidget* aParent) : QWidget(aParent) , mViaPoint(aViaPoint) , mResources(aResources) + , mKeyCommandMap(aKeyCommandMap) , mSizeHint(aSizeHint) , mViewPanel() , mModePanel() @@ -108,19 +109,24 @@ void ToolWidget::createViewPanel() this->viewSetting().cutImagesByTheFrame = aChecked; this->onViewSettingChanged(this->viewSetting()); }); - mViewPanel->addButton("rotateac", false, tr("Rotate the View Anticlockwise"), [=](bool) + + QString _rotateViewAntiClockwiseText = this->mKeyCommandMap.get("RotateCanvas15AntiClockwise")->binding.text(); + mViewPanel->addButton("rotateac", false, tr("Rotate the View Anticlockwise (%1").arg(_rotateViewAntiClockwiseText), [=](bool) { this->viewSetting().rotateViewACW = true; this->onViewSettingChanged(this->viewSetting()); this->viewSetting().rotateViewACW = false; }); + mViewPanel->addButton("resetrot", false, tr("Reset Rotation of the View"), [=](bool) { this->viewSetting().resetRotateView = true; this->onViewSettingChanged(this->viewSetting()); this->viewSetting().resetRotateView = false; }); - mViewPanel->addButton("rotatecw", false, tr("Rotate the View Clockwise"), [=](bool) + + QString _rotateViewClockwiseText = this->mKeyCommandMap.get("RotateCanvas15Clockwise")->binding.text(); + mViewPanel->addButton("rotatecw", false, tr("Rotate the View Clockwise (%1)").arg(_rotateViewClockwiseText), [=](bool) { this->viewSetting().rotateViewCW = true; this->onViewSettingChanged(this->viewSetting()); diff --git a/src/gui/ToolWidget.h b/src/gui/ToolWidget.h index 96bdac06..af782add 100644 --- a/src/gui/ToolWidget.h +++ b/src/gui/ToolWidget.h @@ -25,7 +25,7 @@ class ToolWidget : public QWidget { Q_OBJECT public: - ToolWidget(ViaPoint& aViaPoint, GUIResources& aResources, + ToolWidget(ViaPoint& aViaPoint, GUIResources& aResources, KeyCommandMap& aKeyCommandMap, const QSize& aSizeHint, QWidget* aParent); void setDriver(ctrl::Driver* aDriver); @@ -51,6 +51,7 @@ class ToolWidget : public QWidget ViaPoint& mViaPoint; GUIResources& mResources; + KeyCommandMap& mKeyCommandMap; const QSize mSizeHint; tool::ViewPanel* mViewPanel; tool::ModePanel* mModePanel;