diff --git a/src/Mod/TechDraw/Gui/CMakeLists.txt b/src/Mod/TechDraw/Gui/CMakeLists.txt index a43f3baf3d..2acd0a770e 100644 --- a/src/Mod/TechDraw/Gui/CMakeLists.txt +++ b/src/Mod/TechDraw/Gui/CMakeLists.txt @@ -123,6 +123,8 @@ SET(TechDrawGuiView_SRCS QGCustomBorder.h QGCustomImage.cpp QGCustomImage.h + QGDisplayArea.cpp + QGDisplayArea.h QGIView.cpp QGIView.h QGIArrow.cpp diff --git a/src/Mod/TechDraw/Gui/QGDisplayArea.cpp b/src/Mod/TechDraw/Gui/QGDisplayArea.cpp new file mode 100644 index 0000000000..45a9336748 --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGDisplayArea.cpp @@ -0,0 +1,81 @@ +/*************************************************************************** + * Copyright (c) 2017 WandererFan * + * * + * 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 +#include +#include +#include +#include +#include +#endif + +#include +#include +#include +#include + +#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(); +} + diff --git a/src/Mod/TechDraw/Gui/QGDisplayArea.h b/src/Mod/TechDraw/Gui/QGDisplayArea.h new file mode 100644 index 0000000000..4797f4e160 --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGDisplayArea.h @@ -0,0 +1,61 @@ +/*************************************************************************** + * Copyright (c) 2017 WandererFan * + * * + * 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 +#include +#include + +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 + diff --git a/src/Mod/TechDraw/Gui/QGIUserTypes.h b/src/Mod/TechDraw/Gui/QGIUserTypes.h index 8571677c04..d8a9798bd4 100644 --- a/src/Mod/TechDraw/Gui/QGIUserTypes.h +++ b/src/Mod/TechDraw/Gui/QGIUserTypes.h @@ -25,6 +25,7 @@ QGCustomClip: 132 QGCustomRect: 133 QGCustomLabel:135 QGCustomBorder: 136 +QGDisplayArea: 137 QGraphicsItemTemplate: 150 QGraphicsItemDrawingTemplate: 151 QGraphicsItemSVGTemplate: 153 diff --git a/src/Mod/TechDraw/Gui/QGIViewSymbol.cpp b/src/Mod/TechDraw/Gui/QGIViewSymbol.cpp index 71ab65a1d5..48123e23f8 100644 --- a/src/Mod/TechDraw/Gui/QGIViewSymbol.cpp +++ b/src/Mod/TechDraw/Gui/QGIViewSymbol.cpp @@ -44,7 +44,9 @@ #include #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); +} + diff --git a/src/Mod/TechDraw/Gui/QGIViewSymbol.h b/src/Mod/TechDraw/Gui/QGIViewSymbol.h index 032c00b5ca..055085a7e1 100644 --- a/src/Mod/TechDraw/Gui/QGIViewSymbol.h +++ b/src/Mod/TechDraw/Gui/QGIViewSymbol.h @@ -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; };