From fe617e14330a0c5e507f503905cafe1fbdba8bbb Mon Sep 17 00:00:00 2001 From: WandererFan Date: Wed, 7 Dec 2016 20:13:09 -0500 Subject: [PATCH] Make SVG hatches scalable --- src/Mod/TechDraw/App/DrawHatch.cpp | 5 ++++- src/Mod/TechDraw/App/DrawHatch.h | 1 + src/Mod/TechDraw/Gui/QGIFace.cpp | 19 ++++++++++++++----- src/Mod/TechDraw/Gui/QGIFace.h | 2 ++ src/Mod/TechDraw/Gui/QGIViewPart.cpp | 1 + 5 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/Mod/TechDraw/App/DrawHatch.cpp b/src/Mod/TechDraw/App/DrawHatch.cpp index 44587f420..5e3942d1f 100644 --- a/src/Mod/TechDraw/App/DrawHatch.cpp +++ b/src/Mod/TechDraw/App/DrawHatch.cpp @@ -61,6 +61,8 @@ DrawHatch::DrawHatch(void) ADD_PROPERTY_TYPE(Source,(0),vgroup,(App::PropertyType)(App::Prop_None),"The View + Face to be hatched"); ADD_PROPERTY_TYPE(HatchPattern ,(""),vgroup,App::Prop_None,"The hatch pattern file for this area"); ADD_PROPERTY_TYPE(HatchColor,(fcColor),vgroup,App::Prop_None,"The color of the hatch pattern"); + ADD_PROPERTY_TYPE(HatchScale,(1.0),vgroup,App::Prop_None,"Hatch pattern size adjustment"); + DirProjection.setStatus(App::Property::ReadOnly,true); hGrp = App::GetApplication().GetUserParameter() .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Files"); @@ -84,7 +86,8 @@ DrawHatch::~DrawHatch() void DrawHatch::onChanged(const App::Property* prop) { if (prop == &Source || - prop == &HatchPattern || + prop == &HatchPattern || //sb VP property? + prop == &HatchScale || prop == &HatchColor) { if (!isRestoring()) { DrawHatch::execute(); diff --git a/src/Mod/TechDraw/App/DrawHatch.h b/src/Mod/TechDraw/App/DrawHatch.h index 5219bb1e5..496cc15a4 100644 --- a/src/Mod/TechDraw/App/DrawHatch.h +++ b/src/Mod/TechDraw/App/DrawHatch.h @@ -44,6 +44,7 @@ public: App::PropertyLinkSub Source; //the dvp & face this hatch belongs to App::PropertyFile HatchPattern; App::PropertyColor HatchColor; + App::PropertyFloat HatchScale; //short mustExecute() const; diff --git a/src/Mod/TechDraw/Gui/QGIFace.cpp b/src/Mod/TechDraw/Gui/QGIFace.cpp index 551b7e706..65801adcf 100644 --- a/src/Mod/TechDraw/Gui/QGIFace.cpp +++ b/src/Mod/TechDraw/Gui/QGIFace.cpp @@ -73,6 +73,7 @@ QGIFace::QGIFace(int index) : m_rect->setParentItem(this); m_svgCol = SVGCOLDEFAULT; + m_svgScale = 1.0; } QGIFace::~QGIFace() @@ -149,14 +150,16 @@ void QGIFace::setPath(const QPainterPath & path) void QGIFace::buildHatch() { m_styleNormal = Qt::NoBrush; + double wTile = SVGSIZEW * m_svgScale; + double hTile = SVGSIZEH * m_svgScale; double w = boundingRect().width(); double h = boundingRect().height(); QRectF r = boundingRect(); QPointF fCenter = r.center(); - double nw = ceil(w / SVGSIZEW); - double nh = ceil(h / SVGSIZEH); - w = nw * SVGSIZEW; - h = nh * SVGSIZEW; + double nw = ceil(w / wTile); + double nh = ceil(h / hTile); + w = nw * wTile; + h = nh * hTile; m_rect->setRect(0.,0.,w,-h); m_rect->centerAt(fCenter); r = m_rect->rect(); @@ -167,9 +170,10 @@ void QGIFace::buildHatch() for (int iw = 0; iw < int(nw); iw++) { for (int ih = 0; ih < int(nh); ih++) { QGCustomSvg* tile = new QGCustomSvg(); + tile->setScale(m_svgScale); if (tile->load(&colorXML)) { tile->setParentItem(m_rect); - tile->setPos(iw*SVGSIZEW,-h + ih*SVGSIZEH); + tile->setPos(iw*wTile,-h + ih*hTile); } } } @@ -183,6 +187,11 @@ void QGIFace::setHatchColor(std::string c) m_svgCol = c; } +void QGIFace::setHatchScale(double s) +{ + m_svgScale = s; +} + //QtSvg does not handle clipping, so we must be able to turn the hatching on/off void QGIFace::toggleSvg(bool b) { diff --git a/src/Mod/TechDraw/Gui/QGIFace.h b/src/Mod/TechDraw/Gui/QGIFace.h index 99f21c652..9ee259337 100644 --- a/src/Mod/TechDraw/Gui/QGIFace.h +++ b/src/Mod/TechDraw/Gui/QGIFace.h @@ -65,6 +65,7 @@ public: void setPath(const QPainterPath & path); void buildHatch(void); void setHatchColor(std::string c); + void setHatchScale(double s); void setDrawEdges(bool b); void toggleSvg(bool b); @@ -77,6 +78,7 @@ protected: QGCustomSvg *m_svg; QByteArray m_svgXML; std::string m_svgCol; + double m_svgScale; private: QBrush m_brush; diff --git a/src/Mod/TechDraw/Gui/QGIViewPart.cpp b/src/Mod/TechDraw/Gui/QGIViewPart.cpp index 406a08f0b..22af898bc 100644 --- a/src/Mod/TechDraw/Gui/QGIViewPart.cpp +++ b/src/Mod/TechDraw/Gui/QGIViewPart.cpp @@ -379,6 +379,7 @@ void QGIViewPart::drawViewPart() if (!fHatch->HatchPattern.isEmpty()) { App::Color hColor = fHatch->HatchColor.getValue(); newFace->setHatchColor(hColor.asCSSString()); + newFace->setHatchScale(fHatch->HatchScale.getValue()); newFace->setHatch(fHatch->HatchPattern.getValue()); } }