QElectroTech  0.8-dev
partline.h
Go to the documentation of this file.
1 /*
2  Copyright 2006-2020 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 
40  Q_PROPERTY(Qet::EndType end1 READ firstEndType WRITE setFirstEndType)
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();
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
QPropertyUndoCommand::enableAnimation
void enableAnimation(bool animate=true)
QPropertyUndoCommand::enableAnimation True to enable animation.
Definition: qpropertyundocommand.cpp:92
ElementScene::snapToGrid
QPointF snapToGrid(QPointF point)
ElementScene::snapToGrid Rounds the coordinates of the point passed as a parameter so that this point...
Definition: elementscene.cpp:1270
PartLine::handlerMousePressEvent
void handlerMousePressEvent(QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event)
PartLine::handlerMousePressEvent.
Definition: partline.cpp:247
PartLine::~PartLine
~PartLine() override
Destructeur.
Definition: partline.cpp:41
QetGraphicsHandlerItem::Type
@ Type
Definition: qetgraphicshandleritem.h:42
PartLine::m_vector_index
int m_vector_index
Definition: partline.h:126
PartLine::secondEndType
Qet::EndType secondEndType() const
Definition: partline.h:91
ElementScene::undoStack
QUndoStack & undoStack()
ElementScene::undoStack.
Definition: elementscene.cpp:603
PartLine::debugPaint
void debugPaint(QPainter *)
PartLine::debugPaint Display several composante of the drawing -the bounding rect -special points at ...
Definition: partline.cpp:497
PartLine::setSecondEndLength
void setSecondEndLength(const qreal &l)
Definition: partline.cpp:658
PartLine::toXml
const QDomElement toXml(QDomDocument &) const override
PartLine::toXml Export this line in xml.
Definition: partline.cpp:105
CustomElementGraphicPart
The CustomElementGraphicPart class This class is the base for all home-made primitive like line,...
Definition: customelementgraphicpart.h:36
PartLine::end1
Qet::EndType end1
Definition: partline.h:40
PartLine::second_end
Qet::EndType second_end
Definition: partline.h:122
PartLine::fourShapePoints
QList< QPointF > fourShapePoints() const
PartLine::fourShapePoints.
Definition: partline.cpp:411
PartLine::m_undo_command
QPropertyUndoCommand * m_undo_command
Definition: partline.h:127
PartLine::setFirstEndType
void setFirstEndType(const Qet::EndType &et)
Definition: partline.cpp:633
PartLine::type
int type() const override
Definition: partline.h:69
PartLine::isUseless
bool isUseless() const override
PartLine::isUseless.
Definition: partline.cpp:546
PartLine::requiredLengthForEndType
static uint requiredLengthForEndType(const Qet::EndType &)
PartLine::requiredLengthForEndType.
Definition: partline.cpp:54
PartLine::setFirstEndLength
void setFirstEndLength(const qreal &l)
Definition: partline.cpp:649
CustomElementGraphicPart::stylesToXml
void stylesToXml(QDomElement &) const
CustomElementGraphicPart::stylesToXml Write the curent style to xml element. The style are stored lik...
Definition: customelementgraphicpart.cpp:162
Qet::Simple
@ Simple
Base-less triangle.
Definition: qet.h:195
PartLine::secondEndLength
qreal secondEndLength() const
Definition: partline.h:95
PartLine::Type
@ Type
Definition: partline.h:63
PartLine::startUserTransformation
void startUserTransformation(const QRectF &) override
PartLine::startUserTransformation Start the user-induced transformation, provided this primitive is c...
Definition: partline.cpp:567
QPropertyUndoCommand::setNewValue
void setNewValue(const QVariant &new_value)
QPropertyUndoCommand::setNewValue Set the new value of the property (set with redo) to new_value.
Definition: qpropertyundocommand.cpp:83
Qet::Diamond
@ Diamond
Diamond.
Definition: qet.h:198
PartLine::paint
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *=nullptr) override
PartLine::paint Draw this line.
Definition: partline.cpp:73
PartLine::second_length
qreal second_length
Definition: partline.h:123
PartLine::first_length
qreal first_length
Definition: partline.h:120
PartLine::boundingRect
QRectF boundingRect() const override
PartLine::boundingRect.
Definition: partline.cpp:522
partline.h
PartLine::path
QPainterPath path() const
PartLine::path.
Definition: partline.cpp:674
PartLine::secondEndTypeChanged
void secondEndTypeChanged()
PartLine::sceneP1
virtual QPointF sceneP1() const
PartLine::sceneP1.
Definition: partline.cpp:349
PartLine::saved_points_
QList< QPointF > saved_points_
Definition: partline.h:124
PartLine::sceneP2
virtual QPointF sceneP2() const
PartLine::sceneP2.
Definition: partline.cpp:357
CustomElementGraphicPart::stylesFromXml
void stylesFromXml(const QDomElement &)
CustomElementGraphicPart::stylesFromXml Read the style used by this, from a xml element.
Definition: customelementgraphicpart.cpp:508
PartLine::length2
qreal length2
Definition: partline.h:43
PartLine::name
QString name() const override
Definition: partline.h:71
PartLine::firstEndCircleRect
QRectF firstEndCircleRect() const
PartLine::firstEndCircleRect.
Definition: partline.cpp:458
PartLine::end2
Qet::EndType end2
Definition: partline.h:41
PartLine::secondEndCircleRect
QRectF secondEndCircleRect() const
PartLine::secondEndCircleRect.
Definition: partline.cpp:476
PartLine::firstEndLengthChanged
void firstEndLengthChanged()
qet.h
PartLine::handleUserTransformation
void handleUserTransformation(const QRectF &, const QRectF &) override
PartLine::handleUserTransformation Handle the user-induced transformation from initial_selection_rect...
Definition: partline.cpp:580
PartLine::m_handler_vector
QVector< QetGraphicsHandlerItem * > m_handler_vector
Definition: partline.h:128
PartLine::firstEndTypeChanged
void firstEndTypeChanged()
PartLine::removeHandler
void removeHandler()
PartLine::removeHandler Remove the handlers of this item.
Definition: partline.cpp:336
PartLine
Definition: partline.h:37
Qet::EndType
EndType
This enum lists the various available endings for line primitives when drawing an electrical element.
Definition: qet.h:193
PartLine::PartLine
PartLine(QETElementEditor *, QGraphicsItem *=nullptr)
PartLine::PartLine Constructor.
Definition: partline.cpp:31
elementscene.h
PartLine::length1
qreal length1
Definition: partline.h:42
qpropertyundocommand.h
qetgraphicshandleritem.h
PartLine::xmlName
QString xmlName() const override
Definition: partline.h:72
PartLine::fromXml
void fromXml(const QDomElement &) override
PartLine::fromXml Import the properties of this line from a xml element.
Definition: partline.cpp:129
QetGraphicsHandlerItem
The QetGraphicsHandlerItem class This graphics item represents a point, destined to be used as an han...
Definition: qetgraphicshandleritem.h:37
PartLine::itemChange
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override
PartLine::itemChange.
Definition: partline.cpp:148
PartLine::fourEndPoints
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
CustomElementGraphicPart::m_hovered
bool m_hovered
Definition: customelementgraphicpart.h:323
PartLine::lineChanged
void lineChanged()
PartLine::m_line
QLineF m_line
Definition: partline.h:125
PartLine::sceneGeometricRect
QRectF sceneGeometricRect() const override
PartLine::sceneGeometricRect.
Definition: partline.cpp:557
customelementgraphicpart.h
Qet::endTypeFromString
static Qet::EndType endTypeFromString(const QString &)
Definition: qet.cpp:506
PartLine::sceneSelectionChanged
void sceneSelectionChanged()
PartLine::sceneSelectionChanged When the scene selection change, if there are several primitive selec...
Definition: partline.cpp:301
PartLine::setLine
void setLine(const QLineF &line)
Definition: partline.cpp:624
SHADOWS_HEIGHT
#define SHADOWS_HEIGHT
Definition: customelementgraphicpart.h:37
PartLine::handlerMouseReleaseEvent
void handlerMouseReleaseEvent(QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event)
PartLine::handlerMouseReleaseEvent.
Definition: partline.cpp:286
Qet::Circle
@ Circle
Circle.
Definition: qet.h:197
PartLine::line
QLineF line
Definition: partline.h:44
PartLine::addHandler
void addHandler()
PartLine::addHandler Add handlers for this item.
Definition: partline.cpp:313
Qet::endTypeToString
static QString endTypeToString(const Qet::EndType &)
Definition: qet.cpp:489
PartLine::firstEndLength
qreal firstEndLength() const
Definition: partline.h:93
CustomElementPart::elementScene
virtual ElementScene * elementScene() const
Definition: customelementpart.cpp:37
CustomElementPart::mapPoints
QList< QPointF > mapPoints(const QRectF &, const QRectF &, const QList< QPointF > &)
Definition: customelementpart.cpp:69
PartLine::handlerMouseMoveEvent
void handlerMouseMoveEvent(QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event)
PartLine::handlerMouseMoveEvent.
Definition: partline.cpp:263
Qet
Definition: qet.h:188
PartLine::firstEndType
Qet::EndType firstEndType() const
Definition: partline.h:89
PartLine::adjusteHandlerPos
void adjusteHandlerPos()
PartLine::adjusteHandlerPos Adjust the position of the handler item.
Definition: partline.cpp:226
PartLine::setSecondEndType
void setSecondEndType(const Qet::EndType &et)
Definition: partline.cpp:641
Qet::Triangle
@ Triangle
Triangle.
Definition: qet.h:196
PartLine::shadowShape
QPainterPath shadowShape() const override
Definition: partline.cpp:386
CustomElementGraphicPart::applyStylesToQPainter
void applyStylesToQPainter(QPainter &) const
CustomElementGraphicPart::applyStylesToQPainter Apply the current style to the QPainter.
Definition: customelementgraphicpart.cpp:885
CustomElementGraphicPart::penWeight
qreal penWeight() const
CustomElementGraphicPart::penWeight.
Definition: customelementgraphicpart.cpp:109
PartLine::secondEndLengthChanged
void secondEndLengthChanged()
QPropertyUndoCommand
The QPropertyUndoCommand class This undo command manage QProperty of a QObject. This undo command can...
Definition: qpropertyundocommand.h:34
PartLine::PartLine
PartLine(const PartLine &)
PartLine::sceneEventFilter
bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) override
PartLine::sceneEventFilter.
Definition: partline.cpp:188
QetGraphicsHandlerItem::handlerForPoint
static QVector< QetGraphicsHandlerItem * > handlerForPoint(const QVector< QPointF > &points, int size=10)
QetGraphicsHandlerItem::handlerForPoint.
Definition: qetgraphicshandleritem.cpp:87
PartLine::shape
QPainterPath shape() const override
PartLine::shape.
Definition: partline.cpp:365
QET::Icons::tr
QIcon tr
Definition: qeticons.cpp:206
QETElementEditor
Definition: qetelementeditor.h:33
CustomElementGraphicPart::drawShadowShape
void drawShadowShape(QPainter *painter)
CustomElementGraphicPart::drawShadowShape Draw a transparent blue shadow arround the shape of this it...
Definition: customelementgraphicpart.cpp:1240
PartLine::first_end
Qet::EndType first_end
Definition: partline.h:119