00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "othemestyle.h"
00020 #include "othemebase.h"
00021 #include <qpe/qpeapplication.h>
00022 #include <qbitmap.h>
00023 #define INCLUDE_MENUITEM_DEF
00024 #include <qmenudata.h>
00025 #include <qpopupmenu.h>
00026 #include <qtabbar.h>
00027 #include <qglobal.h>
00028 #include <qprogressbar.h>
00029
00030 #include <limits.h>
00031 #include <stdio.h>
00032
00033 typedef void (QStyle::*QDrawMenuBarItemImpl) (QPainter *, int, int, int, int, QMenuItem *,
00034 QColorGroup &, bool, bool);
00035
00036 QDrawMenuBarItemImpl qt_set_draw_menu_bar_impl(QDrawMenuBarItemImpl impl);
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050 class HackProgressBar : public QProgressBar {
00051 public:
00052 HackProgressBar ( );
00053
00054 void paint ( QPaintEvent *event, OThemeStyle *style )
00055 {
00056 QPainter p( this );
00057
00058 if ( !contentsRect().contains( event->rect() ) ) {
00059 p.save();
00060 p.setClipRegion( event->region().intersect(frameRect()) );
00061 drawFrame( &p);
00062 p.restore();
00063 }
00064 if ( event->rect().intersects( contentsRect() )) {
00065 p.setClipRegion( event->region().intersect( contentsRect() ) );
00066
00067 int x, y, w, h;
00068 contentsRect ( ). rect ( &x, &y, &w, &h );
00069
00070 int prog = progress ( );
00071 int total = totalSteps ( );
00072 if ( prog < 0 )
00073 prog = 0;
00074 if ( total <= 0 )
00075 total = 1;
00076 int perc = prog * 100 / total;
00077
00078 style-> drawProgressBar ( &p, x, y, w, h, colorGroup ( ), perc );
00079
00080 if ( progress ( ) >= 0 && totalSteps ( ) > 0 ) {
00081 QString pstr;
00082 pstr. sprintf ( "%d%%", 100 * progress()/totalSteps ());
00083 p. setPen ( colorGroup().text());
00084 p. drawText (x,y,w-1,h-1,AlignCenter,pstr);
00085 }
00086 }
00087 }
00088 };
00089
00090
00091 #define QCOORDARRLEN(x) sizeof(x)/(sizeof(QCOORD)*2)
00092
00093 OThemeStyle::OThemeStyle( const QString &configFile )
00094 : OThemeBase( configFile )
00095 {
00096 setScrollBarExtent( getSBExtent(), getSBExtent() );
00097 setButtonDefaultIndicatorWidth( 0 );
00098 }
00099
00100 OThemeStyle::~OThemeStyle()
00101 {}
00102
00103 void OThemeStyle::polish( QApplication * )
00104 {
00105 qt_set_draw_menu_bar_impl((QDrawMenuBarItemImpl) &OThemeStyle::drawMenuBarItem);
00106 }
00107
00108
00109 void OThemeStyle::polish( QPalette &p )
00110 {
00111 oldPalette = p;
00112
00113 QColor bg = oldPalette. color ( QPalette::Normal, QColorGroup::Background );
00114
00115 if ( bgcolor. isValid ( ))
00116 bg = bgcolor;
00117
00118 if ( isColor ( Background ))
00119 bg = colorGroup ( oldPalette. active ( ), Background )-> background ( );
00120
00121 p = QPalette ( bg, bg );
00122
00123 if ( isPixmap( Background ) )
00124 p. setBrush ( QColorGroup::Background, QBrush ( bg, *uncached ( Background )));
00125
00126 if ( fgcolor. isValid ( )) {
00127 p. setColor ( QColorGroup::Foreground, fgcolor );
00128 p. setColor ( QColorGroup::ButtonText, fgcolor );
00129 }
00130 if ( selfgcolor. isValid ( ))
00131 p. setColor ( QColorGroup::HighlightedText, selfgcolor );
00132 if ( selbgcolor. isValid ( ))
00133 p. setColor ( QColorGroup::Highlight, selbgcolor );
00134 if ( winfgcolor. isValid ( ))
00135 p. setColor ( QColorGroup::Text, winfgcolor );
00136 if ( winbgcolor. isValid ( ))
00137 p. setColor ( QColorGroup::Base, winbgcolor );
00138
00139 }
00140
00141
00142 void OThemeStyle::unPolish( QApplication *app )
00143 {
00144 qt_set_draw_menu_bar_impl ( 0 );
00145 app->setPalette( oldPalette, true );
00146 }
00147
00148 void OThemeStyle::polish( QWidget *w )
00149 {
00150 if ( !w->isTopLevel() ) {
00151 if ( w->inherits( "QGroupBox" )
00152 || w->inherits( "QTabWidget" ) ) {
00153 w->setAutoMask( TRUE );
00154 return ;
00155 }
00156 if ( w->inherits( "QLabel" )
00157 || w->inherits( "QSlider" )
00158 || w->inherits( "QButton" )
00159 || w->inherits( "QProgressBar" )
00160 ) {
00161 w->setBackgroundOrigin( QWidget::ParentOrigin );
00162 }
00163 }
00164 if ( w->inherits( "QPopupMenu" ) ) {
00165 popupPalette = w->palette();
00166 if ( isColor( MenuItem ) || isColor( MenuItemDown ) ) {
00167 QPalette newPal( w->palette() );
00168 w->setPalettePropagation( QWidget::SamePalette );
00169 if ( isColor( MenuItem ) ) {
00170 newPal.setNormal( *colorGroup( newPal.normal(), MenuItem ) );
00171 newPal.setDisabled( *colorGroup( newPal.normal(), MenuItem ) );
00172 }
00173 if ( isColor( MenuItemDown ) )
00174 newPal.setActive( *colorGroup( newPal.active(), MenuItemDown ) );
00175 w->setPalette( newPal );
00176 }
00177 }
00178 else if ( w->inherits( "QCheckBox" ) ) {
00179 if ( isColor( IndicatorOff ) || isColor( IndicatorOn ) ) {
00180 QPalette newPal( w->palette() );
00181 w->setPalettePropagation( QWidget::SamePalette );
00182 if ( isColor( IndicatorOff ) ) {
00183 newPal.setNormal( *colorGroup( newPal.normal(), IndicatorOff ) );
00184 newPal.setDisabled( *colorGroup( newPal.normal(), IndicatorOff ) );
00185 }
00186 if ( isColor( IndicatorOn ) )
00187 newPal.setActive( *colorGroup( newPal.active(), IndicatorOn ) );
00188 w->setPalette( newPal );
00189 }
00190 }
00191 else if ( w->inherits( "QRadioButton" ) ) {
00192 if ( isColor( ExIndicatorOff ) || isColor( ExIndicatorOn ) ) {
00193 QPalette newPal( w->palette() );
00194 w->setPalettePropagation( QWidget::SamePalette );
00195 if ( isColor( ExIndicatorOff ) ) {
00196 newPal.setNormal( *colorGroup( newPal.normal(), ExIndicatorOff ) );
00197 newPal.setDisabled( *colorGroup( newPal.normal(),
00198 ExIndicatorOff ) );
00199 }
00200 if ( isColor( ExIndicatorOn ) )
00201 newPal.setActive( *colorGroup( newPal.active(), ExIndicatorOn ) );
00202 w->setPalette( newPal );
00203 }
00204 }
00205 else if ( w-> inherits ( "QProgressBar" ) ) {
00206 w-> installEventFilter ( this );
00207 }
00208 }
00209
00210 void OThemeStyle::unPolish( QWidget* w )
00211 {
00212 if ( !w->isTopLevel() ) {
00213 if ( w->inherits( "QGroupBox" )
00214 || w->inherits( "QTabWidget" ) ) {
00215 w->setAutoMask( FALSE );
00216 return ;
00217 }
00218 if ( w->inherits( "QLabel" )
00219 || w->inherits( "QSlider" )
00220 || w->inherits( "QButton" )
00221 || w->inherits( "QProgressBar" )
00222 ) {
00223 w->setBackgroundOrigin( QWidget::WidgetOrigin );
00224 }
00225 }
00226 if ( w->inherits( "QPopupMenu" ) )
00227 w->unsetPalette();
00228 else if ( w->inherits( "QCheckBox" ) )
00229 w->unsetPalette();
00230 else if ( w->inherits( "QRadioButton" ) )
00231 w->unsetPalette();
00232 else if ( w-> inherits ( "QProgressBar" ) )
00233 w-> removeEventFilter ( this );
00234 }
00235
00236 bool OThemeStyle::eventFilter ( QObject *obj, QEvent *ev )
00237 {
00238
00239
00240 if ( ev-> type ( ) == QEvent::Paint ) {
00241 HackProgressBar *pb = (HackProgressBar *) obj;
00242 pb-> paint ((QPaintEvent *) ev, this );
00243 return true;
00244 }
00245 return false;
00246 }
00247
00248 void OThemeStyle::drawBaseButton( QPainter *p, int x, int y, int w, int h,
00249 const QColorGroup &g, bool sunken, bool
00250 rounded, WidgetType type, const QBrush * )
00251 {
00252 if ( w <= 0 || h <= 0 )
00253 return;
00254
00255 int offset = borderPixmap( type ) ? 0 : decoWidth( type );
00256 QPen oldPen = p->pen();
00257
00258
00259 if ( gradientHint( type ) == GrReverseBevel ) {
00260 int i;
00261 bitBlt( p->device(), x, y, scalePixmap( w, h, type ), 0, 0, w, h,
00262 Qt::CopyROP, true );
00263 p->setPen( g.text() );
00264 for ( i = 0; i < borderWidth( type ); ++i, ++x, ++y, w -= 2, h -= 2 )
00265 p->drawRect( x, y, w, h );
00266 }
00267
00268 else if ( !borderPixmap( type ) && shade() == KDE ) {
00269 qDrawWinButton( p, x, y, w, h, g, sunken );
00270 if ( isPixmap( type ) )
00271 p->drawTiledPixmap( x + 4, y + 4, w - 6, h - 6,
00272 *scalePixmap( w - 6, h - 6,
00273 type ) );
00274 else
00275 p->fillRect( x + 4, y + 4, w - 6, h - offset * 6,
00276 g.brush( QColorGroup::Button ) );
00277
00278 }
00279 else {
00280 if ( ( w - offset * 2 ) > 0 && ( h - offset * 2 ) > 0 ) {
00281 if ( isPixmap( type ) )
00282 if ( rounded )
00283 p->drawTiledPixmap( x, y, w, h, *scalePixmap( w, h, type ) );
00284 else
00285 p->drawTiledPixmap( x + offset, y + offset, w - offset * 2,
00286 h - offset * 2,
00287 *scalePixmap( w - offset * 2, h - offset * 2,
00288 type ) );
00289 else
00290 p->fillRect( x + offset, y + offset, w - offset * 2, h - offset * 2,
00291 g.brush( QColorGroup::Button ) );
00292 }
00293 if ( borderPixmap( type ) ) {
00294 bitBlt( p->device(), x, y, scaleBorder( w, h, type ), 0, 0, w, h,
00295 Qt::CopyROP, false );
00296 }
00297 else
00298 drawShade( p, x, y, w, h, g, sunken, rounded,
00299 highlightWidth( type ), borderWidth( type ), shade() );
00300 }
00301 p->setPen( oldPen );
00302 }
00303
00304 void OThemeStyle::drawButton( QPainter *p, int x, int y, int w, int h,
00305 const QColorGroup &g, bool sunken,
00306 const QBrush *fill )
00307 {
00308 drawBaseButton( p, x, y, w, h, g, sunken, roundButton(), sunken ?
00309 PushButtonDown : PushButton, fill );
00310 }
00311
00312 void OThemeStyle::drawPushButton( QPushButton* btn, QPainter *p )
00313 {
00314 bool sunken = btn->isOn() || btn->isDown();
00315 int diw = buttonDefaultIndicatorWidth();
00316 drawBaseButton( p, diw, diw, btn->width() - 2 * diw, btn->height() - 2 * diw,
00317 *colorGroup( btn->colorGroup(), sunken ? PushButtonDown :
00318 PushButton ), sunken, roundButton(),
00319 sunken ? PushButtonDown : PushButton, NULL );
00320
00321 }
00322
00323 void OThemeStyle::drawBaseMask( QPainter *p, int x, int y, int w, int h,
00324 bool round )
00325 {
00326
00327 static const QCOORD btm_left_fill[] = {
00328 0, 0, 1, 0, 2, 0, 3, 0, 4, 0, 0, 1, 1, 1, 2, 1, 3, 1, 4, 1,
00329 1, 2, 2, 2, 3, 2, 4, 2, 2, 3, 3, 3, 4, 3, 3, 4, 4, 4
00330 };
00331
00332 static const QCOORD btm_right_fill[] = {
00333 0, 0, 1, 0, 2, 0, 3, 0, 4, 0, 0, 1, 1, 1, 2, 1, 3, 1, 4,
00334 1, 0, 2, 1, 2, 2, 2, 3, 2, 0, 3, 1, 3, 2, 3, 0, 4, 1, 4
00335 };
00336
00337 static const QCOORD top_left_fill[] = {
00338 3, 0, 4, 0, 2, 1, 3, 1, 4, 1, 1, 2, 2, 2, 3, 2, 4, 2, 0, 3,
00339 1, 3, 2, 3, 3, 3, 4, 3, 0, 4, 1, 4, 2, 4, 3, 4, 4, 4
00340 };
00341
00342 static const QCOORD top_right_fill[] = {
00343 0, 0, 1, 0, 0, 1, 1, 1, 2, 1, 0, 2, 1, 2, 2, 2, 3, 2, 0,
00344 3, 1, 3, 2, 3, 3, 3, 4, 3, 0, 4, 1, 4, 2, 4, 3, 4, 4, 4
00345 };
00346
00347 QBrush fillBrush( color1, SolidPattern );
00348 p->setPen( color1 );
00349 if ( round && w > 19 && h > 19 ) {
00350 int x2 = x + w - 1;
00351 int y2 = y + h - 1;
00352 QPointArray a( QCOORDARRLEN( top_left_fill ), top_left_fill );
00353 a.translate( 1, 1 );
00354 p->drawPoints( a );
00355 a.setPoints( QCOORDARRLEN( btm_left_fill ), btm_left_fill );
00356 a.translate( 1, h - 6 );
00357 p->drawPoints( a );
00358 a.setPoints( QCOORDARRLEN( top_right_fill ), top_right_fill );
00359 a.translate( w - 6, 1 );
00360 p->drawPoints( a );
00361 a.setPoints( QCOORDARRLEN( btm_right_fill ), btm_right_fill );
00362 a.translate( w - 6, h - 6 );
00363 p->drawPoints( a );
00364
00365 p->fillRect( x + 6, y, w - 12, h, fillBrush );
00366 p->fillRect( x, y + 6, x + 6, h - 12, fillBrush );
00367 p->fillRect( x2 - 6, y + 6, x2, h - 12, fillBrush );
00368 p->drawLine( x + 6, y, x2 - 6, y );
00369 p->drawLine( x + 6, y2, x2 - 6, y2 );
00370 p->drawLine( x, y + 6, x, y2 - 6 );
00371 p->drawLine( x2, y + 6, x2, y2 - 6 );
00372
00373 }
00374 else
00375 p->fillRect( x, y, w, h, fillBrush );
00376 }
00377
00378 void OThemeStyle::drawButtonMask( QPainter *p, int x, int y, int w, int h )
00379 {
00380 drawBaseMask( p, x, y, w, h, roundButton() );
00381 }
00382
00383 void OThemeStyle::drawComboButtonMask( QPainter *p, int x, int y, int w, int h )
00384 {
00385 drawBaseMask( p, x, y, w, h, roundComboBox() );
00386 }
00387
00388 void OThemeStyle::drawBevelButton( QPainter *p, int x, int y, int w, int h,
00389 const QColorGroup &g, bool sunken,
00390 const QBrush * )
00391 {
00392 WidgetType type = sunken ? BevelDown : Bevel;
00393 drawBaseButton( p, x, y, w, h, *colorGroup( g, type ), sunken, false, type );
00394 }
00395
00396 void OThemeStyle::drawToolButton( QPainter *p, int x, int y, int w, int h,
00397 const QColorGroup &g, bool sunken,
00398 const QBrush * )
00399 {
00400 WidgetType type = sunken ? ToolButtonDown : ToolButton;
00401 drawBaseButton( p, x, y, w, h, *colorGroup( g, type ), sunken, false, type );
00402 }
00403
00404 #if 0
00405 void OThemeStyle::drawKToolBarButton( QPainter *p, int x, int y, int w, int h,
00406 const QColorGroup &g, bool sunken,
00407 bool raised, bool enabled, bool popup,
00408 KToolButtonType type, const QString &btext,
00409 const QPixmap *pixmap, QFont *font,
00410 QWidget * )
00411 {
00412 QFont tmp_font( QString::fromLatin1( "Helvetica" ), 10 );
00413 if ( font )
00414 tmp_font = *font;
00415 QFontMetrics fm( tmp_font );
00416 WidgetType widget = sunken ? ToolButtonDown : ToolButton;
00417
00418 drawBaseButton( p, x, y, w, h, *colorGroup( g, widget ), sunken, false,
00419 widget );
00420 int dx, dy;
00421 if ( type == Icon ) {
00422 if ( pixmap ) {
00423 dx = ( w - pixmap->width() ) / 2;
00424 dy = ( h - pixmap->height() ) / 2;
00425 if ( sunken ) {
00426 ++dx;
00427 ++dy;
00428 }
00429 p->drawPixmap( x + dx, y + dy, *pixmap );
00430 }
00431 }
00432 else if ( type == IconTextRight ) {
00433 if ( pixmap ) {
00434 dx = 4;
00435 dy = ( h - pixmap->height() ) / 2;
00436 if ( sunken ) {
00437 ++dx;
00438 ++dy;
00439 }
00440 p->drawPixmap( x + dx, y + dy, *pixmap );
00441 }
00442 if ( !btext.isNull() ) {
00443 int tf = AlignVCenter | AlignLeft;
00444 if ( pixmap )
00445 dx = 4 + pixmap->width() + 2;
00446 else
00447 dx = 4;
00448 dy = 0;
00449 if ( sunken ) {
00450 ++dx;
00451 ++dy;
00452 }
00453 if ( font )
00454 p->setFont( *font );
00455 if ( raised )
00456 p->setPen( KGlobalSettings::toolBarHighlightColor() );
00457 p->drawText( x + dx, y + dy, w - dx, h, tf, btext );
00458 }
00459 }
00460 else if ( type == Text ) {
00461 if ( !btext.isNull() ) {
00462 int tf = AlignTop | AlignLeft;
00463 if ( !enabled )
00464 p->setPen( g.dark() );
00465 dx = ( w - fm.width( btext ) ) / 2;
00466 dy = ( h - fm.lineSpacing() ) / 2;
00467 if ( sunken ) {
00468 ++dx;
00469 ++dy;
00470 }
00471 if ( font )
00472 p->setFont( *font );
00473 if ( raised )
00474 p->setPen( KGlobalSettings::toolBarHighlightColor() );
00475 p->drawText( x + dx, y + dy, fm.width( btext ), fm.lineSpacing(), tf, btext );
00476 }
00477 }
00478 else if ( type == IconTextBottom ) {
00479 if ( pixmap ) {
00480 dx = ( w - pixmap->width() ) / 2;
00481 dy = ( h - fm.lineSpacing() - pixmap->height() ) / 2;
00482 if ( sunken ) {
00483 ++dx;
00484 ++dy;
00485 }
00486 p->drawPixmap( x + dx, y + dy, *pixmap );
00487 }
00488 if ( !btext.isNull() ) {
00489 int tf = AlignBottom | AlignHCenter;
00490 dx = ( w - fm.width( btext ) ) / 2;
00491 dy = h - fm.lineSpacing() - 4;
00492 if ( sunken ) {
00493 ++dx;
00494 ++dy;
00495 }
00496 if ( font )
00497 p->setFont( *font );
00498 if ( raised )
00499 p->setPen( KGlobalSettings::toolBarHighlightColor() );
00500 p->drawText( x + dx, y + dy, fm.width( btext ), fm.lineSpacing(), tf, btext );
00501 }
00502 }
00503 if ( popup ) {
00504 if ( enabled )
00505 qDrawArrow ( p, DownArrow, WindowsStyle, false, w - 5, h - 5, 0, 0,
00506 g, true );
00507 else
00508 qDrawArrow ( p, DownArrow, WindowsStyle, false, w - 5, h - 5,
00509 0, 0, g, false );
00510 }
00511 }
00512
00513 void OThemeStyle::drawKBarHandle( QPainter *p, int x, int y, int w, int h,
00514 const QColorGroup &g, KToolBarPos, QBrush * )
00515 {
00516 if ( w > h )
00517 drawBaseButton( p, x, y, w, h, *colorGroup( g, HBarHandle ), false, false,
00518 HBarHandle );
00519 else
00520 drawBaseButton( p, x, y, w, h, *colorGroup( g, VBarHandle ), false, false,
00521 VBarHandle );
00522 }
00523
00524 void OThemeStyle::drawKToolBar( QPainter *p, int x, int y, int w, int h,
00525 const QColorGroup &g, KToolBarPos, QBrush * )
00526 {
00527 drawBaseButton( p, x, y, w, h, *colorGroup( g, ToolBar ), false, false,
00528 ToolBar );
00529 }
00530 #endif
00531
00532 QRect OThemeStyle::buttonRect( int x, int y, int w, int h )
00533 {
00534 int spacing = decoWidth( PushButton ) > decoWidth( PushButtonDown ) ?
00535 decoWidth( PushButton ) : decoWidth( PushButtonDown );
00536 return ( QRect( x + spacing, y + spacing, w - ( spacing * 2 ), h - ( spacing * 2 ) ) );
00537 }
00538
00539 void OThemeStyle::drawComboButton( QPainter *p, int x, int y, int w, int h,
00540 const QColorGroup &g, bool sunken, bool,
00541 bool, const QBrush * )
00542 {
00543 WidgetType widget = sunken ? ComboBoxDown : ComboBox;
00544 drawBaseButton( p, x, y, w, h, *colorGroup( g, widget ), sunken,
00545 roundComboBox(), widget );
00546 if ( !sunken && isPixmap( ComboDeco ) )
00547 p->drawPixmap( w - uncached( ComboDeco ) ->width() -
00548 decoWidth( ComboBox ) - 2,
00549 y + ( h - uncached( ComboDeco ) ->
00550 height() ) / 2, *uncached( ComboDeco ) );
00551 else if ( sunken && isPixmap( ComboDecoDown ) )
00552 p->drawPixmap( w - uncached( ComboDecoDown ) ->width() -
00553 decoWidth( ComboBoxDown ) - 2,
00554 y + ( h - uncached( ComboDecoDown ) ->
00555 height() ) / 2, *uncached( ComboDecoDown ) );
00556 else {
00557 qDrawArrow( p, Qt::DownArrow, Qt::MotifStyle, false, w - 15, y + 6, 10,
00558 h - 15, *colorGroup( g, widget ), true );
00559 qDrawShadeRect( p, w - 14, y + 7 + ( h - 15 ), 10, 3, *colorGroup( g, widget ) );
00560 }
00561 }
00562
00563 void OThemeStyle::drawScrollBarControls( QPainter *p, const QScrollBar *sb,
00564 int sliderStart, uint controls,
00565 uint activeControl )
00566 {
00567 int sliderMin, sliderMax, sliderLength, buttonDim;
00568 QRect add
00569 , sub, addPage, subPage, slider;
00570 int addX, addY, subX, subY;
00571 bool horizontal = sb->orientation() == QScrollBar::Horizontal;
00572 int len = ( horizontal ) ? sb->width() : sb->height();
00573 int extent = ( horizontal ) ? sb->height() : sb->width();
00574 int offset = decoWidth( horizontal ? HScrollGroove : VScrollGroove );
00575 QColorGroup g = sb->colorGroup();
00576
00577 scrollBarMetrics( sb, sliderMin, sliderMax, sliderLength, buttonDim );
00578 if ( sliderStart > sliderMax )
00579 sliderStart = sliderMax;
00580
00581 int sliderEnd = sliderStart + sliderLength;
00582 int sliderWidth = extent - offset * 2;
00583
00584
00585
00586 if ( scrollBarLayout() == SBOpposite ) {
00587 if ( horizontal ) {
00588 subY = addY = ( extent - buttonDim ) / 2;
00589 subX = offset;
00590 addX = len - buttonDim - offset;
00591 }
00592 else {
00593 subX = addX = ( extent - buttonDim ) / 2;
00594 subY = offset;
00595 addY = len - buttonDim - offset;
00596 }
00597 sub.setRect( subX, subY, buttonDim, buttonDim );
00598 add.setRect( addX, addY, buttonDim, buttonDim );
00599 if ( horizontal ) {
00600 subPage.setRect( sub.right() + 1, offset,
00601 sliderStart - sub.right() - 1 , sliderWidth );
00602 addPage.setRect( sliderEnd, offset, addX - sliderEnd, sliderWidth );
00603 slider.setRect( sliderStart, offset, sliderLength, sliderWidth );
00604 }
00605 else {
00606 subPage.setRect( offset, sub.bottom() + 1, sliderWidth,
00607 sliderStart - sub.bottom() - 1 );
00608 addPage.setRect( offset, sliderEnd, sliderWidth, addY - sliderEnd );
00609 slider.setRect( offset, sliderStart, sliderWidth, sliderLength );
00610 }
00611 }
00612 else if ( horizontal ) {
00613 subY = addY = ( extent - buttonDim ) / 2;
00614 if ( scrollBarLayout() == SBBottomLeft ) {
00615 subX = offset;
00616 addX = buttonDim + offset;
00617 subPage.setRect( buttonDim * 2, 0, sliderStart - 1, extent );
00618 addPage.setRect( sliderEnd, 0, len - sliderEnd, extent );
00619 slider.setRect( sliderStart, 0, sliderLength, extent );
00620 }
00621 else {
00622 subX = len - buttonDim - buttonDim - offset;
00623 addX = len - buttonDim - offset;
00624 subPage.setRect( offset + 1, offset, sliderStart - 1 , sliderWidth );
00625 addPage.setRect( sliderEnd, offset, subX - sliderEnd, sliderWidth );
00626 slider.setRect( sliderStart, offset, sliderLength, sliderWidth );
00627 }
00628 sub.setRect( subX, subY, buttonDim, buttonDim );
00629 add.setRect( addX, addY, buttonDim, buttonDim );
00630 }
00631 else {
00632 subX = addX = ( extent - buttonDim ) / 2;
00633 subY = len - buttonDim - buttonDim - offset;
00634 addY = len - buttonDim - offset;
00635 subPage.setRect( offset, offset + 1, sliderWidth,
00636 sliderStart - offset - 1 );
00637 addPage.setRect( offset, sliderEnd, sliderWidth, subY - sliderEnd );
00638 slider.setRect( offset, sliderStart, sliderWidth, sliderLength );
00639 sub.setRect( subX, subY, buttonDim, buttonDim );
00640 add.setRect( addX, addY, buttonDim, buttonDim );
00641 }
00642
00643
00644 bool active;
00645 if ( ( controls & QStyle::SubPage ) ) {
00646 drawScrollBarGroove( p, sb, horizontal, subPage, g );
00647 }
00648 if ( ( controls & QStyle::AddPage ) ) {
00649 drawScrollBarGroove( p, sb, horizontal, addPage, g );
00650 }
00651 if ( controls & QStyle::AddLine ) {
00652 active = activeControl == QStyle::AddLine;
00653 drawBaseButton( p, add.x(), add.y(), add.width(), add.height(),
00654 *colorGroup( g, active ? ScrollButtonDown : ScrollButton ),
00655 active, false, active ? ScrollButtonDown : ScrollButton );
00656 drawArrow( p, ( horizontal ) ? RightArrow : DownArrow, active, add.x() + 3,
00657 add.y() + 3, add.width() - 6, add.height() - 6,
00658 *colorGroup( g, active ? ScrollButtonDown : ScrollButton ) );
00659 }
00660 if ( controls & QStyle::SubLine ) {
00661 active = activeControl == QStyle::SubLine;
00662 p->setPen( g.dark() );
00663 p->drawRect( sub );
00664 drawBaseButton( p, sub.x(), sub.y(), sub.width(), sub.height(),
00665 *colorGroup( g, active ? ScrollButtonDown : ScrollButton ),
00666 active, false, active ? ScrollButtonDown : ScrollButton );
00667 drawArrow( p, ( horizontal ) ? LeftArrow : UpArrow, active, sub.x() + 3,
00668 sub.y() + 3, sub.width() - 6, sub.height() - 6,
00669 *colorGroup( g, active ? ScrollButtonDown : ScrollButton ) );
00670 }
00671 if ( controls & QStyle::Slider ) {
00672 active = activeControl == QStyle::Slider;
00673 WidgetType widget = horizontal ?
00674 active ? HScrollBarSliderDown : HScrollBarSlider :
00675 active ? VScrollBarSliderDown : VScrollBarSlider;
00676
00677 drawBaseButton( p, slider.x(), slider.y(), slider.width(),
00678 slider.height(), *colorGroup( g, widget ), active, false,
00679 widget );
00680 int spaceW = horizontal ? slider.width() - decoWidth( widget ) - 4 :
00681 slider.width();
00682 int spaceH = horizontal ? slider.height() :
00683 slider.height() - decoWidth( widget ) - 4;
00684 widget = active ? horizontal ? HScrollDecoDown : VScrollDecoDown :
00685 horizontal ? HScrollDeco : VScrollDeco;
00686 if ( isPixmap( widget ) ) {
00687 if ( spaceW >= uncached( widget ) ->width() &&
00688 spaceH >= uncached( widget ) ->height() ) {
00689 p->drawPixmap( slider.x() + ( slider.width() -
00690 uncached( widget ) ->width() ) / 2,
00691 slider.y() + ( slider.height() -
00692 uncached( widget ) ->height() ) / 2,
00693 *uncached( widget ) );
00694 }
00695 }
00696 }
00697 }
00698
00699 void OThemeStyle::drawScrollBarGroove( QPainter *p, const QScrollBar *sb,
00700 bool horizontal, QRect r, QColorGroup g )
00701
00702 {
00703 WidgetType widget = ( horizontal ) ? HScrollGroove : VScrollGroove;
00704 if ( !isPixmap( widget ) ) {
00705 p->fillRect( r, colorGroup( g, widget ) ->brush( QColorGroup::Background ) );
00706 }
00707 else {
00708
00709
00710 QPixmap buffer( sb->size() );
00711 QPainter bPainter( &buffer );
00712 bPainter.drawTiledPixmap( 0, 0, buffer.width(), buffer.height(),
00713 *scalePixmap( buffer.width(), buffer.height(),
00714 widget ) );
00715 bitBlt( p->device(), r.x(), r.y(), &buffer, r.x(), r.y(), r.width(),
00716 r.height(), Qt::CopyROP );
00717 }
00718
00719 drawShade( p, sb->rect().x(), sb->rect().y(), sb->rect().width(),
00720 sb->rect().height(), *colorGroup( g, widget ), true, false,
00721 highlightWidth( widget ), borderWidth( widget ), shade() );
00722 }
00723
00724 void OThemeStyle::scrollBarMetrics( const QScrollBar *sb, int &sliderMin,
00725 int &sliderMax, int &sliderLength,
00726 int &buttonDim )
00727 {
00728 bool horizontal = sb->orientation() == QScrollBar::Horizontal;
00729 int offset = decoWidth( horizontal ? HScrollGroove : VScrollGroove );
00730 int maxlen;
00731 int len = horizontal ? sb->width() : sb->height();
00732 int extent = horizontal ? sb->height() : sb->width();
00733
00734 if ( len > ( extent - offset * 2 - 1 ) * 2 + offset * 2 )
00735 buttonDim = extent - offset * 2;
00736 else
00737 buttonDim = ( len - offset * 2 ) / 2 - 1;
00738 maxlen = len - offset * 2 - buttonDim * 2 - 1;
00739
00740 switch ( scrollBarLayout() ) {
00741 case SBBottomLeft:
00742 sliderMin = ( horizontal ) ? buttonDim * 2 + offset + 1 : offset + 1;
00743 break;
00744 case SBBottomRight:
00745 sliderMin = offset + 1;
00746 break;
00747 case SBOpposite:
00748 default:
00749 sliderMin = offset + buttonDim;
00750 break;
00751 }
00752 if ( sb->maxValue() == sb->minValue() )
00753 sliderLength = maxlen;
00754 else
00755 sliderLength = ( sb->pageStep() * maxlen ) / ( sb->maxValue() -
00756 sb->minValue() + sb->pageStep() );
00757 if ( sliderLength < 12 || ( sb->maxValue() - sb->minValue() ) > INT_MAX / 2 )
00758 sliderLength = 12;
00759 if ( sliderLength > maxlen )
00760 sliderLength = maxlen;
00761 sliderMax = sliderMin + maxlen - sliderLength;
00762 }
00763
00764 QStyle::ScrollControl OThemeStyle::scrollBarPointOver( const QScrollBar *sb,
00765 int sliderStart,
00766 const QPoint &p )
00767 {
00768 if ( !sb->rect().contains( p ) )
00769 return ( QStyle::NoScroll );
00770 int sliderMin, sliderMax, sliderLength, buttonDim;
00771 int pos = ( sb->orientation() == QScrollBar::Horizontal ) ? p.x() : p.y();
00772 scrollBarMetrics( sb, sliderMin, sliderMax, sliderLength, buttonDim );
00773
00774 if ( scrollBarLayout() == SBOpposite ) {
00775 if ( pos < sliderMin )
00776 return QStyle::SubLine;
00777 if ( pos < sliderStart )
00778 return SubPage;
00779 if ( pos < sliderStart + sliderLength )
00780 return QStyle::Slider;
00781 if ( pos < sliderMax + sliderLength )
00782 return QStyle::AddPage;
00783 return QStyle::AddLine;
00784 }
00785 if ( scrollBarLayout() == SBBottomLeft && sb->orientation() ==
00786 QScrollBar::Horizontal ) {
00787 if ( pos <= buttonDim )
00788 return ( QStyle::SubLine );
00789 else if ( pos <= buttonDim * 2 )
00790 return ( QStyle::AddLine );
00791 else if ( pos < sliderStart )
00792 return ( QStyle::SubPage );
00793 else if ( pos < sliderStart + sliderLength )
00794 return ( QStyle::Slider );
00795 return ( AddPage );
00796 }
00797 else {
00798 if ( pos < sliderStart )
00799 return QStyle::SubPage;
00800 if ( pos < sliderStart + sliderLength )
00801 return QStyle::Slider;
00802 if ( pos < sliderMax + sliderLength )
00803 return QStyle::AddPage;
00804 if ( pos < sliderMax + sliderLength + buttonDim )
00805 return QStyle::SubLine;
00806 return QStyle::AddLine;
00807 }
00808 }
00809
00810 QSize OThemeStyle::exclusiveIndicatorSize() const
00811 {
00812 if ( isPixmap( ExIndicatorOn ) )
00813 return ( uncached( ExIndicatorOn ) ->size() );
00814 else
00815 return ( QWindowsStyle::exclusiveIndicatorSize() );
00816 }
00817
00818 QSize OThemeStyle::indicatorSize() const
00819 {
00820 if ( isPixmap( IndicatorOn ) )
00821 return ( uncached( IndicatorOn ) ->size() );
00822 else
00823 return ( QWindowsStyle::indicatorSize() );
00824 }
00825
00826 void OThemeStyle::drawExclusiveIndicator( QPainter* p, int x, int y, int w,
00827 int h, const QColorGroup &g, bool on,
00828 bool down, bool enabled )
00829 {
00830 if ( isPixmap( ( on || down ) ? ExIndicatorOn : ExIndicatorOff ) ) {
00831 p->drawPixmap( x, y, *uncached( ( on || down ) ? ExIndicatorOn :
00832 ExIndicatorOff ) );
00833 }
00834 else {
00835 QWindowsStyle::drawExclusiveIndicator( p, x, y, w, h,
00836 *colorGroup( g, ExIndicatorOn ),
00837 on, down, enabled );
00838 }
00839
00840 }
00841
00842 void OThemeStyle::drawIndicator( QPainter* p, int x, int y, int w, int h,
00843 const QColorGroup &g, int state, bool down,
00844 bool enabled )
00845 {
00846 if ( isPixmap( ( down || state != QButton::Off ) ?
00847 IndicatorOn : IndicatorOff ) ) {
00848 p->drawPixmap( x, y, *uncached( ( down || state != QButton::Off ) ?
00849 IndicatorOn : IndicatorOff ) );
00850 }
00851 else {
00852 QWindowsStyle::drawIndicator( p, x, y, w, h,
00853 *colorGroup( g, IndicatorOn ), state,
00854 down, enabled );
00855 }
00856 }
00857
00858 void OThemeStyle::drawExclusiveIndicatorMask( QPainter *p, int x, int y, int w,
00859 int h, bool on )
00860 {
00861 if ( isPixmap( ( on ) ? ExIndicatorOn : ExIndicatorOff ) ) {
00862 const QBitmap * mask = uncached( ( on ) ? ExIndicatorOn : ExIndicatorOff ) ->
00863 mask();
00864 if ( mask ) {
00865 p->drawPixmap( x, y, *mask );
00866 }
00867 else
00868 p->fillRect( x, y, w, h, QBrush( color1, SolidPattern ) );
00869 }
00870 else
00871 QWindowsStyle::drawExclusiveIndicatorMask( p, x, y, w, h, on );
00872 }
00873
00874 void OThemeStyle::drawIndicatorMask( QPainter *p, int x, int y, int w, int h,
00875 int state )
00876 {
00877 if ( isPixmap( ( state != QButton::Off ) ? IndicatorOn : IndicatorOff ) ) {
00878 const QBitmap * mask = uncached( ( state != QButton::Off ) ? IndicatorOn :
00879 IndicatorOff ) ->mask();
00880 if ( mask )
00881 p->drawPixmap( x, y, *mask );
00882 else
00883 p->fillRect( x, y, w, h, QBrush( color1, SolidPattern ) );
00884 }
00885 else
00886 QWindowsStyle::drawIndicatorMask( p, x, y, w, h, state );
00887 }
00888
00889 void OThemeStyle::drawSliderGroove( QPainter *p, int x, int y, int w, int h,
00890 const QColorGroup& g, QCOORD c,
00891 Orientation orient )
00892 {
00893 if ( roundSlider() )
00894 QWindowsStyle::drawSliderGroove( p, x, y, w, h,
00895 *colorGroup( g, SliderGroove ),
00896 c, orient );
00897 else
00898 drawBaseButton( p, x, y, w, h, *colorGroup( g, SliderGroove ), true,
00899 false, SliderGroove );
00900 }
00901
00902 void OThemeStyle::drawSlider( QPainter *p, int x, int y, int w, int h,
00903 const QColorGroup &g, Orientation orient,
00904 bool tickAbove, bool tickBelow )
00905 {
00906 if ( isPixmap( Slider ) ) {
00907 if ( orient == Qt::Horizontal )
00908 p->drawPixmap( x, y + ( h - uncached( Slider ) ->height() ) / 2,
00909 *uncached( Slider ) );
00910 else
00911 p->drawPixmap( x + ( w - uncached( Slider ) ->width() ) / 2,
00912 y, *uncached( Slider ) );
00913 }
00914 else {
00915 QWindowsStyle::drawSlider( p, x, y, w, h, *colorGroup( g, Slider ),
00916 orient, tickAbove, tickBelow );
00917 }
00918 }
00919
00920 void OThemeStyle::drawSliderMask( QPainter *p, int x, int y, int w, int h,
00921 Orientation orient, bool tickAbove,
00922 bool tickBelow )
00923 {
00924
00925
00926 if ( isPixmap( Slider ) )
00927 p->fillRect( x, y, w, h, QBrush( color1, SolidPattern ) );
00928 else
00929 QWindowsStyle::drawSliderMask( p, x, y, w, h, orient, tickAbove,
00930 tickBelow );
00931 }
00932
00933 int OThemeStyle::defaultFrameWidth() const
00934 {
00935 return ( frameWidth() );
00936 }
00937
00938 void OThemeStyle::getButtonShift( int &x, int &y )
00939 {
00940 x = buttonXShift();
00941 y = buttonYShift();
00942 }
00943
00944 int OThemeStyle::sliderLength() const
00945 {
00946 return ( sliderButtonLength() );
00947 }
00948
00949 void OThemeStyle::drawArrow( QPainter *p, Qt::ArrowType type, bool down, int x,
00950 int y, int w, int h, const QColorGroup &g,
00951 bool enabled, const QBrush * )
00952 {
00953
00954
00955 WidgetType widget;
00956 switch ( type ) {
00957 case UpArrow:
00958 widget = enabled ? down ? SunkenArrowUp : ArrowUp : DisArrowUp;
00959 break;
00960 case DownArrow:
00961 widget = enabled ? down ? SunkenArrowDown : ArrowDown : DisArrowDown;
00962 break;
00963 case LeftArrow:
00964 widget = enabled ? down ? SunkenArrowLeft : ArrowLeft : DisArrowLeft;
00965 break;
00966 case RightArrow:
00967 default:
00968 widget = enabled ? down ? SunkenArrowRight : ArrowRight : DisArrowRight;
00969 break;
00970 }
00971 if ( isPixmap( widget ) ) {
00972 p->drawPixmap( x + ( w - uncached( widget ) ->width() ) / 2,
00973 y + ( h - uncached( widget ) ->height() ) / 2,
00974 *uncached( widget ) );
00975 return ;
00976 }
00977 const QColorGroup *cg = colorGroup( g, widget );
00978
00979 if ( arrowType() == MotifArrow )
00980 qDrawArrow( p, type, Qt::MotifStyle, down, x, y, w, h, *cg, enabled );
00981 else if ( arrowType() == SmallArrow ) {
00982 QColorGroup tmp( *cg );
00983 tmp.setBrush( QColorGroup::Button, QBrush( NoBrush ) );
00984 QWindowsStyle::drawArrow( p, type, false, x, y, w, h,
00985 tmp, true );
00986 }
00987 else {
00988 QPointArray a;
00989 int x2 = x + w - 1, y2 = y + h - 1;
00990 switch ( type ) {
00991 case Qt::UpArrow:
00992 a.setPoints( 4, x, y2, x2, y2, x + w / 2, y, x, y2 );
00993 break;
00994 case Qt::DownArrow:
00995 a.setPoints( 4, x, y, x2, y, x + w / 2, y2, x, y );
00996 break;
00997 case Qt::LeftArrow:
00998 a.setPoints( 4, x2, y, x2, y2, x, y + h / 2, x2, y );
00999 break;
01000 default:
01001 a.setPoints( 4, x, y, x, y2, x2, y + h / 2, x, y );
01002 break;
01003 }
01004 QBrush oldBrush = p->brush();
01005 QPen oldPen = p->pen();
01006 p->setBrush( cg->brush( QColorGroup::Shadow ) );
01007 p->setPen( cg->shadow() );
01008 p->drawPolygon( a );
01009 p->setBrush( oldBrush );
01010 p->setPen( oldPen );
01011 }
01012 }
01013
01014
01015
01016
01017
01018
01019
01020
01021
01022 void OThemeStyle::drawShade( QPainter *p, int x, int y, int w, int h,
01023 const QColorGroup &g, bool sunken, bool rounded,
01024 int hWidth, int bWidth, ShadeStyle style )
01025 {
01026 int i, sc, bc, x2, y2;
01027 QPen highPen, lowPen;
01028
01029 if ( style == Motif ) {
01030 highPen.setColor( sunken ? g.dark() : g.light() );
01031 lowPen.setColor( sunken ? g.light() : g.dark() );
01032 }
01033 else {
01034 highPen.setColor( sunken ? g.shadow() : g.light() );
01035 lowPen.setColor( sunken ? g.light() : g.shadow() );
01036 }
01037
01038
01039 if ( rounded && w > 19 && h > 19 ) {
01040 x2 = x + w - 1, y2 = y + h - 1;
01041 QPointArray bPntArray, hPntArray, lPntArray;
01042 QPointArray bLineArray, hLineArray, lLineArray;
01043
01044 for ( i = 0, bc = 0; i < bWidth; ++i ) {
01045 bPntArray.putPoints( bc, 24, x + 4, y + 1, x + 5, y + 1, x + 3, y + 2, x + 2, y + 3,
01046 x + 1, y + 4, x + 1, y + 5, x + 1, y2 - 5, x + 1, y2 - 4, x + 2, y2 - 3,
01047 x2 - 5, y + 1, x2 - 4, y + 1, x2 - 3, y + 2, x2 - 5, y2 - 1,
01048 x2 - 4, y2 - 1, x2 - 3, y2 - 2, x2 - 2, y2 - 3, x2 - 1, y2 - 5,
01049 x2 - 1, y2 - 4, x + 3, y2 - 2, x + 4, y2 - 1, x + 5, y2 - 1,
01050 x2 - 2, y + 3, x2 - 1, y + 4, x2 - 1, y + 5 );
01051 bc += 24;
01052
01053 if ( i < bWidth - 1 || hWidth != 0 ) {
01054 bPntArray.putPoints( bc, 20, x + 6, y + 1, x + 4, y + 2, x + 3, y + 3,
01055 x + 2, y + 4, x + 1, y + 6, x2 - 6, y + 1, x2 - 4, y + 2,
01056 x2 - 3, y + 3, x + 2, y2 - 4, x + 1, y2 - 6, x2 - 6, y2 - 1,
01057 x2 - 4, y2 - 2, x2 - 3, y2 - 3, x2 - 2, y2 - 4, x2 - 1, y2 - 6,
01058 x + 6, y2 - 1, x + 4, y2 - 2, x + 3, y2 - 3, x2 - 1, y + 6,
01059 x2 - 2, y + 4 );
01060 bc += 20;
01061 }
01062 bLineArray.putPoints( i * 8, 8, x + 6, y, x2 - 6, y, x, y + 6, x, y2 - 6,
01063 x + 6, y2, x2 - 6, y2, x2, y + 6, x2, y2 - 6 );
01064 ++x, ++y;
01065 --x2, --y2;
01066 }
01067
01068 for ( i = 0, sc = 0; i < hWidth; ++i ) {
01069 hPntArray.putPoints( sc, 12, x + 4, y + 1, x + 5, y + 1,
01070 x + 3, y + 2, x + 2, y + 3, x + 1, y + 4, x + 1, y + 5,
01071 x + 1, y2 - 5, x + 1, y2 - 4, x + 2, y2 - 3,
01072 x2 - 5, y + 1, x2 - 4, y + 1, x2 - 3, y + 2 );
01073 lPntArray.putPoints( sc, 12, x2 - 5, y2 - 1, x2 - 4, y2 - 1,
01074 x2 - 3, y2 - 2, x2 - 2, y2 - 3, x2 - 1, y2 - 5, x2 - 1, y2 - 4,
01075 x + 3, y2 - 2, x + 4, y2 - 1, x + 5, y2 - 1,
01076 x2 - 2, y + 3, x2 - 1, y + 4, x2 - 1, y + 5 );
01077 sc += 12;
01078 if ( i < hWidth - 1 ) {
01079 hPntArray.putPoints( sc, 10, x + 6, y + 1, x + 4, y + 2,
01080 x + 3, y + 3, x + 2, y + 4, x + 1, y + 6,
01081 x2 - 6, y + 1, x2 - 4, y + 2,
01082 x2 - 3, y + 3, x + 2, y2 - 4, x + 1, y2 - 6 );
01083 lPntArray.putPoints( sc, 10, x2 - 6, y2 - 1, x2 - 4, y2 - 2,
01084 x2 - 3, y2 - 3, x2 - 2, y2 - 4, x2 - 1, y2 - 6,
01085 x + 6, y2 - 1, x + 4, y2 - 2,
01086 x + 3, y2 - 3, x2 - 1, y + 6, x2 - 2, y + 4 );
01087 sc += 10;
01088 }
01089 hLineArray.putPoints( i * 4, 4, x + 6, y, x2 - 6, y, x, y + 6, x, y2 - 6 );
01090 lLineArray.putPoints( i * 4, 4, x + 6, y2, x2 - 6, y2, x2, y + 6, x2, y2 - 6 );
01091 ++x, ++y;
01092 --x2, --y2;
01093 }
01094 p->setPen( Qt::black );
01095 p->drawPoints( bPntArray );
01096 p->drawLineSegments( bLineArray );
01097 p->setPen( highPen );
01098 p->drawPoints( hPntArray );
01099 p->drawLineSegments( hLineArray );
01100 p->setPen( lowPen );
01101 p->drawPoints( lPntArray );
01102 p->drawLineSegments( lLineArray );
01103 }
01104
01105 else {
01106 QPointArray highShade( hWidth * 4 );
01107 QPointArray lowShade( hWidth * 4 );
01108
01109 p->setPen( g.shadow() );
01110 for ( i = 0; i < bWidth && w > 2 && h > 2; ++i, ++x, ++y, w -= 2, h -= 2 )
01111 p->drawRect( x, y , w, h );
01112
01113 if ( !hWidth )
01114 return ;
01115
01116 x2 = x + w - 1, y2 = y + h - 1;
01117 for ( i = 0; i < hWidth; ++i, ++x, ++y, --x2, --y2 ) {
01118 highShade.putPoints( i * 4, 4, x, y, x2, y, x, y, x, y2 );
01119 lowShade.putPoints( i * 4, 4, x, y2, x2, y2, x2, y, x2, y2 );
01120 }
01121 if ( style == Windows && hWidth > 1 ) {
01122 p->setPen( highPen );
01123 p->drawLineSegments( highShade, 0, 2 );
01124 p->setPen( lowPen );
01125 p->drawLineSegments( lowShade, 0, 2 );
01126
01127 p->setPen( ( sunken ) ? g.dark() : g.mid() );
01128 p->drawLineSegments( highShade, 4 );
01129 p->setPen( ( sunken ) ? g.mid() : g.dark() );
01130 p->drawLineSegments( lowShade, 4 );
01131 }
01132 else {
01133 p->setPen( ( sunken ) ? g.dark() : g.light() );
01134 p->drawLineSegments( highShade );
01135 p->setPen( ( sunken ) ? g.light() : g.dark() );
01136 p->drawLineSegments( lowShade );
01137 }
01138 }
01139 }
01140
01141 void OThemeStyle::drawPushButtonLabel( QPushButton *btn, QPainter *p )
01142 {
01143 WidgetType widget = btn->isDown() || btn->isOn() ? PushButtonDown :
01144 PushButton;
01145 const QColorGroup *cg = colorGroup( btn->colorGroup(), widget );
01146 int x, y, w, h;
01147
01148 QRect r = btn->rect();
01149 r.rect( &x, &y, &w, &h );
01150 x += decoWidth( widget );
01151 y += decoWidth( widget );
01152 w -= decoWidth( widget ) * 2;
01153 h -= decoWidth( widget ) * 2;
01154 bool act = btn->isOn() || btn->isDown();
01155
01156
01157 if ( btn->popup() ) {
01158 int dx = menuButtonIndicatorWidth( btn->height() );
01159
01160 QColorGroup g( btn->colorGroup() );
01161 int xx = x + w - dx - 4;
01162 int yy = y - 3;
01163 int hh = h + 6;
01164
01165 if ( !act ) {
01166 p->setPen( g.light() );
01167 p->drawLine( xx, yy + 3, xx, yy + hh - 4 );
01168 }
01169 else {
01170 p->setPen( g.button() );
01171 p->drawLine( xx, yy + 4, xx, yy + hh - 4 );
01172 }
01173 drawArrow( p, DownArrow, FALSE,
01174 x + w - dx - 2, y + 2, dx, h - 4,
01175 btn->colorGroup(),
01176 btn->isEnabled() );
01177 w -= dx;
01178 }
01179
01180
01181 if ( btn->iconSet() && !btn->iconSet() ->isNull() ) {
01182 QIconSet::Mode mode = btn->isEnabled()
01183 ? QIconSet::Normal : QIconSet::Disabled;
01184 if ( mode == QIconSet::Normal && btn->hasFocus() )
01185 mode = QIconSet::Active;
01186 QPixmap pixmap = btn->iconSet() ->pixmap( QIconSet::Automatic, mode );
01187 int pixw = pixmap.width();
01188 int pixh = pixmap.height();
01189
01190 p->drawPixmap( x + 6, y + h / 2 - pixh / 2, pixmap );
01191 x += pixw + 8;
01192 w -= pixw + 8;
01193 }
01194
01195 if ( widget == PushButtonDown ) {
01196 drawItem( p, x + buttonXShift(), y + buttonYShift(),
01197 w, h, AlignCenter | ShowPrefix, *cg, btn->isEnabled(),
01198 btn->pixmap(), btn->text(), -1, &cg->buttonText() );
01199 }
01200 else {
01201 drawItem( p, x, y, w, h, AlignCenter | ShowPrefix, *cg,
01202 btn->isEnabled(), btn->pixmap(), btn->text(), -1,
01203 &cg->buttonText() );
01204 }
01205 }
01206
01207 int OThemeStyle::splitterWidth() const
01208 {
01209 return ( splitWidth() );
01210 }
01211
01212 void OThemeStyle::drawSplitter( QPainter *p, int x, int y, int w, int h,
01213 const QColorGroup &g, Orientation )
01214 {
01215 drawBaseButton( p, x, y, w, h, *colorGroup( g, Splitter ), false, false,
01216 Splitter );
01217 }
01218
01219 void OThemeStyle::drawCheckMark( QPainter *p, int x, int y, int w, int h,
01220 const QColorGroup &g, bool act, bool dis )
01221 {
01222 if ( isPixmap( CheckMark ) ) {
01223 if ( !dis )
01224 p->drawPixmap( x + ( w - uncached( CheckMark ) ->width() ) / 2,
01225 y + ( h - uncached( CheckMark ) ->height() ) / 2,
01226 *uncached( CheckMark ) );
01227 }
01228 else
01229 QWindowsStyle::drawCheckMark( p, x, y, w, h, *colorGroup( g, CheckMark ),
01230 act, dis );
01231 }
01232
01233 int OThemeStyle::popupMenuItemHeight( bool , QMenuItem *mi,
01234 const QFontMetrics &fm )
01235 {
01236 int h2, h = 0;
01237 int offset = QMAX( decoWidth( MenuItemDown ), decoWidth( MenuItem ) ) + 4;
01238
01239 if ( mi->isSeparator() )
01240 return ( 2 );
01241 if ( mi->isChecked() )
01242 h = isPixmap( CheckMark ) ? uncached( CheckMark ) ->height() + offset :
01243 offset + 16;
01244 if ( mi->pixmap() ) {
01245 h2 = mi->pixmap() ->height() + offset;
01246 h = h2 > h ? h2 : h;
01247 }
01248 if ( mi->iconSet() ) {
01249 h2 = mi->iconSet() ->pixmap().height() + offset;
01250 h = h2 > h ? h2 : h;
01251 }
01252 h2 = fm.height() + offset;
01253 h = h2 > h ? h2 : h;
01254 return ( h );
01255 }
01256
01257 void OThemeStyle::drawPopupMenuItem( QPainter* p, bool checkable, int maxpmw,
01258 int tab, QMenuItem* mi,
01259 const QPalette& pal, bool act,
01260 bool enabled, int x, int y, int w, int h )
01261 {
01262
01263
01264 static const int motifItemFrame = 2;
01265 static const int motifItemHMargin = 5;
01266 static const int motifItemVMargin = 4;
01267
01268 static const int motifArrowHMargin = 6;
01269 static const int windowsRightBorder = 12;
01270 bool dis = !enabled;
01271 const QColorGroup &g = dis ? *colorGroup( pal.normal(), MenuItem ) :
01272 *colorGroup( pal.normal(), MenuItemDown );
01273
01274 QColorGroup itemg = dis ? *colorGroup( pal.disabled(), MenuItem )
01275 : act ? *colorGroup( pal.active(), MenuItemDown )
01276 : *colorGroup( pal.normal(), MenuItem );
01277
01278 maxpmw = QMAX( maxpmw, 20 );
01279 int checkcol = maxpmw;
01280
01281 if ( mi && mi->isSeparator() ) {
01282 p->setPen( g.dark() );
01283 p->drawLine( x, y, x + w, y );
01284 p->setPen( g.light() );
01285 p->drawLine( x, y + 1, x + w, y + 1 );
01286 return ;
01287 }
01288 if ( act ) {
01289 drawBaseButton( p, x, y, w, h, g, true, false, MenuItemDown );
01290 }
01291 else {
01292 drawShade( p, x, y, w, h, *colorGroup( g, MenuItem ), false, false,
01293 highlightWidth( MenuItem ), borderWidth( MenuItem ),
01294 shade() );
01295 int dw = decoWidth( MenuItem );
01296 if ( !isPixmap( MenuItem ) ) {
01297 p->fillRect( x + dw, y + dw, w - dw * 2, h - dw * 2,
01298 colorGroup( g, MenuItem ) ->
01299 brush( QColorGroup::Background ) );
01300 }
01301 else {
01302
01303 p->drawTiledPixmap( x + dw, y + dw, w - dw * 2, h - dw * 2, *scalePixmap
01304 (w, ((QWidget *)p->device())->height(), MenuItem),
01305
01306 x, y );
01307 }
01308
01309 if ( checkable && mi && mi->isChecked() ) {
01310
01311
01312
01313
01314
01315 int mw = checkcol + motifItemFrame;
01316 drawShade( p, x, y, mw, h, g, true, false,
01317 highlightWidth( MenuItemDown ),
01318 borderWidth( MenuItemDown ), shade() );
01319 }
01320 }
01321 if ( !mi )
01322 return ;
01323 if ( mi->iconSet() ) {
01324 QIconSet::Mode mode = dis ? QIconSet::Disabled : QIconSet::Normal;
01325 if ( act && !dis )
01326 mode = QIconSet::Active;
01327 QPixmap pixmap;
01328 if ( mode == QIconSet::Disabled )
01329 pixmap = mi->iconSet()->pixmap( QIconSet::Automatic, mode );
01330 else
01331 pixmap = mi->iconSet()->pixmap();
01332 int pixw = pixmap.width();
01333 int pixh = pixmap.height();
01334 QRect cr( x, y, checkcol, h );
01335 QRect pmr( 0, 0, pixw, pixh );
01336 pmr.moveCenter( cr.center() );
01337 p->setPen( itemg.text() );
01338 p->drawPixmap( pmr.topLeft(), pixmap );
01339
01340 }
01341 else if ( checkable ) {
01342 int mw = checkcol + motifItemFrame;
01343 int mh = h - 2 * motifItemFrame;
01344 if ( mi->isChecked() ) {
01345 drawCheckMark( p, x + motifItemFrame,
01346 y + motifItemFrame, mw, mh, itemg, act, dis );
01347 }
01348 }
01349
01350 p->setPen( colorGroup( g, act ? MenuItemDown : MenuItem ) ->text() );
01351
01352 QColor discol;
01353 if ( dis ) {
01354 discol = itemg.text();
01355 p->setPen( discol );
01356 }
01357
01358 int xm = motifItemFrame + checkcol + motifItemHMargin;
01359
01360 QString s = mi->text();
01361 if ( !s.isNull() ) {
01362 int t = s.find( '\t' );
01363 int m = motifItemVMargin;
01364 const int text_flags = AlignVCenter | ShowPrefix | DontClip | SingleLine;
01365 if ( t >= 0 ) {
01366 if ( dis && !act ) {
01367 p->setPen( g.light() );
01368 p->drawText( x + w - tab - windowsRightBorder - motifItemHMargin - motifItemFrame + 1,
01369 y + m + 1, tab, h - 2 * m, text_flags, s.mid( t + 1 ) );
01370 p->setPen( discol );
01371 }
01372 p->drawText( x + w - tab - windowsRightBorder - motifItemHMargin - motifItemFrame,
01373 y + m, tab, h - 2 * m, text_flags, s.mid( t + 1 ) );
01374 }
01375 if ( dis && !act ) {
01376 p->setPen( g.light() );
01377 p->drawText( x + xm + 1, y + m + 1, w - xm + 1, h - 2 * m, text_flags, s, t );
01378 p->setPen( discol );
01379 }
01380 p->drawText( x + xm, y + m, w - xm - tab + 1, h - 2 * m, text_flags, s, t );
01381 }
01382 else if ( mi->pixmap() ) {
01383 QPixmap * pixmap = mi->pixmap();
01384 if ( pixmap->depth() == 1 )
01385 p->setBackgroundMode( OpaqueMode );
01386 p->drawPixmap( x + xm, y + motifItemFrame, *pixmap );
01387 if ( pixmap->depth() == 1 )
01388 p->setBackgroundMode( TransparentMode );
01389 }
01390 if ( mi->popup() ) {
01391 int dim = ( h - 2 * motifItemFrame ) / 2;
01392 if ( act ) {
01393 if ( !dis )
01394 discol = colorGroup( g, MenuItemDown ) ->text();
01395
01396 QColorGroup g2( discol, g.highlight(),
01397 white, white,
01398 dis ? discol : white,
01399 discol, white );
01400 drawArrow( p, RightArrow, true,
01401 x + w - motifArrowHMargin - motifItemFrame - dim, y + h / 2 - dim / 2,
01402 dim, dim, g2, TRUE );
01403 }
01404 else {
01405 drawArrow( p, RightArrow,
01406 false,
01407 x + w - motifArrowHMargin - motifItemFrame - dim, y + h / 2 - dim / 2,
01408 dim, dim, g, mi->isEnabled() );
01409 }
01410 }
01411 }
01412
01413 void OThemeStyle::drawFocusRect( QPainter *p, const QRect &r,
01414 const QColorGroup &g, const QColor *c,
01415 bool atBorder )
01416 {
01417 p->setPen( g.dark() );
01418 if ( !is3DFocus() )
01419 QWindowsStyle::drawFocusRect( p, r, g, c, atBorder );
01420 else {
01421 int i = focusOffset();
01422 p->drawLine( r.x() + i, r.y() + 1 + i, r.x() + i, r.bottom() - 1 - i );
01423 p->drawLine( r.x() + 1 + i, r.y() + i, r.right() - 1 - i, r.y() + i );
01424 p->setPen( g.light() );
01425 p->drawLine( r.right() - i, r.y() + 1 + i, r.right() - i, r.bottom() - 1 - i );
01426 p->drawLine( r.x() + 1 + i, r.bottom() - i, r.right() - 1 - i, r.bottom() - i );
01427 }
01428 }
01429
01430 #if 0
01431 void OThemeStyle::drawKMenuBar( QPainter *p, int x, int y, int w, int h,
01432 const QColorGroup &g, bool, QBrush * )
01433 {
01434 drawBaseButton( p, x, y, w, h, *colorGroup( g, MenuBar ), false, false,
01435 MenuBar );
01436 }
01437 #endif
01438
01439 void OThemeStyle::drawMenuBarItem( QPainter *p, int x, int y, int w, int h,
01440 QMenuItem *mi, const QColorGroup &g,
01441 bool , bool active )
01442 {
01443 if(active){
01444 x -= 2;
01445 y -= 2;
01446 w += 2;
01447 h += 2;
01448 }
01449
01450 const QColorGroup * cg = colorGroup( g, active ? MenuBarItem : MenuBar );
01451 QColor btext = cg->buttonText();
01452 if ( active )
01453 drawBaseButton( p, x, y, w, h, *cg, false, false, MenuBarItem );
01454
01455
01456 drawItem( p, x, y, w, h, AlignCenter | ShowPrefix | DontClip | SingleLine,
01457 *cg, mi-> isEnabled ( ), mi->pixmap(), mi->text(),
01458 -1, &btext );
01459 }
01460
01461
01462
01463 void OThemeStyle::drawProgressBar ( QPainter *p, int x, int y, int w, int h, const QColorGroup &g, int percent )
01464 {
01465 const QColorGroup * cg = colorGroup( g, ProgressBg );
01466 QBrush bg;
01467 bg.setColor( cg->color( QColorGroup::Background ) );
01468 if ( isPixmap( ProgressBg ) )
01469 bg.setPixmap( *uncached( ProgressBg ) );
01470
01471 int pw = w * percent / 100;
01472
01473 p-> fillRect ( x + pw, y, w - pw, h, bg );
01474
01475 drawBaseButton( p, x, y, pw, h, *cg, false, false, ProgressBar );
01476 }
01477
01478 #if 0
01479
01480 void OThemeStyle::drawKProgressBlock( QPainter *p, int x, int y, int w, int h,
01481 const QColorGroup &g, QBrush * )
01482 {
01483 drawBaseButton( p, x, y, w, h, *colorGroup( g, ProgressBar ), false, false,
01484 ProgressBar );
01485 }
01486
01487 void OThemeStyle::getKProgressBackground( const QColorGroup &g, QBrush &bg )
01488 {
01489 const QColorGroup * cg = colorGroup( g, ProgressBg );
01490 bg.setColor( cg->color( QColorGroup::Background ) );
01491 if ( isPixmap( ProgressBg ) )
01492 bg.setPixmap( *uncached( ProgressBg ) );
01493 }
01494 #endif
01495
01496 void OThemeStyle::tabbarMetrics( const QTabBar* t, int& hframe, int& vframe, int& overlap )
01497 {
01498 QCommonStyle::tabbarMetrics( t, hframe, vframe, overlap );
01499 }
01500
01501 void OThemeStyle::drawTab( QPainter* p, const QTabBar* tb, QTab* t ,
01502 bool selected )
01503 {
01504 WidgetType widget = selected ? ActiveTab : InactiveTab;
01505 const QColorGroup *cg = colorGroup( tb->colorGroup(), widget );
01506 int i;
01507 int x = t->r.x(), y = t->r.y();
01508 int x2 = t->r.right(), y2 = t->r.bottom();
01509 int bWidth = borderWidth( widget );
01510 int hWidth = highlightWidth( widget );
01511 if ( tb->shape() == QTabBar::RoundedAbove ) {
01512 if ( !selected ) {
01513 p->fillRect( x, y, x2 - x + 1, 2,
01514 tb->palette().normal().brush( QColorGroup::Background ) );
01515 y += 2;
01516 }
01517 p->setPen( cg->text() );
01518 i = 0;
01519 if ( i < bWidth ) {
01520 p->drawLine( x, y + 1, x, y2 );
01521 p->drawLine( x2, y + 1, x2, y2 );
01522 p->drawLine( x + 1, y, x2 - 1, y );
01523 if ( selected ? activeTabLine() : inactiveTabLine() ) {
01524 p->drawLine( x, y2, x2, y2 );
01525 --y2;
01526 }
01527 ++i, ++x, ++y, --x2;
01528 }
01529 for ( ; i < bWidth; ++i, ++x, ++y, --x2 ) {
01530 p->drawLine( x, y, x, y2 );
01531 p->drawLine( x2, y, x2, y2 );
01532 p->drawLine( x, y, x2, y );
01533 if ( selected ? activeTabLine() : inactiveTabLine() ) {
01534 p->drawLine( x, y2, x2, y2 );
01535 --y2;
01536 }
01537 }
01538 i = 0;
01539 if ( i < hWidth && bWidth == 0 ) {
01540 p->setPen( cg->light() );
01541 p->drawLine( x, y + 1, x, y2 );
01542 p->drawLine( x + 1, y, x2 - 1, y );
01543 p->setPen( cg->dark() );
01544 p->drawLine( x2, y + 1, x2, y2 );
01545 if ( selected ? activeTabLine() : inactiveTabLine() ) {
01546 p->drawLine( x, y2, x2, y2 );
01547 --y2;
01548 }
01549 ++i, ++x, ++y, --x2;
01550 }
01551 for ( ; i < hWidth; ++i, ++x, ++y, --x2 ) {
01552 p->setPen( cg->light() );
01553 p->drawLine( x, y, x, y2 );
01554 p->drawLine( x, y, x2, y );
01555 p->setPen( cg->dark() );
01556 p->drawLine( x2, y + 1, x2, y2 );
01557 if ( selected ? activeTabLine() : inactiveTabLine() ) {
01558 p->drawLine( x, y2, x2, y2 );
01559 --y2;
01560 }
01561 }
01562 if ( isPixmap( widget ) )
01563 p->drawTiledPixmap( x, y, x2 - x + 1, y2 - y + 1,
01564 *scalePixmap( x2 - x + 1, y2 - y + 1, widget ) );
01565 else
01566 p->fillRect( x, y, x2 - x + 1, y2 - y + 1, cg->background() );
01567 }
01568 else if ( tb->shape() == QTabBar::RoundedBelow ) {
01569 if ( !selected ) {
01570 p->fillRect( x, y2 - 2, x2 - x + 1, 2,
01571 tb->palette().normal().brush( QColorGroup::Background ) );
01572 y2 -= 2;
01573 }
01574 p->setPen( cg->text() );
01575 i = 0;
01576 if ( i < bWidth ) {
01577 p->drawLine( x, y, x, y2 - 1 );
01578 p->drawLine( x2, y, x2, y2 - 1 );
01579 p->drawLine( x + 1, y2, x2 - 1, y2 );
01580 if ( selected ? activeTabLine() : inactiveTabLine() ) {
01581 p->drawLine( x, y, x2, y );
01582 ++y;
01583 }
01584 }
01585 for ( ; i < bWidth; ++i, ++x, --x2, --y2 ) {
01586 p->drawLine( x, y, x, y2 );
01587 p->drawLine( x2, y, x2, y2 );
01588 p->drawLine( x, y2, x2, y2 );
01589 if ( selected ? activeTabLine() : inactiveTabLine() ) {
01590 p->drawLine( x, y, x2, y );
01591 ++y;
01592 }
01593 }
01594 i = 0;
01595 if ( i < hWidth && bWidth == 0 ) {
01596 p->setPen( cg->dark() );
01597 p->drawLine( x + 1, y2, x2 - 1, y2 );
01598 p->drawLine( x2, y, x2, y2 - 1 );
01599 p->setPen( cg->light() );
01600 p->drawLine( x, y, x, y2 - 1 );
01601 if ( selected ? activeTabLine() : inactiveTabLine() ) {
01602 p->drawLine( x, y, x2, y );
01603 ++y;
01604 }
01605 ++i, ++x, --x2, --y2;
01606 }
01607 for ( ; i < hWidth; ++i, ++x, --x2, --y2 ) {
01608 p->setPen( cg->dark() );
01609 p->drawLine( x, y2, x2, y2 );
01610 p->drawLine( x2, y, x2, y2 );
01611 p->setPen( cg->light() );
01612 p->drawLine( x, y, x, y2 );
01613 if ( selected ? activeTabLine() : inactiveTabLine() ) {
01614 p->drawLine( x, y, x2, y );
01615 ++y;
01616 }
01617 }
01618 if ( isPixmap( widget ) )
01619 p->drawTiledPixmap( x, y, x2 - x + 1, y2 - y + 1,
01620 *scalePixmap( x2 - x + 1, y2 - y + 1, widget ) );
01621 else
01622 p->fillRect( x, y, x2 - x + 1, y2 - y + 1, cg->background() );
01623 }
01624 else
01625 QCommonStyle::drawTab( p, tb, t, selected );
01626 }
01627
01628 void OThemeStyle::drawTabMask( QPainter* p, const QTabBar* tb, QTab* t,
01629 bool selected )
01630 {
01631 QRect r( t->r );
01632
01633 if ( tb->shape() == QTabBar::RoundedAbove ) {
01634 if ( !selected )
01635 r.setTop( r.top() + 2 );
01636 p->drawLine( r.left() + 1, r.top(), r.right() - 1, r.top() );
01637 QBrush b( color1, SolidPattern );
01638 p->fillRect( r.left(), r.top() + 1, r.width(), r.height() - 1, b );
01639 }
01640 else if ( tb->shape() == QTabBar::RoundedBelow ) {
01641 if ( !selected )
01642 r.setBottom( r.bottom() - 2 );
01643 p->drawLine( r.left() + 1, r.bottom(), r.right() - 1, r.bottom() );
01644 QBrush b( color1, SolidPattern );
01645 p->fillRect( r.left(), r.top(), r.width(), r.height() - 1, b );
01646 }
01647 else
01648 QCommonStyle::drawTabMask( p, tb, t, selected );
01649
01650 }
01651
01652
01653
01654