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