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