summaryrefslogtreecommitdiff
authorsandman <sandman>2002-10-06 20:54:49 (UTC)
committer sandman <sandman>2002-10-06 20:54:49 (UTC)
commite334186122e512a57bd27026014f01f501db93fc (patch) (unidiff)
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
@@ -25,17 +25,17 @@
25#include <qradiobutton.h> 25#include <qradiobutton.h>
26#include <qcombobox.h> 26#include <qcombobox.h>
27#include <qdrawutil.h> 27#include <qdrawutil.h>
28#include <qwidgetlist.h> 28#include <qwidgetlist.h>
29#include <qtoolbutton.h> 29#include <qtoolbutton.h>
30#include <qheader.h> 30#include <qheader.h>
31#include <unistd.h> 31#include <unistd.h>
32#include <qmenubar.h> 32#include <qmenubar.h>
33 33#include <qprogressbar.h>
34 34
35#include <stdio.h> 35#include <stdio.h>
36 36
37#include "htmlmasks.h" 37#include "htmlmasks.h"
38#include "embeddata.h" 38#include "embeddata.h"
39 39
40typedef void (QStyle::*QDrawMenuBarItemImpl) (QPainter *, int, int, int, int, QMenuItem *, 40typedef void (QStyle::*QDrawMenuBarItemImpl) (QPainter *, int, int, int, int, QMenuItem *,
41 QColorGroup &, bool, bool); 41 QColorGroup &, bool, bool);
@@ -848,20 +848,17 @@ void LiquidStyle::polish(QWidget *w)
848 else if(w-> testWFlags(Qt::WType_Popup) && !w->inherits("QListBox")) { 848 else if(w-> testWFlags(Qt::WType_Popup) && !w->inherits("QListBox")) {
849 w->installEventFilter(menuHandler); 849 w->installEventFilter(menuHandler);
850 } 850 }
851 851
852 if(w->isTopLevel()){ 852 if(w->isTopLevel()){
853 return; 853 return;
854 } 854 }
855 855
856 856 if(w->inherits("QComboBox") || w->inherits("QProgressBar") ||
857
858
859 if(w->inherits("QComboBox") ||
860 w->inherits("QLineEdit") || w->inherits("QRadioButton") || 857 w->inherits("QLineEdit") || w->inherits("QRadioButton") ||
861 w->inherits("QCheckBox") || w->inherits("QScrollBar")) { 858 w->inherits("QCheckBox") || w->inherits("QScrollBar")) {
862 w->installEventFilter(this); 859 w->installEventFilter(this);
863 } 860 }
864 if(w->inherits("QLineEdit")){ 861 if(w->inherits("QLineEdit")){
865 QPalette pal = w->palette(); 862 QPalette pal = w->palette();
866 pal.setBrush(QColorGroup::Base, baseBrush); 863 pal.setBrush(QColorGroup::Base, baseBrush);
867 w->setPalette(pal); 864 w->setPalette(pal);
@@ -1030,16 +1027,78 @@ void LiquidStyle::unPolish(QApplication *app)
1030 app->setEffectEnabled(UI_AnimateMenu, menuAni); 1027 app->setEffectEnabled(UI_AnimateMenu, menuAni);
1031 app->setEffectEnabled(UI_FadeMenu, menuFade); 1028 app->setEffectEnabled(UI_FadeMenu, menuFade);
1032 1029
1033 qt_set_draw_menu_bar_impl ( 0 ); 1030 qt_set_draw_menu_bar_impl ( 0 );
1034 1031
1035// QApplication::qwsSetDecoration ( new QPEDecoration ( )); 1032// QApplication::qwsSetDecoration ( new QPEDecoration ( ));
1036} 1033}
1037 1034
1035
1036/* !! HACK !! Beware
1037 *
1038 * TT forgot to make the QProgressBar widget styleable in Qt 2.x
1039 * So the only way to customize the drawing, is to intercept the
1040 * paint event - since we have to use protected functions, we need
1041 * to derive a "hack" class from QProgressBar and do the painting
1042 * in there.
1043 *
1044 * - sandman
1045 */
1046
1047class HackProgressBar : public QProgressBar {
1048public:
1049 HackProgressBar ( );
1050
1051 void paint ( QPaintEvent *event, const QColorGroup &g, QPixmap *pix )
1052 {
1053 QPainter p( this );
1054
1055 if ( !contentsRect().contains( event->rect() ) ) {
1056 p.save();
1057 p.setClipRegion( event->region().intersect(frameRect()) );
1058 drawFrame( &p);
1059 p.restore();
1060 }
1061 if ( event->rect().intersects( contentsRect() )) {
1062 p.setClipRegion( event->region().intersect( contentsRect() ) );
1063
1064 int x, y, w, h;
1065 contentsRect ( ). rect ( &x, &y, &w, &h );
1066
1067 int prog = progress ( );
1068 int total = totalSteps ( );
1069 if ( prog < 0 )
1070 prog = 0;
1071 if ( total <= 0 )
1072 total = 1;
1073 int bw = w * prog / total;
1074 if ( bw > w )
1075 bw = w;
1076
1077 p.setPen(g.button().dark(130));
1078 p.drawRect(x, y, bw, h);
1079 p.setPen(g.button().light(120));
1080 p.drawRect(x+1, y+1, bw-2, h-2);
1081
1082 if(bw >= 4 && h >= 4 && pix)
1083 p.drawTiledPixmap(x+2, y+2, bw-4, h-4, *pix);
1084
1085 if ( progress ( )>= 0 && totalSteps ( ) > 0 ) {
1086 QString pstr;
1087 pstr. sprintf ( "%d%%", 100 * progress()/totalSteps ());
1088 p. setPen ( g.text());//g.highlightedText ( ));
1089 p. drawText (x,y,w-1,h-1,AlignCenter,pstr);
1090 }
1091 }
1092 }
1093};
1094
1095
1096
1038/* 1097/*
1039 * This is a fun method ;-) Here's an overview. KToolBar grabs resize to 1098 * This is a fun method ;-) Here's an overview. KToolBar grabs resize to
1040 * force everything to erase and repaint on resize. This is going away, I'm 1099 * force everything to erase and repaint on resize. This is going away, I'm
1041 * trying to get shaped widgets to work right without masking. QPushButton, 1100 * trying to get shaped widgets to work right without masking. QPushButton,
1042 * QComboBox, and Panel applet handles capture mouse enter and leaves in order 1101 * QComboBox, and Panel applet handles capture mouse enter and leaves in order
1043 * to set the highlightwidget and repaint for mouse hovers. CheckBoxes and 1102 * to set the highlightwidget and repaint for mouse hovers. CheckBoxes and
1044 * RadioButtons need to do this differently. Qt buffers these in pixmaps and 1103 * RadioButtons need to do this differently. Qt buffers these in pixmaps and
1045 * caches them in QPixmapCache, which is bad for doing things like hover 1104 * caches them in QPixmapCache, which is bad for doing things like hover
@@ -1235,17 +1294,34 @@ bool LiquidStyle::eventFilter(QObject *obj, QEvent *ev)
1235 } 1294 }
1236 if(headerHoverID != -1){ 1295 if(headerHoverID != -1){
1237 hw->repaint(hw->sectionPos(headerHoverID), 0, 1296 hw->repaint(hw->sectionPos(headerHoverID), 0,
1238 hw->sectionSize(headerHoverID), hw->height()); 1297 hw->sectionSize(headerHoverID), hw->height());
1239 } 1298 }
1240 } 1299 }
1241 } 1300 }
1242 } 1301 }
1243 return(false); 1302 else if (obj-> inherits( "QProgressBar" )) {
1303 if ( ev->type() == QEvent::Paint ) {
1304 HackProgressBar *p = (HackProgressBar *) obj;
1305 const QColorGroup &g = p-> colorGroup ( );
1306
1307 QPixmap *pix = bevelFillDict.find(g.button().dark(120).rgb());
1308 if(!pix){
1309 int h, s, v;
1310 g.button().dark(120).hsv(&h, &s, &v);
1311 pix = new QPixmap(*bevelFillPix);
1312 adjustHSV(*pix, h, s, v);
1313 bevelFillDict.insert(g.button().dark(120).rgb(), pix);
1314 }
1315 p-> paint ((QPaintEvent *) ev, g, pix );
1316 return true;
1317 }
1318 }
1319 return false ;
1244} 1320}
1245 1321
1246void LiquidStyle::drawButton(QPainter *p, int x, int y, int w, int h, 1322void LiquidStyle::drawButton(QPainter *p, int x, int y, int w, int h,
1247 const QColorGroup &g, bool sunken, 1323 const QColorGroup &g, bool sunken,
1248 const QBrush *) 1324 const QBrush *)
1249{ 1325{
1250 drawRoundButton(p, sunken ? g.background() : g.button(), g.background(), 1326 drawRoundButton(p, sunken ? g.background() : g.button(), g.background(),
1251 x, y, w, h); 1327 x, y, w, h);