From d30ca54297a0926d7384c5af5a74add8cd463247 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 23 Jan 2021 18:54:07 +0200 Subject: [PATCH] Fix width of a grainline on export. --- src/app/valentina/mainwindowsnogui.cpp | 10 +++--- src/libs/vlayout/vgraphicsfillitem.cpp | 8 +++-- src/libs/vlayout/vgraphicsfillitem.h | 18 +++++++++++ src/libs/vlayout/vlayoutpiece.cpp | 15 +++++++-- src/libs/vwidgets/vgrainlineitem.cpp | 45 +++++++------------------- src/libs/vwidgets/vgrainlineitem.h | 5 +-- 6 files changed, 54 insertions(+), 47 deletions(-) diff --git a/src/app/valentina/mainwindowsnogui.cpp b/src/app/valentina/mainwindowsnogui.cpp index e099ce634..80f377365 100644 --- a/src/app/valentina/mainwindowsnogui.cpp +++ b/src/app/valentina/mainwindowsnogui.cpp @@ -1122,12 +1122,12 @@ void MainWindowsNoGUI::ExportScene(const QList &scenes, paper->setVisible(true); break; case LayoutExportFormats::PDF: - exporter.SetPen(QPen(Qt::black, qApp->Settings()->WidthMainLine(), Qt::SolidLine, Qt::RoundCap, + exporter.SetPen(QPen(Qt::black, qApp->Settings()->WidthHairLine(), Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); exporter.ExportToPDF(scene); break; case LayoutExportFormats::PNG: - exporter.SetPen(QPen(Qt::black, qApp->Settings()->WidthMainLine(), Qt::SolidLine, Qt::RoundCap, + exporter.SetPen(QPen(Qt::black, qApp->Settings()->WidthHairLine(), Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); exporter.ExportToPNG(scene); break; @@ -1137,12 +1137,12 @@ void MainWindowsNoGUI::ExportScene(const QList &scenes, paper->setVisible(true); break; case LayoutExportFormats::PS: - exporter.SetPen(QPen(Qt::black, qApp->Settings()->WidthMainLine(), Qt::SolidLine, Qt::RoundCap, + exporter.SetPen(QPen(Qt::black, qApp->Settings()->WidthHairLine(), Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); exporter.ExportToPS(scene); break; case LayoutExportFormats::EPS: - exporter.SetPen(QPen(Qt::black, qApp->Settings()->WidthMainLine(), Qt::SolidLine, Qt::RoundCap, + exporter.SetPen(QPen(Qt::black, qApp->Settings()->WidthHairLine(), Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); exporter.ExportToEPS(scene); break; @@ -1201,7 +1201,7 @@ void MainWindowsNoGUI::ExportScene(const QList &scenes, paper->setVisible(true); break; case LayoutExportFormats::TIF: - exporter.SetPen(QPen(Qt::black, qApp->Settings()->WidthMainLine(), Qt::SolidLine, Qt::RoundCap, + exporter.SetPen(QPen(Qt::black, qApp->Settings()->WidthHairLine(), Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); exporter.ExportToTIF(scene); break; diff --git a/src/libs/vlayout/vgraphicsfillitem.cpp b/src/libs/vlayout/vgraphicsfillitem.cpp index 5eae5a20d..7fb676f36 100644 --- a/src/libs/vlayout/vgraphicsfillitem.cpp +++ b/src/libs/vlayout/vgraphicsfillitem.cpp @@ -43,10 +43,12 @@ void VGraphicsFillItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* Q_UNUSED(option) Q_UNUSED(widget) painter->save(); + + QPen pen = painter->pen(); + pen.setWidthF(width); + painter->setPen(pen); + painter->setBrush(painter->pen().color()); painter->drawPath(path()); painter->restore(); } - -//--------------------------------------------------------------------------------------------------------------------- - diff --git a/src/libs/vlayout/vgraphicsfillitem.h b/src/libs/vlayout/vgraphicsfillitem.h index ef8f87c8e..60aee1a37 100644 --- a/src/libs/vlayout/vgraphicsfillitem.h +++ b/src/libs/vlayout/vgraphicsfillitem.h @@ -50,6 +50,24 @@ public: * @param widget unused */ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); + + auto GetWidth() const -> qreal; + void SetWidth(const qreal &value); + +private: + qreal width{1}; }; +//--------------------------------------------------------------------------------------------------------------------- +inline auto VGraphicsFillItem::GetWidth() const -> qreal +{ + return width; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline void VGraphicsFillItem::SetWidth(const qreal &value) +{ + width = value; +} + #endif // VGRAPHICSFILLITEM_H diff --git a/src/libs/vlayout/vlayoutpiece.cpp b/src/libs/vlayout/vlayoutpiece.cpp index 7248e2299..cc83c765d 100644 --- a/src/libs/vlayout/vlayoutpiece.cpp +++ b/src/libs/vlayout/vlayoutpiece.cpp @@ -1152,12 +1152,16 @@ QGraphicsItem *VLayoutPiece::GetItem(bool textAsPaths) const QPen pen = pathItem->pen(); pen.setStyle(path.PenStyle()); + pen.setWidthF(qApp->Settings()->WidthHairLine()); pathItem->setPen(pen); } for (auto &label : d->m_placeLabels) { QGraphicsPathItem* pathItem = new QGraphicsPathItem(item); + QPen pen = pathItem->pen(); + pen.setWidthF(qApp->Settings()->WidthHairLine()); + pathItem->setPen(pen); pathItem->setPath(d->matrix.map(VPlaceLabelItem::LabelShapePath(label.shape))); } @@ -1322,13 +1326,14 @@ void VLayoutPiece::CreateGrainlineItem(QGraphicsItem *parent) const { return; } - VGraphicsFillItem* item = new VGraphicsFillItem(parent); + auto* item = new VGraphicsFillItem(parent); + item->SetWidth(qApp->Settings()->WidthHairLine()); QPainterPath path; QVector gPoints = GetGrainline(); path.moveTo(gPoints.at(0)); - for (auto p : gPoints) + for (auto p : qAsConst(gPoints)) { path.lineTo(p); } @@ -1352,6 +1357,9 @@ QVector VLayoutPiece::DetailPath() const QGraphicsPathItem *VLayoutPiece::GetMainItem() const { QGraphicsPathItem *item = new QGraphicsPathItem(); + QPen pen = item->pen(); + pen.setWidthF(qApp->Settings()->WidthHairLine()); + item->setPen(pen); item->setPath(ContourPath()); return item; } @@ -1360,6 +1368,9 @@ QGraphicsPathItem *VLayoutPiece::GetMainItem() const QGraphicsPathItem *VLayoutPiece::GetMainPathItem() const { QGraphicsPathItem *item = new QGraphicsPathItem(); + QPen pen = item->pen(); + pen.setWidthF(qApp->Settings()->WidthHairLine()); + item->setPen(pen); QPainterPath path; diff --git a/src/libs/vwidgets/vgrainlineitem.cpp b/src/libs/vwidgets/vgrainlineitem.cpp index ae694daf8..d564f896c 100644 --- a/src/libs/vwidgets/vgrainlineitem.cpp +++ b/src/libs/vwidgets/vgrainlineitem.cpp @@ -37,6 +37,8 @@ #include "../vmisc/def.h" #include "../vmisc/vmath.h" +#include "../vmisc/vabstractvalapplication.h" +#include "global.h" #include "vgrainlineitem.h" @@ -61,7 +63,6 @@ VGrainlineItem::VGrainlineItem(QGraphicsItem* pParent) m_polyBound(), m_ptStartPos(), m_ptStartMove(), - m_dScale(1), m_polyResize(), m_dStartLength(0), m_ptStart(), @@ -69,7 +70,7 @@ VGrainlineItem::VGrainlineItem(QGraphicsItem* pParent) m_ptCenter(), m_dAngle(0), m_eArrowType(GrainlineArrowDirection::atBoth), - m_penWidth(LINE_PEN_WIDTH) + m_penWidth(qApp->Settings()->WidthMainLine()) { setAcceptHoverEvents(true); m_inactiveZ = 5; @@ -105,7 +106,9 @@ void VGrainlineItem::paint(QPainter* pP, const QStyleOptionGraphicsItem* pOption Q_UNUSED(pWidget) pP->save(); QColor clr = Qt::black; - pP->setPen(QPen(clr, m_penWidth, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); + + const qreal width = ScaleWidth(qApp->Settings()->WidthHairLine(), SceneScale(scene())); + pP->setPen(QPen(clr, width, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); pP->setRenderHints(QPainter::Antialiasing); // line @@ -114,8 +117,7 @@ void VGrainlineItem::paint(QPainter* pP, const QStyleOptionGraphicsItem* pOption pP->setBrush(clr); - m_dScale = GetScale(); - qreal dArrLen = ARROW_LENGTH*m_dScale; + qreal dArrLen = ARROW_LENGTH; if (m_eArrowType != GrainlineArrowDirection::atRear) { // first arrow @@ -153,7 +155,7 @@ void VGrainlineItem::paint(QPainter* pP, const QStyleOptionGraphicsItem* pOption if (m_eMode == mRotate) { QPointF ptC = (m_polyBound.at(0) + m_polyBound.at(2))/2; - qreal dRad = m_dScale * ROTATE_CIRC_R; + qreal dRad = ROTATE_CIRC_R; pP->setBrush(clr); pP->drawEllipse(ptC, dRad, dRad); @@ -526,7 +528,7 @@ void VGrainlineItem::hoverEnterEvent(QGraphicsSceneHoverEvent *pME) if (flags() & QGraphicsItem::ItemIsMovable) { SetItemOverrideCursor(this, cursorArrowOpenHand, 1, 1); - m_penWidth = LINE_PEN_WIDTH + 1; + m_penWidth = qApp->Settings()->WidthMainLine() + 1; } VPieceItem::hoverEnterEvent(pME); } @@ -536,7 +538,7 @@ void VGrainlineItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *pME) { if (flags() & QGraphicsItem::ItemIsMovable) { - m_penWidth = LINE_PEN_WIDTH; + m_penWidth = qApp->Settings()->WidthMainLine(); } VPieceItem::hoverLeaveEvent(pME); } @@ -624,29 +626,6 @@ QPointF VGrainlineItem::GetInsideCorner(int i, qreal dDist) const return m_polyBound.at(i) + pt1 + pt2; } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief GetScale gets the scale for keeping the arrows of constant size - */ -qreal VGrainlineItem::GetScale() const -{ - if (scene()->views().count() > 0) - { - const QPoint pt0 = scene()->views().at(0)->mapFromScene(0, 0); - const QPoint pt = scene()->views().at(0)->mapFromScene(0, 100); - const QPoint p = pt - pt0; - qreal dScale = qSqrt(QPoint::dotProduct(p, p)); - dScale = 100.0/dScale; - if (dScale < 1.0) - { - dScale = 1.0; - } - return dScale; - } - - return 1.0; -} - //--------------------------------------------------------------------------------------------------------------------- QLineF VGrainlineItem::MainLine() const { @@ -696,7 +675,7 @@ QPainterPath VGrainlineItem::MainShape() const path.addPath((stroker.createStroke(linePath) + linePath).simplified()); path.closeSubpath(); - const qreal dArrLen = ARROW_LENGTH*GetScale(); + const qreal dArrLen = ARROW_LENGTH; if (m_eArrowType != GrainlineArrowDirection::atRear) { // first arrow @@ -761,7 +740,7 @@ void VGrainlineItem::UpdatePolyResize() m_polyResize.clear(); QPointF ptA = m_polyBound.at(1); m_polyResize << ptA; - const double dSize = m_dScale * RESIZE_RECT_SIZE; + const double dSize = RESIZE_RECT_SIZE; ptA.setX(ptA.x() - dSize*cos(m_dRotation - M_PI/2)); ptA.setY(ptA.y() + dSize*sin(m_dRotation - M_PI/2)); diff --git a/src/libs/vwidgets/vgrainlineitem.h b/src/libs/vwidgets/vgrainlineitem.h index cbd05fe7d..d15a3e987 100644 --- a/src/libs/vwidgets/vgrainlineitem.h +++ b/src/libs/vwidgets/vgrainlineitem.h @@ -78,7 +78,6 @@ private: QPolygonF m_polyBound; QPointF m_ptStartPos; QPointF m_ptStartMove; - qreal m_dScale; QPolygonF m_polyResize; qreal m_dStartLength; QPointF m_ptStart; @@ -86,9 +85,7 @@ private: QPointF m_ptCenter; qreal m_dAngle; GrainlineArrowDirection m_eArrowType; - int m_penWidth; - - qreal GetScale() const; + double m_penWidth{1}; QLineF MainLine() const; QPolygonF FirstArrow(qreal dArrLen) const;