diff --git a/src/app/dialogs/tools/dialogendline.cpp b/src/app/dialogs/tools/dialogendline.cpp index 4d84ba70b..2672660c3 100644 --- a/src/app/dialogs/tools/dialogendline.cpp +++ b/src/app/dialogs/tools/dialogendline.cpp @@ -199,7 +199,7 @@ void DialogEndLine::ShowDialog(bool click) QLineF line = QLineF(point->toQPointF(), scene->getScenePos()); //Radius of point circle, but little bigger. Need handle with hover sizes. - qreal radius = ((DefPointRadius/*mm*/ / 25.4) * VApplication::PrintDPI)*1.5; + qreal radius = qApp->toPixel(DefPointRadius/*mm*/, Unit::Mm)*1.5; if (line.length() <= radius) { return; diff --git a/src/app/tablewindow.cpp b/src/app/tablewindow.cpp index 100052979..1dce82fef 100644 --- a/src/app/tablewindow.cpp +++ b/src/app/tablewindow.cpp @@ -51,7 +51,7 @@ TableWindow::TableWindow(QWidget *parent) ui->statusBar->addWidget(colission); outItems = collidingItems = false; //sceneRect = QRectF(0, 0, qApp->toPixel(203), qApp->toPixel(287)); - sceneRect = QRectF(0, 0, qApp->toPixel(823), qApp->toPixel(1171)); + sceneRect = QRectF(0, 0, qApp->toPixel(823, Unit::Mm), qApp->toPixel(1171, Unit::Mm)); tableScene = new QGraphicsScene(sceneRect); QBrush brush; brush.setStyle( Qt::SolidPattern ); @@ -206,7 +206,7 @@ void TableWindow::StopTable() delete listOutItems; listDetails.clear(); //sceneRect = QRectF(0, 0, 230*resol/25.9, 327*resol/25.9); - sceneRect = QRectF(0, 0, qApp->toPixel(823), qApp->toPixel(1171)); + sceneRect = QRectF(0, 0, qApp->toPixel(823, Unit::Mm), qApp->toPixel(1171, Unit::Mm)); emit closed(); } @@ -442,13 +442,13 @@ void TableWindow::GetNextDetail() void TableWindow::AddLength() { QRectF rect = tableScene->sceneRect(); - rect.setHeight(rect.height()+qApp->toPixel(279)); + rect.setHeight(rect.height()+qApp->toPixel(279, Unit::Mm)); tableScene->setSceneRect(rect); rect = shadowPaper->rect(); - rect.setHeight(rect.height()+qApp->toPixel(279)); + rect.setHeight(rect.height()+qApp->toPixel(279, Unit::Mm)); shadowPaper->setRect(rect); rect = paper->rect(); - rect.setHeight(rect.height()+qApp->toPixel(279)); + rect.setHeight(rect.height()+qApp->toPixel(279, Unit::Mm)); paper->setRect(rect); ui->actionRemove->setEnabled(true); emit LengthChanged(); @@ -463,13 +463,13 @@ void TableWindow::RemoveLength() if (sceneRect.height() <= tableScene->sceneRect().height() - 100) { QRectF rect = tableScene->sceneRect(); - rect.setHeight(rect.height()-qApp->toPixel(279)); + rect.setHeight(rect.height()-qApp->toPixel(279, Unit::Mm)); tableScene->setSceneRect(rect); rect = shadowPaper->rect(); - rect.setHeight(rect.height()-qApp->toPixel(279)); + rect.setHeight(rect.height()-qApp->toPixel(279, Unit::Mm)); shadowPaper->setRect(rect); rect = paper->rect(); - rect.setHeight(rect.height()-qApp->toPixel(279)); + rect.setHeight(rect.height()-qApp->toPixel(279, Unit::Mm)); paper->setRect(rect); if (fabs(sceneRect.height() - tableScene->sceneRect().height()) < 0.01) { @@ -561,7 +561,7 @@ void TableWindow::PdfFile(const QString &name) const qreal x=0, y=0, w=0, h=0; r.getRect(&x, &y, &w, &h);// Re-shrink the scene to it's bounding contents printer.setResolution(static_cast(qApp->PrintDPI)); - printer.setPaperSize ( QSizeF(qApp->fromPixel(w), qApp->fromPixel(h)), QPrinter::Millimeter ); + printer.setPaperSize ( QSizeF(qApp->fromPixel(w, Unit::Mm), qApp->fromPixel(h, Unit::Mm)), QPrinter::Millimeter ); QPainter painter; if (painter.begin( &printer ) == false) { // failed to open file diff --git a/src/app/tools/drawTools/vtoolpoint.cpp b/src/app/tools/drawTools/vtoolpoint.cpp index 5760b86cc..d7ebd0555 100644 --- a/src/app/tools/drawTools/vtoolpoint.cpp +++ b/src/app/tools/drawTools/vtoolpoint.cpp @@ -44,7 +44,7 @@ const QString VToolPoint::TagName = QStringLiteral("point"); VToolPoint::VToolPoint(VPattern *doc, VContainer *data, quint32 id, QGraphicsItem *parent):VDrawTool(doc, data, id), QGraphicsEllipseItem(parent), radius(DefPointRadius), namePoint(0), lineName(0) { - radius = (DefPointRadius/*mm*/ / 25.4) * VApplication::PrintDPI; + radius = qApp->toPixel(DefPointRadius/*mm*/, Unit::Mm); namePoint = new VGraphicsSimpleTextItem(this); connect(namePoint, &VGraphicsSimpleTextItem::ShowContextMenu, this, &VToolPoint::ShowContextMenu); namePoint->setBrush(Qt::black); diff --git a/src/app/visualization/vistoolendline.cpp b/src/app/visualization/vistoolendline.cpp index ad729930b..f9ac28119 100644 --- a/src/app/visualization/vistoolendline.cpp +++ b/src/app/visualization/vistoolendline.cpp @@ -49,7 +49,7 @@ VisToolEndLine::VisToolEndLine(const VContainer *data, QGraphicsItem *parent) point->setBrush(QBrush(Qt::NoBrush)); point->setPen(QPen(color, qApp->toPixel(qApp->widthHairLine())/factor)); - const qreal radius = (DefPointRadius/*mm*/ / 25.4) * VApplication::PrintDPI; + const qreal radius = qApp->toPixel(DefPointRadius/*mm*/, Unit::Mm); QRectF rec = QRectF(0, 0, radius*2/factor, radius*2/factor); rec.translate(-rec.center().x(), -rec.center().y()); point->setRect(rec); diff --git a/src/app/widgets/vapplication.cpp b/src/app/widgets/vapplication.cpp index fcd87e9a1..ecd8e5c0f 100644 --- a/src/app/widgets/vapplication.cpp +++ b/src/app/widgets/vapplication.cpp @@ -144,19 +144,19 @@ bool VApplication::notify(QObject *receiver, QEvent *event) } //--------------------------------------------------------------------------------------------------------------------- -double VApplication::toPixel(double unit) const +double VApplication::toPixel(double val, const Unit &unit) const { double result = 0; - switch (_patternUnit) + switch (unit) { case Unit::Mm: - result = (unit / 25.4) * PrintDPI; + result = (val / 25.4) * PrintDPI; break; case Unit::Cm: - result = ((unit * 10.0) / 25.4) * PrintDPI; + result = ((val * 10.0) / 25.4) * PrintDPI; break; case Unit::Inch: - result = unit * PrintDPI; + result = val * PrintDPI; break; default: break; @@ -165,10 +165,16 @@ double VApplication::toPixel(double unit) const } //--------------------------------------------------------------------------------------------------------------------- -double VApplication::fromPixel(double pix) const +double VApplication::toPixel(double val) const +{ + return toPixel(val, _patternUnit); +} + +//--------------------------------------------------------------------------------------------------------------------- +double VApplication::fromPixel(double pix, const Unit &unit) const { double result = 0; - switch (_patternUnit) + switch (unit) { case Unit::Mm: result = (pix / PrintDPI) * 25.4; @@ -185,6 +191,12 @@ double VApplication::fromPixel(double pix) const return result; } +//--------------------------------------------------------------------------------------------------------------------- +double VApplication::fromPixel(double pix) const +{ + return fromPixel(pix, _patternUnit); +} + //--------------------------------------------------------------------------------------------------------------------- QString VApplication::pathToTables() const { diff --git a/src/app/widgets/vapplication.h b/src/app/widgets/vapplication.h index 0db4722aa..8cdbb5e11 100644 --- a/src/app/widgets/vapplication.h +++ b/src/app/widgets/vapplication.h @@ -60,8 +60,12 @@ public: void setPatternUnit(const Unit &patternUnit); MeasurementsType patternType() const; void setPatternType(const MeasurementsType &patternType); - double toPixel(double unit) const; + + double toPixel(double val, const Unit &unit) const; + double toPixel(double val) const; + double fromPixel(double pix, const Unit &unit) const; double fromPixel(double pix) const; + static const qreal PrintDPI; QString translationsPath() const; QString pathToTables() const;