00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "qpestyle.h"
00022
00023
00024 #define QCOORDARRLEN(x) sizeof(x)/(sizeof(QCOORD)*2)
00025
00026 #if QT_VERSION >= 0x030000
00027
00028 #include <qdrawutil.h>
00029 #include <qcombobox.h>
00030 #include <qtabbar.h>
00031
00032 QPEStyle::QPEStyle()
00033 {
00034 }
00035
00036 QPEStyle::~QPEStyle()
00037 {
00038 }
00039
00040 void QPEStyle::drawPrimitive( PrimitiveElement pe, QPainter *p, const QRect &r,
00041 const QColorGroup &cg, SFlags flags, const QStyleOption &data) const
00042 {
00043 switch ( pe ) {
00044 case PE_ButtonTool:
00045 {
00046 QColorGroup mycg = cg;
00047 if ( flags & Style_On ) {
00048 QBrush fill( cg.mid(), Dense4Pattern );
00049 mycg.setBrush( QColorGroup::Button, fill );
00050 }
00051 drawPrimitive( PE_ButtonBevel, p, r, mycg, flags, data );
00052 break;
00053 }
00054 case PE_ButtonCommand:
00055 case PE_ButtonDefault:
00056 case PE_ButtonBevel:
00057 case PE_HeaderSection:
00058 {
00059 QPen oldPen = p->pen();
00060 p->fillRect( r.x()+1, r.y()+1, r.width()-2, r.height()-2, cg.brush(QColorGroup::Button) );
00061
00062 int x2 = r.right();
00063 int y2 = r.bottom();
00064
00065 if ( flags & (Style_Sunken | Style_Down | Style_On) )
00066 p->setPen( cg.dark() );
00067 else
00068 p->setPen( cg.light() );
00069 p->drawLine( r.x(), r.y()+1, r.x(), y2-1 );
00070 p->drawLine( r.x()+1, r.y(), x2-1, r.y() );
00071
00072 if ( flags & (Style_Sunken | Style_Down | Style_On) )
00073 p->setPen( cg.light() );
00074 else
00075 p->setPen( cg.dark() );
00076 p->drawLine( x2, r.y()+1, x2, y2-1 );
00077 p->drawLine( r.x()+1, y2, x2-1, y2 );
00078 p->setPen( oldPen );
00079 break;
00080 }
00081 case PE_FocusRect:
00082 break;
00083 case PE_Indicator:
00084 {
00085 QColorGroup mycg( cg );
00086 QBrush fill;
00087 if ( flags & Style_Down )
00088 fill = cg.brush( QColorGroup::Button );
00089 else
00090 fill = cg.brush( (flags&Style_Enabled) ? QColorGroup::Base : QColorGroup::Background );
00091 mycg.setBrush( QColorGroup::Button, fill );
00092 if ( flags&Style_Enabled )
00093 flags |= Style_Sunken;
00094 drawPrimitive( PE_ButtonBevel, p, r, mycg, flags );
00095 if ( flags & Style_On ) {
00096 QPointArray a( 7*2 );
00097 int i, xx, yy;
00098 xx = r.x()+3;
00099 yy = r.y()+5;
00100 for ( i=0; i<3; i++ ) {
00101 a.setPoint( 2*i, xx, yy );
00102 a.setPoint( 2*i+1, xx, yy+2 );
00103 xx++; yy++;
00104 }
00105 yy -= 2;
00106 for ( i=3; i<7; i++ ) {
00107 a.setPoint( 2*i, xx, yy );
00108 a.setPoint( 2*i+1, xx, yy+2 );
00109 xx++; yy--;
00110 }
00111 if ( flags & Style_NoChange ) {
00112 p->setPen( mycg.dark() );
00113 } else {
00114 p->setPen( mycg.text() );
00115 }
00116 p->drawLineSegments( a );
00117 }
00118 break;
00119 }
00120 case PE_ExclusiveIndicator:
00121 {
00122 static const QCOORD pts1[] = {
00123 1,9, 1,8, 0,7, 0,4, 1,3, 1,2, 2,1, 3,1, 4,0, 7,0, 8,1, 9,1 };
00124 static const QCOORD pts4[] = {
00125 2,10, 3,10, 4,11, 7,11, 8,10, 9,10, 10,9, 10,8, 11,7,
00126 11,4, 10,3, 10,2 };
00127 static const QCOORD pts5[] = {
00128 4,2, 7,2, 9,4, 9,7, 7,9, 4,9, 2,7, 2,4 };
00129
00130 int x, y, w, h;
00131 r.rect( &x, &y, &w, &h );
00132 p->eraseRect( x, y, w, h );
00133 QPointArray a( QCOORDARRLEN(pts1), pts1 );
00134 a.translate( x, y );
00135 p->setPen( cg.dark() );
00136 p->drawPolyline( a );
00137 a.setPoints( QCOORDARRLEN(pts4), pts4 );
00138 a.translate( x, y );
00139 p->setPen( cg.light() );
00140 p->drawPolyline( a );
00141 a.setPoints( QCOORDARRLEN(pts5), pts5 );
00142 a.translate( x, y );
00143 QColor fillColor = ( flags&Style_Down || !(flags&Style_Enabled) ) ? cg.button() : cg.base();
00144 p->setPen( fillColor );
00145 p->setBrush( fillColor ) ;
00146 p->drawPolygon( a );
00147 if ( flags&Style_On ) {
00148 p->setPen( NoPen );
00149 p->setBrush( cg.text() );
00150 p->drawRect( x+5, y+4, 2, 4 );
00151 p->drawRect( x+4, y+5, 4, 2 );
00152 }
00153 break;
00154 }
00155 default:
00156 QWindowsStyle::drawPrimitive( pe, p, r, cg, flags, data );
00157 break;
00158 }
00159 }
00160
00161 void QPEStyle::drawControl( ControlElement ce, QPainter *p,
00162 const QWidget *widget, const QRect &r,
00163 const QColorGroup &cg, SFlags how, const QStyleOption &data) const
00164 {
00165 switch ( ce ) {
00166 case CE_PushButton:
00167 {
00168 const QPushButton *btn = (QPushButton*)widget;
00169 SFlags flags;
00170 flags = Style_Default;
00171 if ( btn->isDown() )
00172 flags |= Style_Down;
00173 if ( btn->isOn() )
00174 flags |= Style_On;
00175 if ( btn->isEnabled() )
00176 flags |= Style_Enabled;
00177 if ( btn->isDefault() )
00178 flags |= Style_Default;
00179 if (! btn->isFlat() && !(flags & Style_Down))
00180 flags |= Style_Raised;
00181 p->setPen( cg.foreground() );
00182 p->setBrush( QBrush(cg.button(), NoBrush) );
00183 QColorGroup mycg( cg );
00184 if ( flags & Style_On ) {
00185 QBrush fill = QBrush( cg.mid(), Dense4Pattern );
00186 mycg.setBrush( QColorGroup::Button, fill );
00187 }
00188 drawPrimitive( PE_ButtonBevel, p, r, mycg, flags, data );
00189 break;
00190 }
00191 case CE_TabBarTab:
00192 {
00193 if ( !widget || !widget->parentWidget() )
00194 break;
00195
00196 const QTabBar *tb = (const QTabBar *) widget;
00197 bool selected = how & Style_Selected;
00198
00199 QRect r2(r);
00200 if ( tb->shape() == QTabBar::RoundedAbove ) {
00201 p->setPen( cg.light() );
00202 p->drawLine( r2.left(), r2.bottom(), r2.right(), r2.bottom() );
00203 if ( r2.left() == 0 )
00204 p->drawPoint( tb->rect().bottomLeft() );
00205 else {
00206 p->setPen( cg.light() );
00207 p->drawLine( r2.left(), r2.bottom(), r2.right(), r2.bottom() );
00208 }
00209
00210 if ( selected ) {
00211 p->setPen( cg.background() );
00212 p->drawLine( r2.left()+2, r2.top()+1, r2.right()-2, r2.top()+1 );
00213 p->fillRect( QRect( r2.left()+1, r2.top()+2, r2.width()-2, r2.height()-2),
00214 cg.brush( QColorGroup::Background ));
00215 } else {
00216 r2.setRect( r2.left() + 2, r2.top() + 2,
00217 r2.width() - 4, r2.height() - 2 );
00218 p->setPen( cg.button() );
00219 p->drawLine( r2.left()+2, r2.top()+1, r2.right()-2, r2.top()+1 );
00220 p->fillRect( QRect( r2.left()+1, r2.top()+2, r2.width()-2, r2.height()-3),
00221 cg.brush( QColorGroup::Button ));
00222
00223
00224 QColor bg = cg.button();
00225
00226
00227 int n = r2.height()/2;
00228 int dark = 100;
00229 for ( int i = 1; i < n; i++ ) {
00230 dark = (dark * (100+(i*15)/n) )/100;
00231 p->setPen( bg.dark( dark ) );
00232 int y = r2.bottom()-n+i;
00233 int x1 = r2.left()+1;
00234 int x2 = r2.right()-1;
00235 p->drawLine( x1, y, x2, y );
00236 }
00237 }
00238
00239 p->setPen( cg.light() );
00240 p->drawLine( r2.left(), r2.bottom()-1, r2.left(), r2.top() + 2 );
00241 p->drawPoint( r2.left()+1, r2.top() + 1 );
00242 p->drawLine( r2.left()+2, r2.top(),
00243 r2.right() - 2, r2.top() );
00244
00245 p->setPen( cg.dark() );
00246 p->drawPoint( r2.right() - 1, r2.top() + 1 );
00247 p->drawLine( r2.right(), r2.top() + 2, r2.right(), r2.bottom() - 1);
00248 } else if ( tb->shape() == QTabBar::RoundedBelow ) {
00249 if ( selected ) {
00250 p->setPen( cg.background() );
00251 p->drawLine( r2.left()+2, r2.bottom()-1, r2.right()-2, r2.bottom()-1 );
00252 p->fillRect( QRect( r2.left()+1, r2.top(), r2.width()-2, r2.height()-2),
00253 tb->palette().normal().brush( QColorGroup::Background ));
00254 } else {
00255 p->setPen( cg.dark() );
00256 p->drawLine( r2.left(), r2.top(),
00257 r2.right(), r2.top() );
00258 r2.setRect( r2.left() + 2, r2.top(),
00259 r2.width() - 4, r2.height() - 2 );
00260 p->setPen( cg.button() );
00261 p->drawLine( r2.left()+2, r2.bottom()-1, r2.right()-2, r2.bottom()-1 );
00262 p->fillRect( QRect( r2.left()+1, r2.top()+1, r2.width()-2, r2.height()-3),
00263 tb->palette().normal().brush( QColorGroup::Button ));
00264 }
00265
00266 p->setPen( cg.dark() );
00267 p->drawLine( r2.right(), r2.top(),
00268 r2.right(), r2.bottom() - 2 );
00269 p->drawPoint( r2.right() - 1, r2.bottom() - 1 );
00270 p->drawLine( r2.right() - 2, r2.bottom(),
00271 r2.left() + 2, r2.bottom() );
00272
00273 p->setPen( cg.light() );
00274 p->drawLine( r2.left(), r2.top()+1,
00275 r2.left(), r2.bottom() - 2 );
00276 p->drawPoint( r2.left() + 1, r2.bottom() - 1 );
00277 if ( r2.left() == 0 )
00278 p->drawPoint( tb->rect().topLeft() );
00279
00280 } else {
00281 QCommonStyle::drawControl( ce, p, widget, r, cg, how, data );
00282 }
00283 break;
00284 }
00285 default:
00286 QWindowsStyle::drawControl( ce, p, widget, r, cg, how, data );
00287 break;
00288 }
00289 }
00290
00291 void QPEStyle::drawComplexControl( ComplexControl control, QPainter *p,
00292 const QWidget *widget, const QRect &r,
00293 const QColorGroup &cg, SFlags how,
00294 SCFlags sub, SCFlags subActive, const QStyleOption &data) const
00295 {
00296 switch ( control ) {
00297 case CC_ComboBox:
00298 if ( sub & SC_ComboBoxArrow ) {
00299 SFlags flags = Style_Default;
00300
00301 drawPrimitive( PE_ButtonBevel, p, r, cg, flags, data );
00302
00303 QRect ar =
00304 QStyle::visualRect( querySubControlMetrics( CC_ComboBox, widget,
00305 SC_ComboBoxArrow ), widget );
00306
00307 if ( subActive == SC_ComboBoxArrow ) {
00308 p->setPen( cg.dark() );
00309 p->setBrush( cg.brush( QColorGroup::Button ) );
00310 p->drawRect( ar );
00311 }
00312
00313 ar.addCoords( 2, 2, -2, -2 );
00314 if ( widget->isEnabled() )
00315 flags |= Style_Enabled;
00316
00317 if ( subActive & Style_Sunken ) {
00318 flags |= Style_Sunken;
00319 }
00320 drawPrimitive( PE_ArrowDown, p, ar, cg, flags );
00321 }
00322
00323 if ( sub & SC_ComboBoxEditField ) {
00324 const QComboBox * cb = (const QComboBox *) widget;
00325 QRect re =
00326 QStyle::visualRect( querySubControlMetrics( CC_ComboBox, widget,
00327 SC_ComboBoxEditField ), widget );
00328 if ( cb->hasFocus() && !cb->editable() )
00329 p->fillRect( re.x(), re.y(), re.width(), re.height(),
00330 cg.brush( QColorGroup::Highlight ) );
00331
00332 if ( cb->hasFocus() ) {
00333 p->setPen( cg.highlightedText() );
00334 p->setBackgroundColor( cg.highlight() );
00335
00336 } else {
00337 p->setPen( cg.text() );
00338 p->setBackgroundColor( cg.background() );
00339 }
00340
00341 if ( cb->hasFocus() && !cb->editable() ) {
00342 QRect re =
00343 QStyle::visualRect( subRect( SR_ComboBoxFocusRect, cb ), widget );
00344 drawPrimitive( PE_FocusRect, p, re, cg, Style_FocusAtBorder, QStyleOption(cg.highlight()));
00345 }
00346 }
00347 break;
00348 default:
00349 QWindowsStyle::drawComplexControl( control, p, widget, r, cg, how,
00350 sub, subActive, data );
00351 break;
00352 }
00353 }
00354
00355 int QPEStyle::pixelMetric( PixelMetric metric, const QWidget *widget ) const
00356 {
00357 int ret;
00358 switch( metric ) {
00359 case PM_ButtonMargin:
00360 ret = 2;
00361 break;
00362 case PM_DefaultFrameWidth:
00363 ret = 1;
00364 break;
00365 case PM_ButtonDefaultIndicator:
00366 ret = 2;
00367 break;
00368 case PM_ButtonShiftHorizontal:
00369 case PM_ButtonShiftVertical:
00370 ret = -1;
00371 break;
00372 case PM_IndicatorWidth:
00373 ret = 15;
00374 break;
00375 case PM_IndicatorHeight:
00376 ret = 13;
00377 break;
00378 case PM_ExclusiveIndicatorHeight:
00379 case PM_ExclusiveIndicatorWidth:
00380 ret = 15;
00381 break;
00382 case PM_ScrollBarExtent:
00383 ret = 13;
00384 break;
00385 case PM_SliderLength:
00386 ret = 12;
00387 break;
00388 default:
00389 ret = QWindowsStyle::pixelMetric( metric, widget );
00390 break;
00391 }
00392 return ret;
00393 }
00394
00395 QSize QPEStyle::sizeFromContents( ContentsType contents, const QWidget *widget,
00396 const QSize &contentsSize, const QStyleOption &data) const
00397 {
00398 QSize sz(contentsSize);
00399
00400 switch ( contents ) {
00401 case CT_PopupMenuItem:
00402 {
00403 if ( !widget || data.isDefault() )
00404 break;
00405 sz = QWindowsStyle::sizeFromContents( contents, widget, contentsSize, data );
00406 sz = QSize( sz.width(), sz.height()-2 );
00407 break;
00408 }
00409 default:
00410 sz = QWindowsStyle::sizeFromContents( contents, widget, contentsSize, data );
00411 break;
00412 }
00413
00414 return sz;
00415 }
00416
00417 #else
00418
00419 #include <qfontmetrics.h>
00420 #include <qpalette.h>
00421 #include <qdrawutil.h>
00422 #include <qscrollbar.h>
00423 #include <qbutton.h>
00424 #include <qframe.h>
00425 #include <qtabbar.h>
00426
00427 #define INCLUDE_MENUITEM_DEF
00428 #include <qmenudata.h>
00429
00430 QPEStyle::QPEStyle()
00431 {
00432 #if QT_VERSION < 0x030000
00433 setButtonMargin(buttonMargin());
00434 setScrollBarExtent(scrollBarExtent().width(),scrollBarExtent().height());
00435 #endif
00436 }
00437
00438 QPEStyle::~QPEStyle()
00439 {
00440 }
00441
00442 int QPEStyle::buttonMargin() const
00443 {
00444 return 2;
00445 }
00446
00447 QSize QPEStyle::scrollBarExtent() const
00448 {
00449 return QSize(13,13);
00450 }
00451
00452 void QPEStyle::polish ( QPalette & )
00453 {
00454 }
00455
00456 void QPEStyle::polish( QWidget *w )
00457 {
00458 if ( w->inherits( "QListBox" ) ||
00459 w->inherits( "QListView" ) ||
00460 w->inherits( "QPopupMenu" ) ||
00461 w->inherits( "QSpinBox" ) ) {
00462 QFrame *f = (QFrame *)w;
00463 f->setFrameShape( QFrame::StyledPanel );
00464 f->setLineWidth( 1 );
00465 }
00466 }
00467
00468 void QPEStyle::unPolish( QWidget *w )
00469 {
00470 if ( w->inherits( "QListBox" ) ||
00471 w->inherits( "QListView" ) ||
00472 w->inherits( "QPopupMenu" ) ||
00473 w->inherits( "QSpinBox" ) ) {
00474 QFrame *f = (QFrame *)w;
00475 f->setFrameShape( QFrame::StyledPanel );
00476 f->setLineWidth( 2 );
00477 }
00478 }
00479
00480 int QPEStyle::defaultFrameWidth() const
00481 {
00482 return 1;
00483 }
00484
00485 void QPEStyle::drawPanel ( QPainter * p, int x, int y, int w, int h,
00486 const QColorGroup &g, bool sunken, int lineWidth, const QBrush * fill )
00487 {
00488 qDrawShadePanel( p, QRect(x, y, w, h), g, sunken, lineWidth, fill );
00489 }
00490
00491 void QPEStyle::drawButton( QPainter *p, int x, int y, int w, int h,
00492 const QColorGroup &g, bool sunken, const QBrush* fill )
00493 {
00494 QPen oldPen = p->pen();
00495 if ( sunken )
00496 p->setPen( g.dark() );
00497 else
00498 p->setPen( g.light() );
00499
00500 int x2 = x+w-1;
00501 int y2 = y+h-1;
00502
00503 p->drawLine( x, y, x, y2 );
00504 p->drawLine( x, y, x2, y );
00505
00506 if ( sunken )
00507 p->setPen( g.light() );
00508 else
00509 p->setPen( g.dark() );
00510
00511 p->drawLine( x2, y, x2, y2 );
00512 p->drawLine( x, y2, x2, y2 );
00513 p->setPen( oldPen );
00514
00515 p->fillRect( x+1, y+1, w-2, h-2, fill?(*fill):g.brush(QColorGroup::Button) );
00516 }
00517
00518 void QPEStyle::drawButtonMask ( QPainter * p, int x, int y, int w, int h )
00519 {
00520 p->fillRect( x, y, w, h, color1 );
00521 }
00522
00523 void QPEStyle::drawBevelButton( QPainter *p, int x, int y, int w, int h,
00524 const QColorGroup &g, bool sunken, const QBrush* fill )
00525 {
00526 drawButton( p, x, y, w, h, g, sunken, fill );
00527 }
00528
00529 QRect QPEStyle::comboButtonRect( int x, int y, int w, int h)
00530 {
00531 return QRect(x+1, y+1, w-2-14, h-2);
00532 }
00533
00534
00535 QRect QPEStyle::comboButtonFocusRect( int x, int y, int w, int h)
00536 {
00537 return QRect(x+2, y+2, w-4-14, h-4);
00538 }
00539
00540 void QPEStyle::drawComboButton( QPainter *p, int x, int y, int w, int h,
00541 const QColorGroup &g, bool sunken,
00542 bool ,
00543 bool enabled,
00544 const QBrush *fill )
00545 {
00546 drawBevelButton( p, x, y, w, h, g, FALSE, fill );
00547 drawBevelButton( p, x+w-14, y, 14, h, g, sunken, fill );
00548 drawArrow( p, QStyle::DownArrow, sunken,
00549 x+w-14+ 2, y+ 2, 14- 4, h- 4, g, enabled,
00550 &g.brush( QColorGroup::Button ) );
00551
00552 }
00553
00554
00555 void QPEStyle::drawExclusiveIndicator ( QPainter * p, int x, int y, int w,
00556 int h, const QColorGroup & g, bool on, bool down, bool enabled )
00557 {
00558 static const QCOORD pts1[] = {
00559 1,9, 1,8, 0,7, 0,4, 1,3, 1,2, 2,1, 3,1, 4,0, 7,0, 8,1, 9,1 };
00560 static const QCOORD pts4[] = {
00561 2,10, 3,10, 4,11, 7,11, 8,10, 9,10, 10,9, 10,8, 11,7,
00562 11,4, 10,3, 10,2 };
00563 static const QCOORD pts5[] = {
00564 4,2, 7,2, 9,4, 9,7, 7,9, 4,9, 2,7, 2,4 };
00565
00566 p->eraseRect( x, y, w, h );
00567 QPointArray a( QCOORDARRLEN(pts1), pts1 );
00568 a.translate( x, y );
00569 p->setPen( g.dark() );
00570 p->drawPolyline( a );
00571 a.setPoints( QCOORDARRLEN(pts4), pts4 );
00572 a.translate( x, y );
00573 p->setPen( g.light() );
00574 p->drawPolyline( a );
00575 a.setPoints( QCOORDARRLEN(pts5), pts5 );
00576 a.translate( x, y );
00577 QColor fillColor = ( down || !enabled ) ? g.button() : g.base();
00578 p->setPen( fillColor );
00579 p->setBrush( fillColor ) ;
00580 p->drawPolygon( a );
00581 if ( on ) {
00582 p->setPen( NoPen );
00583 p->setBrush( g.text() );
00584 p->drawRect( x+5, y+4, 2, 4 );
00585 p->drawRect( x+4, y+5, 4, 2 );
00586 }
00587 }
00588
00589 void QPEStyle::drawIndicator ( QPainter * p, int x, int y, int w, int h,
00590 const QColorGroup & g, int state, bool down, bool enabled )
00591 {
00592
00593 QBrush fill;
00594 if ( state == QButton::NoChange ) {
00595 QBrush b = p->brush();
00596 QColor c = p->backgroundColor();
00597 p->setBackgroundMode( TransparentMode );
00598 p->setBackgroundColor( green );
00599 fill = QBrush(g.base(), Dense4Pattern);
00600 p->setBackgroundColor( c );
00601 p->setBrush( b );
00602 } else if ( down )
00603 fill = g.brush( QColorGroup::Button );
00604 else
00605 fill = g.brush( enabled ? QColorGroup::Base : QColorGroup::Background );
00606 drawPanel( p, x, y, w, h, g, TRUE, 1, &fill );
00607 if ( state != QButton::Off ) {
00608 QPointArray a( 7*2 );
00609 int i, xx, yy;
00610 xx = x+3;
00611 yy = y+5;
00612 for ( i=0; i<3; i++ ) {
00613 a.setPoint( 2*i, xx, yy );
00614 a.setPoint( 2*i+1, xx, yy+2 );
00615 xx++; yy++;
00616 }
00617 yy -= 2;
00618 for ( i=3; i<7; i++ ) {
00619 a.setPoint( 2*i, xx, yy );
00620 a.setPoint( 2*i+1, xx, yy+2 );
00621 xx++; yy--;
00622 }
00623 if ( state == QButton::NoChange ) {
00624 p->setPen( g.dark() );
00625 } else {
00626 p->setPen( g.text() );
00627 }
00628 p->drawLineSegments( a );
00629 }
00630 }
00631
00632 #define HORIZONTAL (sb->orientation() == QScrollBar::Horizontal)
00633 #define VERTICAL !HORIZONTAL
00634 #define MOTIF_BORDER 2
00635 #define SLIDER_MIN 9 // ### motif says 6 but that's too small
00636
00639 void QPEStyle::scrollBarMetrics( const QScrollBar* sb, int &sliderMin, int &sliderMax, int &sliderLength, int& buttonDim )
00640 {
00641 int maxLength;
00642 int length = HORIZONTAL ? sb->width() : sb->height();
00643 int extent = HORIZONTAL ? sb->height() : sb->width();
00644
00645 if ( length > (extent - 1)*2 )
00646 buttonDim = extent;
00647 else
00648 buttonDim = length/2 - 1;
00649
00650 sliderMin = 0;
00651 maxLength = length - buttonDim*2;
00652
00653 if ( sb->maxValue() == sb->minValue() ) {
00654 sliderLength = maxLength;
00655 } else {
00656 sliderLength = (sb->pageStep()*maxLength)/
00657 (sb->maxValue()-sb->minValue()+sb->pageStep());
00658 uint range = sb->maxValue()-sb->minValue();
00659 if ( sliderLength < SLIDER_MIN || range > INT_MAX/2 )
00660 sliderLength = SLIDER_MIN;
00661 if ( sliderLength > maxLength )
00662 sliderLength = maxLength;
00663 }
00664
00665 sliderMax = sliderMin + maxLength - sliderLength;
00666 }
00667
00670 QStyle::ScrollControl QPEStyle::scrollBarPointOver( const QScrollBar* sb, int sliderStart, const QPoint& p )
00671 {
00672 if ( !sb->rect().contains( p ) )
00673 return NoScroll;
00674 int sliderMin, sliderMax, sliderLength, buttonDim, pos;
00675 scrollBarMetrics( sb, sliderMin, sliderMax, sliderLength, buttonDim );
00676
00677 if (sb->orientation() == QScrollBar::Horizontal)
00678 pos = p.x();
00679 else
00680 pos = p.y();
00681
00682 if (pos < sliderStart)
00683 return SubPage;
00684 if (pos < sliderStart + sliderLength)
00685 return Slider;
00686 if (pos < sliderMax + sliderLength)
00687 return AddPage;
00688 if (pos < sliderMax + sliderLength + buttonDim)
00689 return SubLine;
00690 return AddLine;
00691 }
00692
00695 void QPEStyle::drawScrollBarControls( QPainter* p, const QScrollBar* sb, int sliderStart, uint controls, uint activeControl )
00696 {
00697 #define ADD_LINE_ACTIVE ( activeControl == AddLine )
00698 #define SUB_LINE_ACTIVE ( activeControl == SubLine )
00699 QColorGroup g = sb->colorGroup();
00700
00701 int sliderMin, sliderMax, sliderLength, buttonDim;
00702 scrollBarMetrics( sb, sliderMin, sliderMax, sliderLength, buttonDim );
00703
00704 if ( controls == (AddLine | SubLine | AddPage | SubPage | Slider | First | Last ) )
00705 p->fillRect( 0, 0, sb->width(), sb->height(), g.brush( QColorGroup::Mid ));
00706
00707 if (sliderStart > sliderMax) {
00708 sliderStart = sliderMax;
00709 }
00710
00711 int dimB = buttonDim;
00712 QRect addB;
00713 QRect subB;
00714 QRect addPageR;
00715 QRect subPageR;
00716 QRect sliderR;
00717 int addX, addY, subX, subY;
00718 int length = HORIZONTAL ? sb->width() : sb->height();
00719 int extent = HORIZONTAL ? sb->height() : sb->width();
00720
00721 if ( HORIZONTAL ) {
00722 subY = addY = ( extent - dimB ) / 2;
00723 subX = length - dimB - dimB;
00724 addX = length - dimB;
00725 } else {
00726 subX = addX = ( extent - dimB ) / 2;
00727 subY = length - dimB - dimB;
00728 addY = length - dimB;
00729 }
00730
00731 int sliderEnd = sliderStart + sliderLength;
00732 int sliderW = extent;
00733 if ( HORIZONTAL ) {
00734 subB.setRect( subX,subY+1,dimB,dimB-1 );
00735 addB.setRect( addX,addY+1,dimB,dimB-1 );
00736
00737 subPageR.setRect( 0, 0,
00738 sliderStart+1, sliderW );
00739 addPageR.setRect( sliderEnd-1, 0, subX - sliderEnd+1, sliderW );
00740 sliderR .setRect( sliderStart, 1, sliderLength, sliderW-1 );
00741
00742 } else {
00743 subB.setRect( subX+1,subY,dimB-1,dimB );
00744 addB.setRect( addX+1,addY,dimB-1,dimB );
00745
00746 subPageR.setRect( 0, 0, sliderW,
00747 sliderStart+1 );
00748 addPageR.setRect( 0, sliderEnd-1, sliderW, subY - sliderEnd+1 );
00749 sliderR .setRect( 1, sliderStart, sliderW-1, sliderLength );
00750 }
00751
00752 bool maxedOut = (sb->maxValue() == sb->minValue());
00753 if ( controls & AddLine ) {
00754 drawBevelButton( p, addB.x(), addB.y(),
00755 addB.width(), addB.height(), g,
00756 ADD_LINE_ACTIVE);
00757 p->setPen(g.shadow());
00758 drawArrow( p, VERTICAL ? DownArrow : RightArrow,
00759 FALSE, addB.x()+2, addB.y()+2,
00760 addB.width()-4, addB.height()-4, g, !maxedOut,
00761 &g.brush( QColorGroup::Button ));
00762 }
00763 if ( controls & SubLine ) {
00764 drawBevelButton( p, subB.x(), subB.y(),
00765 subB.width(), subB.height(), g,
00766 SUB_LINE_ACTIVE );
00767 p->setPen(g.shadow());
00768 drawArrow( p, VERTICAL ? UpArrow : LeftArrow,
00769 FALSE, subB.x()+2, subB.y()+2,
00770 subB.width()-4, subB.height()-4, g, !maxedOut,
00771 &g.brush( QColorGroup::Button ));
00772 }
00773
00774
00775 if ( controls & SubPage )
00776 p->fillRect( subPageR.x(), subPageR.y(), subPageR.width(),
00777 subPageR.height(), g.brush( QColorGroup::Mid ));
00778 if ( controls & AddPage )
00779 p->fillRect( addPageR.x(), addPageR.y(), addPageR.width(),
00780 addPageR.height(), g.brush( QColorGroup::Mid ));
00781 if ( controls & Slider ) {
00782 QPoint bo = p->brushOrigin();
00783 p->setBrushOrigin(sliderR.topLeft());
00784 drawBevelButton( p, sliderR.x(), sliderR.y(),
00785 sliderR.width(), sliderR.height(), g,
00786 FALSE, &g.brush( QColorGroup::Button ) );
00787 p->setBrushOrigin(bo);
00788 drawRiffles( p, sliderR.x(), sliderR.y(),
00789 sliderR.width(), sliderR.height(), g, HORIZONTAL );
00790 }
00791
00792
00793 if ( sb->hasFocus() && (controls & Slider) )
00794 p->drawWinFocusRect( sliderR.x()+2, sliderR.y()+2,
00795 sliderR.width()-5, sliderR.height()-5,
00796 sb->backgroundColor() );
00797
00798 }
00799
00800 void QPEStyle::drawRiffles( QPainter* p, int x, int y, int w, int h,
00801 const QColorGroup &g, bool horizontal )
00802 {
00803 if (!horizontal) {
00804 if (h > 20) {
00805 y += (h-20)/2 ;
00806 h = 20;
00807 }
00808 if (h > 12) {
00809 int n = 3;
00810 int my = y+h/2-4;
00811 int i ;
00812 p->setPen(g.light());
00813 for (i=0; i<n; i++) {
00814 p->drawLine(x+2, my+3*i, x+w-4, my+3*i);
00815 }
00816 p->setPen(g.dark());
00817 my++;
00818 for (i=0; i<n; i++) {
00819 p->drawLine(x+2, my+3*i, x+w-4, my+3*i);
00820 }
00821 }
00822 }
00823 else {
00824 if (w > 20) {
00825 x += (w-20)/2 ;
00826 w = 20;
00827 }
00828 if (w > 12) {
00829 int n = 3;
00830 int mx = x+w/2-4;
00831 int i ;
00832 p->setPen(g.light());
00833 for (i=0; i<n; i++) {
00834 p->drawLine(mx+3*i, y+2, mx + 3*i, y+h-4);
00835 }
00836 p->setPen(g.dark());
00837 mx++;
00838 for (i=0; i<n; i++) {
00839 p->drawLine(mx+3*i, y+2, mx + 3*i, y+h-4);
00840 }
00841 }
00842 }
00843 }
00844
00845 int QPEStyle::sliderLength() const
00846 {
00847 return 12;
00848 }
00849
00850 void QPEStyle::drawSlider( QPainter *p, int x, int y, int w, int h,
00851 const QColorGroup &g, Orientation o, bool tickAbove, bool tickBelow )
00852 {
00853 int a = tickAbove ? 3 : 0;
00854 int b = tickBelow ? 3 : 0;
00855
00856 if ( o == Horizontal ) {
00857 drawBevelButton( p, x, y+a, w, h-a-b, g, FALSE, &g.brush( QColorGroup::Button ) );
00858 int xp = x + w/2;
00859 qDrawShadeLine( p, xp, y+a+2, xp, y+h-b-3, g );
00860 } else {
00861 drawBevelButton( p, x+a, y, w-a-b, h, g, FALSE, &g.brush( QColorGroup::Button ) );
00862 int yp = y + h/2;
00863 qDrawShadeLine( p, x+a+2, yp, x+w-b-3, yp, g );
00864 }
00865 }
00866
00867 void QPEStyle::drawSliderMask ( QPainter * p, int x, int y, int w, int h,
00868 Orientation o, bool tickAbove, bool tickBelow )
00869 {
00870 int a = tickAbove ? 3 : 0;
00871 int b = tickBelow ? 3 : 0;
00872 if ( o == Horizontal )
00873 p->fillRect( x, y+a, w, h-a-b, color1 );
00874 else
00875 p->fillRect( x+a, y, w-a-b, h, color1 );
00876 }
00877
00880 void QPEStyle::drawSliderGrooveMask( QPainter *p,
00881 int x, int y, int w, int h,
00882 const QColorGroup& , QCOORD c,
00883 Orientation orient )
00884 {
00885 if ( orient == Horizontal )
00886 p->fillRect( x, y + c - 2, w, 4, color1 );
00887 else
00888 p->fillRect( x + c - 2, y, 4, h, color1 );
00889 }
00890
00891 void QPEStyle::drawTab( QPainter *p, const QTabBar *tb, QTab *t, bool selected )
00892 {
00893 QRect r( t->rect() );
00894 if ( tb->shape() == QTabBar::RoundedAbove ) {
00895 p->setPen( tb->colorGroup().light() );
00896 p->drawLine( r.left(), r.bottom(), r.right(), r.bottom() );
00897 if ( r.left() == 0 )
00898 p->drawPoint( tb->rect().bottomLeft() );
00899 else {
00900 p->setPen( tb->colorGroup().light() );
00901 p->drawLine( r.left(), r.bottom(), r.right(), r.bottom() );
00902 }
00903
00904 if ( selected ) {
00905 p->setPen( tb->colorGroup().background() );
00906 p->drawLine( r.left()+2, r.top()+1, r.right()-2, r.top()+1 );
00907 p->fillRect( QRect( r.left()+1, r.top()+2, r.width()-2, r.height()-2),
00908 tb->colorGroup().brush( QColorGroup::Background ));
00909 } else {
00910 r.setRect( r.left() + 2, r.top() + 2,
00911 r.width() - 4, r.height() - 2 );
00912 p->setPen( tb->colorGroup().button() );
00913 p->drawLine( r.left()+2, r.top()+1, r.right()-2, r.top()+1 );
00914 p->fillRect( QRect( r.left()+1, r.top()+2, r.width()-2, r.height()-3),
00915 tb->colorGroup().brush( QColorGroup::Button ));
00916
00917
00918 QColor bg = tb->colorGroup().button();
00919
00920
00921 int n = r.height()/2;
00922 int dark = 100;
00923 for ( int i = 1; i < n; i++ ) {
00924 dark = (dark * (100+(i*15)/n) )/100;
00925 p->setPen( bg.dark( dark ) );
00926 int y = r.bottom()-n+i;
00927 int x1 = r.left()+1;
00928 int x2 = r.right()-1;
00929 p->drawLine( x1, y, x2, y );
00930 }
00931 }
00932
00933 p->setPen( tb->colorGroup().light() );
00934 p->drawLine( r.left(), r.bottom()-1, r.left(), r.top() + 2 );
00935 p->drawPoint( r.left()+1, r.top() + 1 );
00936 p->drawLine( r.left()+2, r.top(),
00937 r.right() - 2, r.top() );
00938
00939 p->setPen( tb->colorGroup().dark() );
00940 p->drawPoint( r.right() - 1, r.top() + 1 );
00941 p->drawLine( r.right(), r.top() + 2, r.right(), r.bottom() - 1);
00942 } else if ( tb->shape() == QTabBar::RoundedBelow ) {
00943 if ( selected ) {
00944 p->setPen( tb->colorGroup().background() );
00945 p->drawLine( r.left()+2, r.bottom()-1, r.right()-2, r.bottom()-1 );
00946 p->fillRect( QRect( r.left()+1, r.top(), r.width()-2, r.height()-2),
00947 tb->palette().normal().brush( QColorGroup::Background ));
00948 } else {
00949 p->setPen( tb->colorGroup().dark() );
00950 p->drawLine( r.left(), r.top(),
00951 r.right(), r.top() );
00952 r.setRect( r.left() + 2, r.top(),
00953 r.width() - 4, r.height() - 2 );
00954 p->setPen( tb->colorGroup().button() );
00955 p->drawLine( r.left()+2, r.bottom()-1, r.right()-2, r.bottom()-1 );
00956 p->fillRect( QRect( r.left()+1, r.top()+1, r.width()-2, r.height()-3),
00957 tb->palette().normal().brush( QColorGroup::Button ));
00958 }
00959
00960 p->setPen( tb->colorGroup().dark() );
00961 p->drawLine( r.right(), r.top(),
00962 r.right(), r.bottom() - 2 );
00963 p->drawPoint( r.right() - 1, r.bottom() - 1 );
00964 p->drawLine( r.right() - 2, r.bottom(),
00965 r.left() + 2, r.bottom() );
00966
00967 p->setPen( tb->colorGroup().light() );
00968 p->drawLine( r.left(), r.top()+1,
00969 r.left(), r.bottom() - 2 );
00970 p->drawPoint( r.left() + 1, r.bottom() - 1 );
00971 if ( r.left() == 0 )
00972 p->drawPoint( tb->rect().topLeft() );
00973
00974 } else {
00975 QCommonStyle::drawTab( p, tb, t, selected );
00976 }
00977 }
00978
00979 static const int motifItemFrame = 0;
00980 static const int motifSepHeight = 2;
00981 static const int motifItemHMargin = 1;
00982 static const int motifItemVMargin = 2;
00983 static const int motifArrowHMargin = 0;
00984 static const int motifTabSpacing = 12;
00985 static const int motifCheckMarkHMargin = 1;
00986 static const int windowsRightBorder = 8;
00987 static const int windowsCheckMarkWidth = 2;
00988
00991 int QPEStyle::extraPopupMenuItemWidth( bool checkable, int maxpmw, QMenuItem* mi, const QFontMetrics& )
00992 {
00993 #ifndef QT_NO_MENUDATA
00994 int w = 2*motifItemHMargin + 2*motifItemFrame;
00995
00996 if ( mi->isSeparator() )
00997 return 10;
00998 else if ( mi->pixmap() )
00999 w += mi->pixmap()->width();
01000
01001 if ( !mi->text().isNull() ) {
01002 if ( mi->text().find('\t') >= 0 )
01003 w += motifTabSpacing;
01004 }
01005
01006 if ( maxpmw ) {
01007 w += maxpmw;
01008 w += 6;
01009 }
01010
01011 if ( checkable && maxpmw < windowsCheckMarkWidth ) {
01012 w += windowsCheckMarkWidth - maxpmw;
01013 }
01014
01015 if ( maxpmw > 0 || checkable )
01016 w += motifCheckMarkHMargin;
01017
01018 w += windowsRightBorder;
01019
01020 return w;
01021 #endif
01022 }
01023
01026 int QPEStyle::popupMenuItemHeight( bool , QMenuItem* mi, const QFontMetrics& fm )
01027 {
01028 #ifndef QT_NO_MENUDATA
01029 int h = 0;
01030 if ( mi->isSeparator() )
01031 h = motifSepHeight;
01032 else if ( mi->pixmap() )
01033 h = mi->pixmap()->height() + 2*motifItemFrame;
01034 else
01035 h = fm.height() + 2*motifItemVMargin + 2*motifItemFrame - 1;
01036
01037 if ( !mi->isSeparator() && mi->iconSet() != 0 ) {
01038 h = QMAX( h, mi->iconSet()->pixmap().height() + 2*motifItemFrame );
01039 }
01040 if ( mi->custom() )
01041 h = QMAX( h, mi->custom()->sizeHint().height() + 2*motifItemVMargin + 2*motifItemFrame ) - 1;
01042 return h;
01043 #endif
01044 }
01045
01046 void QPEStyle::drawPopupMenuItem( QPainter* p, bool checkable, int maxpmw, int tab, QMenuItem* mi,
01047 const QPalette& pal,
01048 bool act, bool enabled, int x, int y, int w, int h)
01049 {
01050 #ifndef QT_NO_MENUDATA
01051 const QColorGroup & g = pal.active();
01052 bool dis = !enabled;
01053 QColorGroup itemg = dis ? pal.disabled() : pal.active();
01054
01055 if ( checkable )
01056 maxpmw = QMAX( maxpmw, 8 );
01057
01058 int checkcol = maxpmw;
01059
01060 if ( mi && mi->isSeparator() ) {
01061 p->setPen( g.dark() );
01062 p->drawLine( x, y, x+w, y );
01063 p->setPen( g.light() );
01064 p->drawLine( x, y+1, x+w, y+1 );
01065 return;
01066 }
01067
01068 QBrush fill = act? g.brush( QColorGroup::Highlight ) :
01069 g.brush( QColorGroup::Button );
01070 p->fillRect( x, y, w, h, fill);
01071
01072 if ( !mi )
01073 return;
01074
01075 if ( mi->isChecked() ) {
01076 if ( act && !dis ) {
01077 qDrawShadePanel( p, x, y, checkcol, h,
01078 g, TRUE, 1, &g.brush( QColorGroup::Button ) );
01079 } else {
01080 qDrawShadePanel( p, x, y, checkcol, h,
01081 g, TRUE, 1, &g.brush( QColorGroup::Midlight ) );
01082 }
01083 } else if ( !act ) {
01084 p->fillRect(x, y, checkcol , h,
01085 g.brush( QColorGroup::Button ));
01086 }
01087
01088 if ( mi->iconSet() ) {
01089 QIconSet::Mode mode = dis ? QIconSet::Disabled : QIconSet::Normal;
01090 if (act && !dis )
01091 mode = QIconSet::Active;
01092 QPixmap pixmap;
01093 if ( mode == QIconSet::Disabled )
01094 pixmap = mi->iconSet()->pixmap( QIconSet::Automatic, mode );
01095 else
01096 pixmap = mi->iconSet()->pixmap();
01097 int pixw = pixmap.width();
01098 int pixh = pixmap.height();
01099 if ( act && !dis ) {
01100 if ( !mi->isChecked() )
01101 qDrawShadePanel( p, x, y, checkcol, h, g, FALSE, 1, &g.brush( QColorGroup::Button ) );
01102 }
01103 QRect cr( x, y, checkcol, h );
01104 QRect pmr( 0, 0, pixw, pixh );
01105 pmr.moveCenter( cr.center() );
01106 p->setPen( itemg.text() );
01107 p->drawPixmap( pmr.topLeft(), pixmap );
01108
01109 QBrush fill = act? g.brush( QColorGroup::Highlight ) :
01110 g.brush( QColorGroup::Button );
01111 p->fillRect( x+checkcol + 1, y, w - checkcol - 1, h, fill);
01112 } else if ( checkable ) {
01113 int mw = checkcol + motifItemFrame;
01114 int mh = h - 2*motifItemFrame;
01115 if ( mi->isChecked() ) {
01116 drawCheckMark( p, x + motifItemFrame + 2,
01117 y+motifItemFrame, mw, mh, itemg, act, dis );
01118 }
01119 }
01120
01121 p->setPen( act ? g.highlightedText() : g.buttonText() );
01122
01123 QColor discol;
01124 if ( dis ) {
01125 discol = itemg.text();
01126 p->setPen( discol );
01127 }
01128
01129 int xm = motifItemFrame + checkcol + motifItemHMargin;
01130
01131 if ( mi->custom() ) {
01132 int m = motifItemVMargin;
01133 p->save();
01134 if ( dis && !act ) {
01135 p->setPen( g.light() );
01136 mi->custom()->paint( p, itemg, act, enabled,
01137 x+xm+1, y+m+1, w-xm-tab+1, h-2*m );
01138 p->setPen( discol );
01139 }
01140 mi->custom()->paint( p, itemg, act, enabled,
01141 x+xm, y+m, w-xm-tab+1, h-2*m );
01142 p->restore();
01143 }
01144 QString s = mi->text();
01145 if ( !s.isNull() ) {
01146 int t = s.find( '\t' );
01147 int m = motifItemVMargin;
01148 const int text_flags = AlignVCenter|ShowPrefix | DontClip | SingleLine;
01149 if ( t >= 0 ) {
01150 if ( dis && !act ) {
01151 p->setPen( g.light() );
01152 p->drawText( x+w-tab-windowsRightBorder-motifItemHMargin-motifItemFrame+1,
01153 y+m+1, tab, h-2*m, text_flags, s.mid( t+1 ));
01154 p->setPen( discol );
01155 }
01156 p->drawText( x+w-tab-windowsRightBorder-motifItemHMargin-motifItemFrame,
01157 y+m, tab, h-2*m, text_flags, s.mid( t+1 ) );
01158 }
01159 if ( dis && !act ) {
01160 p->setPen( g.light() );
01161 p->drawText( x+xm+1, y+m+1, w-xm+1, h-2*m, text_flags, s, t );
01162 p->setPen( discol );
01163 }
01164 p->drawText( x+xm, y+m, w-xm-tab+1, h-2*m, text_flags, s, t );
01165 } else if ( mi->pixmap() ) {
01166 QPixmap *pixmap = mi->pixmap();
01167 if ( pixmap->depth() == 1 )
01168 p->setBackgroundMode( OpaqueMode );
01169 p->drawPixmap( x+xm, y+motifItemFrame, *pixmap );
01170 if ( pixmap->depth() == 1 )
01171 p->setBackgroundMode( TransparentMode );
01172 }
01173 if ( mi->popup() ) {
01174 int dim = (h-2*motifItemFrame) / 2;
01175 if ( act ) {
01176 if ( !dis )
01177 discol = white;
01178 QColorGroup g2( discol, g.highlight(),
01179 white, white,
01180 dis ? discol : white,
01181 discol, white );
01182 drawArrow( p, RightArrow, FALSE,
01183 x+w - motifArrowHMargin - motifItemFrame - dim, y+h/2-dim/2,
01184 dim, dim, g2, TRUE );
01185 } else {
01186 drawArrow( p, RightArrow,
01187 FALSE,
01188 x+w - motifArrowHMargin - motifItemFrame - dim, y+h/2-dim/2,
01189 dim, dim, g, mi->isEnabled() );
01190 }
01191 }
01192 #endif
01193 }
01194
01195 #endif