QElectroTech  0.70
partrectangle.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_RECTANGLE_H
19 #define PART_RECTANGLE_H
20 
22 
24 
31 {
32  Q_OBJECT
33 
34  Q_PROPERTY(QRectF rect READ rect WRITE setRect)
35  Q_PROPERTY(qreal xRadius READ XRadius WRITE setXRadius NOTIFY XRadiusChanged)
36  Q_PROPERTY(qreal yRadius READ YRadius WRITE setYRadius NOTIFY YRadiusChanged)
37 
38  // constructors, destructor
39  public:
40  PartRectangle(QETElementEditor *, QGraphicsItem *parent = nullptr);
41  ~PartRectangle() override;
42 
43  private:
45 
46  signals:
47  void rectChanged();
48  void XRadiusChanged();
49  void YRadiusChanged();
50 
51  // methods
52  public:
53  enum { Type = UserType + 1109 };
58  int type () const override { return Type; }
59  void paint (QPainter *, const QStyleOptionGraphicsItem *, QWidget * = nullptr) override;
60  QString name () const override { return(QObject::tr("rectangle", "element part name")); }
61 
62  QString xmlName () const override { return(QString("rect")); }
63  const QDomElement toXml (QDomDocument &) const override;
64  void fromXml (const QDomElement &) override;
65 
66  QRectF rect() const;
67  void setRect(const QRectF &rect);
68  qreal XRadius() const {return m_xRadius;}
69  void setXRadius(qreal X);
70  qreal YRadius() const {return m_yRadius;}
71  void setYRadius(qreal Y);
72 
73  QRectF sceneGeometricRect() const override;
74  virtual QPointF sceneTopLeft() const;
75 
76  QPainterPath shape () const override;
77  QPainterPath shadowShape() const override;
78  QRectF boundingRect() const override;
79  bool isUseless() const override;
80 
81  void startUserTransformation(const QRectF &) override;
82  void handleUserTransformation(const QRectF &, const QRectF &) override;
83 
84  protected:
85  void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
86  QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
87  bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) override;
88 
89  private:
90  void switchResizeMode();
91  void adjusteHandlerPos();
92  void handlerMousePressEvent (QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event);
93  void handlerMouseMoveEvent (QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event);
94  void handlerMouseReleaseEvent (QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event);
95  void sceneSelectionChanged ();
96 
97  void addHandler();
98  void removeHandler();
99 
100  private:
101  QRectF m_rect,
102  m_old_rect;
103  QList<QPointF> saved_points_;
104  int m_resize_mode = 1,
106  QVector<QetGraphicsHandlerItem *> m_handler_vector;
107  qreal m_xRadius = 0,
112 };
113 #endif
void sceneSelectionChanged()
PartRectangle::sceneSelectionChanged When the scene selection change, if there are several primitive ...
void adjusteHandlerPos()
PartRectangle::adjusteHandlerPos.
virtual QPointF sceneTopLeft() const
PartRectangle::sceneTopLeft.
void handlerMouseReleaseEvent(QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event)
bool m_modifie_radius_equaly
QRectF rect() const
QRectF boundingRect() const override
PartRectangle::boundingRect.
const QDomElement toXml(QDomDocument &) const override
PartRectangle::toXml Export this rectangle in xml.
The QetGraphicsHandlerItem class This graphics item represents a point, destined to be used as an han...
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *=nullptr) override
PartRectangle::paint Draw this Rectangle.
void XRadiusChanged()
QPainterPath shape() const override
PartRectangle::shape.
bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) override
PartRectangle::sceneEventFilter.
qreal XRadius() const
Definition: partrectangle.h:68
void setRect(const QRectF &rect)
PartRectangle::setRect Sets the item&#39;s rectangle to be the given rectangle.
The CustomElementGraphicPart class This class is the base for all home-made primitive like line...
void handlerMouseMoveEvent(QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event)
PartRectangle::handlerMouseMoveEvent.
void addHandler()
PartRectangle::addHandler Add handlers for this item.
QList< QPointF > saved_points_
void setYRadius(qreal Y)
void setXRadius(qreal X)
void fromXml(const QDomElement &) override
PartRectangle::fromXml Import the properties of this rectangle from a xml element.
QIcon tr
Definition: qeticons.cpp:204
void YRadiusChanged()
void handleUserTransformation(const QRectF &, const QRectF &) override
PartRectangle::handleUserTransformation Handle the user-induced transformation from initial_selection...
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override
PartRectangle::mouseReleaseEvent Handle mouse release event.
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override
PartRectangle::itemChange.
void rectChanged()
void removeHandler()
PartRectangle::removeHandler Remove the handlers of this item.
QPainterPath shadowShape() const override
bool isUseless() const override
PartRectangle::isUseless.
QString name() const override
Definition: partrectangle.h:60
int type() const override
Definition: partrectangle.h:58
QString xmlName() const override
Definition: partrectangle.h:62
QVector< QetGraphicsHandlerItem * > m_handler_vector
QRectF sceneGeometricRect() const override
PartRectangle::sceneGeometricRect.
void handlerMousePressEvent(QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event)
PartRectangle::handlerMousePressEvent.
qreal YRadius() const
Definition: partrectangle.h:70
void switchResizeMode()
PartRectangle::switchResizeMode.
void startUserTransformation(const QRectF &) override
PartRectangle::startUserTransformation Start the user-induced transformation, provided this primitive...