summaryrefslogtreecommitdiff
path: root/noncore/styles/theme/othemestyle.cpp
Unidiff
Diffstat (limited to 'noncore/styles/theme/othemestyle.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/styles/theme/othemestyle.cpp53
1 files changed, 28 insertions, 25 deletions
diff --git a/noncore/styles/theme/othemestyle.cpp b/noncore/styles/theme/othemestyle.cpp
index 98e7253..106d206 100644
--- a/noncore/styles/theme/othemestyle.cpp
+++ b/noncore/styles/theme/othemestyle.cpp
@@ -28,65 +28,65 @@
28#include <qprogressbar.h> 28#include <qprogressbar.h>
29 29
30#include <limits.h> 30#include <limits.h>
31#include <stdio.h> 31#include <stdio.h>
32 32
33typedef void (QStyle::*QDrawMenuBarItemImpl) (QPainter *, int, int, int, int, QMenuItem *, 33typedef void (QStyle::*QDrawMenuBarItemImpl) (QPainter *, int, int, int, int, QMenuItem *,
34 QColorGroup &, bool, bool); 34 QColorGroup &, bool, bool);
35 35
36QDrawMenuBarItemImpl qt_set_draw_menu_bar_impl(QDrawMenuBarItemImpl impl); 36QDrawMenuBarItemImpl qt_set_draw_menu_bar_impl(QDrawMenuBarItemImpl impl);
37 37
38 38
39/* !! HACK !! Beware 39/* !! HACK !! Beware
40 * 40 *
41 * TT forgot to make the QProgressBar widget styleable in Qt 2.x 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 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 43 * paint event - since we have to use protected functions, we need
44 * to derive a "hack" class from QProgressBar and do the painting 44 * to derive a "hack" class from QProgressBar and do the painting
45 * in there. 45 * in there.
46 * 46 *
47 * - sandman 47 * - sandman
48 */ 48 */
49 49
50class HackProgressBar : public QProgressBar { 50class HackProgressBar : public QProgressBar {
51public: 51public:
52 HackProgressBar ( ); 52 HackProgressBar ( );
53 53
54 void paint ( QPaintEvent *event, OThemeStyle *style ) 54 void paint ( QPaintEvent *event, OThemeStyle *style )
55 { 55 {
56 QPainter p( this ); 56 QPainter p( this );
57 57
58 if ( !contentsRect().contains( event->rect() ) ) { 58 if ( !contentsRect().contains( event->rect() ) ) {
59 p.save(); 59 p.save();
60 p.setClipRegion( event->region().intersect(frameRect()) ); 60 p.setClipRegion( event->region().intersect(frameRect()) );
61 drawFrame( &p); 61 drawFrame( &p);
62 p.restore(); 62 p.restore();
63 } 63 }
64 if ( event->rect().intersects( contentsRect() )) { 64 if ( event->rect().intersects( contentsRect() )) {
65 p.setClipRegion( event->region().intersect( contentsRect() ) ); 65 p.setClipRegion( event->region().intersect( contentsRect() ) );
66 66
67 int x, y, w, h; 67 int x, y, w, h;
68 contentsRect ( ). rect ( &x, &y, &w, &h ); 68 contentsRect ( ). rect ( &x, &y, &w, &h );
69 69
70 int prog = progress ( ); 70 int prog = progress ( );
71 int total = totalSteps ( ); 71 int total = totalSteps ( );
72 if ( prog < 0 ) 72 if ( prog < 0 )
73 prog = 0; 73 prog = 0;
74 if ( total <= 0 ) 74 if ( total <= 0 )
75 total = 1; 75 total = 1;
76 int perc = prog * 100 / total; 76 int perc = prog * 100 / total;
77 77
78 style-> drawProgressBar ( &p, x, y, w, h, colorGroup ( ), perc ); 78 style-> drawProgressBar ( &p, x, y, w, h, colorGroup ( ), perc );
79 79
80 if ( progress ( ) >= 0 && totalSteps ( ) > 0 ) { 80 if ( progress ( ) >= 0 && totalSteps ( ) > 0 ) {
81 QString pstr; 81 QString pstr;
82 pstr. sprintf ( "%d%%", 100 * progress()/totalSteps ()); 82 pstr. sprintf ( "%d%%", 100 * progress()/totalSteps ());
83 p. setPen ( colorGroup().text());//g.highlightedText ( )); 83 p. setPen ( colorGroup().text());//g.highlightedText ( ));
84 p. drawText (x,y,w-1,h-1,AlignCenter,pstr); 84 p. drawText (x,y,w-1,h-1,AlignCenter,pstr);
85 } 85 }
86 } 86 }
87 } 87 }
88}; 88};
89 89
90 90
91#define QCOORDARRLEN(x) sizeof(x)/(sizeof(QCOORD)*2) 91#define QCOORDARRLEN(x) sizeof(x)/(sizeof(QCOORD)*2)
92 92
@@ -100,51 +100,51 @@ OThemeStyle::OThemeStyle( const QString &configFile )
100OThemeStyle::~OThemeStyle() 100OThemeStyle::~OThemeStyle()
101{} 101{}
102 102
103void OThemeStyle::polish( QApplication * /*app*/ ) 103void OThemeStyle::polish( QApplication * /*app*/ )
104{ 104{
105 qt_set_draw_menu_bar_impl((QDrawMenuBarItemImpl) &OThemeStyle::drawMenuBarItem); 105 qt_set_draw_menu_bar_impl((QDrawMenuBarItemImpl) &OThemeStyle::drawMenuBarItem);
106} 106}
107 107
108 108
109void OThemeStyle::polish( QPalette &p ) 109void OThemeStyle::polish( QPalette &p )
110{ 110{
111 oldPalette = p; 111 oldPalette = p;
112 112
113 QColor bg = oldPalette. color ( QPalette::Normal, QColorGroup::Background ); 113 QColor bg = oldPalette. color ( QPalette::Normal, QColorGroup::Background );
114 114
115 if ( bgcolor. isValid ( )) 115 if ( bgcolor. isValid ( ))
116 bg = bgcolor; 116 bg = bgcolor;
117 117
118 if ( isColor ( Background )) 118 if ( isColor ( Background ))
119 bg = colorGroup ( oldPalette. active ( ), Background )-> background ( ); 119 bg = colorGroup ( oldPalette. active ( ), Background )-> background ( );
120 120
121 p = QPalette ( bg, bg ); 121 p = QPalette ( bg, bg );
122 122
123 if ( isPixmap( Background ) ) 123 if ( isPixmap( Background ) )
124 p. setBrush ( QColorGroup::Background, QBrush ( bg, *uncached ( Background ))); 124 p. setBrush ( QColorGroup::Background, QBrush ( bg, *uncached ( Background )));
125 125
126 if ( fgcolor. isValid ( )) { 126 if ( fgcolor. isValid ( )) {
127 p. setColor ( QColorGroup::Foreground, fgcolor ); 127 p. setColor ( QColorGroup::Foreground, fgcolor );
128 p. setColor ( QColorGroup::ButtonText, fgcolor ); 128 p. setColor ( QColorGroup::ButtonText, fgcolor );
129 } 129 }
130 if ( selfgcolor. isValid ( )) 130 if ( selfgcolor. isValid ( ))
131 p. setColor ( QColorGroup::HighlightedText, selfgcolor ); 131 p. setColor ( QColorGroup::HighlightedText, selfgcolor );
132 if ( selbgcolor. isValid ( )) 132 if ( selbgcolor. isValid ( ))
133 p. setColor ( QColorGroup::Highlight, selbgcolor ); 133 p. setColor ( QColorGroup::Highlight, selbgcolor );
134 if ( winfgcolor. isValid ( )) 134 if ( winfgcolor. isValid ( ))
135 p. setColor ( QColorGroup::Text, winfgcolor ); 135 p. setColor ( QColorGroup::Text, winfgcolor );
136 if ( winbgcolor. isValid ( )) 136 if ( winbgcolor. isValid ( ))
137 p. setColor ( QColorGroup::Base, winbgcolor ); 137 p. setColor ( QColorGroup::Base, winbgcolor );
138 138
139} 139}
140 140
141 141
142void OThemeStyle::unPolish( QApplication *app ) 142void OThemeStyle::unPolish( QApplication *app )
143{ 143{
144 qt_set_draw_menu_bar_impl ( 0 ); 144 qt_set_draw_menu_bar_impl ( 0 );
145 app->setPalette( oldPalette, true ); 145 app->setPalette( oldPalette, true );
146} 146}
147 147
148void OThemeStyle::polish( QWidget *w ) 148void OThemeStyle::polish( QWidget *w )
149{ 149{
150 if ( !w->isTopLevel() ) { 150 if ( !w->isTopLevel() ) {
@@ -1174,25 +1174,25 @@ void OThemeStyle::drawPushButtonLabel( QPushButton *btn, QPainter *p )
1174 x + w - dx - 2, y + 2, dx, h - 4, 1174 x + w - dx - 2, y + 2, dx, h - 4,
1175 btn->colorGroup(), 1175 btn->colorGroup(),
1176 btn->isEnabled() ); 1176 btn->isEnabled() );
1177 w -= dx; 1177 w -= dx;
1178 } 1178 }
1179 1179
1180 // Next, draw iconset, if any 1180 // Next, draw iconset, if any
1181 if ( btn->iconSet() && !btn->iconSet() ->isNull() ) { 1181 if ( btn->iconSet() && !btn->iconSet() ->isNull() ) {
1182 QIconSet::Mode mode = btn->isEnabled() 1182 QIconSet::Mode mode = btn->isEnabled()
1183 ? QIconSet::Normal : QIconSet::Disabled; 1183 ? QIconSet::Normal : QIconSet::Disabled;
1184 if ( mode == QIconSet::Normal && btn->hasFocus() ) 1184 if ( mode == QIconSet::Normal && btn->hasFocus() )
1185 mode = QIconSet::Active; 1185 mode = QIconSet::Active;
1186 QPixmap pixmap = btn->iconSet() ->pixmap( QIconSet::Small, mode ); 1186 QPixmap pixmap = btn->iconSet() ->pixmap( QIconSet::Automatic, mode );
1187 int pixw = pixmap.width(); 1187 int pixw = pixmap.width();
1188 int pixh = pixmap.height(); 1188 int pixh = pixmap.height();
1189 1189
1190 p->drawPixmap( x + 6, y + h / 2 - pixh / 2, pixmap ); 1190 p->drawPixmap( x + 6, y + h / 2 - pixh / 2, pixmap );
1191 x += pixw + 8; 1191 x += pixw + 8;
1192 w -= pixw + 8; 1192 w -= pixw + 8;
1193 } 1193 }
1194 1194
1195 if ( widget == PushButtonDown ) { 1195 if ( widget == PushButtonDown ) {
1196 drawItem( p, x + buttonXShift(), y + buttonYShift(), 1196 drawItem( p, x + buttonXShift(), y + buttonYShift(),
1197 w, h, AlignCenter | ShowPrefix, *cg, btn->isEnabled(), 1197 w, h, AlignCenter | ShowPrefix, *cg, btn->isEnabled(),
1198 btn->pixmap(), btn->text(), -1, &cg->buttonText() ); 1198 btn->pixmap(), btn->text(), -1, &cg->buttonText() );
@@ -1237,26 +1237,25 @@ int OThemeStyle::popupMenuItemHeight( bool /*checkable*/, QMenuItem *mi,
1237 int offset = QMAX( decoWidth( MenuItemDown ), decoWidth( MenuItem ) ) + 4; 1237 int offset = QMAX( decoWidth( MenuItemDown ), decoWidth( MenuItem ) ) + 4;
1238 1238
1239 if ( mi->isSeparator() ) 1239 if ( mi->isSeparator() )
1240 return ( 2 ); 1240 return ( 2 );
1241 if ( mi->isChecked() ) 1241 if ( mi->isChecked() )
1242 h = isPixmap( CheckMark ) ? uncached( CheckMark ) ->height() + offset : 1242 h = isPixmap( CheckMark ) ? uncached( CheckMark ) ->height() + offset :
1243 offset + 16; 1243 offset + 16;
1244 if ( mi->pixmap() ) { 1244 if ( mi->pixmap() ) {
1245 h2 = mi->pixmap() ->height() + offset; 1245 h2 = mi->pixmap() ->height() + offset;
1246 h = h2 > h ? h2 : h; 1246 h = h2 > h ? h2 : h;
1247 } 1247 }
1248 if ( mi->iconSet() ) { 1248 if ( mi->iconSet() ) {
1249 h2 = mi->iconSet() -> 1249 h2 = mi->iconSet() ->pixmap().height() + offset;
1250 pixmap( QIconSet::Small, QIconSet::Normal ).height() + offset;
1251 h = h2 > h ? h2 : h; 1250 h = h2 > h ? h2 : h;
1252 } 1251 }
1253 h2 = fm.height() + offset; 1252 h2 = fm.height() + offset;
1254 h = h2 > h ? h2 : h; 1253 h = h2 > h ? h2 : h;
1255 return ( h ); 1254 return ( h );
1256} 1255}
1257 1256
1258void OThemeStyle::drawPopupMenuItem( QPainter* p, bool checkable, int maxpmw, 1257void OThemeStyle::drawPopupMenuItem( QPainter* p, bool checkable, int maxpmw,
1259 int tab, QMenuItem* mi, 1258 int tab, QMenuItem* mi,
1260 const QPalette& pal, bool act, 1259 const QPalette& pal, bool act,
1261 bool enabled, int x, int y, int w, int h ) 1260 bool enabled, int x, int y, int w, int h )
1262{ 1261{
@@ -1316,25 +1315,29 @@ void OThemeStyle::drawPopupMenuItem( QPainter* p, bool checkable, int maxpmw,
1316 int mw = checkcol + motifItemFrame; 1315 int mw = checkcol + motifItemFrame;
1317 drawShade( p, x, y, mw, h, g, true, false, 1316 drawShade( p, x, y, mw, h, g, true, false,
1318 highlightWidth( MenuItemDown ), 1317 highlightWidth( MenuItemDown ),
1319 borderWidth( MenuItemDown ), shade() ); 1318 borderWidth( MenuItemDown ), shade() );
1320 } 1319 }
1321 } 1320 }
1322 if ( !mi ) 1321 if ( !mi )
1323 return ; 1322 return ;
1324 if ( mi->iconSet() ) { 1323 if ( mi->iconSet() ) {
1325 QIconSet::Mode mode = dis ? QIconSet::Disabled : QIconSet::Normal; 1324 QIconSet::Mode mode = dis ? QIconSet::Disabled : QIconSet::Normal;
1326 if ( act && !dis ) 1325 if ( act && !dis )
1327 mode = QIconSet::Active; 1326 mode = QIconSet::Active;
1328 QPixmap pixmap = mi->iconSet() ->pixmap( QIconSet::Small, mode ); 1327 QPixmap pixmap;
1328 if ( mode == QIconSet::Disabled )
1329 pixmap = mi->iconSet()->pixmap( QIconSet::Automatic, mode );
1330 else
1331 pixmap = mi->iconSet()->pixmap();
1329 int pixw = pixmap.width(); 1332 int pixw = pixmap.width();
1330 int pixh = pixmap.height(); 1333 int pixh = pixmap.height();
1331 QRect cr( x, y, checkcol, h ); 1334 QRect cr( x, y, checkcol, h );
1332 QRect pmr( 0, 0, pixw, pixh ); 1335 QRect pmr( 0, 0, pixw, pixh );
1333 pmr.moveCenter( cr.center() ); 1336 pmr.moveCenter( cr.center() );
1334 p->setPen( itemg.text() ); 1337 p->setPen( itemg.text() );
1335 p->drawPixmap( pmr.topLeft(), pixmap ); 1338 p->drawPixmap( pmr.topLeft(), pixmap );
1336 1339
1337 } 1340 }
1338 else if ( checkable ) { 1341 else if ( checkable ) {
1339 int mw = checkcol + motifItemFrame; 1342 int mw = checkcol + motifItemFrame;
1340 int mh = h - 2 * motifItemFrame; 1343 int mh = h - 2 * motifItemFrame;
@@ -1425,29 +1428,29 @@ void OThemeStyle::drawFocusRect( QPainter *p, const QRect &r,
1425} 1428}
1426 1429
1427#if 0 1430#if 0
1428void OThemeStyle::drawKMenuBar( QPainter *p, int x, int y, int w, int h, 1431void OThemeStyle::drawKMenuBar( QPainter *p, int x, int y, int w, int h,
1429 const QColorGroup &g, bool, QBrush * ) 1432 const QColorGroup &g, bool, QBrush * )
1430{ 1433{
1431 drawBaseButton( p, x, y, w, h, *colorGroup( g, MenuBar ), false, false, 1434 drawBaseButton( p, x, y, w, h, *colorGroup( g, MenuBar ), false, false,
1432 MenuBar ); 1435 MenuBar );
1433} 1436}
1434#endif 1437#endif
1435 1438
1436void OThemeStyle::drawMenuBarItem( QPainter *p, int x, int y, int w, int h, 1439void OThemeStyle::drawMenuBarItem( QPainter *p, int x, int y, int w, int h,
1437 QMenuItem *mi, const QColorGroup &g, 1440 QMenuItem *mi, const QColorGroup &g,
1438 bool /*enabled*/, bool active ) 1441 bool /*enabled*/, bool active )
1439{ 1442{
1440 if(active){ 1443 if(active){
1441 x -= 2; // Bug in Qt/E 1444 x -= 2; // Bug in Qt/E
1442 y -= 2; 1445 y -= 2;
1443 w += 2; 1446 w += 2;
1444 h += 2; 1447 h += 2;
1445 } 1448 }
1446 1449
1447 const QColorGroup * cg = colorGroup( g, active ? MenuBarItem : MenuBar ); 1450 const QColorGroup * cg = colorGroup( g, active ? MenuBarItem : MenuBar );
1448 QColor btext = cg->buttonText(); 1451 QColor btext = cg->buttonText();
1449 if ( active ) 1452 if ( active )
1450 drawBaseButton( p, x, y, w, h, *cg, false, false, MenuBarItem ); 1453 drawBaseButton( p, x, y, w, h, *cg, false, false, MenuBarItem );
1451 //qDrawShadePanel(p, x, y, w, h, *cg, false, 1); 1454 //qDrawShadePanel(p, x, y, w, h, *cg, false, 1);
1452 1455
1453 drawItem( p, x, y, w, h, AlignCenter | ShowPrefix | DontClip | SingleLine, 1456 drawItem( p, x, y, w, h, AlignCenter | ShowPrefix | DontClip | SingleLine,
@@ -1455,29 +1458,29 @@ void OThemeStyle::drawMenuBarItem( QPainter *p, int x, int y, int w, int h,
1455 -1, &btext ); 1458 -1, &btext );
1456} 1459}
1457 1460
1458 1461
1459 1462
1460void OThemeStyle::drawProgressBar ( QPainter *p, int x, int y, int w, int h, const QColorGroup &g, int percent ) 1463void OThemeStyle::drawProgressBar ( QPainter *p, int x, int y, int w, int h, const QColorGroup &g, int percent )
1461{ 1464{
1462 const QColorGroup * cg = colorGroup( g, ProgressBg ); 1465 const QColorGroup * cg = colorGroup( g, ProgressBg );
1463 QBrush bg; 1466 QBrush bg;
1464 bg.setColor( cg->color( QColorGroup::Background ) ); 1467 bg.setColor( cg->color( QColorGroup::Background ) );
1465 if ( isPixmap( ProgressBg ) ) 1468 if ( isPixmap( ProgressBg ) )
1466 bg.setPixmap( *uncached( ProgressBg ) ); 1469 bg.setPixmap( *uncached( ProgressBg ) );
1467 1470
1468 int pw = w * percent / 100; 1471 int pw = w * percent / 100;
1469 1472
1470 p-> fillRect ( x + pw, y, w - pw, h, bg ); // ### TODO 1473 p-> fillRect ( x + pw, y, w - pw, h, bg ); // ### TODO
1471 1474
1472 drawBaseButton( p, x, y, pw, h, *cg, false, false, ProgressBar ); 1475 drawBaseButton( p, x, y, pw, h, *cg, false, false, ProgressBar );
1473} 1476}
1474 1477
1475#if 0 1478#if 0
1476 1479
1477void OThemeStyle::drawKProgressBlock( QPainter *p, int x, int y, int w, int h, 1480void OThemeStyle::drawKProgressBlock( QPainter *p, int x, int y, int w, int h,
1478 const QColorGroup &g, QBrush * ) 1481 const QColorGroup &g, QBrush * )
1479{ 1482{
1480 drawBaseButton( p, x, y, w, h, *colorGroup( g, ProgressBar ), false, false, 1483 drawBaseButton( p, x, y, w, h, *colorGroup( g, ProgressBar ), false, false,
1481 ProgressBar ); 1484 ProgressBar );
1482} 1485}
1483 1486