QElectroTech  0.70
elementprimitivedecorator.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 ELEMENTPRIMITIVEDECORATOR_H
19 #define ELEMENTPRIMITIVEDECORATOR_H
20 
21 #include <QGraphicsObject>
22 #include "qet.h"
23 
25 class ElementScene;
26 class CustomElementPart;
28 
40 class ElementPrimitiveDecorator : public QGraphicsObject
41 {
42  Q_OBJECT
43 
44  public:
45  ElementPrimitiveDecorator(QGraphicsItem * = nullptr);
46  ~ElementPrimitiveDecorator() override;
47 
48  enum { Type = UserType + 2200 };
49 
50  // methods
51  QRectF internalBoundingRect() const;
52  QRectF boundingRect () const override;
53  void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget * = nullptr) override;
54  int type() const override { return Type; }
55  void setItems(const QList<QGraphicsItem *> &);
56  void setItems(const QList<CustomElementPart *> &);
57  QList<CustomElementPart *> items() const;
58  QList<QGraphicsItem *> graphicsItems() const;
59 
60  public slots:
61  void adjust();
62 
63  signals:
65 
66  protected:
67  void mousePressEvent(QGraphicsSceneMouseEvent *) override;
68  void mouseMoveEvent(QGraphicsSceneMouseEvent *) override;
69  void mouseReleaseEvent(QGraphicsSceneMouseEvent *) override;
70  void keyPressEvent(QKeyEvent *) override;
71  void keyReleaseEvent(QKeyEvent *) override;
72  QPointF deltaForRoundScaling(const QRectF &, const QRectF &, qreal);
73  QPointF snapConstPointToGrid(const QPointF &) const;
74  void snapPointToGrid(QPointF &) const;
75  bool mustSnapToGrid(QGraphicsSceneMouseEvent *);
76  QET::ScalingMethod scalingMethod(QGraphicsSceneMouseEvent *);
77  QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
78  bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) override;
79 
80  private:
81  void init();
84  void startMovement();
85  void applyMovementToRect(int, const QPointF &, QRectF &);
87  void translateItems(const QPointF &);
88  void scaleItems(const QRectF &, const QRectF &);
89  QRectF getSceneBoundingRect(QGraphicsItem *) const;
90  QVector <QPointF> getResizingsPoints() const;
91 
92 
93  private:
94  void adjusteHandlerPos();
95  void handlerMousePressEvent (QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event);
96  void handlerMouseMoveEvent (QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event);
97  void handlerMouseReleaseEvent (QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event);
98 
99  void addHandler();
100  void removeHandler();
101 
102 
103 
104 
105  QList<CustomElementPart *> decorated_items_;
109 
117  QPointF first_pos_;
118  QPointF latest_pos_;
119  QPointF mouse_offset_;
121  QPointF keys_movement_;
122  QVector<QetGraphicsHandlerItem *> m_handler_vector;
123  int m_vector_index = -1;
124 };
125 
126 #endif
QPointF deltaForRoundScaling(const QRectF &, const QRectF &, qreal)
void keyPressEvent(QKeyEvent *) override
QRectF modified_bounding_rect_
new bounding rect, after the user moved or resized items
void addHandler()
ElementPrimitiveDecorator::addHandler Add handlers for this item.
The QetGraphicsHandlerItem class This graphics item represents a point, destined to be used as an han...
QVector< QPointF > getResizingsPoints() const
QPointF snapConstPointToGrid(const QPointF &) const
bool moving_by_keys_
Whether we are currently moving our decorated items using the arrow keys.
void handlerMouseReleaseEvent(QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event)
ElementPrimitiveDecorator::handlerMouseReleaseEvent.
QList< CustomElementPart * > items() const
void mouseMoveEvent(QGraphicsSceneMouseEvent *) override
QPointF keys_movement_
Movement applied to our decorated items using the arrow keys.
void actionFinished(ElementEditionCommand *)
QList< QGraphicsItem * > graphicsItems() const
QET::ScalingMethod scalingMethod(QGraphicsSceneMouseEvent *)
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *=nullptr) override
QPointF mouse_offset_
Offset between the mouse position and the point to be snapped to grid when moving selection...
QList< CustomElementPart * > decorated_items_
void handlerMousePressEvent(QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event)
ElementPrimitiveDecorator::handlerMousePressEvent.
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override
ElementPrimitiveDecorator::itemChange.
void handlerMouseMoveEvent(QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event)
ElementPrimitiveDecorator::handlerMouseMoveEvent.
The ElementEditionCommand class ElementEditionCommand is the base class for all commands classes invo...
QPointF latest_pos_
Latest point involved within the current resizing operation.
bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) override
ElementPrimitiveDecorator::sceneEventFilter.
QRectF effective_bounding_rect_
actual, effective bounding rect – never shrinks
void mouseReleaseEvent(QGraphicsSceneMouseEvent *) override
void applyMovementToRect(int, const QPointF &, QRectF &)
int grid_step_x_
Grid horizontal step.
void keyReleaseEvent(QKeyEvent *) override
QRectF original_bounding_rect_
original bounding rect
ScalingMethod
Supported types of interactive scaling, typically for a single element primitive. ...
Definition: qet.h:79
void adjusteHandlerPos()
ElementPrimitiveDecorator::adjusteHandlerPos.
QRectF boundingRect() const override
QPointF first_pos_
First point involved within the current resizing operation.
void removeHandler()
ElementPrimitiveDecorator::removeHandler Remove the handlers of this item.
ElementPrimitiveDecorator(QGraphicsItem *=nullptr)
void mousePressEvent(QGraphicsSceneMouseEvent *) override
int grid_step_y_
Grid horizontal step.
void setItems(const QList< QGraphicsItem *> &)
bool mustSnapToGrid(QGraphicsSceneMouseEvent *)
QRectF getSceneBoundingRect(QGraphicsItem *) const
CustomElementPart * singleItem() const
void scaleItems(const QRectF &, const QRectF &)
QVector< QetGraphicsHandlerItem * > m_handler_vector