18 #include <qstyleoption.h> 20 #include <qpainterpath.h> 22 static 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.type() == QVariant::Double
84 && frameWidth.type() == QVariant::Int )
86 const double br = borderRadius.toDouble();
87 const int fw = frameWidth.toInt();
89 if ( br > 0.0 && fw > 0 )
91 painter.setPen( QPen( Qt::color1, fw ) );
92 painter.setBrush( Qt::NoBrush );
93 painter.setRenderHint( QPainter::Antialiasing,
true );
95 painter.drawPath( borderPath );
102 const QImage mask = image.createMaskFromColor(
103 QColor( Qt::color1 ).rgb(), Qt::MaskOutColor );
105 return QBitmap::fromImage( mask );
134 connect(
this, SIGNAL(
panned(
int,
int)),
180 return parentWidget();
186 return parentWidget();
194 w = w->parentWidget();
196 return qobject_cast<
QwtPlot *>( w );
202 const QWidget *w =
canvas();
204 w = w->parentWidget();
206 return qobject_cast<
const QwtPlot *>( w );
219 if ( dx == 0 && dy == 0 )
277 const QWidget *cv =
canvas();
278 if ( cv && cv->inherits(
"QGLWidget" ) )
282 QPixmap pm( cv->size() );
285 QPainter painter( &pm );
286 const_cast<QwtPlot *
>(
plot() )->drawCanvas( &painter );
295 #include "moc_qwt_plot_panner.cpp" QwtPlotPanner(QWidget *)
A panner for the canvas of a QwtPlot.
static void fillPixmap(const QWidget *, QPixmap &, const QPoint &offset=QPoint())
const QwtScaleDiv & axisScaleDiv(int axisId) const
Return the scale division of a specified axis.
bool isAxisEnabled(int axis) const
virtual QBitmap contentsMask() const
Calculate a mask for the contents of the panned widget.
virtual ~QwtPlotPanner()
Destructor.
void setAutoReplot(bool=true)
Set or reset the autoReplot option.
QwtPanner provides panning of a widget.
virtual void replot()
Redraw the plot.
virtual QPixmap grab() const QWT_OVERRIDE
void setAxisEnabled(int axis, bool on)
En/Disable an axis.
double upperBound() const
double lowerBound() const
static qreal devicePixelRatio(const QPaintDevice *)
virtual QBitmap contentsMask() const QWT_OVERRIDE
virtual QwtScaleMap canvasMap(int axisId) const
void panned(int dx, int dy)
QwtPlot * plot()
Return plot widget, containing the observed plot canvas.
static QBitmap qwtBorderMask(const QWidget *canvas, const QSize &size)
double invTransform(double p) const
virtual QPixmap grab() const
QWidget * canvas()
Return observed plot canvas.
void setAxisScale(int axisId, double min, double max, double stepSize=0)
Disable autoscaling and specify a fixed scale for a selected axis.
virtual void moveCanvas(int dx, int dy)
bool isAxisEnabled[QwtPlot::axisCnt]
double transform(double s) const