diff --git a/app/actionmanager.cpp b/app/actionmanager.cpp index 3306782..0bfeb48 100644 --- a/app/actionmanager.cpp +++ b/app/actionmanager.cpp @@ -68,6 +68,7 @@ void ActionManager::setupAction(MainWindow *mainWindow) CREATE_NEW_ACTION(mainWindow, actionPaste); CREATE_NEW_ACTION(mainWindow, actionToggleStayOnTop); CREATE_NEW_ACTION(mainWindow, actionToggleProtectMode); + CREATE_NEW_ACTION(mainWindow, actionToggleAvoidResetTransform); CREATE_NEW_ACTION(mainWindow, actionSettings); CREATE_NEW_ACTION(mainWindow, actionHelp); CREATE_NEW_ACTION(mainWindow, actionLocateInFileManager); @@ -104,6 +105,7 @@ void ActionManager::retranslateUi(MainWindow *mainWindow) actionPaste->setText(QCoreApplication::translate("MainWindow", "&Paste", nullptr)); actionToggleStayOnTop->setText(QCoreApplication::translate("MainWindow", "Stay on top", nullptr)); actionToggleProtectMode->setText(QCoreApplication::translate("MainWindow", "Protected mode", nullptr)); + actionToggleAvoidResetTransform->setText("Avoid reset transform"); // TODO: what should it called? actionSettings->setText(QCoreApplication::translate("MainWindow", "Configure...", nullptr)); actionHelp->setText(QCoreApplication::translate("MainWindow", "Help", nullptr)); #ifdef Q_OS_WIN diff --git a/app/actionmanager.h b/app/actionmanager.h index ede536c..1257604 100644 --- a/app/actionmanager.h +++ b/app/actionmanager.h @@ -42,6 +42,7 @@ public: QAction *actionPaste; QAction *actionToggleStayOnTop; QAction *actionToggleProtectMode; + QAction *actionToggleAvoidResetTransform; QAction *actionSettings; QAction *actionHelp; QAction *actionLocateInFileManager; diff --git a/app/graphicsview.cpp b/app/graphicsview.cpp index 0bff010..e87d827 100644 --- a/app/graphicsview.cpp +++ b/app/graphicsview.cpp @@ -121,7 +121,9 @@ qreal GraphicsView::scaleFactor() const void GraphicsView::resetTransform() { - QGraphicsView::resetTransform(); + if (!m_avoidResetTransform) { + QGraphicsView::resetTransform(); + } } void GraphicsView::zoomView(qreal scaleFactor) @@ -197,6 +199,11 @@ void GraphicsView::fitByOrientation(Qt::Orientation ori, bool scaleDownOnly) void GraphicsView::displayScene() { + if (m_avoidResetTransform) { + emit navigatorViewRequired(!isThingSmallerThanWindowWith(transform()), transform()); + return; + } + if (isSceneBiggerThanView()) { fitInView(sceneRect(), Qt::KeepAspectRatio); } @@ -219,6 +226,16 @@ void GraphicsView::setEnableAutoFitInView(bool enable) m_enableFitInView = enable; } +bool GraphicsView::avoidResetTransform() const +{ + return m_avoidResetTransform; +} + +void GraphicsView::setAvoidResetTransform(bool avoidReset) +{ + m_avoidResetTransform = avoidReset; +} + inline double zeroOrOne(double number) { return qFuzzyIsNull(number) ? 0 : (number > 0 ? 1 : -1); diff --git a/app/graphicsview.h b/app/graphicsview.h index 51b5ecf..833cd3d 100644 --- a/app/graphicsview.h +++ b/app/graphicsview.h @@ -40,6 +40,9 @@ public: bool isSceneBiggerThanView() const; void setEnableAutoFitInView(bool enable = true); + bool avoidResetTransform() const; + void setAvoidResetTransform(bool avoidReset); + static QTransform resetScale(const QTransform & orig); signals: @@ -70,6 +73,7 @@ private: // ... or even more? e.g. "fit/snap width" things... // Currently it's "no fit" when it's false and "fit when view is smaller" when it's true. bool m_enableFitInView = false; + bool m_avoidResetTransform = false; bool m_checkerboardEnabled = false; bool m_isLastCheckerboardColorInverted = false; }; diff --git a/app/mainwindow.cpp b/app/mainwindow.cpp index 75ac843..26e07c1 100644 --- a/app/mainwindow.cpp +++ b/app/mainwindow.cpp @@ -453,6 +453,10 @@ void MainWindow::contextMenuEvent(QContextMenuEvent *event) protectedMode->setCheckable(true); protectedMode->setChecked(m_protectedMode); + QAction * avoidResetTransform = m_am->actionToggleAvoidResetTransform; + avoidResetTransform->setCheckable(true); + avoidResetTransform->setChecked(m_graphicsView->avoidResetTransform()); + QAction * toggleSettings = m_am->actionSettings; QAction * helpAction = m_am->actionHelp; QAction * propertiesAction = m_am->actionProperties; @@ -481,6 +485,9 @@ void MainWindow::contextMenuEvent(QContextMenuEvent *event) menu->addSeparator(); menu->addAction(stayOnTopMode); menu->addAction(protectedMode); +#if 0 + menu->addAction(avoidResetTransform); +#endif // 0 menu->addSeparator(); menu->addAction(toggleSettings); menu->addAction(helpAction); @@ -545,6 +552,11 @@ void MainWindow::toggleStayOnTop() show(); } +void MainWindow::toggleAvoidResetTransform() +{ + m_graphicsView->setAvoidResetTransform(!m_graphicsView->avoidResetTransform()); +} + bool MainWindow::stayOnTop() const { return windowFlags().testFlag(Qt::WindowStaysOnTopHint); @@ -727,6 +739,11 @@ void MainWindow::on_actionToggleProtectMode_triggered() toggleProtectedMode(); } +void MainWindow::on_actionToggleAvoidResetTransform_triggered() +{ + toggleAvoidResetTransform(); +} + void MainWindow::on_actionSettings_triggered() { SettingsDialog * sd = new SettingsDialog(this); diff --git a/app/mainwindow.h b/app/mainwindow.h index 885b413..b655b6f 100644 --- a/app/mainwindow.h +++ b/app/mainwindow.h @@ -63,6 +63,7 @@ protected slots: void updateWidgetsPosition(); void toggleProtectedMode(); void toggleStayOnTop(); + void toggleAvoidResetTransform(); bool stayOnTop() const; bool canPaste() const; void quitAppAction(bool force = false); @@ -93,6 +94,7 @@ private slots: void on_actionPaste_triggered(); void on_actionToggleStayOnTop_triggered(); void on_actionToggleProtectMode_triggered(); + void on_actionToggleAvoidResetTransform_triggered(); void on_actionSettings_triggered(); void on_actionHelp_triggered(); void on_actionProperties_triggered();