QElectroTech  0.8-dev
partrectangle.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_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();
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,
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
qetgraphicshandlerutility.h
PartRectangle::m_handler_vector
QVector< QetGraphicsHandlerItem * > m_handler_vector
Definition: partrectangle.h:106
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
PartRectangle::sceneGeometricRect
QRectF sceneGeometricRect() const override
PartRectangle::sceneGeometricRect.
Definition: partrectangle.cpp:170
QetGraphicsHandlerItem::Type
@ Type
Definition: qetgraphicshandleritem.h:42
PartRectangle::sceneSelectionChanged
void sceneSelectionChanged()
PartRectangle::sceneSelectionChanged When the scene selection change, if there are several primitive ...
Definition: partrectangle.cpp:502
PartRectangle::paint
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *=nullptr) override
PartRectangle::paint Draw this Rectangle.
Definition: partrectangle.cpp:48
ElementScene::undoStack
QUndoStack & undoStack()
ElementScene::undoStack.
Definition: elementscene.cpp:603
PartRectangle::m_old_xRadius
qreal m_old_xRadius
Definition: partrectangle.h:109
CustomElementGraphicPart::drawCross
static void drawCross(const QPointF &center, QPainter *painter)
CustomElementGraphicPart::drawCross Draw a cross at pos center.
Definition: customelementgraphicpart.cpp:60
PartRectangle::YRadiusChanged
void YRadiusChanged()
PartRectangle::XRadiusChanged
void XRadiusChanged()
PartRectangle::fromXml
void fromXml(const QDomElement &) override
PartRectangle::fromXml Import the properties of this rectangle from a xml element.
Definition: partrectangle.cpp:111
PartRectangle::m_old_rect
QRectF m_old_rect
Definition: partrectangle.h:102
PartRectangle::setYRadius
void setYRadius(qreal Y)
Definition: partrectangle.cpp:155
CustomElementGraphicPart
The CustomElementGraphicPart class This class is the base for all home-made primitive like line,...
Definition: customelementgraphicpart.h:36
PartRectangle::setRect
void setRect(const QRectF &rect)
PartRectangle::setRect Sets the item's rectangle to be the given rectangle.
Definition: partrectangle.cpp:138
PartRectangle::Type
@ Type
Definition: partrectangle.h:53
PartRectangle::handlerMousePressEvent
void handlerMousePressEvent(QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event)
PartRectangle::handlerMousePressEvent.
Definition: partrectangle.cpp:424
PartRectangle::m_old_yRadius
qreal m_old_yRadius
Definition: partrectangle.h:110
PartRectangle::saved_points_
QList< QPointF > saved_points_
Definition: partrectangle.h:103
QetGraphicsHandlerUtility::pointForRadiusRect
static QVector< QPointF > pointForRadiusRect(const QRectF &rect, qreal xRadius, qreal yRadius, Qt::SizeMode mode=Qt::AbsoluteSize)
QetGraphicsHandlerUtility::pointForRadiusRect.
Definition: qetgraphicshandlerutility.cpp:276
CustomElementGraphicPart::stylesToXml
void stylesToXml(QDomElement &) const
CustomElementGraphicPart::stylesToXml Write the curent style to xml element. The style are stored lik...
Definition: customelementgraphicpart.cpp:162
PartRectangle::itemChange
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override
PartRectangle::itemChange.
Definition: partrectangle.cpp:280
PartRectangle::adjusteHandlerPos
void adjusteHandlerPos()
PartRectangle::adjusteHandlerPos.
Definition: partrectangle.cpp:390
CustomElementGraphicPart::mouseReleaseEvent
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override
Definition: customelementgraphicpart.cpp:1318
PartRectangle::switchResizeMode
void switchResizeMode()
PartRectangle::switchResizeMode.
Definition: partrectangle.cpp:357
PartRectangle::YRadius
qreal YRadius() const
Definition: partrectangle.h:70
QetGraphicsHandlerUtility::radiusForPosAtIndex
static qreal radiusForPosAtIndex(const QRectF &rect, const QPointF &pos, int index, Qt::SizeMode mode=Qt::AbsoluteSize)
QetGraphicsHandlerUtility::radiusForPosAtIndex.
Definition: qetgraphicshandlerutility.cpp:316
PartRectangle::PartRectangle
PartRectangle(QETElementEditor *, QGraphicsItem *parent=nullptr)
PartRectangle::PartRectangle Constructor.
Definition: partrectangle.cpp:30
PartRectangle::m_vector_index
int m_vector_index
Definition: partrectangle.h:105
PartRectangle::m_rect
QRectF m_rect
Definition: partrectangle.h:101
PartRectangle::boundingRect
QRectF boundingRect() const override
PartRectangle::boundingRect.
Definition: partrectangle.cpp:213
PartRectangle::m_modifie_radius_equaly
bool m_modifie_radius_equaly
Definition: partrectangle.h:111
PartRectangle::handlerMouseReleaseEvent
void handlerMouseReleaseEvent(QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event)
Definition: partrectangle.cpp:473
PartRectangle::startUserTransformation
void startUserTransformation(const QRectF &) override
PartRectangle::startUserTransformation Start the user-induced transformation, provided this primitive...
Definition: partrectangle.cpp:241
CustomElementGraphicPart::stylesFromXml
void stylesFromXml(const QDomElement &)
CustomElementGraphicPart::stylesFromXml Read the style used by this, from a xml element.
Definition: customelementgraphicpart.cpp:508
QetGraphicsHandlerUtility::mirrorRectForPosAtIndex
static QRectF mirrorRectForPosAtIndex(const QRectF &old_rect, const QPointF &pos, int index)
QetGraphicsHandlerUtility::mirrorRectForPosAtIndex Return a rectangle after modification of the point...
Definition: qetgraphicshandlerutility.cpp:139
PartRectangle::m_resize_mode
int m_resize_mode
Definition: partrectangle.h:104
PartRectangle::shadowShape
QPainterPath shadowShape() const override
Definition: partrectangle.cpp:198
PartRectangle::handleUserTransformation
void handleUserTransformation(const QRectF &, const QRectF &) override
PartRectangle::handleUserTransformation Handle the user-induced transformation from initial_selection...
Definition: partrectangle.cpp:255
QetGraphicsHandlerUtility::pointsForRect
static QVector< QPointF > pointsForRect(const QRectF &rect)
QetGraphicsHandlerUtility::pointsForRect Return the keys points of the rectangle, stored in a vector....
Definition: qetgraphicshandlerutility.cpp:36
PartRectangle::rectChanged
void rectChanged()
PartRectangle::toXml
const QDomElement toXml(QDomDocument &) const override
PartRectangle::toXml Export this rectangle in xml.
Definition: partrectangle.cpp:80
PartRectangle::xmlName
QString xmlName() const override
Definition: partrectangle.h:62
PartRectangle::m_yRadius
qreal m_yRadius
Definition: partrectangle.h:108
PartRectangle::XRadius
qreal XRadius() const
Definition: partrectangle.h:68
partrectangle.h
elementscene.h
PartRectangle::handlerMouseMoveEvent
void handlerMouseMoveEvent(QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event)
PartRectangle::handlerMouseMoveEvent.
Definition: partrectangle.cpp:442
PartRectangle::shape
QPainterPath shape() const override
PartRectangle::shape.
Definition: partrectangle.cpp:186
PartRectangle::addHandler
void addHandler()
PartRectangle::addHandler Add handlers for this item.
Definition: partrectangle.cpp:514
qpropertyundocommand.h
PartRectangle::removeHandler
void removeHandler()
PartRectangle::removeHandler Remove the handlers of this item.
Definition: partrectangle.cpp:544
PartRectangle::isUseless
bool isUseless() const override
PartRectangle::isUseless.
Definition: partrectangle.cpp:231
PartRectangle::sceneEventFilter
bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) override
PartRectangle::sceneEventFilter.
Definition: partrectangle.cpp:320
QetGraphicsHandlerUtility::rectForPosAtIndex
static QRectF rectForPosAtIndex(const QRectF &old_rect, const QPointF &pos, int index)
QetGraphicsHandlerUtility::rectForPosAtIndex Return a rectangle after modification of the point 'pos'...
Definition: qetgraphicshandlerutility.cpp:106
qetgraphicshandleritem.h
QetGraphicsHandlerItem
The QetGraphicsHandlerItem class This graphics item represents a point, destined to be used as an han...
Definition: qetgraphicshandleritem.h:37
PartRectangle::rect
QRectF rect
Definition: partrectangle.h:34
QPropertyUndoCommand::setAnimated
void setAnimated(bool animate=true, bool first_time=true)
QPropertyUndoCommand::setAnimated.
Definition: qpropertyundocommand.cpp:103
CustomElementGraphicPart::m_hovered
bool m_hovered
Definition: customelementgraphicpart.h:323
PartRectangle::mouseReleaseEvent
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override
PartRectangle::mouseReleaseEvent Handle mouse release event.
Definition: partrectangle.cpp:266
PartRectangle::~PartRectangle
~PartRectangle() override
PartRectangle::~PartRectangle.
Definition: partrectangle.cpp:37
PartRectangle::type
int type() const override
Definition: partrectangle.h:58
customelementgraphicpart.h
SHADOWS_HEIGHT
#define SHADOWS_HEIGHT
Definition: customelementgraphicpart.h:37
CustomElementGraphicPart::color
Color color
Definition: customelementgraphicpart.h:44
PartRectangle
Definition: partrectangle.h:31
PartRectangle::xRadius
qreal xRadius
Definition: partrectangle.h:35
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
PartRectangle::setXRadius
void setXRadius(qreal X)
Definition: partrectangle.cpp:147
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
PartRectangle::yRadius
qreal yRadius
Definition: partrectangle.h:36
PartRectangle::m_xRadius
qreal m_xRadius
Definition: partrectangle.h:107
QPropertyUndoCommand
The QPropertyUndoCommand class This undo command manage QProperty of a QObject. This undo command can...
Definition: qpropertyundocommand.h:34
QetGraphicsHandlerItem::handlerForPoint
static QVector< QetGraphicsHandlerItem * > handlerForPoint(const QVector< QPointF > &points, int size=10)
QetGraphicsHandlerItem::handlerForPoint.
Definition: qetgraphicshandleritem.cpp:87
QET::Icons::tr
QIcon tr
Definition: qeticons.cpp:206
PartRectangle::sceneTopLeft
virtual QPointF sceneTopLeft() const
PartRectangle::sceneTopLeft.
Definition: partrectangle.cpp:178
QETElementEditor
Definition: qetelementeditor.h:33
PartRectangle::PartRectangle
PartRectangle(const PartRectangle &)
CustomElementGraphicPart::drawShadowShape
void drawShadowShape(QPainter *painter)
CustomElementGraphicPart::drawShadowShape Draw a transparent blue shadow arround the shape of this it...
Definition: customelementgraphicpart.cpp:1240
PartRectangle::name
QString name() const override
Definition: partrectangle.h:60