QElectroTech  0.8-dev
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>

Inherits QGraphicsObject.

Collaboration diagram for ElementPrimitiveDecorator:
Collaboration graph

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
 ElementPrimitiveDecorator::paint Paint the contents of an item in local coordinates, using painter, with respect to option and. More...
 
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
 ElementPrimitiveDecorator::keyPressEvent. More...
 
void keyReleaseEvent (QKeyEvent *) override
 ElementPrimitiveDecorator::keyReleaseEvent. More...
 
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:

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
Type 

Constructor & Destructor Documentation

◆ ElementPrimitiveDecorator()

ElementPrimitiveDecorator::ElementPrimitiveDecorator ( QGraphicsItem *  parent = nullptr)

Constructor

Parameters
parentParent QGraphicsItem
Here is the call graph for this function:

◆ ~ElementPrimitiveDecorator()

ElementPrimitiveDecorator::~ElementPrimitiveDecorator ( )
override

Destructor

Here is the call graph for this function:

Member Function Documentation

◆ actionFinished

void ElementPrimitiveDecorator::actionFinished ( ElementEditionCommand )
signal
Here is the caller graph for this function:

◆ addHandler()

void ElementPrimitiveDecorator::addHandler ( )
private

ElementPrimitiveDecorator::addHandler Add handlers for this item.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ adjust

void ElementPrimitiveDecorator::adjust ( )
slot

Adjust the visual decorator according to the currently assigned items. It is notably called by setItems().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ adjustEffectiveBoundingRect()

void ElementPrimitiveDecorator::adjustEffectiveBoundingRect ( )
private

Adjust the effective bounding rect. This method should be called after the modified_bouding_rect_ attribute was modified.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ adjusteHandlerPos()

void ElementPrimitiveDecorator::adjusteHandlerPos ( )
private

ElementPrimitiveDecorator::adjusteHandlerPos.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ applyMovementToRect()

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

Apply the movement described by movement_type and movement to rect.

Here is the caller graph for this function:

◆ boundingRect()

QRectF ElementPrimitiveDecorator::boundingRect ( ) const
override
Returns
the outer bounds of the decorator as a rectangle.
Here is the caller graph for this function:

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getResizingsPoints()

QVector< QPointF > ElementPrimitiveDecorator::getResizingsPoints ( ) const
private
Here is the caller graph for this function:

◆ getSceneBoundingRect()

QRectF ElementPrimitiveDecorator::getSceneBoundingRect ( QGraphicsItem *  item) const
private
Returns
the bounding rectangle of item, in scene coordinates
Here is the call graph for this function:
Here is the caller graph for this function:

◆ graphicsItems()

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

◆ handlerMouseMoveEvent()

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

ElementPrimitiveDecorator::handlerMouseMoveEvent.

Parameters
qghi
event
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handlerMousePressEvent()

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

ElementPrimitiveDecorator::handlerMousePressEvent.

Parameters
qghi
event
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handlerMouseReleaseEvent()

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

ElementPrimitiveDecorator::handlerMouseReleaseEvent.

Parameters
qghi
event
Here is the call graph for this function:
Here is the caller graph for this function:

◆ init()

void ElementPrimitiveDecorator::init ( )
private

Initialize an ElementPrimitiveDecorator

Here is the caller graph for this function:

◆ internalBoundingRect()

QRectF ElementPrimitiveDecorator::internalBoundingRect ( ) const
Returns
the internal bouding rect, i.e. the smallest rectangle containing the bounding rectangle of every selected item.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ itemChange()

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

ElementPrimitiveDecorator::itemChange.

Parameters
change
value
Returns
Here is the call graph for this function:

◆ items()

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

◆ keyPressEvent()

void ElementPrimitiveDecorator::keyPressEvent ( QKeyEvent *  e)
overrideprotected

ElementPrimitiveDecorator::keyPressEvent.

Parameters
e
See also
QGraphicsItem::keyPressEvent
Here is the call graph for this function:

◆ keyReleaseEvent()

void ElementPrimitiveDecorator::keyReleaseEvent ( QKeyEvent *  e)
overrideprotected

ElementPrimitiveDecorator::keyReleaseEvent.

Parameters
e
See also
QGraphicsItem::keyReleaseEvent
Here is the call graph for this function:

◆ 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()
Here is the call graph for this function:

◆ mousePressEvent()

void ElementPrimitiveDecorator::mousePressEvent ( QGraphicsSceneMouseEvent *  event)
overrideprotected

Handle event generated when mouse buttons are pressed.

Parameters
eventObject describing the mouse event
Here is the call graph for this function:

◆ 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()
Here is the call graph for this function:

◆ 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
Here is the caller graph for this function:

◆ paint()

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

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

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

◆ removeHandler()

void ElementPrimitiveDecorator::removeHandler ( )
private

ElementPrimitiveDecorator::removeHandler Remove the handlers of this item.

Here is the caller graph for this function:

◆ saveOriginalBoundingRect()

void ElementPrimitiveDecorator::saveOriginalBoundingRect ( )
private

Save the original bounding rectangle.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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

Here is the caller graph for this function:

◆ 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()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sceneEventFilter()

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

ElementPrimitiveDecorator::sceneEventFilter.

Parameters
watched
event
Returns
Here is the call graph for this function:

◆ setItems() [1/2]

void ElementPrimitiveDecorator::setItems ( const QList< CustomElementPart * > &  items)
Parameters
itemsthe new list of items this decorator is suposed to manipulate.
Here is the call graph for this function:

◆ setItems() [2/2]

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

◆ singleItem()

CustomElementPart * ElementPrimitiveDecorator::singleItem ( ) const
private
Here is the caller graph for this function:

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

Here is the caller graph for this function:

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

◆ startMovement()

void ElementPrimitiveDecorator::startMovement ( )
private

Start a movement (i.e. either a move or scaling operation)

Here is the call graph for this function:
Here is the caller graph for this function:

◆ translateItems()

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

Translated the managed items by the movement

Here is the call graph for this function:
Here is the caller graph for this function:

◆ type()

int ElementPrimitiveDecorator::type ( ) const
inlineoverride

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.

◆ decorated_items_

QList<CustomElementPart *> ElementPrimitiveDecorator::decorated_items_
private

◆ effective_bounding_rect_

QRectF ElementPrimitiveDecorator::effective_bounding_rect_
private

actual, effective bounding rect – never shrinks

◆ first_pos_

QPointF ElementPrimitiveDecorator::first_pos_
private

First point involved within the current resizing operation.

◆ grid_step_x_

int ElementPrimitiveDecorator::grid_step_x_
private

Grid horizontal step.

◆ grid_step_y_

int ElementPrimitiveDecorator::grid_step_y_
private

Grid horizontal step.

◆ keys_movement_

QPointF ElementPrimitiveDecorator::keys_movement_
private

Movement applied to our decorated items using the arrow keys.

◆ latest_pos_

QPointF ElementPrimitiveDecorator::latest_pos_
private

Latest point involved within the current resizing operation.

◆ m_handler_vector

QVector<QetGraphicsHandlerItem *> ElementPrimitiveDecorator::m_handler_vector
private

◆ m_vector_index

int ElementPrimitiveDecorator::m_vector_index = -1
private

◆ modified_bounding_rect_

QRectF ElementPrimitiveDecorator::modified_bounding_rect_
private

new bounding rect, after the user moved or resized items

◆ mouse_offset_

QPointF ElementPrimitiveDecorator::mouse_offset_
private

Offset between the mouse position and the point to be snapped to grid when moving selection.

◆ moving_by_keys_

bool ElementPrimitiveDecorator::moving_by_keys_
private

Whether we are currently moving our decorated items using the arrow keys.

◆ original_bounding_rect_

QRectF ElementPrimitiveDecorator::original_bounding_rect_
private

original bounding rect


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