SelectionMoveResizer Class Reference

Handler for modifying one or more QWidget and/or QwtPlotMarker with mouse or keyboard. More...

`#include <SelectionMoveResizer.h>`

Inheritance diagram for SelectionMoveResizer:

## Public Slots

void | add (ArrowMarker *target)
| Add target to the list of items to be moved/resized together. More...
void | add (QWidget *target)
| Add target to the list of items to be moved/resized together. More...
void | recalcBoundingRect ()
| Calculate d_bounding_rect based on the bounding rectangles of all targets. More...
int | removeAll (ArrowMarker *target)
| Remove target from the list of items to be moved/resized together and returns the number of occurences removed. More...
int | removeAll (QWidget *target)
| Remove target from the list of items to be moved/resized together and returns the number of occurences removed. More...

## Signals

void | targetsChanged ()
| Emitted when the targets are modified (moved or resized). More...

## Public Member Functions

void | alignTargetsBottom ()
void | alignTargetsLeft ()
void | alignTargetsRight ()
void | alignTargetsTop ()
bool | contains (QWidget *w) const
| Returns true if w is one of targets, false else. More...
bool | contains (ArrowMarker *m) const
| Returns true if m is one of targets, false else. More...
virtual bool | eventFilter (QObject *o, QEvent *e)
| React on geometry changes of parent and targets. More...
void | raiseTargets (bool on=true)
| SelectionMoveResizer (ArrowMarker *target)
| Construct a new MoveResizer with the given marker as the only target. More...
| SelectionMoveResizer (QWidget *target)
| Construct a new MoveResizer with the given widget as the only target. More...
QList< QWidget * > | widgetsList () const
| ~SelectionMoveResizer ()
| Clean up after myself. More...

## Protected Types

enum | Operation { None =-2, Move, Resize_N, Resize_NE, Resize_E, Resize_SE, Resize_S, Resize_SW, Resize_W, Resize_NW }
| Available modes of operation. More...

## Protected Member Functions

virtual void | keyPressEvent (QKeyEvent *e)
| Allow keyboard-based moving of the selection. More...
virtual void | mouseDoubleClickEvent (QMouseEvent *e)
| Ignore double-clicks so that they can be used by my parent. More...
virtual void | mouseMoveEvent (QMouseEvent *e)
| Mouse movements need to be monitored for updating the frame during operation. More...
virtual void | mousePressEvent (QMouseEvent *e)
| Mouse button presses start move/resize operations. More...
virtual void | mouseReleaseEvent (QMouseEvent *e)
| Mouse releases end the current operation and apply it to the targets. More...
virtual void | paintEvent (QPaintEvent *e)
| Draw frame and resize handlers. More...

## Private Slots

void | removeWidget (QObject *w)
| A non-typesafe version of remvoveAll(QWidget*) needed for QObject::destroyed(). More...

## Private Member Functions

QRect | boundingRectOf (QwtPlotMarker *target) const
| Get the bounding rectangle of a marker in paint coordinates. More...
QRect | boundingRectOf (QwtPlotCanvas *canvas) const
| Get the bounding rectangle of a plot canvas area in paint coordinates. More...
void | init ()
| The initialization part common to all constructors. More...
QRect | operateOn (const QRect in)
| Apply operation specified by d_op and d_op_dp to in. More...
void | operateOnTargets ()
| Apply operation specified by d_op and d_op_dp to all targets. More...

## Static Private Member Functions

static const QRect | handlerRect (QRect rect, Operation op)
| Return one of the rectangles to be filled for starting resize operations. More...

## Private Attributes

QRect | d_bounding_rect
| Bounding rectangle of all targets taken together, in drawing coordinates. More...
QList< ArrowMarker * > | d_line_markers
| Target markers I'm handling. More...
Operation | d_op
| The type of operation currently in progress. More...
QPoint | d_op_dp
| Difference between current and start position during operation. More...
QPoint | d_op_start
| Mouse position where an operation started; (-1,-1) means started by keyboard. More...
QList< QWidget * > | d_widgets
| Target widgets I'm handling. More...

## Static Private Attributes

static const int | handler_size = 10
| Size of resize handle in pixels. More...

## Detailed Description

Handler for modifying one or more QWidget and/or QwtPlotMarker with mouse or keyboard.

During initialization, the SelectionMoveResizer adds itself as a new child widget to the target's parentWidget() or QwtPlotCanvas. Because Qt 4.1 and beyond propagate a widget's background by default, frame and resize handlers can then simply be drawn on top of the usual content of the parent. Also, the SelectionMoveResizer gets to see mouse and key events first without the need to filter events for its parent. Note however that the latter must still be done in order to catch geometry changes and stay the same size as the parent.

At every point in time, the list of managed targets must be non-empty, so that the SelectionMoveResizer has a well-defined bounding rectangle. When there are no more selected targets, it deletes itself, so references to a SelectionMoveResizer should be maintained by QPointer and checked for validity before use.

QWidget targets are automatically removed when they are deleted (possibly also deleting the SelectionMoveResizer), using the QObject::destroyed() signal. With QwtPlotMarker, this is not possible since it's not a QObject. Thus, care has to be taken to remove them before or shortly after deletion, lest the wrath of Segmentation Fault shall come upon you.

# Design Ideas

- Keep as much of the select/move/resize code as possible in one class to ease maintanance.
- Use the same class for layer and marker handling to avoid duplicating code. Good for bugfixing and for maintaining a consistent user interface.
- Keep this class generic so that it can later be used for other parents (than MultiLayer's canvas QWidget and Plot's QwtPlotCanvas) and/or targets (e.g. new QwtPlotMarker subclasses) with little to no modifications.
- Differentiate between move/resize, which are generic operations, and editing (like moving the endpoints of a ArrowMarker), which requires detailed knowledge about the target. This way, new types of markers or MultiLayer children support moving/resizing without further work. Editing can then be implemented in the targets themselves, as shown in ArrowMarker.

# Future Plans

See the documentation of ImageMarker for ideas about replacing QwtPlotMarker with a new QwtPlotItem subclass. For SelectionMoveResizer this would mean supporting new enrichments without modifications and being able to automatically remove them upon deletion (if the new class inherits QObject). Not to mention that the implementation would be a lot cleaner if we would only have to handle two target classes instead of four.

Think about turning SelectionMoveResizer into an input method for general affine transformations. Particularly, this would add rotation, flipping and shearing. Markers could implement this using QPainter's coordinate transformations. Definitely not a priority, though.

## Member Enumeration Documentation

## Operation

enum SelectionMoveResizer::Operation

protected

Available modes of operation.

Enumerator
None |
Move |
Resize_N |
Resize_NE |
Resize_E |
Resize_SE |
Resize_S |
Resize_SW |
Resize_W |
Resize_NW |

## Constructor & Destructor Documentation

## SelectionMoveResizer() [1/2]

SelectionMoveResizer::SelectionMoveResizer | ( | ArrowMarker * | target | ) |

Construct a new MoveResizer with the given marker as the only target.

References add(), and init().

## SelectionMoveResizer() [2/2]

SelectionMoveResizer::SelectionMoveResizer | ( | QWidget * | target | ) |

Construct a new MoveResizer with the given widget as the only target.

References add(), and init().

## ~SelectionMoveResizer()

SelectionMoveResizer::~SelectionMoveResizer | ( |  | ) |

Clean up after myself.

References d_widgets.

## Member Function Documentation

## add [1/2]

void SelectionMoveResizer::add | ( | ArrowMarker * | target | ) |

slot

Add target to the list of items to be moved/resized together.

References boundingRectOf(), d_bounding_rect, and d_line_markers.

Referenced by contains(), and SelectionMoveResizer().

## add [2/2]

void SelectionMoveResizer::add | ( | QWidget * | target | ) |

slot

Add target to the list of items to be moved/resized together.

References boundingRectOf(), d_bounding_rect, d_widgets, and removeWidget().

## alignTargetsBottom()

void SelectionMoveResizer::alignTargetsBottom | ( |  | ) |

References d_widgets, FrameWidget::move(), Graph::notifyChanges(), and FrameWidget::plot().

Referenced by contains().

## alignTargetsLeft()

void SelectionMoveResizer::alignTargetsLeft | ( |  | ) |

References d_widgets, FrameWidget::move(), Graph::notifyChanges(), and FrameWidget::plot().

Referenced by contains().

## alignTargetsRight()

void SelectionMoveResizer::alignTargetsRight | ( |  | ) |

References d_widgets, FrameWidget::move(), Graph::notifyChanges(), and FrameWidget::plot().

Referenced by contains().

## alignTargetsTop()

void SelectionMoveResizer::alignTargetsTop | ( |  | ) |

References d_widgets, FrameWidget::move(), Graph::notifyChanges(), and FrameWidget::plot().

Referenced by contains().

## boundingRectOf() [1/2]

QRect SelectionMoveResizer::boundingRectOf | ( | QwtPlotMarker * | target | ) | const

private

Get the bounding rectangle of a marker in paint coordinates.

Referenced by add(), and recalcBoundingRect().

## boundingRectOf() [2/2]

QRect SelectionMoveResizer::boundingRectOf | ( | QwtPlotCanvas * | canvas | ) | const

private

Get the bounding rectangle of a plot canvas area in paint coordinates.

## contains() [1/2]

bool SelectionMoveResizer::contains | ( | QWidget * | w | ) | const

inline

Returns true if w is one of targets, false else.

References d_widgets.

Referenced by mouseMoveEvent(), and mousePressEvent().

## contains() [2/2]

bool SelectionMoveResizer::contains | ( | ArrowMarker * | m | ) | const

inline

Returns true if m is one of targets, false else.

References add(), alignTargetsBottom(), alignTargetsLeft(), alignTargetsRight(), alignTargetsTop(), d_line_markers, raiseTargets(), recalcBoundingRect(), removeAll(), and targetsChanged().

## eventFilter()

bool SelectionMoveResizer::eventFilter | ( | QObject * | o,
|  | QEvent * | e
| ) |  |

virtual

React on geometry changes of parent and targets.

References recalcBoundingRect().

## handlerRect()

const QRect SelectionMoveResizer::handlerRect | ( | QRect | rect,
|  | Operation | op
| ) |  |

static private

Return one of the rectangles to be filled for starting resize operations.

References handler_size, Resize_E, Resize_N, Resize_NE, Resize_NW, Resize_S, Resize_SE, Resize_SW, and Resize_W.

Referenced by mouseMoveEvent(), mousePressEvent(), and paintEvent().

## init()

void SelectionMoveResizer::init | ( |  | ) |

private

The initialization part common to all constructors.

References d_bounding_rect, d_op, d_op_dp, d_op_start, and None.

Referenced by SelectionMoveResizer().

## keyPressEvent()

void SelectionMoveResizer::keyPressEvent | ( | QKeyEvent * | e | ) |

protected virtual

Allow keyboard-based moving of the selection.

Unused keys are passed on to the parent.

References d_op, d_op_dp, d_op_start, d_widgets, FrameWidget::isOnTop(), Move, None, operateOnTargets(), and FrameWidget::showPropertiesDialog().

## mouseDoubleClickEvent()

void SelectionMoveResizer::mouseDoubleClickEvent | ( | QMouseEvent * | e | ) |

protected virtual

Ignore double-clicks so that they can be used by my parent.

References d_widgets, FrameWidget::showPropertiesDialog(), and LegendWidget::showTextEditor().

## mouseMoveEvent()

void SelectionMoveResizer::mouseMoveEvent | ( | QMouseEvent * | e | ) |

protected virtual

Mouse movements need to be monitored for updating the frame during operation.

When no operation is in progress, the mouse cursor is updated based on its position before the event is passed on to the parent.

References contains(), d_bounding_rect, d_op, d_op_dp, d_op_start, handlerRect(), Move, None, Resize_E, Resize_N, Resize_NE, Resize_NW, Resize_S, Resize_SE, Resize_SW, and Resize_W.

## mousePressEvent()

void SelectionMoveResizer::mousePressEvent | ( | QMouseEvent * | e | ) |

protected virtual

Mouse button presses start move/resize operations.

Clicks outside of d_bounding_rect or with anything else than the left button are propagated to the parent as usual.

References contains(), d_bounding_rect, d_op, d_op_start, d_widgets, handlerRect(), Graph::increasingAreaEnrichmentsList(), Move, FrameWidget::plot(), Graph::select(), and FrameWidget::showContextMenu().

## mouseReleaseEvent()

void SelectionMoveResizer::mouseReleaseEvent | ( | QMouseEvent * | e | ) |

protected virtual

Mouse releases end the current operation and apply it to the targets.

When there is no operation in progress, the event is passed on to the parent.

References d_op, d_op_dp, d_op_start, None, and operateOnTargets().

## operateOn()

QRect SelectionMoveResizer::operateOn | ( | const QRect | in | ) |

private

Apply operation specified by d_op and d_op_dp to in.

References d_bounding_rect, d_op, d_op_dp, Move, Resize_E, Resize_N, Resize_NE, Resize_NW, Resize_S, Resize_SE, Resize_SW, and Resize_W.

Referenced by operateOnTargets(), and paintEvent().

## operateOnTargets()

void SelectionMoveResizer::operateOnTargets | ( |  | ) |

private

Apply operation specified by d_op and d_op_dp to all targets.

References d_bounding_rect, d_line_markers, d_op_dp, d_op_start, d_widgets, ArrowMarker::endPoint(), LegendWidget::font(), FrameWidget::move(), Graph::notifyFontChange(), operateOn(), FrameWidget::plot(), recalcBoundingRect(), ArrowMarker::rect(), ArrowMarker::setEndPoint(), LegendWidget::setFont(), ArrowMarker::setStartPoint(), ArrowMarker::startPoint(), targetsChanged(), LegendWidget::text(), and FrameWidget::updateCoordinates().

Referenced by keyPressEvent(), and mouseReleaseEvent().

## paintEvent()

void SelectionMoveResizer::paintEvent | ( | QPaintEvent * | e | ) |

protected virtual

Draw frame and resize handlers.

Besides managing resize operations, this also provides a visual feedback on the selection state.

References d_bounding_rect, handlerRect(), and operateOn().

## raiseTargets()

void SelectionMoveResizer::raiseTargets | ( | bool | on = `true` | ) |

References d_widgets, and FrameWidget::setOnTop().

Referenced by contains().

## recalcBoundingRect

void SelectionMoveResizer::recalcBoundingRect | ( |  | ) |

slot

Calculate d_bounding_rect based on the bounding rectangles of all targets.

References boundingRectOf(), d_bounding_rect, d_line_markers, and d_widgets.

Referenced by contains(), eventFilter(), operateOnTargets(), and removeAll().

## removeAll [1/2]

int SelectionMoveResizer::removeAll | ( | ArrowMarker * | target | ) |

slot

Remove target from the list of items to be moved/resized together and returns the number of occurences removed.

References d_line_markers, d_widgets, and recalcBoundingRect().

Referenced by contains(), and removeWidget().

## removeAll [2/2]

int SelectionMoveResizer::removeAll | ( | QWidget * | target | ) |

slot

Remove target from the list of items to be moved/resized together and returns the number of occurences removed.

References d_line_markers, d_widgets, FrameWidget::isOnTop(), and recalcBoundingRect().

## removeWidget

void SelectionMoveResizer::removeWidget | ( | QObject * | w | ) |

inline private slot

A non-typesafe version of remvoveAll(QWidget*) needed for QObject::destroyed().

References removeAll().

Referenced by add().

## targetsChanged

void SelectionMoveResizer::targetsChanged | ( |  | ) |

signal

Emitted when the targets are modified (moved or resized).

Referenced by contains(), and operateOnTargets().

## widgetsList()

QList<QWidget *> SelectionMoveResizer::widgetsList | ( |  | ) | const

inline

References d_widgets.

Referenced by ApplicationWindow::graphSelectionChanged().

## Member Data Documentation

## d_bounding_rect

QRect SelectionMoveResizer::d_bounding_rect

private

Bounding rectangle of all targets taken together, in drawing coordinates.

Referenced by add(), init(), mouseMoveEvent(), mousePressEvent(), operateOn(), operateOnTargets(), paintEvent(), and recalcBoundingRect().

## d_line_markers

QList<ArrowMarker *> SelectionMoveResizer::d_line_markers

private

Target markers I'm handling.

Referenced by add(), contains(), operateOnTargets(), recalcBoundingRect(), and removeAll().

## d_op

Operation SelectionMoveResizer::d_op

private

The type of operation currently in progress.

Referenced by init(), keyPressEvent(), mouseMoveEvent(), mousePressEvent(), mouseReleaseEvent(), and operateOn().

## d_op_dp

QPoint SelectionMoveResizer::d_op_dp

private

Difference between current and start position during operation.

Referenced by init(), keyPressEvent(), mouseMoveEvent(), mouseReleaseEvent(), operateOn(), and operateOnTargets().

## d_op_start

QPoint SelectionMoveResizer::d_op_start

private

Mouse position where an operation started; (-1,-1) means started by keyboard.

Referenced by init(), keyPressEvent(), mouseMoveEvent(), mousePressEvent(), mouseReleaseEvent(), and operateOnTargets().

## d_widgets

QList<QWidget *> SelectionMoveResizer::d_widgets

private

Target widgets I'm handling.

Referenced by add(), alignTargetsBottom(), alignTargetsLeft(), alignTargetsRight(), alignTargetsTop(), contains(), keyPressEvent(), mouseDoubleClickEvent(), mousePressEvent(), operateOnTargets(), raiseTargets(), recalcBoundingRect(), removeAll(), widgetsList(), and ~SelectionMoveResizer().

## handler_size

const int SelectionMoveResizer::handler_size = 10

static private

Size of resize handle in pixels.

Referenced by handlerRect().

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

- qtiplot/src/plot2D/SelectionMoveResizer.h
- qtiplot/src/plot2D/SelectionMoveResizer.cpp