00001 /*************************************************************************** 00002 File : RangeSelectorTool.h 00003 Project : QtiPlot 00004 -------------------------------------------------------------------- 00005 Copyright : (C) 2006,2007 by Ion Vasilief, 00006 Tilman Hoener zu Siederdissen, Knut Franke 00007 Email (use @ for *) : ion_vasilief*yahoo.fr, thzs*gmx.net, 00008 knut.franke*gmx.de 00009 Description : Plot tool for selecting ranges on curves. 00010 00011 ***************************************************************************/ 00012 00013 /*************************************************************************** 00014 * * 00015 * This program is free software; you can redistribute it and/or modify * 00016 * it under the terms of the GNU General Public License as published by * 00017 * the Free Software Foundation; either version 2 of the License, or * 00018 * (at your option) any later version. * 00019 * * 00020 * This program is distributed in the hope that it will be useful, * 00021 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00022 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00023 * GNU General Public License for more details. * 00024 * * 00025 * You should have received a copy of the GNU General Public License * 00026 * along with this program; if not, write to the Free Software * 00027 * Foundation, Inc., 51 Franklin Street, Fifth Floor, * 00028 * Boston, MA 02110-1301 USA * 00029 * * 00030 ***************************************************************************/ 00031 #ifndef RANGE_SELECTOR_TOOL_H 00032 #define RANGE_SELECTOR_TOOL_H 00033 00034 #include "PlotToolInterface.h" 00035 #include <qwt_double_rect.h> 00036 #include <qwt_plot_marker.h> 00037 #include <qwt_plot_picker.h> 00038 00039 class QwtPlotCurve; 00040 class QPoint; 00041 class QEvent; 00042 00054 class RangeSelectorTool : public QwtPlotPicker, public PlotToolInterface 00055 { 00056 Q_OBJECT 00057 public: 00058 RangeSelectorTool(Graph *graph, const QObject *status_target=NULL, const char *status_slot=""); 00059 virtual ~RangeSelectorTool(); 00060 double minXValue() const { return qMin(d_active_marker.xValue(), d_inactive_marker.xValue()); } 00061 double maxXValue() const { return qMax(d_active_marker.xValue(), d_inactive_marker.xValue()); } 00062 int dataSize() const { return qAbs(d_active_point - d_inactive_point); } 00063 virtual bool eventFilter(QObject *obj, QEvent *event); 00064 bool keyEventFilter(QKeyEvent *ke); 00065 00066 QwtPlotCurve *selectedCurve() const { return d_selected_curve; } 00068 void setSelectedCurve(QwtPlotCurve *curve); 00069 00070 public slots: 00071 virtual void pointSelected(const QPoint &point); 00072 00073 signals: 00078 void statusText(const QString&); 00080 void changed(); 00081 protected: 00082 virtual void append(const QPoint& point) { pointSelected(point); } 00083 void emitStatusText(); 00084 void switchActiveMarker(); 00086 void setActivePoint(int index); 00087 private: 00088 QwtPlotMarker d_active_marker, d_inactive_marker; 00089 int d_active_point, d_inactive_point; 00090 QwtPlotCurve *d_selected_curve; 00091 }; 00092 00093 #endif // ifndef RANGE_SELECTOR_TOOL_H 00094