Make SVG hatches scalable
This commit is contained in:
parent
f68cbc83e3
commit
fe617e1433
|
@ -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(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(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(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()
|
hGrp = App::GetApplication().GetUserParameter()
|
||||||
.GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Files");
|
.GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Files");
|
||||||
|
@ -84,7 +86,8 @@ DrawHatch::~DrawHatch()
|
||||||
void DrawHatch::onChanged(const App::Property* prop)
|
void DrawHatch::onChanged(const App::Property* prop)
|
||||||
{
|
{
|
||||||
if (prop == &Source ||
|
if (prop == &Source ||
|
||||||
prop == &HatchPattern ||
|
prop == &HatchPattern || //sb VP property?
|
||||||
|
prop == &HatchScale ||
|
||||||
prop == &HatchColor) {
|
prop == &HatchColor) {
|
||||||
if (!isRestoring()) {
|
if (!isRestoring()) {
|
||||||
DrawHatch::execute();
|
DrawHatch::execute();
|
||||||
|
|
|
@ -44,6 +44,7 @@ public:
|
||||||
App::PropertyLinkSub Source; //the dvp & face this hatch belongs to
|
App::PropertyLinkSub Source; //the dvp & face this hatch belongs to
|
||||||
App::PropertyFile HatchPattern;
|
App::PropertyFile HatchPattern;
|
||||||
App::PropertyColor HatchColor;
|
App::PropertyColor HatchColor;
|
||||||
|
App::PropertyFloat HatchScale;
|
||||||
|
|
||||||
//short mustExecute() const;
|
//short mustExecute() const;
|
||||||
|
|
||||||
|
|
|
@ -73,6 +73,7 @@ QGIFace::QGIFace(int index) :
|
||||||
m_rect->setParentItem(this);
|
m_rect->setParentItem(this);
|
||||||
|
|
||||||
m_svgCol = SVGCOLDEFAULT;
|
m_svgCol = SVGCOLDEFAULT;
|
||||||
|
m_svgScale = 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
QGIFace::~QGIFace()
|
QGIFace::~QGIFace()
|
||||||
|
@ -149,14 +150,16 @@ void QGIFace::setPath(const QPainterPath & path)
|
||||||
void QGIFace::buildHatch()
|
void QGIFace::buildHatch()
|
||||||
{
|
{
|
||||||
m_styleNormal = Qt::NoBrush;
|
m_styleNormal = Qt::NoBrush;
|
||||||
|
double wTile = SVGSIZEW * m_svgScale;
|
||||||
|
double hTile = SVGSIZEH * m_svgScale;
|
||||||
double w = boundingRect().width();
|
double w = boundingRect().width();
|
||||||
double h = boundingRect().height();
|
double h = boundingRect().height();
|
||||||
QRectF r = boundingRect();
|
QRectF r = boundingRect();
|
||||||
QPointF fCenter = r.center();
|
QPointF fCenter = r.center();
|
||||||
double nw = ceil(w / SVGSIZEW);
|
double nw = ceil(w / wTile);
|
||||||
double nh = ceil(h / SVGSIZEH);
|
double nh = ceil(h / hTile);
|
||||||
w = nw * SVGSIZEW;
|
w = nw * wTile;
|
||||||
h = nh * SVGSIZEW;
|
h = nh * hTile;
|
||||||
m_rect->setRect(0.,0.,w,-h);
|
m_rect->setRect(0.,0.,w,-h);
|
||||||
m_rect->centerAt(fCenter);
|
m_rect->centerAt(fCenter);
|
||||||
r = m_rect->rect();
|
r = m_rect->rect();
|
||||||
|
@ -167,9 +170,10 @@ void QGIFace::buildHatch()
|
||||||
for (int iw = 0; iw < int(nw); iw++) {
|
for (int iw = 0; iw < int(nw); iw++) {
|
||||||
for (int ih = 0; ih < int(nh); ih++) {
|
for (int ih = 0; ih < int(nh); ih++) {
|
||||||
QGCustomSvg* tile = new QGCustomSvg();
|
QGCustomSvg* tile = new QGCustomSvg();
|
||||||
|
tile->setScale(m_svgScale);
|
||||||
if (tile->load(&colorXML)) {
|
if (tile->load(&colorXML)) {
|
||||||
tile->setParentItem(m_rect);
|
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;
|
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
|
//QtSvg does not handle clipping, so we must be able to turn the hatching on/off
|
||||||
void QGIFace::toggleSvg(bool b)
|
void QGIFace::toggleSvg(bool b)
|
||||||
{
|
{
|
||||||
|
|
|
@ -65,6 +65,7 @@ public:
|
||||||
void setPath(const QPainterPath & path);
|
void setPath(const QPainterPath & path);
|
||||||
void buildHatch(void);
|
void buildHatch(void);
|
||||||
void setHatchColor(std::string c);
|
void setHatchColor(std::string c);
|
||||||
|
void setHatchScale(double s);
|
||||||
void setDrawEdges(bool b);
|
void setDrawEdges(bool b);
|
||||||
void toggleSvg(bool b);
|
void toggleSvg(bool b);
|
||||||
|
|
||||||
|
@ -77,6 +78,7 @@ protected:
|
||||||
QGCustomSvg *m_svg;
|
QGCustomSvg *m_svg;
|
||||||
QByteArray m_svgXML;
|
QByteArray m_svgXML;
|
||||||
std::string m_svgCol;
|
std::string m_svgCol;
|
||||||
|
double m_svgScale;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QBrush m_brush;
|
QBrush m_brush;
|
||||||
|
|
|
@ -379,6 +379,7 @@ void QGIViewPart::drawViewPart()
|
||||||
if (!fHatch->HatchPattern.isEmpty()) {
|
if (!fHatch->HatchPattern.isEmpty()) {
|
||||||
App::Color hColor = fHatch->HatchColor.getValue();
|
App::Color hColor = fHatch->HatchColor.getValue();
|
||||||
newFace->setHatchColor(hColor.asCSSString());
|
newFace->setHatchColor(hColor.asCSSString());
|
||||||
|
newFace->setHatchScale(fHatch->HatchScale.getValue());
|
||||||
newFace->setHatch(fHatch->HatchPattern.getValue());
|
newFace->setHatch(fHatch->HatchPattern.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user