Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

qwt_picker.h

00001 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
00002  * Qwt Widget Library
00003  * Copyright (C) 1997   Josef Wilgen
00004  * Copyright (C) 2002   Uwe Rathmann
00005  * 
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the Qwt License, Version 1.0
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 <qpointarray.h>
00018 #include "qwt_event_pattern.h"
00019 #include "qwt_global.h"
00020 
00021 class QWidget;
00022 class QMouseEvent;
00023 class QWheelEvent;
00024 class QKeyEvent;
00025 class QwtPickerMachine;
00026 
00079 class QWT_EXPORT QwtPicker: public QObject, public QwtEventPattern
00080 {
00081     Q_OBJECT
00082 
00083     Q_ENUMS(RubberBand)
00084     Q_ENUMS(DisplayMode)
00085     Q_ENUMS(ResizeMode)
00086 
00087     Q_PROPERTY(int selectionFlags READ selectionFlags WRITE setSelectionFlags)
00088     Q_PROPERTY(DisplayMode cursorLabelMode 
00089         READ cursorLabelMode WRITE setCursorLabelMode)
00090     Q_PROPERTY(QFont cursorLabelFont 
00091         READ cursorLabelFont WRITE setCursorLabelFont)
00092     Q_PROPERTY(RubberBand rubberBand READ rubberBand WRITE setRubberBand)
00093     Q_PROPERTY(ResizeMode resizeMode READ resizeMode WRITE setResizeMode)
00094     Q_PROPERTY(bool isEnabled READ isEnabled WRITE setEnabled)
00095 
00096 #if QT_VERSION >= 300
00097     // Unfortunately moc is not aware of #ifdefs. To enable the QPen
00098     // attributes as properties uncomment the following lines.
00099 
00100     //Q_PROPERTY(QPen cursorLabelPen READ cursorLabelPen WRITE setCursorLabelPen)
00101     //Q_PROPERTY(QPen rubberBandPen READ rubberBandPen WRITE setRubberBandPen)
00102 #endif
00103 
00104 public:
00123     enum SelectionType
00124     {
00125         NoSelection = 0,
00126         PointSelection = 1,
00127         RectSelection = 2,
00128         PolygonSelection = 4
00129     };
00130 
00149     enum RectSelectionType
00150     {
00151         CornerToCorner = 64,
00152         CenterToCorner = 128,
00153         CenterToRadius = 256
00154     };
00155 
00163     enum SelectionMode
00164     {
00165         ClickSelection = 1024,
00166         DragSelection = 2048
00167     };
00168 
00193     enum RubberBand
00194     {
00195         NoRubberBand = 0,
00196 
00197         // Point
00198         HLineRubberBand,
00199         VLineRubberBand,
00200         CrossRubberBand,
00201 
00202         // Rect
00203         RectRubberBand,
00204         EllipseRubberBand,
00205 
00206         // Polygon
00207         PolygonRubberBand,
00208 
00209         UserRubberBand = 100
00210     };
00211 
00223     enum DisplayMode
00224     {
00225         AlwaysOff,
00226         AlwaysOn,
00227         ActiveOnly
00228     };
00229 
00242     enum ResizeMode
00243     {
00244         Stretch,
00245         KeepSize
00246     };
00247 
00248     QwtPicker(QWidget *, const char *name = 0);
00249     QwtPicker(int selectionFlags, RubberBand rubberBand,
00250         DisplayMode cursorLabelMode, QWidget *, const char *name = 0);
00251 
00252     virtual ~QwtPicker();
00253 
00254     virtual void setSelectionFlags(int);
00255     int selectionFlags() const;
00256 
00257     virtual void setRubberBand(RubberBand);
00258     RubberBand rubberBand() const;
00259 
00260     virtual void setCursorLabelMode(DisplayMode);
00261     DisplayMode cursorLabelMode() const;
00262 
00263     virtual void setResizeMode(ResizeMode);
00264     ResizeMode resizeMode() const;
00265 
00266     virtual void setRubberBandPen(const QPen &);
00267     QPen rubberBandPen() const;
00268 
00269     virtual void setCursorLabelPen(const QPen &);
00270     QPen cursorLabelPen() const;
00271 
00272     virtual void setCursorLabelFont(const QFont &);
00273     QFont cursorLabelFont() const;
00274 
00275     bool isEnabled() const;
00276     virtual void setEnabled(bool);
00277 
00278     bool isActive() const;
00279 
00280     virtual bool eventFilter(QObject *, QEvent *);
00281 
00282     QWidget *parentWidget();
00283     const QWidget *parentWidget() const;
00284 
00285     virtual QRect pickRect() const;
00286     const QPointArray &selection() const; 
00287 
00288     virtual bool event(QEvent *);
00289 
00290 signals:
00297     void selected(const QPointArray &pa);
00298 
00305     void appended(const QPoint &pos);
00306 
00314     void moved(const QPoint &pos);
00315 
00323     void changed(const QPointArray &pa);
00324 
00325 protected:
00334     virtual bool accept(QPointArray &selection) const;
00335 
00336     virtual void transition(const QEvent *);
00337 
00338     virtual void begin();
00339     virtual void append(const QPoint &);
00340     virtual void move(const QPoint &);
00341     virtual bool end(bool ok = TRUE);
00342 
00343     virtual void widgetMousePressEvent(QMouseEvent *);
00344     virtual void widgetMouseReleaseEvent(QMouseEvent *);
00345     virtual void widgetMouseDoubleClickEvent(QMouseEvent *); 
00346     virtual void widgetMouseMoveEvent(QMouseEvent *); 
00347     virtual void widgetWheelEvent(QWheelEvent *);
00348     virtual void widgetKeyPressEvent(QKeyEvent *); 
00349     virtual void widgetKeyReleaseEvent(QKeyEvent *); 
00350 
00351     virtual void drawRubberBand(const QRect &clipRect = QRect()) const;
00352     virtual void drawRubberBand(QPainter *, 
00353         const QRect &rect, const QPointArray &) const;
00354 
00355     virtual void drawCursorLabel(const QRect &clipRect = QRect()) const;
00356     virtual void drawCursorLabel(QPainter *, const QRect &rect, 
00357         const QPoint &, const QPointArray &) const;
00358 
00359     virtual void stretchSelection(const QSize &oldSize, 
00360         const QSize &newSize);
00361 
00362     virtual QString cursorLabel(const QPoint &pos) const;
00363 
00364     virtual QwtPickerMachine *stateMachine(int) const;
00365 
00366     void repaint(const QRect &rect = QRect());
00367 
00368 private:
00369     void init(QWidget *, int selectionFlags, RubberBand rubberBand,
00370         DisplayMode cursorLabelMode);
00371 
00372     void setStateMachine(QwtPickerMachine *);
00373     void setMouseTracking(bool);
00374 
00375     bool d_enabled;
00376 
00377     QwtPickerMachine *d_stateMachine;
00378 
00379     int d_selectionFlags;
00380     ResizeMode d_resizeMode;
00381 
00382     RubberBand d_rubberBand;
00383     QPen d_rubberBandPen;
00384 
00385     DisplayMode d_cursorLabelMode;
00386     QPen d_cursorLabelPen;
00387     QFont d_cursorLabelFont;
00388 
00389     QPointArray d_selection;
00390     bool d_isActive;
00391     QPoint d_labelPosition;
00392 
00393     bool d_mouseTracking; // used to save previous value
00394 };
00395             
00396 #endif

Generated on Sun Nov 21 11:12:43 2004 for Qwt User's Guide by doxygen 1.3.5