QElectroTech  0.70
partline.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 PART_LINE_H
19 #define PART_LINE_H
20 
22 #include "qet.h"
23 
26 
37 {
38  Q_OBJECT
39 
41  Q_PROPERTY(Qet::EndType end2 READ secondEndType WRITE setSecondEndType)
42  Q_PROPERTY(qreal length1 READ firstEndLength WRITE setFirstEndLength)
43  Q_PROPERTY(qreal length2 READ secondEndLength WRITE setSecondEndLength)
44  Q_PROPERTY(QLineF line READ line WRITE setLine)
45 
46  // constructors, destructor
47  public:
48  PartLine(QETElementEditor *, QGraphicsItem * = nullptr);
49  ~PartLine() override;
50  private:
51  PartLine(const PartLine &);
52 
53  signals:
54  void lineChanged();
55  void firstEndTypeChanged();
56  void secondEndTypeChanged();
57  void firstEndLengthChanged();
59 
60 
61  // methods
62  public:
63  enum { Type = UserType + 1104 };
64 
69  int type() const override { return Type; }
70  void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget * = nullptr) override;
71  QString name() const override { return(QObject::tr("ligne", "element part name")); }
72  QString xmlName() const override { return(QString("line")); }
73  const QDomElement toXml(QDomDocument &) const override;
74  void fromXml(const QDomElement &) override;
75  virtual QPointF sceneP1() const;
76  virtual QPointF sceneP2() const;
77  QPainterPath shape() const override;
78  QPainterPath shadowShape() const override;
79  QRectF boundingRect() const override;
80  bool isUseless() const override;
81  QRectF sceneGeometricRect() const override;
82  void startUserTransformation(const QRectF &) override;
83  void handleUserTransformation(const QRectF &, const QRectF &) override;
84  static uint requiredLengthForEndType(const Qet::EndType &);
85  static QList<QPointF> fourEndPoints(const QPointF &, const QPointF &, const qreal &);
86 
87  QLineF line() const;
88  void setLine(const QLineF &line);
90  void setFirstEndType(const Qet::EndType &et);
92  void setSecondEndType(const Qet::EndType &et);
93  qreal firstEndLength() const {return first_length;}
94  void setFirstEndLength(const qreal &l);
95  qreal secondEndLength() const {return second_length;}
96  void setSecondEndLength(const qreal &l);
97 
98  protected:
99  QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
100  bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) override;
101 
102  private:
103  void adjusteHandlerPos();
104  void handlerMousePressEvent (QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event);
105  void handlerMouseMoveEvent (QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event);
106  void handlerMouseReleaseEvent (QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event);
107  void sceneSelectionChanged ();
108 
109  void addHandler();
110  void removeHandler();
111 
112  QPainterPath path() const;
113  QList<QPointF> fourShapePoints() const;
114  QRectF firstEndCircleRect() const;
115  QRectF secondEndCircleRect() const;
116  void debugPaint(QPainter *);
117 
118  /*****************/
121 
124  QList<QPointF> saved_points_;
125  QLineF m_line;
126  int m_vector_index = -1;
128  QVector<QetGraphicsHandlerItem *> m_handler_vector;
129 };
130 #endif
EndType
This enum lists the various available endings for line primitives when drawing an electrical element...
Definition: qet.h:191
QRectF sceneGeometricRect() const override
PartLine::sceneGeometricRect.
Definition: partline.cpp:557
The QPropertyUndoCommand class This undo command manage QProperty of a QObject. This undo command can...
bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) override
PartLine::sceneEventFilter.
Definition: partline.cpp:188
virtual QPointF sceneP2() const
PartLine::sceneP2.
Definition: partline.cpp:357
void setSecondEndLength(const qreal &l)
Definition: partline.cpp:658
qreal firstEndLength() const
Definition: partline.h:93
QString name() const override
Definition: partline.h:71
The QetGraphicsHandlerItem class This graphics item represents a point, destined to be used as an han...
Qet::EndType firstEndType() const
Definition: partline.h:89
void setFirstEndType(const Qet::EndType &et)
Definition: partline.cpp:633
virtual QPointF sceneP1() const
PartLine::sceneP1.
Definition: partline.cpp:349
void sceneSelectionChanged()
PartLine::sceneSelectionChanged When the scene selection change, if there are several primitive selec...
Definition: partline.cpp:301
QRectF firstEndCircleRect() const
PartLine::firstEndCircleRect.
Definition: partline.cpp:458
QLineF m_line
Definition: partline.h:125
void startUserTransformation(const QRectF &) override
PartLine::startUserTransformation Start the user-induced transformation, provided this primitive is c...
Definition: partline.cpp:567
qreal length1
Definition: partline.h:42
void setSecondEndType(const Qet::EndType &et)
Definition: partline.cpp:641
Qet::EndType end2
Definition: partline.h:41
void handlerMouseReleaseEvent(QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event)
PartLine::handlerMouseReleaseEvent.
Definition: partline.cpp:286
void handleUserTransformation(const QRectF &, const QRectF &) override
PartLine::handleUserTransformation Handle the user-induced transformation from initial_selection_rect...
Definition: partline.cpp:580
Qet::EndType end1
Definition: partline.h:40
The CustomElementGraphicPart class This class is the base for all home-made primitive like line...
void firstEndLengthChanged()
qreal secondEndLength() const
Definition: partline.h:95
qreal second_length
Definition: partline.h:123
Qet::EndType first_end
Definition: partline.h:119
QList< QPointF > saved_points_
Definition: partline.h:124
void setLine(const QLineF &line)
Definition: partline.cpp:624
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *=nullptr) override
PartLine::paint Draw this line.
Definition: partline.cpp:73
void secondEndTypeChanged()
void lineChanged()
static uint requiredLengthForEndType(const Qet::EndType &)
PartLine::requiredLengthForEndType.
Definition: partline.cpp:54
bool isUseless() const override
PartLine::isUseless.
Definition: partline.cpp:546
QString xmlName() const override
Definition: partline.h:72
QPainterPath path() const
PartLine::path.
Definition: partline.cpp:674
void fromXml(const QDomElement &) override
PartLine::fromXml Import the properties of this line from a xml element.
Definition: partline.cpp:129
QList< QPointF > fourShapePoints() const
PartLine::fourShapePoints.
Definition: partline.cpp:411
QIcon tr
Definition: qeticons.cpp:204
int type() const override
Definition: partline.h:69
void firstEndTypeChanged()
QRectF boundingRect() const override
PartLine::boundingRect.
Definition: partline.cpp:522
qreal first_length
Definition: partline.h:120
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override
PartLine::itemChange.
Definition: partline.cpp:148
void handlerMousePressEvent(QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event)
PartLine::handlerMousePressEvent.
Definition: partline.cpp:247
void debugPaint(QPainter *)
PartLine::debugPaint Display several composante of the drawing -the bounding rect -special points at ...
Definition: partline.cpp:497
qreal length2
Definition: partline.h:43
Qet::EndType second_end
Definition: partline.h:122
QLineF line() const
void handlerMouseMoveEvent(QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event)
PartLine::handlerMouseMoveEvent.
Definition: partline.cpp:263
QVector< QetGraphicsHandlerItem * > m_handler_vector
Definition: partline.h:128
void secondEndLengthChanged()
int m_vector_index
Definition: partline.h:126
const QDomElement toXml(QDomDocument &) const override
PartLine::toXml Export this line in xml.
Definition: partline.cpp:105
static QList< QPointF > fourEndPoints(const QPointF &, const QPointF &, const qreal &)
PartLine::fourEndPoints Return the four interesting point needed to draw the shape at extremity of li...
Definition: partline.cpp:601
void adjusteHandlerPos()
PartLine::adjusteHandlerPos Adjust the position of the handler item.
Definition: partline.cpp:226
void removeHandler()
PartLine::removeHandler Remove the handlers of this item.
Definition: partline.cpp:336
void addHandler()
PartLine::addHandler Add handlers for this item.
Definition: partline.cpp:313
Qet::EndType secondEndType() const
Definition: partline.h:91
QRectF secondEndCircleRect() const
PartLine::secondEndCircleRect.
Definition: partline.cpp:476
QPropertyUndoCommand * m_undo_command
Definition: partline.h:127
Definition: qet.h:185
QPainterPath shape() const override
PartLine::shape.
Definition: partline.cpp:365
QPainterPath shadowShape() const override
Definition: partline.cpp:386
void setFirstEndLength(const qreal &l)
Definition: partline.cpp:649