QtiPlot  0.9.8.2
SelectionMoveResizer.h
Go to the documentation of this file.
1 /***************************************************************************
2  File : SelectionMoveResizer.h
3  Project : QtiPlot
4  --------------------------------------------------------------------
5  Copyright : (C) 2007 by Knut Franke, 2008 by Ion Vasilief
6  Email (use @ for *) : knut.franke*gmx.de, ion_vasilief*yahoo.fr
7  Description : Selection of Widgets and QwtPlotMarkers
8 
9  ***************************************************************************/
10 
11 /***************************************************************************
12  * *
13  * This program is free software; you can redistribute it and/or modify *
14  * it under the terms of the GNU General Public License as published by *
15  * the Free Software Foundation; either version 2 of the License, or *
16  * (at your option) any later version. *
17  * *
18  * This program is distributed in the hope that it will be useful, *
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
21  * GNU General Public License for more details. *
22  * *
23  * You should have received a copy of the GNU General Public License *
24  * along with this program; if not, write to the Free Software *
25  * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
26  * Boston, MA 02110-1301 USA *
27  * *
28  ***************************************************************************/
29 
30 #ifndef SELECTION_MOVE_RESIZER_H
31 #define SELECTION_MOVE_RESIZER_H
32 
33 #include <QWidget>
34 #include <QList>
35 #include <QRect>
36 
37 class QPoint;
38 class QwtPlotMarker;
39 class QwtPlotCanvas;
40 class LegendWidget;
41 class ArrowMarker;
42 
89 class SelectionMoveResizer : public QWidget
90 {
91  Q_OBJECT
92 
93  public:
97  SelectionMoveResizer(QWidget *target);
102  virtual bool eventFilter(QObject *o, QEvent *e);
104  bool contains(QWidget *w) const { return d_widgets.contains(w); };
105  QList <QWidget *> widgetsList() const { return d_widgets; };
107  bool contains(ArrowMarker *m) const { return d_line_markers.contains(m); };
108  void raiseTargets(bool on = true);
109  void alignTargetsLeft();
110  void alignTargetsRight();
111  void alignTargetsTop();
112  void alignTargetsBottom();
113 
114  public slots:
116  void add(ArrowMarker *target);
118  void add(QWidget *target);
120  int removeAll(ArrowMarker *target);
122  int removeAll(QWidget *target);
124  void recalcBoundingRect();
125 
126  signals:
128  void targetsChanged();
129 
130  protected:
133 
139  virtual void paintEvent(QPaintEvent *e);
145  virtual void mousePressEvent(QMouseEvent *e);
151  virtual void mouseMoveEvent(QMouseEvent *e);
156  virtual void mouseReleaseEvent(QMouseEvent *e);
161  virtual void keyPressEvent(QKeyEvent *e);
163  virtual void mouseDoubleClickEvent(QMouseEvent *e);
164 
165  private:
167  static const int handler_size = 10;
169  static const QRect handlerRect(QRect rect, Operation op);
171  QRect operateOn(const QRect in);
173  void operateOnTargets();
175  void init();
177  QRect boundingRectOf(QwtPlotMarker *target) const;
179  QRect boundingRectOf(QwtPlotCanvas *canvas) const;
180 
182  QList <ArrowMarker *> d_line_markers;
184  QList <QWidget *> d_widgets;
190  QPoint d_op_start;
192  QPoint d_op_dp;
193 
194  private slots:
196  void removeWidget(QObject* w) { removeAll((QWidget*) w); }
197 };
198 
199 #endif // ifndef SELECTION_MOVE_RESIZER_H
Definition: SelectionMoveResizer.h:132
QPoint d_op_dp
Difference between current and start position during operation.
Definition: SelectionMoveResizer.h:192
void alignTargetsRight()
Definition: SelectionMoveResizer.cpp:201
Definition: SelectionMoveResizer.h:132
int removeAll(ArrowMarker *target)
Remove target from the list of items to be moved/resized together and returns the number of occurence...
Definition: SelectionMoveResizer.cpp:141
bool contains(ArrowMarker *m) const
Returns true if m is one of targets, false else.
Definition: SelectionMoveResizer.h:107
void removeWidget(QObject *w)
A non-typesafe version of remvoveAll(QWidget*) needed for QObject::destroyed().
Definition: SelectionMoveResizer.h:196
Definition: SelectionMoveResizer.h:132
Definition: SelectionMoveResizer.h:132
QList< QWidget * > widgetsList() const
Definition: SelectionMoveResizer.h:105
QRect boundingRectOf(QwtPlotMarker *target) const
Get the bounding rectangle of a marker in paint coordinates.
Definition: SelectionMoveResizer.cpp:128
Definition: SelectionMoveResizer.h:132
Draws lines and arrows on a QwtPlot.
Definition: ArrowMarker.h:43
static const QRect handlerRect(QRect rect, Operation op)
Return one of the rectangles to be filled for starting resize operations.
Definition: SelectionMoveResizer.cpp:302
virtual void mouseDoubleClickEvent(QMouseEvent *e)
Ignore double-clicks so that they can be used by my parent.
Definition: SelectionMoveResizer.cpp:527
virtual void mouseReleaseEvent(QMouseEvent *e)
Mouse releases end the current operation and apply it to the targets.
Definition: SelectionMoveResizer.cpp:553
virtual void mouseMoveEvent(QMouseEvent *e)
Mouse movements need to be monitored for updating the frame during operation.
Definition: SelectionMoveResizer.cpp:501
void alignTargetsLeft()
Definition: SelectionMoveResizer.cpp:178
Definition: SelectionMoveResizer.h:132
virtual void paintEvent(QPaintEvent *e)
Draw frame and resize handlers.
Definition: SelectionMoveResizer.cpp:434
void raiseTargets(bool on=true)
Definition: SelectionMoveResizer.cpp:166
void add(ArrowMarker *target)
Add target to the list of items to be moved/resized together.
Definition: SelectionMoveResizer.cpp:92
Operation
Available modes of operation.
Definition: SelectionMoveResizer.h:132
Handler for modifying one or more QWidget and/or QwtPlotMarker with mouse or keyboard.
Definition: SelectionMoveResizer.h:89
static const int handler_size
Size of resize handle in pixels.
Definition: SelectionMoveResizer.h:167
virtual bool eventFilter(QObject *o, QEvent *e)
React on geometry changes of parent and targets.
Definition: SelectionMoveResizer.cpp:635
void targetsChanged()
Emitted when the targets are modified (moved or resized).
Definition: LegendWidget.h:42
QList< ArrowMarker * > d_line_markers
Target markers I'm handling.
Definition: SelectionMoveResizer.h:182
QRect operateOn(const QRect in)
Apply operation specified by d_op and d_op_dp to in.
Definition: SelectionMoveResizer.cpp:334
void operateOnTargets()
Apply operation specified by d_op and d_op_dp to all targets.
Definition: SelectionMoveResizer.cpp:384
QRect d_bounding_rect
Bounding rectangle of all targets taken together, in drawing coordinates.
Definition: SelectionMoveResizer.h:186
SelectionMoveResizer(ArrowMarker *target)
Construct a new MoveResizer with the given marker as the only target.
Definition: SelectionMoveResizer.cpp:44
bool contains(QWidget *w) const
Returns true if w is one of targets, false else.
Definition: SelectionMoveResizer.h:104
virtual void keyPressEvent(QKeyEvent *e)
Allow keyboard-based moving of the selection.
Definition: SelectionMoveResizer.cpp:564
Definition: SelectionMoveResizer.h:132
~SelectionMoveResizer()
Clean up after myself.
Definition: SelectionMoveResizer.cpp:78
Definition: SelectionMoveResizer.h:132
void init()
The initialization part common to all constructors.
Definition: SelectionMoveResizer.cpp:62
QPoint d_op_start
Mouse position where an operation started; (-1,-1) means started by keyboard.
Definition: SelectionMoveResizer.h:190
QList< QWidget * > d_widgets
Target widgets I'm handling.
Definition: SelectionMoveResizer.h:184
void recalcBoundingRect()
Calculate d_bounding_rect based on the bounding rectangles of all targets.
Definition: SelectionMoveResizer.cpp:276
Definition: SelectionMoveResizer.h:132
void alignTargetsBottom()
Definition: SelectionMoveResizer.cpp:250
virtual void mousePressEvent(QMouseEvent *e)
Mouse button presses start move/resize operations.
Definition: SelectionMoveResizer.cpp:453
void alignTargetsTop()
Definition: SelectionMoveResizer.cpp:227
Operation d_op
The type of operation currently in progress.
Definition: SelectionMoveResizer.h:188
Definition: SelectionMoveResizer.h:132