author | sandman <sandman> | 2002-11-01 16:07:10 (UTC) |
---|---|---|
committer | sandman <sandman> | 2002-11-01 16:07:10 (UTC) |
commit | 9e4d914ade0af86707531a80e93a870e52738ce6 (patch) (side-by-side diff) | |
tree | 13bcdec43e9d1afc7392ce44cd72ff1289f0c8eb | |
parent | 28b70b2b7f8fa03ba0991fb73dccf7b46e5c3d1f (diff) | |
download | opie-9e4d914ade0af86707531a80e93a870e52738ce6.zip opie-9e4d914ade0af86707531a80e93a870e52738ce6.tar.gz opie-9e4d914ade0af86707531a80e93a870e52738ce6.tar.bz2 |
Some fixes and enhancements:
- don't rely on clipping information from Qt/E -- this doesn't work
- theme style has support for all KDE gradient types now
-rw-r--r-- | noncore/styles/theme/ogfxeffect.cpp | 243 | ||||
-rw-r--r-- | noncore/styles/theme/ogfxeffect.h | 3 | ||||
-rw-r--r-- | noncore/styles/theme/othemestyle.cpp | 7 |
3 files changed, 220 insertions, 33 deletions
diff --git a/noncore/styles/theme/ogfxeffect.cpp b/noncore/styles/theme/ogfxeffect.cpp index 55f3c1f..cc5bbcd 100644 --- a/noncore/styles/theme/ogfxeffect.cpp +++ b/noncore/styles/theme/ogfxeffect.cpp @@ -1,211 +1,394 @@ /* This file is part of the KDE libraries Copyright (C) 1998, 1999 Christian Tibirna <ctibirna@total.net> (C) 1998, 1999 Daniel M. Duley <mosfet@kde.org> (C) 1998, 1999 Dirk A. Mueller <mueller@kde.org> */ // $Id$ #include <qimage.h> #include <qpainter.h> #include <qpe/qmath.h> #include "ogfxeffect.h" //====================================================================== // // Gradient effects // //====================================================================== QPixmap& OGfxEffect::gradient(QPixmap &pixmap, const QColor &ca, - const QColor &cb, GradientType eff, int /*ncols*/) + const QColor &cb, GradientType eff, int ncols) { - if(pixmap.depth() > 8 && - (eff == VerticalGradient || eff == HorizontalGradient)) { + QImage image = gradient(pixmap.size(), ca, cb, eff, ncols); + pixmap.convertFromImage(image); + + return pixmap; +} +QImage OGfxEffect::gradient(const QSize &size, const QColor &ca, + const QColor &cb, GradientType eff, int /*ncols*/) +{ int rDiff, gDiff, bDiff; - int rca, gca, bca /*, rcb, gcb, bcb*/; + int rca, gca, bca, rcb, gcb, bcb; + + QImage image(size, 32); + + if (size.width() == 0 || size.height() == 0) { + qDebug ( "WARNING: OGfxEffect::gradient: invalid image" ); + return image; + } register int x, y; - rDiff = (/*rcb = */ cb.red()) - (rca = ca.red()); - gDiff = (/*gcb = */ cb.green()) - (gca = ca.green()); - bDiff = (/*bcb = */ cb.blue()) - (bca = ca.blue()); + rDiff = (rcb = cb.red()) - (rca = ca.red()); + gDiff = (gcb = cb.green()) - (gca = ca.green()); + bDiff = (bcb = cb.blue()) - (bca = ca.blue()); + + if( eff == VerticalGradient || eff == HorizontalGradient ){ + + uint *p; + uint rgb; register int rl = rca << 16; register int gl = gca << 16; register int bl = bca << 16; - int rcdelta = ((1<<16) / (eff == VerticalGradient ? pixmap.height() : pixmap.width())) * rDiff; - int gcdelta = ((1<<16) / (eff == VerticalGradient ? pixmap.height() : pixmap.width())) * gDiff; - int bcdelta = ((1<<16) / (eff == VerticalGradient ? pixmap.height() : pixmap.width())) * bDiff; + if( eff == VerticalGradient ) { + + int rcdelta = ((1<<16) / size.height()) * rDiff; + int gcdelta = ((1<<16) / size.height()) * gDiff; + int bcdelta = ((1<<16) / size.height()) * bDiff; - QPainter p(&pixmap); + for ( y = 0; y < size.height(); y++ ) { + p = (uint *) image.scanLine(y); - // these for-loops could be merged, but the if's in the inner loop - // would make it slow - switch(eff) { - case VerticalGradient: - for ( y = 0; y < pixmap.height(); y++ ) { rl += rcdelta; gl += gcdelta; bl += bcdelta; - p.setPen(QColor(rl>>16, gl>>16, bl>>16)); - p.drawLine(0, y, pixmap.width()-1, y); + rgb = qRgb( (rl>>16), (gl>>16), (bl>>16) ); + + for( x = 0; x < size.width(); x++ ) { + *p = rgb; + p++; + } + } + } - break; - case HorizontalGradient: - for( x = 0; x < pixmap.width(); x++) { + else { // must be HorizontalGradient + + unsigned int *o_src = (unsigned int *)image.scanLine(0); + unsigned int *src = o_src; + + int rcdelta = ((1<<16) / size.width()) * rDiff; + int gcdelta = ((1<<16) / size.width()) * gDiff; + int bcdelta = ((1<<16) / size.width()) * bDiff; + + for( x = 0; x < size.width(); x++) { + rl += rcdelta; gl += gcdelta; bl += bcdelta; - p.setPen(QColor(rl>>16, gl>>16, bl>>16)); - p.drawLine(x, 0, x, pixmap.height()-1); + *src++ = qRgb( (rl>>16), (gl>>16), (bl>>16)); + } + + src = o_src; + + // Believe it or not, manually copying in a for loop is faster + // than calling memcpy for each scanline (on the order of ms...). + // I think this is due to the function call overhead (mosfet). + + for (y = 1; y < size.height(); ++y) { + + p = (unsigned int *)image.scanLine(y); + src = o_src; + for(x=0; x < size.width(); ++x) + *p++ = *src++; } - break; - default: - ; } } + else { -// QImage image = OGfxEffect::gradient(pixmap.size(), ca, cb, -// (OGfxEffect::GradientType) eff, ncols); -// pixmap.convertFromImage(image); + + float rfd, gfd, bfd; + float rd = rca, gd = gca, bd = bca; + + unsigned char *xtable[3]; + unsigned char *ytable[3]; + + unsigned int w = size.width(), h = size.height(); + xtable[0] = new unsigned char[w]; + xtable[1] = new unsigned char[w]; + xtable[2] = new unsigned char[w]; + ytable[0] = new unsigned char[h]; + ytable[1] = new unsigned char[h]; + ytable[2] = new unsigned char[h]; + w*=2, h*=2; + + if ( eff == DiagonalGradient || eff == CrossDiagonalGradient) { + // Diagonal dgradient code inspired by BlackBox (mosfet) + // BlackBox dgradient is (C) Brad Hughes, <bhughes@tcac.net> and + // Mike Cole <mike@mydot.com>. + + rfd = (float)rDiff/w; + gfd = (float)gDiff/w; + bfd = (float)bDiff/w; + + int dir; + for (x = 0; x < size.width(); x++, rd+=rfd, gd+=gfd, bd+=bfd) { + dir = eff == DiagonalGradient? x : size.width() - x - 1; + xtable[0][dir] = (unsigned char) rd; + xtable[1][dir] = (unsigned char) gd; + xtable[2][dir] = (unsigned char) bd; + } + rfd = (float)rDiff/h; + gfd = (float)gDiff/h; + bfd = (float)bDiff/h; + rd = gd = bd = 0; + for (y = 0; y < size.height(); y++, rd+=rfd, gd+=gfd, bd+=bfd) { + ytable[0][y] = (unsigned char) rd; + ytable[1][y] = (unsigned char) gd; + ytable[2][y] = (unsigned char) bd; } - return pixmap; + for (y = 0; y < size.height(); y++) { + unsigned int *scanline = (unsigned int *)image.scanLine(y); + for (x = 0; x < size.width(); x++) { + scanline[x] = qRgb(xtable[0][x] + ytable[0][y], + xtable[1][x] + ytable[1][y], + xtable[2][x] + ytable[2][y]); + } + } + } + + else if (eff == RectangleGradient || + eff == PyramidGradient || + eff == PipeCrossGradient || + eff == EllipticGradient) + { + int rSign = rDiff>0? 1: -1; + int gSign = gDiff>0? 1: -1; + int bSign = bDiff>0? 1: -1; + + rfd = (float)rDiff / size.width(); + gfd = (float)gDiff / size.width(); + bfd = (float)bDiff / size.width(); + + rd = (float)rDiff/2; + gd = (float)gDiff/2; + bd = (float)bDiff/2; + + for (x = 0; x < size.width(); x++, rd-=rfd, gd-=gfd, bd-=bfd) + { + xtable[0][x] = (unsigned char) abs((int)rd); + xtable[1][x] = (unsigned char) abs((int)gd); + xtable[2][x] = (unsigned char) abs((int)bd); + } + + rfd = (float)rDiff/size.height(); + gfd = (float)gDiff/size.height(); + bfd = (float)bDiff/size.height(); + + rd = (float)rDiff/2; + gd = (float)gDiff/2; + bd = (float)bDiff/2; + + for (y = 0; y < size.height(); y++, rd-=rfd, gd-=gfd, bd-=bfd) + { + ytable[0][y] = (unsigned char) abs((int)rd); + ytable[1][y] = (unsigned char) abs((int)gd); + ytable[2][y] = (unsigned char) abs((int)bd); + } + unsigned int rgb; + int h = (size.height()+1)>>1; + for (y = 0; y < h; y++) { + unsigned int *sl1 = (unsigned int *)image.scanLine(y); + unsigned int *sl2 = (unsigned int *)image.scanLine(QMAX(size.height()-y-1, y)); + + int w = (size.width()+1)>>1; + int x2 = size.width()-1; + + for (x = 0; x < w; x++, x2--) { + rgb = 0; + if (eff == PyramidGradient) { + rgb = qRgb(rcb-rSign*(xtable[0][x]+ytable[0][y]), + gcb-gSign*(xtable[1][x]+ytable[1][y]), + bcb-bSign*(xtable[2][x]+ytable[2][y])); + } + if (eff == RectangleGradient) { + rgb = qRgb(rcb - rSign * + QMAX(xtable[0][x], ytable[0][y]) * 2, + gcb - gSign * + QMAX(xtable[1][x], ytable[1][y]) * 2, + bcb - bSign * + QMAX(xtable[2][x], ytable[2][y]) * 2); + } + if (eff == PipeCrossGradient) { + rgb = qRgb(rcb - rSign * + QMIN(xtable[0][x], ytable[0][y]) * 2, + gcb - gSign * + QMIN(xtable[1][x], ytable[1][y]) * 2, + bcb - bSign * + QMIN(xtable[2][x], ytable[2][y]) * 2); + } + if (eff == EllipticGradient) { + rgb = qRgb(rcb - rSign * + (int)sqrt((xtable[0][x]*xtable[0][x] + + ytable[0][y]*ytable[0][y])*2.0), + gcb - gSign * + (int)sqrt((xtable[1][x]*xtable[1][x] + + ytable[1][y]*ytable[1][y])*2.0), + bcb - bSign * + (int)sqrt((xtable[2][x]*xtable[2][x] + + ytable[2][y]*ytable[2][y])*2.0)); + } + + sl1[x] = sl2[x] = rgb; + sl1[x2] = sl2[x2] = rgb; + } + } + } + + delete [] xtable[0]; + delete [] xtable[1]; + delete [] xtable[2]; + delete [] ytable[0]; + delete [] ytable[1]; + delete [] ytable[2]; + } + return image; } //====================================================================== // // Blend effects // //====================================================================== QPixmap& OGfxEffect::blend(QPixmap &pixmap, float initial_intensity, const QColor &bgnd, GradientType eff, bool anti_dir, int /*ncols*/) { QImage image = pixmap.convertToImage(); OGfxEffect::blend(image, initial_intensity, bgnd, eff, anti_dir); if ( pixmap. depth ( ) <= 8 ) image. convertDepth ( pixmap. depth ( )); pixmap.convertFromImage(image); return pixmap; } QImage& OGfxEffect::blend(QImage &image, float initial_intensity, const QColor &bgnd, GradientType eff, bool anti_dir) { if (image.width() == 0 || image.height() == 0) { qDebug ( "Invalid image\n" ); return image; } int r_bgnd = bgnd.red(), g_bgnd = bgnd.green(), b_bgnd = bgnd.blue(); int r, g, b; int ind; unsigned int xi, xf, yi, yf; unsigned int a; // check the boundaries of the initial intesity param float unaffected = 1; if (initial_intensity > 1) initial_intensity = 1; if (initial_intensity < -1) initial_intensity = -1; if (initial_intensity < 0) { unaffected = 1. + initial_intensity; initial_intensity = 0; } float intensity = initial_intensity; float var = 1. - initial_intensity; if (anti_dir) { initial_intensity = intensity = 1.; var = -var; } register int x, y; unsigned int *data = (unsigned int *)image.bits(); if( eff == VerticalGradient || eff == HorizontalGradient ) { // set the image domain to apply the effect to xi = 0, xf = image.width(); yi = 0, yf = image.height(); if (eff == VerticalGradient) { if (anti_dir) yf = (int)(image.height() * unaffected); else yi = (int)(image.height() * (1 - unaffected)); } else { if (anti_dir) xf = (int)(image.width() * unaffected); else xi = (int)(image.height() * (1 - unaffected)); } var /= (eff == VerticalGradient?yf-yi:xf-xi); for (y = yi; y < (int)yf; y++) { intensity = eff == VerticalGradient? intensity + var : initial_intensity; for (x = xi; x < (int)xf ; x++) { if (eff == HorizontalGradient) intensity += var; ind = x + image.width() * y ; r = qRed (data[ind]) + (int)(intensity * (r_bgnd - qRed (data[ind]))); g = qGreen(data[ind]) + (int)(intensity * (g_bgnd - qGreen(data[ind]))); b = qBlue (data[ind]) + (int)(intensity * (b_bgnd - qBlue (data[ind]))); if (r > 255) r = 255; if (r < 0 ) r = 0; if (g > 255) g = 255; if (g < 0 ) g = 0; if (b > 255) b = 255; if (b < 0 ) b = 0; a = qAlpha(data[ind]); data[ind] = qRgba(r, g, b, a); } } } else if (eff == DiagonalGradient || eff == CrossDiagonalGradient) { float xvar = var / 2 / image.width(); // / unaffected; float yvar = var / 2 / image.height(); // / unaffected; float tmp; for (x = 0; x < image.width() ; x++) { tmp = xvar * (eff == DiagonalGradient? x : image.width()-x-1); for (y = 0; y < image.height() ; y++) { intensity = initial_intensity + tmp + yvar * y; ind = x + image.width() * y ; r = qRed (data[ind]) + (int)(intensity * (r_bgnd - qRed (data[ind]))); g = qGreen(data[ind]) + (int)(intensity * (g_bgnd - qGreen(data[ind]))); b = qBlue (data[ind]) + (int)(intensity * (b_bgnd - qBlue (data[ind]))); if (r > 255) r = 255; if (r < 0 ) r = 0; if (g > 255) g = 255; if (g < 0 ) g = 0; if (b > 255) b = 255; if (b < 0 ) b = 0; a = qAlpha(data[ind]); data[ind] = qRgba(r, g, b, a); } } } else if (eff == RectangleGradient || eff == EllipticGradient) { float xvar; float yvar; diff --git a/noncore/styles/theme/ogfxeffect.h b/noncore/styles/theme/ogfxeffect.h index 45a8482..755537f 100644 --- a/noncore/styles/theme/ogfxeffect.h +++ b/noncore/styles/theme/ogfxeffect.h @@ -1,78 +1,81 @@ /* This file is part of the KDE libraries Copyright (C) 1998, 1999 Christian Tibirna <ctibirna@total.net> (C) 1998, 1999 Daniel M. Duley <mosfet@kde.org> (C) 1998, 1999 Dirk A. Mueller <mueller@kde.org> */ // $Id$ #ifndef __OGFX_EFFECT_H #define __OGFX_EFFECT_H #include <qpixmap.h> #include <qimage.h> /** * This class includes various pixmap-based graphical effects. * * Everything is * static, so there is no need to create an instance of this class. You can * just call the static methods. They are encapsulated here merely to provide * a common namespace. */ class OGfxEffect { public: enum GradientType { VerticalGradient, HorizontalGradient, DiagonalGradient, CrossDiagonalGradient, PyramidGradient, RectangleGradient, PipeCrossGradient, EllipticGradient }; enum RGBComponent { Red, Green, Blue }; enum Lighting {NorthLite, NWLite, WestLite, SWLite, SouthLite, SELite, EastLite, NELite}; /** * Create a gradient from color a to color b of the specified type. * * @param pixmap The pixmap to process. * @param ca Color a. * @param cb Color b. * @param type The type of gradient. * @param ncols The number of colors to use when not running on a * truecolor display. The gradient will be dithered to this number of * colors. Pass 0 to prevent dithering. * @return Returns the generated pixmap, for convenience. */ static QPixmap& gradient(QPixmap& pixmap, const QColor &ca, const QColor &cb, GradientType type, int ncols=3); + static QImage gradient (const QSize &size, const QColor &ca, const QColor &cb, + GradientType type, int ncols=3); + /** * Blend the provided pixmap into a background of the indicated color * * @param pixmap The pixmap to process. * @param initial_intensity this parameter takes values from -1 to 1: * @li If positive, it tells how much to fade the image in its * less affected spot. * @li If negative, it tells roughly indicates how much of the image * remains unaffected * @param bgnd Indicates the color of the background to blend in. * @param eff Lets you choose what kind of blending you like. * @param anti_dir Blend in the opposite direction (makes no much sense * with concentric blending effects). * @return Returns the @ref pixmap(), provided for convenience. */ static QPixmap& blend(QPixmap& pixmap, float initial_intensity, const QColor &bgnd, GradientType eff, bool anti_dir=false, int ncols=3); static QImage& blend(QImage &image, float initial_intensity, const QColor &bgnd, GradientType eff, bool anti_dir); }; #endif diff --git a/noncore/styles/theme/othemestyle.cpp b/noncore/styles/theme/othemestyle.cpp index d97b026..8c7a71b 100644 --- a/noncore/styles/theme/othemestyle.cpp +++ b/noncore/styles/theme/othemestyle.cpp @@ -1085,265 +1085,266 @@ void OThemeStyle::drawPushButtonLabel( QPushButton *btn, QPainter *p ) else { p->setPen( g.button() ); p->drawLine( xx, yy + 4, xx, yy + hh - 4 ); } drawArrow( p, DownArrow, FALSE, x + w - dx - 2, y + 2, dx, h - 4, btn->colorGroup(), btn->isEnabled() ); w -= dx; } // Next, draw iconset, if any if ( btn->iconSet() && !btn->iconSet() ->isNull() ) { QIconSet::Mode mode = btn->isEnabled() ? QIconSet::Normal : QIconSet::Disabled; if ( mode == QIconSet::Normal && btn->hasFocus() ) mode = QIconSet::Active; QPixmap pixmap = btn->iconSet() ->pixmap( QIconSet::Small, mode ); int pixw = pixmap.width(); int pixh = pixmap.height(); p->drawPixmap( x + 6, y + h / 2 - pixh / 2, pixmap ); x += pixw + 8; w -= pixw + 8; } if ( widget == PushButtonDown ) { drawItem( p, x + buttonXShift(), y + buttonYShift(), w, h, AlignCenter | ShowPrefix, *cg, btn->isEnabled(), btn->pixmap(), btn->text(), -1, &cg->buttonText() ); } else { drawItem( p, x, y, w, h, AlignCenter | ShowPrefix, *cg, btn->isEnabled(), btn->pixmap(), btn->text(), -1, &cg->buttonText() ); } } int OThemeStyle::splitterWidth() const { return ( splitWidth() ); } void OThemeStyle::drawSplitter( QPainter *p, int x, int y, int w, int h, const QColorGroup &g, Orientation ) { drawBaseButton( p, x, y, w, h, *colorGroup( g, Splitter ), false, false, Splitter ); } void OThemeStyle::drawCheckMark( QPainter *p, int x, int y, int w, int h, const QColorGroup &g, bool act, bool dis ) { if ( isPixmap( CheckMark ) ) { if ( !dis ) p->drawPixmap( x + ( w - uncached( CheckMark ) ->width() ) / 2, y + ( h - uncached( CheckMark ) ->height() ) / 2, *uncached( CheckMark ) ); } else QWindowsStyle::drawCheckMark( p, x, y, w, h, *colorGroup( g, CheckMark ), act, dis ); } int OThemeStyle::popupMenuItemHeight( bool /*checkable*/, QMenuItem *mi, const QFontMetrics &fm ) { int h2, h = 0; int offset = QMAX( decoWidth( MenuItemDown ), decoWidth( MenuItem ) ) + 4; if ( mi->isSeparator() ) return ( 2 ); if ( mi->isChecked() ) h = isPixmap( CheckMark ) ? uncached( CheckMark ) ->height() + offset : offset + 16; if ( mi->pixmap() ) { h2 = mi->pixmap() ->height() + offset; h = h2 > h ? h2 : h; } if ( mi->iconSet() ) { h2 = mi->iconSet() -> pixmap( QIconSet::Small, QIconSet::Normal ).height() + offset; h = h2 > h ? h2 : h; } h2 = fm.height() + offset; h = h2 > h ? h2 : h; return ( h ); } void OThemeStyle::drawPopupMenuItem( QPainter* p, bool checkable, int maxpmw, int tab, QMenuItem* mi, const QPalette& pal, bool act, bool enabled, int x, int y, int w, int h ) { // I changed the following method to be based from Qt's instead of my own // wacky code. Works much better now :P (mosfet) static const int motifItemFrame = 2; // menu item frame width static const int motifItemHMargin = 5; // menu item hor text margin static const int motifItemVMargin = 4; // menu item ver text margin static const int motifArrowHMargin = 6; // arrow horizontal margin static const int windowsRightBorder = 12; // right border on windowsstatic const int windowsCheckMarkWidth = 12; // checkmarks width on windows bool dis = !enabled; const QColorGroup &g = dis ? *colorGroup( pal.normal(), MenuItem ) : *colorGroup( pal.normal(), MenuItemDown ); QColorGroup itemg = dis ? *colorGroup( pal.disabled(), MenuItem ) : act ? *colorGroup( pal.active(), MenuItemDown ) : *colorGroup( pal.normal(), MenuItem ); maxpmw = QMAX( maxpmw, 20 ); int checkcol = maxpmw; if ( mi && mi->isSeparator() ) { p->setPen( g.dark() ); p->drawLine( x, y, x + w, y ); p->setPen( g.light() ); p->drawLine( x, y + 1, x + w, y + 1 ); return ; } if ( act ) { drawBaseButton( p, x, y, w, h, g, true, false, MenuItemDown ); } else { drawShade( p, x, y, w, h, *colorGroup( g, MenuItem ), false, false, highlightWidth( MenuItem ), borderWidth( MenuItem ), shade() ); int dw = decoWidth( MenuItem ); - if ( !isPixmap( MenuItem ) ) + if ( !isPixmap( MenuItem ) ) { p->fillRect( x + dw, y + dw, w - dw * 2, h - dw * 2, colorGroup( g, MenuItem ) -> brush( QColorGroup::Background ) ); + } else { // process inactive item pixmaps as one large item p->drawTiledPixmap( x + dw, y + dw, w - dw * 2, h - dw * 2, *scalePixmap - // (w, p->window().height(), MenuItem), - ( w, p->clipRegion().boundingRect().height(), MenuItem ), + (w, ((QWidget *)p->device())->height(), MenuItem), + //( w, p->clipRegion().boundingRect().height(), MenuItem ), // cliping does not work in Qt/E x, y ); } if ( checkable && mi && mi->isChecked() ) { // draw 'pressed' border around checkable items // This is extremely important for items that have an iconset // because the checkmark isn't drawn in that case // An alternative would be superimposing the checkmark over // the iconset instead or not drawing the iconset at all. int mw = checkcol + motifItemFrame; drawShade( p, x, y, mw, h, g, true, false, highlightWidth( MenuItemDown ), borderWidth( MenuItemDown ), shade() ); } } if ( !mi ) return ; if ( mi->iconSet() ) { QIconSet::Mode mode = dis ? QIconSet::Disabled : QIconSet::Normal; if ( act && !dis ) mode = QIconSet::Active; QPixmap pixmap = mi->iconSet() ->pixmap( QIconSet::Small, mode ); int pixw = pixmap.width(); int pixh = pixmap.height(); QRect cr( x, y, checkcol, h ); QRect pmr( 0, 0, pixw, pixh ); pmr.moveCenter( cr.center() ); p->setPen( itemg.text() ); p->drawPixmap( pmr.topLeft(), pixmap ); } else if ( checkable ) { int mw = checkcol + motifItemFrame; int mh = h - 2 * motifItemFrame; if ( mi->isChecked() ) { drawCheckMark( p, x + motifItemFrame, y + motifItemFrame, mw, mh, itemg, act, dis ); } } p->setPen( colorGroup( g, act ? MenuItemDown : MenuItem ) ->text() ); QColor discol; if ( dis ) { discol = itemg.text(); p->setPen( discol ); } int xm = motifItemFrame + checkcol + motifItemHMargin; QString s = mi->text(); if ( !s.isNull() ) { int t = s.find( '\t' ); int m = motifItemVMargin; const int text_flags = AlignVCenter | ShowPrefix | DontClip | SingleLine; if ( t >= 0 ) { if ( dis && !act ) { p->setPen( g.light() ); p->drawText( x + w - tab - windowsRightBorder - motifItemHMargin - motifItemFrame + 1, y + m + 1, tab, h - 2 * m, text_flags, s.mid( t + 1 ) ); p->setPen( discol ); } p->drawText( x + w - tab - windowsRightBorder - motifItemHMargin - motifItemFrame, y + m, tab, h - 2 * m, text_flags, s.mid( t + 1 ) ); } if ( dis && !act ) { p->setPen( g.light() ); p->drawText( x + xm + 1, y + m + 1, w - xm + 1, h - 2 * m, text_flags, s, t ); p->setPen( discol ); } p->drawText( x + xm, y + m, w - xm - tab + 1, h - 2 * m, text_flags, s, t ); } else if ( mi->pixmap() ) { QPixmap * pixmap = mi->pixmap(); if ( pixmap->depth() == 1 ) p->setBackgroundMode( OpaqueMode ); p->drawPixmap( x + xm, y + motifItemFrame, *pixmap ); if ( pixmap->depth() == 1 ) p->setBackgroundMode( TransparentMode ); } if ( mi->popup() ) { int dim = ( h - 2 * motifItemFrame ) / 2; if ( act ) { if ( !dis ) discol = colorGroup( g, MenuItemDown ) ->text(); //discol = white; QColorGroup g2( discol, g.highlight(), white, white, dis ? discol : white, discol, white ); drawArrow( p, RightArrow, true, x + w - motifArrowHMargin - motifItemFrame - dim, y + h / 2 - dim / 2, dim, dim, g2, TRUE ); } else { drawArrow( p, RightArrow, false, x + w - motifArrowHMargin - motifItemFrame - dim, y + h / 2 - dim / 2, dim, dim, g, mi->isEnabled() ); } } } void OThemeStyle::drawFocusRect( QPainter *p, const QRect &r, const QColorGroup &g, const QColor *c, bool atBorder ) { p->setPen( g.dark() ); if ( !is3DFocus() ) QWindowsStyle::drawFocusRect( p, r, g, c, atBorder ); else { int i = focusOffset(); p->drawLine( r.x() + i, r.y() + 1 + i, r.x() + i, r.bottom() - 1 - i ); p->drawLine( r.x() + 1 + i, r.y() + i, r.right() - 1 - i, r.y() + i ); p->setPen( g.light() ); p->drawLine( r.right() - i, r.y() + 1 + i, r.right() - i, r.bottom() - 1 - i ); p->drawLine( r.x() + 1 + i, r.bottom() - i, r.right() - 1 - i, r.bottom() - i ); } } #if 0 void OThemeStyle::drawKMenuBar( QPainter *p, int x, int y, int w, int h, const QColorGroup &g, bool, QBrush * ) { drawBaseButton( p, x, y, w, h, *colorGroup( g, MenuBar ), false, false, MenuBar ); } |