Qwt User's Guide 6.3.0
Loading...
Searching...
No Matches
qwt_polar_magnifier.cpp
1/******************************************************************************
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
15#include <qevent.h>
16
17class QwtPolarMagnifier::PrivateData
18{
19 public:
20 PrivateData()
21 : unzoomKey( Qt::Key_Home )
22 , unzoomKeyModifiers( Qt::NoModifier )
23 {
24 }
25
26 int unzoomKey;
27 int unzoomKeyModifiers;
28};
29
35 : QwtMagnifier( canvas )
36{
37 m_data = new PrivateData();
38}
39
42{
43 delete m_data;
44}
45
54void QwtPolarMagnifier::setUnzoomKey( int key, int modifiers )
55{
56 m_data->unzoomKey = key;
57 m_data->unzoomKeyModifiers = modifiers;
58}
59
67void QwtPolarMagnifier::getUnzoomKey( int& key, int& modifiers ) const
68{
69 key = m_data->unzoomKey;
70 modifiers = m_data->unzoomKeyModifiers;
71}
72
75{
76 return qobject_cast< QwtPolarCanvas* >( parent() );
77}
78
81{
82 return qobject_cast< QwtPolarCanvas* >( parent() );
83}
84
87{
89 if ( c )
90 return c->plot();
91
92 return NULL;
93}
94
97{
98 const QwtPolarCanvas* c = canvas();
99 if ( c )
100 return c->plot();
101
102 return NULL;
103}
104
111{
112 const int key = event->key();
113 const int state = event->modifiers();
114
115 if ( key == m_data->unzoomKey &&
116 state == m_data->unzoomKeyModifiers )
117 {
118 unzoom();
119 return;
120 }
121
123}
124
129void QwtPolarMagnifier::rescale( double factor )
130{
131 factor = qAbs( factor );
132 if ( factor == 1.0 || factor == 0.0 )
133 return;
134
135 QwtPolarPlot* plt = plot();
136 if ( plt == NULL )
137 return;
138
139 QwtPointPolar zoomPos;
140 double newZoomFactor = plt->zoomFactor() * factor;
141
142 if ( newZoomFactor >= 1.0 )
143 newZoomFactor = 1.0;
144 else
145 zoomPos = plt->zoomPos();
146
147 const bool autoReplot = plt->autoReplot();
148 plt->setAutoReplot( false );
149
150 plt->zoom( zoomPos, newZoomFactor );
151
152 plt->setAutoReplot( autoReplot );
153 plt->replot();
154}
155
158{
159 QwtPolarPlot* plt = plot();
160
161 const bool autoReplot = plt->autoReplot();
162 plt->setAutoReplot( false );
163
164 plt->unzoom();
165
166 plt->setAutoReplot( autoReplot );
167 plt->replot();
168}
169
170#include "moc_qwt_polar_magnifier.cpp"
QwtMagnifier provides zooming, by magnifying in steps.
virtual void widgetKeyPressEvent(QKeyEvent *)
A point in polar coordinates.
Canvas of a QwtPolarPlot.
QwtPolarPlot * plot()
virtual void widgetKeyPressEvent(QKeyEvent *) override
void getUnzoomKey(int &key, int &modifiers) const
void unzoom()
Unzoom the plot widget.
void setUnzoomKey(int key, int modifiers)
virtual void rescale(double factor) override
QwtPolarCanvas * canvas()
QwtPolarMagnifier(QwtPolarCanvas *)
virtual ~QwtPolarMagnifier()
Destructor.
A plotting widget, displaying a polar coordinate system.
QwtPointPolar zoomPos() const
virtual void replot()
Redraw the plot.
void zoom(const QwtPointPolar &, double factor)
Translate and in/decrease the zoom factor.
double zoomFactor() const
bool autoReplot() const
void setAutoReplot(bool tf=true)
Set or reset the autoReplot option.