source: ntrip/trunk/BNC/qwtpolar/qwt_polar_panner.cpp@ 9550

Last change on this file since 9550 was 4272, checked in by mervart, 12 years ago
File size: 2.9 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_panner.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//! Create a plot panner for a polar plot canvas
16QwtPolarPanner::QwtPolarPanner( QwtPolarCanvas *canvas ):
17 QwtPanner( canvas )
18{
19 connect( this, SIGNAL( panned( int, int ) ),
20 SLOT( movePlot( int, int ) ) );
21}
22
23//! Destructor
24QwtPolarPanner::~QwtPolarPanner()
25{
26}
27
28//! \return observed plot canvas
29QwtPolarCanvas *QwtPolarPanner::canvas()
30{
31 return qobject_cast<QwtPolarCanvas *>( parent() );
32}
33
34//! \return observed plot canvas
35const QwtPolarCanvas *QwtPolarPanner::canvas() const
36{
37 return qobject_cast<const QwtPolarCanvas *>( parent() );
38}
39
40//! \return observed plot
41QwtPolarPlot *QwtPolarPanner::plot()
42{
43 QwtPolarCanvas *c = canvas();
44 if ( c )
45 return c->plot();
46
47 return NULL;
48}
49
50//! \return observed plot
51const QwtPolarPlot *QwtPolarPanner::plot() const
52{
53 const QwtPolarCanvas *c = canvas();
54 if ( c )
55 return c->plot();
56
57 return NULL;
58}
59
60/*!
61 Adjust the zoomed area according to dx/dy
62
63 \param dx Pixel offset in x direction
64 \param dy Pixel offset in y direction
65
66 \sa QwtPanner::panned(), QwtPolarPlot::zoom()
67*/
68void QwtPolarPanner::movePlot( int dx, int dy )
69{
70 QwtPolarPlot *plot = QwtPolarPanner::plot();
71 if ( plot == NULL || ( dx == 0 && dy == 0 ) )
72 return;
73
74 const QwtScaleMap map = plot->scaleMap( QwtPolar::Radius );
75
76 QwtPointPolar pos = plot->zoomPos();
77 if ( map.s1() <= map.s2() )
78 {
79 pos.setRadius(
80 map.transform( map.s1() + pos.radius() ) - map.p1() );
81 pos.setPoint( pos.toPoint() - QPointF( dx, -dy ) );
82 pos.setRadius(
83 map.invTransform( map.p1() + pos.radius() ) - map.s1() );
84 }
85 else
86 {
87 pos.setRadius(
88 map.transform( map.s1() - pos.radius() ) - map.p1() );
89 pos.setPoint( pos.toPoint() - QPointF( dx, -dy ) );
90 pos.setRadius(
91 map.s1() - map.invTransform( map.p1() + pos.radius() ) );
92 }
93
94 const bool doAutoReplot = plot->autoReplot();
95 plot->setAutoReplot( false );
96
97 plot->zoom( pos, plot->zoomFactor() );
98
99 plot->setAutoReplot( doAutoReplot );
100 plot->replot();
101}
102
103/*!
104 Block panning when the plot zoom factor is >= 1.0.
105
106 \param event Mouse event
107*/
108void QwtPolarPanner::widgetMousePressEvent( QMouseEvent *event )
109{
110 const QwtPolarPlot *plot = QwtPolarPanner::plot();
111 if ( plot )
112 {
113 if ( plot->zoomFactor() < 1.0 )
114 QwtPanner::widgetMousePressEvent( event );
115 }
116}
117
118
Note: See TracBrowser for help on using the repository browser.