Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

liquid.cpp

Go to the documentation of this file.
00001 /*-
00002  * Copyright (C)QPL 2001 Daniel M. Duley. All rights reserved.
00003  */
00004 
00005 //
00006 // (c) 2002 Robert 'sandman' Griebl
00007 //
00008 
00009 
00010 #ifndef INCLUDE_MENUITEM_DEF
00011 #define INCLUDE_MENUITEM_DEF
00012 #endif
00013 
00014 #include "liquid.h"
00015 #include "effects.h"
00016 #include "htmlmasks.h"
00017 #include "embeddata.h"
00018 
00019 /* OPIE */
00020 #include <opie2/odebug.h>
00021 #include <qpe/config.h>
00022 using namespace Opie::Core;
00023 
00024 /* QT */
00025 #include <qmenudata.h>
00026 #include <qapplication.h>
00027 #include <qpalette.h>
00028 #include <qbitmap.h>
00029 #include <qtabbar.h>
00030 #include <qpopupmenu.h>
00031 #include <qobjectlist.h>
00032 #include <qimage.h>
00033 #include <qtimer.h>
00034 #include <qpixmapcache.h>
00035 #include <qradiobutton.h>
00036 #include <qcombobox.h>
00037 #include <qdrawutil.h>
00038 #include <qwidgetlist.h>
00039 #include <qtoolbutton.h>
00040 #include <qheader.h>
00041 #include <qmenubar.h>
00042 #include <qprogressbar.h>
00043 #include <qlineedit.h>
00044 #include <qlistbox.h>
00045 
00046 /* STD */
00047 #include <unistd.h>
00048 #include <stdio.h>
00049 
00050 
00051 typedef void (QStyle::*QDrawMenuBarItemImpl) (QPainter *, int, int, int, int, QMenuItem *,
00052                           QColorGroup &, bool, bool);
00053 
00054 QDrawMenuBarItemImpl qt_set_draw_menu_bar_impl(QDrawMenuBarItemImpl impl);
00055 
00056 void TransMenuHandler::stripePixmap(QPixmap &pix, const QColor &color)
00057 {
00058     QImage img(pix.convertToImage());
00059     QImageEffect::fade(img, 0.9, color);
00060     int x, y;
00061     int r, g, b;
00062     for(y=0; y < img.height(); y+=3){
00063         unsigned int *data = (unsigned int  *) img.scanLine(y);
00064         for(x=0; x < img.width(); ++x){
00065             r = qRed(data[x]);
00066             g = qGreen(data[x]);
00067             b = qBlue(data[x]);
00068             if(r-10)
00069                 r-=10;
00070             if(g-10)
00071                 g-=10;
00072             if(b-10)
00073                 b-=10;
00074             data[x] = qRgb(r, g, b);
00075         }
00076     }
00077     pix.convertFromImage(img);
00078 }
00079 
00080 TransMenuHandler::TransMenuHandler(QObject *parent)
00081     : QObject(parent)
00082 {
00083     pixDict.setAutoDelete(true);
00084     reloadSettings();
00085 }
00086 
00087 void TransMenuHandler::reloadSettings()
00088 {
00089     pixDict.clear();
00090 
00091     Config config ( "qpe" );
00092     config. setGroup ( "Liquid-Style" );
00093 
00094     type = config. readNumEntry("Type", TransStippleBg);
00095     color = QColor ( config. readEntry("Color",  QApplication::palette().active().button().name()));
00096     fgColor = QColor ( config. readEntry("TextColor", QApplication::palette().active().text().name()));
00097     opacity = config. readNumEntry("Opacity", 10);
00098     if ( opacity < -20 )
00099         opacity = 20;
00100     else if ( opacity > 20 )
00101         opacity = 20;
00102 
00103     shadowText = config. readBoolEntry("ShadowText", true);
00104 }
00105 
00106 bool TransMenuHandler::eventFilter(QObject *obj, QEvent *ev)
00107 {
00108     QWidget *p = (QWidget *)obj;
00109 
00110     if(ev->type() == QEvent::Show){
00111         if(type == TransStippleBg || type == TransStippleBtn ||
00112            type == Custom){
00113             QApplication::syncX();
00114             QPixmap *pix = new QPixmap;
00115             if(p->testWFlags(Qt::WType_Popup)){
00116                 QRect r(p->x(), p->y(), p->width(), p->height());
00117                 QRect deskR = QApplication::desktop()->rect();
00118                 if(r.right() > deskR.right() || r.bottom() > deskR.bottom()){
00119                     r.setBottom(deskR.bottom());
00120                     r.setRight(deskR.right());
00121                 }
00122                 *pix = QPixmap::grabWindow(QApplication::desktop()-> winId(), r.x(), r.y(),
00123                                            r.width(), r.height());
00124             }
00125             else{ // tear off menu
00126                 pix->resize(p->width(), p->height());
00127                 pix->fill(Qt::black.rgb());
00128             }
00129             if(type == TransStippleBg){
00130                 stripePixmap(*pix, p->colorGroup().background());
00131             }
00132             else if(type == TransStippleBtn){
00133                 stripePixmap(*pix, p->colorGroup().button());
00134             }
00135             else{
00136                 QPixmapEffect::fade(*pix, (((float)opacity)+80)*0.01, color);
00137             }
00138 
00139             pixDict.insert(p->winId(), pix);
00140 
00141             if ( !p->inherits("QPopupMenu"))
00142                 p->setBackgroundPixmap(*pix);
00143 
00144             QObjectList *ol = p-> queryList("QWidget");
00145                         for ( QObjectListIt it( *ol ); it. current ( ); ++it ) {
00146                                 QWidget *wid = (QWidget *) it.current ( );
00147 
00148                                 wid-> setBackgroundPixmap(*pix);
00149                                 wid-> setBackgroundOrigin(QWidget::ParentOrigin);
00150             }
00151                         delete ol;
00152         }
00153     }
00154     else if(ev->type() == QEvent::Hide){
00155         if(type == TransStippleBg || type == TransStippleBtn ||
00156            type == Custom){
00157 //            owarn << "Deleting menu pixmap, width " << pixDict.find(p->winId())->width() << "" << oendl;
00158 
00159             pixDict.remove(p->winId());
00160             if ( !p->inherits("QPopupMenu"))
00161                 p->setBackgroundMode(QWidget::PaletteBackground);
00162 
00163                 QObjectList *ol = p-> queryList("QWidget");
00164                         for ( QObjectListIt it( *ol ); it. current ( ); ++it ) {
00165                                 QWidget *wid = (QWidget *) it.current ( );
00166 
00167                                 wid-> setBackgroundMode( QWidget::PaletteBackground );
00168             }
00169                         delete ol;
00170         }
00171     }
00172     return(false);
00173 }
00174 
00175 
00176 
00177 
00178 LiquidStyle::LiquidStyle()
00179     :QWindowsStyle()
00180 {
00181     setName ( "LiquidStyle" );
00182 
00183         flatTBButtons = false;
00184         currentHeader = 0;
00185 
00186     btnMaskBmp = QBitmap(37, 26, buttonmask_bits, true);
00187     btnMaskBmp.setMask(btnMaskBmp);
00188     htmlBtnMaskBmp = QBitmap(37, 26, htmlbuttonmask_bits, true);
00189     htmlBtnMaskBmp.setMask(htmlBtnMaskBmp);
00190     headerHoverID = -1;
00191     highlightWidget = NULL;
00192     setButtonDefaultIndicatorWidth(0);
00193     btnDict.setAutoDelete(true);
00194     bevelFillDict.setAutoDelete(true);
00195     smallBevelFillDict.setAutoDelete(true);
00196 
00197     rMatrix.rotate(270.0);
00198     btnBorderPix = new QPixmap;
00199     btnBorderPix->convertFromImage(qembed_findImage("buttonfill"));
00200     btnBlendPix = new QPixmap;
00201     btnBlendPix->convertFromImage(qembed_findImage("buttonborder"));
00202     bevelFillPix = new QPixmap;
00203     bevelFillPix->convertFromImage(qembed_findImage("clear_fill_large"));
00204     smallBevelFillPix = new QPixmap;
00205     smallBevelFillPix->convertFromImage(qembed_findImage("clear_fill_small"));
00206     // new stuff
00207     vsbSliderFillPix = menuPix = NULL;
00208     menuHandler = new TransMenuHandler(this);
00209     setScrollBarExtent(15, 15);
00210     int i;
00211     for(i=0; i < BITMAP_ITEMS; ++i){
00212         pixmaps[i] = NULL;
00213     }
00214     oldSliderThickness = sliderThickness();
00215     setSliderThickness(11);
00216 }
00217 
00218 LiquidStyle::~LiquidStyle()
00219 {
00220     if(btnBorderPix)
00221         delete btnBorderPix;
00222     if(btnBlendPix)
00223         delete btnBlendPix;
00224     if(bevelFillPix)
00225         delete bevelFillPix;
00226     if(smallBevelFillPix)
00227         delete smallBevelFillPix;
00228     if(vsbSliderFillPix)
00229         delete vsbSliderFillPix;
00230     if(menuPix)
00231         delete menuPix;
00232 
00233     setScrollBarExtent(16, 16);
00234     setSliderThickness(oldSliderThickness);
00235     int i;
00236     for(i=0; i < BITMAP_ITEMS; ++i){
00237         if(pixmaps[i])
00238             delete pixmaps[i];
00239     }
00240 }
00241 
00242 void LiquidStyle::drawClearBevel(QPainter *p, int x, int y, int w, int h,
00243                                 const QColor &c, const QColor &bg)
00244 {
00245 
00246     QPen oldPen = p->pen(); // headers need this
00247     int x2 = x+w-1;
00248     int y2 = y+h-1;
00249     // outer dark rect
00250     p->setPen(c.dark(130));
00251     p->drawLine(x, y+2, x, y2-2); // l
00252     p->drawLine(x2, y+2, x2, y2-2); // r
00253     p->drawLine(x+2, y, x2-2, y); // t
00254     p->drawLine(x+2, y2, x2-2, y2); // b
00255     p->drawPoint(x+1, y+1); // tl
00256     p->drawPoint(x2-1, y+1); // tr
00257     p->drawPoint(x+1, y2-1); // bl
00258     p->drawPoint(x2-1, y2-1); // br
00259 
00260     // inner top light lines
00261     p->setPen(c.light(105));
00262     p->drawLine(x+2, y+1, x2-2, y+1);
00263     p->drawLine(x+1, y+2, x2-1, y+2);
00264     p->drawLine(x+1, y+3, x+2, y+3);
00265     p->drawLine(x2-2, y+3, x2-1, y+3);
00266     p->drawPoint(x+1, y+4);
00267     p->drawPoint(x2-1, y+4);
00268 
00269     // inner bottom light lines
00270     p->setPen(c.light(110));
00271     p->drawLine(x+2, y2-1, x2-2, y2-1);
00272     p->drawLine(x+1, y2-2, x2-1, y2-2);
00273     p->drawLine(x+1, y2-3, x+2, y2-3);
00274     p->drawLine(x2-2, y2-3, x2-1, y2-3);
00275     p->drawPoint(x+1, y2-4);
00276     p->drawPoint(x2-1, y2-4);
00277 
00278     // inner left mid lines
00279     //p->setPen(c.light(105));
00280     p->setPen(c);
00281     p->drawLine(x+1, y+5, x+1, y2-5);
00282     p->drawLine(x+2, y+4, x+2, y2-4);
00283 
00284     // inner right mid lines
00285     p->drawLine(x2-1, y+5, x2-1, y2-5);
00286     p->drawLine(x2-2, y+4, x2-2, y2-4);
00287 
00288     // fill
00289     QPixmap *pix;
00290     if(h >= 32){
00291         pix = bevelFillDict.find(c.rgb());
00292         if(!pix){
00293             int h, s, v;
00294             c.hsv(&h, &s, &v);
00295             pix = new QPixmap(*bevelFillPix);
00296             adjustHSV(*pix, h, s, v);
00297             bevelFillDict.insert(c.rgb(), pix);
00298         }
00299     }
00300     else{
00301         pix = smallBevelFillDict.find(c.rgb());
00302         if(!pix){
00303             int h, s, v;
00304             c.hsv(&h, &s, &v);
00305             pix = new QPixmap(*smallBevelFillPix);
00306             adjustHSV(*pix, h, s, v);
00307             smallBevelFillDict.insert(c.rgb(), pix);
00308         }
00309     }
00310     p->drawTiledPixmap(x+3, y+3, w-6, h-6, *pix);
00311     // blend
00312     int red, green, blue;
00313     QColor btnColor(c.dark(130));
00314     red = (btnColor.red() >> 1) + (bg.red() >> 1);
00315     green = (btnColor.green() >> 1) + (bg.green() >> 1);
00316     blue = (btnColor.blue() >> 1) + (bg.blue() >> 1);
00317     btnColor.setRgb(red, green, blue);
00318 
00319     p->setPen(btnColor);
00320     p->drawPoint(x+1, y);
00321     p->drawPoint(x, y+1);
00322     p->drawPoint(x+1, y2);
00323     p->drawPoint(x, y2-1);
00324 
00325     p->drawPoint(x2-1, y);
00326     p->drawPoint(x2, y+1);
00327     p->drawPoint(x2-1, y2);
00328     p->drawPoint(x2, y2-1);
00329 
00330     p->setPen(oldPen);
00331 
00332 }
00333 
00334 void LiquidStyle::drawRoundButton(QPainter *painter, const QColor &c,
00335                                   const QColor &back, int x, int y, int w, int h,
00336                                   bool supportPushDown, bool pushedDown,
00337                                   bool autoDefault, bool isMasked)
00338 {
00339     if(w < 21 || h < 21){
00340         drawClearBevel(painter, x, y, w, h, c, back);
00341         return;
00342     }
00343     if(supportPushDown){
00344         --w, --h;
00345     }
00346     /* We don't make the round buttons smaller, since they don't look as good
00347     if(autoDefault){
00348         w = w-buttonDefaultIndicatorWidth()*2;
00349         h = h-buttonDefaultIndicatorWidth()*2;
00350     }*/
00351 
00352 
00353     QPixmap *pix = btnDict.find(c.rgb());
00354     if(!pix){
00355         int h, s, v;
00356         c.hsv(&h, &s, &v);
00357         pix = new QPixmap(*btnBorderPix);
00358         adjustHSV(*pix, h, s, v);
00359         btnDict.insert(c.rgb(), pix);
00360     }
00361     int x2 = x+w-1;
00362     int y2 = y+h-1;
00363     int bx2 = pix->width()-1;
00364     int by2 = pix->height()-1;
00365 
00366     QPixmap tmpPix(w, h);
00367     QPixmap tilePix;
00368     QPainter p;
00369     p.begin(&tmpPix);
00370 
00371     // do the fill
00372     p.drawPixmap(0, 0, *pix, 0, 0, 10, 10); // tl
00373     p.drawPixmap(x2-9, 0, *pix, bx2-9, 0, 10, 10); // tr
00374     p.drawPixmap(0, y2-9, *pix, 0, by2-9, 10, 10); // bl
00375     p.drawPixmap(x2-9, y2-9, *pix, bx2-9, by2-9, 10, 10); // br
00376 
00377     // edges
00378     tilePix.resize(pix->width()-20, 10);
00379     // top
00380     bitBlt(&tilePix, 0, 0, pix, 10, 0, pix->width()-20, 10);
00381     p.drawTiledPixmap(10, 0, w-20, 10, tilePix);
00382     // bottom
00383     bitBlt(&tilePix, 0, 0, pix, 10, by2-9, pix->width()-20, 20);
00384     p.drawTiledPixmap(10, y2-9, w-20, 10, tilePix);
00385     // left
00386     tilePix.resize(10, pix->height()-20);
00387     bitBlt(&tilePix, 0, 0, pix, 0, 10, 10, pix->height()-20);
00388     p.drawTiledPixmap(0, 10, 10, h-20, tilePix);
00389     // right
00390     bitBlt(&tilePix, 0, 0, pix, bx2-9, 10, 10, pix->height()-20);
00391     p.drawTiledPixmap(x2-9, 10, 10, h-20, tilePix);
00392 
00393     // middle
00394     tilePix.resize(pix->width()-20, pix->height()-20);
00395     bitBlt(&tilePix, 0, 0, pix, 10, 10, pix->width()-20, pix->height()-20);
00396     p.drawTiledPixmap(10, 10, w-20, h-20, tilePix);
00397 
00398 
00399     // do the blend
00400     QBitmap blendMask;
00401     if(!isMasked){
00402         //QRgb bgRgb = back.rgb();
00403         //QRgb fgRgb = c.rgb();
00404         //int r, g, b;
00405 
00406         //r = (int)(qRed(bgRgb)*0.75 + qRed(fgRgb)*0.25);
00407         //g = (int)(qGreen(bgRgb)*0.75 + qGreen(fgRgb)*0.25);
00408         //b = (int)(qBlue(bgRgb)*0.75 + qBlue(fgRgb)*0.25);
00409         //QColor blendColor(r, g, b);
00410         int hue, sat, v1, v2;
00411         QColor blendColor(autoDefault ? c : back);
00412         back.hsv(&hue, &sat, &v1);
00413         blendColor.hsv(&hue, &sat, &v2);
00414         if(v2 > v1)
00415             blendColor.setHsv(hue, sat, (int)(v1*0.75 + v2*0.25));
00416 
00417         pix = btnBorderDict.find(blendColor.rgb());
00418         if(!pix){
00419             int h, s, v;
00420             blendColor.hsv(&h, &s, &v);
00421             pix = new QPixmap(*btnBlendPix);
00422             adjustHSV(*pix, h, s, v);
00423             btnBorderDict.insert(blendColor.rgb(), pix);
00424         }
00425     }
00426     else{
00427         pix = pushedDown ? getPixmap(HTMLBtnBorderDown) :
00428             getPixmap(HTMLBtnBorder);
00429     }
00430     p.drawPixmap(0, 0, *pix, 0, 0, 10, 10); // tl
00431     p.drawPixmap(x2-9, 0, *pix, bx2-9, 0, 10, 10); // tr
00432     p.drawPixmap(0, y2-9, *pix, 0, by2-9, 10, 10); // bl
00433     p.drawPixmap(x2-9, y2-9, *pix, bx2-9, by2-9, 10, 10); // br
00434 
00435     // edges
00436     tilePix.resize(pix->width()-20, 10);
00437     blendMask.resize(pix->width()-20, 10);
00438     // top
00439     bitBlt(&tilePix, 0, 0, pix, 10, 0, pix->width()-20, 10);
00440     bitBlt(&blendMask, 0, 0, pix->mask(), 10, 0, pix->width()-20, 10);
00441     tilePix.setMask(blendMask);
00442     p.drawTiledPixmap(10, 0, w-20, 10, tilePix);
00443     // bottom
00444     bitBlt(&tilePix, 0, 0, pix, 10, by2-9, pix->width()-20, 20);
00445     bitBlt(&blendMask, 0, 0, pix->mask(), 10, by2-9, pix->width()-20, 20);
00446     tilePix.setMask(blendMask);
00447     p.drawTiledPixmap(10, y2-9, w-20, 10, tilePix);
00448     // left
00449     tilePix.resize(10, pix->height()-20);
00450     blendMask.resize(10, pix->height()-20);
00451     bitBlt(&tilePix, 0, 0, pix, 0, 10, 10, pix->height()-20);
00452     bitBlt(&blendMask, 0, 0, pix->mask(), 0, 10, 10, pix->height()-20);
00453     tilePix.setMask(blendMask);
00454     p.drawTiledPixmap(0, 10, 10, h-20, tilePix);
00455     // right
00456     bitBlt(&tilePix, 0, 0, pix, bx2-9, 10, 10, pix->height()-20);
00457     bitBlt(&blendMask, 0, 0, pix->mask(), bx2-9, 10, 10, pix->height()-20);
00458     tilePix.setMask(blendMask);
00459     p.drawTiledPixmap(x2-9, 10, 10, h-20, tilePix);
00460 
00461     p.end();
00462 
00463     // do the button mask - we don't automask buttons
00464     QBitmap btnMask(w, h);
00465     QBitmap *mask = isMasked ? &htmlBtnMaskBmp : &btnMaskBmp;
00466     p.begin(&btnMask);
00467     p.fillRect(0, 0, w, h, Qt::color0);
00468     p.drawPixmap(0, 0, *mask, 0, 0, 10, 10); // tl
00469     p.drawPixmap(x2-9, 0, *mask, bx2-9, 0, 10, 10); // tr
00470     p.drawPixmap(0, y2-9, *mask, 0, by2-9, 10, 10); // bl
00471     p.drawPixmap(x2-9, y2-9, *mask, bx2-9, by2-9, 10, 10); // br
00472     // fills
00473     p.fillRect(10, 0, w-20, 10, Qt::color1); // top
00474     p.fillRect(10, y2-9, w-20, 10, Qt::color1); // bottom
00475     p.fillRect(0, 10, w, h-20, Qt::color1); // middle
00476     p.end();
00477     tmpPix.setMask(btnMask);
00478     /*if(autoDefault){
00479         if(supportPushDown && pushedDown){
00480             painter->drawPixmap(x+3, y+3, tmpPix);
00481         }
00482         else{
00483             painter->drawPixmap(x+2, y+2, tmpPix);
00484         }
00485     }
00486     else */if(supportPushDown && pushedDown)
00487         painter->drawPixmap(x+1, y+1, tmpPix);
00488     else
00489         painter->drawPixmap(x, y, tmpPix);
00490 
00491 
00492 
00493 }
00494 
00495 
00496 QPixmap* LiquidStyle::processEmbedded(const char *label, int h, int s, int v,
00497                                       bool blend)
00498 {
00499     QImage img(qembed_findImage(label));
00500     img.detach();
00501     if(img.isNull()){ // shouldn't happen, been tested
00502         owarn << "Invalid embedded label " << label << "" << oendl;
00503         return(NULL);
00504     }
00505     if(img.depth() != 32)
00506         img = img.convertDepth(32);
00507     unsigned int *data = (unsigned int *)img.bits();
00508     int total = img.width()*img.height();
00509     int current;
00510     QColor c;
00511     int oldH, oldS, oldV;
00512     int alpha;
00513     if(v < 235)
00514         v += 20;
00515     else
00516         v = 255;
00517     float intensity = v/255.0;
00518 
00519     for(current=0; current<total; ++current){
00520         alpha = qAlpha(data[current]);
00521         c.setRgb(data[current]);
00522         c.hsv(&oldH, &oldS, &oldV);
00523         oldV = (int)(oldV*intensity);
00524         c.setHsv(h, s, oldV);
00525         if(blend && alpha != 255 && alpha != 0){
00526             float srcPercent = ((float)alpha)/255.0;
00527             float destPercent = 1.0-srcPercent;
00528             oldH = (int)((srcPercent*h) + (destPercent*bH));
00529             oldS = (int)((srcPercent*s) + (destPercent*bS));
00530             oldV = (int)((srcPercent*oldV) + (destPercent*bV));
00531             c.setHsv(oldH, oldS, oldV);
00532             alpha = 255;
00533         }
00534         data[current] = qRgba(c.red(), c.green(), c.blue(), alpha);
00535     }
00536     QPixmap *pix = new QPixmap;
00537     pix->convertFromImage(img);
00538     return(pix);
00539 }
00540 
00541 
00542 
00543 
00544 QPixmap* LiquidStyle::getPixmap(BitmapData item)
00545 {
00546 
00547     if(pixmaps[item])
00548         return(pixmaps[item]);
00549 
00550     switch(item){
00551     case HTMLBtnBorder:
00552         pixmaps[HTMLBtnBorder] = processEmbedded("htmlbtnborder", btnH, btnS, btnV);
00553         break;
00554     case HTMLBtnBorderDown:
00555         pixmaps[HTMLBtnBorderDown] = processEmbedded("htmlbtnborder", btnHoverH, btnHoverS, btnHoverV);
00556         break;
00557 
00558     case HTMLCB:
00559         pixmaps[HTMLCB] = processEmbedded("htmlcheckbox", bH, bS, bV);
00560         break;
00561     case HTMLCBHover:
00562         pixmaps[HTMLCBHover] = processEmbedded("htmlcheckbox", btnHoverH, btnHoverS, btnHoverV);
00563         break;
00564     case HTMLCBDown:
00565         pixmaps[HTMLCBDown] = processEmbedded("htmlcheckboxdown", btnH, btnS, btnV);
00566         break;
00567     case HTMLCBDownHover:
00568         pixmaps[HTMLCBDownHover] = processEmbedded("htmlcheckboxdown", btnHoverH, btnHoverS, btnHoverV);
00569         break;
00570 
00571     case HTMLRadio:
00572         pixmaps[HTMLRadio] = processEmbedded("htmlradio", bH, bS, bV);
00573                 break;
00574     case HTMLRadioHover:
00575         pixmaps[HTMLRadioHover] = processEmbedded("htmlradio", btnHoverH, btnHoverS, btnHoverV);
00576                 break;
00577     case HTMLRadioDown:
00578         pixmaps[HTMLRadioDown] = processEmbedded("htmlradiodown", btnH, btnS, btnV);
00579                 break;
00580     case HTMLRadioDownHover:
00581         pixmaps[HTMLRadioDownHover] = processEmbedded("htmlradiodown", btnHoverH, btnHoverS, btnHoverV);
00582                 break;
00583 
00584     case RadioOff:
00585         pixmaps[RadioOff] = processEmbedded("radio", bH, bS, bV /*, true*/);
00586         break;
00587     case RadioOffHover:
00588         pixmaps[RadioOffHover] = processEmbedded("radio", btnHoverH, btnHoverS, btnHoverV /*, true*/);
00589         break;
00590         case RadioOn:
00591         pixmaps[RadioOn] = processEmbedded("radio_down", btnH, btnS, btnV /*, true*/);
00592         break;
00593     case RadioOnHover:
00594         pixmaps[RadioOnHover] = processEmbedded("radio_down", btnHoverH, btnHoverS, btnHoverV /*, true*/);
00595         break;
00596 
00597     case Tab:
00598         pixmaps[Tab] = processEmbedded("tab", bH, bS, bV /*, true*/);
00599         break;
00600     case TabDown:
00601         pixmaps[TabDown] = processEmbedded("tab", btnH, btnS, btnV /*, true*/);
00602         break;
00603     case TabFocus:
00604         pixmaps[TabFocus] = processEmbedded("tab", btnHoverH, btnHoverS, btnHoverV /*, true*/);
00605         break;
00606 
00607         case CB:
00608         pixmaps[CB] = processEmbedded("checkbox", bH, bS, bV /*, true*/);
00609         break;
00610     case CBHover:
00611         pixmaps[CBHover] = processEmbedded("checkbox", btnHoverH, btnHoverS, btnHoverV /*, true*/);
00612         break;
00613     case CBDown:
00614         pixmaps[CBDown] = processEmbedded("checkboxdown", btnH, btnS, btnV /*, true*/);
00615         break;
00616     case CBDownHover:
00617         pixmaps[CBDownHover] = processEmbedded("checkboxdown", btnHoverH, btnHoverS, btnHoverV /*, true*/);
00618         break;
00619 
00620         case VSlider:
00621         pixmaps[VSlider] = processEmbedded("sliderarrow", btnH, btnS, btnV, true );
00622         *pixmaps[VSlider] = pixmaps[VSlider]->xForm(rMatrix);
00623         break;
00624     case VSBSliderTop:
00625     case VSBSliderTopHover:
00626         pixmaps[item] = processEmbedded("sbslider_top", btnH, btnS, btnV /*, true*/);
00627         break;
00628     case VSBSliderBtm:
00629     case VSBSliderBtmHover:
00630         pixmaps[item] = processEmbedded("sbslider_btm", btnH, btnS, btnV /*, true*/);
00631         break;
00632     case VSBSliderMid:
00633     case VSBSliderMidHover:
00634         pixmaps[item] = processEmbedded("sbslider_mid", btnH, btnS, btnV);
00635         break;
00636         case VSBSliderTopBg:
00637         pixmaps[VSBSliderTopBg] = processEmbedded("sbslider_top", bH, bS, bV /*, true*/);
00638         break;
00639     case VSBSliderBtmBg:
00640         pixmaps[VSBSliderBtmBg] = processEmbedded("sbslider_btm", bH, bS, bV /*, true*/);
00641         break;
00642     case VSBSliderMidBg:
00643         pixmaps[VSBSliderMidBg] = processEmbedded("sbslider_mid", bH, bS, bV);
00644         break;
00645 
00646         case HSlider:
00647         pixmaps[HSlider] = processEmbedded("sliderarrow", btnH, btnS, btnV /*, true*/);
00648         break;
00649     case HSBSliderTop:
00650     case HSBSliderTopHover:
00651         pixmaps[item] = processEmbedded("sbslider_top", btnH, btnS, btnV, true );
00652         *pixmaps[item] = pixmaps[item]->xForm(rMatrix);
00653         break;
00654     case HSBSliderBtm:
00655     case HSBSliderBtmHover:
00656         pixmaps[item] = processEmbedded("sbslider_btm", btnH, btnS, btnV, true );
00657         *pixmaps[item] = pixmaps[item]->xForm(rMatrix);
00658         break;
00659     case HSBSliderMid:
00660     case HSBSliderMidHover:
00661         pixmaps[item] = processEmbedded("sbslider_mid", btnH, btnS, btnV);
00662         *pixmaps[item] = pixmaps[item]->xForm(rMatrix);
00663         break;
00664     case HSBSliderTopBg:
00665         pixmaps[HSBSliderTopBg] = processEmbedded("sbslider_top", bH, bS, bV, true );
00666         *pixmaps[HSBSliderTopBg] = pixmaps[HSBSliderTopBg]->xForm(rMatrix);
00667         break;
00668     case HSBSliderBtmBg:
00669         pixmaps[HSBSliderBtmBg] = processEmbedded("sbslider_btm", bH, bS, bV, true );
00670         *pixmaps[HSBSliderBtmBg] = pixmaps[HSBSliderBtmBg]->xForm(rMatrix);
00671         break;
00672     case HSBSliderMidBg:
00673         pixmaps[HSBSliderMidBg] = processEmbedded("sbslider_mid", bH, bS, bV);
00674         *pixmaps[HSBSliderMidBg] = pixmaps[HSBSliderMidBg]->xForm(rMatrix);
00675         break;
00676     default:
00677         break;
00678     }
00679     return(pixmaps[item]);
00680 }
00681 
00682 void LiquidStyle::polish(QPalette &appPal)
00683 {
00684     int i;
00685     for(i=0; i < BITMAP_ITEMS; ++i){
00686         if(pixmaps[i]){
00687             delete pixmaps[i];
00688             pixmaps[i] = NULL;
00689         }
00690     }
00691     lowLightVal = 100 + (2* /*KGlobalSettings::contrast()*/ 3 +4)*10;
00692     btnDict.clear();
00693     btnBorderDict.clear();
00694     bevelFillDict.clear();
00695     smallBevelFillDict.clear();
00696 
00697     Config config ( "qpe" );
00698     config. setGroup ( "Liquid-Style" );
00699         int contrast = config. readNumEntry ( "StippleContrast", 5 );
00700         if ( contrast < 0 )
00701                 contrast = 0;
00702         else if ( contrast > 10 )
00703                 contrast = 10;
00704 
00705 //    QPalette pal = QApplication::palette();
00706 
00707     // button color stuff
00708     config. setGroup ( "Appearance" );
00709     QColor c = appPal. color ( QPalette::Active, QColorGroup::Button );
00710     if ( c == appPal. color ( QPalette::Active, QColorGroup::Background )) {
00711         // force button color to be different from background
00712         QBrush btnBrush(QColor(200, 202, 228));
00713         appPal.setBrush(QColorGroup::Button, btnBrush);
00714     }
00715     c.hsv(&btnH, &btnS, &btnV);
00716     c.light(120).hsv(&btnHoverH, &btnHoverS, &btnHoverV);
00717 
00718     // menu pixmap
00719     if(!menuPix){
00720         menuPix = new QPixmap;
00721         menuPix->resize(64, 64);
00722     }
00723     QPainter painter;
00724     menuPix->fill(c.rgb());
00725     painter.begin(menuPix);
00726     painter.setPen(c.dark(105));
00727     for(i=0; i < 63; i+=4){
00728         painter.drawLine(0, i, 63, i);
00729         painter.drawLine(0, i+1, 63, i+1);
00730     };
00731     painter.end();
00732     menuBrush.setColor(c);
00733     menuBrush.setPixmap(*menuPix);
00734 
00735     // pager brush
00736     c = c.dark(120);
00737     QPixmap *pix = smallBevelFillDict.find(c.rgb()); // better be NULL ;-)
00738     if(!pix){
00739         int h, s, v;
00740         c.hsv(&h, &s, &v);
00741         pix = new QPixmap(*smallBevelFillPix);
00742         adjustHSV(*pix, h, s, v);
00743         smallBevelFillDict.insert(c.rgb(), pix);
00744     }
00745 //    pagerHoverBrush.setColor(c);
00746 //    pagerHoverBrush.setPixmap(*pix);
00747 
00748     c = c.dark(120);
00749     pix = smallBevelFillDict.find(c.rgb()); // better be NULL ;-)
00750     if(!pix){
00751         int h, s, v;
00752         c.hsv(&h, &s, &v);
00753         pix = new QPixmap(*smallBevelFillPix);
00754         adjustHSV(*pix, h, s, v);
00755         smallBevelFillDict.insert(c.rgb(), pix);
00756     }
00757 //    pagerBrush.setColor(c);
00758 //    pagerBrush.setPixmap(*pix);
00759 
00760     // background color stuff
00761     c = appPal. color ( QPalette::Active, QColorGroup::Background );
00762 
00763     c.hsv(&bH, &bS, &bV);
00764     c.light(120).hsv(&bHoverH, &bHoverS, &bHoverV);
00765 
00766     // FIXME?
00767     if(vsbSliderFillPix)
00768         delete vsbSliderFillPix;
00769     vsbSliderFillPix = new QPixmap(bevelFillPix->xForm(rMatrix));
00770     adjustHSV(*vsbSliderFillPix, bH, bS, bV);
00771 
00772     // background brush
00773     QPixmap wallPaper(32, 32);
00774     wallPaper.fill(c.rgb());
00775     painter.begin(&wallPaper);
00776     for(i=0; i < 32; i+=4){
00777         painter.setPen(c.dark(100 + contrast));
00778         painter.drawLine(0, i, 32, i);
00779         painter.setPen(c.dark(100 + 3 * contrast / 5 ) );
00780         painter.drawLine(0, i+1, 32, i+1);
00781     };
00782     painter.end();
00783     bgBrush.setColor(c);
00784     bgBrush.setPixmap(wallPaper);
00785     appPal.setBrush(QColorGroup::Background, bgBrush);
00786 }
00787 
00788 void LiquidStyle::polish(QWidget *w)
00789 {
00790     if(w->inherits("QMenuBar")){
00791         //((QFrame*)w)->setLineWidth(0);
00792         w->setBackgroundMode(QWidget::PaletteBackground);
00793         w->setBackgroundOrigin(QWidget::ParentOrigin);
00794         return;
00795     }
00796     if(w->inherits("QToolBar")){
00797         w->installEventFilter(this);
00798         w->setBackgroundMode(QWidget::PaletteBackground);
00799         w->setBackgroundOrigin(QWidget::WidgetOrigin);
00800         return;
00801     }
00802     if(w->inherits("QPopupMenu"))
00803         w->setBackgroundMode(QWidget::NoBackground);
00804     else if(w-> testWFlags(Qt::WType_Popup) &&
00805             !w->inherits("QListBox") &&
00806             ( qstrcmp ( w-> name(), "automatic what's this? widget" ) != 0 )) {
00807         w->installEventFilter(menuHandler);
00808     }
00809 
00810     if(w->isTopLevel()){
00811         return;
00812     }
00813 
00814     if(w->inherits("QRadioButton") || w->inherits("QCheckBox") || w->inherits("QProgressBar")) {
00815         w->installEventFilter(this);
00816     }
00817 
00818     if(w->inherits("QButton") || w-> inherits("QComboBox")){
00819         w-> setBackgroundMode ( QWidget::PaletteBackground );
00820         w->setBackgroundOrigin ( QWidget::ParentOrigin);
00821     }
00822 
00823     bool isViewport = qstrcmp(w->name(), "qt_viewport") == 0 ||
00824         qstrcmp(w->name(), "qt_clipped_viewport") == 0;
00825     bool isViewportChild = w->parent() &&
00826         ((qstrcmp(w->parent()->name(), "qt_viewport") == 0) ||
00827          (qstrcmp(w->parent()->name(), "qt_clipped_viewport") == 0));
00828 
00829     if(isViewport && w->parent() && qstrcmp(w->parent()->name(), "proxyview") == 0){
00830         w->setBackgroundMode(QWidget::X11ParentRelative);
00831         return;
00832     }
00833     if(isViewportChild){
00834         if(w->inherits("QButton") || w->inherits("QComboBox")){
00835             if(w->parent()){ // heh, only way to test for KHTML children ;-)
00836                 if(w->parent()->parent()){
00837                     if(w->parent()->parent()->parent() &&
00838                        w->parent()->parent()->parent()->inherits("KHTMLView")){
00839                         w->setAutoMask(true);
00840                         w->setBackgroundMode(QWidget::NoBackground);
00841                     }
00842                 }
00843             }
00844             return;
00845         }
00846     }
00847     if(w->inherits("QHeader")){
00848         w->setMouseTracking(true);
00849         w->installEventFilter(this);
00850     }
00851     if(w-> inherits("QToolButton")) {
00852         if (w->parent()->inherits("QToolBar")) {
00853             ((QToolButton*)w)->setAutoRaise (flatTBButtons);
00854             if ( flatTBButtons )
00855                     w->setBackgroundOrigin(QWidget::ParentOrigin);
00856         }
00857         w-> installEventFilter ( this );
00858     }
00859     if(w-> inherits("QToolBarSeparator")&&w->parent()->inherits("QToolBar")) {
00860         ((QFrame *) w)-> setFrameShape ( QFrame::NoFrame );
00861     }
00862     if(w->ownPalette() && !w->inherits("QButton") && !w->inherits("QComboBox")){
00863         return;
00864     }
00865 
00866     if(w->parent() && w->parent()->isWidgetType() && !((QWidget*)w->parent())->
00867        palette().active().brush(QColorGroup::Background).pixmap()){
00868         owarn << "No parent pixmap for child widget " << w->className() << "" << oendl;
00869         return;
00870     }
00871     if(!isViewport && !isViewportChild && !w->testWFlags(WType_Popup) &&
00872            !( !w-> inherits("QLineEdit") && w-> parent() && w-> parent()-> isWidgetType ( ) && w-> parent()-> inherits ( "QMultiLineEdit" ))) {
00873         if(w->backgroundMode() == QWidget::PaletteBackground ||
00874            w->backgroundMode() == QWidget::PaletteButton){
00875             w->setBackgroundMode(w->parentWidget()->backgroundMode( )/*QWidget::X11ParentRelative*/);
00876             w->setBackgroundOrigin(QWidget::ParentOrigin);
00877 //                      w->setBackgroundMode(QWidget::NoBackground);
00878         }
00879     }
00880     if ( !w-> inherits("QFrame") || (((QFrame*) w)-> frameShape () == QFrame::NoFrame ))
00881             w-> setBackgroundOrigin ( QWidget::ParentOrigin );
00882         else if ( w-> inherits("QFrame") )
00883             w->setBackgroundOrigin ( QWidget::WidgetOrigin );
00884 
00885         if ( w->parentWidget()->inherits ( "QWidgetStack" )) {
00886             w->setBackgroundOrigin ( QWidget::WidgetOrigin );
00887         }
00888 }
00889 
00890 void LiquidStyle::unPolish(QWidget *w)
00891 {
00892     if(w->inherits("QMenuBar")){
00893         ((QFrame *)w)->setLineWidth(1);
00894         w->setBackgroundMode(QWidget::PaletteBackground);
00895         return;
00896     }
00897 
00898     if(w->inherits("QPopupMenu"))
00899         w->setBackgroundMode(QWidget::PaletteButton);
00900     else if(w-> testWFlags(Qt::WType_Popup) &&
00901             !w->inherits("QListBox") &&
00902             ( qstrcmp ( w-> name(), "automatic what's this? widget" ) != 0 )) {
00903         w->removeEventFilter(menuHandler);
00904     }
00905 
00906     if(w->isTopLevel())
00907         return;
00908 
00909     // for viewport children, don't just check for NoBackground....
00910     bool isViewportChild = w->parent() &&
00911         ((qstrcmp(w->parent()->name(), "qt_viewport") == 0) ||
00912          (qstrcmp(w->parent()->name(), "qt_clipped_viewport") == 0));
00913 
00914     w->unsetPalette();
00915     if(w->backgroundMode() == QWidget::X11ParentRelative || isViewportChild){
00916         if(w->inherits("QPushButton"))
00917             w->setBackgroundMode(QWidget::PaletteButton);
00918         else
00919             w->setBackgroundMode(QWidget::PaletteBackground);
00920     }
00921 
00922     if(isViewportChild)
00923         w->setAutoMask(false);
00924 
00925 /*
00926     if(w->inherits("QPushButton") || w-> inherits("QComboBox")){
00927         w-> setBackgroundMode ( PaletteBackground );
00928     }
00929 */
00930     if( w->inherits("QRadioButton") || w->inherits("QCheckBox") || w->inherits("QProgressBar")) {
00931        w->removeEventFilter(this);
00932     }
00933     if(w->inherits("QButton") || w->inherits("QComboBox")){
00934         if(w->parent() && w->parent()->inherits("KHTMLPart")){
00935             w->setAutoMask(false);
00936         }
00937     }
00938     if(w-> inherits("QToolButton")) {
00939         w-> removeEventFilter ( this );
00940     }
00941     if(w->inherits("QToolBar")){
00942         w->removeEventFilter(this);
00943         w->setBackgroundMode(QWidget::PaletteBackground);
00944         return;
00945     }
00946     if(w->inherits("QHeader")){
00947         w->setMouseTracking(false);
00948         w->removeEventFilter(this);
00949     }
00950 }
00951 
00952 void LiquidStyle::polish(QApplication *app)
00953 {
00954 
00955     QWindowsStyle::polish(app);
00956     menuAni = app->isEffectEnabled(UI_AnimateMenu);
00957     menuFade = app->isEffectEnabled(UI_FadeMenu);
00958     if(menuAni)
00959         app->setEffectEnabled(UI_AnimateMenu, false);
00960     if(menuFade)
00961         app->setEffectEnabled(UI_FadeMenu, false);
00962 
00963     qt_set_draw_menu_bar_impl((QDrawMenuBarItemImpl) &LiquidStyle::drawMenuBarItem);
00964 
00965     Config config ( "qpe" );
00966     config. setGroup ( "Liquid-Style" );
00967 
00968 //    if ( config. readBoolEntry ( "WinDecoration", true ))
00969 //          QApplication::qwsSetDecoration ( new LiquidDecoration ( ));
00970 
00971         flatTBButtons = config. readBoolEntry ( "FlatToolButtons", false );
00972 }
00973 
00974 void LiquidStyle::unPolish(QApplication *app)
00975 {
00976     QWindowsStyle::unPolish(app);
00977     app->setEffectEnabled(UI_AnimateMenu, menuAni);
00978     app->setEffectEnabled(UI_FadeMenu, menuFade);
00979 
00980     qt_set_draw_menu_bar_impl ( 0 );
00981 
00982 //    QApplication::qwsSetDecoration ( new QPEDecoration ( ));
00983 }
00984 
00985 
00986 /* !! HACK !! Beware
00987  *
00988  * TT forgot to make the QProgressBar widget styleable in Qt 2.x
00989  * So the only way to customize the drawing, is to intercept the
00990  * paint event - since we have to use protected functions, we need
00991  * to derive a "hack" class from QProgressBar and do the painting
00992  * in there.
00993  *
00994  * - sandman
00995  */
00996 
00997 class HackProgressBar : public QProgressBar {
00998 public:
00999         HackProgressBar ( );
01000 
01001         void paint ( QPaintEvent *event, const QColorGroup &g, QPixmap *pix )
01002         {
01003                 QPainter p( this );
01004 
01005                 if ( !contentsRect().contains( event->rect() ) ) {
01006                         p.save();
01007                         p.setClipRegion( event->region().intersect(frameRect()) );
01008                         drawFrame( &p);
01009                         p.restore();
01010                 }
01011                 if ( event->rect().intersects( contentsRect() ))  {
01012                         p.setClipRegion( event->region().intersect( contentsRect() ) );
01013 
01014                         int x, y, w, h;
01015                         contentsRect ( ). rect ( &x, &y, &w, &h );
01016 
01017                         int prog = progress ( );
01018                         int total = totalSteps ( );
01019                         if ( prog < 0 )
01020                                 prog = 0;
01021                         if ( total <= 0 )
01022                                 total = 1;
01023                         int bw = w * prog / total;
01024                         if ( bw > w )
01025                                 bw = w;
01026 
01027                         p.setPen(g.button().dark(130));
01028                         p.drawRect(x, y, bw, h);
01029                         p.setPen(g.button().light(120));
01030                         p.drawRect(x+1, y+1, bw-2, h-2);
01031 
01032                         if(bw >= 4 && h >= 4 && pix)
01033                                 p.drawTiledPixmap(x+2, y+2, bw-4, h-4, *pix);
01034 
01035                         if ( progress ( )>= 0 && totalSteps ( ) > 0 ) {
01036                                 QString pstr;
01037                                 pstr. sprintf ( "%d%%", 100 * progress()/totalSteps ());
01038                                 p. setPen ( g.text());//g.highlightedText ( ));
01039                                 p. drawText (x,y,w-1,h-1,AlignCenter,pstr);
01040                         }
01041                 }
01042         }
01043 };
01044 
01045 
01046 /*
01047  * The same for QToolButton:
01048  * TT hardcoded the drawing of the focus rect ...
01049  *
01050  * - sandman
01051  */
01052 
01053 
01054 class HackToolButton : public QToolButton {
01055 public:
01056         HackToolButton ( );
01057 
01058         void paint ( QPaintEvent *ev )
01059         {
01060                 erase ( ev-> region ( ));
01061                 QPainter p ( this );
01062                 style ( ). drawToolButton ( this, &p );
01063                 drawButtonLabel ( &p );
01064         }
01065 };
01066 
01067 /*
01068  * This is a fun method ;-) Here's an overview. KToolBar grabs resize to
01069  * force everything to erase and repaint on resize. This is going away, I'm
01070  * trying to get shaped widgets to work right without masking. QPushButton,
01071  * QComboBox, and Panel applet handles capture mouse enter and leaves in order
01072  * to set the highlightwidget and repaint for mouse hovers. CheckBoxes and
01073  * RadioButtons need to do this differently. Qt buffers these in pixmaps and
01074  * caches them in QPixmapCache, which is bad for doing things like hover
01075  * because the style methods aren't called in paintEvents if everything
01076  * is cached. We use our own Paint event handler instead. Taskbuttons and
01077  * pager buttons draw into a pixmap buffer, so we handle those with palette
01078  * modifications. For QHeader, different header items are actually one widget
01079  * that draws multiple items, so we need to check which ID is hightlighted
01080  * and draw it. Finally, we also check enter and leave events for QLineEdit,
01081  * since if it's inside a combobox we want to highlight the combobox during
01082  * hovering in the edit.
01083  */
01084 bool LiquidStyle::eventFilter(QObject *obj, QEvent *ev)
01085 {
01086     if(obj->inherits("QToolBar")){
01087         if(ev->type() == QEvent::Resize){
01088             const QObjectList *tbChildList = obj->children();
01089             QObjectListIt it(*tbChildList);
01090             QObject *child;
01091             while((child = it.current()) != NULL){
01092                 ++it;
01093                 if(child->isWidgetType())
01094                     ((QWidget *)child)->repaint(true);
01095             }
01096 
01097         }
01098     }
01099     else if(obj->inherits("QToolButton")){
01100         QToolButton *btn = (QToolButton *)obj;
01101         if(ev->type() == QEvent::FocusIn ){ // && !btn-> autoRaise ()
01102             if(btn->isEnabled()){
01103                 highlightWidget = btn;
01104                 btn->repaint(false);
01105             }
01106         }
01107         else if(ev->type() == QEvent::FocusOut ){
01108             if(btn == highlightWidget){
01109                 highlightWidget = NULL;
01110                 btn->repaint(false);
01111             }
01112         }
01113         else if(ev->type() == QEvent::Paint) {
01114                 (( HackToolButton *) btn )-> paint ((QPaintEvent *) ev );
01115                 return true;
01116         }
01117     }
01118     else if(obj->inherits("QRadioButton") || obj->inherits("QCheckBox")){
01119         QButton *btn = (QButton *)obj;
01120         bool isRadio = obj->inherits("QRadioButton");
01121         if(ev->type() == QEvent::Paint){
01122             //if(btn->autoMask())
01123             btn->erase();
01124             QPainter p;
01125             p.begin(btn);
01126             QFontMetrics fm = btn->fontMetrics();
01127             QSize lsz = fm.size(ShowPrefix, btn->text());
01128             QSize sz = isRadio ? exclusiveIndicatorSize()
01129                 : indicatorSize();
01130 
01131 /*
01132             if(btn->hasFocus()){
01133                 QRect r = QRect(0, 0, btn->width(), btn->height());
01134                 p.setPen(btn->colorGroup().button().dark(140));
01135                 p.drawLine(r.x()+1, r.y(), r.right()-1, r.y());
01136                 p.drawLine(r.x(), r.y()+1, r.x(), r.bottom()-1);
01137                 p.drawLine(r.right(), r.y()+1, r.right(), r.bottom()-1);
01138                 p.drawLine(r.x()+1, r.bottom(), r.right()-1, r.bottom());
01139             }
01140 */
01141             int x = 0;
01142             int y = (btn->height()-lsz.height()+fm.height()-sz.height())/2;
01143             if(isRadio)
01144                 drawExclusiveIndicator(&p, x, y, sz.width(), sz.height(),
01145                                        btn->colorGroup(), btn->isOn(),
01146                                        btn->isDown(), btn->isEnabled());
01147             else
01148                 drawIndicator(&p, x, y, sz.width(), sz.height(),
01149                               btn->colorGroup(), btn->state(), btn->isDown(),
01150                               btn->isEnabled());
01151             x = sz.width() + 6;
01152             y = 0;
01153             drawItem(&p, sz.width()+6+1, 0, btn->width()-(sz.width()+6+1),
01154                      btn->height(), AlignLeft|AlignVCenter|ShowPrefix,
01155                      btn->colorGroup(), btn->isEnabled(),
01156                      btn->pixmap(), btn->text());
01157             p.end();
01158             return(true);
01159         }
01160     }
01161     else if(obj->inherits("QHeader")){
01162         QHeader *hw = (QHeader *)obj;
01163         if(ev->type() == QEvent::Enter){
01164             currentHeader = hw;
01165             headerHoverID = -1;
01166         }
01167         else if(ev->type() == QEvent::Leave){
01168             currentHeader = NULL;
01169             if(headerHoverID != -1){
01170                 hw->repaint(hw->sectionPos(headerHoverID), 0,
01171                             hw->sectionSize(headerHoverID), hw->height());
01172             }
01173             headerHoverID = -1;
01174         }
01175         else if(ev->type() == QEvent::MouseMove){
01176             QMouseEvent *me = (QMouseEvent *)ev;
01177             int oldHeader = headerHoverID;
01178             headerHoverID = hw->sectionAt(me->x());
01179             if(oldHeader != headerHoverID){
01180                 // reset old header
01181                 if(oldHeader != -1){
01182                     hw->repaint(hw->sectionPos(oldHeader), 0,
01183                                 hw->sectionSize(oldHeader), hw->height());
01184                 }
01185                 if(headerHoverID != -1){
01186                     hw->repaint(hw->sectionPos(headerHoverID), 0,
01187                                 hw->sectionSize(headerHoverID), hw->height());
01188                 }
01189             }
01190         }
01191     }
01192     else if (obj-> inherits( "QProgressBar" )) {
01193         if ( ev->type() == QEvent::Paint ) {
01194                 HackProgressBar *p = (HackProgressBar *) obj;
01195                 const QColorGroup &g = p-> colorGroup ( );
01196 
01197                         QPixmap *pix = bevelFillDict.find(g.button().dark(120).rgb());
01198                         if(!pix){
01199                                 int h, s, v;
01200                                 g.button().dark(120).hsv(&h, &s, &v);
01201                                 pix = new QPixmap(*bevelFillPix);
01202                                 adjustHSV(*pix, h, s, v);
01203                                 bevelFillDict.insert(g.button().dark(120).rgb(), pix);
01204                         }
01205                 p-> paint ((QPaintEvent *) ev, g, pix );
01206                 return true;
01207         }
01208         }
01209         return false ;
01210 }
01211 
01212 void LiquidStyle::drawButton(QPainter *p, int x, int y, int w, int h,
01213                          const QColorGroup &g, bool sunken,
01214                          const QBrush *)
01215 {
01216     drawRoundButton(p, sunken ? g.background() : g.button(), g.background(),
01217                     x, y, w, h);
01218 }
01219 
01220 void LiquidStyle::drawToolButton(QPainter *p, int x, int y, int w, int h,
01221                                  const QColorGroup &g, bool sunken,
01222                                  const QBrush *)
01223 {
01224     if(p->device()->devType() != QInternal::Widget){
01225         // drawing into a temp pixmap, don't use mask
01226         QColor c = sunken ? g.button() : g.background();
01227         p->setPen(c.dark(130));
01228         p->drawRect(x, y, w, h);
01229         p->setPen(c.light(105));
01230         p->drawRect(x+1, y+1, w-2, h-2);
01231 
01232 
01233         // fill
01234         QPixmap *pix = bevelFillDict.find(c.rgb());
01235         if(!pix){
01236             int h, s, v;
01237             c.hsv(&h, &s, &v);
01238             pix = new QPixmap(*bevelFillPix);
01239             adjustHSV(*pix, h, s, v);
01240             bevelFillDict.insert(c.rgb(), pix);
01241         }
01242 
01243         p->drawTiledPixmap(x+2, y+2, w-4, h-4, *pix);
01244     }
01245     else{
01246         drawClearBevel(p, x, y, w, h, sunken ? g.button() :
01247                        highlightWidget == p->device() ? g.button().light(110) :
01248                        g.background(), g.background());
01249     }
01250 }
01251 
01252 void LiquidStyle::drawPushButton(QPushButton *btn, QPainter *p)
01253 {
01254     QRect r = btn->rect();
01255     bool sunken = btn->isOn() || btn->isDown();
01256     QColorGroup g = btn->colorGroup();
01257 
01258 
01259     //int dw = buttonDefaultIndicatorWidth();
01260     if(btn->hasFocus() || btn->isDefault()){
01261         QColor c = btn->hasFocus() ? g.button().light(110) : g.background();
01262         QPixmap *pix = bevelFillDict.find(c.rgb());
01263         if(!pix){
01264             int h, s, v;
01265             c.hsv(&h, &s, &v);
01266             pix = new QPixmap(*bevelFillPix);
01267             adjustHSV(*pix, h, s, v);
01268             bevelFillDict.insert(c.rgb(), pix);
01269         }
01270         p->setPen(c.dark(150));
01271         p->drawLine(r.x()+1, r.y(), r.right()-1, r.y());
01272         p->drawLine(r.x(), r.y()+1, r.x(), r.bottom()-1);
01273         p->drawLine(r.right(), r.y()+1, r.right(), r.bottom()-1);
01274         p->drawLine(r.x()+1, r.bottom(), r.right()-1, r.bottom());
01275         p->drawTiledPixmap(r.x()+1, r.y()+1, r.width()-2, r.height()-2, *pix);
01276     }
01277 
01278     QColor newColor = btn == highlightWidget || sunken ?
01279         g.button().light(120) : g.button();
01280 
01281     drawRoundButton(p, newColor, g.background(),
01282                     r.x(), r.y(), r.width(), r.height(), !btn->autoMask(),
01283                     sunken, btn->isDefault() || btn->autoDefault() || btn->hasFocus(),
01284                     btn->autoMask());
01285 }
01286 
01287 void LiquidStyle::drawPushButtonLabel(QPushButton *btn, QPainter *p)
01288 {
01289     int x1, y1, x2, y2, w, h;
01290     btn->rect().coords(&x1, &y1, &x2, &y2);
01291     w = btn->width();
01292     h = btn->height();
01293 
01294     bool act = btn->isOn() || btn->isDown();
01295     if(act){
01296         ++x1, ++y1;
01297     }
01298 
01299     // Draw iconset first, if any
01300     if ( btn->iconSet() && !btn->iconSet()->isNull() )
01301     {
01302         QIconSet::Mode mode = btn->isEnabled()
01303                               ? QIconSet::Normal : QIconSet::Disabled;
01304         if ( mode == QIconSet::Normal && btn->hasFocus() )
01305             mode = QIconSet::Active;
01306     QPixmap pixmap;
01307     if ( mode == QIconSet::Disabled )
01308         pixmap = btn->iconSet()->pixmap( QIconSet::Automatic, mode );
01309     else
01310         pixmap = btn->iconSet()->pixmap();
01311         int pixw = pixmap.width();
01312         int pixh = pixmap.height();
01313 
01314         p->drawPixmap( x1+6, y1+h/2-pixh/2, pixmap );
01315         x1 += pixw + 8;
01316         w -= pixw + 8;
01317     }
01318 
01319     if(act){
01320         QFont font = btn->font();
01321         font.setBold(true);
01322         p->setFont(font);
01323         QColor shadow(btn->colorGroup().button().dark(130));
01324         drawItem( p, x1+1, y1+1, w, h,
01325                   AlignCenter | ShowPrefix, btn->colorGroup(), btn->isEnabled(),
01326                   btn->pixmap(), btn->text(), -1,
01327                   &shadow);
01328 
01329         drawItem( p, x1, y1, w, h,
01330                   AlignCenter | ShowPrefix, btn->colorGroup(), btn->isEnabled(),
01331                   btn->pixmap(), btn->text(), -1, &btn->colorGroup().light());
01332     }
01333     else{
01334         /* Too blurry
01335         drawItem( p, x1+1, y1+1, w, h,
01336                   AlignCenter | ShowPrefix, btn->colorGroup(), btn->isEnabled(),
01337                   btn->pixmap(), btn->text(), -1,
01338                   &btn->colorGroup().button().dark(115));
01339                   */
01340         drawItem( p, x1, y1, w, h,
01341                   AlignCenter | ShowPrefix,
01342                   btn->colorGroup(), btn->isEnabled(),
01343                   btn->pixmap(), btn->text(), -1,
01344                   &btn->colorGroup().buttonText());
01345     }
01346 }
01347 
01348 void LiquidStyle::drawButtonMask(QPainter *p, int x, int y, int w, int h)
01349 {
01350     int x2 = x+w-1;
01351     int y2 = y+h-1;
01352 
01353     p->setPen(Qt::color1);
01354     p->fillRect(x, y, w, h, Qt::color0);
01355     if(w < 21 || h < 21){
01356         // outer rect
01357         p->drawLine(x, y+2, x, y2-2); // l
01358         p->drawLine(x2, y+2, x2, y2-2); // r
01359         p->drawLine(x+2, y, x2-2, y); // t
01360         p->drawLine(x+2, y2, x2-2, y2); // b
01361         p->drawLine(x+1, y+1, x2-1, y+1); // top second line
01362         p->drawLine(x+1, y2-1, x2-1, y2-1); // bottom second line
01363         p->fillRect(x+1, y+2, w-2, h-4, Qt::color1);
01364     }
01365     else{
01366         int x2 = x+w-1;
01367         int y2 = y+h-1;
01368         int bx2 = htmlBtnMaskBmp.width()-1;
01369         int by2 = htmlBtnMaskBmp.height()-1;
01370         p->drawPixmap(0, 0, htmlBtnMaskBmp, 0, 0, 10, 10); // tl
01371         p->drawPixmap(x2-9, 0, htmlBtnMaskBmp, bx2-9, 0, 10, 10); // tr
01372         p->drawPixmap(0, y2-9, htmlBtnMaskBmp, 0, by2-9, 10, 10); // bl
01373         p->drawPixmap(x2-9, y2-9, htmlBtnMaskBmp, bx2-9, by2-9, 10, 10); // br
01374         // fills
01375         p->fillRect(10, 0, w-20, 10, Qt::color1); // top
01376         p->fillRect(10, y2-9, w-20, 10, Qt::color1); // bottom
01377         p->fillRect(0, 10, w, h-20, Qt::color1); // middle
01378     }
01379 }
01380 
01381 void LiquidStyle::drawBevelButton(QPainter *p, int x, int y, int w, int h,
01382                               const QColorGroup &g, bool sunken,
01383                               const QBrush */*fill*/)
01384 {
01385     if(currentHeader && p->device() == currentHeader){
01386         int id = currentHeader->sectionAt(x);
01387         bool isHeaderHover = id != -1 && id == headerHoverID;
01388         drawClearBevel(p, x, y, w, h, sunken ?
01389                        g.button() : isHeaderHover ? g.button().light(110) :
01390                        g.background(), g.background());
01391     }
01392     else
01393         drawClearBevel(p, x, y, w, h, sunken ? g.button() : g.background(),
01394                       g.background());
01395 }
01396 
01397 QRect LiquidStyle::buttonRect(int x, int y, int w, int h)
01398 {
01399     return(QRect(x+5, y+5, w-10, h-10));
01400 }
01401 
01402 void LiquidStyle::drawComboButton(QPainter *painter, int x, int y, int w, int h,
01403                                  const QColorGroup &g, bool sunken,
01404                                  bool edit, bool, const QBrush *)
01405 {
01406     bool isActive = false;
01407     if (( painter->device()->devType() == QInternal::Widget ) &&
01408         (
01409          ( qApp-> focusWidget ( ) == painter-> device ( )) ||
01410          (
01411           edit &&
01412           ((QWidget *) painter-> device ( ))-> inherits ( "QComboBox" ) &&
01413           ( qApp-> focusWidget ( ) == ((QComboBox *) painter->device())->lineEdit ( ) ||
01414             qApp-> focusWidget ( ) == ((QComboBox *) painter->device())->listBox ( ))
01415          )
01416         )
01417       ) {
01418         isActive = true;
01419     }
01420 
01421     bool isMasked = false;
01422     if(painter->device()->devType() == QInternal::Widget)
01423         isMasked = ((QWidget*)painter->device())->autoMask();
01424     // TODO: Do custom code, don't just call drawRoundButton into a pixmap
01425     QPixmap tmpPix(w, h);
01426     QPainter p(&tmpPix);
01427 
01428     drawRoundButton(&p, g.button(), g.background(), 0, 0, w, h, false,
01429                     sunken, false, isMasked);
01430     if(!isActive){
01431         p.setClipRect(0, 0, w-17, h);
01432         drawRoundButton(&p, g.background(), g.background(), 0, 0, w, h, false,
01433                         sunken, false, isMasked);
01434     }
01435     p.end();
01436     int x2 = x+w-1;
01437     int y2 = y+h-1;
01438     int bx2 = btnMaskBmp.width()-1;
01439     int by2 = btnMaskBmp.height()-1;
01440     QBitmap btnMask(w, h);
01441     QBitmap *mask = isMasked ? &htmlBtnMaskBmp : &btnMaskBmp;
01442     p.begin(&btnMask);
01443     p.fillRect(0, 0, w, h, Qt::color0);
01444     p.drawPixmap(0, 0, *mask, 0, 0, 10, 10); // tl
01445     p.drawPixmap(x2-9, 0, *mask, bx2-9, 0, 10, 10); // tr
01446     p.drawPixmap(0, y2-9, *mask, 0, by2-9, 10, 10); // bl
01447     p.drawPixmap(x2-9, y2-9, *mask, bx2-9, by2-9, 10, 10); // br
01448     // fills
01449     p.fillRect(10, 0, w-20, 10, Qt::color1); // top
01450     p.fillRect(10, y2-9, w-20, 10, Qt::color1); // bottom
01451     p.fillRect(0, 10, w, h-20, Qt::color1); // middle
01452     p.end();
01453     tmpPix.setMask(btnMask);
01454 
01455     painter->drawPixmap(x, y, tmpPix);
01456 
01457     painter->setPen(g.button().dark(120));
01458     painter->drawLine(x2-16, y+1, x2-16, y2-1);
01459 
01460     if(edit){
01461         painter->setPen(g.mid());
01462         painter->drawRect(x+8, y+2, w-25, h-4);
01463     }
01464     int arrow_h = h / 3;
01465     int arrow_w = arrow_h;
01466     int arrow_x = w - arrow_w - 6;
01467     int arrow_y = (h - arrow_h) / 2;
01468     drawArrow(painter, DownArrow, false, arrow_x, arrow_y, arrow_w, arrow_h, g, true);
01469 }
01470 
01471 void LiquidStyle::drawComboButtonMask(QPainter *p, int x, int y, int w, int h)
01472 {
01473     drawButtonMask(p, x, y, w, h);
01474 }
01475 
01476 QRect LiquidStyle::comboButtonRect(int x, int y, int w, int h)
01477 {
01478     //return(QRect(x+3, y+3, w - (h / 3) - 13, h-6));
01479     return(QRect(x+9, y+3, w - (h / 3) - 20, h-6));
01480 }
01481 
01482 QRect LiquidStyle::comboButtonFocusRect(int /*x*/, int /*y*/, int /*w*/, int /*h*/)
01483 {
01484         return QRect ( );
01485 
01486 //    return(QRect(x+5, y+3, w-(h/3)-13, h-5));
01487 }
01488 
01489 void LiquidStyle::drawScrollBarControls(QPainter *p, const QScrollBar *sb,
01490                                        int sliderStart, uint controls,
01491                                        uint activeControl)
01492 {
01493     int sliderMin, sliderMax, sliderLength, buttonDim;
01494     scrollBarMetrics( sb, sliderMin, sliderMax, sliderLength, buttonDim );
01495 
01496     if (sliderStart > sliderMax)
01497         sliderStart = sliderMax;
01498 
01499     bool horiz = sb->orientation() == QScrollBar::Horizontal;
01500     QColorGroup g = sb->colorGroup();
01501     QRect addB, subHC, subB;
01502     QRect addPageR, subPageR, sliderR;
01503     int addX, addY, subX, subY;
01504     int len = horiz ? sb->width() : sb->height();
01505     int extent = horiz ? sb->height() : sb->width();
01506 
01507     // a few apps (ie: KSpread), are broken and use a hardcoded scrollbar
01508     // extent of 16. Luckily, most apps (ie: Kate), seem fixed by now.
01509     bool brokenApp;
01510     if(extent == 16)
01511         brokenApp = true;
01512     else
01513         brokenApp = false;
01514 
01515     if (horiz) {
01516         subY = addY = ( extent - buttonDim ) / 2;
01517         subX = 0;
01518         addX = len - buttonDim;
01519         if(sbBuffer.size() != sb->size())
01520             sbBuffer.resize(sb->size());
01521     }
01522     else {
01523         subX = addX = ( extent - buttonDim ) / 2;
01524         subY = 0;
01525         addY = len - buttonDim;
01526         if(sbBuffer.size() != sb->size())
01527             sbBuffer.resize(sb->size());
01528     }
01529     subB.setRect( subX,subY,0,0); // buttonDim,buttonDim );
01530     addB.setRect( addX,addY,buttonDim,buttonDim );
01531     if(horiz)
01532         subHC.setRect(addX-buttonDim,addY,buttonDim,buttonDim );
01533     else
01534         subHC.setRect(addX,addY-buttonDim,buttonDim,buttonDim );
01535 
01536     int sliderEnd = sliderStart + sliderLength;
01537     int sliderW = extent;
01538 
01539     if (horiz) {
01540         subPageR.setRect( subB.right() + 1, 0,
01541                           sliderStart - subB.right() - 1 , sliderW );
01542         addPageR.setRect( sliderEnd, 0, addX - sliderEnd - buttonDim, sliderW );
01543         sliderR .setRect( sliderStart, 0, sliderLength, sliderW );
01544     }
01545     else {
01546         subPageR.setRect( 0, subB.bottom() + 1, sliderW,
01547                           sliderStart - subB.bottom() - 1 );
01548         addPageR.setRect( 0, sliderEnd, sliderW, addY - buttonDim - sliderEnd);
01549         sliderR .setRect( 0, sliderStart, sliderW, sliderLength );
01550     }
01551 
01552     bool maxed = sb->maxValue() == sb->minValue();
01553 
01554     QPainter painter;
01555     if(!horiz){
01556         painter.begin(&sbBuffer);
01557         QRect bgR(0, subB.bottom()+1, sb->width(), (len-(buttonDim*2))+1);
01558         if(sliderR.height() >= 8){
01559             painter.drawPixmap(bgR.x()+1, bgR.y(), *vsbSliderFillPix, 0, 0,
01560                           13, 8);
01561             painter.drawPixmap(bgR.x()+1, bgR.y(), *getPixmap(VSBSliderTopBg));
01562             painter.drawTiledPixmap(bgR.x()+1, bgR.y()+8, 13,
01563                                     bgR.height()-16, *getPixmap(VSBSliderMidBg));
01564             painter.drawPixmap(bgR.x()+1, bgR.bottom()-8, *vsbSliderFillPix,
01565                           0, 0, 13, 8);
01566             painter.drawPixmap(bgR.x()+1, bgR.bottom()-8, *getPixmap(VSBSliderBtmBg));
01567         }
01568         else{
01569             painter.drawTiledPixmap(bgR.x()+1, bgR.y(), 13, bgR.height(),
01570                                     *getPixmap(VSBSliderMidBg));
01571             painter.setPen(g.background().dark(210));
01572             painter.drawRect(bgR.x()+1, bgR.y(), 13, bgR.height()-1);
01573             painter.setPen(g.mid());
01574             painter.drawPoint(bgR.x()+1, bgR.y());
01575             painter.drawPoint(bgR.x()+13, bgR.y());
01576             painter.drawPoint(bgR.x()+1, bgR.bottom()-1);
01577             painter.drawPoint(bgR.x()+13, bgR.bottom()-1);
01578         }
01579         if(controls & Slider){
01580             if(sliderR.height() >= 16){
01581                 painter.drawPixmap(sliderR.x()+1, sliderR.y(), *getPixmap(VSBSliderTop));
01582                 painter.drawTiledPixmap(sliderR.x()+1, sliderR.y()+8, 13,
01583                                         sliderR.height()-16, *getPixmap(VSBSliderMid));
01584                 painter.drawPixmap(sliderR.x()+1, sliderR.bottom()-8, *getPixmap(VSBSliderBtm));
01585             }
01586             else if(sliderR.height() >= 8){
01587                 int m = sliderR.height()/2;
01588                 painter.drawPixmap(sliderR.x()+1, sliderR.y(), *getPixmap(VSBSliderTop), 0, 0, 13, m);
01589                 painter.drawPixmap(sliderR.x()+1, sliderR.y()+m, *getPixmap(VSBSliderBtm), 0, 8-m, 13, m);
01590             }
01591             else{
01592                 painter.setPen(g.button().dark(210));
01593                 drawRoundRect(&painter, sliderR.x()+1, sliderR.y(),
01594                               13, sliderR.height());
01595                 painter.drawTiledPixmap(sliderR.x()+2, sliderR.y()+1,
01596                                         11, sliderR.height()-2,
01597                                         *getPixmap(VSBSliderMid), 1, 0);
01598             }
01599         }
01600         painter.setPen(g.mid());
01601         painter.drawLine(bgR.x(), bgR.y(), bgR.x(), bgR.bottom());
01602         painter.drawLine(bgR.right(), bgR.y(), bgR.right(), bgR.bottom());
01603         if(brokenApp && (controls & Slider)){
01604             painter.setPen(g.background());
01605             painter.drawLine(bgR.right()-1, bgR.y(), bgR.right()-1,
01606                              bgR.bottom());
01607         }
01608         painter.end();
01609     }
01610     else{
01611         painter.begin(&sbBuffer);
01612         QRect bgR(subB.right()+1, 0, (len-(buttonDim*2))+1, sb->height());
01613         if(sliderR.width() >= 8){
01614             painter.drawPixmap(bgR.x(), bgR.y()+1, *vsbSliderFillPix, 0, 0,
01615                                8, 13);
01616             painter.drawPixmap(bgR.x(), bgR.y()+1, *getPixmap(HSBSliderTopBg));
01617             painter.drawTiledPixmap(bgR.x()+8, bgR.y()+1, bgR.width()-16,
01618                                     13, *getPixmap(HSBSliderMidBg));
01619             painter.drawPixmap(bgR.right()-8, bgR.y()+1, *vsbSliderFillPix,
01620                                0, 0, 8, 13);
01621             painter.drawPixmap(bgR.right()-8, bgR.y()+1, *getPixmap(HSBSliderBtmBg));
01622         }
01623         else{
01624             painter.drawTiledPixmap(bgR.x(), bgR.y()+1, bgR.width(), 13,
01625                                     *getPixmap(HSBSliderMidBg));
01626             painter.setPen(g.background().dark(210));
01627             painter.drawRect(bgR.x(), bgR.y()+1, bgR.width()-1, 13);
01628             painter.setPen(g.mid());
01629             painter.drawPoint(bgR.x(), bgR.y()+1);
01630             painter.drawPoint(bgR.x(), bgR.bottom()-1);
01631             painter.drawPoint(bgR.right()-1, bgR.y()+1);
01632             painter.drawPoint(bgR.right()-1, bgR.bottom()-1);
01633         }
01634         if(controls & Slider){
01635             if(sliderR.width() >= 16){
01636                 painter.drawPixmap(sliderR.x(), sliderR.y()+1,
01637                                    *getPixmap(HSBSliderTop));
01638                 painter.drawTiledPixmap(sliderR.x()+8, sliderR.y()+1, sliderR.width()-16,
01639                                         13, *getPixmap(HSBSliderMid));
01640                 painter.drawPixmap(sliderR.right()-8, sliderR.y()+1,
01641                                    *getPixmap(HSBSliderBtm));
01642             }
01643             else if(sliderR.width() >= 8){
01644                 int m = sliderR.width()/2;
01645                 painter.drawPixmap(sliderR.x(), sliderR.y()+1,
01646                                    *getPixmap(HSBSliderTop), 0, 0, m, 13);
01647                 painter.drawPixmap(sliderR.right()-8, sliderR.y()+1,
01648                                    *getPixmap(HSBSliderBtm), 8-m, 0, m, 13);
01649             }
01650             else{
01651                 painter.setPen(g.button().dark(210));
01652                 drawRoundRect(&painter, sliderR.x(), sliderR.y()+1,
01653                               sliderR.width(), 13);
01654                 painter.drawTiledPixmap(sliderR.x()+1, sliderR.y()+2,
01655                                         sliderR.width()-2, 11,
01656                                         *getPixmap(HSBSliderMid), 0, 1);
01657             }
01658         }
01659         painter.setPen(g.mid());
01660         painter.drawLine(bgR.x(), bgR.y(), bgR.right(), bgR.y());
01661         painter.drawLine(bgR.x(), bgR.bottom(), bgR.right(), bgR.bottom());
01662         if(brokenApp && (controls & Slider)){
01663             painter.setPen(g.background());
01664             painter.drawLine(bgR.x(), bgR.bottom()-1, bgR.right(),
01665                              bgR.bottom()-1);
01666         }
01667         painter.end();
01668     }
01669 
01670     if ( controls & AddLine ) {
01671         drawSBButton(p, addB, g, activeControl == AddLine);
01672         drawArrow( p, horiz ? RightArrow : DownArrow,
01673                    false, addB.x()+4, addB.y()+4,
01674                    addB.width()-8, addB.height()-8, g, !maxed);
01675     }
01676     if ( controls & SubLine ) {
01677      //   drawSBButton(p, subB, g, activeControl == SubLine);
01678      //   drawArrow( p, horiz ? LeftArrow : UpArrow,
01679      //              false, subB.x()+4, subB.y()+4,
01680      //              subB.width()-8, subB.height()-8, g, !maxed);
01681         drawSBButton(p, subHC, g, activeControl == SubLine);
01682         drawArrow( p, horiz ? LeftArrow : UpArrow,
01683                    false, subHC.x()+4, subHC.y()+4,
01684                    subHC.width()-8, subHC.height()-8, g, !maxed);
01685     }
01686 
01687     if(controls & AddPage){
01688         if(addPageR.width()){
01689             p->drawPixmap(addPageR.x(), addPageR.y(), sbBuffer,
01690                           addPageR.x(), addPageR.y(), addPageR.width(),
01691                           addPageR.height());
01692         }
01693     }
01694     if(controls & SubPage){
01695         if(subPageR.height()){
01696             p->drawPixmap(subPageR.x(), subPageR.y(), sbBuffer,
01697                           subPageR.x(), subPageR.y(), subPageR.width(),
01698                           subPageR.height());
01699         }
01700     }
01701     if ( controls & Slider ) {
01702         p->drawPixmap(sliderR.x(), sliderR.y(), sbBuffer,
01703                       sliderR.x(), sliderR.y(), sliderR.width(),
01704                       sliderR.height());
01705     }
01706 }
01707 
01708 void LiquidStyle::drawSBButton(QPainter *p, const QRect &r, const QColorGroup &g,
01709                            bool down, bool /*fast*/)
01710 {
01711     p->setPen(g.mid());
01712     p->drawRect(r);
01713     QColor c(down ? g.button() : g.background());
01714     QPixmap *pix = bevelFillDict.find(c.rgb());
01715     if(!pix){
01716         int h, s, v;
01717         c.hsv(&h, &s, &v);
01718         pix = new QPixmap(*bevelFillPix);
01719         adjustHSV(*pix, h, s, v);
01720         bevelFillDict.insert(c.rgb(), pix);
01721     }
01722     p->drawTiledPixmap(r.x()+1, r.y()+1, r.width()-2, r.height()-2, *pix);
01723 
01724 }
01725 
01726 void LiquidStyle::drawSBDeco(QPainter *p, const QRect &r, const QColorGroup &g,
01727                          bool horiz)
01728 {
01729     if(horiz){
01730         if(r.width() >= 15){
01731             int y = r.y()+3;
01732             int x = r.x() + (r.width()-7)/2;
01733             int y2 = r.bottom()-3;
01734             p->setPen(g.light());
01735             p->drawLine(x, y, x, y2);
01736             p->drawLine(x+3, y, x+3, y2);
01737             p->drawLine(x+6, y, x+6, y2);
01738 
01739             p->setPen(g.mid());
01740             p->drawLine(x+1, y, x+1, y2);
01741             p->drawLine(x+4, y, x+4, y2);
01742             p->drawLine(x+7, y, x+7, y2);
01743         }
01744     }
01745     else{
01746         if(r.height() >= 15){
01747             int x = r.x()+3;
01748             int y = r.y() + (r.height()-7)/2;
01749             int x2 = r.right()-3;
01750             p->setPen(g.light());
01751             p->drawLine(x, y, x2, y);
01752             p->drawLine(x, y+3, x2, y+3);
01753             p->drawLine(x, y+6, x2, y+6);
01754 
01755             p->setPen(g.mid());
01756             p->drawLine(x, y+1, x2, y+1);
01757             p->drawLine(x, y+4, x2, y+4);
01758             p->drawLine(x, y+7, x2, y+7);
01759         }
01760     }
01761 
01762 }
01763 
01764 
01765 void LiquidStyle::scrollBarMetrics(const QScrollBar *sb, int &sliderMin,
01766                                   int &sliderMax, int &sliderLength,
01767                                   int &buttonDim)
01768 {
01769 
01770     int maxLength;
01771     int b = 0;
01772     bool horiz = sb->orientation() == QScrollBar::Horizontal;
01773     int length = horiz ? sb->width()  : sb->height();
01774     int extent = horiz ? sb->height() : sb->width();
01775 
01776     if ( length > ( extent - b*2 - 1 )*2 + b*2  )
01777         buttonDim = extent - b*2;
01778     else
01779         buttonDim = ( length - b*2 )/2 - 1;
01780 
01781     sliderMin = b + 0; // buttonDim;
01782     maxLength  = length - b*2 - buttonDim*2; // 3;
01783 
01784     if ( sb->maxValue() == sb->minValue() ) {
01785         sliderLength = maxLength;
01786     } else {
01787         sliderLength = (sb->pageStep()*maxLength)/
01788                         (sb->maxValue()-sb->minValue()+sb->pageStep());
01789         uint range = sb->maxValue()-sb->minValue();
01790         if ( sliderLength < 9 || range > INT_MAX/2 )
01791             sliderLength = 9;
01792         if ( sliderLength > maxLength )
01793             sliderLength = maxLength;
01794     }
01795     sliderMax = sliderMin + maxLength - sliderLength;
01796 
01797 }
01798 
01799 QStyle::ScrollControl LiquidStyle::scrollBarPointOver(const QScrollBar *sb,
01800                                                      int sliderStart,
01801                                                      const QPoint &p)
01802 {
01803     if ( !sb->rect().contains( p ) )
01804         return NoScroll;
01805     int sliderMin, sliderMax, sliderLength, buttonDim, pos;
01806     scrollBarMetrics( sb, sliderMin, sliderMax, sliderLength, buttonDim );
01807     pos = (sb->orientation() == QScrollBar::Horizontal)? p.x() : p.y();
01808     if ( pos < sliderMin )
01809         return SubLine;
01810     if ( pos < sliderStart )
01811         return SubPage;
01812     if ( pos < sliderStart + sliderLength )
01813         return Slider;
01814     if ( pos < sliderMax + sliderLength)
01815         return AddPage;
01816     if(pos > sliderMax + sliderLength + 16)
01817         return AddLine;
01818 
01819     return SubLine;
01820 }
01821 
01822 #define QCOORDARRLEN(x) sizeof(x)/(sizeof(QCOORD)*2)
01823 
01824 
01825 QSize LiquidStyle::exclusiveIndicatorSize() const
01826 {
01827     return(QSize(16, 16));
01828 }
01829 
01830 void LiquidStyle::drawExclusiveIndicator(QPainter *p, int x, int y, int /*w*/,
01831                                         int /*h*/, const QColorGroup &/*g*/, bool on,
01832                                         bool down, bool)
01833 {
01834     bool isActive = ( p->device()->devType() == QInternal::Widget ) && ( qApp-> focusWidget ( ) == p-> device ( ));
01835     bool isMasked = p->device() && p->device()->devType() == QInternal::Widget
01836         && ((QWidget*)p->device())->autoMask();
01837 
01838     if(isMasked){
01839         if(on || down){
01840             p->drawPixmap(x, y, isActive ? *getPixmap(HTMLRadioDownHover) :
01841                           *getPixmap(HTMLRadioDown));
01842         }
01843         else
01844             p->drawPixmap(x, y, isActive ? *getPixmap(HTMLRadioHover) :
01845                           *getPixmap(HTMLRadio));
01846 
01847     }
01848     else{
01849         if(on || down){
01850             p->drawPixmap(x, y, isActive ? *getPixmap(RadioOnHover) :
01851                           *getPixmap(RadioOn));
01852         }
01853         else
01854             p->drawPixmap(x, y, isActive ? *getPixmap(RadioOffHover) :
01855                           *getPixmap(RadioOff));
01856     }
01857 }
01858 
01859 void LiquidStyle::drawExclusiveIndicatorMask(QPainter *p, int x, int y, int w,
01860                                             int h, bool)
01861 {
01862     p->fillRect(x, y, w, h, Qt::color0);
01863     p->setPen(Qt::color1);
01864     p->drawPixmap(x, y, *getPixmap(RadioOn)->mask());
01865 }
01866 
01867 
01868 QSize LiquidStyle::indicatorSize() const
01869 {
01870     return(QSize(20, 22));
01871 }
01872 
01873 void LiquidStyle::drawIndicator(QPainter *p, int x, int y, int /*w*/, int /*h*/,
01874                             const QColorGroup &/*g*/, int state, bool /*down*/, bool)
01875 {
01876     bool isActive = ( p->device()->devType() == QInternal::Widget ) && ( qApp-> focusWidget ( ) == p-> device ( ));
01877     bool isMasked = p->device() && p->device()->devType() == QInternal::Widget
01878         && ((QWidget*)p->device())->autoMask();
01879     if(isMasked){
01880         if(state != QButton::Off){
01881             p->drawPixmap(x, y, isActive ? *getPixmap(HTMLCBDownHover) :
01882                           *getPixmap(HTMLCBDown));
01883         }
01884         else
01885             p->drawPixmap(x, y, isActive ? *getPixmap(HTMLCBHover) :
01886                           *getPixmap(HTMLCB));
01887 
01888     }
01889     else{
01890         if(state != QButton::Off){
01891             p->drawPixmap(x, y, isActive ? *getPixmap(CBDownHover) :
01892                           *getPixmap(CBDown));
01893             /*  Todo - tristate
01894              if(state == QButton::On){
01895              p->setPen(Qt::black);
01896              p->drawPixmap(3, 3, xBmp);
01897              }
01898              else{
01899              p->setPen(g.dark());
01900              p->drawRect(x+2, y+2, w-4, h-4);
01901              p->setPen(Qt::black);
01902              p->drawLine(x+3, (y+h)/2-2, x+w-4, (y+h)/2-2);
01903              p->drawLine(x+3, (y+h)/2, x+w-4, (y+h)/2);
01904              p->drawLine(x+3, (y+h)/2+2, x+w-4, (y+h)/2+2);
01905              }*/
01906         }
01907         else
01908             p->drawPixmap(x, y, isActive ? *getPixmap(CBHover) : *getPixmap(CB));
01909     }
01910 }
01911 
01912 void LiquidStyle::drawIndicatorMask(QPainter *p, int x, int y, int /*w*/, int /*h*/,
01913                                    int /*state*/)
01914 {
01915     // needed for some reason by KHtml, even tho it's all filled ;P
01916     p->drawPixmap(x, y, *getPixmap(HTMLCB)->mask());
01917 
01918 }
01919 
01920 void LiquidStyle::drawSlider(QPainter *p, int x, int y, int w, int h,
01921                          const QColorGroup &/*g*/, Orientation orient,
01922                          bool, bool)
01923 {
01924     QWidget *parent = (QWidget *)p->device();
01925     p->setBrushOrigin(parent->pos());
01926     parent->erase(x, y, w, h);
01927     p->drawPixmap(x, y, orient == Qt::Horizontal ? *getPixmap(HSlider) :
01928                   *getPixmap(VSlider));
01929 }
01930 
01931 void LiquidStyle::drawSliderMask(QPainter *p, int x, int y, int /*w*/, int /*h*/,
01932                              Orientation orient, bool, bool)
01933 {
01934     p->drawPixmap(x, y, orient == Qt::Horizontal ? *getPixmap(HSlider)->mask() :
01935                   *getPixmap(VSlider)->mask());
01936 }
01937 
01938 int LiquidStyle::sliderLength() const
01939 {
01940     return(10);
01941 }
01942 
01943 #define QCOORDARRLEN(x) sizeof(x)/(sizeof(QCOORD)*2)
01944 
01945 void LiquidStyle::drawArrow(QPainter *p, Qt::ArrowType type, bool on, int x,
01946                             int y, int w, int h, const QColorGroup &g,
01947                             bool enabled, const QBrush *)
01948 {
01949     static const QCOORD u_arrow[]={3,1, 4,1, 2,2, 5,2, 1,3, 6,3, 0,4, 7,4, 0,5, 7,5};
01950     static const QCOORD d_arrow[]={0,2, 7,2, 0,3, 7,3, 1,4, 6,4, 2,5, 5,5, 3,6, 4,6};
01951     static const QCOORD l_arrow[]={1,3, 1,4, 2,2, 2,5, 3,1, 3,6, 4,0, 4,7, 5,0, 5,7};
01952     static const QCOORD r_arrow[]={2,0, 2,7, 3,0, 3,7, 4,1, 4,6, 5,2, 5,5, 6,3, 6,4};
01953 
01954     p->setPen(enabled ? on ? g.light() : g.buttonText() : g.mid());
01955     if(w > 8){
01956         x = x + (w-8)/2;
01957         y = y + (h-8)/2;
01958     }
01959 
01960     QPointArray a;
01961     switch(type){
01962     case Qt::UpArrow:
01963         a.setPoints(QCOORDARRLEN(u_arrow), u_arrow);
01964         break;
01965     case Qt::DownArrow:
01966         a.setPoints(QCOORDARRLEN(d_arrow), d_arrow);
01967         break;
01968     case Qt::LeftArrow:
01969         a.setPoints(QCOORDARRLEN(l_arrow), l_arrow);
01970         break;
01971     default:
01972         a.setPoints(QCOORDARRLEN(r_arrow), r_arrow);
01973         break;
01974     }
01975 
01976     a.translate(x, y);
01977     p->drawLineSegments(a);
01978 }
01979 
01980 
01981 void LiquidStyle::drawMenuBarItem(QPainter *p, int x, int y, int w, int h,
01982                             QMenuItem *mi, QColorGroup &g, bool /*enabled*/, bool active )
01983 {
01984     if(active){
01985         x -= 2; // Bug in Qt/E
01986         y -= 2;
01987         w += 2;
01988         h += 2;
01989     }
01990 
01991     QWidget *parent = (QWidget *)p->device();
01992     p->setBrushOrigin(parent->pos());
01993     parent->erase(x, y, w, h);
01994 
01995     if(menuHandler->useShadowText()){
01996         QColor shadow;
01997         if(p->device() && p->device()->devType() == QInternal::Widget &&
01998            ((QWidget *)p->device())->inherits("QMenuBar")){
01999             shadow = ((QMenuBar*)p->device())->isTopLevel() ? g.button().dark(130) :
02000                 g.background().dark(130);
02001         }
02002         else
02003             shadow = g.background().dark(130);
02004 
02005                 QPixmap *dummy = 0;
02006 
02007                 if ( mi-> pixmap ( ) && !mi-> pixmap ( )-> isNull ( )) {
02008                         dummy = new QPixmap ( mi-> pixmap ( )-> size ( ));
02009                         QBitmap dummy_mask ( dummy-> size ( ));
02010                         dummy_mask. fill ( color1 );
02011                         dummy-> setMask ( dummy_mask );
02012                 }
02013 
02014         if(active){
02015             drawClearBevel(p, x+1, y+1, w-1, h-1, g.button(), g.background());
02016             QApplication::style().drawItem(p, x+1, y+1, w, h,
02017                                            AlignCenter|ShowPrefix|DontClip|SingleLine,
02018                                            g, mi->isEnabled(), dummy, mi->text(),
02019                                            -1, &shadow);
02020             QApplication::style().drawItem(p, x, y, w, h,
02021                                            AlignCenter|ShowPrefix|DontClip|SingleLine,
02022                                            g, mi->isEnabled(), mi-> pixmap ( ), mi->text(),
02023                                            -1, &g.text());
02024         }
02025         else{
02026             QApplication::style().drawItem(p, x+1, y+1, w, h,
02027                                            AlignCenter|ShowPrefix|DontClip|SingleLine,
02028                                            g, mi->isEnabled(), dummy, mi->text(),
02029                                            -1, &shadow);
02030             QApplication::style().drawItem(p, x, y, w, h,
02031                                            AlignCenter|ShowPrefix|DontClip|SingleLine,
02032                                            g, mi->isEnabled(), mi-> pixmap ( ), mi->text(),
02033                                            -1, &g.text());
02034         }
02035         delete dummy;
02036     }
02037     else{
02038         if(active)
02039             drawClearBevel(p, x+1, y+1, w-1, h-1, g.button(), g.background());
02040         QApplication::style().drawItem(p, x, y, w, h,
02041                                        AlignCenter|ShowPrefix|DontClip|SingleLine,
02042                                        g, mi->isEnabled(), mi-> pixmap ( ), mi->text(),
02043                                        -1, &g.text());
02044     }
02045 }
02046 
02047 void LiquidStyle::drawPopupPanel(QPainter *p, int x, int y, int w, int h,
02048                                  const QColorGroup &g, int /*lineWidth*/,
02049                                  const QBrush * /*fill*/)
02050 {
02051     QColor c;
02052     switch(menuHandler->transType()){
02053     case None:
02054     case StippledBg:
02055     case TransStippleBg:
02056         c = g.background();
02057         break;
02058     case StippledBtn:
02059     case TransStippleBtn:
02060         c = g.button();
02061         break;
02062     default:
02063         c = menuHandler->bgColor();
02064     }
02065     p->setPen(c.dark(140));
02066     p->drawRect(x, y, w, h);
02067     p->setPen(c.light(120));
02068     p->drawRect(x+1, y+1, w-2, h-2);
02069 }
02070 
02071 void LiquidStyle::drawPopupMenuItem( QPainter* p, bool checkable, int maxpmw,
02072                                      int tab, QMenuItem* mi,
02073                                      const QPalette& pal, bool act,
02074                                      bool enabled, int x, int y, int w, int h)
02075 {
02076 static const int motifItemFrame         = 2;
02077 static const int motifItemHMargin       = 3;
02078 static const int motifItemVMargin       = 2;
02079 static const int motifArrowHMargin      = 6;
02080 static const int windowsRightBorder     = 12;
02081 
02082     maxpmw = QMAX( maxpmw, 20 );
02083 
02084 
02085     bool dis = !enabled;
02086     QColorGroup itemg = dis ? pal.disabled() : pal.active();
02087 
02088     int checkcol = maxpmw;
02089     if(act){
02090 
02091         // FIXME
02092         drawClearBevel(p, x, y, w, h, itemg.button(), itemg.background());
02093     }
02094     //else if(((QWidget*)p->device())->backgroundPixmap()){
02095     //    p->drawPixmap(x, y, *((QWidget*)p->device())->backgroundPixmap(),
02096     //                  x, y, w, h);
02097     //}
02098     else{
02099         if(menuHandler->transType() == None){
02100             p->fillRect(x, y, w, h, pal.active().background());
02101         }
02102         else if(menuHandler->transType() == StippledBg){
02103             p->fillRect(x, y, w, h, bgBrush);
02104         }
02105         else if(menuHandler->transType() == StippledBtn){
02106             p->fillRect(x, y, w, h, menuBrush);
02107         }
02108         else{
02109             QPixmap *pix = menuHandler->pixmap(((QWidget*)p->device())->winId());
02110             if(pix)
02111                 p->drawPixmap(x, y, *pix, x, y, w, h);
02112         }
02113     }
02114 
02115     if(!mi)
02116         return;
02117 
02118     QColor discol;
02119     if (dis) {
02120         discol = itemg.mid();
02121         p->setPen(discol);
02122     }
02123 
02124     QColorGroup cg2(itemg);
02125 
02126     if(menuHandler->transType() == Custom){
02127         cg2.setColor(QColorGroup::Foreground, menuHandler->textColor());
02128         cg2.setColor(QColorGroup::Text, menuHandler->textColor());
02129         cg2.setColor(QColorGroup::Light, menuHandler->textColor().light(120));
02130         cg2.setColor(QColorGroup::Mid, menuHandler->textColor().dark(120));
02131     }
02132     else{
02133         cg2 = QColorGroup(discol, itemg.highlight(), black, black,
02134                           dis ? discol : black, discol, black);
02135     }
02136 
02137     if(mi->isSeparator()){
02138         QColor c;
02139         switch(menuHandler->transType()){
02140         case None:
02141         case StippledBg:
02142         case TransStippleBg:
02143             c = QApplication::palette().active().background();
02144             break;
02145         case StippledBtn:
02146         case TransStippleBtn:
02147             c = QApplication::palette().active().button();
02148             break;
02149         default:
02150             c = menuHandler->bgColor();
02151         }
02152         p->setPen(c.dark(140));
02153         p->drawLine(x, y, x+w, y );
02154         p->setPen(c.light(115));
02155         p->drawLine(x, y+1, x+w, y+1 );
02156         return;
02157     }
02158     if(mi->iconSet()) {
02159         QIconSet::Mode mode = dis? QIconSet::Disabled : QIconSet::Normal;
02160         if (!dis)
02161             mode = QIconSet::Active;
02162         QPixmap pixmap;
02163         if ( mode == QIconSet::Disabled )
02164             pixmap = mi->iconSet()->pixmap( QIconSet::Automatic, mode );
02165         else
02166             pixmap = mi->iconSet()->pixmap();
02167         int pixw = pixmap.width();
02168         int pixh = pixmap.height();
02169         QRect cr(x, y, checkcol, h);
02170         QRect pmr(0, 0, pixw, pixh);
02171         pmr.moveCenter( cr.center() );
02172         p->setPen(itemg.highlightedText());
02173         p->drawPixmap(pmr.topLeft(), pixmap );
02174 
02175     }
02176     else if(checkable) {
02177         int mw = checkcol + motifItemFrame;
02178         int mh = h - 2*motifItemFrame;
02179         if (mi->isChecked()){
02180             drawCheckMark( p, x + motifItemFrame,
02181                            y+motifItemFrame, mw, mh, cg2, act, dis );
02182         }
02183     }
02184     if(menuHandler->transType() == Custom)
02185         p->setPen(menuHandler->textColor());
02186     else
02187         p->setPen(itemg.text());
02188 
02189 
02190     int xm = motifItemFrame + checkcol + motifItemHMargin;
02191     QString s = mi->text();
02192     if (!s.isNull()) {
02193         int t = s.find( '\t' );
02194         int m = motifItemVMargin;
02195         const int text_flags = AlignVCenter|ShowPrefix | DontClip | SingleLine;
02196         QPen oldPen = p->pen();
02197         if(menuHandler->useShadowText()){
02198             if(menuHandler->transType() == Custom)
02199                 p->setPen(menuHandler->bgColor().dark(130));
02200             else if(menuHandler->transType() == StippledBtn ||
02201                     menuHandler->transType() == TransStippleBtn)
02202                 p->setPen(itemg.button().dark(130));
02203             else
02204                 p->setPen(bgBrush.color().dark(130));
02205 
02206             if (t >= 0) {
02207                 p->drawText(x+w-tab-windowsRightBorder-motifItemHMargin-motifItemFrame+2,
02208                             y+m+2, tab-1, h-2*m-1, text_flags, s.mid( t+1 ));
02209             }
02210             p->drawText(x+xm+1, y+m+1, w-xm-tab, h-2*m-1, text_flags, s, t);
02211         }
02212         p->setPen(oldPen);
02213         if (t >= 0) {
02214             p->drawText(x+w-tab-windowsRightBorder-motifItemHMargin-motifItemFrame+1,
02215                         y+m+1, tab, h-2*m, text_flags, s.mid( t+1 ));
02216         }
02217         p->drawText(x+xm, y+m, w-xm-tab+1, h-2*m, text_flags, s, t);
02218 
02219     }
02220     else if (mi->pixmap()) {
02221         QPixmap *pixmap = mi->pixmap();
02222         if (pixmap->depth() == 1)
02223             p->setBackgroundMode(OpaqueMode);
02224         p->drawPixmap( x+xm, y+motifItemFrame, *pixmap);
02225         if (pixmap->depth() == 1)
02226             p->setBackgroundMode(TransparentMode);
02227     }
02228     if (mi->popup()) {
02229         int dim = (h-2*motifItemFrame) / 2;
02230         drawArrow(p, RightArrow, true,
02231                   x+w - motifArrowHMargin - motifItemFrame - dim,  y+h/2-dim/2,
02232                   dim, dim, cg2, TRUE);
02233     }
02234 }
02235 
02236 int LiquidStyle::popupMenuItemHeight(bool /*checkable*/, QMenuItem *mi,
02237                                  const QFontMetrics &fm)
02238 {
02239     if (mi->isSeparator())
02240         return 2;
02241 
02242     int h = 0;
02243     if (mi->pixmap())
02244         h = mi->pixmap()->height();
02245 
02246     if (mi->iconSet())
02247         h = QMAX(mi->iconSet()->pixmap().height(), h);
02248 
02249     h = QMAX(fm.height() + 4, h);
02250 
02251     // we want a minimum size of 18
02252     h = QMAX(h, 18);
02253 
02254     return h;
02255 }
02256 
02257 
02258 void LiquidStyle::drawFocusRect(QPainter *p, const QRect &r,
02259                             const QColorGroup &g, const QColor *c,
02260                             bool atBorder)
02261 {
02262     // are we painting a widget?
02263     if(p->device()->devType() == QInternal::Widget){
02264         // if so does it use a special focus rectangle?
02265         QWidget *w = (QWidget *)p->device();
02266         if(w->inherits("QPushButton") || w->inherits("QSlider") || w->inherits("QComboBox") || w->inherits("QToolButton" )){
02267             return;
02268         }
02269         else{
02270             QWindowsStyle::drawFocusRect(p, r, g, c, atBorder);
02271         }
02272     }
02273     else
02274         QWindowsStyle::drawFocusRect(p, r, g, c, atBorder);
02275 
02276 }
02277 
02278 void LiquidStyle::polishPopupMenu(QPopupMenu *mnu)
02279 {
02280     mnu->installEventFilter(menuHandler);
02281     QWindowsStyle::polishPopupMenu(mnu);
02282 }
02283 
02284 void LiquidStyle::drawTab(QPainter *p, const QTabBar *tabBar, QTab *tab,
02285                       bool selected)
02286 {
02287     if(tabBar->shape() != QTabBar::RoundedAbove){
02288         QWindowsStyle::drawTab(p, tabBar, tab, selected);
02289         return;
02290     }
02291     QPixmap tilePix;
02292     QRect r = tab->rect();
02293     //QPixmap *pix = selected ? tabBar->hasFocus() ? pixmaps[TabFocus] :
02294     //    pixmaps[TabDown] : pixmaps[Tab];
02295 
02296     QPixmap *pix = selected ? getPixmap(TabDown) : getPixmap(Tab);
02297     p->drawPixmap(r.x(), r.y(), *pix, 0, 0, 9, r.height());
02298     p->drawPixmap(r.right()-9, r.y(), *pix, pix->width()-9, 0, 9, r.height());
02299     tilePix.resize(pix->width()-18, r.height());
02300     bitBlt(&tilePix, 0, 0, pix, 9, 0, pix->width()-18, r.height());
02301     p->drawTiledPixmap(r.x()+9, r.y(), r.width()-18, r.height(), tilePix);
02302     QColor c = tabBar->colorGroup().button();
02303     if(!selected){
02304         p->setPen(c.dark(130));
02305         p->drawLine(r.x(), r.bottom(), r.right(), r.bottom());
02306     }
02307 
02308     /*
02309     p->setPen(c.light(110));
02310     p->drawLine(r.x(), r.bottom()+1, r.right(), r.bottom()+1);
02311     p->setPen(c);
02312     p->drawLine(r.x(), r.bottom()+2, r.right(), r.bottom()+2);
02313     p->setPen(c.light(110));
02314     p->drawLine(r.x(), r.bottom()+3, r.right(), r.bottom()+3);
02315     p->setPen(c.light(120));
02316     p->drawLine(r.x(), r.bottom()+4, r.right(), r.bottom()+4);
02317     */
02318 
02319     /*
02320     QColor c = tabBar->colorGroup().button();
02321     pix = bevelFillDict.find(c.rgb());
02322     if(!pix){
02323         int h, s, v;
02324         c.hsv(&h, &s, &v);
02325         pix = new QPixmap(*bevelFillPix);
02326         adjustHSV(*pix, h, s);
02327         bevelFillDict.insert(c.rgb(), pix);
02328     }*/
02329 
02330     /*
02331     QRect r = tab->rect();
02332     QColorGroup g = tabBar->colorGroup();
02333     if(!selected){
02334         r.setY(r.y()+1);
02335         p->setPen(g.dark());
02336         p->drawLine(r.x(), r.y()+4, r.x(), r.bottom()-2);
02337         p->drawLine(r.x(), r.y()+4, r.x()+4, r.y());
02338         p->drawLine(r.x()+4, r.y(), r.right()-1, r.y());
02339         p->drawLine(r.right(), r.y()+1, r.right(), r.bottom()-2);
02340 
02341         p->setPen(g.midlight());
02342         p->drawLine(r.x()+1, r.y()+4, r.x()+1, r.bottom());
02343         p->drawLine(r.x()+1, r.y()+4, r.x()+4, r.y()+1);
02344         p->drawLine(r.x()+5, r.y()+1, r.right()-2, r.y()+1);
02345         p->drawLine(r.x(), r.bottom(), r.right(), r.bottom());
02346 
02347         p->setPen(g.mid());
02348         p->drawPoint(r.right()-1, r.y()+1);
02349         p->drawLine(r.x()+4, r.y()+2, r.right()-1, r.y()+2);
02350         p->drawLine(r.x()+3, r.y()+3, r.right()-1, r.y()+3);
02351 
02352         p->fillRect(r.x()+2, r.y()+4, r.width()-3, r.height()-6,
02353                     g.brush(QColorGroup::Mid));
02354 
02355         p->setPen(g.light());
02356         p->drawLine(r.x(), r.bottom()-1, r.right(), r.bottom()-1);
02357 
02358     }
02359     else{
02360         p->setPen(g.light());
02361         p->drawLine(r.x(), r.y()+4, r.x(), r.bottom());
02362         p->drawLine(r.x(), r.y()+4, r.x()+4, r.y());
02363         p->drawLine(r.x()+4, r.y(), r.right()-1, r.y());
02364         p->setPen(g.dark());
02365         p->drawLine(r.right(), r.y()+1, r.right(), r.bottom());
02366 
02367         p->setPen(g.midlight());
02368         p->drawLine(r.x()+1, r.y()+4, r.x()+1, r.bottom());
02369         p->drawLine(r.x()+1, r.y()+4, r.x()+4, r.y()+1);
02370         p->drawLine(r.x()+5, r.y()+1, r.right() - 2, r.y()+1);
02371         p->setPen(g.mid());
02372         p->drawLine(r.right()-1, r.y()+1, r.right()-1, r.bottom());
02373     }*/
02374 
02375 }
02376 
02377 
02378 
02379 void LiquidStyle::drawTabMask(QPainter *p, const QTabBar*, QTab *tab,
02380                              bool selected)
02381 
02382 
02383 {
02384     //p->fillRect(tab->rect(), Qt::color1);
02385     QRect r = tab->rect();
02386     QPixmap *pix = selected ? getPixmap(TabDown) : getPixmap(Tab);
02387     p->drawPixmap(r.x(), r.y(), *pix->mask(), 0, 0, 9, r.height());
02388     p->drawPixmap(r.right()-9, r.y(), *pix->mask(), pix->width()-9, 0, 9, r.height());
02389     p->fillRect(r.x()+9, r.y(), r.width()-18, r.height(), Qt::color1);
02390 }
02391 
02392 void LiquidStyle::tabbarMetrics(const QTabBar *t, int &hFrame, int &vFrame,
02393                             int &overlap)
02394 {
02395     if(t->shape() == QTabBar::RoundedAbove){
02396         overlap = 1;
02397         hFrame = 18; // was 24
02398         vFrame = 8; // was 10
02399     }
02400     else
02401         QWindowsStyle::tabbarMetrics(t, hFrame, vFrame, overlap);
02402 }
02403 
02404 
02405 
02406 void LiquidStyle::drawSplitter(QPainter *p, int x, int y, int w, int h,
02407                            const QColorGroup &g, Orientation)
02408 {
02409     drawClearBevel(p, x, y, w, h, highlightWidget == p->device() ?
02410                    g.button().light(120) : g.button(), g.background());
02411 }
02412 
02413 
02414 void LiquidStyle::drawPanel(QPainter *p, int x, int y, int w, int h,
02415                         const QColorGroup &g, bool sunken,
02416                         int lineWidth, const QBrush *fill)
02417 {
02418     if(p->device()->devType() == QInternal::Widget &&
02419        ((QWidget *)p->device())->inherits("QLineEdit")){
02420         int x2 = x+w-1;
02421         int y2 = y+h-1;
02422         p->setPen(g.dark());
02423         p->drawRect(x, y, w, h);
02424         p->setPen(g.mid());
02425         p->drawLine(x+1, y+1, x2-2, y+1);
02426         p->drawLine(x+1, y+1, x+1, y2-1);
02427     }
02428     else if(lineWidth != 2 || !sunken)
02429         QWindowsStyle::drawPanel(p, x, y, w, h, g, sunken, lineWidth, fill);
02430     else{
02431         QPen oldPen = p->pen();
02432         int x2 = x+w-1;
02433         int y2 = y+h-1;
02434         p->setPen(g.light());
02435         p->drawLine(x, y2, x2, y2);
02436         p->drawLine(x2, y, x2, y2);
02437         p->setPen(g.mid());
02438         p->drawLine(x, y, x2, y);
02439         p->drawLine(x, y, x, y2);
02440 
02441         p->setPen(g.midlight());
02442         p->drawLine(x+1, y2-1, x2-1, y2-1);
02443         p->drawLine(x2-1, y+1, x2-1, y2-1);
02444         p->setPen(g.dark());
02445         p->drawLine(x+1, y+1, x2-1, y+1);
02446         p->drawLine(x+1, y+1, x+1, y2-1);
02447         p->setPen(oldPen);
02448         if(fill){
02449             // I believe here we are only supposed to fill if there is a
02450             // specified fill brush...
02451             p->fillRect(x+2, y+2, w-4, h-4, *fill);
02452         }
02453     }
02454 }
02455 
02456 
02457 void LiquidStyle::adjustHSV(QPixmap &pix, int h, int s, int v)
02458 {
02459     QBitmap *maskBmp = NULL;
02460     if(pix.mask())
02461         maskBmp = new QBitmap(*pix.mask());
02462     QImage img = pix.convertToImage();
02463     if(img.depth() != 32)
02464         img = img.convertDepth(32);
02465     unsigned int *data = (unsigned int *)img.bits();
02466     int total = img.width()*img.height();
02467     int current;
02468     QColor c;
02469     int oldH, oldS, oldV;
02470     if(v < 235)
02471         v += 20;
02472     else
02473         v = 255;
02474     float intensity = v/255.0;
02475 
02476     for(current=0; current<total; ++current){
02477         c.setRgb(data[current]);
02478         c.hsv(&oldH, &oldS, &oldV);
02479         oldV = (int)(oldV*intensity);
02480         c.setHsv(h, s, oldV);
02481         data[current] = c.rgb();
02482     }
02483     pix.convertFromImage(img);
02484     if(maskBmp)
02485         pix.setMask(*maskBmp);
02486 }
02487 
02488 void LiquidStyle::intensity(QPixmap &pix, float percent)
02489 {
02490     QImage image = pix.convertToImage();
02491     int i, tmp, r, g, b;
02492     int segColors = image.depth() > 8 ? 256 : image.numColors();
02493     unsigned char *segTbl = new unsigned char[segColors];
02494     int pixels = image.depth() > 8 ? image.width()*image.height() :
02495         image.numColors();
02496     unsigned int *data = image.depth() > 8 ? (unsigned int *)image.bits() :
02497         (unsigned int *)image.colorTable();
02498 
02499     bool brighten = (percent >= 0);
02500     if(percent < 0)
02501         percent = -percent;
02502 
02503     if(brighten){ // keep overflow check out of loops
02504         for(i=0; i < segColors; ++i){
02505             tmp = (int)(i*percent);
02506             if(tmp > 255)
02507                 tmp = 255;
02508             segTbl[i] = tmp;
02509         }
02510     }
02511     else{
02512         for(i=0; i < segColors; ++i){
02513             tmp = (int)(i*percent);
02514             if(tmp < 0)
02515                 tmp = 0;
02516             segTbl[i] = tmp;
02517         }
02518     }
02519 
02520     if(brighten){ // same here
02521         for(i=0; i < pixels; ++i){
02522             r = qRed(data[i]);
02523             g = qGreen(data[i]);
02524             b = qBlue(data[i]);
02525             r = r + segTbl[r] > 255 ? 255 : r + segTbl[r];
02526             g = g + segTbl[g] > 255 ? 255 : g + segTbl[g];
02527             b = b + segTbl[b] > 255 ? 255 : b + segTbl[b];
02528             data[i] = qRgb(r, g, b);
02529         }
02530     }
02531     else{
02532         for(i=0; i < pixels; ++i){
02533             r = qRed(data[i]);
02534             g = qGreen(data[i]);
02535             b = qBlue(data[i]);
02536             r = r - segTbl[r] < 0 ? 0 : r - segTbl[r];
02537             g = g - segTbl[g] < 0 ? 0 : g - segTbl[g];
02538             b = b - segTbl[b] < 0 ? 0 : b - segTbl[b];
02539             data[i] = qRgb(r, g, b);
02540         }
02541     }
02542     delete [] segTbl;
02543     pix.convertFromImage(image);
02544 }
02545 
02546 void LiquidStyle::drawRoundRect(QPainter *p, int x, int y, int w, int h)
02547 {
02548     int x2 = x+w-1;
02549     int y2 = y+h-1;
02550     p->drawLine(x+1, y, x2-1, y);
02551     p->drawLine(x, y+1, x, y2-1);
02552     p->drawLine(x+1, y2, x2-1, y2);
02553     p->drawLine(x2, y+1, x2, y2-1);
02554 }
02555 
02556 void LiquidStyle::drawSliderGroove (QPainter * p, int x, int y, int w,  int h,
02557                                     const QColorGroup &g, QCOORD,
02558                                     Orientation orient)
02559 {
02560     bool isFocus = ((QWidget *)p->device())->hasFocus();
02561     QColor c = isFocus ? g.background().dark(120) : g.background();
02562     if(orient == Qt::Horizontal){
02563         int x2 = x+w-1;
02564         y+=2;
02565         p->setPen(c.dark(130));
02566         p->drawLine(x+1, y, x2-1, y);
02567         p->setPen(c.dark(150));
02568         p->drawLine(x, y+1, x2, y+1);
02569         p->setPen(c.dark(125));
02570         p->drawLine(x, y+2, x2, y+2);
02571         p->setPen(c.dark(130));
02572         p->drawLine(x, y+3, x2, y+3);
02573         p->setPen(c.dark(120));
02574         p->drawLine(x, y+4, x2, y+4);
02575         p->setPen(c.light(110));
02576         p->drawLine(x+1, y+5, x2-1, y+5);
02577     }
02578     else{
02579         int y2 = y+h-1;
02580         x+=2;
02581         p->setPen(c.dark(130));
02582         p->drawLine(x, y+1, x, y2-1);
02583         p->setPen(c.dark(150));
02584         p->drawLine(x+1, y, x+1, y2);
02585         p->setPen(c.dark(125));
02586         p->drawLine(x+2, y, x+2, y2);
02587         p->setPen(c.dark(130));
02588         p->drawLine(x+3, y, x+3, y2);
02589         p->setPen(c.dark(120));
02590         p->drawLine(x+4, y, x+4, y2);
02591         p->setPen(c.light(110));
02592         p->drawLine(x+5, y+1, x+5, y2-1);
02593     }
02594     //QWindowsStyle::drawSliderGroove(p, x, y, w, h, g, c, orient);
02595 
02596 }
02597 
02598 void LiquidStyle::drawSliderGrooveMask (QPainter * p, int x, int y, int w,
02599                                         int h, QCOORD, Orientation orient)
02600 {
02601     p->fillRect(x, y, w, h, Qt::color0);
02602     p->setPen(Qt::color1);
02603     if(orient == Qt::Horizontal){
02604         int x2 = x+w-1;
02605         y+=2;
02606         p->drawLine(x+1, y, x2-1, y);
02607         p->fillRect(x, y+1, w, 4, Qt::color1);
02608         p->drawLine(x+1, y+5, x2-1, y+5);
02609     }
02610     else{
02611         int y2 = y+h-1;
02612         x+=2;
02613         p->drawLine(x, y+1, x, y2-1);
02614         p->fillRect(x+1, y, 4, h, Qt::color1);
02615         p->drawLine(x+5, y+1, x+5, y2-1);
02616     }
02617 }
02618 
02619 
02620 /* vim: set noet sw=8 ts=8: */

Generated on Sat Nov 5 16:17:17 2005 for OPIE by  doxygen 1.4.2