QElectroTech  0.70
customelementgraphicpart.h
Go to the documentation of this file.
1 /*
2  Copyright 2006-2019 The QElectroTech Team
3  This file is part of QElectroTech.
4 
5  QElectroTech is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 2 of the License, or
8  (at your option) any later version.
9 
10  QElectroTech is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
17 */
18 #ifndef CUSTOM_ELEMENT_GRAPHIC_PART_H
19 #define CUSTOM_ELEMENT_GRAPHIC_PART_H
20 
21 #include <QGraphicsObject>
22 #include "customelementpart.h"
23 
24 class QETElementEditor;
25 class QPainter;
26 
27 
33 class CustomElementGraphicPart : public QGraphicsObject, public CustomElementPart
34 {
35  #define SHADOWS_HEIGHT 4.0
36 
37  Q_OBJECT
38 
39  Q_PROPERTY(LineStyle line_style READ lineStyle WRITE setLineStyle)
41  Q_PROPERTY(Filling filling READ filling WRITE setFilling)
42  Q_PROPERTY(Color color READ color WRITE setColor)
43  Q_PROPERTY(bool antialias READ antialiased WRITE setAntialiased)
44 
45  public:
46  //Line style
48  Q_ENUM (LineStyle)
49 
50  //Line weight : invisible, 0px, 1px, 2px, 5px
52  Q_ENUM (LineWeight)
53 
54  //Filling color of the part : NoneFilling -> No filling (i.e. transparent)
56  Q_ENUM (Filling)
57 
58  //Line color
60  Q_ENUM (Color)
61 
62  // constructors, destructor
63  public:
64 
65  CustomElementGraphicPart(QETElementEditor *editor, QGraphicsItem *parent = nullptr);
66  ~CustomElementGraphicPart() override;
67 
68  static void drawCross (const QPointF &center, QPainter *painter);
69 
70  //Getter and setter
71  LineStyle lineStyle () const {return _linestyle;}
72  void setLineStyle (const LineStyle ls);
73 
74  LineWeight lineWeight () const {return _lineweight;}
75  void setLineWeight (const LineWeight lw);
76  qreal penWeight () const;
77 
78  Filling filling () const {return _filling;}
79  void setFilling(const Filling f);
80 
81  Color color () const {return _color;}
82  void setColor(const Color c);
83 
84  bool antialiased () const {return _antialiased;}
85  void setAntialiased(const bool b);
86  //End of getter and setter
87 
88 
89  //Rediriged to QObject Q_PROPERTY system
90  void setProperty (const char *name, const QVariant &value) override {QObject::setProperty(name, value);}
91  QVariant property (const char *name) const override {return QObject::property(name);}
92 
93  virtual QPainterPath shadowShape ()const = 0;
94 
95  protected:
96  void stylesToXml (QDomElement &) const;
97  void stylesFromXml(const QDomElement &);
98  void resetStyles ();
99  void applyStylesToQPainter(QPainter &) const;
100  void drawShadowShape (QPainter *painter);
101 
102  QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
103  void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override;
104  void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override;
105 
106  void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
107  void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
108  void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
109 
110  // attributes
111  bool m_hovered;
112  private:
118  QPointF m_origin_pos;
119 };
120 
122 #endif
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.
static void drawCross(const QPointF &center, QPainter *painter)
CustomElementGraphicPart::drawCross Draw a cross at pos center.
The CustomElementGraphicPart class This class is the base for all home-made primitive like line...
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
QVariant property(const char *name) const 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...
void setLineWeight(const LineWeight lw)
CustomElementGraphicPart::setLineWeight Set line weight to lw.
void setProperty(const char *name, const QVariant &value) override
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.
virtual QString name() const =0
void setColor(const Color c)
CustomElementGraphicPart::setColor Set color to c.
CustomElementGraphicPart CEGP
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...