source: ntrip/trunk/BNC/qwtpolar/qwt_polar_magnifier.cpp@ 5349

Last change on this file since 5349 was 4272, checked in by mervart, 12 years ago
File size: 3.6 KB
Line 
1/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
2 * QwtPolar Widget Library
3 * Copyright (C) 2008 Uwe Rathmann
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the Qwt License, Version 1.0
7 *****************************************************************************/
8
9#include "qwt_polar_magnifier.h"
10#include "qwt_polar_plot.h"
11#include "qwt_polar_canvas.h"
12#include <qwt_scale_div.h>
13#include <qwt_point_polar.h>
14#include <qevent.h>
15
16class QwtPolarMagnifier::PrivateData
17{
18public:
19 PrivateData():
20 unzoomKey( Qt::Key_Home ),
21 unzoomKeyModifiers( Qt::NoModifier )
22 {
23 }
24
25 int unzoomKey;
26 int unzoomKeyModifiers;
27};
28
29/*!
30 Constructor
31 \param canvas Plot canvas to be magnified
32*/
33QwtPolarMagnifier::QwtPolarMagnifier( QwtPolarCanvas *canvas ):
34 QwtMagnifier( canvas )
35{
36 d_data = new PrivateData();
37}
38
39//! Destructor
40QwtPolarMagnifier::~QwtPolarMagnifier()
41{
42 delete d_data;
43}
44
45/*!
46 Assign key and modifiers, that are used for unzooming
47 The default combination is Qt::Key_Home + Qt::NoModifier.
48
49 \param key Key code
50 \param modifiers Modifiers
51 \sa getUnzoomKey(), QwtPolarPlot::unzoom()
52*/
53void QwtPolarMagnifier::setUnzoomKey( int key, int modifiers )
54{
55 d_data->unzoomKey = key;
56 d_data->unzoomKeyModifiers = modifiers;
57}
58
59/*!
60 \return Key, and modifiers that are used for unzooming
61
62 \param key Key code
63 \param modifiers Modifiers
64 \sa setUnzoomKey(), QwtPolarPlot::unzoom()
65*/
66void QwtPolarMagnifier::getUnzoomKey( int &key, int &modifiers ) const
67{
68 key = d_data->unzoomKey;
69 modifiers = d_data->unzoomKeyModifiers;
70}
71
72//! \return Observed plot canvas
73QwtPolarCanvas *QwtPolarMagnifier::canvas()
74{
75 return qobject_cast<QwtPolarCanvas *>( parent() );
76}
77
78//! \return Observed plot canvas
79const QwtPolarCanvas *QwtPolarMagnifier::canvas() const
80{
81 return qobject_cast<QwtPolarCanvas *>( parent() );
82}
83
84//! \return Observed plot
85QwtPolarPlot *QwtPolarMagnifier::plot()
86{
87 QwtPolarCanvas *c = canvas();
88 if ( c )
89 return c->plot();
90
91 return NULL;
92}
93
94//! \return observed plot
95const QwtPolarPlot *QwtPolarMagnifier::plot() const
96{
97 const QwtPolarCanvas *c = canvas();
98 if ( c )
99 return c->plot();
100
101 return NULL;
102}
103
104/*!
105 Handle a key press event for the observed widget.
106
107 \param event Key event
108*/
109void QwtPolarMagnifier::widgetKeyPressEvent( QKeyEvent *event )
110{
111 const int key = event->key();
112 const int state = event->modifiers();
113
114 if ( key == d_data->unzoomKey &&
115 state == d_data->unzoomKeyModifiers )
116 {
117 unzoom();
118 return;
119 }
120
121 QwtMagnifier::widgetKeyPressEvent( event );
122}
123
124/*!
125 Zoom in/out the zoomed area
126 \param factor A value < 1.0 zooms in, a value > 1.0 zooms out.
127*/
128void QwtPolarMagnifier::rescale( double factor )
129{
130 factor = qAbs( factor );
131 if ( factor == 1.0 || factor == 0.0 )
132 return;
133
134 QwtPolarPlot* plt = plot();
135 if ( plt == NULL )
136 return;
137
138 QwtPointPolar zoomPos;
139 double newZoomFactor = plt->zoomFactor() * factor;
140
141 if ( newZoomFactor >= 1.0 )
142 newZoomFactor = 1.0;
143 else
144 zoomPos = plt->zoomPos();
145
146 const bool autoReplot = plt->autoReplot();
147 plt->setAutoReplot( false );
148
149 plt->zoom( zoomPos, newZoomFactor );
150
151 plt->setAutoReplot( autoReplot );
152 plt->replot();
153}
154
155//! Unzoom the plot widget
156void QwtPolarMagnifier::unzoom()
157{
158 QwtPolarPlot* plt = plot();
159
160 const bool autoReplot = plt->autoReplot();
161 plt->setAutoReplot( false );
162
163 plt->unzoom();
164
165 plt->setAutoReplot( autoReplot );
166 plt->replot();
167}
Note: See TracBrowser for help on using the repository browser.