Add scale spinbox functionality

This commit is contained in:
Ronan Le Tiec 2020-11-14 10:20:02 +01:00
parent c497e325d8
commit d55dbbb61e
3 changed files with 55 additions and 5 deletions

View File

@ -29,6 +29,7 @@
#include <QFileDialog> #include <QFileDialog>
#include <QCloseEvent> #include <QCloseEvent>
#include <QtMath>
#include "ui_vpmainwindow.h" #include "ui_vpmainwindow.h"
#include "dialogs/vpdialogabout.h" #include "dialogs/vpdialogabout.h"
@ -84,7 +85,7 @@ VPMainWindow::VPMainWindow(const VPCommandLinePtr &cmd, QWidget *parent) :
InitCarrousel(); InitCarrousel();
InitMainGraphics(); InitMainGraphics();
InitToolBar(); InitZoomToolBar();
SetPropertiesData(); SetPropertiesData();
@ -477,11 +478,15 @@ void VPMainWindow::InitMainGraphics()
ui->centralWidget->layout()->addWidget(m_graphicsView); ui->centralWidget->layout()->addWidget(m_graphicsView);
m_graphicsView->RefreshLayout(); 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<QKeySequence> zoomInShortcuts; QList<QKeySequence> zoomInShortcuts;
zoomInShortcuts.append(QKeySequence(QKeySequence::ZoomIn)); zoomInShortcuts.append(QKeySequence(QKeySequence::ZoomIn));
zoomInShortcuts.append(QKeySequence(Qt::ControlModifier + Qt::Key_Plus + Qt::KeypadModifier)); 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)); zoomFitBestShortcuts.append(QKeySequence(Qt::ControlModifier + Qt::Key_Equal));
ui->actionZoomFitBest->setShortcuts(zoomFitBestShortcuts); ui->actionZoomFitBest->setShortcuts(zoomFitBestShortcuts);
connect(ui->actionZoomFitBest, &QAction::triggered, m_graphicsView, &VPMainGraphicsView::ZoomFitBest); 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<double>::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); 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);
}
}

View File

@ -103,6 +103,9 @@ private:
VPLayout *m_layout{nullptr}; VPLayout *m_layout{nullptr};
QList<VPPiece *>m_selectedPieces{QList<VPPiece *>()}; QList<VPPiece *>m_selectedPieces{QList<VPPiece *>()};
QLabel* m_mouseCoordinate{nullptr};
QPointer<QDoubleSpinBox> m_doubleSpinBoxScale{nullptr};
/** /**
* @brief CreatePiece creates a piece from the given VLayoutPiece data * @brief CreatePiece creates a piece from the given VLayoutPiece data
* @param rawPiece the raw piece data * @param rawPiece the raw piece data
@ -152,7 +155,7 @@ private:
/** /**
* @brief InitToolBar Initialises the tool bar * @brief InitToolBar Initialises the tool bar
*/ */
void InitToolBar(); void InitZoomToolBar();
/** /**
* @brief SetPropertiesData Sets the values of UI elements * @brief SetPropertiesData Sets the values of UI elements
@ -395,6 +398,11 @@ private slots:
*/ */
void on_PieceRotationChanged(); void on_PieceRotationChanged();
/**
* @brief on_ScaleChanged
*/
void on_ScaleChanged(qreal scale);
}; };
#endif // VPMAINWINDOW_H #endif // VPMAINWINDOW_H

View File

@ -1182,7 +1182,7 @@
</layout> </layout>
</widget> </widget>
</widget> </widget>
<widget class="QToolBar" name="toolBarTools"> <widget class="QToolBar" name="toolBarZoom">
<property name="windowTitle"> <property name="windowTitle">
<string>toolBar</string> <string>toolBar</string>
</property> </property>
@ -1311,7 +1311,7 @@
<normaloff>.</normaloff>.</iconset> <normaloff>.</normaloff>.</iconset>
</property> </property>
<property name="text"> <property name="text">
<string>Zoom sheet</string> <string>Zoom fit best</string>
</property> </property>
<property name="toolTip"> <property name="toolTip">
<string>Zoom sheet</string> <string>Zoom sheet</string>