Qwt User's Guide
|
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 #include <qpainterpath.h> 00021 00022 class QWidget; 00023 class QMouseEvent; 00024 class QWheelEvent; 00025 class QKeyEvent; 00026 class QwtPickerMachine; 00027 class QwtWidgetOverlay; 00028 00095 class QWT_EXPORT QwtPicker: public QObject, public QwtEventPattern 00096 { 00097 Q_OBJECT 00098 00099 Q_ENUMS( RubberBand DisplayMode 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 QPainterPath pickArea() const; 00219 00220 virtual void drawRubberBand( QPainter * ) const; 00221 virtual void drawTracker( QPainter * ) const; 00222 00223 virtual QRegion rubberBandMask() const; 00224 00225 virtual QwtText trackerText( const QPoint &pos ) const; 00226 QPoint trackerPosition() const; 00227 virtual QRect trackerRect( const QFont & ) const; 00228 00229 QPolygon selection() const; 00230 00231 public Q_SLOTS: 00232 void setEnabled( bool ); 00233 00234 Q_SIGNALS: 00242 void activated( bool on ); 00243 00250 void selected( const QPolygon &polygon ); 00251 00258 void appended( const QPoint &pos ); 00259 00267 void moved( const QPoint &pos ); 00268 00276 void removed( const QPoint &pos ); 00284 void changed( const QPolygon &selection ); 00285 00286 protected: 00287 virtual QPolygon adjustedPoints( const QPolygon & ) const; 00288 00289 virtual void transition( const QEvent * ); 00290 00291 virtual void begin(); 00292 virtual void append( const QPoint & ); 00293 virtual void move( const QPoint & ); 00294 virtual void remove(); 00295 virtual bool end( bool ok = true ); 00296 00297 virtual bool accept( QPolygon & ) const; 00298 virtual void reset(); 00299 00300 virtual void widgetMousePressEvent( QMouseEvent * ); 00301 virtual void widgetMouseReleaseEvent( QMouseEvent * ); 00302 virtual void widgetMouseDoubleClickEvent( QMouseEvent * ); 00303 virtual void widgetMouseMoveEvent( QMouseEvent * ); 00304 virtual void widgetWheelEvent( QWheelEvent * ); 00305 virtual void widgetKeyPressEvent( QKeyEvent * ); 00306 virtual void widgetKeyReleaseEvent( QKeyEvent * ); 00307 virtual void widgetEnterEvent( QEvent * ); 00308 virtual void widgetLeaveEvent( QEvent * ); 00309 00310 virtual void stretchSelection( const QSize &oldSize, 00311 const QSize &newSize ); 00312 00313 virtual void updateDisplay(); 00314 00315 const QwtWidgetOverlay *rubberBandOverlay() const; 00316 const QwtWidgetOverlay *trackerOverlay() const; 00317 00318 const QPolygon &pickedPoints() const; 00319 00320 private: 00321 void init( QWidget *, RubberBand rubberBand, DisplayMode trackerMode ); 00322 00323 void setMouseTracking( bool ); 00324 00325 class PrivateData; 00326 PrivateData *d_data; 00327 }; 00328 00329 #endif