#include <qwt_plot_canvas.h>

Classes | |
| class | PrivateData |
Public Types | |
| enum | PaintAttribute { PaintCached = 1, PaintPacked = 2 } |
Paint attributes. More... | |
| enum | FocusIndicator { NoFocusIndicator, CanvasFocusIndicator, ItemFocusIndicator } |
Focus indicator. More... | |
Public Member Functions | |
| QwtPlotCanvas (QwtPlot *) | |
| Sets a cross cursor, enables QwtPlotCanvas::PaintCached. | |
| virtual | ~QwtPlotCanvas () |
| Destructor. | |
| QwtPlot * | plot () |
| Return parent plot widget. | |
| const QwtPlot * | plot () const |
| Return parent plot widget. | |
| void | setFocusIndicator (FocusIndicator) |
| FocusIndicator | focusIndicator () const |
| void | setPaintAttribute (PaintAttribute, bool on=true) |
| Changing the paint attributes. | |
| bool | testPaintAttribute (PaintAttribute) const |
| QPixmap * | paintCache () |
| Return the paint cache, might be null. | |
| const QPixmap * | paintCache () const |
| Return the paint cache, might be null. | |
| void | invalidatePaintCache () |
| Invalidate the internal paint cache. | |
| void | replot () |
Protected Member Functions | |
| virtual void | hideEvent (QHideEvent *) |
| virtual void | paintEvent (QPaintEvent *) |
| virtual void | drawContents (QPainter *) |
| virtual void | drawFocusIndicator (QPainter *) |
| void | drawCanvas (QPainter *painter=NULL) |
Canvas of a QwtPlot.
Definition at line 26 of file qwt_plot_canvas.h.
Focus indicator.
Definition at line 77 of file qwt_plot_canvas.h.
Paint attributes.
The default setting enables PaintCached and PaintPacked
Definition at line 53 of file qwt_plot_canvas.h.
{
PaintCached = 1,
PaintPacked = 2
};
| QwtPlotCanvas::QwtPlotCanvas | ( | QwtPlot * | plot ) | [explicit] |
Sets a cross cursor, enables QwtPlotCanvas::PaintCached.
Definition at line 50 of file qwt_plot_canvas.cpp.
References PaintCached, PaintPacked, and setPaintAttribute().
:
QFrame(plot)
{
d_data = new PrivateData;
#if QT_VERSION >= 0x040100
setAutoFillBackground(true);
#endif
#if QT_VERSION < 0x040000
setWFlags(Qt::WNoAutoErase);
#ifndef QT_NO_CURSOR
setCursor(Qt::crossCursor);
#endif
#else
#ifndef QT_NO_CURSOR
setCursor(Qt::CrossCursor);
#endif
#endif // >= 0x040000
setPaintAttribute(PaintCached, true);
setPaintAttribute(PaintPacked, true);
}
| QwtPlotCanvas::~QwtPlotCanvas | ( | ) | [virtual] |
| void QwtPlotCanvas::drawCanvas | ( | QPainter * | painter = NULL ) |
[protected] |
Draw the the canvas
Paints all plot items to the contentsRect(), using QwtPlot::drawCanvas and updates the paint cache.
| painter | Painter |
Definition at line 292 of file qwt_plot_canvas.cpp.
References QwtPlotCanvas::PrivateData::cache, QwtPlotCanvas::PrivateData::paintAttributes, PaintCached, and PaintPacked.
Referenced by drawContents().
{
if ( !contentsRect().isValid() )
return;
QBrush bgBrush;
#if QT_VERSION >= 0x040000
bgBrush = palette().brush(backgroundRole());
#else
QColorGroup::ColorRole role =
QPalette::backgroundRoleFromMode( backgroundMode() );
bgBrush = colorGroup().brush( role );
#endif
if ( d_data->paintAttributes & PaintCached && d_data->cache )
{
*d_data->cache = QPixmap(contentsRect().size());
#ifdef Q_WS_X11
#if QT_VERSION >= 0x040000
if ( d_data->cache->x11Info().screen() != x11Info().screen() )
d_data->cache->x11SetScreen(x11Info().screen());
#else
if ( d_data->cache->x11Screen() != x11Screen() )
d_data->cache->x11SetScreen(x11Screen());
#endif
#endif
if ( d_data->paintAttributes & PaintPacked )
{
QPainter bgPainter(d_data->cache);
bgPainter.setPen(Qt::NoPen);
bgPainter.setBrush(bgBrush);
bgPainter.drawRect(d_data->cache->rect());
}
else
d_data->cache->fill(this, d_data->cache->rect().topLeft());
QPainter cachePainter(d_data->cache);
cachePainter.translate(-contentsRect().x(),
-contentsRect().y());
((QwtPlot *)parent())->drawCanvas(&cachePainter);
cachePainter.end();
painter->drawPixmap(contentsRect(), *d_data->cache);
}
else
{
#if QT_VERSION >= 0x040000
if ( d_data->paintAttributes & PaintPacked )
#endif
{
painter->save();
painter->setPen(Qt::NoPen);
painter->setBrush(bgBrush);
painter->drawRect(contentsRect());
painter->restore();
}
((QwtPlot *)parent())->drawCanvas(painter);
}
}
| void QwtPlotCanvas::drawContents | ( | QPainter * | painter ) | [protected, virtual] |
Redraw the canvas, and focus rect
| painter | Painter |
Definition at line 260 of file qwt_plot_canvas.cpp.
References QwtPlot::autoReplot(), QwtPlotCanvas::PrivateData::cache, CanvasFocusIndicator, drawCanvas(), drawFocusIndicator(), focusIndicator(), QwtPlotCanvas::PrivateData::paintAttributes, PaintCached, plot(), and QwtPlot::setAutoReplot().
Referenced by paintEvent().
{
if ( d_data->paintAttributes & PaintCached && d_data->cache
&& d_data->cache->size() == contentsRect().size() )
{
painter->drawPixmap(contentsRect().topLeft(), *d_data->cache);
}
else
{
QwtPlot *plot = ((QwtPlot *)parent());
const bool doAutoReplot = plot->autoReplot();
plot->setAutoReplot(false);
drawCanvas(painter);
plot->setAutoReplot(doAutoReplot);
}
if ( hasFocus() && focusIndicator() == CanvasFocusIndicator )
drawFocusIndicator(painter);
}
| void QwtPlotCanvas::drawFocusIndicator | ( | QPainter * | painter ) | [protected, virtual] |
Draw the focus indication
| painter | Painter |
Definition at line 364 of file qwt_plot_canvas.cpp.
References QwtPainter::drawFocusRect().
Referenced by drawContents().
{
const int margin = 1;
QRect focusRect = contentsRect();
focusRect.setRect(focusRect.x() + margin, focusRect.y() + margin,
focusRect.width() - 2 * margin, focusRect.height() - 2 * margin);
QwtPainter::drawFocusRect(painter, this, focusRect);
}
| QwtPlotCanvas::FocusIndicator QwtPlotCanvas::focusIndicator | ( | ) | const |
Definition at line 206 of file qwt_plot_canvas.cpp.
References QwtPlotCanvas::PrivateData::focusIndicator.
Referenced by drawContents(), and setFocusIndicator().
{
return d_data->focusIndicator;
}
| void QwtPlotCanvas::hideEvent | ( | QHideEvent * | event ) | [protected, virtual] |
Hide event
| event | Hide event |
Definition at line 215 of file qwt_plot_canvas.cpp.
References QwtPlotCanvas::PrivateData::paintAttributes, and PaintPacked.
{
QFrame::hideEvent(event);
if ( d_data->paintAttributes & PaintPacked )
{
// enable system background to avoid the "looking through
// the canvas" effect, for the next show
setSystemBackground(true);
}
}
| void QwtPlotCanvas::invalidatePaintCache | ( | ) |
Invalidate the internal paint cache.
Definition at line 185 of file qwt_plot_canvas.cpp.
References QwtPlotCanvas::PrivateData::cache.
Referenced by replot().
| const QPixmap * QwtPlotCanvas::paintCache | ( | ) | const |
Return the paint cache, might be null.
Definition at line 179 of file qwt_plot_canvas.cpp.
References QwtPlotCanvas::PrivateData::cache.
{
return d_data->cache;
}
| QPixmap * QwtPlotCanvas::paintCache | ( | ) |
Return the paint cache, might be null.
Definition at line 173 of file qwt_plot_canvas.cpp.
References QwtPlotCanvas::PrivateData::cache.
Referenced by QwtPlotCurve::draw().
{
return d_data->cache;
}
| void QwtPlotCanvas::paintEvent | ( | QPaintEvent * | event ) | [protected, virtual] |
Paint event
| event | Paint event |
Definition at line 232 of file qwt_plot_canvas.cpp.
References drawContents(), QwtPlotCanvas::PrivateData::paintAttributes, and PaintPacked.
{
#if QT_VERSION >= 0x040000
QPainter painter(this);
if ( !contentsRect().contains( event->rect() ) )
{
painter.save();
painter.setClipRegion( event->region() & frameRect() );
drawFrame( &painter );
painter.restore();
}
painter.setClipRegion(event->region() & contentsRect());
drawContents( &painter );
#else // QT_VERSION < 0x040000
QFrame::paintEvent(event);
#endif
if ( d_data->paintAttributes & PaintPacked )
setSystemBackground(false);
}
| const QwtPlot * QwtPlotCanvas::plot | ( | ) | const |
Return parent plot widget.
Definition at line 91 of file qwt_plot_canvas.cpp.
{
const QWidget *w = parentWidget();
if ( w && w->inherits("QwtPlot") )
return (QwtPlot *)w;
return NULL;
}
| QwtPlot * QwtPlotCanvas::plot | ( | ) |
Return parent plot widget.
Definition at line 81 of file qwt_plot_canvas.cpp.
Referenced by drawContents().
{
QWidget *w = parentWidget();
if ( w && w->inherits("QwtPlot") )
return (QwtPlot *)w;
return NULL;
}
| void QwtPlotCanvas::replot | ( | ) |
Invalidate the paint cache and repaint the canvas
Definition at line 398 of file qwt_plot_canvas.cpp.
References invalidatePaintCache(), PaintCached, PaintPacked, and testPaintAttribute().
{
invalidatePaintCache();
/*
In case of cached or packed painting the canvas
is repainted completely and doesn't need to be erased.
*/
const bool erase =
!testPaintAttribute(QwtPlotCanvas::PaintPacked)
&& !testPaintAttribute(QwtPlotCanvas::PaintCached);
#if QT_VERSION >= 0x040000
const bool noBackgroundMode = testAttribute(Qt::WA_NoBackground);
if ( !erase && !noBackgroundMode )
setAttribute(Qt::WA_NoBackground, true);
repaint(contentsRect());
if ( !erase && !noBackgroundMode )
setAttribute(Qt::WA_NoBackground, false);
#else
repaint(contentsRect(), erase);
#endif
}
| void QwtPlotCanvas::setFocusIndicator | ( | FocusIndicator | focusIndicator ) |
Set the focus indicator
Definition at line 196 of file qwt_plot_canvas.cpp.
References focusIndicator(), and QwtPlotCanvas::PrivateData::focusIndicator.
{
d_data->focusIndicator = focusIndicator;
}
| void QwtPlotCanvas::setPaintAttribute | ( | PaintAttribute | attribute, |
| bool | on = true |
||
| ) |
Changing the paint attributes.
| attribute | Paint attribute |
| on | On/Off |
The default setting enables PaintCached and PaintPacked
Definition at line 110 of file qwt_plot_canvas.cpp.
References QwtPlotCanvas::PrivateData::cache, QwtPlotCanvas::PrivateData::paintAttributes, PaintCached, and PaintPacked.
Referenced by QwtPlotCanvas().
{
if ( bool(d_data->paintAttributes & attribute) == on )
return;
if ( on )
d_data->paintAttributes |= attribute;
else
d_data->paintAttributes &= ~attribute;
switch(attribute)
{
case PaintCached:
{
if ( on )
{
if ( d_data->cache == NULL )
d_data->cache = new QPixmap();
if ( isVisible() )
{
const QRect cr = contentsRect();
*d_data->cache = QPixmap::grabWidget(this,
cr.x(), cr.y(), cr.width(), cr.height() );
}
}
else
{
delete d_data->cache;
d_data->cache = NULL;
}
break;
}
case PaintPacked:
{
/*
If not visible, changing of the background mode
is delayed until it becomes visible. This tries to avoid
looking through the canvas when the canvas is shown the first
time.
*/
if ( on == false || isVisible() )
QwtPlotCanvas::setSystemBackground(!on);
break;
}
}
}
| bool QwtPlotCanvas::testPaintAttribute | ( | PaintAttribute | attribute ) | const |
Test wether a paint attribute is enabled
| attribute | Paint attribute |
Definition at line 167 of file qwt_plot_canvas.cpp.
References QwtPlotCanvas::PrivateData::paintAttributes.
Referenced by QwtPlotCurve::draw(), and replot().
{
return (d_data->paintAttributes & attribute) != 0;
}
1.7.2