Resolved issue #794. Better control over scale value.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2018-01-09 20:13:30 +02:00
parent d61ba2200f
commit 910ac6864c
5 changed files with 66 additions and 5 deletions

View File

@ -37,6 +37,7 @@
- [#790] Generate unique name for each detail.
- [#792] New feature. Visibility trigger for internal path.
- New internal variable RotationElArc.
- [#794] Better control over scale value.
# Version 0.5.1
- [#683] Tool Seam allowance's dialog is off screen on small resolutions.

View File

@ -85,6 +85,7 @@
#include <QFileSystemWatcher>
#include <QComboBox>
#include <QTextCodec>
#include <QDoubleSpinBox>
#if defined(Q_OS_MAC)
#include <QMimeData>
@ -126,7 +127,12 @@ MainWindow::MainWindow(QWidget *parent)
drawMode(true), recentFileActs(),
separatorAct(nullptr),
leftGoToStage(nullptr), rightGoToStage(nullptr), autoSaveTimer(nullptr), guiEnabled(true),
gradationHeights(nullptr), gradationSizes(nullptr), gradationHeightsLabel(nullptr), gradationSizesLabel(nullptr),
gradationHeights(nullptr),
gradationSizes(nullptr),
gradationHeightsLabel(nullptr),
gradationSizesLabel(nullptr),
zoomScale(nullptr),
doubleSpinBoxScale(nullptr),
toolOptions(nullptr),
groupsWidget(nullptr),
detailsWidget(nullptr),
@ -373,6 +379,7 @@ void MainWindow::InitScenes()
sceneDetails->setTransform(ui->view->transform());
connect(ui->view, &VMainGraphicsView::MouseRelease, this, [this](){EndVisualization(true);});
connect(ui->view, &VMainGraphicsView::ScaleChanged, this, &MainWindow::ScaleChanged);
QSizePolicy policy(QSizePolicy::Expanding, QSizePolicy::Expanding);
policy.setHorizontalStretch(12);
ui->view->setSizePolicy(policy);
@ -1592,6 +1599,17 @@ void MainWindow::ExportToCSVData(const QString &fileName, bool withHeader, int m
csv.toCSV(fileName, error, withHeader, separator, QTextCodec::codecForMib(mib));
}
//---------------------------------------------------------------------------------------------------------------------
void MainWindow::ScaleChanged(qreal scale)
{
doubleSpinBoxScale->blockSignals(true);
doubleSpinBoxScale->setMaximum(qFloor(VMainGraphicsView::MaxScale()*1000)/10.0);
doubleSpinBoxScale->setMinimum(qFloor(VMainGraphicsView::MinScale()*1000)/10.0);
doubleSpinBoxScale->setValue(qFloor(scale*1000)/10.0);
doubleSpinBoxScale->setSingleStep(1);
doubleSpinBoxScale->blockSignals(false);
}
//---------------------------------------------------------------------------------------------------------------------
void MainWindow::LoadIndividual()
{
@ -1869,6 +1887,14 @@ void MainWindow::ToolBarOption()
{
delete gradationSizesLabel;
}
if (not zoomScale.isNull())
{
delete zoomScale;
}
if (not doubleSpinBoxScale.isNull())
{
delete doubleSpinBoxScale;
}
if (qApp->patternType() == MeasurementsType::Multisize)
{
@ -1898,6 +1924,19 @@ void MainWindow::ToolBarOption()
ui->toolBarOption->addSeparator();
}
zoomScale = new QLabel(tr("Scale:"), this);
ui->toolBarOption->addWidget(zoomScale);
doubleSpinBoxScale = new QDoubleSpinBox(this);
doubleSpinBoxScale->setDecimals(1);
doubleSpinBoxScale->setSuffix("%");
ScaleChanged(ui->view->transform().m11());
connect(doubleSpinBoxScale, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), this,
[this](double d){ui->view->Zoom(d/100.0);});
ui->toolBarOption->addWidget(doubleSpinBoxScale);
ui->toolBarOption->addSeparator();
mouseCoordinate = new QLabel(QString("0, 0 (%1)").arg(UnitsToStr(qApp->patternUnit(), true)));
ui->toolBarOption->addWidget(mouseCoordinate);
}

View File

@ -51,6 +51,7 @@ class DialogFinalMeasurements;
class VWidgetGroups;
class VWidgetDetails;
class QToolButton;
class QDoubleSpinBox;
/**
* @brief The MainWindow class main windows.
@ -106,6 +107,7 @@ protected:
virtual void ExportToCSVData(const QString &fileName, bool withHeader, int mib,
const QChar &separator) Q_DECL_FINAL;
private slots:
void ScaleChanged(qreal scale);
void MouseMove(const QPointF &scenePos);
void Clear();
void PatternChangesWereSaved(bool saved);
@ -269,6 +271,8 @@ private:
QPointer<QComboBox> gradationSizes;
QPointer<QLabel> gradationHeightsLabel;
QPointer<QLabel> gradationSizesLabel;
QPointer<QLabel> zoomScale;
QPointer<QDoubleSpinBox> doubleSpinBoxScale;
VToolOptionsPropertyBrowser *toolOptions;
VWidgetGroups *groupsWidget;
VWidgetDetails *detailsWidget;

View File

@ -360,6 +360,20 @@ VMainGraphicsView::VMainGraphicsView(QWidget *parent)
this->setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
this->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
this->setInteractive(true);
connect(zoom, &GraphicsViewZoom::zoomed, this, [this](){emit ScaleChanged(transform().m11());});
}
//---------------------------------------------------------------------------------------------------------------------
void VMainGraphicsView::Zoom(qreal scale)
{
qreal factor = qBound(MinScale(), scale, MaxScale());
QTransform transform = this->transform();
transform.setMatrix(factor, transform.m12(), transform.m13(), transform.m21(), factor, transform.m23(),
transform.m31(), transform.m32(), transform.m33());
this->setTransform(transform);
VMainGraphicsView::NewSceneRect(this->scene(), this);
emit ScaleChanged(this->transform().m11());
}
//---------------------------------------------------------------------------------------------------------------------
@ -371,6 +385,7 @@ void VMainGraphicsView::ZoomIn()
{
scale(1.1, 1.1);
VMainGraphicsView::NewSceneRect(this->scene(), this);
emit ScaleChanged(transform().m11());
}
}
@ -383,6 +398,7 @@ void VMainGraphicsView::ZoomOut()
{
scale(1.0/1.1, 1.0/1.1);
VMainGraphicsView::NewSceneRect(this->scene(), this);
emit ScaleChanged(transform().m11());
}
}
@ -394,6 +410,7 @@ void VMainGraphicsView::ZoomOriginal()
trans.m33());
this->setTransform(trans);
VMainGraphicsView::NewSceneRect(this->scene(), this);
emit ScaleChanged(transform().m11());
}
//---------------------------------------------------------------------------------------------------------------------
@ -412,15 +429,13 @@ void VMainGraphicsView::ZoomFitBest()
this->fitInView(rect, Qt::KeepAspectRatio);
QTransform transform = this->transform();
qreal factor = transform.m11();
factor = qMax(factor, MinScale());
factor = qMin(factor, MaxScale());
const qreal factor = qBound(MinScale(), transform.m11(), MaxScale());
transform.setMatrix(factor, transform.m12(), transform.m13(), transform.m21(), factor, transform.m23(),
transform.m31(), transform.m32(), transform.m33());
this->setTransform(transform);
VMainGraphicsView::NewSceneRect(scene(), this);
emit ScaleChanged(this->transform().m11());
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -139,7 +139,9 @@ signals:
*/
void MouseRelease();
void itemClicked(QGraphicsItem *item);
void ScaleChanged(qreal scale);
public slots:
void Zoom(qreal scale);
void ZoomIn();
void ZoomOut();
void ZoomOriginal();