Make SVG hatches scalable

This commit is contained in:
WandererFan 2016-12-07 20:13:09 -05:00
parent f68cbc83e3
commit fe617e1433
5 changed files with 22 additions and 6 deletions

View File

@ -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();

View File

@ -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;

View File

@ -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)
{

View File

@ -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;

View File

@ -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());
}
}