Diffstat (limited to 'noncore/styles/liquid/liquid.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/styles/liquid/liquid.cpp | 88 |
1 files changed, 82 insertions, 6 deletions
diff --git a/noncore/styles/liquid/liquid.cpp b/noncore/styles/liquid/liquid.cpp index 259f6af..4013981 100644 --- a/noncore/styles/liquid/liquid.cpp +++ b/noncore/styles/liquid/liquid.cpp @@ -25,17 +25,17 @@ #include <qradiobutton.h> #include <qcombobox.h> #include <qdrawutil.h> #include <qwidgetlist.h> #include <qtoolbutton.h> #include <qheader.h> #include <unistd.h> #include <qmenubar.h> - +#include <qprogressbar.h> #include <stdio.h> #include "htmlmasks.h" #include "embeddata.h" typedef void (QStyle::*QDrawMenuBarItemImpl) (QPainter *, int, int, int, int, QMenuItem *, QColorGroup &, bool, bool); @@ -848,20 +848,17 @@ void LiquidStyle::polish(QWidget *w) else if(w-> testWFlags(Qt::WType_Popup) && !w->inherits("QListBox")) { w->installEventFilter(menuHandler); } if(w->isTopLevel()){ return; } - - - - if(w->inherits("QComboBox") || + if(w->inherits("QComboBox") || w->inherits("QProgressBar") || w->inherits("QLineEdit") || w->inherits("QRadioButton") || w->inherits("QCheckBox") || w->inherits("QScrollBar")) { w->installEventFilter(this); } if(w->inherits("QLineEdit")){ QPalette pal = w->palette(); pal.setBrush(QColorGroup::Base, baseBrush); w->setPalette(pal); @@ -1030,16 +1027,78 @@ void LiquidStyle::unPolish(QApplication *app) app->setEffectEnabled(UI_AnimateMenu, menuAni); app->setEffectEnabled(UI_FadeMenu, menuFade); qt_set_draw_menu_bar_impl ( 0 ); // QApplication::qwsSetDecoration ( new QPEDecoration ( )); } + +/* !! HACK !! Beware + * + * TT forgot to make the QProgressBar widget styleable in Qt 2.x + * So the only way to customize the drawing, is to intercept the + * paint event - since we have to use protected functions, we need + * to derive a "hack" class from QProgressBar and do the painting + * in there. + * + * - sandman + */ + +class HackProgressBar : public QProgressBar { +public: + HackProgressBar ( ); + + void paint ( QPaintEvent *event, const QColorGroup &g, QPixmap *pix ) + { + QPainter p( this ); + + if ( !contentsRect().contains( event->rect() ) ) { + p.save(); + p.setClipRegion( event->region().intersect(frameRect()) ); + drawFrame( &p); + p.restore(); + } + if ( event->rect().intersects( contentsRect() )) { + p.setClipRegion( event->region().intersect( contentsRect() ) ); + + int x, y, w, h; + contentsRect ( ). rect ( &x, &y, &w, &h ); + + int prog = progress ( ); + int total = totalSteps ( ); + if ( prog < 0 ) + prog = 0; + if ( total <= 0 ) + total = 1; + int bw = w * prog / total; + if ( bw > w ) + bw = w; + + p.setPen(g.button().dark(130)); + p.drawRect(x, y, bw, h); + p.setPen(g.button().light(120)); + p.drawRect(x+1, y+1, bw-2, h-2); + + if(bw >= 4 && h >= 4 && pix) + p.drawTiledPixmap(x+2, y+2, bw-4, h-4, *pix); + + if ( progress ( )>= 0 && totalSteps ( ) > 0 ) { + QString pstr; + pstr. sprintf ( "%d%%", 100 * progress()/totalSteps ()); + p. setPen ( g.text());//g.highlightedText ( )); + p. drawText (x,y,w-1,h-1,AlignCenter,pstr); + } + } + } +}; + + + /* * This is a fun method ;-) Here's an overview. KToolBar grabs resize to * force everything to erase and repaint on resize. This is going away, I'm * trying to get shaped widgets to work right without masking. QPushButton, * QComboBox, and Panel applet handles capture mouse enter and leaves in order * to set the highlightwidget and repaint for mouse hovers. CheckBoxes and * RadioButtons need to do this differently. Qt buffers these in pixmaps and * caches them in QPixmapCache, which is bad for doing things like hover @@ -1235,17 +1294,34 @@ bool LiquidStyle::eventFilter(QObject *obj, QEvent *ev) } if(headerHoverID != -1){ hw->repaint(hw->sectionPos(headerHoverID), 0, hw->sectionSize(headerHoverID), hw->height()); } } } } - return(false); + else if (obj-> inherits( "QProgressBar" )) { + if ( ev->type() == QEvent::Paint ) { + HackProgressBar *p = (HackProgressBar *) obj; + const QColorGroup &g = p-> colorGroup ( ); + + QPixmap *pix = bevelFillDict.find(g.button().dark(120).rgb()); + if(!pix){ + int h, s, v; + g.button().dark(120).hsv(&h, &s, &v); + pix = new QPixmap(*bevelFillPix); + adjustHSV(*pix, h, s, v); + bevelFillDict.insert(g.button().dark(120).rgb(), pix); + } + p-> paint ((QPaintEvent *) ev, g, pix ); + return true; + } + } + return false ; } void LiquidStyle::drawButton(QPainter *p, int x, int y, int w, int h, const QColorGroup &g, bool sunken, const QBrush *) { drawRoundButton(p, sunken ? g.background() : g.button(), g.background(), x, y, w, h); |