QtiPlot 0.9.8.2
SelectionMoveResizer.h
Go to the documentation of this file.
00001 /***************************************************************************
00002     File                 : SelectionMoveResizer.h
00003     Project              : QtiPlot
00004     --------------------------------------------------------------------
00005     Copyright            : (C) 2007 by Knut Franke, 2008 by Ion Vasilief
00006     Email (use @ for *)  : knut.franke*gmx.de, ion_vasilief*yahoo.fr
00007     Description          : Selection of Widgets and QwtPlotMarkers
00008 
00009  ***************************************************************************/
00010 
00011 /***************************************************************************
00012  *                                                                         *
00013  *  This program is free software; you can redistribute it and/or modify   *
00014  *  it under the terms of the GNU General Public License as published by   *
00015  *  the Free Software Foundation; either version 2 of the License, or      *
00016  *  (at your option) any later version.                                    *
00017  *                                                                         *
00018  *  This program is distributed in the hope that it will be useful,        *
00019  *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
00020  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
00021  *  GNU General Public License for more details.                           *
00022  *                                                                         *
00023  *   You should have received a copy of the GNU General Public License     *
00024  *   along with this program; if not, write to the Free Software           *
00025  *   Foundation, Inc., 51 Franklin Street, Fifth Floor,                    *
00026  *   Boston, MA  02110-1301  USA                                           *
00027  *                                                                         *
00028  ***************************************************************************/
00029 
00030 #ifndef SELECTION_MOVE_RESIZER_H
00031 #define SELECTION_MOVE_RESIZER_H
00032 
00033 #include <QWidget>
00034 #include <QList>
00035 #include <QRect>
00036 
00037 class QPoint;
00038 class QwtPlotMarker;
00039 class QwtPlotCanvas;
00040 class LegendWidget;
00041 class ArrowMarker;
00042 
00089 class SelectionMoveResizer : public QWidget
00090 {
00091     Q_OBJECT
00092 
00093     public:
00095         SelectionMoveResizer(ArrowMarker *target);
00097         SelectionMoveResizer(QWidget *target);
00099         ~SelectionMoveResizer();
00102         virtual bool eventFilter(QObject *o, QEvent *e);
00104         bool contains(QWidget *w) const { return d_widgets.contains(w); };
00105         QList <QWidget *> widgetsList() const { return d_widgets; };
00107         bool contains(ArrowMarker *m) const { return d_line_markers.contains(m); };
00108         void raiseTargets(bool on = true);
00109         void alignTargetsLeft();
00110         void alignTargetsRight();
00111         void alignTargetsTop();
00112         void alignTargetsBottom();
00113 
00114     public slots:
00116         void add(ArrowMarker *target);
00118         void add(QWidget *target);
00120         int removeAll(ArrowMarker *target);
00122         int removeAll(QWidget *target);
00124         void recalcBoundingRect();
00125 
00126     signals:
00128         void targetsChanged();
00129 
00130     protected:
00132         enum Operation { None=-2, Move, Resize_N, Resize_NE, Resize_E, Resize_SE, Resize_S, Resize_SW, Resize_W, Resize_NW };
00133 
00139         virtual void paintEvent(QPaintEvent *e);
00145         virtual void mousePressEvent(QMouseEvent *e);
00151         virtual void mouseMoveEvent(QMouseEvent *e);
00156         virtual void mouseReleaseEvent(QMouseEvent *e);
00161         virtual void keyPressEvent(QKeyEvent *e);
00163         virtual void mouseDoubleClickEvent(QMouseEvent *e);
00164 
00165     private:
00167         static const int handler_size = 10;
00169         static const QRect handlerRect(QRect rect, Operation op);
00171         QRect operateOn(const QRect in);
00173         void operateOnTargets();
00175         void init();
00177         QRect boundingRectOf(QwtPlotMarker *target) const;
00179         QRect boundingRectOf(QwtPlotCanvas *canvas) const;
00180 
00182         QList <ArrowMarker *> d_line_markers;
00184         QList <QWidget *> d_widgets;
00186         QRect d_bounding_rect;
00188         Operation d_op;
00190         QPoint d_op_start;
00192         QPoint d_op_dp;
00193 
00194     private slots:
00196         void removeWidget(QObject* w) { removeAll((QWidget*) w); }
00197 };
00198 
00199 #endif // ifndef SELECTION_MOVE_RESIZER_H