qwt_plot_zoomer.h 4.19 KB
Newer Older
pixhawk's avatar
pixhawk committed
1 2 3 4
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
 * Qwt Widget Library
 * Copyright (C) 1997   Josef Wilgen
 * Copyright (C) 2002   Uwe Rathmann
5
 *
pixhawk's avatar
pixhawk committed
6 7 8 9 10 11 12
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the Qwt License, Version 1.0
 *****************************************************************************/

#ifndef QWT_PLOT_ZOOMER_H
#define QWT_PLOT_ZOOMER_H

Bryant's avatar
Bryant committed
13
#include "qwt_global.h"
pixhawk's avatar
pixhawk committed
14
#include "qwt_plot_picker.h"
Bryant's avatar
Bryant committed
15
#include <qstack.h>
pixhawk's avatar
pixhawk committed
16 17 18 19

/*!
  \brief QwtPlotZoomer provides stacked zooming for a plot widget

Bryant's avatar
Bryant committed
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
  QwtPlotZoomer selects rectangles from user inputs ( mouse or keyboard )
  translates them into plot coordinates and adjusts the axes to them.
  The selection is supported by a rubber band and optionally by displaying
  the coordinates of the current mouse position.

  Zooming can be repeated as often as possible, limited only by 
  maxStackDepth() or minZoomSize().  Each rectangle is pushed on a stack.

  The default setting how to select rectangles is 
  a QwtPickerDragRectMachine with the following bindings:

  - QwtEventPattern::MouseSelect1\n
    The first point of the zoom rectangle is selected by a mouse press, 
    the second point from the position, where the mouse is released.

  - QwtEventPattern::KeySelect1\n
    The first key press selects the first, the second key press
    selects the second point.

  - QwtEventPattern::KeyAbort\n
    Discard the selection in the state, where the first point
    is selected.

  To traverse the zoom stack the following bindings are used:

  - QwtEventPattern::MouseSelect3, QwtEventPattern::KeyUndo\n
    Zoom out one position on the zoom stack
    
  - QwtEventPattern::MouseSelect6, QwtEventPattern::KeyRedo\n
    Zoom in one position on the zoom stack

  - QwtEventPattern::MouseSelect2, QwtEventPattern::KeyHome\n
    Zoom to the zoom base

  The setKeyPattern() and setMousePattern() functions can be used
  to configure the zoomer actions. The following example 
  shows, how to configure the 'I' and 'O' keys for zooming in and out 
  one position on the zoom stack. The "Home" key is used to 
  "unzoom" the plot.
pixhawk's avatar
pixhawk committed
59

Bryant's avatar
Bryant committed
60 61 62 63 64 65
  \code
   zoomer = new QwtPlotZoomer( plot );
   zoomer->setKeyPattern( QwtEventPattern::KeyRedo, Qt::Key_I, Qt::ShiftModifier );
   zoomer->setKeyPattern( QwtEventPattern::KeyUndo, Qt::Key_O, Qt::ShiftModifier );
   zoomer->setKeyPattern( QwtEventPattern::KeyHome, Qt::Key_Home );
  \endcode
66

pixhawk's avatar
pixhawk committed
67
  QwtPlotZoomer is tailored for plots with one x and y axis, but it is
Bryant's avatar
Bryant committed
68 69
  allowed to attach a second QwtPlotZoomer ( without rubber band and tracker )
  for the other axes.
pixhawk's avatar
pixhawk committed
70

71
  \note The realtime example includes an derived zoomer class that adds
pixhawk's avatar
pixhawk committed
72
        scrollbars to the plot canvas.
Bryant's avatar
Bryant committed
73 74

  \sa QwtPlotPanner, QwtPlotMagnifier
pixhawk's avatar
pixhawk committed
75 76 77 78 79 80
*/

class QWT_EXPORT QwtPlotZoomer: public QwtPlotPicker
{
    Q_OBJECT
public:
Bryant's avatar
Bryant committed
81 82 83
    explicit QwtPlotZoomer( QWidget *, bool doReplot = true );
    explicit QwtPlotZoomer( int xAxis, int yAxis,
                            QWidget *, bool doReplot = true );
pixhawk's avatar
pixhawk committed
84 85 86

    virtual ~QwtPlotZoomer();

Bryant's avatar
Bryant committed
87 88
    virtual void setZoomBase( bool doReplot = true );
    virtual void setZoomBase( const QRectF & );
pixhawk's avatar
pixhawk committed
89

Bryant's avatar
Bryant committed
90 91
    QRectF zoomBase() const;
    QRectF zoomRect() const;
pixhawk's avatar
pixhawk committed
92

Bryant's avatar
Bryant committed
93
    virtual void setAxis( int xAxis, int yAxis );
pixhawk's avatar
pixhawk committed
94

Bryant's avatar
Bryant committed
95
    void setMaxStackDepth( int );
pixhawk's avatar
pixhawk committed
96 97
    int maxStackDepth() const;

Bryant's avatar
Bryant committed
98 99 100
    const QStack<QRectF> &zoomStack() const;
    void setZoomStack( const QStack<QRectF> &,
        int zoomRectIndex = -1 );
Don Gagne's avatar
Don Gagne committed
101

Bryant's avatar
Bryant committed
102
    uint zoomRectIndex() const;
pixhawk's avatar
pixhawk committed
103

Bryant's avatar
Bryant committed
104 105 106
public Q_SLOTS:
    void moveBy( double x, double y );
    virtual void moveTo( const QPointF & );
Don Gagne's avatar
Don Gagne committed
107

Bryant's avatar
Bryant committed
108 109
    virtual void zoom( const QRectF & );
    virtual void zoom( int up );
pixhawk's avatar
pixhawk committed
110

Bryant's avatar
Bryant committed
111
Q_SIGNALS:
pixhawk's avatar
pixhawk committed
112
    /*!
113
      A signal emitting the zoomRect(), when the plot has been
pixhawk's avatar
pixhawk committed
114 115 116 117 118
      zoomed in or out.

      \param rect Current zoom rectangle.
    */

Bryant's avatar
Bryant committed
119
    void zoomed( const QRectF &rect );
pixhawk's avatar
pixhawk committed
120 121 122 123

protected:
    virtual void rescale();

Bryant's avatar
Bryant committed
124
    virtual QSizeF minZoomSize() const;
pixhawk's avatar
pixhawk committed
125

Bryant's avatar
Bryant committed
126 127
    virtual void widgetMouseReleaseEvent( QMouseEvent * );
    virtual void widgetKeyPressEvent( QKeyEvent * );
pixhawk's avatar
pixhawk committed
128 129

    virtual void begin();
Bryant's avatar
Bryant committed
130 131
    virtual bool end( bool ok = true );
    virtual bool accept( QPolygon & ) const;
pixhawk's avatar
pixhawk committed
132 133

private:
Bryant's avatar
Bryant committed
134
    void init( bool doReplot );
pixhawk's avatar
pixhawk committed
135 136 137 138

    class PrivateData;
    PrivateData *d_data;
};
139

pixhawk's avatar
pixhawk committed
140
#endif