QElectroTech  0.70
Public Types | Public Slots | Signals | Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
ElementPrimitiveDecorator Class Reference

#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 Member Functions

void init ()
 
void saveOriginalBoundingRect ()
 
void adjustEffectiveBoundingRect ()
 
void startMovement ()
 
void applyMovementToRect (int, const QPointF &, QRectF &)
 
CustomElementPartsingleItem () const
 
void translateItems (const QPointF &)
 
void scaleItems (const QRectF &, const QRectF &)
 
QRectF getSceneBoundingRect (QGraphicsItem *) const
 
QVector< QPointF > getResizingsPoints () const
 
void adjusteHandlerPos ()
 ElementPrimitiveDecorator::adjusteHandlerPos. More...
 
void handlerMousePressEvent (QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event)
 ElementPrimitiveDecorator::handlerMousePressEvent. More...
 
void handlerMouseMoveEvent (QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event)
 ElementPrimitiveDecorator::handlerMouseMoveEvent. More...
 
void handlerMouseReleaseEvent (QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event)
 ElementPrimitiveDecorator::handlerMouseReleaseEvent. More...
 
void addHandler ()
 ElementPrimitiveDecorator::addHandler Add handlers for this item. More...
 
void removeHandler ()
 ElementPrimitiveDecorator::removeHandler Remove the handlers of this item. 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
 

Detailed Description

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.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
Type 

Definition at line 48 of file elementprimitivedecorator.h.

Constructor & Destructor Documentation

◆ ElementPrimitiveDecorator()

ElementPrimitiveDecorator::ElementPrimitiveDecorator ( QGraphicsItem *  parent = nullptr)

Constructor

Parameters
parentParent QGraphicsItem

Definition at line 33 of file elementprimitivedecorator.cpp.

References init().

◆ ~ElementPrimitiveDecorator()

ElementPrimitiveDecorator::~ElementPrimitiveDecorator ( )
override

Destructor

Definition at line 42 of file elementprimitivedecorator.cpp.

References removeHandler().

Member Function Documentation

◆ actionFinished

void ElementPrimitiveDecorator::actionFinished ( ElementEditionCommand )
signal

◆ addHandler()

void ElementPrimitiveDecorator::addHandler ( )
private

◆ adjust

void ElementPrimitiveDecorator::adjust ( )
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().

◆ adjustEffectiveBoundingRect()

void ElementPrimitiveDecorator::adjustEffectiveBoundingRect ( )
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().

◆ adjusteHandlerPos()

void ElementPrimitiveDecorator::adjusteHandlerPos ( )
private

◆ applyMovementToRect()

void ElementPrimitiveDecorator::applyMovementToRect ( int  movement_type,
const QPointF &  movement,
QRectF &  rect 
)
private

◆ boundingRect()

QRectF ElementPrimitiveDecorator::boundingRect ( ) const
override
Returns
the outer bounds of the decorator as a rectangle.

Definition at line 70 of file elementprimitivedecorator.cpp.

References effective_bounding_rect_.

Referenced by getSceneBoundingRect(), handlerMouseReleaseEvent(), and startMovement().

◆ deltaForRoundScaling()

QPointF ElementPrimitiveDecorator::deltaForRoundScaling ( const QRectF &  original,
const QRectF &  current,
qreal  epsilon 
)
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().

◆ getResizingsPoints()

QVector< QPointF > ElementPrimitiveDecorator::getResizingsPoints ( ) const
private

◆ getSceneBoundingRect()

QRectF ElementPrimitiveDecorator::getSceneBoundingRect ( QGraphicsItem *  item) const
private
Returns
the bounding rectangle of item, in scene coordinates

Definition at line 432 of file elementprimitivedecorator.cpp.

References boundingRect().

Referenced by internalBoundingRect().

◆ graphicsItems()

QList< QGraphicsItem * > ElementPrimitiveDecorator::graphicsItems ( ) const
Returns
the list of items this decorator is supposed to manipulate

Definition at line 143 of file elementprimitivedecorator.cpp.

References decorated_items_.

Referenced by keyPressEvent(), keyReleaseEvent(), mouseReleaseEvent(), and translateItems().

◆ handlerMouseMoveEvent()

void ElementPrimitiveDecorator::handlerMouseMoveEvent ( QetGraphicsHandlerItem qghi,
QGraphicsSceneMouseEvent *  event 
)
private

◆ handlerMousePressEvent()

void ElementPrimitiveDecorator::handlerMousePressEvent ( QetGraphicsHandlerItem qghi,
QGraphicsSceneMouseEvent *  event 
)
private

◆ handlerMouseReleaseEvent()

void ElementPrimitiveDecorator::handlerMouseReleaseEvent ( QetGraphicsHandlerItem qghi,
QGraphicsSceneMouseEvent *  event 
)
private

◆ init()

void ElementPrimitiveDecorator::init ( )
private

Initialize an ElementPrimitiveDecorator

Definition at line 309 of file elementprimitivedecorator.cpp.

References grid_step_x_, and grid_step_y_.

Referenced by ElementPrimitiveDecorator().

◆ internalBoundingRect()

QRectF ElementPrimitiveDecorator::internalBoundingRect ( ) const
Returns
the internal bouding rect, i.e. the smallest rectangle containing the bounding rectangle of every selected item.

Definition at line 51 of file elementprimitivedecorator.cpp.

References decorated_items_, and getSceneBoundingRect().

Referenced by mousePressEvent(), and saveOriginalBoundingRect().

◆ itemChange()

QVariant ElementPrimitiveDecorator::itemChange ( GraphicsItemChange  change,
const QVariant &  value 
)
overrideprotected

ElementPrimitiveDecorator::itemChange.

Parameters
change
value
Returns

Definition at line 685 of file elementprimitivedecorator.cpp.

References addHandler(), m_handler_vector, and removeHandler().

◆ items()

QList< CustomElementPart * > ElementPrimitiveDecorator::items ( ) const
Returns
the list of items this decorator is supposed to manipulate

Definition at line 136 of file elementprimitivedecorator.cpp.

References decorated_items_.

Referenced by handlerMouseReleaseEvent(), and setItems().

◆ keyPressEvent()

void ElementPrimitiveDecorator::keyPressEvent ( QKeyEvent *  e)
overrideprotected

QGraphicsItem::keyPressEvent

Definition at line 249 of file elementprimitivedecorator.cpp.

References adjust(), graphicsItems(), keys_movement_, and moving_by_keys_.

◆ keyReleaseEvent()

void ElementPrimitiveDecorator::keyReleaseEvent ( QKeyEvent *  e)
overrideprotected

QGraphicsItem::keyReleaseEvent

Definition at line 289 of file elementprimitivedecorator.cpp.

References actionFinished(), graphicsItems(), keys_movement_, and moving_by_keys_.

◆ mouseMoveEvent()

void ElementPrimitiveDecorator::mouseMoveEvent ( QGraphicsSceneMouseEvent *  event)
overrideprotected

Handle event generated when the mouse is moved and the decorator is the mouse grabber item.

Parameters
eventObject describing the mouse event
See also
QGraphicsScene::mouseGrabberItem()

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().

◆ mousePressEvent()

void ElementPrimitiveDecorator::mousePressEvent ( QGraphicsSceneMouseEvent *  event)
overrideprotected

Handle event generated when mouse buttons are pressed.

Parameters
eventObject 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().

◆ mouseReleaseEvent()

void ElementPrimitiveDecorator::mouseReleaseEvent ( QGraphicsSceneMouseEvent *  event)
overrideprotected

Handle event generated when a mouse buttons are releaseis moved and the decorator is the mouse grabber item.

Parameters
eventObject describing the mouse event
See also
QGraphicsScene::mouseGrabberItem()

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_.

◆ mustSnapToGrid()

bool ElementPrimitiveDecorator::mustSnapToGrid ( QGraphicsSceneMouseEvent *  event)
protected
Returns
whether the current operation should take the grid into account according to the state of the provided event

Definition at line 659 of file elementprimitivedecorator.cpp.

Referenced by scalingMethod().

◆ paint()

void ElementPrimitiveDecorator::paint ( QPainter *  painter,
const QStyleOptionGraphicsItem *  option,
QWidget *  widget = nullptr 
)
override

Paint the contents of an item in local coordinates, using painter, with respect to option and

Parameters
optionThe option parameter provides style options for the item, such as its state, exposed area and its level-of-detail hints.
Thewidget 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_.

◆ removeHandler()

void ElementPrimitiveDecorator::removeHandler ( )
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().

◆ saveOriginalBoundingRect()

void ElementPrimitiveDecorator::saveOriginalBoundingRect ( )
private

Save the original bounding rectangle.

Definition at line 319 of file elementprimitivedecorator.cpp.

References internalBoundingRect(), and original_bounding_rect_.

Referenced by adjust().

◆ scaleItems()

void ElementPrimitiveDecorator::scaleItems ( const QRectF &  original_rect,
const QRectF &  new_rect 
)
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().

◆ scalingMethod()

QET::ScalingMethod ElementPrimitiveDecorator::scalingMethod ( QGraphicsSceneMouseEvent *  event)
protected
Parameters
eventMouse event during the scale operations – simply passed to mustSnapToGrid()
Returns
the scaling method to be used for the currently decorated items.
See also
QET::ScalingMethod
mustSnapToGrid()

Definition at line 669 of file elementprimitivedecorator.cpp.

References QET::FreeScaling, mustSnapToGrid(), QET::RoundScaleRatios, and singleItem().

Referenced by handlerMouseMoveEvent().

◆ sceneEventFilter()

bool ElementPrimitiveDecorator::sceneEventFilter ( QGraphicsItem *  watched,
QEvent *  event 
)
overrideprotected

◆ setItems() [1/2]

void ElementPrimitiveDecorator::setItems ( const QList< QGraphicsItem *> &  items)
Parameters
itemsthe new list of items this decorator is suposed to manipulate.

Definition at line 120 of file elementprimitivedecorator.cpp.

References items().

◆ setItems() [2/2]

void ElementPrimitiveDecorator::setItems ( const QList< CustomElementPart *> &  items)
Parameters
itemsthe 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().

◆ singleItem()

CustomElementPart * ElementPrimitiveDecorator::singleItem ( ) const
private

Definition at line 391 of file elementprimitivedecorator.cpp.

References decorated_items_.

Referenced by scalingMethod().

◆ snapConstPointToGrid()

QPointF ElementPrimitiveDecorator::snapConstPointToGrid ( const QPointF &  point) const
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().

◆ snapPointToGrid()

void ElementPrimitiveDecorator::snapPointToGrid ( QPointF &  point) const
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_.

◆ startMovement()

void ElementPrimitiveDecorator::startMovement ( )
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().

◆ translateItems()

void ElementPrimitiveDecorator::translateItems ( const QPointF &  movement)
private

Translated the managed items by the movement

Definition at line 401 of file elementprimitivedecorator.cpp.

References decorated_items_, and graphicsItems().

Referenced by mouseMoveEvent().

◆ type()

int ElementPrimitiveDecorator::type ( ) const
inlineoverride

Definition at line 54 of file elementprimitivedecorator.h.

References Type.

Member Data Documentation

◆ current_operation_square_

int ElementPrimitiveDecorator::current_operation_square_
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().

◆ decorated_items_

QList<CustomElementPart *> ElementPrimitiveDecorator::decorated_items_
private

◆ effective_bounding_rect_

QRectF ElementPrimitiveDecorator::effective_bounding_rect_
private

actual, effective bounding rect – never shrinks

Definition at line 106 of file elementprimitivedecorator.h.

Referenced by adjustEffectiveBoundingRect(), and boundingRect().

◆ first_pos_

QPointF ElementPrimitiveDecorator::first_pos_
private

First point involved within the current resizing operation.

Definition at line 117 of file elementprimitivedecorator.h.

Referenced by handlerMouseMoveEvent(), handlerMousePressEvent(), and mousePressEvent().

◆ grid_step_x_

int ElementPrimitiveDecorator::grid_step_x_
private

Grid horizontal step.

Definition at line 115 of file elementprimitivedecorator.h.

Referenced by init(), snapConstPointToGrid(), and snapPointToGrid().

◆ grid_step_y_

int ElementPrimitiveDecorator::grid_step_y_
private

Grid horizontal step.

Definition at line 116 of file elementprimitivedecorator.h.

Referenced by init(), snapConstPointToGrid(), and snapPointToGrid().

◆ keys_movement_

QPointF ElementPrimitiveDecorator::keys_movement_
private

Movement applied to our decorated items using the arrow keys.

Definition at line 121 of file elementprimitivedecorator.h.

Referenced by keyPressEvent(), and keyReleaseEvent().

◆ latest_pos_

QPointF ElementPrimitiveDecorator::latest_pos_
private

Latest point involved within the current resizing operation.

Definition at line 118 of file elementprimitivedecorator.h.

Referenced by handlerMouseMoveEvent(), handlerMousePressEvent(), mouseMoveEvent(), and mousePressEvent().

◆ m_handler_vector

QVector<QetGraphicsHandlerItem *> ElementPrimitiveDecorator::m_handler_vector
private

◆ m_vector_index

int ElementPrimitiveDecorator::m_vector_index = -1
private

Definition at line 123 of file elementprimitivedecorator.h.

Referenced by sceneEventFilter().

◆ modified_bounding_rect_

QRectF ElementPrimitiveDecorator::modified_bounding_rect_
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().

◆ mouse_offset_

QPointF ElementPrimitiveDecorator::mouse_offset_
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().

◆ moving_by_keys_

bool ElementPrimitiveDecorator::moving_by_keys_
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().

◆ original_bounding_rect_

QRectF ElementPrimitiveDecorator::original_bounding_rect_
private

The documentation for this class was generated from the following files: