10#include "qwt_plot_panner.h"
11#include "qwt_scale_div.h"
13#include "qwt_scale_map.h"
14#include "qwt_painter.h"
18#include <qstyleoption.h>
20#include <qpainterpath.h>
22static QBitmap qwtBorderMask(
const QWidget* canvas,
const QSize& size )
24#if QT_VERSION >= 0x050000
28 const QRect r( 0, 0, size.width(), size.height() );
30 QPainterPath borderPath;
32 ( void )QMetaObject::invokeMethod(
33 const_cast< QWidget*
>( canvas ),
"borderPath", Qt::DirectConnection,
34 Q_RETURN_ARG( QPainterPath, borderPath ), Q_ARG( QRect, r ) );
36 if ( borderPath.isEmpty() )
38 if ( canvas->contentsRect() == canvas->rect() )
41#if QT_VERSION >= 0x050000
42 QBitmap mask( size* pixelRatio );
43 mask.setDevicePixelRatio( pixelRatio );
47 mask.fill( Qt::color0 );
49 QPainter painter( &mask );
50 painter.fillRect( canvas->contentsRect(), Qt::color1 );
55#if QT_VERSION >= 0x050000
56 QImage image( size* pixelRatio, QImage::Format_ARGB32_Premultiplied );
57 image.setDevicePixelRatio( pixelRatio );
59 QImage image( size, QImage::Format_ARGB32_Premultiplied );
61 image.fill( Qt::color0 );
63 QPainter painter( &image );
64 painter.setClipPath( borderPath );
65 painter.fillRect( r, Qt::color1 );
69 painter.setCompositionMode( QPainter::CompositionMode_DestinationOut );
71 if ( canvas->testAttribute(Qt::WA_StyledBackground ) )
73 QStyleOptionFrame opt;
76 canvas->style()->drawPrimitive( QStyle::PE_Frame, &opt, &painter, canvas );
80 const QVariant borderRadius = canvas->property(
"borderRadius" );
81 const QVariant frameWidth = canvas->property(
"frameWidth" );
83 if ( borderRadius.canConvert<
double >() && frameWidth.canConvert<
int >() )
85 const double br = borderRadius.value<
double >();
86 const int fw = frameWidth.value<
int >();
88 if ( br > 0.0 && fw > 0 )
90 painter.setPen( QPen( Qt::color1, fw ) );
91 painter.setBrush( Qt::NoBrush );
92 painter.setRenderHint( QPainter::Antialiasing,
true );
94 painter.drawPath( borderPath );
101 const QImage mask = image.createMaskFromColor(
102 QColor( Qt::color1 ).rgb(), Qt::MaskOutColor );
104 return QBitmap::fromImage( mask );
107class QwtPlotPanner::PrivateData
112 for (
int axis = 0; axis < QwtAxis::AxisPositions; axis++ )
113 isAxisEnabled[axis] =
true;
116 bool isAxisEnabled[QwtAxis::AxisPositions];
131 m_data =
new PrivateData();
133 connect(
this, SIGNAL(
panned(
int,
int)),
157 m_data->isAxisEnabled[axisId] = on;
171 return m_data->isAxisEnabled[axisId];
179 return parentWidget();
185 return parentWidget();
193 w = w->parentWidget();
195 return qobject_cast< QwtPlot* >( w );
201 const QWidget* w =
canvas();
203 w = w->parentWidget();
205 return qobject_cast< const QwtPlot* >( w );
218 if ( dx == 0 && dy == 0 )
228 for (
int axisPos = 0; axisPos < QwtAxis::AxisPositions; axisPos++ )
231 const QwtAxisId axisId( axisPos );
233 if ( !m_data->isAxisEnabled[axisId] )
270 return qwtBorderMask(
canvas(), size() );
280 const QWidget* cv =
canvas();
281 if ( cv && cv->inherits(
"QGLWidget" ) )
285 QPixmap pm( cv->size() );
288 QPainter painter( &pm );
289 const_cast< QwtPlot*
>(
plot() )->drawCanvas( &painter );
297#include "moc_qwt_plot_panner.cpp"
static void fillPixmap(const QWidget *, QPixmap &, const QPoint &offset=QPoint())
static qreal devicePixelRatio(const QPaintDevice *)
QwtPanner provides panning of a widget.
virtual QBitmap contentsMask() const
Calculate a mask for the contents of the panned widget.
virtual QPixmap grab() const
void panned(int dx, int dy)
void setAxisScale(QwtAxisId, double min, double max, double stepSize=0)
Disable autoscaling and specify a fixed scale for a selected axis.
virtual void replot()
Redraw the plot.
void setAutoReplot(bool=true)
Set or reset the autoReplot option.
virtual QwtScaleMap canvasMap(QwtAxisId) const
const QwtScaleDiv & axisScaleDiv(QwtAxisId) const
Return the scale division of a specified axis.
QWidget * canvas()
Return observed plot canvas.
virtual QBitmap contentsMask() const override
QwtPlotPanner(QWidget *)
A panner for the canvas of a QwtPlot.
void setAxisEnabled(QwtAxisId axisId, bool on)
En/Disable an axis.
virtual ~QwtPlotPanner()
Destructor.
virtual void moveCanvas(int dx, int dy)
bool isAxisEnabled(QwtAxisId) const
QwtPlot * plot()
Return plot widget, containing the observed plot canvas.
virtual QPixmap grab() const override
double lowerBound() const
double upperBound() const
double transform(double s) const
double invTransform(double p) const
bool isValid(int axisPos)
bool isXAxis(int axisPos)