author | sandman <sandman> | 2002-10-06 20:54:49 (UTC) |
---|---|---|
committer | sandman <sandman> | 2002-10-06 20:54:49 (UTC) |
commit | e334186122e512a57bd27026014f01f501db93fc (patch) (side-by-side diff) | |
tree | 218c24647dbf6ce15fda1d1ef987ab70e6964570 | |
parent | e28318681d10236fe06cc478d329b4d000c2a48a (diff) | |
download | opie-e334186122e512a57bd27026014f01f501db93fc.zip opie-e334186122e512a57bd27026014f01f501db93fc.tar.gz opie-e334186122e512a57bd27026014f01f501db93fc.tar.bz2 |
QProgressBar widget are now also painted in liquid style -- this is only
possible by intercepting the paint events, since TT forgot to make this
widget styleable.
-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 @@ -21,25 +21,25 @@ #include <qobjectlist.h> #include <qimage.h> #include <qtimer.h> #include <qpixmapcache.h> #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); QDrawMenuBarItemImpl qt_set_draw_menu_bar_impl(QDrawMenuBarItemImpl impl); void TransMenuHandler::stripePixmap(QPixmap &pix, const QColor &color) @@ -844,28 +844,25 @@ void LiquidStyle::polish(QWidget *w) return; } if(w->inherits("QPopupMenu")) w->setBackgroundMode(QWidget::NoBackground); 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); } if(w->inherits("QPushButton")){ applyCustomAttributes((QPushButton *)w); w->installEventFilter(this); @@ -1026,24 +1023,86 @@ void LiquidStyle::polish(QApplication *app) void LiquidStyle::unPolish(QApplication *app) { QWindowsStyle::unPolish(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 * because the style methods aren't called in paintEvents if everything * is cached. We use our own Paint event handler instead. Taskbuttons and * pager buttons draw into a pixmap buffer, so we handle those with palette * modifications. For QHeader, different header items are actually one widget @@ -1231,25 +1290,42 @@ bool LiquidStyle::eventFilter(QObject *obj, QEvent *ev) // reset old header if(oldHeader != -1){ hw->repaint(hw->sectionPos(oldHeader), 0, hw->sectionSize(oldHeader), hw->height()); } 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); } void LiquidStyle::drawToolButton(QPainter *p, int x, int y, int w, int h, const QColorGroup &g, bool sunken, |