ListBoxDevice::ListBoxDevice(const QPixmap & pixmap, const QString & title, const QString & url, const QString & name, const QString & mountPoint, bool mounted, bool ejectable, bool removable, int id) : ListBoxLink(pixmap, title, url), name_(name), mountPoint_(mountPoint), mounted_(mounted), ejectable_(ejectable), removable_(removable),id_(id) { if (!eject.mask()) eject.setMask(eject); if (!locked.mask()) locked.setMask(locked); }
void KarbonGradientWidget::paintColorStop(QPainter& p, int x, const QColor& color) { QBitmap bitmap = QBitmap::fromData(QSize(colorStop_width, colorStop_height), colorStop_bits); bitmap.setMask(bitmap); p.setPen(color); p.drawPixmap(x - 4, 1, bitmap); bitmap = QBitmap::fromData(QSize(colorStopBorder_width, colorStopBorder_height), colorStopBorder_bits); bitmap.setMask(bitmap); p.setPen(Qt::black); p.drawPixmap(x - 5, 1, bitmap); }
void KarbonGradientWidget::paintMidPoint(QPainter& p, int x) { QBitmap bitmap = QBitmap::fromData(QSize(midPoint_width, midPoint_height), midPoint_bits); bitmap.setMask(bitmap); p.setPen(Qt::black); p.drawPixmap(x - 3, 1, bitmap); }
void KstViewLabel::paintSelf(KstPainter& p, const QRegion& bounds) { p.save(); if (p.type() == KstPainter::P_PRINT || p.type() == KstPainter::P_EXPORT) { int absFontSizeOld = _absFontSize; QRect cr(contentsRectForPainter(p)); cr.setSize(sizeForText(_parent->geometry())); setContentsRectForPainter(p, cr); KstBorderedViewObject::paintSelf(p, bounds); p.translate(cr.left(), cr.top()); if (!_transparent) { p.fillRect(0, 0, cr.width(), cr.height(), backgroundColor()); } drawToPainter(_parsed, p); _absFontSize = absFontSizeOld; } else { if (p.makingMask()) { KstBorderedViewObject::paintSelf(p, bounds); p.setRasterOp(Qt::SetROP); const QRect cr(contentsRect()); // slow but preserves antialiasing... QBitmap bm = _backBuffer.buffer().createHeuristicMask(false); bm.setMask(bm); p.drawPixmap(cr.left(), cr.top(), bm, 0, 0, cr.width(), cr.height()); } else { const QRegion clip(clipRegion()); KstBorderedViewObject::paintSelf(p, bounds); p.setClipRegion(bounds & clip); _backBuffer.paintInto(p, contentsRect()); } } p.restore(); }
KDEFX_EXPORT void kColorBitmaps(QPainter *p, const QColorGroup &g, int x, int y, int w, int h, bool isXBitmaps, const uchar *lightColor, const uchar *midColor, const uchar *midlightColor, const uchar *darkColor, const uchar *blackColor, const uchar *whiteColor) { const uchar *data[]={lightColor, midColor, midlightColor, darkColor, blackColor, whiteColor}; QColor colors[]={g.light(), g.mid(), g.midlight(), g.dark(), Qt::black, Qt::white}; int i; QBitmap b; for(i=0; i < 6; ++i){ if(data[i]){ b = QBitmap(w, h, data[i], isXBitmaps); b.setMask(b); p->setPen(colors[i]); p->drawPixmap(x, y, b); } } }
/*! Returns a pixmap with size \a s and mode \a m, generating one if needed. Generated pixmaps are cached. */ QPixmap QIconSet::pixmap( Size s, Mode m ) const { if ( !d ) { QPixmap r; return r; } QImage i; QIconSetPrivate * p = ((QIconSet *)this)->d; QPixmap * pm = 0; if ( s == Large ) { switch( m ) { case Normal: if ( !p->large.pm ) { ASSERT( p->small.pm ); i = p->small.pm->convertToImage(); i = i.smoothScale( i.width() * 3 / 2, i.height() * 3 / 2 ); p->large.pm = new QPixmap; p->large.generated = TRUE; p->large.pm->convertFromImage( i ); if ( !p->large.pm->mask() ) { i = i.createHeuristicMask(); QBitmap tmp; tmp.convertFromImage( i, Qt::MonoOnly + Qt::ThresholdDither ); p->large.pm->setMask( tmp ); } } pm = p->large.pm; break; case Active: if ( !p->largeActive.pm ) { p->largeActive.pm = new QPixmap( pixmap( Large, Normal ) ); p->largeActive.generated = TRUE; } pm = p->largeActive.pm; break; case Disabled: if ( !p->largeDisabled.pm ) { #if defined(_WS_QWS_) && !defined(QT_NO_DEPTH_32) p->largeDisabled.pm = newDisablePixmap(pixmap(Large,Normal)); #else QBitmap tmp; if ( p->large.generated && !p->smallDisabled.generated && p->smallDisabled.pm && !p->smallDisabled.pm->isNull() ) { // if there's a hand-drawn disabled small image, // but the normal big one is generated, use the // hand-drawn one to generate this one. i = p->smallDisabled.pm->convertToImage(); i = i.smoothScale( i.width() * 3 / 2, i.height() * 3 / 2 ); p->largeDisabled.pm = new QPixmap; p->largeDisabled.pm->convertFromImage( i ); if ( !p->largeDisabled.pm->mask() ) { i = i.createHeuristicMask(); tmp.convertFromImage( i, Qt::MonoOnly + Qt::ThresholdDither ); } } else { if (pixmap( Large, Normal).mask()) tmp = *pixmap( Large, Normal).mask(); else { QPixmap conv = pixmap( Large, Normal ); if ( !conv.isNull() ) { i = conv.convertToImage(); i = i.createHeuristicMask(); tmp.convertFromImage( i, Qt::MonoOnly + Qt::ThresholdDither ); } } p->largeDisabled.pm = new QPixmap( p->large.pm->width()+1, p->large.pm->height()+1); QColorGroup dis( QApplication::palette().disabled() ); p->largeDisabled.pm->fill( dis.background() ); QPainter painter( p->largeDisabled.pm ); painter.setPen( dis.base() ); painter.drawPixmap( 1, 1, tmp ); painter.setPen( dis.foreground() ); painter.drawPixmap( 0, 0, tmp ); } if ( !p->largeDisabled.pm->mask() ) { if ( !tmp.mask() ) tmp.setMask( tmp ); QBitmap mask( d->largeDisabled.pm->size() ); mask.fill( Qt::color0 ); QPainter painter( &mask ); painter.drawPixmap( 0, 0, tmp ); painter.drawPixmap( 1, 1, tmp ); painter.end(); p->largeDisabled.pm->setMask( mask ); } #endif p->largeDisabled.generated = TRUE; } pm = p->largeDisabled.pm; break; } } else { switch( m ) { case Normal: if ( !p->small.pm ) { ASSERT( p->large.pm ); i = p->large.pm->convertToImage(); i = i.smoothScale( i.width() * 2 / 3, i.height() * 2 / 3 ); p->small.pm = new QPixmap; p->small.generated = TRUE; p->small.pm->convertFromImage( i ); if ( !p->small.pm->mask() ) { i = i.createHeuristicMask(); QBitmap tmp; tmp.convertFromImage( i, Qt::MonoOnly + Qt::ThresholdDither ); p->small.pm->setMask( tmp ); } } pm = p->small.pm; break; case Active: if ( !p->smallActive.pm ) { p->smallActive.pm = new QPixmap( pixmap( Small, Normal ) ); p->smallActive.generated = TRUE; } pm = p->smallActive.pm; break; case Disabled: if ( !p->smallDisabled.pm ) { #if defined(_WS_QWS_) && !defined(QT_NO_DEPTH_32) p->smallDisabled.pm = newDisablePixmap(pixmap(Small,Normal)); #else QBitmap tmp; if ( p->small.generated && !p->largeDisabled.generated && p->largeDisabled.pm && !p->largeDisabled.pm->isNull() ) { // if there's a hand-drawn disabled large image, // but the normal small one is generated, use the // hand-drawn one to generate this one. i = p->largeDisabled.pm->convertToImage(); i = i.smoothScale( i.width() * 3 / 2, i.height() * 3 / 2 ); p->smallDisabled.pm = new QPixmap; p->smallDisabled.pm->convertFromImage( i ); if ( !p->smallDisabled.pm->mask() ) { i = i.createHeuristicMask(); tmp.convertFromImage( i, Qt::MonoOnly + Qt::ThresholdDither ); } } else { if ( pixmap( Small, Normal).mask()) tmp = *pixmap( Small, Normal).mask(); else { QPixmap conv = pixmap( Small, Normal ); if ( !conv.isNull() ) { i = conv.convertToImage(); i = i.createHeuristicMask(); tmp.convertFromImage( i, Qt::MonoOnly + Qt::ThresholdDither ); } } p->smallDisabled.pm = new QPixmap( p->small.pm->width()+1, p->small.pm->height()+1); QColorGroup dis( QApplication::palette().disabled() ); p->smallDisabled.pm->fill( dis.background() ); QPainter painter( p->smallDisabled.pm ); painter.setPen( dis.base() ); painter.drawPixmap( 1, 1, tmp ); painter.setPen( dis.foreground() ); painter.drawPixmap( 0, 0, tmp ); } if ( !p->smallDisabled.pm->mask() ) { if ( !tmp.mask() ) tmp.setMask( tmp ); QBitmap mask( d->smallDisabled.pm->size() ); mask.fill( Qt::color0 ); QPainter painter( &mask ); painter.drawPixmap( 0, 0, tmp ); painter.drawPixmap( 1, 1, tmp ); painter.end(); p->smallDisabled.pm->setMask( mask ); } #endif p->smallDisabled.generated = TRUE; } pm = p->smallDisabled.pm; break; } } ASSERT( pm ); return *pm; }
void KniftyButton::drawButton(QPainter *painter) { if (!KniftyHandler::initialized()) return; bool active = m_client->isActive(); QPixmap backgroundTile = m_client->getTitleBarTile(active); QColor titleBorder3 = KniftyHandler::useTitleColor() ? m_client->options()->colorGroup(KDecoration::ColorTitleBar, active).background() : colorGroup().background(); QColor titleBorder1 = titleBorder3.dark(155); // dark QPixmap buffer; buffer.resize(width(), height()); QPainter bufferPainter(&buffer); bufferPainter.drawTiledPixmap(0, 0, width(), width(), backgroundTile); if (!KniftyHandler::useHighContrastHoveredButtons()) { if (hover) { if (isDown()) { bufferPainter.setPen(titleBorder3.dark(150)); } else { bufferPainter.setPen(titleBorder3.dark(120)); } bufferPainter.drawLine(1, 0, width()-2, 0); bufferPainter.drawLine(0, 1, 0, height()-2); bufferPainter.drawLine(1, height()-1, width()-2, height()-1); bufferPainter.drawLine(width()-1, 1, width()-1, height()-2); } } if (m_type == ButtonMenu) { QPixmap menuIcon = m_client->icon().pixmap(QIconSet::Small, QIconSet::Normal); if (width() < menuIcon.width() || height() < menuIcon.height() ) { menuIcon.convertFromImage( menuIcon.convertToImage().smoothScale(width()-2, height()-2)); } bufferPainter.drawPixmap((width()-menuIcon.width())/2, (height()-menuIcon.height())/2, menuIcon); } else { QBitmap deco; switch (m_type) { case ButtonClose: deco = QBitmap(DECOSIZE, DECOSIZE, close_bits, true); break; case ButtonMax: deco = QBitmap(DECOSIZE, DECOSIZE, isMaximized ? restore_bits : maximize_bits, true); break; case ButtonMin: deco = QBitmap(DECOSIZE, DECOSIZE, minimize_bits, true); break; case ButtonHelp: deco = QBitmap(DECOSIZE, DECOSIZE, help_bits, true); break; case ButtonOnAllDesktops: deco = QBitmap(DECOSIZE, DECOSIZE, isSticky ? unsticky_bits : sticky_bits, true); break; default: deco = QBitmap(DECOSIZE, DECOSIZE, empty_bits, true); } deco.setMask(deco); int dX = (width()-DECOSIZE)/2; int dY = (height()-DECOSIZE)/2; if (isDown()) { dY++; if (hover) { bufferPainter.setPen(titleBorder1.dark(120)); } else { bufferPainter.setPen(titleBorder1); } } else { bufferPainter.setPen(titleBorder3.light(120) ); bufferPainter.drawPixmap((width()-DECOSIZE)/2, (height()-DECOSIZE)/2+1, deco); if(hover) { if (!KniftyHandler::useHighContrastHoveredButtons()) bufferPainter.setPen(titleBorder1.light(120)); else { int bw = inverseBwColor(titleBorder3); bufferPainter.setPen(QColor(bw,bw,bw)); } } else { bufferPainter.setPen(titleBorder1); } } bufferPainter.drawPixmap(dX, dY, deco); } bufferPainter.end(); painter->drawPixmap(0, 0, buffer); }