qwt_plot_zoomer.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
  2. * Qwt Widget Library
  3. * Copyright (C) 1997 Josef Wilgen
  4. * Copyright (C) 2002 Uwe Rathmann
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the Qwt License, Version 1.0
  8. *****************************************************************************/
  9. #ifndef QWT_PLOT_ZOOMER_H
  10. #define QWT_PLOT_ZOOMER_H
  11. #include "qwt_global.h"
  12. #include "qwt_plot_picker.h"
  13. #include <qstack.h>
  14. /*!
  15. \brief QwtPlotZoomer provides stacked zooming for a plot widget
  16. QwtPlotZoomer selects rectangles from user inputs ( mouse or keyboard )
  17. translates them into plot coordinates and adjusts the axes to them.
  18. The selection is supported by a rubber band and optionally by displaying
  19. the coordinates of the current mouse position.
  20. Zooming can be repeated as often as possible, limited only by
  21. maxStackDepth() or minZoomSize(). Each rectangle is pushed on a stack.
  22. The default setting how to select rectangles is
  23. a QwtPickerDragRectMachine with the following bindings:
  24. - QwtEventPattern::MouseSelect1\n
  25. The first point of the zoom rectangle is selected by a mouse press,
  26. the second point from the position, where the mouse is released.
  27. - QwtEventPattern::KeySelect1\n
  28. The first key press selects the first, the second key press
  29. selects the second point.
  30. - QwtEventPattern::KeyAbort\n
  31. Discard the selection in the state, where the first point
  32. is selected.
  33. To traverse the zoom stack the following bindings are used:
  34. - QwtEventPattern::MouseSelect3, QwtEventPattern::KeyUndo\n
  35. Zoom out one position on the zoom stack
  36. - QwtEventPattern::MouseSelect6, QwtEventPattern::KeyRedo\n
  37. Zoom in one position on the zoom stack
  38. - QwtEventPattern::MouseSelect2, QwtEventPattern::KeyHome\n
  39. Zoom to the zoom base
  40. The setKeyPattern() and setMousePattern() functions can be used
  41. to configure the zoomer actions. The following example
  42. shows, how to configure the 'I' and 'O' keys for zooming in and out
  43. one position on the zoom stack. The "Home" key is used to
  44. "unzoom" the plot.
  45. \code
  46. zoomer = new QwtPlotZoomer( plot );
  47. zoomer->setKeyPattern( QwtEventPattern::KeyRedo, Qt::Key_I, Qt::ShiftModifier );
  48. zoomer->setKeyPattern( QwtEventPattern::KeyUndo, Qt::Key_O, Qt::ShiftModifier );
  49. zoomer->setKeyPattern( QwtEventPattern::KeyHome, Qt::Key_Home );
  50. \endcode
  51. QwtPlotZoomer is tailored for plots with one x and y axis, but it is
  52. allowed to attach a second QwtPlotZoomer ( without rubber band and tracker )
  53. for the other axes.
  54. \note The realtime example includes an derived zoomer class that adds
  55. scrollbars to the plot canvas.
  56. \sa QwtPlotPanner, QwtPlotMagnifier
  57. */
  58. class QWT_EXPORT QwtPlotZoomer: public QwtPlotPicker
  59. {
  60. Q_OBJECT
  61. public:
  62. explicit QwtPlotZoomer( QWidget *, bool doReplot = true );
  63. explicit QwtPlotZoomer( int xAxis, int yAxis,
  64. QWidget *, bool doReplot = true );
  65. virtual ~QwtPlotZoomer();
  66. virtual void setZoomBase( bool doReplot = true );
  67. virtual void setZoomBase( const QRectF & );
  68. QRectF zoomBase() const;
  69. QRectF zoomRect() const;
  70. virtual void setAxis( int xAxis, int yAxis );
  71. void setMaxStackDepth( int );
  72. int maxStackDepth() const;
  73. const QStack<QRectF> &zoomStack() const;
  74. void setZoomStack( const QStack<QRectF> &,
  75. int zoomRectIndex = -1 );
  76. uint zoomRectIndex() const;
  77. public Q_SLOTS:
  78. void moveBy( double dx, double dy );
  79. virtual void moveTo( const QPointF & );
  80. virtual void zoom( const QRectF & );
  81. virtual void zoom( int offset );
  82. Q_SIGNALS:
  83. /*!
  84. A signal emitting the zoomRect(), when the plot has been
  85. zoomed in or out.
  86. \param rect Current zoom rectangle.
  87. */
  88. void zoomed( const QRectF &rect );
  89. protected:
  90. virtual void rescale();
  91. virtual QSizeF minZoomSize() const;
  92. virtual void widgetMouseReleaseEvent( QMouseEvent * );
  93. virtual void widgetKeyPressEvent( QKeyEvent * );
  94. virtual void begin();
  95. virtual bool end( bool ok = true );
  96. virtual bool accept( QPolygon & ) const;
  97. private:
  98. void init( bool doReplot );
  99. class PrivateData;
  100. PrivateData *d_data;
  101. };
  102. #endif