From d55dbbb61e47dde15007987895b4ebd9dbc42699 Mon Sep 17 00:00:00 2001 From: Ronan Le Tiec Date: Sat, 14 Nov 2020 10:20:02 +0100 Subject: [PATCH] Add scale spinbox functionality --- src/app/puzzle/vpmainwindow.cpp | 46 +++++++++++++++++++++++++++++++-- src/app/puzzle/vpmainwindow.h | 10 ++++++- src/app/puzzle/vpmainwindow.ui | 4 +-- 3 files changed, 55 insertions(+), 5 deletions(-) diff --git a/src/app/puzzle/vpmainwindow.cpp b/src/app/puzzle/vpmainwindow.cpp index e4a000619..97740e8de 100644 --- a/src/app/puzzle/vpmainwindow.cpp +++ b/src/app/puzzle/vpmainwindow.cpp @@ -29,6 +29,7 @@ #include #include +#include #include "ui_vpmainwindow.h" #include "dialogs/vpdialogabout.h" @@ -84,7 +85,7 @@ VPMainWindow::VPMainWindow(const VPCommandLinePtr &cmd, QWidget *parent) : InitCarrousel(); InitMainGraphics(); - InitToolBar(); + InitZoomToolBar(); SetPropertiesData(); @@ -477,11 +478,15 @@ void VPMainWindow::InitMainGraphics() ui->centralWidget->layout()->addWidget(m_graphicsView); m_graphicsView->RefreshLayout(); + + connect(m_graphicsView, &VPMainGraphicsView::ScaleChanged, this, &VPMainWindow::on_ScaleChanged); } //--------------------------------------------------------------------------------------------------------------------- -void VPMainWindow::InitToolBar() +void VPMainWindow::InitZoomToolBar() { + + // connect the zoom buttons and shortcuts to the slots QList zoomInShortcuts; zoomInShortcuts.append(QKeySequence(QKeySequence::ZoomIn)); zoomInShortcuts.append(QKeySequence(Qt::ControlModifier + Qt::Key_Plus + Qt::KeypadModifier)); @@ -504,6 +509,28 @@ void VPMainWindow::InitToolBar() zoomFitBestShortcuts.append(QKeySequence(Qt::ControlModifier + Qt::Key_Equal)); ui->actionZoomFitBest->setShortcuts(zoomFitBestShortcuts); connect(ui->actionZoomFitBest, &QAction::triggered, m_graphicsView, &VPMainGraphicsView::ZoomFitBest); + + // defined the scale + ui->toolBarZoom->addSeparator(); + QLabel* zoomScale = new QLabel(tr("Scale:"), this); + ui->toolBarZoom->addWidget(zoomScale); + + m_doubleSpinBoxScale = new QDoubleSpinBox(this); + m_doubleSpinBoxScale->setDecimals(1); + m_doubleSpinBoxScale->setSuffix("%"); + on_ScaleChanged(m_graphicsView->transform().m11()); + connect(m_doubleSpinBoxScale.data(), QOverload::of(&QDoubleSpinBox::valueChanged), + this, [this](double d){m_graphicsView->Zoom(d/100.0);}); + ui->toolBarZoom->addWidget(m_doubleSpinBoxScale); + + + // define the mouse position + ui->toolBarZoom->addSeparator(); + + m_mouseCoordinate = new QLabel(QString("0, 0 (%1)").arg(UnitsToStr(m_layout->GetUnit(), true))); + ui->toolBarZoom->addWidget(m_mouseCoordinate); + ui->toolBarZoom->addSeparator(); + } //--------------------------------------------------------------------------------------------------------------------- @@ -1057,3 +1084,18 @@ void VPMainWindow::on_PieceRotationChanged() SetDoubleSpinBoxValue(ui->doubleSpinBoxCurrentPieceAngle, angle); } } + + +//--------------------------------------------------------------------------------------------------------------------- +void VPMainWindow::on_ScaleChanged(qreal scale) +{ + if (not m_doubleSpinBoxScale.isNull()) + { + m_doubleSpinBoxScale->blockSignals(true); + m_doubleSpinBoxScale->setMaximum(qFloor(VPMainGraphicsView::MaxScale()*1000)/10.0); + m_doubleSpinBoxScale->setMinimum(qFloor(VPMainGraphicsView::MinScale()*1000)/10.0); + m_doubleSpinBoxScale->setValue(qFloor(scale*1000)/10.0); + m_doubleSpinBoxScale->setSingleStep(1); + m_doubleSpinBoxScale->blockSignals(false); + } +} diff --git a/src/app/puzzle/vpmainwindow.h b/src/app/puzzle/vpmainwindow.h index fd004d680..5e74f3f1d 100644 --- a/src/app/puzzle/vpmainwindow.h +++ b/src/app/puzzle/vpmainwindow.h @@ -103,6 +103,9 @@ private: VPLayout *m_layout{nullptr}; QListm_selectedPieces{QList()}; + QLabel* m_mouseCoordinate{nullptr}; + QPointer m_doubleSpinBoxScale{nullptr}; + /** * @brief CreatePiece creates a piece from the given VLayoutPiece data * @param rawPiece the raw piece data @@ -152,7 +155,7 @@ private: /** * @brief InitToolBar Initialises the tool bar */ - void InitToolBar(); + void InitZoomToolBar(); /** * @brief SetPropertiesData Sets the values of UI elements @@ -395,6 +398,11 @@ private slots: */ void on_PieceRotationChanged(); + /** + * @brief on_ScaleChanged + */ + void on_ScaleChanged(qreal scale); + }; #endif // VPMAINWINDOW_H diff --git a/src/app/puzzle/vpmainwindow.ui b/src/app/puzzle/vpmainwindow.ui index 84b9fa0ea..412528d40 100644 --- a/src/app/puzzle/vpmainwindow.ui +++ b/src/app/puzzle/vpmainwindow.ui @@ -1182,7 +1182,7 @@ - + toolBar @@ -1311,7 +1311,7 @@ .. - Zoom sheet + Zoom fit best Zoom sheet