Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/ctrl/KeyBinding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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())
Expand All @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions src/ctrl/KeyBinding.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions src/gui/KeyCommandMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
34 changes: 31 additions & 3 deletions src/gui/MainDisplayWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions src/gui/MainDisplayWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <QScopedPointer>
#include <QTabBar>
#include <QReadWriteLock>
#include <QtMath>
#include "util/LinkPointer.h"
#include "gl/Global.h"
#include "gl/Root.h"
Expand Down
2 changes: 1 addition & 1 deletion src/gui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion src/gui/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class MainWindow : public QMainWindow
ctrl::System& mSystem;
GUIResources& mGUIResources;
ViaPoint mViaPoint;
QScopedPointer<KeyCommandMap> mKeyCommandMap;
QScopedPointer<KeyCommandMap> mKeyCommandMap;
QScopedPointer<KeyCommandInvoker> mKeyCommandInvoker;
MouseSetting mMouseSetting;
MainMenuBar* mMainMenuBar;
Expand Down
14 changes: 10 additions & 4 deletions src/gui/ToolWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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());
Expand Down
3 changes: 2 additions & 1 deletion src/gui/ToolWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -51,6 +51,7 @@ class ToolWidget : public QWidget

ViaPoint& mViaPoint;
GUIResources& mResources;
KeyCommandMap& mKeyCommandMap;
const QSize mSizeHint;
tool::ViewPanel* mViewPanel;
tool::ModePanel* mModePanel;
Expand Down