/*! Handles paint events for buttons. Small and typically complex buttons (less than 300x100 pixels) are painted double-buffered to reduce flicker. The actually drawing is done in the virtual functions drawButton() and drawButtonLabel(). \sa drawButton(), drawButtonLabel() */ void QButton::paintEvent( QPaintEvent *event ) { if ( event && width() <= drawingPixWidth && height() <= drawingPixHeight && backgroundMode() != X11ParentRelative ) { makeDrawingPixmap(); // makes file-static drawpm variable if ( backgroundOrigin() == ParentOrigin && !isTopLevel() ) drawpm->fill( this, x(), y() ); else drawpm->fill( this, 0, 0 ); QPainter paint; paint.begin( drawpm, this ); drawButton( &paint ); paint.end(); paint.begin( this ); paint.drawPixmap( 0, 0, *drawpm ); paint.end(); } else { erase( event->region() ); QPainter paint( this ); drawButton( &paint ); } }
void KLineEdit::init() { d = new KLineEditPrivate; possibleTripleClick = false; d->bgMode = backgroundMode (); // Enable the context menu by default. KLineEdit::setContextMenuEnabled( true ); KCursor::setAutoHideCursor( this, true, true ); installEventFilter( this ); KGlobalSettings::Completion mode = completionMode(); d->autoSuggest = (mode == KGlobalSettings::CompletionMan || mode == KGlobalSettings::CompletionPopupAuto || mode == KGlobalSettings::CompletionAuto); connect( this, SIGNAL(selectionChanged()), this, SLOT(slotRestoreSelectionColors())); QPalette p = palette(); if ( !d->previousHighlightedTextColor.isValid() ) d->previousHighlightedTextColor=p.color(QPalette::Normal,QColorGroup::HighlightedText); if ( !d->previousHighlightColor.isValid() ) d->previousHighlightColor=p.color(QPalette::Normal,QColorGroup::Highlight); d->drawClickMsg = false; }
void KLineEdit::setReadOnly(bool readOnly) { // Do not do anything if nothing changed... if (readOnly == isReadOnly ()) return; QLineEdit::setReadOnly (readOnly); if (readOnly) { d->bgMode = backgroundMode (); setBackgroundMode (Qt::PaletteBackground); if (d->enableSqueezedText && d->squeezedText.isEmpty()) { d->squeezedText = text(); setSqueezedText(); } } else { if (!d->squeezedText.isEmpty()) { setText(d->squeezedText); d->squeezedText = QString::null; } setBackgroundMode (d->bgMode); } }
void QWidget::erase( const QRegion& reg ) { //this is experimental, I need to test more, but it seems in unclipped mode erasing shouldn't happen???? if ( backgroundMode() == NoBackground || testWFlags(WPaintUnclipped) ) return; bool unclipped = testWFlags( WPaintUnclipped ); clearWFlags( WPaintUnclipped ); QPainter p(this); p.setClipRegion( reg ); if ( extra && extra->bg_pix ) { if ( !extra->bg_pix->isNull() ) { QPoint offset = backgroundOffset(); int xoff = offset.x(); int yoff = offset.y(); p.drawTiledPixmap(rect(),*extra->bg_pix, QPoint(xoff%extra->bg_pix->width(), yoff%extra->bg_pix->height())); } } else { p.fillRect(rect(),bg_col); } if ( unclipped ) setWFlags( WPaintUnclipped ); }
void QWidget::erase( int x, int y, int w, int h ) { if ( backgroundMode() == NoBackground || !isVisible() ) return; erase( QRegion( x, y, w, h ) ); }
void MainWindow::tunePalette() { bool ok; QPalette pal = PaletteEditorAdvanced::getPalette(&ok, editPalette, backgroundMode(), this); if (! ok) return; editPalette = pal; setPreviewPalette(editPalette); setModified(true); }
void QwtPlotCanvas::setSystemBackground(bool on) { #if QT_VERSION < 0x040000 if ( backgroundMode() == Qt::NoBackground ) { if ( on ) setBackgroundMode(Qt::PaletteBackground); } else { if ( !on ) setBackgroundMode(Qt::NoBackground); } #else if ( testAttribute(Qt::WA_NoSystemBackground) == on ) setAttribute(Qt::WA_NoSystemBackground, !on); #endif }
void QwtPlot::printLegend(QPainter *painter, const QRect &rect) const { if ( !legend() || legend()->isEmpty() ) return; QLayout *l = legend()->contentsWidget()->layout(); if ( l == 0 || !l->inherits("QwtDynGridLayout") ) return; QwtDynGridLayout *legendLayout = (QwtDynGridLayout *)l; uint numCols = legendLayout->columnsForWidth(rect.width()); #if QT_VERSION < 0x040000 QValueList<QRect> itemRects = legendLayout->layoutItems(rect, numCols); #else QList<QRect> itemRects = legendLayout->layoutItems(rect, numCols); #endif int index = 0; #if QT_VERSION < 0x040000 QLayoutIterator layoutIterator = legendLayout->iterator(); for ( QLayoutItem *item = layoutIterator.current(); item != 0; item = ++layoutIterator) { #else for ( int i = 0; i < legendLayout->count(); i++ ) { QLayoutItem *item = legendLayout->itemAt(i); #endif QWidget *w = item->widget(); if ( w ) { painter->save(); painter->setClipping(true); QwtPainter::setClipRect(painter, itemRects[index]); printLegendItem(painter, w, itemRects[index]); index++; painter->restore(); } } } /*! Print the legend item into a given rectangle. \param painter Painter \param w Widget representing a legend item \param rect Bounding rectangle */ void QwtPlot::printLegendItem(QPainter *painter, const QWidget *w, const QRect &rect) const { if ( w->inherits("QwtLegendItem") ) { QwtLegendItem *item = (QwtLegendItem *)w; painter->setFont(item->font()); item->drawItem(painter, rect); } } /*! \brief Paint a scale into a given rectangle. Paint the scale into a given rectangle. \param painter Painter \param axisId Axis \param startDist Start border distance \param endDist End border distance \param baseDist Base distance \param rect Bounding rectangle */ void QwtPlot::printScale(QPainter *painter, int axisId, int startDist, int endDist, int baseDist, const QRect &rect) const { if (!axisEnabled(axisId)) return; const QwtScaleWidget *scaleWidget = axisWidget(axisId); if ( scaleWidget->isColorBarEnabled() && scaleWidget->colorBarWidth() > 0) { const QwtMetricsMap map = QwtPainter::metricsMap(); QRect r = map.layoutToScreen(rect); r.setWidth(r.width() - 1); r.setHeight(r.height() - 1); scaleWidget->drawColorBar(painter, scaleWidget->colorBarRect(r)); const int off = scaleWidget->colorBarWidth() + scaleWidget->spacing(); if ( scaleWidget->scaleDraw()->orientation() == Qt::Horizontal ) baseDist += map.screenToLayoutY(off); else baseDist += map.screenToLayoutX(off); } QwtScaleDraw::Alignment align; int x, y, w; switch(axisId) { case yLeft: { x = rect.right() - baseDist; y = rect.y() + startDist; w = rect.height() - startDist - endDist; align = QwtScaleDraw::LeftScale; break; } case yRight: { x = rect.left() + baseDist; y = rect.y() + startDist; w = rect.height() - startDist - endDist; align = QwtScaleDraw::RightScale; break; } case xTop: { x = rect.left() + startDist; y = rect.bottom() - baseDist; w = rect.width() - startDist - endDist; align = QwtScaleDraw::TopScale; break; } case xBottom: { x = rect.left() + startDist; y = rect.top() + baseDist; w = rect.width() - startDist - endDist; align = QwtScaleDraw::BottomScale; break; } default: return; } scaleWidget->drawTitle(painter, align, rect); painter->save(); painter->setFont(scaleWidget->font()); QPen pen = painter->pen(); pen.setWidth(scaleWidget->penWidth()); painter->setPen(pen); QwtScaleDraw *sd = (QwtScaleDraw *)scaleWidget->scaleDraw(); const QPoint sdPos = sd->pos(); const int sdLength = sd->length(); sd->move(x, y); sd->setLength(w); #if QT_VERSION < 0x040000 sd->draw(painter, scaleWidget->palette().active()); #else QPalette palette = scaleWidget->palette(); palette.setCurrentColorGroup(QPalette::Active); sd->draw(painter, palette); #endif // reset previous values sd->move(sdPos); sd->setLength(sdLength); painter->restore(); } /*! Print the canvas into a given rectangle. \param painter Painter \param map Maps mapping between plot and paint device coordinates \param boundingRect Bounding rectangle \param canvasRect Canvas rectangle \param pfilter Print filter \sa QwtPlotPrintFilter */ void QwtPlot::printCanvas(QPainter *painter, const QRect &boundingRect, const QRect &canvasRect, const QwtScaleMap map[axisCnt], const QwtPlotPrintFilter &pfilter) const { if ( pfilter.options() & QwtPlotPrintFilter::PrintBackground ) { QBrush bgBrush; #if QT_VERSION >= 0x040000 bgBrush = canvas()->palette().brush(backgroundRole()); #else QColorGroup::ColorRole role = QPalette::backgroundRoleFromMode( backgroundMode() ); bgBrush = canvas()->colorGroup().brush( role ); #endif QRect r = boundingRect; if ( !(pfilter.options() & QwtPlotPrintFilter::PrintFrameWithScales) ) { r = canvasRect; #if QT_VERSION >= 0x040000 // Unfortunately the paint engines do no always the same const QPaintEngine *pe = painter->paintEngine(); if ( pe ) { switch(painter->paintEngine()->type() ) { case QPaintEngine::Raster: case QPaintEngine::X11: break; default: r.setWidth(r.width() - 1); r.setHeight(r.height() - 1); break; } } #else if ( painter->device()->isExtDev() ) { r.setWidth(r.width() - 1); r.setHeight(r.height() - 1); } #endif } QwtPainter::fillRect(painter, r, bgBrush); } if ( pfilter.options() & QwtPlotPrintFilter::PrintFrameWithScales ) { painter->save(); painter->setPen(QPen(Qt::black)); painter->setBrush(QBrush(Qt::NoBrush)); QwtPainter::drawRect(painter, boundingRect); painter->restore(); } painter->setClipping(true); QwtPainter::setClipRect(painter, canvasRect); drawItems(painter, canvasRect, map, pfilter); }
/*! \brief Draw the contents inside the frame QColorGroup::Background is the background color outside of the frame. QColorGroup::Base is the background color inside the frame. QColorGroup::Foreground is the background color inside the scale. \param painter Painter \sa QwtDial::boundingRect, QwtDial::contentsRect, QwtDial::scaleContentsRect, QWidget::setPalette */ void QwtDial::drawContents(QPainter *painter) const { if ( backgroundMode() == NoBackground || colorGroup().brush(QColorGroup::Base) != colorGroup().brush(QColorGroup::Background) ) { // Don´t use QPainter::drawEllipse. There are some pixels // different compared to the region in the mask, leaving // them in background color. painter->save(); painter->setPen(Qt::NoPen); painter->setBrush(colorGroup().brush(QColorGroup::Base)); // Even if we want to fill the contentsRect only, we fill the // complete boundingRect. The frame will be painted later // above, but we want to have the base color below it // because round objects doesn´t cover all pixels. QRect br = boundingRect(); #if QT_VERSION < 300 #ifdef _WS_WIN32_ // Qt-230-NC draws ellipses not as nicely as Qt-2.3.x on X Windows br.setTop(br.top()-1); br.setLeft(br.left()-1); br.setBottom(br.bottom()+1); br.setRight(br.right()+1); #endif #endif painter->setClipRegion(QRegion(painter->xForm(br), QRegion::Ellipse)); painter->drawRect(br); painter->restore(); } const QRect insideScaleRect = scaleContentsRect(); if ( colorGroup().brush(QColorGroup::Foreground) != colorGroup().brush(QColorGroup::Base) ) { painter->save(); painter->setPen(Qt::NoPen); painter->setBrush(colorGroup().brush(QColorGroup::Foreground)); painter->setClipRegion( QRegion(painter->xForm(insideScaleRect), QRegion::Ellipse)); painter->drawRect(insideScaleRect); painter->restore(); } const QPoint center = insideScaleRect.center(); const int radius = insideScaleRect.width() / 2; painter->save(); drawScaleContents(painter, center, radius); painter->restore(); double direction = d_origin; if (isValid()) { direction = d_origin + d_minScaleArc; if ( maxValue() > minValue() && d_maxScaleArc > d_minScaleArc ) { const double ratio = (value() - minValue()) / (maxValue() - minValue()); direction += ratio * (d_maxScaleArc - d_minScaleArc); } if ( direction >= 360.0 ) direction -= 360.0; } double origin = d_origin; if ( mode() == RotateScale ) { origin -= direction - d_origin; direction = d_origin; } painter->save(); drawScale(painter, center, radius, origin, d_minScaleArc, d_maxScaleArc); painter->restore(); if ( isValid() ) { QPalette::ColorGroup cg; if ( isEnabled() ) cg = hasFocus() ? QPalette::Active : QPalette::Inactive; else cg = QPalette::Disabled; painter->save(); drawNeedle(painter, center, radius, direction, cg); painter->restore(); } }
void QwtPlot::printLegend(QPainter *painter, const QRect &rect) const { if ( !legend() || legend()->isEmpty() ) return; QLayout *l = legend()->contentsWidget()->layout(); if ( l == 0 || !l->inherits("QwtDynGridLayout") ) return; QwtDynGridLayout *legendLayout = (QwtDynGridLayout *)l; uint numCols = legendLayout->columnsForWidth(rect.width()); #if QT_VERSION < 0x040000 QValueList<QRect> itemRects = legendLayout->layoutItems(rect, numCols); #else QList<QRect> itemRects = legendLayout->layoutItems(rect, numCols); #endif int index = 0; #if QT_VERSION < 0x040000 QLayoutIterator layoutIterator = legendLayout->iterator(); for ( QLayoutItem *item = layoutIterator.current(); item != 0; item = ++layoutIterator) { #else for ( int i = 0; i < legendLayout->count(); i++ ) { QLayoutItem *item = legendLayout->itemAt(i); #endif QWidget *w = item->widget(); if ( w ) { painter->save(); painter->setClipping(true); QwtPainter::setClipRect(painter, itemRects[index]); printLegendItem(painter, w, itemRects[index]); index++; painter->restore(); } } } /*! Print the legend item into a given rectangle. \param painter Painter \param w Widget representing a legend item \param rect Bounding rectangle */ void QwtPlot::printLegendItem(QPainter *painter, const QWidget *w, const QRect &rect) const { if ( w->inherits("QwtLegendItem") ) { QwtLegendItem *item = (QwtLegendItem *)w; painter->setFont(item->font()); item->drawItem(painter, rect); } } /*! \brief Paint a scale into a given rectangle. Paint the scale into a given rectangle. \param painter Painter \param axisId Axis \param startDist Start border distance \param endDist End border distance \param baseDist Base distance \param rect Bounding rectangle */ void QwtPlot::printScale(QPainter *painter, int axisId, int startDist, int endDist, int baseDist, const QRect &rect) const { if (!axisEnabled(axisId)) return; QwtScaleDraw::Alignment align; int x, y, w; switch(axisId) { case yLeft: { x = rect.right() - baseDist + 1; y = rect.y() + startDist; w = rect.height() - startDist - endDist; align = QwtScaleDraw::LeftScale; break; } case yRight: { x = rect.left() + baseDist; y = rect.y() + startDist; w = rect.height() - startDist - endDist; align = QwtScaleDraw::RightScale; break; } case xTop: { x = rect.left() + startDist; y = rect.bottom() - baseDist + 1; w = rect.width() - startDist - endDist; align = QwtScaleDraw::TopScale; break; } case xBottom: { x = rect.left() + startDist; y = rect.top() + baseDist; w = rect.width() - startDist - endDist; align = QwtScaleDraw::BottomScale; break; } default: return; } const QwtScaleWidget *scaleWidget = axisWidget(axisId); scaleWidget->drawTitle(painter, align, rect); painter->save(); painter->setFont(scaleWidget->font()); QwtScaleDraw *sd = (QwtScaleDraw *)scaleWidget->scaleDraw(); const QPoint sdPos = sd->pos(); const int sdLength = sd->length(); sd->move(x, y); sd->setLength(w); #if QT_VERSION < 0x040000 sd->draw(painter, scaleWidget->palette().active()); #else QPalette palette = scaleWidget->palette(); palette.setCurrentColorGroup(QPalette::Active); sd->draw(painter, palette); #endif // reset previous values sd->move(sdPos); sd->setLength(sdLength); painter->restore(); } /*! Print the canvas into a given rectangle. \param painter Painter \param map Maps mapping between plot and paint device coordinates \param canvasRect Bounding rectangle \param pfilter Print filter \sa QwtPlotPrintFilter */ void QwtPlot::printCanvas(QPainter *painter, const QRect &canvasRect, const QwtArray<QwtScaleMap> &map, const QwtPlotPrintFilter &pfilter) const { if ( pfilter.options() & QwtPlotPrintFilter::PrintCanvasBackground ) { painter->setPen(Qt::NoPen); QBrush bgBrush; #if QT_VERSION >= 0x040000 bgBrush = canvas()->palette().brush(backgroundRole()); #else QColorGroup::ColorRole role = QPalette::backgroundRoleFromMode( backgroundMode() ); bgBrush = canvas()->colorGroup().brush( role ); #endif painter->setBrush(bgBrush); int x1 = 0; int x2 = 0; int y1 = 0; int y2 = 0; #if QT_VERSION >= 0x040000 switch(painter->device()->paintEngine()->type()) { case QPaintEngine::PostScript: x2 = 1; y2 = 1; break; default:; } #endif const QwtMetricsMap map = QwtPainter::metricsMap(); x1 = map.screenToLayoutX(x1); x2 = map.screenToLayoutX(x2); y1 = map.screenToLayoutY(y1); y2 = map.screenToLayoutY(y2); QwtPainter::drawRect(painter, canvasRect.x() + x1, canvasRect.y() + y1, canvasRect.width() - x2, canvasRect.height() - y2); } else { // Paint the canvas borders instead. painter->setPen(QPen(Qt::black)); painter->setBrush(QBrush(Qt::NoBrush)); QwtPainter::drawRect(painter, canvasRect); } painter->setClipping(true); QwtPainter::setClipRect(painter, canvasRect); drawItems(painter, canvasRect, map, pfilter); }
void QWidgetStack::raiseWidget( QWidget *w ) { if ( !w || w == invisible || w->parent() != this || w == topWidget ) return; if ( id(w) == -1 ) addWidget( w ); if ( !isVisible() ) { topWidget = w; return; } if (w->maximumSize().width() < invisible->width() || w->maximumSize().height() < invisible->height()) invisible->setBackgroundMode(backgroundMode()); else if (invisible->backgroundMode() != NoBackground) invisible->setBackgroundMode(NoBackground); if ( invisible->isHidden() ) { invisible->setGeometry( contentsRect() ); invisible->lower(); invisible->show(); QApplication::sendPostedEvents( invisible, QEvent::ShowWindowRequest ); } // try to move focus onto the incoming widget if focus // was somewhere on the outgoing widget. if ( topWidget ) { QWidget * fw = focusWidget(); QWidget* p = fw; while ( p && p != topWidget ) p = p->parentWidget(); if ( p == topWidget ) { // focus was on old page if ( !focusWidgets ) focusWidgets = new QPtrDict<QWidget>( 17 ); focusWidgets->replace( topWidget, fw ); fw->clearFocus(); // look for the best focus widget we can find // best == what we had (which may be deleted) fw = focusWidgets->take( w ); if ( isChildOf( fw, w ) ) { fw->setFocus(); } else { // second best == first child widget in the focus chain QFocusData *f = focusData(); QWidget* home = f->home(); QWidget *i = home; do { if ( ( ( i->focusPolicy() & TabFocus ) == TabFocus ) && !i->focusProxy() && i->isVisibleTo(w) && i->isEnabled() ) { p = i; while ( p && p != w ) p = p->parentWidget(); if ( p == w ) { i->setFocus(); break; } } i = f->next(); } while( i != home ); } } } if ( isVisible() ) { emit aboutToShow( w ); int i = id( w ); if ( i != -1 ) emit aboutToShow( i ); } topWidget = w; const QObjectList * c = children(); QObjectListIt it( *c ); QObject * o; while( (o=it.current()) != 0 ) { ++it; if ( o->isWidgetType() && o != w && o != invisible ) ((QWidget *)o)->hide(); } w->setGeometry( invisible->geometry() ); w->show(); }
void QLCDNumber::internalSetString( const QString& s ) { QString buffer; int i; int len = s.length(); QBitArray newPoints(ndigits); if ( !smallPoint ) { if ( len == ndigits ) buffer = s; else buffer = s.right( ndigits ).rightJustify( ndigits, ' ' ); } else { int index = -1; bool lastWasPoint = TRUE; newPoints.clearBit(0); for ( i=0; i<len; i++ ) { if ( s[i] == '.' ) { if ( lastWasPoint ) { // point already set for digit? if ( index == ndigits - 1 ) // no more digits break; index++; buffer[index] = ' '; // 2 points in a row, add space } newPoints.setBit(index); // set decimal point lastWasPoint = TRUE; } else { if ( index == ndigits - 1 ) break; index++; buffer[index] = s[i]; newPoints.clearBit(index); // decimal point default off lastWasPoint = FALSE; } } if ( index < ((int) ndigits) - 1 ) { for( i=index; i>=0; i-- ) { buffer[ndigits - 1 - index + i] = buffer[i]; newPoints.setBit( ndigits - 1 - index + i, newPoints.testBit(i) ); } for( i=0; i<ndigits-index-1; i++ ) { buffer[i] = ' '; newPoints.clearBit(i); } } } if ( buffer == digitStr ) return; if ( backgroundMode() == FixedPixmap || colorGroup().brush( QColorGroup::Background ).pixmap() ) { digitStr = buffer; if ( smallPoint ) points = newPoints; repaint( contentsRect() ); } else { QPainter p( this ); if ( !smallPoint ) drawString( buffer, p ); else drawString( buffer, p, &newPoints ); } }
void KMenuBar::drawContents(QPainter *p) { // Closes the BR77113 // We need to overload this method to paint only the menu items // This way when the KMenuBar is embedded in the menu applet it // integrates correctly. // // Background mode and origin are set so late because of styles // using the polish() method to modify these settings. // // Of course this hack can safely be removed when real transparency // will be available if(!d->topLevel) { QMenuBar::drawContents(p); } else { bool up_enabled = isUpdatesEnabled(); BackgroundMode bg_mode = backgroundMode(); BackgroundOrigin bg_origin = backgroundOrigin(); setUpdatesEnabled(false); setBackgroundMode(X11ParentRelative); setBackgroundOrigin(WindowOrigin); p->eraseRect(rect()); erase(); QColorGroup g = colorGroup(); bool e; for(int i = 0; i < (int)count(); i++) { QMenuItem *mi = findItem(idAt(i)); if(!mi->text().isNull() || mi->pixmap()) { QRect r = itemRect(i); if(r.isEmpty() || !mi->isVisible()) continue; e = mi->isEnabledAndVisible(); if(e) g = isEnabled() ? (isActiveWindow() ? palette().active() : palette().inactive()) : palette().disabled(); else g = palette().disabled(); bool item_active = (actItem == i); p->setClipRect(r); if(item_active) { QStyle::SFlags flags = QStyle::Style_Default; if(isEnabled() && e) flags |= QStyle::Style_Enabled; if(item_active) flags |= QStyle::Style_Active; if(item_active && actItemDown) flags |= QStyle::Style_Down; flags |= QStyle::Style_HasFocus; style().drawControl(QStyle::CE_MenuBarItem, p, this, r, g, flags, QStyleOption(mi)); } else { style().drawItem(p, r, AlignCenter | AlignVCenter | ShowPrefix, g, e, mi->pixmap(), mi->text()); } } } setBackgroundOrigin(bg_origin); setBackgroundMode(bg_mode); setUpdatesEnabled(up_enabled); } }
/*! Draw the the canvas Paints all plot items to the contentsRect(), using QwtPlot::drawCanvas and updates the paint cache. \param painter Painter \sa QwtPlot::drawCanvas(), setPaintAttributes(), testPaintAttributes() */ void QwtPlotCanvas::drawCanvas(QPainter *painter) { 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); } }
/*!\reimp */ void QRadioButton::drawButton( QPainter *paint ) { QPainter *p = paint; const QColorGroup & g = colorGroup(); int x, y; QFontMetrics fm = fontMetrics(); QSize lsz = fm.size(ShowPrefix, text()); QSize sz = style().exclusiveIndicatorSize(); x = text().isEmpty() ? 1 : 0; y = (height() - lsz.height() + fm.height() - sz.height())/2; #ifndef QT_NO_TEXTSTREAM #define SAVE_RADIOBUTTON_PIXMAPS #endif #if defined(SAVE_RADIOBUTTON_PIXMAPS) QString pmkey; // pixmap key int kf = 0; if ( isDown() ) kf |= 1; if ( isOn() ) kf |= 2; if ( isEnabled() ) kf |= 4; QTextOStream os(&pmkey); os << "$qt_radio_" << style().className() << "_" << palette().serialNumber() << "_" << kf; QPixmap *pm = QPixmapCache::find( pmkey ); if ( pm ) { // pixmap exists drawButtonLabel( p ); p->drawPixmap( x, y, *pm ); return; } bool use_pm = TRUE; QPainter pmpaint; int wx, wy; if ( use_pm ) { pm = new QPixmap( sz ); // create new pixmap CHECK_PTR( pm ); pmpaint.begin( pm ); p = &pmpaint; // draw in pixmap wx=x; wy=y; // save x,y coords x = y = 0; p->setBackgroundColor( g.background() ); } #endif #define QCOORDARRLEN(x) sizeof(x)/(sizeof(QCOORD)*2) style().drawExclusiveIndicator(p, x, y, sz.width(), sz.height(), g, isOn(), isDown(), isEnabled() ); #if defined(SAVE_RADIOBUTTON_PIXMAPS) if ( use_pm ) { pmpaint.end(); if ( backgroundPixmap() || backgroundMode() == X11ParentRelative ) { QBitmap bm( pm->size() ); bm.fill( color0 ); pmpaint.begin( &bm ); style().drawExclusiveIndicatorMask( &pmpaint, 0, 0, bm.width(), bm.height(), isOn() ); pmpaint.end(); pm->setMask( bm ); } p = paint; // draw in default device p->drawPixmap( wx, wy, *pm ); if (!QPixmapCache::insert(pmkey, pm) ) // save in cache delete pm; } #endif drawButtonLabel( p ); }