Qwt User's Guide svn
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 "qwt_global.h"
00014 #include "qwt_text.h"
00015 #include "qwt_event_pattern.h"
00016 #include <qobject.h>
00017 #include <qpen.h>
00018 #include <qfont.h>
00019 #include <qrect.h>
00020 
00021 class QWidget;
00022 class QMouseEvent;
00023 class QWheelEvent;
00024 class QKeyEvent;
00025 class QwtPickerMachine;
00026 
00093 class QWT_EXPORT QwtPicker: public QObject, public QwtEventPattern
00094 {
00095     Q_OBJECT
00096 
00097     Q_ENUMS( RubberBand )
00098     Q_ENUMS( DisplayMode )
00099     Q_ENUMS( ResizeMode )
00100 
00101     Q_PROPERTY( bool isEnabled READ isEnabled WRITE setEnabled )
00102     Q_PROPERTY( ResizeMode resizeMode READ resizeMode WRITE setResizeMode )
00103 
00104     Q_PROPERTY( DisplayMode trackerMode READ trackerMode WRITE setTrackerMode )
00105     Q_PROPERTY( QPen trackerPen READ trackerPen WRITE setTrackerPen )
00106     Q_PROPERTY( QFont trackerFont READ trackerFont WRITE setTrackerFont )
00107 
00108     Q_PROPERTY( RubberBand rubberBand READ rubberBand WRITE setRubberBand )
00109     Q_PROPERTY( QPen rubberBandPen READ rubberBandPen WRITE setRubberBandPen )
00110 
00111 public:
00119     enum RubberBand
00120     {
00122         NoRubberBand = 0,
00123 
00125         HLineRubberBand,
00126 
00128         VLineRubberBand,
00129 
00131         CrossRubberBand,
00132 
00134         RectRubberBand,
00135 
00137         EllipseRubberBand,
00138 
00140         PolygonRubberBand,
00141 
00146         UserRubberBand = 100
00147     };
00148 
00153     enum DisplayMode
00154     {
00156         AlwaysOff,
00157 
00159         AlwaysOn,
00160 
00162         ActiveOnly
00163     };
00164 
00173     enum ResizeMode
00174     {
00176         Stretch,
00177 
00179         KeepSize
00180     };
00181 
00182     explicit QwtPicker( QWidget *parent );
00183     explicit QwtPicker( RubberBand rubberBand,
00184                         DisplayMode trackerMode, QWidget * );
00185 
00186     virtual ~QwtPicker();
00187 
00188     void setStateMachine( QwtPickerMachine * );
00189     const QwtPickerMachine *stateMachine() const;
00190     QwtPickerMachine *stateMachine();
00191 
00192     void setRubberBand( RubberBand );
00193     RubberBand rubberBand() const;
00194 
00195     void setTrackerMode( DisplayMode );
00196     DisplayMode trackerMode() const;
00197 
00198     void setResizeMode( ResizeMode );
00199     ResizeMode resizeMode() const;
00200 
00201     void setRubberBandPen( const QPen & );
00202     QPen rubberBandPen() const;
00203 
00204     void setTrackerPen( const QPen & );
00205     QPen trackerPen() const;
00206 
00207     void setTrackerFont( const QFont & );
00208     QFont trackerFont() const;
00209 
00210     bool isEnabled() const;
00211     bool isActive() const;
00212 
00213     virtual bool eventFilter( QObject *, QEvent * );
00214 
00215     QWidget *parentWidget();
00216     const QWidget *parentWidget() const;
00217 
00218     virtual QRect pickRect() const;
00219 
00220     virtual void drawRubberBand( QPainter * ) const;
00221     virtual void drawTracker( QPainter * ) const;
00222 
00223     virtual QwtText trackerText( const QPoint &pos ) const;
00224     QPoint trackerPosition() const;
00225     virtual QRect trackerRect( const QFont & ) const;
00226 
00227     QPolygon selection() const;
00228 
00229 public Q_SLOTS:
00230     void setEnabled( bool );
00231 
00232 Q_SIGNALS:
00240     void activated( bool on );
00241 
00248     void selected( const QPolygon &polygon );
00249 
00256     void appended( const QPoint &pos );
00257 
00265     void moved( const QPoint &pos );
00266 
00273     void removed( const QPoint &pos );
00281     void changed( const QPolygon &selection );
00282 
00283 protected:
00284     virtual QPolygon adjustedPoints( const QPolygon & ) const;
00285 
00286     virtual void transition( const QEvent * );
00287 
00288     virtual void begin();
00289     virtual void append( const QPoint & );
00290     virtual void move( const QPoint & );
00291     virtual void remove();
00292     virtual bool end( bool ok = true );
00293 
00294     virtual bool accept( QPolygon & ) const;
00295     virtual void reset();
00296 
00297     virtual void widgetMousePressEvent( QMouseEvent * );
00298     virtual void widgetMouseReleaseEvent( QMouseEvent * );
00299     virtual void widgetMouseDoubleClickEvent( QMouseEvent * );
00300     virtual void widgetMouseMoveEvent( QMouseEvent * );
00301     virtual void widgetWheelEvent( QWheelEvent * );
00302     virtual void widgetKeyPressEvent( QKeyEvent * );
00303     virtual void widgetKeyReleaseEvent( QKeyEvent * );
00304     virtual void widgetEnterEvent( QEvent * );
00305     virtual void widgetLeaveEvent( QEvent * );
00306 
00307     virtual void stretchSelection( const QSize &oldSize,
00308                                    const QSize &newSize );
00309 
00310     virtual void updateDisplay();
00311 
00312     const QWidget *rubberBandWidget() const;
00313     const QWidget *trackerWidget() const;
00314 
00315     const QPolygon &pickedPoints() const;
00316 
00317 private:
00318     void init( QWidget *, RubberBand rubberBand, DisplayMode trackerMode );
00319 
00320     void setMouseTracking( bool );
00321 
00322     class PickerWidget;
00323     class PrivateData;
00324     PrivateData *d_data;
00325 };
00326 
00327 #endif
qmi style