00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef QWT_PICKER
00011 #define QWT_PICKER 1
00012
00013 #include <qobject.h>
00014 #include <qpen.h>
00015 #include <qfont.h>
00016 #include <qrect.h>
00017 #include "qwt_global.h"
00018 #include "qwt_event_pattern.h"
00019 #if QT_VERSION < 0x040000
00020 #include <qpointarray.h>
00021 #else
00022 #include <qpolygon.h>
00023 #endif
00024
00025 class QWidget;
00026 class QMouseEvent;
00027 class QWheelEvent;
00028 class QKeyEvent;
00029 class QwtPickerMachine;
00030
00083 class QWT_EXPORT QwtPicker: public QObject, public QwtEventPattern
00084 {
00085 Q_OBJECT
00086
00087 Q_ENUMS(RubberBand)
00088 Q_ENUMS(DisplayMode)
00089 Q_ENUMS(ResizeMode)
00090
00091 Q_PROPERTY(int selectionFlags READ selectionFlags WRITE setSelectionFlags)
00092 Q_PROPERTY(DisplayMode trackerMode READ trackerMode WRITE setTrackerMode)
00093 Q_PROPERTY(QFont trackerFont READ trackerFont WRITE setTrackerFont)
00094 Q_PROPERTY(RubberBand rubberBand READ rubberBand WRITE setRubberBand)
00095 Q_PROPERTY(ResizeMode resizeMode READ resizeMode WRITE setResizeMode)
00096 Q_PROPERTY(bool isEnabled READ isEnabled WRITE setEnabled)
00097
00098 Q_PROPERTY(QPen trackerPen READ trackerPen WRITE setTrackerPen)
00099 Q_PROPERTY(QPen rubberBandPen READ rubberBandPen WRITE setRubberBandPen)
00100
00101 public:
00120 enum SelectionType
00121 {
00122 NoSelection = 0,
00123 PointSelection = 1,
00124 RectSelection = 2,
00125 PolygonSelection = 4
00126 };
00127
00146 enum RectSelectionType
00147 {
00148 CornerToCorner = 64,
00149 CenterToCorner = 128,
00150 CenterToRadius = 256
00151 };
00152
00160 enum SelectionMode
00161 {
00162 ClickSelection = 1024,
00163 DragSelection = 2048
00164 };
00165
00166 #if QT_VERSION < 0x040000
00167 typedef QPointArray SelectedPoints;
00168 #else
00169 typedef QPolygon SelectedPoints;
00170 #endif
00171
00195 enum RubberBand
00196 {
00197 NoRubberBand = 0,
00198
00199
00200 HLineRubberBand,
00201 VLineRubberBand,
00202 CrossRubberBand,
00203
00204
00205 RectRubberBand,
00206 EllipseRubberBand,
00207
00208
00209 PolygonRubberBand,
00210
00211 UserRubberBand = 100
00212 };
00213
00225 enum DisplayMode
00226 {
00227 AlwaysOff,
00228 AlwaysOn,
00229 ActiveOnly
00230 };
00231
00244 enum ResizeMode
00245 {
00246 Stretch,
00247 KeepSize
00248 };
00249
00250 explicit QwtPicker(QWidget *parent);
00251 explicit QwtPicker(int selectionFlags, RubberBand rubberBand,
00252 DisplayMode trackerMode, QWidget *);
00253
00254 virtual ~QwtPicker();
00255
00256 virtual void setSelectionFlags(int);
00257 int selectionFlags() const;
00258
00259 virtual void setRubberBand(RubberBand);
00260 RubberBand rubberBand() const;
00261
00262 virtual void setTrackerMode(DisplayMode);
00263 DisplayMode trackerMode() const;
00264
00265 virtual void setResizeMode(ResizeMode);
00266 ResizeMode resizeMode() const;
00267
00268 virtual void setRubberBandPen(const QPen &);
00269 QPen rubberBandPen() const;
00270
00271 virtual void setTrackerPen(const QPen &);
00272 QPen trackerPen() const;
00273
00274 virtual void setTrackerFont(const QFont &);
00275 QFont trackerFont() const;
00276
00277 bool isEnabled() const;
00278 virtual void setEnabled(bool);
00279
00280 bool isActive() const;
00281
00282 virtual bool eventFilter(QObject *, QEvent *);
00283
00284 QWidget *parentWidget();
00285 const QWidget *parentWidget() const;
00286
00287 virtual QRect pickRect() const;
00288 const SelectedPoints &selection() const;
00289
00290 virtual void drawRubberBand(QPainter *) const;
00291 virtual void drawTracker(QPainter *) const;
00292
00293 signals:
00300 void selected(const QwtPicker::SelectedPoints &pa);
00301
00308 void appended(const QPoint &pos);
00309
00317 void moved(const QPoint &pos);
00318
00326 void changed(const SelectedPoints &pa);
00327
00328 protected:
00337 virtual bool accept(SelectedPoints &selection) const;
00338
00339 virtual void transition(const QEvent *);
00340
00341 virtual void begin();
00342 virtual void append(const QPoint &);
00343 virtual void move(const QPoint &);
00344 virtual bool end(bool ok = true);
00345
00346 virtual void widgetMousePressEvent(QMouseEvent *);
00347 virtual void widgetMouseReleaseEvent(QMouseEvent *);
00348 virtual void widgetMouseDoubleClickEvent(QMouseEvent *);
00349 virtual void widgetMouseMoveEvent(QMouseEvent *);
00350 virtual void widgetWheelEvent(QWheelEvent *);
00351 virtual void widgetKeyPressEvent(QKeyEvent *);
00352 virtual void widgetKeyReleaseEvent(QKeyEvent *);
00353
00354 QRect trackerRect(QPainter *painter) const;
00355
00356 virtual void stretchSelection(const QSize &oldSize,
00357 const QSize &newSize);
00358
00359 virtual QString trackerText(const QPoint &pos) const;
00360
00361 virtual QwtPickerMachine *stateMachine(int) const;
00362
00363 private:
00364 void init(QWidget *, int selectionFlags, RubberBand rubberBand,
00365 DisplayMode trackerMode);
00366
00367 void setStateMachine(QwtPickerMachine *);
00368 void setMouseTracking(bool);
00369
00370 void updateDisplay();
00371
00372 class PrivateData;
00373 PrivateData *d_data;
00374 };
00375
00376 #endif