QGIArrow inherits QGIPrimPath
This commit is contained in:
parent
4fe4c31966
commit
5c62493b31
|
@ -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();
|
||||
}
|
||||
//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);
|
||||
}
|
||||
//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);
|
||||
}
|
||||
//QVariant QGIArrow::itemChange(GraphicsItemChange change, const QVariant &value)
|
||||
//{
|
||||
// return QGraphicsPathItem::itemChange(change, value);
|
||||
//}
|
||||
|
||||
void QGIArrow::flip(bool state) {
|
||||
isFlipped = state;
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
#ifndef DRAWINGGUI_QGRAPHICSITEMARROW_H
|
||||
#define DRAWINGGUI_QGRAPHICSITEMARROW_H
|
||||
|
||||
# include <QGraphicsItem>
|
||||
# include "QGIPrimPath.h"
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QPainter;
|
||||
|
@ -33,10 +33,10 @@ 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};
|
||||
|
@ -44,20 +44,23 @@ public:
|
|||
|
||||
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;
|
||||
};
|
||||
|
||||
|
|
|
@ -40,7 +40,8 @@
|
|||
|
||||
using namespace TechDrawGui;
|
||||
|
||||
QGIPrimPath::QGIPrimPath()
|
||||
QGIPrimPath::QGIPrimPath():
|
||||
m_width(0)
|
||||
{
|
||||
setCacheMode(QGraphicsItem::NoCache);
|
||||
setFlag(QGraphicsItem::ItemIsSelectable, true);
|
||||
|
@ -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)
|
||||
|
@ -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()
|
||||
|
|
|
@ -45,11 +45,14 @@ public:
|
|||
|
||||
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);
|
||||
|
@ -65,6 +68,7 @@ protected:
|
|||
QPen m_pen;
|
||||
QColor m_colCurrent;
|
||||
Qt::PenStyle m_styleCurrent;
|
||||
double m_width;
|
||||
|
||||
private:
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
@ -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) {
|
||||
|
@ -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) {
|
||||
|
@ -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
|
||||
|
||||
|
@ -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??
|
||||
|
@ -1172,6 +1183,7 @@ 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 {
|
||||
|
@ -1179,6 +1191,8 @@ void QGIViewDimension::paint ( QPainter * painter, const QStyleOptionGraphicsIte
|
|||
}
|
||||
QGIView::paint (painter, &myOption, widget);
|
||||
m_pen.setWidthF(saveWidth);
|
||||
aHead1->setWidth(arrowSaveWidth);
|
||||
aHead2->setWidth(arrowSaveWidth);
|
||||
}
|
||||
|
||||
void QGIViewDimension::setSvgPens(void)
|
||||
|
@ -1186,15 +1200,13 @@ 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>
|
||||
|
|
Loading…
Reference in New Issue
Block a user