-rw-r--r-- | noncore/styles/theme/othemestyle.cpp | 126 | ||||
-rw-r--r-- | noncore/styles/theme/othemestyle.h | 16 |
2 files changed, 124 insertions, 18 deletions
diff --git a/noncore/styles/theme/othemestyle.cpp b/noncore/styles/theme/othemestyle.cpp index 8c7a71b..a820efb 100644 --- a/noncore/styles/theme/othemestyle.cpp +++ b/noncore/styles/theme/othemestyle.cpp | |||
@@ -25,10 +25,69 @@ | |||
25 | #include <qpopupmenu.h> | 25 | #include <qpopupmenu.h> |
26 | #include <qtabbar.h> | 26 | #include <qtabbar.h> |
27 | #include <qglobal.h> | 27 | #include <qglobal.h> |
28 | #include <qprogressbar.h> | ||
28 | 29 | ||
29 | #include <limits.h> | 30 | #include <limits.h> |
30 | #include <stdio.h> | 31 | #include <stdio.h> |
31 | 32 | ||
33 | typedef void (QStyle::*QDrawMenuBarItemImpl) (QPainter *, int, int, int, int, QMenuItem *, | ||
34 | QColorGroup &, bool, bool); | ||
35 | |||
36 | QDrawMenuBarItemImpl qt_set_draw_menu_bar_impl(QDrawMenuBarItemImpl impl); | ||
37 | |||
38 | |||
39 | /* !! HACK !! Beware | ||
40 | * | ||
41 | * TT forgot to make the QProgressBar widget styleable in Qt 2.x | ||
42 | * So the only way to customize the drawing, is to intercept the | ||
43 | * paint event - since we have to use protected functions, we need | ||
44 | * to derive a "hack" class from QProgressBar and do the painting | ||
45 | * in there. | ||
46 | * | ||
47 | * - sandman | ||
48 | */ | ||
49 | |||
50 | class HackProgressBar : public QProgressBar { | ||
51 | public: | ||
52 | HackProgressBar ( ); | ||
53 | |||
54 | void paint ( QPaintEvent *event, OThemeStyle *style ) | ||
55 | { | ||
56 | QPainter p( this ); | ||
57 | |||
58 | if ( !contentsRect().contains( event->rect() ) ) { | ||
59 | p.save(); | ||
60 | p.setClipRegion( event->region().intersect(frameRect()) ); | ||
61 | drawFrame( &p); | ||
62 | p.restore(); | ||
63 | } | ||
64 | if ( event->rect().intersects( contentsRect() )) { | ||
65 | p.setClipRegion( event->region().intersect( contentsRect() ) ); | ||
66 | |||
67 | int x, y, w, h; | ||
68 | contentsRect ( ). rect ( &x, &y, &w, &h ); | ||
69 | |||
70 | int prog = progress ( ); | ||
71 | int total = totalSteps ( ); | ||
72 | if ( prog < 0 ) | ||
73 | prog = 0; | ||
74 | if ( total <= 0 ) | ||
75 | total = 1; | ||
76 | int perc = prog * 100 / total; | ||
77 | |||
78 | style-> drawProgressBar ( &p, x, y, w, h, colorGroup ( ), perc ); | ||
79 | |||
80 | if ( progress ( ) >= 0 && totalSteps ( ) > 0 ) { | ||
81 | QString pstr; | ||
82 | pstr. sprintf ( "%d%%", 100 * progress()/totalSteps ()); | ||
83 | p. setPen ( colorGroup().text());//g.highlightedText ( )); | ||
84 | p. drawText (x,y,w-1,h-1,AlignCenter,pstr); | ||
85 | } | ||
86 | } | ||
87 | } | ||
88 | }; | ||
89 | |||
90 | |||
32 | #define QCOORDARRLEN(x) sizeof(x)/(sizeof(QCOORD)*2) | 91 | #define QCOORDARRLEN(x) sizeof(x)/(sizeof(QCOORD)*2) |
33 | 92 | ||
34 | OThemeStyle::OThemeStyle( const QString &configFile ) | 93 | OThemeStyle::OThemeStyle( const QString &configFile ) |
@@ -42,7 +101,10 @@ OThemeStyle::~OThemeStyle() | |||
42 | {} | 101 | {} |
43 | 102 | ||
44 | void OThemeStyle::polish( QApplication * /*app*/ ) | 103 | void OThemeStyle::polish( QApplication * /*app*/ ) |
45 | {} | 104 | { |
105 | qt_set_draw_menu_bar_impl((QDrawMenuBarItemImpl) &OThemeStyle::drawMenuBarItem); | ||
106 | } | ||
107 | |||
46 | 108 | ||
47 | void OThemeStyle::polish( QPalette &p ) | 109 | void OThemeStyle::polish( QPalette &p ) |
48 | { | 110 | { |
@@ -79,6 +141,7 @@ void OThemeStyle::polish( QPalette &p ) | |||
79 | 141 | ||
80 | void OThemeStyle::unPolish( QApplication *app ) | 142 | void OThemeStyle::unPolish( QApplication *app ) |
81 | { | 143 | { |
144 | qt_set_draw_menu_bar_impl ( 0 ); | ||
82 | app->setPalette( oldPalette, true ); | 145 | app->setPalette( oldPalette, true ); |
83 | } | 146 | } |
84 | 147 | ||
@@ -112,7 +175,7 @@ void OThemeStyle::polish( QWidget *w ) | |||
112 | w->setPalette( newPal ); | 175 | w->setPalette( newPal ); |
113 | } | 176 | } |
114 | } | 177 | } |
115 | if ( w->inherits( "QCheckBox" ) ) { | 178 | else if ( w->inherits( "QCheckBox" ) ) { |
116 | if ( isColor( IndicatorOff ) || isColor( IndicatorOn ) ) { | 179 | if ( isColor( IndicatorOff ) || isColor( IndicatorOn ) ) { |
117 | QPalette newPal( w->palette() ); | 180 | QPalette newPal( w->palette() ); |
118 | w->setPalettePropagation( QWidget::SamePalette ); | 181 | w->setPalettePropagation( QWidget::SamePalette ); |
@@ -125,7 +188,7 @@ void OThemeStyle::polish( QWidget *w ) | |||
125 | w->setPalette( newPal ); | 188 | w->setPalette( newPal ); |
126 | } | 189 | } |
127 | } | 190 | } |
128 | if ( w->inherits( "QRadioButton" ) ) { | 191 | else if ( w->inherits( "QRadioButton" ) ) { |
129 | if ( isColor( ExIndicatorOff ) || isColor( ExIndicatorOn ) ) { | 192 | if ( isColor( ExIndicatorOff ) || isColor( ExIndicatorOn ) ) { |
130 | QPalette newPal( w->palette() ); | 193 | QPalette newPal( w->palette() ); |
131 | w->setPalettePropagation( QWidget::SamePalette ); | 194 | w->setPalettePropagation( QWidget::SamePalette ); |
@@ -139,6 +202,9 @@ void OThemeStyle::polish( QWidget *w ) | |||
139 | w->setPalette( newPal ); | 202 | w->setPalette( newPal ); |
140 | } | 203 | } |
141 | } | 204 | } |
205 | else if ( w-> inherits ( "QProgressBar" ) ) { | ||
206 | w-> installEventFilter ( this ); | ||
207 | } | ||
142 | } | 208 | } |
143 | 209 | ||
144 | void OThemeStyle::unPolish( QWidget* w ) | 210 | void OThemeStyle::unPolish( QWidget* w ) |
@@ -159,10 +225,24 @@ void OThemeStyle::unPolish( QWidget* w ) | |||
159 | } | 225 | } |
160 | if ( w->inherits( "QPopupMenu" ) ) | 226 | if ( w->inherits( "QPopupMenu" ) ) |
161 | w->unsetPalette(); | 227 | w->unsetPalette(); |
162 | if ( w->inherits( "QCheckBox" ) ) | 228 | else if ( w->inherits( "QCheckBox" ) ) |
163 | w->unsetPalette(); | 229 | w->unsetPalette(); |
164 | if ( w->inherits( "QRadioButton" ) ) | 230 | else if ( w->inherits( "QRadioButton" ) ) |
165 | w->unsetPalette(); | 231 | w->unsetPalette(); |
232 | else if ( w-> inherits ( "QProgressBar" ) ) | ||
233 | w-> removeEventFilter ( this ); | ||
234 | } | ||
235 | |||
236 | bool OThemeStyle::eventFilter ( QObject *obj, QEvent *ev ) | ||
237 | { | ||
238 | // only QProgressBar so far | ||
239 | |||
240 | if ( ev-> type ( ) == QEvent::Paint ) { | ||
241 | HackProgressBar *pb = (HackProgressBar *) obj; | ||
242 | pb-> paint ((QPaintEvent *) ev, this ); | ||
243 | return true; | ||
244 | } | ||
245 | return false; | ||
166 | } | 246 | } |
167 | 247 | ||
168 | void OThemeStyle::drawBaseButton( QPainter *p, int x, int y, int w, int h, | 248 | void OThemeStyle::drawBaseButton( QPainter *p, int x, int y, int w, int h, |
@@ -1347,11 +1427,19 @@ void OThemeStyle::drawKMenuBar( QPainter *p, int x, int y, int w, int h, | |||
1347 | drawBaseButton( p, x, y, w, h, *colorGroup( g, MenuBar ), false, false, | 1427 | drawBaseButton( p, x, y, w, h, *colorGroup( g, MenuBar ), false, false, |
1348 | MenuBar ); | 1428 | MenuBar ); |
1349 | } | 1429 | } |
1430 | #endif | ||
1350 | 1431 | ||
1351 | void OThemeStyle::drawKMenuItem( QPainter *p, int x, int y, int w, int h, | 1432 | void OThemeStyle::drawMenuBarItem( QPainter *p, int x, int y, int w, int h, |
1352 | const QColorGroup &g, bool active, | 1433 | QMenuItem *mi, const QColorGroup &g, |
1353 | QMenuItem *mi, QBrush * ) | 1434 | bool /*enabled*/, bool active ) |
1354 | { | 1435 | { |
1436 | if(active){ | ||
1437 | x -= 2; // Bug in Qt/E | ||
1438 | y -= 2; | ||
1439 | w += 2; | ||
1440 | h += 2; | ||
1441 | } | ||
1442 | |||
1355 | const QColorGroup * cg = colorGroup( g, active ? MenuBarItem : MenuBar ); | 1443 | const QColorGroup * cg = colorGroup( g, active ? MenuBarItem : MenuBar ); |
1356 | QColor btext = cg->buttonText(); | 1444 | QColor btext = cg->buttonText(); |
1357 | if ( active ) | 1445 | if ( active ) |
@@ -1359,11 +1447,29 @@ void OThemeStyle::drawKMenuItem( QPainter *p, int x, int y, int w, int h, | |||
1359 | //qDrawShadePanel(p, x, y, w, h, *cg, false, 1); | 1447 | //qDrawShadePanel(p, x, y, w, h, *cg, false, 1); |
1360 | 1448 | ||
1361 | drawItem( p, x, y, w, h, AlignCenter | ShowPrefix | DontClip | SingleLine, | 1449 | drawItem( p, x, y, w, h, AlignCenter | ShowPrefix | DontClip | SingleLine, |
1362 | *cg, mi->isEnabled(), mi->pixmap(), mi->text(), | 1450 | *cg, mi-> isEnabled ( ), mi->pixmap(), mi->text(), |
1363 | -1, &btext ); | 1451 | -1, &btext ); |
1364 | ; | ||
1365 | } | 1452 | } |
1366 | 1453 | ||
1454 | |||
1455 | |||
1456 | void OThemeStyle::drawProgressBar ( QPainter *p, int x, int y, int w, int h, const QColorGroup &g, int percent ) | ||
1457 | { | ||
1458 | const QColorGroup * cg = colorGroup( g, ProgressBg ); | ||
1459 | QBrush bg; | ||
1460 | bg.setColor( cg->color( QColorGroup::Background ) ); | ||
1461 | if ( isPixmap( ProgressBg ) ) | ||
1462 | bg.setPixmap( *uncached( ProgressBg ) ); | ||
1463 | |||
1464 | int pw = w * percent / 100; | ||
1465 | |||
1466 | p-> fillRect ( x + pw, y, w - pw, h, bg ); // ### TODO | ||
1467 | |||
1468 | drawBaseButton( p, x, y, pw, h, *cg, false, false, ProgressBar ); | ||
1469 | } | ||
1470 | |||
1471 | #if 0 | ||
1472 | |||
1367 | void OThemeStyle::drawKProgressBlock( QPainter *p, int x, int y, int w, int h, | 1473 | void OThemeStyle::drawKProgressBlock( QPainter *p, int x, int y, int w, int h, |
1368 | const QColorGroup &g, QBrush * ) | 1474 | const QColorGroup &g, QBrush * ) |
1369 | { | 1475 | { |
diff --git a/noncore/styles/theme/othemestyle.h b/noncore/styles/theme/othemestyle.h index 52445c4..406b35b 100644 --- a/noncore/styles/theme/othemestyle.h +++ b/noncore/styles/theme/othemestyle.h | |||
@@ -26,6 +26,8 @@ | |||
26 | #include <qscrollbar.h> | 26 | #include <qscrollbar.h> |
27 | #include <qstring.h> | 27 | #include <qstring.h> |
28 | 28 | ||
29 | class QProgressBar; | ||
30 | |||
29 | 31 | ||
30 | /** | 32 | /** |
31 | * KDE themed styles. | 33 | * KDE themed styles. |
@@ -63,6 +65,8 @@ public: | |||
63 | // to make it possible for derived classes to overload this function | 65 | // to make it possible for derived classes to overload this function |
64 | virtual void polish( QPalette& pal ); | 66 | virtual void polish( QPalette& pal ); |
65 | 67 | ||
68 | virtual bool eventFilter ( QObject *obj, QEvent *ev ); | ||
69 | |||
66 | /** | 70 | /** |
67 | * This is a convenience method for drawing widgets with | 71 | * This is a convenience method for drawing widgets with |
68 | * borders, highlights, pixmaps, colors, etc... | 72 | * borders, highlights, pixmaps, colors, etc... |
@@ -312,12 +316,9 @@ public: | |||
312 | /** | 316 | /** |
313 | * Draw a menubar item. | 317 | * Draw a menubar item. |
314 | */ | 318 | */ |
315 | #if 0 | 319 | virtual void drawMenuBarItem( QPainter *p, int x, int y, int w, int h, |
316 | 320 | QMenuItem *item, const QColorGroup &g, | |
317 | virtual void drawKMenuItem( QPainter *p, int x, int y, int w, int h, | 321 | bool enabled, bool active ); |
318 | const QColorGroup &g, bool active, | ||
319 | QMenuItem *item, QBrush *fill = NULL ); | ||
320 | #endif | ||
321 | /** | 322 | /** |
322 | * Return the width of the splitter as specified in the config file. | 323 | * Return the width of the splitter as specified in the config file. |
323 | */ | 324 | */ |
@@ -352,8 +353,7 @@ public: | |||
352 | /** | 353 | /** |
353 | * Draw a @ref KProgess bar. | 354 | * Draw a @ref KProgess bar. |
354 | */ | 355 | */ |
355 | // virtual void drawKProgressBlock(QPainter *p, int x, int y, int w, int h, | 356 | virtual void drawProgressBar (QPainter *, int , int , int , int , const QColorGroup &, int ); |
356 | // const QColorGroup &g, QBrush *fill); | ||
357 | /** | 357 | /** |
358 | * Return the background for @ref KProgress. | 358 | * Return the background for @ref KProgress. |
359 | */ | 359 | */ |