#include <SelectionMoveResizer.h>
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.
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.
Public Slots | |
void | add (QWidget *target) |
Add target to the list of items to be moved/resized together. | |
void | add (ImageMarker *target) |
Add target to the list of items to be moved/resized together. | |
void | add (ArrowMarker *target) |
Add target to the list of items to be moved/resized together. | |
void | add (LegendWidget *target) |
Add target to the list of items to be moved/resized together. | |
void | recalcBoundingRect () |
Calculate d_bounding_rect based on the bounding rectangles of all targets. | |
int | removeAll (QWidget *target) |
Remove target from the list of items to be moved/resized together and returns the number of occurences removed. | |
int | removeAll (ImageMarker *target) |
Remove target from the list of items to be moved/resized together and returns the number of occurences removed. | |
int | removeAll (ArrowMarker *target) |
Remove target from the list of items to be moved/resized together and returns the number of occurences removed. | |
int | removeAll (LegendWidget *target) |
Remove target from the list of items to be moved/resized together and returns the number of occurences removed. | |
Signals | |
void | targetsChanged () |
Emitted when the targets are modified (moved or resized). | |
Public Member Functions | |
bool | contains (ImageMarker *m) const |
Returns true if m is one of targets, false else. | |
bool | contains (ArrowMarker *m) const |
Returns true if m is one of targets, false else. | |
bool | contains (LegendWidget *m) const |
Returns true if m is one of targets, false else. | |
bool | contains (QWidget *w) const |
Returns true if w is one of targets, false else. | |
virtual bool | eventFilter (QObject *o, QEvent *e) |
React on geometry changes of parent and targets. | |
SelectionMoveResizer (QWidget *target) | |
Construct a new MoveResizer with the given widget as the only target. | |
SelectionMoveResizer (ImageMarker *target) | |
Construct a new MoveResizer with the given marker as the only target. | |
SelectionMoveResizer (ArrowMarker *target) | |
Construct a new MoveResizer with the given marker as the only target. | |
SelectionMoveResizer (LegendWidget *target) | |
Construct a new MoveResizer with the given marker as the only target. | |
~SelectionMoveResizer () | |
Clean up after myself. | |
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. | |
virtual void | mouseDoubleClickEvent (QMouseEvent *e) |
Ignore double-clicks so that they can be used by my parent. | |
virtual void | mouseMoveEvent (QMouseEvent *e) |
Mouse movements need to be monitored for updating the frame during operation. | |
virtual void | mousePressEvent (QMouseEvent *e) |
Mouse button presses start move/resize operations. | |
virtual void | mouseReleaseEvent (QMouseEvent *e) |
Mouse releases end the current operation and apply it to the targets. | |
virtual void | paintEvent (QPaintEvent *e) |
Draw frame and resize handlers. | |
Private Slots | |
void | removeWidget (QObject *w) |
A non-typesafe version of remvoveAll(QWidget*) needed for QObject::destroyed(). | |
Private Member Functions | |
QRect | boundingRectOf (QwtPlotMarker *target) const |
Get the bounding rectangle of a marker in paint coordinates. | |
void | init () |
The initialization part common to all constructors. | |
QRect | operateOn (const QRect in) |
Apply operation specified by d_op and d_op_dp to in. | |
void | operateOnTargets () |
Apply operation specified by d_op and d_op_dp to all targets. | |
Static Private Member Functions | |
static const QRect | handlerRect (QRect rect, Operation op) |
Return one of the rectangles to be filled for starting resize operations. | |
Private Attributes | |
QRect | d_bounding_rect |
Bounding rectangle of all targets taken together, in drawing coordinates. | |
QList< ImageMarker * > | d_image_markers |
Target markers I'm handling. | |
QList< LegendWidget * > | d_legend_markers |
Target markers I'm handling. | |
QList< ArrowMarker * > | d_line_markers |
Target markers I'm handling. | |
Operation | d_op |
The type of operation currently in progress. | |
QPoint | d_op_dp |
Difference between current and start position during operation. | |
QPoint | d_op_start |
Mouse position where an operation started; (-1,-1) means started by keyboard. | |
QList< QWidget * > | d_widgets |
Target widgets I'm handling. | |
Static Private Attributes | |
static const int | handler_size = 10 |
Size of resize handle in pixels. |
enum SelectionMoveResizer::Operation [protected] |
SelectionMoveResizer::SelectionMoveResizer | ( | LegendWidget * | target | ) |
Construct a new MoveResizer with the given marker as the only target.
SelectionMoveResizer::SelectionMoveResizer | ( | ArrowMarker * | target | ) |
Construct a new MoveResizer with the given marker as the only target.
SelectionMoveResizer::SelectionMoveResizer | ( | ImageMarker * | target | ) |
Construct a new MoveResizer with the given marker as the only target.
SelectionMoveResizer::SelectionMoveResizer | ( | QWidget * | target | ) |
Construct a new MoveResizer with the given widget as the only target.
SelectionMoveResizer::~SelectionMoveResizer | ( | ) |
Clean up after myself.
void SelectionMoveResizer::add | ( | QWidget * | target | ) | [slot] |
Add target to the list of items to be moved/resized together.
void SelectionMoveResizer::add | ( | ImageMarker * | target | ) | [slot] |
Add target to the list of items to be moved/resized together.
void SelectionMoveResizer::add | ( | ArrowMarker * | target | ) | [slot] |
Add target to the list of items to be moved/resized together.
void SelectionMoveResizer::add | ( | LegendWidget * | target | ) | [slot] |
Add target to the list of items to be moved/resized together.
QRect SelectionMoveResizer::boundingRectOf | ( | QwtPlotMarker * | target | ) | const [private] |
Get the bounding rectangle of a marker in paint coordinates.
bool SelectionMoveResizer::contains | ( | ImageMarker * | m | ) | const [inline] |
Returns true if m is one of targets, false else.
bool SelectionMoveResizer::contains | ( | ArrowMarker * | m | ) | const [inline] |
Returns true if m is one of targets, false else.
bool SelectionMoveResizer::contains | ( | LegendWidget * | m | ) | const [inline] |
Returns true if m is one of targets, false else.
bool SelectionMoveResizer::contains | ( | QWidget * | w | ) | const [inline] |
Returns true if w is one of targets, false else.
bool SelectionMoveResizer::eventFilter | ( | QObject * | o, | |
QEvent * | e | |||
) | [virtual] |
React on geometry changes of parent and targets.
const QRect SelectionMoveResizer::handlerRect | ( | QRect | rect, | |
Operation | op | |||
) | [static, private] |
Return one of the rectangles to be filled for starting resize operations.
void SelectionMoveResizer::init | ( | ) | [private] |
The initialization part common to all constructors.
void SelectionMoveResizer::keyPressEvent | ( | QKeyEvent * | e | ) | [protected, virtual] |
Allow keyboard-based moving of the selection.
Unused keys are passed on to the parent.
void SelectionMoveResizer::mouseDoubleClickEvent | ( | QMouseEvent * | e | ) | [protected, virtual] |
Ignore double-clicks so that they can be used by my parent.
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.
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.
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.
QRect SelectionMoveResizer::operateOn | ( | const QRect | in | ) | [private] |
void SelectionMoveResizer::operateOnTargets | ( | ) | [private] |
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.
void SelectionMoveResizer::recalcBoundingRect | ( | ) | [slot] |
Calculate d_bounding_rect based on the bounding rectangles of all targets.
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.
int SelectionMoveResizer::removeAll | ( | ImageMarker * | target | ) | [slot] |
Remove target from the list of items to be moved/resized together and returns the number of occurences removed.
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.
int SelectionMoveResizer::removeAll | ( | LegendWidget * | target | ) | [slot] |
Remove target from the list of items to be moved/resized together and returns the number of occurences removed.
void SelectionMoveResizer::removeWidget | ( | QObject * | w | ) | [inline, private, slot] |
A non-typesafe version of remvoveAll(QWidget*) needed for QObject::destroyed().
void SelectionMoveResizer::targetsChanged | ( | ) | [signal] |
Emitted when the targets are modified (moved or resized).
QRect SelectionMoveResizer::d_bounding_rect [private] |
Bounding rectangle of all targets taken together, in drawing coordinates.
QList<ImageMarker *> SelectionMoveResizer::d_image_markers [private] |
Target markers I'm handling.
QList<LegendWidget *> SelectionMoveResizer::d_legend_markers [private] |
Target markers I'm handling.
QList<ArrowMarker *> SelectionMoveResizer::d_line_markers [private] |
Target markers I'm handling.
Operation SelectionMoveResizer::d_op [private] |
The type of operation currently in progress.
QPoint SelectionMoveResizer::d_op_dp [private] |
Difference between current and start position during operation.
QPoint SelectionMoveResizer::d_op_start [private] |
Mouse position where an operation started; (-1,-1) means started by keyboard.
QList<QWidget *> SelectionMoveResizer::d_widgets [private] |
Target widgets I'm handling.
const int SelectionMoveResizer::handler_size = 10 [static, private] |
Size of resize handle in pixels.