From c497e325d88846e378c9d558a85e82f3b6df0ef2 Mon Sep 17 00:00:00 2001 From: Ronan Le Tiec Date: Fri, 13 Nov 2020 23:31:22 +0100 Subject: [PATCH] Zoom functions --- src/app/puzzle/vpapplication.cpp | 1 + src/app/puzzle/vpmainwindow.cpp | 33 ++++++++++++++++++++++++++++++++ src/app/puzzle/vpmainwindow.h | 10 ++++++++++ src/app/puzzle/vpmainwindow.ui | 8 ++++---- 4 files changed, 48 insertions(+), 4 deletions(-) diff --git a/src/app/puzzle/vpapplication.cpp b/src/app/puzzle/vpapplication.cpp index 9d6233713..e3233a2c0 100644 --- a/src/app/puzzle/vpapplication.cpp +++ b/src/app/puzzle/vpapplication.cpp @@ -363,6 +363,7 @@ VPMainWindow *VPApplication::NewMainWindow(const VPCommandLinePtr &cmd) { puzzle->show(); } + puzzle->InitZoom(); return puzzle; } diff --git a/src/app/puzzle/vpmainwindow.cpp b/src/app/puzzle/vpmainwindow.cpp index ca83c6b61..e4a000619 100644 --- a/src/app/puzzle/vpmainwindow.cpp +++ b/src/app/puzzle/vpmainwindow.cpp @@ -84,6 +84,7 @@ VPMainWindow::VPMainWindow(const VPCommandLinePtr &cmd, QWidget *parent) : InitCarrousel(); InitMainGraphics(); + InitToolBar(); SetPropertiesData(); @@ -185,6 +186,12 @@ void VPMainWindow::ImportRawLayouts(const QStringList &rawLayouts) } } +//--------------------------------------------------------------------------------------------------------------------- +void VPMainWindow::InitZoom() +{ + m_graphicsView->ZoomFitBest(); +} + //--------------------------------------------------------------------------------------------------------------------- VPPiece* VPMainWindow::CreatePiece(const VLayoutPiece &rawPiece) { @@ -472,6 +479,32 @@ void VPMainWindow::InitMainGraphics() m_graphicsView->RefreshLayout(); } +//--------------------------------------------------------------------------------------------------------------------- +void VPMainWindow::InitToolBar() +{ + QList zoomInShortcuts; + zoomInShortcuts.append(QKeySequence(QKeySequence::ZoomIn)); + zoomInShortcuts.append(QKeySequence(Qt::ControlModifier + Qt::Key_Plus + Qt::KeypadModifier)); + ui->actionZoomIn->setShortcuts(zoomInShortcuts); + connect(ui->actionZoomIn, &QAction::triggered, m_graphicsView, &VPMainGraphicsView::ZoomIn); + + QList zoomOutShortcuts; + zoomOutShortcuts.append(QKeySequence(QKeySequence::ZoomOut)); + zoomOutShortcuts.append(QKeySequence(Qt::ControlModifier + Qt::Key_Minus + Qt::KeypadModifier)); + ui->actionZoomOut->setShortcuts(zoomOutShortcuts); + connect(ui->actionZoomOut, &QAction::triggered, m_graphicsView, &VPMainGraphicsView::ZoomOut); + + QList zoomOriginalShortcuts; + zoomOriginalShortcuts.append(QKeySequence(Qt::ControlModifier + Qt::Key_0)); + zoomOriginalShortcuts.append(QKeySequence(Qt::ControlModifier + Qt::Key_0 + Qt::KeypadModifier)); + ui->actionZoomOriginal->setShortcuts(zoomOriginalShortcuts); + connect(ui->actionZoomOriginal, &QAction::triggered, m_graphicsView, &VPMainGraphicsView::ZoomOriginal); + + QList zoomFitBestShortcuts; + zoomFitBestShortcuts.append(QKeySequence(Qt::ControlModifier + Qt::Key_Equal)); + ui->actionZoomFitBest->setShortcuts(zoomFitBestShortcuts); + connect(ui->actionZoomFitBest, &QAction::triggered, m_graphicsView, &VPMainGraphicsView::ZoomFitBest); +} //--------------------------------------------------------------------------------------------------------------------- void VPMainWindow::SetDoubleSpinBoxValue(QDoubleSpinBox *spinBox, qreal value) diff --git a/src/app/puzzle/vpmainwindow.h b/src/app/puzzle/vpmainwindow.h index c7229b089..fd004d680 100644 --- a/src/app/puzzle/vpmainwindow.h +++ b/src/app/puzzle/vpmainwindow.h @@ -74,6 +74,11 @@ public: */ void ImportRawLayouts(const QStringList &rawLayouts); + /** + * @brief InitZoom Initialises the zoom to fit best + */ + void InitZoom(); + public slots: /** * @brief on_actionNew_triggered When the menu action File > New @@ -144,6 +149,11 @@ private: */ void InitMainGraphics(); + /** + * @brief InitToolBar Initialises the tool bar + */ + void InitToolBar(); + /** * @brief SetPropertiesData Sets the values of UI elements * in all the property tabs to the values saved in m_layout diff --git a/src/app/puzzle/vpmainwindow.ui b/src/app/puzzle/vpmainwindow.ui index 8a9cae6aa..84b9fa0ea 100644 --- a/src/app/puzzle/vpmainwindow.ui +++ b/src/app/puzzle/vpmainwindow.ui @@ -1197,8 +1197,8 @@ - - + + @@ -1296,7 +1296,7 @@ Zoom out - + .. @@ -1305,7 +1305,7 @@ Zoom 1:1 - + ..