diff --git a/src/Mod/TechDraw/Gui/PATPathMaker.cpp b/src/Mod/TechDraw/Gui/PATPathMaker.cpp index 3875cce405..7bca467518 100644 --- a/src/Mod/TechDraw/Gui/PATPathMaker.cpp +++ b/src/Mod/TechDraw/Gui/PATPathMaker.cpp @@ -213,6 +213,11 @@ QPainterPath PATPathMaker::dashedPPath(const std::vector dashPattern, co return result; } +void PATPathMaker::setLineWidth(double width) +{ + m_lineWidth = width; + m_pen.setWidthF(width); +} //! convert a dash pattern to an offset dash pattern (ie offset -> end) // dashPattern & offset are already scaled. diff --git a/src/Mod/TechDraw/Gui/PATPathMaker.h b/src/Mod/TechDraw/Gui/PATPathMaker.h index e51a6e559b..d775f22449 100644 --- a/src/Mod/TechDraw/Gui/PATPathMaker.h +++ b/src/Mod/TechDraw/Gui/PATPathMaker.h @@ -40,7 +40,7 @@ public: explicit PATPathMaker(QGraphicsItem* parent = nullptr, double lineWidth = 0.50, double fillScale = 1.0); ~PATPathMaker() = default; - void setLineWidth(double width) { m_lineWidth = width; } + void setLineWidth(double width); void setScale(double scale) { m_fillScale = scale; } void setPen(QPen pen) { m_pen = pen; } QPen getPen() { return m_pen; } @@ -61,7 +61,6 @@ protected: private: QGraphicsItem* m_parent; - QPainterPath m_geomhatch; //crosshatch fill lines QPen m_pen; std::vector m_lineSets; diff --git a/src/Mod/TechDraw/Gui/QGIFace.cpp b/src/Mod/TechDraw/Gui/QGIFace.cpp index b55a09da67..1fa8b3d882 100644 --- a/src/Mod/TechDraw/Gui/QGIFace.cpp +++ b/src/Mod/TechDraw/Gui/QGIFace.cpp @@ -56,7 +56,6 @@ using namespace TechDraw; using DU = DrawUtil; QGIFace::QGIFace(int index) : - m_hideSvgTiles(false), projIndex(index), m_hatchRotation(0.0) { @@ -65,8 +64,6 @@ QGIFace::QGIFace(int index) : setStyle(Qt::NoPen); //don't draw face lines, just fill for debugging //setStyle(Qt::DashLine); - m_geomColor = PreferencesGui::getAccessibleQColor(QColor(Qt::black)); - setLineWeight(0.0); //0 = cosmetic m_texture = QPixmap(); //empty texture @@ -85,6 +82,9 @@ QGIFace::QGIFace(int index) : m_sharedRender = new QSvgRenderer(); m_patMaker = new PATPathMaker(this, 1.0, 1.0); + setHatchColor(PreferencesGui::getAccessibleQColor(QColor(Qt::black))); + m_patMaker->setLineWidth(0.5); + setLineWeight(0.0); //0 = cosmetic } QGIFace::~QGIFace() @@ -105,7 +105,6 @@ QColor QGIFace::getDefaultFillColor() void QGIFace::draw() { // Base::Console().Message("QGIF::draw - pen style: %d\n", m_pen.style()); - setPath(m_outline); //Face boundary m_svgHatchArea->hide(); m_imageSvgHatchArea->hide(); @@ -226,14 +225,13 @@ void QGIFace::setFillMode(FillMode mode) /// update the outline of this face void QGIFace::setOutline(const QPainterPath & path) { - m_outline = path; + setPath(path); } /// remove the PAT hatch lines void QGIFace::clearLineSets() { - m_dashSpecs.clear(); - clearFillItems(); + return; } /// add PAT hatch line set @@ -245,7 +243,6 @@ void QGIFace::addLineSet(LineSet& ls) /// convert the PAT line set to QGraphicsPathItems void QGIFace::lineSetToFillItems(LineSet& ls) { - m_patMaker->setLineWidth(Rez::guiX(m_geomWeight)); m_patMaker->setScale(m_fillScale); m_patMaker->setPen(setGeomPen()); m_patMaker->lineSetToFillItems(ls); @@ -254,8 +251,6 @@ void QGIFace::lineSetToFillItems(LineSet& ls) QPen QGIFace::setGeomPen() { QPen result; - result.setWidthF(Rez::guiX(m_geomWeight)); - result.setColor(m_geomColor); result.setStyle(Qt::SolidLine); return result; } @@ -278,16 +273,6 @@ double QGIFace::getXForm() return 1.0; } -/// remove the children that make up a PAT fill -void QGIFace::clearFillItems() -{ - for (auto& fill: m_fillItems) { - fill->setParentItem(nullptr); - this->scene()->removeItem(fill); - delete fill; - } -} - /// debugging tool draws a mark at a position on this face void QGIFace::makeMark(double x, double y) // NOLINT readability-identifier-length { @@ -305,10 +290,10 @@ void QGIFace::buildSvgHatch() // Base::Console().Message("QGIF::buildSvgHatch() - offset: %s\n", DrawUtil::formatVector(getHatchOffset()).c_str()); double wTile = SVGSIZEW * m_fillScale; double hTile = SVGSIZEH * m_fillScale; - double faceWidth = m_outline.boundingRect().width(); - double faceHeight = m_outline.boundingRect().height(); + double faceWidth = path().boundingRect().width(); + double faceHeight = path().boundingRect().height(); double faceOverlaySize = Preferences::svgHatchFactor() * std::max(faceWidth, faceHeight); - QPointF faceCenter = m_outline.boundingRect().center(); + QPointF faceCenter = path().boundingRect().center(); double tilesWide = ceil(faceOverlaySize / wTile); double tilesHigh = ceil(faceOverlaySize / hTile); @@ -348,21 +333,16 @@ void QGIFace::buildSvgHatch() m_svgHatchArea->setRotation(m_hatchRotation); } -void QGIFace::clearSvg() -{ - hideSvg(true); -} - //! similar to svg hatch, but using pixmaps. we do this because QGraphicsSvgItems are not clipped //! when we export the scene to svg, but pixmaps are clipped. void QGIFace::buildPixHatch() { double wTile = SVGSIZEW * m_fillScale; double hTile = SVGSIZEH * m_fillScale; - double faceWidth = m_outline.boundingRect().width(); - double faceHeight = m_outline.boundingRect().height(); + double faceWidth = path().boundingRect().width(); + double faceHeight = path().boundingRect().height(); double faceOverlaySize = Preferences::svgHatchFactor() * std::max(faceWidth, faceHeight); - QPointF faceCenter = m_outline.boundingRect().center(); + QPointF faceCenter = path().boundingRect().center(); double tilesWide = ceil(faceOverlaySize / wTile); double tilesHigh = ceil(faceOverlaySize / hTile); @@ -452,7 +432,15 @@ void QGIFace::buildPixHatch() void QGIFace::setHatchColor(Base::Color color) { m_svgCol = color.asHexString(); - m_geomColor = color.asValue(); + + QPen p = m_patMaker->getPen(); + p.setColor(color.asValue()); + m_patMaker->setPen(p); +} + +void QGIFace::setHatchColor(QColor color) +{ + setHatchColor(Base::Color::fromValue(color)); } void QGIFace::setHatchScale(double scale) @@ -460,16 +448,6 @@ void QGIFace::setHatchScale(double scale) m_fillScale = scale; } -/// turn svg tiles on or off. QtSvg does not handle clipping, -/// so we must be able to turn the hatching on/off when exporting a face with an -/// svg hatch. Otherwise the full tile pattern is shown in the export. -/// NOTE: there appears to have been a change in Qt that it now clips svg items -void QGIFace::hideSvg(bool state) -{ - m_hideSvgTiles = state; -} - - /// create a QPixmap from a bitmap file. The QPixmap will be used as a QBrush /// texture. QPixmap QGIFace::textureFromBitmap(std::string fileSpec) const @@ -492,13 +470,13 @@ QPixmap QGIFace::textureFromBitmap(std::string fileSpec) const return pix; } -void QGIFace::setLineWeight(double weight) { - m_geomWeight = weight; +void QGIFace::setLineWeight(double weight) +{ + m_patMaker->setLineWidth(Rez::guiX(weight)); } void QGIFace::getParameters() { - m_maxSeg = Preferences::getPreferenceGroup("PAT")->GetInt("MaxSeg", MAXSEGMENT); m_maxTile = Preferences::getPreferenceGroup("Decorations")->GetInt("MaxSVGTile", MAXTILES); } diff --git a/src/Mod/TechDraw/Gui/QGIFace.h b/src/Mod/TechDraw/Gui/QGIFace.h index e06adc270c..d1b025c230 100644 --- a/src/Mod/TechDraw/Gui/QGIFace.h +++ b/src/Mod/TechDraw/Gui/QGIFace.h @@ -48,7 +48,6 @@ class QGCustomImage; constexpr uint32_t COLWHITE{0xfffff}; // white constexpr int ALPHALOW{0}; constexpr int ALPHAHIGH{255}; - constexpr long int MAXSEGMENT{10000L}; constexpr long int MAXTILES{10000L}; const std::string SVGCOLDEFAULT = "#000000"; // black @@ -94,25 +93,22 @@ public: //general hatch parms & methods void setHatchColor(Base::Color color); + void setHatchColor(QColor color); void setHatchScale(double scale); //svg fill parms & methods void setHatchFile(std::string fileSpec); void loadSvgHatch(std::string fileSpec); void buildSvgHatch(); - void hideSvg(bool state); - void clearSvg(); //tiled pixmap fill from svg void buildPixHatch(); //PAT fill parms & methods - void setGeomHatchWeight(double weight) { m_geomWeight = weight; } void setLineWeight(double weight); - void clearLineSets(); + [[deprecated]] void clearLineSets(); void addLineSet(TechDraw::LineSet& ls); - void clearFillItems(); void lineSetToFillItems(TechDraw::LineSet& ls); QGraphicsPathItem* geomToLine(TechDraw::BaseGeomPtr base, TechDraw::LineSet& ls); @@ -153,14 +149,9 @@ protected: private: - std::vector m_fillItems; std::vector m_lineSets; - std::vector m_dashSpecs; - long int m_segCount{0}; - long int m_maxSeg{0}; long int m_maxTile{0}; - bool m_hideSvgTiles{false}; int projIndex; //index of face in Projection. -1 for SectionFace. QGCustomRect* m_svgHatchArea; @@ -175,15 +166,6 @@ private: QGIFace::FillMode m_mode; QPixmap m_texture; // - QPainterPath m_outline; // - - QPainterPath m_geomhatch; //crosshatch fill lines - - QColor m_geomColor; //color for crosshatch lines - double m_geomWeight{0.5}; //lineweight for crosshatch lines - - QColor m_defFaceColor; - double m_hatchRotation{0.0}; Base::Vector3d m_hatchOffset;