Skip to content

Commit

Permalink
Fix scaling for ViewSymbol
Browse files Browse the repository at this point in the history
  • Loading branch information
WandererFan authored and yorikvanhavre committed Aug 1, 2016
1 parent 4de1b39 commit 78924d3
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
13 changes: 13 additions & 0 deletions src/Mod/TechDraw/Gui/QGCustomSvg.cpp
Expand Up @@ -26,6 +26,8 @@
#include <QStyleOptionGraphicsItem>
#endif

#include <Base/Console.h>

#include <QRectF>
#include "QGCustomSvg.h"

Expand All @@ -37,6 +39,7 @@ QGCustomSvg::QGCustomSvg()
setAcceptHoverEvents(false);
setFlag(QGraphicsItem::ItemIsSelectable, false);
setFlag(QGraphicsItem::ItemIsMovable, false);
setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);

m_svgRender = new QSvgRenderer();
}
Expand Down Expand Up @@ -69,10 +72,20 @@ void QGCustomSvg::centerAt(double cX, double cY)
bool QGCustomSvg::load(QByteArray *svgBytes)
{
bool success = m_svgRender->load(*svgBytes);
prepareGeometryChange();
setSharedRenderer(m_svgRender);
return(success);
}

QRectF QGCustomSvg::boundingRect() const
{
QRectF box = m_svgRender->viewBoxF();
double w = box.width();
double h = box.height();
QRectF newRect(0,0,w*scale(),h*scale());
return newRect.adjusted(-1.,-1.,1.,1.);
}

void QGCustomSvg::paint ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget) {
QStyleOptionGraphicsItem myOption(*option);
myOption.state &= ~QStyle::State_Selected;
Expand Down
1 change: 1 addition & 0 deletions src/Mod/TechDraw/Gui/QGCustomSvg.h
Expand Up @@ -50,6 +50,7 @@ class TechDrawGuiExport QGCustomSvg : public QGraphicsSvgItem
virtual void centerAt(QPointF centerPos);
virtual void centerAt(double cX, double cY);
virtual bool load(QByteArray *svgString);
virtual QRectF boundingRect(void) const override;

protected:
QSvgRenderer *m_svgRender;
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/TechDraw/Gui/QGIView.cpp
Expand Up @@ -290,7 +290,6 @@ void QGIView::draw()

void QGIView::drawBorder()
{
prepareGeometryChange();
if (!borderVisible) {
m_label.hide();
m_border.hide();
Expand Down Expand Up @@ -332,6 +331,7 @@ void QGIView::drawBorder()
displayArea.top(),
frameWidth,
frameHeight);
prepareGeometryChange();
m_border.setRect(frameArea);
m_border.setPos(0.,0.);

Expand Down
15 changes: 8 additions & 7 deletions src/Mod/TechDraw/Gui/QGIViewSymbol.cpp
Expand Up @@ -31,9 +31,10 @@
#include <QMouseEvent>
#include <QString>
#include <sstream>
#include <QRectF>
#endif

#include <qmath.h>
//#include <qmath.h>

#include <App/Application.h>
#include <App/Material.h>
Expand All @@ -54,6 +55,7 @@ QGIViewSymbol::QGIViewSymbol()
setAcceptHoverEvents(true);
setFlag(QGraphicsItem::ItemIsMovable, true);
setFlag(QGraphicsItem::ItemIsSelectable, true);
setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);

m_svgItem = new QGCustomSvg();
addToGroup(m_svgItem);
Expand Down Expand Up @@ -103,10 +105,6 @@ void QGIViewSymbol::draw()
return;
}

//note: svg's are overscaled by (72 pixels(pts actually) /in)*(1 in/25.4 mm) = 2.834645669 (could be 96/25.4(CSS)? 110/25.4?)
//due to 1 sceneUnit (1mm) = 1 pixel for some QtSvg functions
TechDraw::DrawViewSymbol *viewSymbol = dynamic_cast<TechDraw::DrawViewSymbol *>(getViewObject());
setScale(viewSymbol->Scale.getValue());
drawSvg();
if (borderVisible) {
drawBorder();
Expand All @@ -119,9 +117,12 @@ void QGIViewSymbol::drawSvg()
return;

TechDraw::DrawViewSymbol *viewSymbol = dynamic_cast<TechDraw::DrawViewSymbol *>(getViewObject());
//note: svg's are overscaled by (72 pixels(pts actually) /in)*(1 in/25.4 mm) = 2.834645669 (could be 96/25.4(CSS)? 110/25.4?)
//due to 1 sceneUnit (1mm) = 1 pixel for some QtSvg functions

QString qs(QString::fromUtf8(viewSymbol->Symbol.getValue()));
m_svgItem->setScale(viewSymbol->Scale.getValue());

QString qs(QString::fromUtf8(viewSymbol->Symbol.getValue()));
symbolToSvg(qs);
}

Expand All @@ -133,9 +134,9 @@ void QGIViewSymbol::symbolToSvg(QString qs)

QByteArray qba;
qba.append(qs);
prepareGeometryChange();
if (!m_svgItem->load(&qba)) {
Base::Console().Error("Error - Could not load Symbol into SVG renderer for %s\n", getViewObject()->getNameInDocument());
}
m_svgItem->setPos(0.,0.);
}

0 comments on commit 78924d3

Please sign in to comment.