diff --git a/src/Mod/TechDraw/Gui/QGIView.cpp b/src/Mod/TechDraw/Gui/QGIView.cpp index be407c7e8..e31738865 100644 --- a/src/Mod/TechDraw/Gui/QGIView.cpp +++ b/src/Mod/TechDraw/Gui/QGIView.cpp @@ -48,9 +48,6 @@ #include #include -#include "QGCustomBorder.h" -#include "QGCustomLabel.h" - #include "QGIView.h" #include "QGCustomClip.h" #include "QGIViewClip.h" @@ -82,11 +79,8 @@ QGIView::QGIView() m_decorPen.setStyle(Qt::DashLine); m_decorPen.setWidth(0); // 0 => 1px "cosmetic pen" - m_label = new QGCustomLabel(); - addToGroup(m_label); - - m_border = new QGCustomBorder(); - addToGroup(m_border); + addToGroup(&m_label); + addToGroup(&m_border); isVisible(true); } @@ -298,27 +292,27 @@ void QGIView::drawBorder() { prepareGeometryChange(); if (!borderVisible) { - m_label->hide(); - m_border->hide(); + m_label.hide(); + m_border.hide(); return; } //double margin = 2.0; - m_label->hide(); - m_border->hide(); + m_label.hide(); + m_border.hide(); - m_label->setDefaultTextColor(m_colCurrent); + m_label.setDefaultTextColor(m_colCurrent); m_font.setFamily(getPrefFont()); - m_label->setFont(m_font); + m_label.setFont(m_font); QString labelStr = QString::fromUtf8(getViewObject()->Label.getValue()); - m_label->setPlainText(labelStr); - QRectF labelArea = m_label->boundingRect(); - double labelWidth = m_label->boundingRect().width(); - double labelHeight = m_label->boundingRect().height(); + m_label.setPlainText(labelStr); + QRectF labelArea = m_label.boundingRect(); + double labelWidth = m_label.boundingRect().width(); + double labelHeight = m_label.boundingRect().height(); - m_border->hide(); + m_border.hide(); m_decorPen.setColor(m_colCurrent); - m_border->setPen(m_decorPen); + m_border.setPen(m_decorPen); QRectF displayArea = customChildrenBoundingRect(); double displayWidth = displayArea.width(); @@ -331,18 +325,18 @@ void QGIView::drawBorder() double frameHeight = labelHeight + displayHeight; QPointF displayCenter = displayArea.center(); - m_label->setX(displayCenter.x() - labelArea.width()/2.); - m_label->setY(displayArea.bottom()); + m_label.setX(displayCenter.x() - labelArea.width()/2.); + m_label.setY(displayArea.bottom()); QRectF frameArea = QRectF(displayCenter.x() - frameWidth/2., displayArea.top(), frameWidth, frameHeight); - m_border->setRect(frameArea); - m_border->setPos(0.,0.); + m_border.setRect(frameArea); + m_border.setPos(0.,0.); - m_label->show(); - m_border->show(); + m_label.show(); + m_border.show(); } void QGIView::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) @@ -371,7 +365,23 @@ QRectF QGIView::customChildrenBoundingRect() { QRectF QGIView::boundingRect() const { - return m_border->rect().adjusted(-2.,-2.,2.,2.); //allow for border line width //TODO: fiddle brect if border off? + return m_border.rect().adjusted(-2.,-2.,2.,2.); //allow for border line width //TODO: fiddle brect if border off? +} + +QGIView* QGIView::getQGIVByName(std::string name) +{ + QList qgItems = scene()->items(); + QList::iterator it = qgItems.begin(); + for (; it != qgItems.end(); it++) { + QGIView* qv = dynamic_cast((*it)); + if (qv) { + const char* qvName = qv->getViewName(); + if(name.compare(qvName) == 0) { + return (qv); + } + } + } + return 0; } QColor QGIView::getNormalColor() diff --git a/src/Mod/TechDraw/Gui/QGIView.h b/src/Mod/TechDraw/Gui/QGIView.h index 182b8b756..a5a131323 100644 --- a/src/Mod/TechDraw/Gui/QGIView.h +++ b/src/Mod/TechDraw/Gui/QGIView.h @@ -31,6 +31,8 @@ #include #include +#include "QGCustomBorder.h" +#include "QGCustomLabel.h" QT_BEGIN_NAMESPACE class QGraphicsScene; @@ -39,8 +41,6 @@ QT_END_NAMESPACE namespace TechDrawGui { -class QGCustomBorder; -class QGCustomLabel; class TechDrawGuiExport QGIView : public QGraphicsItemGroup { @@ -79,6 +79,7 @@ public: virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent * event); protected: + QGIView* getQGIVByName(std::string name); virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value); // Mouse handling @@ -112,8 +113,8 @@ protected: QColor m_colPre; QColor m_colSel; QFont m_font; - QGCustomLabel* m_label; - QGCustomBorder* m_border; + QGCustomLabel m_label; + QGCustomBorder m_border; QPen m_decorPen; }; diff --git a/src/Mod/TechDraw/Gui/QGIViewClip.cpp b/src/Mod/TechDraw/Gui/QGIViewClip.cpp index 10d9b66d6..42ea8fb5d 100644 --- a/src/Mod/TechDraw/Gui/QGIViewClip.cpp +++ b/src/Mod/TechDraw/Gui/QGIViewClip.cpp @@ -47,8 +47,6 @@ #include -#include "QGCustomRect.h" -#include "QGCustomClip.h" #include "QGIViewClip.h" using namespace TechDrawGui; @@ -61,15 +59,13 @@ QGIViewClip::QGIViewClip() setFlag(QGraphicsItem::ItemIsSelectable, true); setFlag(QGraphicsItem::ItemIsMovable, true); - m_cliparea = new QGCustomClip(); - addToGroup(m_cliparea); - m_cliparea->setPos(0.,0.); - m_cliparea->setRect(0.,0.,5.,5.); + addToGroup(&m_cliparea); + m_cliparea.setPos(0.,0.); + m_cliparea.setRect(0.,0.,5.,5.); - m_frame = new QGCustomRect(); - addToGroup(m_frame); - m_frame->setPos(0.,0.); - m_frame->setRect(0.,0.,5.,5.); + addToGroup(&m_frame); + m_frame.setPos(0.,0.); + m_frame.setRect(0.,0.,5.,5.); } @@ -120,15 +116,15 @@ void QGIViewClip::drawClip() double h = viewClip->Height.getValue(); double w = viewClip->Width.getValue(); QRectF r = QRectF(0,0,w,h); - m_frame->setRect(r); - m_frame->setPos(0.,0.); + m_frame.setRect(r); + m_frame.setPos(0.,0.); if (viewClip->ShowFrame.getValue()) { - m_frame->show(); + m_frame.show(); } else { - m_frame->hide(); + m_frame.hide(); } - m_cliparea->setRect(r.adjusted(-1,-1,1,1)); //TODO: clip just outside frame or just inside?? + m_cliparea.setRect(r.adjusted(-1,-1,1,1)); //TODO: clip just outside frame or just inside?? std::vector childNames = viewClip->getChildViewNames(); //for all child Views in Clip, add the graphics representation of the View to the Clip group @@ -136,10 +132,10 @@ void QGIViewClip::drawClip() QGIView* qgiv = getQGIVByName((*it)); if (qgiv) { //TODO: why is qgiv never already in a group? - if (qgiv->group() != m_cliparea) { + if (qgiv->group() != &m_cliparea) { qgiv->hide(); scene()->removeItem(qgiv); - m_cliparea->addToGroup(qgiv); + m_cliparea.addToGroup(qgiv); qgiv->isInnerView(true); double x = qgiv->getViewObject()->X.getValue(); double y = qgiv->getViewObject()->Y.getValue(); @@ -157,14 +153,14 @@ void QGIViewClip::drawClip() } //for all graphic views in qgigroup, remove from qgigroup the ones that aren't in ViewClip - QList qgItems = m_cliparea->childItems(); + QList qgItems = m_cliparea.childItems(); QList::iterator it = qgItems.begin(); for (; it != qgItems.end(); it++) { QGIView* qv = dynamic_cast((*it)); if (qv) { std::string qvName = std::string(qv->getViewName()); if (std::find(childNames.begin(),childNames.end(),qvName) == childNames.end()) { - m_cliparea->removeFromGroup(qv); + m_cliparea.removeFromGroup(qv); removeFromGroup(qv); qv->isInnerView(false); qv->toggleBorder(true); @@ -173,19 +169,4 @@ void QGIViewClip::drawClip() } } -//TODO: at least move to QGIView -QGIView* QGIViewClip::getQGIVByName(std::string name) //should probably be method in MDIViewPage?? but qgiv can't get drawingView? or QGVPage! -{ - QList qgItems = scene()->items(); - QList::iterator it = qgItems.begin(); - for (; it != qgItems.end(); it++) { - QGIView* qv = dynamic_cast((*it)); - if (qv) { - const char* qvName = qv->getViewName(); - if(name.compare(qvName) == 0) { - return (qv); - } - } - } - return 0; -} + diff --git a/src/Mod/TechDraw/Gui/QGIViewClip.h b/src/Mod/TechDraw/Gui/QGIViewClip.h index 71e52e4ca..91b8f6f1c 100644 --- a/src/Mod/TechDraw/Gui/QGIViewClip.h +++ b/src/Mod/TechDraw/Gui/QGIViewClip.h @@ -27,11 +27,11 @@ #include #include "QGIView.h" +#include "QGCustomRect.h" +#include "QGCustomClip.h" namespace TechDrawGui { -class QGCustomRect; -class QGCustomClip; class TechDrawGuiExport QGIViewClip : public QGIView { @@ -50,11 +50,10 @@ public: protected: void drawClip(); virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value) override; - QGIView* getQGIVByName(std::string name); private: - QGCustomRect* m_frame; - QGCustomClip* m_cliparea; + QGCustomRect m_frame; + QGCustomClip m_cliparea; };