Loading...
Searching...
No Matches
qwt_polar_magnifier.cpp
/******************************************************************************
* QwtPolar Widget Library
* Copyright (C) 2008 Uwe Rathmann
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the Qwt License, Version 1.0
*****************************************************************************/
#include "qwt_polar_magnifier.h"
#include "qwt_polar_plot.h"
#include "qwt_polar_canvas.h"
#include "qwt_scale_div.h"
#include "qwt_point_polar.h"
#include <qevent.h>
class QwtPolarMagnifier::PrivateData
{
public:
PrivateData()
: unzoomKey( Qt::Key_Home )
, unzoomKeyModifiers( Qt::NoModifier )
{
}
int unzoomKey;
int unzoomKeyModifiers;
};
QwtPolarMagnifier::QwtPolarMagnifier( QwtPolarCanvas* canvas )
: QwtMagnifier( canvas )
{
m_data = new PrivateData();
}
QwtPolarMagnifier::~QwtPolarMagnifier()
{
delete m_data;
}
void QwtPolarMagnifier::setUnzoomKey( int key, int modifiers )
{
m_data->unzoomKey = key;
m_data->unzoomKeyModifiers = modifiers;
}
void QwtPolarMagnifier::getUnzoomKey( int& key, int& modifiers ) const
{
key = m_data->unzoomKey;
modifiers = m_data->unzoomKeyModifiers;
}
QwtPolarCanvas* QwtPolarMagnifier::canvas()
{
return qobject_cast< QwtPolarCanvas* >( parent() );
}
const QwtPolarCanvas* QwtPolarMagnifier::canvas() const
{
return qobject_cast< QwtPolarCanvas* >( parent() );
}
QwtPolarPlot* QwtPolarMagnifier::plot()
{
QwtPolarCanvas* c = canvas();
if ( c )
return c->plot();
return NULL;
}
const QwtPolarPlot* QwtPolarMagnifier::plot() const
{
const QwtPolarCanvas* c = canvas();
if ( c )
return c->plot();
return NULL;
}
void QwtPolarMagnifier::widgetKeyPressEvent( QKeyEvent* event )
{
const int key = event->key();
const int state = event->modifiers();
if ( key == m_data->unzoomKey &&
state == m_data->unzoomKeyModifiers )
{
unzoom();
return;
}
QwtMagnifier::widgetKeyPressEvent( event );
}
void QwtPolarMagnifier::rescale( double factor )
{
factor = qAbs( factor );
if ( factor == 1.0 || factor == 0.0 )
return;
QwtPolarPlot* plt = plot();
if ( plt == NULL )
return;
QwtPointPolar zoomPos;
double newZoomFactor = plt->zoomFactor() * factor;
if ( newZoomFactor >= 1.0 )
newZoomFactor = 1.0;
else
zoomPos = plt->zoomPos();
const bool autoReplot = plt->autoReplot();
plt->setAutoReplot( false );
plt->zoom( zoomPos, newZoomFactor );
plt->setAutoReplot( autoReplot );
plt->replot();
}
void QwtPolarMagnifier::unzoom()
{
QwtPolarPlot* plt = plot();
const bool autoReplot = plt->autoReplot();
plt->setAutoReplot( false );
plt->unzoom();
plt->setAutoReplot( autoReplot );
plt->replot();
}
#include "moc_qwt_polar_magnifier.cpp"
QwtMagnifier
QwtMagnifier provides zooming, by magnifying in steps.
Definition qwt_magnifier.h:28
QwtMagnifier::widgetKeyPressEvent
virtual void widgetKeyPressEvent(QKeyEvent *)
Definition qwt_magnifier.cpp:473
QwtPointPolar
A point in polar coordinates.
Definition qwt_point_polar.h:29
QwtPolarCanvas
Canvas of a QwtPolarPlot.
Definition qwt_polar_canvas.h:28
QwtPolarCanvas::plot
QwtPolarPlot * plot()
Definition qwt_polar_canvas.cpp:97
QwtPolarMagnifier::widgetKeyPressEvent
virtual void widgetKeyPressEvent(QKeyEvent *) override
Definition qwt_polar_magnifier.cpp:110
QwtPolarMagnifier::getUnzoomKey
void getUnzoomKey(int &key, int &modifiers) const
Definition qwt_polar_magnifier.cpp:67
QwtPolarMagnifier::unzoom
void unzoom()
Unzoom the plot widget.
Definition qwt_polar_magnifier.cpp:157
QwtPolarMagnifier::setUnzoomKey
void setUnzoomKey(int key, int modifiers)
Definition qwt_polar_magnifier.cpp:54
QwtPolarMagnifier::rescale
virtual void rescale(double factor) override
Definition qwt_polar_magnifier.cpp:129
QwtPolarMagnifier::plot
QwtPolarPlot * plot()
Definition qwt_polar_magnifier.cpp:86
QwtPolarMagnifier::canvas
QwtPolarCanvas * canvas()
Definition qwt_polar_magnifier.cpp:74
QwtPolarMagnifier::QwtPolarMagnifier
QwtPolarMagnifier(QwtPolarCanvas *)
Definition qwt_polar_magnifier.cpp:34
QwtPolarMagnifier::~QwtPolarMagnifier
virtual ~QwtPolarMagnifier()
Destructor.
Definition qwt_polar_magnifier.cpp:41
QwtPolarPlot
A plotting widget, displaying a polar coordinate system.
Definition qwt_polar_plot.h:47
QwtPolarPlot::zoomPos
QwtPointPolar zoomPos() const
Definition qwt_polar_plot.cpp:682
QwtPolarPlot::unzoom
void unzoom()
Definition qwt_polar_plot.cpp:668
QwtPolarPlot::replot
virtual void replot()
Redraw the plot.
Definition qwt_polar_plot.cpp:899
QwtPolarPlot::zoom
void zoom(const QwtPointPolar &, double factor)
Translate and in/decrease the zoom factor.
Definition qwt_polar_plot.cpp:651
QwtPolarPlot::zoomFactor
double zoomFactor() const
Definition qwt_polar_plot.cpp:691
QwtPolarPlot::autoReplot
bool autoReplot() const
Definition qwt_polar_plot.cpp:348
QwtPolarPlot::setAutoReplot
void setAutoReplot(bool tf=true)
Set or reset the autoReplot option.
Definition qwt_polar_plot.cpp:342