summaryrefslogtreecommitdiff
authorsandman <sandman>2002-10-06 20:54:49 (UTC)
committer sandman <sandman>2002-10-06 20:54:49 (UTC)
commite334186122e512a57bd27026014f01f501db93fc (patch) (side-by-side diff)
tree218c24647dbf6ce15fda1d1ef987ab70e6964570
parente28318681d10236fe06cc478d329b4d000c2a48a (diff)
downloadopie-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.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/styles/liquid/liquid.cpp88
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
@@ -30,7 +30,7 @@
#include <qheader.h>
#include <unistd.h>
#include <qmenubar.h>
-
+#include <qprogressbar.h>
#include <stdio.h>
@@ -853,10 +853,7 @@ void LiquidStyle::polish(QWidget *w)
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);
@@ -1035,6 +1032,68 @@ void LiquidStyle::unPolish(QApplication *app)
// 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
@@ -1240,7 +1299,24 @@ bool LiquidStyle::eventFilter(QObject *obj, QEvent *ev)
}
}
}
- 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,