1 /***************************************************************************
2     File                 : ScreenPickerTool.h
3     Project              : QtiPlot
4     --------------------------------------------------------------------
5     Copyright            : (C) 2006,2007 by Ion Vasilief, Knut Franke
6     Email (use @ for *)  : ion_vasilief*yahoo.fr, knut.franke*gmx.de
7     Description          : Plot tool for selecting arbitrary points.
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 #ifndef SCREEN_PICKER_TOOL_H
30 #define SCREEN_PICKER_TOOL_H
31 
32 #include <PlotToolInterface.h>
33 #include <DoubleSpinBox.h>
34 
35 #include <QObject>
36 #include <QPointer>
37 #include <QLabel>
38 #include <QSpinBox>
39 
40 #include <qwt_double_rect.h>
41 #include <qwt_plot_marker.h>
42 #include <qwt_plot_picker.h>
43 
44 class ApplicationWindow;
45 class Table;
46 class Matrix;
47 class DataCurve;
48 
49 /*!Plot tool for selecting arbitrary points.
50  *
51  * This is a rather thin wrapper around QwtPlotPicker, providing selection of points
52  * on a Graph/Plot and displaying coordinates.
53  */
54 class ScreenPickerTool : public QwtPlotPicker, public PlotToolInterface
55 {
56 	Q_OBJECT
57 	public:
58 		enum MoveRestriction { NoRestriction, Vertical, Horizontal };
59 		ScreenPickerTool(Graph *graph, const QObject *status_target=NULL, const char *status_slot="");
60 		virtual ~ScreenPickerTool();
61 		virtual void append(const QwtDoublePoint &pos);
setMoveRestriction(ScreenPickerTool::MoveRestriction r)62 		void setMoveRestriction(ScreenPickerTool::MoveRestriction r){d_move_restriction = r;};
63 
xValue()64 		double xValue(){return d_selection_marker.xValue();};
yValue()65 		double yValue(){return d_selection_marker.yValue();};
66 
67 	signals:
68 		/*! Emitted whenever a new message should be presented to the user.
69 		 *
70 		 * You don't have to connect to this signal if you alreay specified a reciever during initialization.
71 		 */
72 		void statusText(const QString&);
73 	protected:
74         virtual bool eventFilter(QObject *obj, QEvent *event);
75 		virtual void append(const QPoint &point);
76 		QwtPlotMarker d_selection_marker;
77 		MoveRestriction d_move_restriction;
78 };
79 
80 /*!Plot tool for drawing arbitrary points.
81  *
82  */
83 class DrawPointTool : public ScreenPickerTool
84 {
85 	Q_OBJECT
86 	public:
87 		DrawPointTool(ApplicationWindow *app, Graph *graph, const QObject *status_target=NULL, const char *status_slot="");
rtti()88 		virtual int rtti() const { return Rtti_DrawDataPoints;};
89 
90 	protected:
91         virtual bool eventFilter(QObject *obj, QEvent *event);
92 		void appendPoint(const QwtDoublePoint &point);
93 		DataCurve *d_curve;
94 		Table *d_table;
95 		ApplicationWindow *d_app;
96 };
97 
98 /*!Plot tool for image analysis.
99  *
100  */
101 class ImageProfilesTool : public ScreenPickerTool
102 {
103 	Q_OBJECT
104 	public:
105 		ImageProfilesTool(ApplicationWindow *app, Graph *graph, Matrix *m, Table *horTable, Table *verTable);
106 		void connectPlotLayers();
107 
108 		ImageProfilesTool* clone(Graph *g);
109 
110 		virtual ~ImageProfilesTool();
111 		virtual void append(const QwtDoublePoint &pos);
rtti()112 		virtual int rtti() const { return Rtti_ImageProfilesTool;};
113 
averagePixels()114 		int averagePixels(){return averageBox->value();}
115 		void setAveragePixels(int pixels);
116 
matrix()117 		QPointer<Matrix> matrix(){return d_matrix;};
horizontalTable()118 		QPointer<Table> horizontalTable(){return d_hor_table;};
verticalTable()119 		QPointer<Table> verticalTable(){return d_ver_table;};
120 
121 	private slots:
122 		void modifiedMatrix(Matrix *);
123 		void updateCursorPosition();
124 		void updateCursorWidth(int width);
125 
126 	private:
127 		void setCursorWidth(int width);
128 
129 	protected:
130 		ApplicationWindow *d_app;
131 		QPointer<Matrix> d_matrix;
132 		QPointer<Table> d_hor_table, d_ver_table;
133 		DoubleSpinBox *horSpinBox, *vertSpinBox;
134 		QSpinBox *averageBox;
135 		QLabel *zLabel;
136 		QWidget *d_box;
137 };
138 
139 #endif // ifndef SCREEN_PICKER_TOOL_H
140