Refactor method to base View

Auto allocate member attributes
This commit is contained in:
WandererFan
2016-07-22 15:20:37 -04:00
committed by wmayer
parent aa8fea7ba4
commit cb51799f60
4 changed files with 62 additions and 71 deletions

View File

@@ -48,9 +48,6 @@
#include <Gui/Selection.h>
#include <Gui/Command.h>
#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<QGraphicsItem*> qgItems = scene()->items();
QList<QGraphicsItem*>::iterator it = qgItems.begin();
for (; it != qgItems.end(); it++) {
QGIView* qv = dynamic_cast<QGIView*>((*it));
if (qv) {
const char* qvName = qv->getViewName();
if(name.compare(qvName) == 0) {
return (qv);
}
}
}
return 0;
}
QColor QGIView::getNormalColor()