30 QGraphicsObject (parent),
33 _linestyle(NormalStyle),
34 _lineweight(NormalWeight),
35 _filling(NoneFilling),
39 setFlags(QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemSendsGeometryChanges);
40 setAcceptHoverEvents(
true);
59 painter -> setRenderHint(QPainter::Antialiasing,
false);
60 painter -> setPen((painter -> brush().
color() == QColor(Qt::black) && painter -> brush().isOpaque()) ? Qt::yellow : Qt::blue);
61 painter -> drawLine(QLineF(center.x() - 2.0, center.y(), center.x() + 2.0, center.y()));
62 painter -> drawLine(QLineF(center.x(), center.y() - 2.0, center.x(), center.y() + 2.0));
149 QString css_like_styles;
151 css_like_styles +=
"line-style:";
157 css_like_styles +=
";line-weight:";
165 css_like_styles +=
";filling:";
186 css_like_styles +=
";color:";
203 qde.setAttribute(
"style", css_like_styles);
204 qde.setAttribute(
"antialias",
_antialiased ?
"true" :
"false");
218 QStringList styles = qde.attribute(
"style").split(
";", QString::SkipEmptyParts);
221 QRegExp rx(
"^\\s*([a-z-]+)\\s*:\\s*([a-z-]+)\\s*$");
222 foreach (QString style, styles)
224 if (!rx.exactMatch(style))
continue;
225 QString style_name = rx.cap(1);
226 QString style_value = rx.cap(2);
227 if (style_name ==
"line-style")
234 else if (style_name ==
"line-weight")
242 else if (style_name ==
"filling")
263 else if (style_name ==
"color")
308 QPen pen = painter.pen();
309 QBrush brush = painter.brush();
332 brush.setStyle(Qt::SolidPattern);
349 if (
_color ==
WhiteColor) pen.setColor(QColor(255, 255, 255, pen.color().alpha()));
350 else if (
_color ==
BlackColor) pen.setColor(QColor( 0, 0, 0, pen.color().alpha()));
365 painter.setRenderHint(QPainter::Antialiasing,
_antialiased);
366 painter.setRenderHint(QPainter::TextAntialiasing,
_antialiased);
367 painter.setRenderHint(QPainter::SmoothPixmapTransform,
_antialiased);
370 painter.setBrush(brush);
384 QPainterPathStroker strock;
386 strock.setJoinStyle(Qt::RoundJoin);
389 QColor
color(Qt::darkBlue);
391 painter -> setBrush (QBrush (
color));
392 painter -> setPen (Qt::NoPen);
393 painter -> drawPath (strock.createStroke(
shadowShape()));
394 painter -> restore ();
409 if (change == QGraphicsItem::ItemPositionChange || change == QGraphicsItem::ItemPositionHasChanged)
412 return(QGraphicsObject::itemChange(change, value));
424 QGraphicsObject::hoverEnterEvent(event);
436 QGraphicsObject::hoverLeaveEvent(event);
441 if(event->button() == Qt::LeftButton)
444 QGraphicsObject::mousePressEvent(event);
449 if((event->buttons() & Qt::LeftButton) && (flags() & QGraphicsItem::ItemIsMovable))
451 QPointF pos =
event->scenePos() + (
m_origin_pos -
event->buttonDownScenePos(Qt::LeftButton));
452 event->modifiers() == Qt::ControlModifier ? setPos(pos) : setPos(
elementScene()->snapToGrid(pos));
455 QGraphicsObject::mouseMoveEvent(event);
460 if((event->button() & Qt::LeftButton) && (flags() & QGraphicsItem::ItemIsMovable) &&
m_origin_pos != pos())
463 undo->setText(
tr(
"Déplacer une primitive"));
468 QGraphicsObject::mouseReleaseEvent(event);
The QPropertyUndoCommand class This undo command manage QProperty of a QObject. This undo command can...
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override
void setFilling(const Filling f)
CustomElementGraphicPart::setFilling Set filling to f.
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override
CustomElementGraphicPart::itemChange Reimplemented from QGraphicsObject. If the item position change ...
virtual QPainterPath shadowShape() const =0
void setAntialiased(const bool b)
CustomElementGraphicPart::setAntialiased Set antialias to b.
~CustomElementGraphicPart() override
CustomElementGraphicPart::~CustomElementGraphicPart Destructor.
void enableAnimation(bool animate=true)
QPropertyUndoCommand::enableAnimation True to enable animation.
static void drawCross(const QPointF ¢er, QPainter *painter)
CustomElementGraphicPart::drawCross Draw a cross at pos center.
void mousePressEvent(QGraphicsSceneMouseEvent *event) override
void stylesToXml(QDomElement &) const
CustomElementGraphicPart::stylesToXml Write the curent style to xml element. The style are stored lik...
void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override
CustomElementGraphicPart::hoverEnterEvent Reimplemented from QGraphicsObject. Set m_hovered to true...
void resetStyles()
CustomElementGraphicPart::resetStyles Reset the curent style to default, same style of default constr...
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override
void setLineStyle(const LineStyle ls)
CustomElementGraphicPart::setLineStyle Set line style to ls.
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override
CustomElementGraphicPart::hoverLeaveEvent Reimplemented from QGraphicsObject. Set m_hovered to false...
virtual void updateCurrentPartEditor() const
void setLineWeight(const LineWeight lw)
CustomElementGraphicPart::setLineWeight Set line weight to lw.
void stylesFromXml(const QDomElement &)
CustomElementGraphicPart::stylesFromXml Read the style used by this, from a xml element.
CustomElementGraphicPart(QETElementEditor *editor, QGraphicsItem *parent=nullptr)
CustomElementGraphicPart::CustomElementGraphicPart Default constructor. By default, item is selectable, send geometry change (Qt > 4.6), accept mouse left button and accept hover event.
void setColor(const Color c)
CustomElementGraphicPart::setColor Set color to c.
virtual ElementScene * elementScene() const
qreal penWeight() const
CustomElementGraphicPart::penWeight.
void applyStylesToQPainter(QPainter &) const
CustomElementGraphicPart::applyStylesToQPainter Apply the current style to the QPainter.
void drawShadowShape(QPainter *painter)
CustomElementGraphicPart::drawShadowShape Draw a transparent blue shadow arround the shape of this it...