Fix QGIVSymbol positioning/rotation

This commit is contained in:
WandererFan
2017-10-19 20:39:26 -04:00
parent 88b15ffdf1
commit 196dd536e0
6 changed files with 166 additions and 1 deletions

View File

@@ -123,6 +123,8 @@ SET(TechDrawGuiView_SRCS
QGCustomBorder.h
QGCustomImage.cpp
QGCustomImage.h
QGDisplayArea.cpp
QGDisplayArea.h
QGIView.cpp
QGIView.h
QGIArrow.cpp

View File

@@ -0,0 +1,81 @@
/***************************************************************************
* Copyright (c) 2017 WandererFan <wandererfan@gmail.com> *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/
#include "PreCompiled.h"
#ifndef _PreComp_
#include <assert.h>
#include <QGraphicsScene>
#include <QGraphicsSceneHoverEvent>
#include <QMouseEvent>
#include <QPainter>
#include <QStyleOptionGraphicsItem>
#endif
#include <App/Application.h>
#include <App/Material.h>
#include <Base/Console.h>
#include <Base/Parameter.h>
#include "QGDisplayArea.h"
using namespace TechDrawGui;
QGDisplayArea::QGDisplayArea(void)
{
setHandlesChildEvents(false);
setCacheMode(QGraphicsItem::NoCache);
setAcceptHoverEvents(false);
setFlag(QGraphicsItem::ItemIsSelectable, false);
setFlag(QGraphicsItem::ItemIsMovable, false);
setFlag(QGraphicsItem::ItemClipsChildrenToShape, false);
setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
}
void QGDisplayArea::centerAt(QPointF centerPos)
{
centerAt(centerPos.x(),centerPos.y());
}
void QGDisplayArea::centerAt(double cX, double cY)
{
QRectF box = boundingRect();
double width = box.width();
double height = box.height();
double newX = cX - width/2.;
double newY = cY - height/2.;
setPos(newX,newY);
}
void QGDisplayArea::paint ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget) {
QStyleOptionGraphicsItem myOption(*option);
myOption.state &= ~QStyle::State_Selected;
//painter->drawRect(boundingRect()); //good for debugging
QGraphicsItemGroup::paint (painter, &myOption, widget);
}
QRectF QGDisplayArea::boundingRect() const
{
return childrenBoundingRect();
}

View File

@@ -0,0 +1,61 @@
/***************************************************************************
* Copyright (c) 2017 WandererFan <wandererfan@gmail.com> *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/
#ifndef DRAWINGGUI_QGDISPLAYAREA_H
#define DRAWINGGUI_QGDISPLAYAREA_H
#include <QGraphicsItem>
#include <QPointF>
#include <QRectF>
QT_BEGIN_NAMESPACE
class QPainter;
class QStyleOptionGraphicsItem;
QT_END_NAMESPACE
namespace TechDrawGui
{
class TechDrawGuiExport QGDisplayArea : public QGraphicsItemGroup
{
public:
explicit QGDisplayArea(void);
~QGDisplayArea() {}
enum {Type = QGraphicsItem::UserType + 137};
int type() const { return Type;}
virtual QRectF boundingRect() const;
void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0 );
virtual void centerAt(QPointF centerPos);
virtual void centerAt(double cX, double cY);
protected:
private:
};
}
#endif // DRAWINGGUI_QGDISPLAYAREA_H

View File

@@ -25,6 +25,7 @@ QGCustomClip: 132
QGCustomRect: 133
QGCustomLabel:135
QGCustomBorder: 136
QGDisplayArea: 137
QGraphicsItemTemplate: 150
QGraphicsItemDrawingTemplate: 151
QGraphicsItemSVGTemplate: 153

View File

@@ -44,7 +44,9 @@
#include <Mod/TechDraw/App/DrawViewSymbol.h>
#include "QGCustomSvg.h"
#include "QGDisplayArea.h"
#include "QGIViewSymbol.h"
#include "DrawGuiUtil.h"
#include "Rez.h"
using namespace TechDrawGui;
@@ -58,8 +60,12 @@ QGIViewSymbol::QGIViewSymbol()
setFlag(QGraphicsItem::ItemIsSelectable, true);
setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
m_displayArea = new QGDisplayArea();
addToGroup(m_displayArea);
m_displayArea->centerAt(0.,0.);
m_svgItem = new QGCustomSvg();
addToGroup(m_svgItem);
m_displayArea->addToGroup(m_svgItem);
m_svgItem->centerAt(0.,0.);
}
@@ -126,6 +132,7 @@ void QGIViewSymbol::drawSvg()
QByteArray qba(viewSymbol->Symbol.getValue(),strlen(viewSymbol->Symbol.getValue()));
symbolToSvg(qba);
rotateView();
}
void QGIViewSymbol::symbolToSvg(QByteArray qba)
@@ -140,3 +147,12 @@ void QGIViewSymbol::symbolToSvg(QByteArray qba)
}
m_svgItem->centerAt(0.,0.);
}
void QGIViewSymbol::rotateView(void)
{
QRectF r = m_displayArea->boundingRect();
m_displayArea->setTransformOriginPoint(r.center());
double rot = getViewObject()->Rotation.getValue();
m_displayArea->setRotation(-rot);
}

View File

@@ -40,6 +40,7 @@ class DrawViewSymbol;
namespace TechDrawGui
{
class QGCustomSvg;
class QGDisplayArea;
class TechDrawGuiExport QGIViewSymbol : public QGIView
{
@@ -54,12 +55,15 @@ public:
void setViewSymbolFeature(TechDraw::DrawViewSymbol *obj);
virtual void draw() override;
virtual void rotateView(void) override;
protected:
virtual void drawSvg();
void symbolToSvg(QByteArray qba);
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
QGDisplayArea* m_displayArea;
QGCustomSvg *m_svgItem;
};