From 0322457ece1f7aed8d1df801289b28be27837b44 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Thu, 11 Jun 2015 20:36:17 +0300 Subject: [PATCH] Refactoring. Make class VDetail more independent. --HG-- branch : feature --- src/app/container/vcontainer.cpp | 10 ++- src/app/container/vcontainer.h | 11 ++-- src/app/core/vapplication.cpp | 64 ++++--------------- src/app/core/vapplication.h | 10 ++- src/app/dialogs/app/dialoglayoutsettings.cpp | 16 ++--- .../tools/dialogcurveintersectaxis.cpp | 2 +- src/app/dialogs/tools/dialogendline.cpp | 2 +- .../dialogs/tools/dialoglineintersectaxis.cpp | 2 +- src/app/geometry/vdetail.cpp | 9 +-- src/app/mainwindowsnogui.cpp | 25 ++++---- src/app/tools/drawTools/vtoolpoint.cpp | 4 +- src/app/tools/nodeDetails/vnodepoint.cpp | 4 +- src/app/visualization/vcontrolpointspline.cpp | 2 +- src/app/visualization/visualization.cpp | 2 +- src/app/xml/vabstractmeasurements.cpp | 12 ++-- src/libs/ifc/ifc.pri | 3 +- src/libs/ifc/ifcdef.cpp | 31 +++++++++ src/libs/ifc/ifcdef.h | 40 ++++++++++++ 18 files changed, 148 insertions(+), 101 deletions(-) create mode 100644 src/libs/ifc/ifcdef.cpp diff --git a/src/app/container/vcontainer.cpp b/src/app/container/vcontainer.cpp index 928d03c9a..921c65f4c 100644 --- a/src/app/container/vcontainer.cpp +++ b/src/app/container/vcontainer.cpp @@ -47,8 +47,8 @@ QSet VContainer::uniqueNames = QSet(); /** * @brief VContainer create empty container */ -VContainer::VContainer(const VTranslateVars *trVars) - :d(new VContainerData(trVars)) +VContainer::VContainer(const VTranslateVars *trVars, const Unit *patternUnit) + :d(new VContainerData(trVars, patternUnit)) {} //--------------------------------------------------------------------------------------------------------------------- @@ -465,6 +465,12 @@ bool VContainer::IsUnique(const QString &name) return (!uniqueNames.contains(name) && !builInFunctions.contains(name)); } +//--------------------------------------------------------------------------------------------------------------------- +const Unit *VContainer::GetPatternUnit() const +{ + return d->patternUnit; +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief VariableExist check if exist variable this same name. diff --git a/src/app/container/vcontainer.h b/src/app/container/vcontainer.h index 2ec693afd..cd4d4dd89 100644 --- a/src/app/container/vcontainer.h +++ b/src/app/container/vcontainer.h @@ -51,15 +51,15 @@ class VContainerData : public QSharedData { public: - VContainerData(const VTranslateVars *trVars) + VContainerData(const VTranslateVars *trVars, const Unit *patternUnit) :sizeName(size_M), heightName(height_M), gObjects(QHash >()), variables(QHash > ()), details(QHash()), - trVars(trVars) + trVars(trVars), patternUnit(patternUnit) {} VContainerData(const VContainerData &data) :QSharedData(data), sizeName(data.sizeName), heightName(data.heightName), gObjects(data.gObjects), - variables(data.variables), details(data.details), trVars(data.trVars) + variables(data.variables), details(data.details), trVars(data.trVars), patternUnit(data.patternUnit) {} virtual ~VContainerData(); @@ -81,6 +81,7 @@ public: QHash details; const VTranslateVars *trVars; + const Unit *patternUnit; }; #ifdef Q_CC_GNU @@ -94,7 +95,7 @@ class VContainer { Q_DECLARE_TR_FUNCTIONS(VContainer) public: - VContainer(const VTranslateVars *trVars); + VContainer(const VTranslateVars *trVars, const Unit *patternUnit); VContainer &operator=(const VContainer &data); VContainer(const VContainer &data); ~VContainer(); @@ -159,6 +160,8 @@ public: static bool IsUnique(const QString &name); + const Unit *GetPatternUnit() const; + private: /** * @brief _id current id. New object will have value +1. For empty class equal 0. diff --git a/src/app/core/vapplication.cpp b/src/app/core/vapplication.cpp index 63bfefc49..ccbbeb309 100644 --- a/src/app/core/vapplication.cpp +++ b/src/app/core/vapplication.cpp @@ -143,8 +143,6 @@ inline void noisyFailureMsgHandler(QtMsgType type, const QMessageLogContext &con //--------------------------------------------------------------------------------------------------------------------- -const qreal VApplication::PrintDPI = 96.0; - #if defined(Q_OS_WIN) && defined(Q_CC_GNU) const QString VApplication::GistFileName = QStringLiteral("gist.json"); #endif // defined(Q_OS_WIN) && defined(Q_CC_GNU) @@ -288,56 +286,6 @@ bool VApplication::notify(QObject *receiver, QEvent *event) return false; } -//--------------------------------------------------------------------------------------------------------------------- -double VApplication::toPixel(double val, const Unit &unit) const -{ - switch (unit) - { - case Unit::Mm: - return (val / 25.4) * PrintDPI; - case Unit::Cm: - return ((val * 10.0) / 25.4) * PrintDPI; - case Unit::Inch: - return val * PrintDPI; - case Unit::Px: - return val; - default: - break; - } - return 0; -} - -//--------------------------------------------------------------------------------------------------------------------- -double VApplication::toPixel(double val) const -{ - return toPixel(val, _patternUnit); -} - -//--------------------------------------------------------------------------------------------------------------------- -double VApplication::fromPixel(double pix, const Unit &unit) const -{ - switch (unit) - { - case Unit::Mm: - return (pix / PrintDPI) * 25.4; - case Unit::Cm: - return ((pix / PrintDPI) * 25.4) / 10.0; - case Unit::Inch: - return pix / PrintDPI; - case Unit::Px: - return pix; - default: - break; - } - return 0; -} - -//--------------------------------------------------------------------------------------------------------------------- -double VApplication::fromPixel(double pix) const -{ - return fromPixel(pix, _patternUnit); -} - #if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0) //--------------------------------------------------------------------------------------------------------------------- bool VApplication::TryLock(QLockFile *lock) @@ -612,6 +560,18 @@ void VApplication::InitOptions() } } +//--------------------------------------------------------------------------------------------------------------------- +double VApplication::toPixel(double val) const +{ + return ToPixel(val, _patternUnit); +} + +//--------------------------------------------------------------------------------------------------------------------- +double VApplication::fromPixel(double pix) const +{ + return FromPixel(pix, _patternUnit); +} + //--------------------------------------------------------------------------------------------------------------------- QWidget *VApplication::getMainWindow() const { diff --git a/src/app/core/vapplication.h b/src/app/core/vapplication.h index 1afbea2f0..e8a89c5f9 100644 --- a/src/app/core/vapplication.h +++ b/src/app/core/vapplication.h @@ -62,22 +62,20 @@ public: static void CheckFactor(qreal &oldFactor, const qreal &Newfactor); virtual bool notify(QObject * receiver, QEvent * event); Unit patternUnit() const; + const Unit *patternUnitP() const; void setPatternUnit(const Unit &patternUnit); MeasurementsType patternType() const; void setPatternType(const MeasurementsType &patternType); void InitOptions(); - 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; #if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0) static bool TryLock(QLockFile *lock); #endif //QT_VERSION >= QT_VERSION_CHECK(5, 1, 0) - static const qreal PrintDPI; QString translationsPath() const; qreal widthMainLine() const; qreal widthHairLine() const; @@ -188,6 +186,12 @@ inline Unit VApplication::patternUnit() const return _patternUnit; } +//--------------------------------------------------------------------------------------------------------------------- +inline const Unit *VApplication::patternUnitP() const +{ + return &_patternUnit; +} + //--------------------------------------------------------------------------------------------------------------------- inline MeasurementsType VApplication::patternType() const { diff --git a/src/app/dialogs/app/dialoglayoutsettings.cpp b/src/app/dialogs/app/dialoglayoutsettings.cpp index aa380e119..f840af433 100644 --- a/src/app/dialogs/app/dialoglayoutsettings.cpp +++ b/src/app/dialogs/app/dialoglayoutsettings.cpp @@ -254,8 +254,8 @@ void DialogLayoutSettings::ConvertPaperSize() const qreal width = ui->doubleSpinBoxPaperWidth->value(); const qreal height = ui->doubleSpinBoxPaperHeight->value(); - ui->doubleSpinBoxPaperWidth->setMaximum(qApp->fromPixel(QIMAGE_MAX, paperUnit)); - ui->doubleSpinBoxPaperHeight->setMaximum(qApp->fromPixel(QIMAGE_MAX, paperUnit)); + ui->doubleSpinBoxPaperWidth->setMaximum(FromPixel(QIMAGE_MAX, paperUnit)); + ui->doubleSpinBoxPaperHeight->setMaximum(FromPixel(QIMAGE_MAX, paperUnit)); ui->doubleSpinBoxPaperWidth->setValue(VAbstractMeasurements::UnitConvertor(width, oldPaperUnit, paperUnit)); ui->doubleSpinBoxPaperHeight->setValue(VAbstractMeasurements::UnitConvertor(height, oldPaperUnit, paperUnit)); @@ -271,8 +271,8 @@ void DialogLayoutSettings::ConvertLayoutSize() const qreal layoutWidth = ui->doubleSpinBoxLayoutWidth->value(); const qreal shift = ui->doubleSpinBoxShift->value(); - ui->doubleSpinBoxLayoutWidth->setMaximum(qApp->fromPixel(QIMAGE_MAX, unit)); - ui->doubleSpinBoxShift->setMaximum(qApp->fromPixel(QIMAGE_MAX, unit)); + ui->doubleSpinBoxLayoutWidth->setMaximum(FromPixel(QIMAGE_MAX, unit)); + ui->doubleSpinBoxShift->setMaximum(FromPixel(QIMAGE_MAX, unit)); ui->doubleSpinBoxLayoutWidth->setValue(VAbstractMeasurements::UnitConvertor(layoutWidth, oldLayoutUnit, unit)); ui->doubleSpinBoxShift->setValue(VAbstractMeasurements::UnitConvertor(shift, oldLayoutUnit, unit)); @@ -389,7 +389,7 @@ void DialogLayoutSettings::InitTemplates() { const QIcon icoPaper("://icon/16x16/template.png"); const QIcon icoRoll("://icon/16x16/roll.png"); - const QString pdi = QString("(%1ppi)").arg(VApplication::PrintDPI); + const QString pdi = QString("(%1ppi)").arg(PrintDPI); ui->comboBoxTemplates->addItem(icoPaper, "A0 "+pdi, QVariant(static_cast(PaperSizeTemplate::A0))); ui->comboBoxTemplates->addItem(icoPaper, "A1 "+pdi, QVariant(static_cast(PaperSizeTemplate::A1))); @@ -582,7 +582,7 @@ void DialogLayoutSettings::Label() Unit::Px)); const int height = qFloor(VAbstractMeasurements::UnitConvertor(ui->doubleSpinBoxPaperHeight->value(), PaperUnit(), Unit::Px)); - QString text = QString("%1 x %2 px, \n%3 ppi").arg(width).arg(height).arg(VApplication::PrintDPI); + QString text = QString("%1 x %2 px, \n%3 ppi").arg(width).arg(height).arg(PrintDPI); ui->labelSizeDescription->setText(text); } @@ -645,8 +645,8 @@ void DialogLayoutSettings::WriteSettings() const void DialogLayoutSettings::SheetSize(const QSizeF &size) { oldPaperUnit = PaperUnit(); - ui->doubleSpinBoxPaperWidth->setMaximum(qApp->fromPixel(QIMAGE_MAX, oldPaperUnit)); - ui->doubleSpinBoxPaperHeight->setMaximum(qApp->fromPixel(QIMAGE_MAX, oldPaperUnit)); + ui->doubleSpinBoxPaperWidth->setMaximum(FromPixel(QIMAGE_MAX, oldPaperUnit)); + ui->doubleSpinBoxPaperHeight->setMaximum(FromPixel(QIMAGE_MAX, oldPaperUnit)); ui->doubleSpinBoxPaperWidth->setValue(size.width()); ui->doubleSpinBoxPaperHeight->setValue(size.height()); diff --git a/src/app/dialogs/tools/dialogcurveintersectaxis.cpp b/src/app/dialogs/tools/dialogcurveintersectaxis.cpp index a5134227a..62aa33b15 100644 --- a/src/app/dialogs/tools/dialogcurveintersectaxis.cpp +++ b/src/app/dialogs/tools/dialogcurveintersectaxis.cpp @@ -179,7 +179,7 @@ void DialogCurveIntersectAxis::ShowDialog(bool click) QLineF line = QLineF(point->toQPointF(), scene->getScenePos()); //Radius of point circle, but little bigger. Need handle with hover sizes. - qreal radius = qApp->toPixel(DefPointRadius/*mm*/, Unit::Mm)*1.5; + qreal radius = ToPixel(DefPointRadius/*mm*/, Unit::Mm)*1.5; if (line.length() <= radius) { return; diff --git a/src/app/dialogs/tools/dialogendline.cpp b/src/app/dialogs/tools/dialogendline.cpp index 88e362040..91ec9114a 100644 --- a/src/app/dialogs/tools/dialogendline.cpp +++ b/src/app/dialogs/tools/dialogendline.cpp @@ -278,7 +278,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 = qApp->toPixel(DefPointRadius/*mm*/, Unit::Mm)*1.5; + qreal radius = ToPixel(DefPointRadius/*mm*/, Unit::Mm)*1.5; if (line.length() <= radius) { return; diff --git a/src/app/dialogs/tools/dialoglineintersectaxis.cpp b/src/app/dialogs/tools/dialoglineintersectaxis.cpp index 153028627..60c399fde 100644 --- a/src/app/dialogs/tools/dialoglineintersectaxis.cpp +++ b/src/app/dialogs/tools/dialoglineintersectaxis.cpp @@ -203,7 +203,7 @@ void DialogLineIntersectAxis::ShowDialog(bool click) QLineF line = QLineF(point->toQPointF(), scene->getScenePos()); //Radius of point circle, but little bigger. Need handle with hover sizes. - qreal radius = qApp->toPixel(DefPointRadius/*mm*/, Unit::Mm)*1.5; + qreal radius = ToPixel(DefPointRadius/*mm*/, Unit::Mm)*1.5; if (line.length() <= radius) { return; diff --git a/src/app/geometry/vdetail.cpp b/src/app/geometry/vdetail.cpp index 72ced0fa1..c902c8f97 100644 --- a/src/app/geometry/vdetail.cpp +++ b/src/app/geometry/vdetail.cpp @@ -29,8 +29,7 @@ #include "vdetail.h" #include "vdetail_p.h" #include "../container/vcontainer.h" -#include "vpointf.h" -#include "../core/vapplication.h" +#include "../libs/vgeometry/vpointf.h" #include #include @@ -428,11 +427,13 @@ QVector VDetail::SeamAllowancePoints(const VContainer *data) const if (getClosed() == true) { - pointsEkv = Equidistant(pointsEkv, EquidistantType::CloseEquidistant, qApp->toPixel(getWidth())); + pointsEkv = Equidistant(pointsEkv, EquidistantType::CloseEquidistant, ToPixel(getWidth(), + *data->GetPatternUnit())); } else { - pointsEkv = Equidistant(pointsEkv, EquidistantType::OpenEquidistant, qApp->toPixel(getWidth())); + pointsEkv = Equidistant(pointsEkv, EquidistantType::OpenEquidistant, ToPixel(getWidth(), + *data->GetPatternUnit())); } return pointsEkv; } diff --git a/src/app/mainwindowsnogui.cpp b/src/app/mainwindowsnogui.cpp index 28e837907..f12399b06 100644 --- a/src/app/mainwindowsnogui.cpp +++ b/src/app/mainwindowsnogui.cpp @@ -57,9 +57,10 @@ //--------------------------------------------------------------------------------------------------------------------- MainWindowsNoGUI::MainWindowsNoGUI(QWidget *parent) : QMainWindow(parent), listDetails(QVector()), currentScene(nullptr), tempSceneLayout(nullptr), - pattern(new VContainer(qApp->TrVars())), doc(nullptr), papers(QList()), shadows(QList()), - scenes(QList()), details(QList >()), undoAction(nullptr), - redoAction(nullptr), actionDockWidgetToolOptions(nullptr), curFile(QString()), isLayoutStale(true), isTiled(false) + pattern(new VContainer(qApp->TrVars(), qApp->patternUnitP())), doc(nullptr), papers(QList()), + shadows(QList()), scenes(QList()), details(QList >()), + undoAction(nullptr), redoAction(nullptr), actionDockWidgetToolOptions(nullptr), curFile(QString()), + isLayoutStale(true), isTiled(false) { InitTempLayoutScene(); } @@ -502,7 +503,7 @@ void MainWindowsNoGUI::SvgFile(const QString &name, int i) const generator.setViewBox(paper->rect()); generator.setTitle("Valentina. Pattern layout"); generator.setDescription(doc->GetDescription()); - generator.setResolution(static_cast(qApp->PrintDPI)); + generator.setResolution(static_cast(PrintDPI)); QPainter painter; painter.begin(&generator); painter.setFont( QFont( "Arial", 8, QFont::Normal ) ); @@ -556,7 +557,7 @@ void MainWindowsNoGUI::PdfFile(const QString &name, int i) const printer.setOutputFileName(name); printer.setDocName(FileName()); const QRectF r = paper->rect(); - printer.setResolution(static_cast(qApp->PrintDPI)); + printer.setResolution(static_cast(PrintDPI)); // Set orientation if (paper->rect().height()>= paper->rect().width()) { @@ -566,7 +567,7 @@ void MainWindowsNoGUI::PdfFile(const QString &name, int i) const { printer.setOrientation(QPrinter::Landscape); } - printer.setPaperSize ( QSizeF(qApp->fromPixel(r.width(), Unit::Mm), qApp->fromPixel(r.height(), Unit::Mm)), + printer.setPaperSize ( QSizeF(FromPixel(r.width(), Unit::Mm), FromPixel(r.height(), Unit::Mm)), QPrinter::Millimeter ); QPainter painter; if (painter.begin( &printer ) == false) @@ -652,7 +653,7 @@ void MainWindowsNoGUI::ObjFile(const QString &name, int i) const VObjPaintDevice generator; generator.setFileName(name); generator.setSize(paper->rect().size().toSize()); - generator.setResolution(static_cast(qApp->PrintDPI)); + generator.setResolution(static_cast(PrintDPI)); QPainter painter; painter.begin(&generator); scenes.at(i)->render(&painter, paper->rect(), paper->rect(), Qt::IgnoreAspectRatio); @@ -730,7 +731,7 @@ void MainWindowsNoGUI::SaveLayoutAs() qApp->getSettings()->SetPathLayout(f.absolutePath()); printer.setOutputFileName(fileName); - printer.setResolution(static_cast(VApplication::PrintDPI)); + printer.setResolution(static_cast(PrintDPI)); PrintPages( &printer ); } } @@ -764,7 +765,7 @@ void MainWindowsNoGUI::PrintPreview() } QPrinter printer(def, QPrinter::ScreenResolution); - printer.setResolution(static_cast(VApplication::PrintDPI)); + printer.setResolution(static_cast(PrintDPI)); SetPrinterSettings(&printer); // display print preview dialog QPrintPreviewDialog preview(&printer); @@ -790,7 +791,7 @@ void MainWindowsNoGUI::LayoutPrint() dialog.setOption(QPrintDialog::PrintCurrentPage, false); if ( dialog.exec() == QDialog::Accepted ) { - printer.setResolution(static_cast(VApplication::PrintDPI)); + printer.setResolution(static_cast(PrintDPI)); PrintPages( &printer ); } } @@ -820,8 +821,8 @@ void MainWindowsNoGUI::SetPrinterSettings(QPrinter *printer) { QGraphicsRectItem *paper = qgraphicsitem_cast(papers.at(0)); SCASSERT(paper != nullptr) - printer->setPaperSize ( QSizeF(qApp->fromPixel(paper->rect().width(), Unit::Mm), - qApp->fromPixel(paper->rect().height(), Unit::Mm)), QPrinter::Millimeter ); + printer->setPaperSize ( QSizeF(FromPixel(paper->rect().width(), Unit::Mm), + FromPixel(paper->rect().height(), Unit::Mm)), QPrinter::Millimeter ); } printer->setDocName(FileName()); diff --git a/src/app/tools/drawTools/vtoolpoint.cpp b/src/app/tools/drawTools/vtoolpoint.cpp index 1da449d57..33a9fac30 100644 --- a/src/app/tools/drawTools/vtoolpoint.cpp +++ b/src/app/tools/drawTools/vtoolpoint.cpp @@ -50,7 +50,7 @@ VToolPoint::VToolPoint(VPattern *doc, VContainer *data, quint32 id, QGraphicsIte :VDrawTool(doc, data, id), QGraphicsEllipseItem(parent), radius(DefPointRadius), namePoint(nullptr), lineName(nullptr) { - radius = qApp->toPixel(DefPointRadius/*mm*/, Unit::Mm); + radius = ToPixel(DefPointRadius/*mm*/, Unit::Mm); namePoint = new VGraphicsSimpleTextItem(this); connect(namePoint, &VGraphicsSimpleTextItem::ShowContextMenu, this, &VToolPoint::contextMenuEvent); connect(namePoint, &VGraphicsSimpleTextItem::DeleteTool, this, &VToolPoint::DeleteFromLabel); @@ -279,7 +279,7 @@ void VToolPoint::RefreshLine() lineName->setLine(QLineF(p1, pRec - scenePos())); lineName->setPen(QPen(CorrectColor(Qt::black), qApp->toPixel(qApp->widthHairLine())/factor)); - if (QLineF(p1, pRec - scenePos()).length() <= qApp->toPixel(4, Unit::Mm)) + if (QLineF(p1, pRec - scenePos()).length() <= ToPixel(4, Unit::Mm)) { lineName->setVisible(false); } diff --git a/src/app/tools/nodeDetails/vnodepoint.cpp b/src/app/tools/nodeDetails/vnodepoint.cpp index c080edf5c..3318a0e63 100644 --- a/src/app/tools/nodeDetails/vnodepoint.cpp +++ b/src/app/tools/nodeDetails/vnodepoint.cpp @@ -55,7 +55,7 @@ VNodePoint::VNodePoint(VPattern *doc, VContainer *data, quint32 id, quint32 idPo :VAbstractNode(doc, data, id, idPoint, idTool, qoParent), QGraphicsEllipseItem(parent), radius(0), namePoint(nullptr), lineName(nullptr) { - radius = qApp->toPixel(DefPointRadius/*mm*/, Unit::Mm); + radius = ToPixel(DefPointRadius/*mm*/, Unit::Mm); namePoint = new VGraphicsSimpleTextItem(this); lineName = new QGraphicsLineItem(this); connect(namePoint, &VGraphicsSimpleTextItem::NameChangePosition, this, @@ -286,7 +286,7 @@ void VNodePoint::RefreshLine() VGObject::LineIntersectCircle(QPointF(), radius, QLineF(QPointF(), nameRec.center()- scenePos()), p1, p2); QPointF pRec = VGObject::LineIntersectRect(nameRec, QLineF(scenePos(), nameRec.center())); lineName->setLine(QLineF(p1, pRec - scenePos())); - if (QLineF(p1, pRec - scenePos()).length() <= qApp->toPixel(4, Unit::Mm)) + if (QLineF(p1, pRec - scenePos()).length() <= ToPixel(4, Unit::Mm)) { lineName->setVisible(false); } diff --git a/src/app/visualization/vcontrolpointspline.cpp b/src/app/visualization/vcontrolpointspline.cpp index 11cc17cd0..5b1a91d48 100644 --- a/src/app/visualization/vcontrolpointspline.cpp +++ b/src/app/visualization/vcontrolpointspline.cpp @@ -49,7 +49,7 @@ VControlPointSpline::VControlPointSpline(const qint32 &indexSpline, SplinePointP :QGraphicsEllipseItem(parent), radius(0), controlLine(nullptr), indexSpline(indexSpline), position(position) { //create circle - radius = (1.5/*mm*/ / 25.4) * VApplication::PrintDPI; + radius = (1.5/*mm*/ / 25.4) * PrintDPI; QRectF rec = QRectF(0, 0, radius*2, radius*2); rec.translate(-rec.center().x(), -rec.center().y()); this->setRect(rec); diff --git a/src/app/visualization/visualization.cpp b/src/app/visualization/visualization.cpp index fdac90ee9..ade0be1ae 100644 --- a/src/app/visualization/visualization.cpp +++ b/src/app/visualization/visualization.cpp @@ -110,7 +110,7 @@ QGraphicsEllipseItem *Visualization::InitPoint(const QColor &color, QGraphicsIte point->setZValue(1); point->setBrush(QBrush(Qt::NoBrush)); point->setPen(QPen(color, qApp->toPixel(qApp->widthMainLine())/factor)); - point->setRect(PointRect(qApp->toPixel(DefPointRadius/*mm*/, Unit::Mm))); + point->setRect(PointRect(ToPixel(DefPointRadius/*mm*/, Unit::Mm))); point->setFlags(QGraphicsItem::ItemStacksBehindParent); point->setVisible(false); return point; diff --git a/src/app/xml/vabstractmeasurements.cpp b/src/app/xml/vabstractmeasurements.cpp index 97be9fb28..4c87b9fc2 100644 --- a/src/app/xml/vabstractmeasurements.cpp +++ b/src/app/xml/vabstractmeasurements.cpp @@ -216,7 +216,7 @@ qreal VAbstractMeasurements::UnitConvertor(qreal value, const Unit &from, const case Unit::Inch: return value / 25.4; case Unit::Px: - return (value / 25.4) * VApplication::PrintDPI; + return (value / 25.4) * PrintDPI; default: break; } @@ -231,7 +231,7 @@ qreal VAbstractMeasurements::UnitConvertor(qreal value, const Unit &from, const case Unit::Inch: return value / 2.54; case Unit::Px: - return ((value * 10.0) / 25.4) * VApplication::PrintDPI; + return ((value * 10.0) / 25.4) * PrintDPI; default: break; } @@ -246,7 +246,7 @@ qreal VAbstractMeasurements::UnitConvertor(qreal value, const Unit &from, const case Unit::Inch: return value; case Unit::Px: - return value * VApplication::PrintDPI; + return value * PrintDPI; default: break; } @@ -255,11 +255,11 @@ qreal VAbstractMeasurements::UnitConvertor(qreal value, const Unit &from, const switch (to) { case Unit::Mm: - return (value / VApplication::PrintDPI) * 25.4; + return (value / PrintDPI) * 25.4; case Unit::Cm: - return ((value / VApplication::PrintDPI) * 25.4) / 10.0; + return ((value / PrintDPI) * 25.4) / 10.0; case Unit::Inch: - return value / VApplication::PrintDPI; + return value / PrintDPI; case Unit::Px: return value; default: diff --git a/src/libs/ifc/ifc.pri b/src/libs/ifc/ifc.pri index 124d558f1..b95b3e813 100644 --- a/src/libs/ifc/ifc.pri +++ b/src/libs/ifc/ifc.pri @@ -10,4 +10,5 @@ HEADERS += \ $$PWD/ifcdef.h SOURCES += \ - $$PWD/stable.cpp + $$PWD/stable.cpp \ + ifcdef.cpp diff --git a/src/libs/ifc/ifcdef.cpp b/src/libs/ifc/ifcdef.cpp new file mode 100644 index 000000000..75410d596 --- /dev/null +++ b/src/libs/ifc/ifcdef.cpp @@ -0,0 +1,31 @@ +/************************************************************************ + ** + ** @file ifcdef.cpp + ** @author Roman Telezhynskyi + ** @date 11 6, 2015 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2015 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#include "ifcdef.h" + +const qreal PrintDPI = 96.0; diff --git a/src/libs/ifc/ifcdef.h b/src/libs/ifc/ifcdef.h index 506533397..9b0e7a03a 100644 --- a/src/libs/ifc/ifcdef.h +++ b/src/libs/ifc/ifcdef.h @@ -59,4 +59,44 @@ static const quint32 null_id = 0; # define V_NOEXCEPT_EXPR(x) # endif +extern const qreal PrintDPI; + +//--------------------------------------------------------------------------------------------------------------------- +inline double ToPixel(double val, const Unit &unit) +{ + switch (unit) + { + case Unit::Mm: + return (val / 25.4) * PrintDPI; + case Unit::Cm: + return ((val * 10.0) / 25.4) * PrintDPI; + case Unit::Inch: + return val * PrintDPI; + case Unit::Px: + return val; + default: + break; + } + return 0; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline double FromPixel(double pix, const Unit &unit) +{ + switch (unit) + { + case Unit::Mm: + return (pix / PrintDPI) * 25.4; + case Unit::Cm: + return ((pix / PrintDPI) * 25.4) / 10.0; + case Unit::Inch: + return pix / PrintDPI; + case Unit::Px: + return pix; + default: + break; + } + return 0; +} + #endif // IFCDEF_H