QElectroTech 0.100.0-dev
Loading...
Searching...
No Matches
elementprimitivedecorator.h
Go to the documentation of this file.
1/*
2 Copyright 2006-2024 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 "../qet.h"
22
23#include <QGraphicsObject>
24
26class ElementScene;
29
41class ElementPrimitiveDecorator : public QGraphicsObject
42{
43 Q_OBJECT
44
45 public:
46 ElementPrimitiveDecorator(QGraphicsItem * = nullptr);
48
49 enum { Type = UserType + 2200 };
50
51 // methods
52 QRectF internalBoundingRect() const;
53 QRectF boundingRect () const override;
54 void paint(QPainter *,
55 const QStyleOptionGraphicsItem *,
56 QWidget * = nullptr) override;
57 int type() const override { return Type; }
58 void setItems(const QList<QGraphicsItem *> &);
59 void setItems(const QList<CustomElementPart *> &);
60 QList<CustomElementPart *> items() const;
61 QList<QGraphicsItem *> graphicsItems() const;
62
63 public slots:
64 void adjust();
65
66 signals:
68
69 protected:
70 void mousePressEvent(QGraphicsSceneMouseEvent *) override;
71 void mouseMoveEvent(QGraphicsSceneMouseEvent *) override;
72 void mouseReleaseEvent(QGraphicsSceneMouseEvent *) override;
73 void keyPressEvent(QKeyEvent *) override;
74 void keyReleaseEvent(QKeyEvent *) override;
75 QPointF deltaForRoundScaling(const QRectF &, const QRectF &, qreal);
76 QPointF snapConstPointToGrid(const QPointF &) const;
77 void snapPointToGrid(QPointF &) const;
78 bool mustSnapToGrid(QGraphicsSceneMouseEvent *);
79 QET::ScalingMethod scalingMethod(QGraphicsSceneMouseEvent *);
80 QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
81 bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) override;
82
83 private:
84 void init();
87 void startMovement();
88 void applyMovementToRect(int, const QPointF &, QRectF &);
90 void translateItems(const QPointF &);
91 void scaleItems(const QRectF &, const QRectF &);
92 QRectF getSceneBoundingRect(QGraphicsItem *) const;
93 QVector <QPointF> getResizingsPoints() const;
94
95
96 private:
97 void adjusteHandlerPos();
98 void handlerMousePressEvent (QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event);
99 void handlerMouseMoveEvent (QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event);
100 void handlerMouseReleaseEvent (QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event);
101
102 void addHandler();
103 void removeHandler();
104
105
106
107
108 QList<CustomElementPart *> decorated_items_;
112
120 QPointF first_pos_;
121 QPointF latest_pos_;
125 QVector<QetGraphicsHandlerItem *> m_handler_vector;
127};
128
129#endif
The CustomElementPart class This abstract class represents a primitive of the visual representation o...
Definition customelementpart.h:40
The ElementEditionCommand class ElementEditionCommand is the base class for all commands classes invo...
Definition editorcommands.h:47
Definition elementprimitivedecorator.h:42
void setItems(const QList< QGraphicsItem * > &)
Definition elementprimitivedecorator.cpp:129
QList< CustomElementPart * > decorated_items_
Definition elementprimitivedecorator.h:108
void applyMovementToRect(int, const QPointF &, QRectF &)
Definition elementprimitivedecorator.cpp:377
void adjusteHandlerPos()
ElementPrimitiveDecorator::adjusteHandlerPos.
Definition elementprimitivedecorator.cpp:497
void keyPressEvent(QKeyEvent *) override
ElementPrimitiveDecorator::keyPressEvent.
Definition elementprimitivedecorator.cpp:262
bool mustSnapToGrid(QGraphicsSceneMouseEvent *)
Definition elementprimitivedecorator.cpp:692
void saveOriginalBoundingRect()
Definition elementprimitivedecorator.cpp:345
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override
ElementPrimitiveDecorator::itemChange.
Definition elementprimitivedecorator.cpp:718
QPointF first_pos_
First point involved within the current resizing operation.
Definition elementprimitivedecorator.h:120
QPointF deltaForRoundScaling(const QRectF &, const QRectF &, qreal)
Definition elementprimitivedecorator.cpp:650
void handlerMousePressEvent(QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event)
ElementPrimitiveDecorator::handlerMousePressEvent.
Definition elementprimitivedecorator.cpp:509
QVector< QPointF > getResizingsPoints() const
Definition elementprimitivedecorator.cpp:468
void adjustEffectiveBoundingRect()
Definition elementprimitivedecorator.cpp:354
int grid_step_x_
Grid horizontal step.
Definition elementprimitivedecorator.h:118
void init()
Definition elementprimitivedecorator.cpp:335
void startMovement()
Definition elementprimitivedecorator.cpp:365
QRectF modified_bounding_rect_
new bounding rect, after the user moved or resized items
Definition elementprimitivedecorator.h:111
QRectF boundingRect() const override
Definition elementprimitivedecorator.cpp:73
QRectF effective_bounding_rect_
actual, effective bounding rect – never shrinks
Definition elementprimitivedecorator.h:109
~ElementPrimitiveDecorator() override
Definition elementprimitivedecorator.cpp:44
QET::ScalingMethod scalingMethod(QGraphicsSceneMouseEvent *)
Definition elementprimitivedecorator.cpp:702
void handlerMouseMoveEvent(QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event)
ElementPrimitiveDecorator::handlerMouseMoveEvent.
Definition elementprimitivedecorator.cpp:526
void snapPointToGrid(QPointF &) const
Definition elementprimitivedecorator.cpp:682
QPointF keys_movement_
Movement applied to our decorated items using the arrow keys.
Definition elementprimitivedecorator.h:124
int current_operation_square_
Definition elementprimitivedecorator.h:117
QPointF mouse_offset_
Offset between the mouse position and the point to be snapped to grid when moving selection.
Definition elementprimitivedecorator.h:122
void adjust()
Definition elementprimitivedecorator.cpp:168
QList< QGraphicsItem * > graphicsItems() const
Definition elementprimitivedecorator.cpp:153
void addHandler()
ElementPrimitiveDecorator::addHandler Add handlers for this item.
Definition elementprimitivedecorator.cpp:611
CustomElementPart * singleItem() const
Definition elementprimitivedecorator.cpp:420
bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) override
ElementPrimitiveDecorator::sceneEventFilter.
Definition elementprimitivedecorator.cpp:748
void keyReleaseEvent(QKeyEvent *) override
ElementPrimitiveDecorator::keyReleaseEvent.
Definition elementprimitivedecorator.cpp:315
int grid_step_y_
Grid horizontal step.
Definition elementprimitivedecorator.h:119
void actionFinished(ElementEditionCommand *)
void mouseMoveEvent(QGraphicsSceneMouseEvent *) override
Definition elementprimitivedecorator.cpp:200
QRectF original_bounding_rect_
original bounding rect
Definition elementprimitivedecorator.h:110
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *=nullptr) override
ElementPrimitiveDecorator::paint Paint the contents of an item in local coordinates,...
Definition elementprimitivedecorator.cpp:91
bool moving_by_keys_
Whether we are currently moving our decorated items using the arrow keys.
Definition elementprimitivedecorator.h:123
void mousePressEvent(QGraphicsSceneMouseEvent *) override
Definition elementprimitivedecorator.cpp:179
QRectF internalBoundingRect() const
Definition elementprimitivedecorator.cpp:53
int m_vector_index
Definition elementprimitivedecorator.h:126
QList< CustomElementPart * > items() const
Definition elementprimitivedecorator.cpp:145
QPointF latest_pos_
Latest point involved within the current resizing operation.
Definition elementprimitivedecorator.h:121
void scaleItems(const QRectF &, const QRectF &)
Definition elementprimitivedecorator.cpp:446
@ Type
Definition elementprimitivedecorator.h:49
void handlerMouseReleaseEvent(QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event)
ElementPrimitiveDecorator::handlerMouseReleaseEvent.
Definition elementprimitivedecorator.cpp:581
QPointF snapConstPointToGrid(const QPointF &) const
Definition elementprimitivedecorator.cpp:668
QVector< QetGraphicsHandlerItem * > m_handler_vector
Definition elementprimitivedecorator.h:125
QRectF getSceneBoundingRect(QGraphicsItem *) const
Definition elementprimitivedecorator.cpp:462
void translateItems(const QPointF &)
Definition elementprimitivedecorator.cpp:431
int type() const override
Definition elementprimitivedecorator.h:57
void mouseReleaseEvent(QGraphicsSceneMouseEvent *) override
Definition elementprimitivedecorator.cpp:232
void removeHandler()
ElementPrimitiveDecorator::removeHandler Remove the handlers of this item.
Definition elementprimitivedecorator.cpp:631
The ElementScene class This class is the canvas allowing the visual edition of an electrical element....
Definition elementscene.h:46
The QetGraphicsHandlerItem class This graphics item represents a point, destined to be used as an han...
Definition qetgraphicshandleritem.h:37
ScalingMethod
Supported types of interactive scaling, typically for a single element primitive.
Definition qet.h:77