QElectroTech
0.70
|
#include <elementprimitivedecorator.h>
Public Types | |
enum | { Type = UserType + 2200 } |
Public Slots | |
void | adjust () |
Signals | |
void | actionFinished (ElementEditionCommand *) |
Public Member Functions | |
ElementPrimitiveDecorator (QGraphicsItem *=nullptr) | |
~ElementPrimitiveDecorator () override | |
QRectF | internalBoundingRect () const |
QRectF | boundingRect () const override |
void | paint (QPainter *, const QStyleOptionGraphicsItem *, QWidget *=nullptr) override |
int | type () const override |
void | setItems (const QList< QGraphicsItem *> &) |
void | setItems (const QList< CustomElementPart *> &) |
QList< CustomElementPart * > | items () const |
QList< QGraphicsItem * > | graphicsItems () const |
Protected Member Functions | |
void | mousePressEvent (QGraphicsSceneMouseEvent *) override |
void | mouseMoveEvent (QGraphicsSceneMouseEvent *) override |
void | mouseReleaseEvent (QGraphicsSceneMouseEvent *) override |
void | keyPressEvent (QKeyEvent *) override |
void | keyReleaseEvent (QKeyEvent *) override |
QPointF | deltaForRoundScaling (const QRectF &, const QRectF &, qreal) |
QPointF | snapConstPointToGrid (const QPointF &) const |
void | snapPointToGrid (QPointF &) const |
bool | mustSnapToGrid (QGraphicsSceneMouseEvent *) |
QET::ScalingMethod | scalingMethod (QGraphicsSceneMouseEvent *) |
QVariant | itemChange (GraphicsItemChange change, const QVariant &value) override |
ElementPrimitiveDecorator::itemChange. More... | |
bool | sceneEventFilter (QGraphicsItem *watched, QEvent *event) override |
ElementPrimitiveDecorator::sceneEventFilter. More... | |
Private Attributes | |
QList< CustomElementPart * > | decorated_items_ |
QRectF | effective_bounding_rect_ |
actual, effective bounding rect – never shrinks More... | |
QRectF | original_bounding_rect_ |
original bounding rect More... | |
QRectF | modified_bounding_rect_ |
new bounding rect, after the user moved or resized items More... | |
int | current_operation_square_ |
int | grid_step_x_ |
Grid horizontal step. More... | |
int | grid_step_y_ |
Grid horizontal step. More... | |
QPointF | first_pos_ |
First point involved within the current resizing operation. More... | |
QPointF | latest_pos_ |
Latest point involved within the current resizing operation. More... | |
QPointF | mouse_offset_ |
Offset between the mouse position and the point to be snapped to grid when moving selection. More... | |
bool | moving_by_keys_ |
Whether we are currently moving our decorated items using the arrow keys. More... | |
QPointF | keys_movement_ |
Movement applied to our decorated items using the arrow keys. More... | |
QVector< QetGraphicsHandlerItem * > | m_handler_vector |
int | m_vector_index = -1 |
This class represents a decorator rendered above selected items so users can manipulate (move, resize, ...) them.
The implementation considers four kinds of bounding rects:
Definition at line 40 of file elementprimitivedecorator.h.
anonymous enum |
Enumerator | |
---|---|
Type |
Definition at line 48 of file elementprimitivedecorator.h.
ElementPrimitiveDecorator::ElementPrimitiveDecorator | ( | QGraphicsItem * | parent = nullptr | ) |
Constructor
parent | Parent QGraphicsItem |
Definition at line 33 of file elementprimitivedecorator.cpp.
References init().
|
override |
|
signal |
Referenced by handlerMouseReleaseEvent(), keyReleaseEvent(), and mouseReleaseEvent().
|
private |
ElementPrimitiveDecorator::addHandler Add handlers for this item.
Definition at line 580 of file elementprimitivedecorator.cpp.
References getResizingsPoints(), QetGraphicsHandlerItem::handlerForPoint(), and m_handler_vector.
Referenced by itemChange().
|
slot |
Adjust the visual decorator according to the currently assigned items. It is notably called by setItems().
Definition at line 157 of file elementprimitivedecorator.cpp.
References adjustEffectiveBoundingRect(), modified_bounding_rect_, original_bounding_rect_, and saveOriginalBoundingRect().
Referenced by handlerMouseReleaseEvent(), keyPressEvent(), mouseReleaseEvent(), setItems(), and startMovement().
|
private |
Adjust the effective bounding rect. This method should be called after the modified_bouding_rect_ attribute was modified.
Definition at line 327 of file elementprimitivedecorator.cpp.
References adjusteHandlerPos(), effective_bounding_rect_, and modified_bounding_rect_.
Referenced by adjust(), handlerMouseMoveEvent(), and mouseMoveEvent().
|
private |
ElementPrimitiveDecorator::adjusteHandlerPos.
Definition at line 466 of file elementprimitivedecorator.cpp.
References getResizingsPoints(), and m_handler_vector.
Referenced by adjustEffectiveBoundingRect(), and setItems().
|
private |
Apply the movement described by movement_type and movement to rect.
Definition at line 348 of file elementprimitivedecorator.cpp.
References QET::MoveArea, QET::ResizeFromBottomCenterCorner, QET::ResizeFromBottomLeftCorner, QET::ResizeFromBottomRightCorner, QET::ResizeFromMiddleLeftCorner, QET::ResizeFromMiddleRightCorner, QET::ResizeFromTopCenterCorner, QET::ResizeFromTopLeftCorner, and QET::ResizeFromTopRightCorner.
Referenced by handlerMouseMoveEvent(), and mouseMoveEvent().
|
override |
Definition at line 70 of file elementprimitivedecorator.cpp.
References effective_bounding_rect_.
Referenced by getSceneBoundingRect(), handlerMouseReleaseEvent(), and startMovement().
|
protected |
Receive two rects, assuming they share a common corner and current is a scaled version of original. Calculate the scale ratios implied by this assumption, round them to the nearest multiple of epsilon, then return the horizontal and vertical offsets to be applied in order to pass from current to original scaled by the rounded factors. This method can be used to adjust a mouse movement so that it inputs a round scaling operation.
Definition at line 619 of file elementprimitivedecorator.cpp.
References QET::round().
Referenced by handlerMouseMoveEvent().
|
private |
Definition at line 437 of file elementprimitivedecorator.cpp.
References modified_bounding_rect_.
Referenced by addHandler(), adjusteHandlerPos(), handlerMouseMoveEvent(), and handlerMousePressEvent().
|
private |
Definition at line 432 of file elementprimitivedecorator.cpp.
References boundingRect().
Referenced by internalBoundingRect().
QList< QGraphicsItem * > ElementPrimitiveDecorator::graphicsItems | ( | ) | const |
Definition at line 143 of file elementprimitivedecorator.cpp.
References decorated_items_.
Referenced by keyPressEvent(), keyReleaseEvent(), mouseReleaseEvent(), and translateItems().
|
private |
ElementPrimitiveDecorator::handlerMouseMoveEvent.
qghi | |
event |
Definition at line 495 of file elementprimitivedecorator.cpp.
References adjustEffectiveBoundingRect(), applyMovementToRect(), current_operation_square_, deltaForRoundScaling(), first_pos_, QET::FreeScaling, getResizingsPoints(), latest_pos_, modified_bounding_rect_, original_bounding_rect_, scaleItems(), scalingMethod(), snapConstPointToGrid(), and QET::SnapScalingPointToGrid.
Referenced by sceneEventFilter().
|
private |
ElementPrimitiveDecorator::handlerMousePressEvent.
qghi | |
event |
Definition at line 478 of file elementprimitivedecorator.cpp.
References current_operation_square_, first_pos_, getResizingsPoints(), latest_pos_, m_handler_vector, and startMovement().
Referenced by sceneEventFilter().
|
private |
ElementPrimitiveDecorator::handlerMouseReleaseEvent.
qghi | |
event |
Definition at line 550 of file elementprimitivedecorator.cpp.
References actionFinished(), adjust(), boundingRect(), current_operation_square_, items(), modified_bounding_rect_, QET::NoOperation, and original_bounding_rect_.
Referenced by sceneEventFilter().
|
private |
Initialize an ElementPrimitiveDecorator
Definition at line 309 of file elementprimitivedecorator.cpp.
References grid_step_x_, and grid_step_y_.
Referenced by ElementPrimitiveDecorator().
QRectF ElementPrimitiveDecorator::internalBoundingRect | ( | ) | const |
Definition at line 51 of file elementprimitivedecorator.cpp.
References decorated_items_, and getSceneBoundingRect().
Referenced by mousePressEvent(), and saveOriginalBoundingRect().
|
overrideprotected |
ElementPrimitiveDecorator::itemChange.
change | |
value |
Definition at line 685 of file elementprimitivedecorator.cpp.
References addHandler(), m_handler_vector, and removeHandler().
QList< CustomElementPart * > ElementPrimitiveDecorator::items | ( | ) | const |
Definition at line 136 of file elementprimitivedecorator.cpp.
References decorated_items_.
Referenced by handlerMouseReleaseEvent(), and setItems().
|
overrideprotected |
QGraphicsItem::keyPressEvent
Definition at line 249 of file elementprimitivedecorator.cpp.
References adjust(), graphicsItems(), keys_movement_, and moving_by_keys_.
|
overrideprotected |
QGraphicsItem::keyReleaseEvent
Definition at line 289 of file elementprimitivedecorator.cpp.
References actionFinished(), graphicsItems(), keys_movement_, and moving_by_keys_.
|
overrideprotected |
Handle event generated when the mouse is moved and the decorator is the mouse grabber item.
event | Object describing the mouse event |
Definition at line 189 of file elementprimitivedecorator.cpp.
References adjustEffectiveBoundingRect(), applyMovementToRect(), current_operation_square_, decorated_items_, latest_pos_, modified_bounding_rect_, mouse_offset_, QET::MoveArea, snapConstPointToGrid(), and translateItems().
|
overrideprotected |
Handle event generated when mouse buttons are pressed.
event | Object describing the mouse event |
Definition at line 168 of file elementprimitivedecorator.cpp.
References current_operation_square_, decorated_items_, first_pos_, internalBoundingRect(), latest_pos_, mouse_offset_, QET::MoveArea, and startMovement().
|
overrideprotected |
Handle event generated when a mouse buttons are releaseis moved and the decorator is the mouse grabber item.
event | Object describing the mouse event |
Definition at line 221 of file elementprimitivedecorator.cpp.
References actionFinished(), adjust(), current_operation_square_, graphicsItems(), modified_bounding_rect_, QET::MoveArea, QET::NoOperation, and original_bounding_rect_.
|
protected |
Definition at line 659 of file elementprimitivedecorator.cpp.
Referenced by scalingMethod().
|
override |
Paint the contents of an item in local coordinates, using painter, with respect to option and
option | The option parameter provides style options for the item, such as its state, exposed area and its level-of-detail hints. |
The | widget argument is optional. If provided, it points to the widget that is being painted on; otherwise, it is 0. For cached painting, widget is always 0. |
Definition at line 84 of file elementprimitivedecorator.cpp.
References modified_bounding_rect_.
|
private |
ElementPrimitiveDecorator::removeHandler Remove the handlers of this item.
Definition at line 600 of file elementprimitivedecorator.cpp.
References m_handler_vector.
Referenced by itemChange(), and ~ElementPrimitiveDecorator().
|
private |
Save the original bounding rectangle.
Definition at line 319 of file elementprimitivedecorator.cpp.
References internalBoundingRect(), and original_bounding_rect_.
Referenced by adjust().
|
private |
Scale the managed items, provided they originally fit within original_rect and they should now fit new_rect
Definition at line 416 of file elementprimitivedecorator.cpp.
References decorated_items_.
Referenced by handlerMouseMoveEvent().
|
protected |
event | Mouse event during the scale operations – simply passed to mustSnapToGrid() |
Definition at line 669 of file elementprimitivedecorator.cpp.
References QET::FreeScaling, mustSnapToGrid(), QET::RoundScaleRatios, and singleItem().
Referenced by handlerMouseMoveEvent().
|
overrideprotected |
ElementPrimitiveDecorator::sceneEventFilter.
watched | |
event |
Definition at line 715 of file elementprimitivedecorator.cpp.
References handlerMouseMoveEvent(), handlerMousePressEvent(), handlerMouseReleaseEvent(), m_handler_vector, m_vector_index, and QetGraphicsHandlerItem::Type.
void ElementPrimitiveDecorator::setItems | ( | const QList< QGraphicsItem *> & | items | ) |
items | the new list of items this decorator is suposed to manipulate. |
Definition at line 120 of file elementprimitivedecorator.cpp.
References items().
void ElementPrimitiveDecorator::setItems | ( | const QList< CustomElementPart *> & | items | ) |
items | the new list of items this decorator is suposed to manipulate. |
Definition at line 105 of file elementprimitivedecorator.cpp.
References adjust(), adjusteHandlerPos(), decorated_items_, and items().
|
private |
Definition at line 391 of file elementprimitivedecorator.cpp.
References decorated_items_.
Referenced by scalingMethod().
|
protected |
Round the coordinates of point so it is snapped to the grid defined by the grid_step_x_ and grid_step_y_ attributes.
Definition at line 637 of file elementprimitivedecorator.cpp.
References grid_step_x_, and grid_step_y_.
Referenced by handlerMouseMoveEvent(), and mouseMoveEvent().
|
protected |
Round the coordinates of point so it is snapped to the grid defined by the grid_step_x_ and grid_step_y_ attributes.
Definition at line 650 of file elementprimitivedecorator.cpp.
References grid_step_x_, and grid_step_y_.
|
private |
Start a movement (i.e. either a move or scaling operation)
Definition at line 337 of file elementprimitivedecorator.cpp.
References adjust(), boundingRect(), decorated_items_, and original_bounding_rect_.
Referenced by handlerMousePressEvent(), and mousePressEvent().
|
private |
Translated the managed items by the movement
Definition at line 401 of file elementprimitivedecorator.cpp.
References decorated_items_, and graphicsItems().
Referenced by mouseMoveEvent().
|
inlineoverride |
Definition at line 54 of file elementprimitivedecorator.h.
References Type.
|
private |
Index of the square leading the current operation (resizing, etc.) or -1 if no operation is occurring, -2 for a move operation.
Definition at line 114 of file elementprimitivedecorator.h.
Referenced by handlerMouseMoveEvent(), handlerMousePressEvent(), handlerMouseReleaseEvent(), mouseMoveEvent(), mousePressEvent(), and mouseReleaseEvent().
|
private |
Definition at line 105 of file elementprimitivedecorator.h.
Referenced by graphicsItems(), internalBoundingRect(), items(), mouseMoveEvent(), mousePressEvent(), scaleItems(), setItems(), singleItem(), startMovement(), and translateItems().
|
private |
actual, effective bounding rect – never shrinks
Definition at line 106 of file elementprimitivedecorator.h.
Referenced by adjustEffectiveBoundingRect(), and boundingRect().
|
private |
First point involved within the current resizing operation.
Definition at line 117 of file elementprimitivedecorator.h.
Referenced by handlerMouseMoveEvent(), handlerMousePressEvent(), and mousePressEvent().
|
private |
Grid horizontal step.
Definition at line 115 of file elementprimitivedecorator.h.
Referenced by init(), snapConstPointToGrid(), and snapPointToGrid().
|
private |
Grid horizontal step.
Definition at line 116 of file elementprimitivedecorator.h.
Referenced by init(), snapConstPointToGrid(), and snapPointToGrid().
|
private |
Movement applied to our decorated items using the arrow keys.
Definition at line 121 of file elementprimitivedecorator.h.
Referenced by keyPressEvent(), and keyReleaseEvent().
|
private |
Latest point involved within the current resizing operation.
Definition at line 118 of file elementprimitivedecorator.h.
Referenced by handlerMouseMoveEvent(), handlerMousePressEvent(), mouseMoveEvent(), and mousePressEvent().
|
private |
Definition at line 122 of file elementprimitivedecorator.h.
Referenced by addHandler(), adjusteHandlerPos(), handlerMousePressEvent(), itemChange(), removeHandler(), and sceneEventFilter().
|
private |
Definition at line 123 of file elementprimitivedecorator.h.
Referenced by sceneEventFilter().
|
private |
new bounding rect, after the user moved or resized items
Definition at line 108 of file elementprimitivedecorator.h.
Referenced by adjust(), adjustEffectiveBoundingRect(), getResizingsPoints(), handlerMouseMoveEvent(), handlerMouseReleaseEvent(), mouseMoveEvent(), mouseReleaseEvent(), and paint().
|
private |
Offset between the mouse position and the point to be snapped to grid when moving selection.
Definition at line 119 of file elementprimitivedecorator.h.
Referenced by mouseMoveEvent(), and mousePressEvent().
|
private |
Whether we are currently moving our decorated items using the arrow keys.
Definition at line 120 of file elementprimitivedecorator.h.
Referenced by keyPressEvent(), and keyReleaseEvent().
|
private |
original bounding rect
Definition at line 107 of file elementprimitivedecorator.h.
Referenced by adjust(), handlerMouseMoveEvent(), handlerMouseReleaseEvent(), mouseReleaseEvent(), saveOriginalBoundingRect(), and startMovement().