Skip to content

Commit

Permalink
QGIArrow inherits QGIPrimPath
Browse files Browse the repository at this point in the history
  • Loading branch information
WandererFan authored and wwmayer committed Aug 16, 2016
1 parent 4fe4c31 commit 5c62493
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 60 deletions.
85 changes: 49 additions & 36 deletions src/Mod/TechDraw/Gui/QGIArrow.cpp
Expand Up @@ -37,45 +37,43 @@

using namespace TechDrawGui;

QGIArrow::QGIArrow(QGraphicsScene *scene)
QGIArrow::QGIArrow() :
m_fill(Qt::SolidPattern),
m_size(5.0)
{
isFlipped = false;
m_brush.setStyle(m_fill);

if(scene) {
scene->addItem(this);
}

// Set Cache Mode
setCacheMode(QGraphicsItem::NoCache);
setAcceptHoverEvents(false);
setFlag(QGraphicsItem::ItemIsSelectable, false);
setFlag(QGraphicsItem::ItemIsMovable, false);
}

QPainterPath QGIArrow::shape() const
{
return path();
}

void QGIArrow::setHighlighted(bool state)
{
QPen myPen = pen();
QBrush myBrush = brush();
if(state) {
myPen.setColor(Qt::blue);
myBrush.setColor(Qt::blue);
} else {
myPen.setColor(Qt::black);
myBrush.setColor(Qt::black);
}
setBrush(myBrush);
setPen(myPen);
}

QVariant QGIArrow::itemChange(GraphicsItemChange change, const QVariant &value)
{
return QGraphicsPathItem::itemChange(change, value);
}
//QPainterPath QGIArrow::shape() const
//{
// return path();
//}

//void QGIArrow::setHighlighted(bool state)
//{
// QPen myPen = pen();
// QBrush myBrush = brush();
// if(state) {
// myPen.setColor(Qt::blue);
// myBrush.setColor(Qt::blue);
// } else {
// myPen.setColor(Qt::black);
// myBrush.setColor(Qt::black);
// }
// setBrush(myBrush);
// setPen(myPen);
//}

//QVariant QGIArrow::itemChange(GraphicsItemChange change, const QVariant &value)
//{
// return QGraphicsPathItem::itemChange(change, value);
//}

void QGIArrow::flip(bool state) {
isFlipped = state;
Expand All @@ -84,14 +82,14 @@ void QGIArrow::flip(bool state) {
void QGIArrow::draw() {
// the center is the end point on a dimension
QPainterPath path;
QPen pen(Qt::black);
pen.setWidth(1);
//QPen pen(Qt::black);
//pen.setWidth(1);

QBrush brush(Qt::black);
//QBrush brush(Qt::black);
//setPen(pen);
setBrush(brush);
//setBrush(brush);

float length = -5.; //TODO: Arrow heads sb preference? size & type?
float length = -m_size; //TODO: Arrow heads sb preference? size & type?

if(isFlipped)
length *= -1;
Expand All @@ -103,12 +101,27 @@ void QGIArrow::draw() {
// path.moveTo(QPointF(-1,1));
// path.lineTo(QPointF(1,-1));
setPath(path);
}

void QGIArrow::setSize(double s)
{
m_size = s;
//???
}

void QGIArrow::setStyle(int s)
{
m_style = s;
//???
}

void QGIArrow::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
QStyleOptionGraphicsItem myOption(*option);
myOption.state &= ~QStyle::State_Selected;
QGraphicsPathItem::paint(painter, &myOption, widget);

m_brush.setColor(m_colCurrent);
m_brush.setStyle(m_fill);
setBrush(m_brush);
QGIPrimPath::paint (painter, &myOption, widget);
}
25 changes: 14 additions & 11 deletions src/Mod/TechDraw/Gui/QGIArrow.h
Expand Up @@ -23,7 +23,7 @@
#ifndef DRAWINGGUI_QGRAPHICSITEMARROW_H
#define DRAWINGGUI_QGRAPHICSITEMARROW_H

# include <QGraphicsItem>
# include "QGIPrimPath.h"

QT_BEGIN_NAMESPACE
class QPainter;
Expand All @@ -33,31 +33,34 @@ QT_END_NAMESPACE
namespace TechDrawGui
{

class TechDrawGuiExport QGIArrow : public QGraphicsPathItem
class TechDrawGuiExport QGIArrow : public QGIPrimPath
{
public:
explicit QGIArrow(QGraphicsScene *scene = 0 );
explicit QGIArrow();
~QGIArrow() {}

enum {Type = QGraphicsItem::UserType + 109};
int type() const { return Type;}

public:
void draw();
void setHighlighted(bool state);
//void setHighlighted(bool state);
void flip(bool state);
QPainterPath shape() const;
double getSize() { return m_size; }
void setSize(double s);
int getStyle() { return m_style; }
void setStyle(int s);
//QPainterPath shape() const;
virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0 );

protected:
// Preselection events:
// void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
// void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
// Selection detection
QVariant itemChange(GraphicsItemChange change, const QVariant &value);
//QVariant itemChange(GraphicsItemChange change, const QVariant &value);

private:
QPen m_pen;
QBrush m_brush;
Qt::BrushStyle m_fill;
double m_size;
int m_style;
bool isFlipped;
};

Expand Down
10 changes: 9 additions & 1 deletion src/Mod/TechDraw/Gui/QGIPrimPath.cpp
Expand Up @@ -40,7 +40,8 @@

using namespace TechDrawGui;

QGIPrimPath::QGIPrimPath()
QGIPrimPath::QGIPrimPath():
m_width(0)
{
setCacheMode(QGraphicsItem::NoCache);
setFlag(QGraphicsItem::ItemIsSelectable, true);
Expand All @@ -56,6 +57,7 @@ QGIPrimPath::QGIPrimPath()
m_styleCurrent = Qt::SolidLine;
m_pen.setStyle(m_styleCurrent);
m_pen.setCapStyle(Qt::RoundCap);
m_pen.setWidthF(m_width);
}

QVariant QGIPrimPath::itemChange(GraphicsItemChange change, const QVariant &value)
Expand Down Expand Up @@ -148,6 +150,12 @@ QColor QGIPrimPath::getSelectColor()
return fcColor.asValue<QColor>();
}

void QGIPrimPath::setWidth(double w)
{
m_width = w;
m_pen.setWidthF(m_width);
}

Base::Reference<ParameterGrp> QGIPrimPath::getParmGroup()
{
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter()
Expand Down
4 changes: 4 additions & 0 deletions src/Mod/TechDraw/Gui/QGIPrimPath.h
Expand Up @@ -45,11 +45,14 @@ class TechDrawGuiExport QGIPrimPath : public QGraphicsPathItem

int type() const { return Type;}
virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0 );
virtual QPainterPath shape() const { return path(); };

void setHighlighted(bool state);
virtual void setPrettyNormal();
virtual void setPrettyPre();
virtual void setPrettySel();
virtual void setWidth(double w);
virtual double getWidth() { return m_width;}

protected:
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
Expand All @@ -65,6 +68,7 @@ class TechDrawGuiExport QGIPrimPath : public QGraphicsPathItem
QPen m_pen;
QColor m_colCurrent;
Qt::PenStyle m_styleCurrent;
double m_width;

private:

Expand Down
1 change: 0 additions & 1 deletion src/Mod/TechDraw/Gui/QGIVertex.cpp
Expand Up @@ -65,6 +65,5 @@ void QGIVertex::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
m_brush.setColor(m_colCurrent);
m_brush.setStyle(m_fill);
setBrush(m_brush);
//setRect(-m_radius,-m_radius,2.*m_radius,2.*m_radius);
QGIPrimPath::paint (painter, &myOption, widget);
}
34 changes: 23 additions & 11 deletions src/Mod/TechDraw/Gui/QGIViewDimension.cpp
Expand Up @@ -554,8 +554,8 @@ void QGIViewDimension::draw()
aHead1->setPos(dim1Tip.x, dim1Tip.y);
aHead2->setPos(dim2Tail.x, dim2Tail.y);

aHead1->setHighlighted(isSelected() || hasHover); //setPrettyxxx??
aHead2->setHighlighted(isSelected() || hasHover);
//aHead1->setHighlighted(isSelected() || hasHover); //setPrettyxxx??
//aHead2->setHighlighted(isSelected() || hasHover);

} else if(strcmp(dimType, "Diameter") == 0) {
// terminology: Dimension Text, Dimension Line(s), Extension Lines, Arrowheads
Expand Down Expand Up @@ -746,8 +746,8 @@ void QGIViewDimension::draw()

float arAngle = atan2(dirDimLine.y, dirDimLine.x) * 180 / M_PI;

aHead1->setHighlighted(isSelected() || hasHover);
aHead2->setHighlighted(isSelected() || hasHover);
//aHead1->setHighlighted(isSelected() || hasHover);
//aHead2->setHighlighted(isSelected() || hasHover);
aHead2->show();

if(outerPlacement) {
Expand Down Expand Up @@ -903,7 +903,7 @@ void QGIViewDimension::draw()

aHead1->setPos(ar1Pos.x, ar1Pos.y);
aHead1->setRotation(arAngle);
aHead1->setHighlighted(isSelected() || hasHover);
//aHead1->setHighlighted(isSelected() || hasHover);
aHead1->show();
aHead2->hide();
} else if(strcmp(dimType, "Angle") == 0) {
Expand Down Expand Up @@ -1111,8 +1111,8 @@ void QGIViewDimension::draw()
aHead2->setRotation(ar2angle);
}

aHead1->setHighlighted(isSelected() || hasHover);
aHead2->setHighlighted(isSelected() || hasHover);
//aHead1->setHighlighted(isSelected() || hasHover);
//aHead2->setHighlighted(isSelected() || hasHover);

// Set the angle of the datum text

Expand All @@ -1136,6 +1136,17 @@ void QGIViewDimension::draw()
} //endif Distance/Diameter/Radius/Angle

// redraw the Dimension and the parent View
if (hasHover) {
aHead1->setPrettyPre();
aHead2->setPrettyPre();
} else if (isSelected()) {
aHead1->setPrettySel();
aHead2->setPrettySel();
} else {
aHead1->setPrettyNormal();
aHead2->setPrettyNormal();
}

update();
if (parentItem()) {
//TODO: parent redraw still required with new frame/label??
Expand Down Expand Up @@ -1172,29 +1183,30 @@ void QGIViewDimension::paint ( QPainter * painter, const QStyleOptionGraphicsIte
QPaintDevice* hw = painter->device();
QSvgGenerator* svg = dynamic_cast<QSvgGenerator*>(hw);
double saveWidth = m_pen.widthF();
double arrowSaveWidth = aHead1->getWidth();
if (svg) {
setSvgPens();
} else {
setPens();
}
QGIView::paint (painter, &myOption, widget);
m_pen.setWidthF(saveWidth);
aHead1->setWidth(arrowSaveWidth);
aHead2->setWidth(arrowSaveWidth);
}

void QGIViewDimension::setSvgPens(void)
{
double svgLineFactor = 3.0; //magic number. should be a setting somewhere.
m_pen.setWidthF(m_pen.widthF()/svgLineFactor);
dimLines->setPen(m_pen);
aHead1->setPen(m_pen);
aHead2->setPen(m_pen);
aHead1->setWidth(aHead1->getWidth()/svgLineFactor);
aHead2->setWidth(aHead2->getWidth()/svgLineFactor);
}

void QGIViewDimension::setPens(void)
{
dimLines->setPen(m_pen);
aHead1->setPen(m_pen);
aHead2->setPen(m_pen);
}

#include <Mod/TechDraw/Gui/moc_QGIViewDimension.cpp>

0 comments on commit 5c62493

Please sign in to comment.