qwt_polar_magnifier.cpp
Go to the documentation of this file.
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 
18 {
19  public:
20  PrivateData()
21  : unzoomKey( Qt::Key_Home )
22  , unzoomKeyModifiers( Qt::NoModifier )
23  {
24  }
25 
26  int unzoomKey;
28 };
29 
35  : QwtMagnifier( canvas )
36 {
37  m_data = new PrivateData();
38 }
39 
42 {
43  delete m_data;
44 }
45 
54 void QwtPolarMagnifier::setUnzoomKey( int key, int modifiers )
55 {
56  m_data->unzoomKey = key;
57  m_data->unzoomKeyModifiers = modifiers;
58 }
59 
67 void 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 {
88  QwtPolarCanvas* c = canvas();
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 &&
117  {
118  unzoom();
119  return;
120  }
121 
123 }
124 
129 void 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 #if QWT_MOC_INCLUDE
171 #include "moc_qwt_polar_magnifier.cpp"
172 #endif
QwtPolarMagnifier::~QwtPolarMagnifier
virtual ~QwtPolarMagnifier()
Destructor.
Definition: qwt_polar_magnifier.cpp:41
QwtPolarMagnifier::canvas
QwtPolarCanvas * canvas()
Definition: qwt_polar_magnifier.cpp:74
QwtPolarPlot
A plotting widget, displaying a polar coordinate system.
Definition: qwt_polar_plot.h:46
detail::state
state
Definition: core.h:2305
qwt_scale_div.h
QwtPolarCanvas
Canvas of a QwtPolarPlot.
Definition: qwt_polar_canvas.h:27
QwtPolarMagnifier::rescale
virtual void rescale(double factor) QWT_OVERRIDE
Definition: qwt_polar_magnifier.cpp:129
QwtPolarMagnifier::PrivateData
Definition: qwt_polar_magnifier.cpp:17
QwtPolarMagnifier::plot
QwtPolarPlot * plot()
Definition: qwt_polar_magnifier.cpp:86
qwt_polar_canvas.h
QwtPolarPlot::zoom
void zoom(const QwtPointPolar &, double factor)
Translate and in/decrease the zoom factor.
Definition: qwt_polar_plot.cpp:651
QwtPointPolar
A point in polar coordinates.
Definition: qwt_point_polar.h:28
QwtMagnifier
QwtMagnifier provides zooming, by magnifying in steps.
Definition: qwt_magnifier.h:27
QwtMagnifier::widgetKeyPressEvent
virtual void widgetKeyPressEvent(QKeyEvent *)
Definition: qwt_magnifier.cpp:473
QwtPolarPlot::unzoom
void unzoom()
Definition: qwt_polar_plot.cpp:668
QwtPolarMagnifier::widgetKeyPressEvent
virtual void widgetKeyPressEvent(QKeyEvent *) QWT_OVERRIDE
Definition: qwt_polar_magnifier.cpp:110
QwtPolarMagnifier::PrivateData::unzoomKeyModifiers
int unzoomKeyModifiers
Definition: qwt_polar_magnifier.cpp:33
QwtPolarMagnifier::unzoom
void unzoom()
Unzoom the plot widget.
Definition: qwt_polar_magnifier.cpp:157
QwtPolarPlot::setAutoReplot
void setAutoReplot(bool tf=true)
Set or reset the autoReplot option.
Definition: qwt_polar_plot.cpp:342
qwt_point_polar.h
QwtPolarMagnifier::PrivateData::unzoomKey
int unzoomKey
Definition: qwt_polar_magnifier.cpp:32
QwtPolarPlot::autoReplot
bool autoReplot() const
Definition: qwt_polar_plot.cpp:348
QwtPolarCanvas::plot
QwtPolarPlot * plot()
Definition: qwt_polar_canvas.cpp:97
QwtPolarPlot::replot
virtual void replot()
Redraw the plot.
Definition: qwt_polar_plot.cpp:899
qwt_polar_plot.h
QwtPolarMagnifier::setUnzoomKey
void setUnzoomKey(int key, int modifiers)
Definition: qwt_polar_magnifier.cpp:54
QwtPolarPlot::zoomPos
QwtPointPolar zoomPos() const
Definition: qwt_polar_plot.cpp:682
QwtPolarMagnifier::QwtPolarMagnifier
QwtPolarMagnifier(QwtPolarCanvas *)
Definition: qwt_polar_magnifier.cpp:34
qwt_polar_magnifier.h
QwtPolarMagnifier::getUnzoomKey
void getUnzoomKey(int &key, int &modifiers) const
Definition: qwt_polar_magnifier.cpp:67
QwtPolarMagnifier::PrivateData::PrivateData
PrivateData()
Definition: qwt_polar_magnifier.cpp:26
QwtPolarPlot::zoomFactor
double zoomFactor() const
Definition: qwt_polar_plot.cpp:691
QwtPolarMagnifier::m_data
PrivateData * m_data
Definition: qwt_polar_magnifier.h:55


plotjuggler
Author(s): Davide Faconti
autogenerated on Mon Nov 11 2024 03:23:46