00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "lightstyle-v3.h"
00024
00025 #include <QtGui/QMenuBar>
00026 #include <QtGui/QApplication>
00027 #include <QtGui/QCheckBox>
00028 #include <QtGui/QPainter>
00029 #include <QtGui/QColorGroup>
00030 #include <QtGui/QPushButton>
00031 #include <QtGui/qdrawutil.h>
00032 #include <QtGui/QProgressBar>
00033 #include <QtGui/QScrollBar>
00034 #include <QtGui/QTabBar>
00035 #include <QtCore/QPointer>
00036 #include <QtGui/QLayout>
00037 #include <QtGui/QLineEdit>
00038 #include <QtGui/QImage>
00039 #include <QtGui/QComboBox>
00040 #include <QtGui/QSlider>
00041 #include <QtGui/QStyleFactory>
00042 #include <Qt3Support/Q3PointArray>
00043
00044
00045
00046
00047 LightStyleV3::LightStyleV3()
00048 : KStyle(AllowMenuTransparency)
00049 {
00050 basestyle = QStyleFactory::create( "Windows" );
00051 if ( ! basestyle )
00052 basestyle = QStyleFactory::create( QStyleFactory::keys().first() );
00053 if ( ! basestyle )
00054 qFatal( "LightStyle: could not find a basestyle!" );
00055 }
00056
00057 LightStyleV3::~LightStyleV3()
00058 {
00059 delete basestyle;
00060 }
00061
00062 void LightStyleV3::polishPopupMenu( QMenu * menu)
00063 {
00064 KStyle::polishPopupMenu(menu);
00065
00066 }
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104 static void drawLightEtch( QPainter *p,
00105 const QRect &rect,
00106 const QColor &color,
00107 bool sunken )
00108 {
00109 Q3PointArray pts( 4 );
00110
00111 pts.setPoint( 0, rect.left(), rect.bottom() - 1);
00112 pts.setPoint( 1, rect.left(), rect.top() );
00113 pts.setPoint( 2, rect.left() + 1, rect.top() );
00114 pts.setPoint( 3, rect.right(), rect.top() );
00115 p->setPen( sunken ? color.dark( 115 ) : color.light( 115 ) );
00116 p->drawLineSegments( pts );
00117
00118 pts.setPoint( 0, rect.left(), rect.bottom() );
00119 pts.setPoint( 1, rect.right(), rect.bottom() );
00120 pts.setPoint( 2, rect.right(), rect.bottom() - 1 );
00121 pts.setPoint( 3, rect.right(), rect.top() + 1 );
00122 p->setPen( sunken ? color.light( 115 ) : color.dark( 115 ) );
00123 p->drawLineSegments( pts );
00124 }
00125
00126 static void drawLightBevel( QPainter *p,
00127 const QRect &rect,
00128 const QColorGroup &cg,
00129 QStyle::State flags,
00130 int linewidth,
00131 bool etch = false,
00132 bool border = true,
00133 const QBrush *fill = 0 )
00134 {
00135 QRect br = rect;
00136 bool bevel = ( flags & ( QStyle::State_Down | QStyle::State_On |
00137 QStyle::State_Sunken | QStyle::State_Raised ) );
00138 bool sunken = (flags & (QStyle::State_Down | QStyle::State_On |
00139 QStyle::State_Sunken));
00140
00141 if ( etch && linewidth > 0 ) {
00142 drawLightEtch( p, br, cg.background(), true );
00143 linewidth--;
00144 br.adjust( 1, 1, -1, -1 );
00145 }
00146
00147 if ( ! br.isValid() )
00148 return;
00149 if ( border && linewidth > 0 ) {
00150 p->setPen( cg.dark() );
00151 p->drawRect( br );
00152 linewidth--;
00153 br.adjust( 1, 1, -1, -1 );
00154 }
00155
00156 if ( ! br.isValid() )
00157 return;
00158 if ( bevel && linewidth > 0 ) {
00159
00160 int x, y, w, h;
00161 br.getRect( &x, &y, &w, &h );
00162
00163
00164 Q3PointArray a( 4*linewidth );
00165 if ( sunken )
00166 p->setPen( border ? cg.mid() : cg.dark() );
00167 else
00168 p->setPen( cg.light() );
00169 int x1, y1, x2, y2;
00170 int i;
00171 int n = 0;
00172 x1 = x;
00173 y1 = y2 = y;
00174 x2 = x+w-2;
00175 for ( i=0; i<linewidth; i++ ) {
00176 a.setPoint( n++, x1, y1++ );
00177 a.setPoint( n++, x2--, y2++ );
00178 }
00179 x2 = x1;
00180 y1 = y+h-2;
00181 for ( i=0; i<linewidth; i++ ) {
00182 a.setPoint( n++, x1++, y1 );
00183 a.setPoint( n++, x2++, y2-- );
00184 }
00185 p->drawLineSegments( a );
00186 n = 0;
00187 if ( sunken )
00188 p->setPen( cg.light() );
00189 else
00190 p->setPen( border ? cg.mid() : cg.dark() );
00191 x1 = x;
00192 y1 = y2 = y+h-1;
00193 x2 = x+w-1;
00194 for ( i=0; i<linewidth; i++ ) {
00195 a.setPoint( n++, x1++, y1-- );
00196 a.setPoint( n++, x2, y2-- );
00197 }
00198 x1 = x2;
00199 y1 = y;
00200 y2 = y+h-linewidth-1;
00201 for ( i=0; i<linewidth; i++ ) {
00202 a.setPoint( n++, x1--, y1++ );
00203 a.setPoint( n++, x2--, y2 );
00204 }
00205 p->drawLineSegments( a );
00206
00207 br.adjust( linewidth, linewidth, -linewidth, -linewidth );
00208 }
00209
00210
00211 if ( fill )
00212 p->fillRect( br, *fill );
00213 }
00214
00215 void LightStyleV3::drawPrimitive( PrimitiveElement pe,
00216 QPainter *p,
00217 const QRect &r,
00218 const QColorGroup &cg,
00219 SFlags flags,
00220 const QStyleOption &data ) const
00221 {
00222 QRect br = r;
00223 const QBrush *fill = 0;
00224
00225 switch (pe) {
00226 case PE_HeaderSection:
00227
00228 flags = ((flags | Style_Sunken) ^ Style_Sunken) | Style_Raised;
00229
00230 p->setPen( cg.background() );
00231
00232 if ( flags & Style_Horizontal ) {
00233 p->drawLine( br.bottomLeft(), br.bottomRight() );
00234 br.adjust( 0, 0, 0, -1 );
00235 } else {
00236 p->drawLine( br.topRight(), br.bottomRight() );
00237 br.adjust( 0, 0, -1, 0 );
00238 }
00239
00240
00241 if ( ! br.isValid() )
00242 break;
00243 drawLightEtch( p, br, ( ( flags & Style_Down ) ?
00244 cg.midlight() : cg.button() ),
00245 ( flags & Style_Down ) );
00246 br.adjust( 1, 1, -1, -1 );
00247
00248
00249 if ( ! br.isValid() )
00250 break;
00251 p->fillRect( br, cg.brush( ( flags & Style_Down ) ?
00252 QPalette::Midlight : QPalette::Button ) );
00253
00254
00255
00256
00257 p->setPen( cg.buttonText() );
00258 break;
00259
00260 case PE_ButtonCommand:
00261 {
00262 QRect br = r;
00263
00264 if (flags & QStyle::State_Enabled) {
00265 if (flags & (QStyle::State_Down |
00266 QStyle::State_On |
00267 QStyle::State_Sunken))
00268 fill = &cg.brush(QPalette::Midlight);
00269 else
00270 fill = &cg.brush(QPalette::Button);
00271 } else
00272 fill = &cg.brush(QPalette::Background);
00273
00274 bool etch = true;
00275 if ( flags & Style_ButtonDefault ) {
00276 etch = false;
00277 br.adjust( 1, 1, -1, -1 );
00278 }
00279 drawLightBevel( p, br, cg, flags,
00280 pixelMetric( PM_DefaultFrameWidth ) + ( etch ? 1 : 0 ),
00281 etch, true, fill );
00282 break;
00283 }
00284
00285 case PE_ButtonBevel:
00286 case PE_ButtonTool:
00287 if (flags & QStyle::State_Enabled) {
00288 if (flags & (QStyle::State_Down |
00289 QStyle::State_On |
00290 QStyle::State_Sunken))
00291 fill = &cg.brush(QPalette::Midlight);
00292 else
00293 fill = &cg.brush(QPalette::Button);
00294 } else
00295 fill = &cg.brush(QPalette::Background);
00296 drawLightBevel( p, r, cg, flags, pixelMetric( PM_DefaultFrameWidth ),
00297 false, true, fill );
00298 break;
00299
00300 case PE_ButtonDropDown:
00301 {
00302 QBrush thefill;
00303 bool sunken =
00304 (flags & (QStyle::State_Down | QStyle::State_On | QStyle::State_Sunken));
00305
00306 if (flags & QStyle::State_Enabled) {
00307 if (sunken)
00308 thefill = cg.brush(QPalette::Midlight);
00309 else
00310 thefill = cg.brush(QPalette::Button);
00311 } else
00312 thefill = cg.brush(QPalette::Background);
00313
00314 p->setPen( cg.dark() );
00315 p->drawLine(r.topLeft(), r.topRight());
00316 p->drawLine(r.topRight(), r.bottomRight());
00317 p->drawLine(r.bottomRight(), r.bottomLeft());
00318
00319 if (flags & (QStyle::State_Down | QStyle::State_On |
00320 QStyle::State_Sunken | QStyle::State_Raised)) {
00321
00322 if (sunken)
00323 p->setPen(cg.mid());
00324 else
00325 p->setPen(cg.light());
00326
00327 p->drawLine(r.x(), r.y() + 2,
00328 r.x(), r.y() + r.height() - 3);
00329 p->drawLine(r.x(), r.y() + 1,
00330 r.x() + r.width() - 2, r.y() + 1);
00331
00332 if (sunken)
00333 p->setPen(cg.light());
00334 else
00335 p->setPen(cg.mid());
00336
00337 p->drawLine(r.x() + r.width() - 2, r.y() + 2,
00338 r.x() + r.width() - 2, r.y() + r.height() - 3);
00339 p->drawLine(r.x() + 1, r.y() + r.height() - 2,
00340 r.x() + r.width() - 2, r.y() + r.height() - 2);
00341 }
00342
00343 p->fillRect(r.x() + 1, r.y() + 2, r.width() - 3, r.height() - 4, thefill);
00344 break;
00345 }
00346
00347 case PE_ButtonDefault:
00348 p->setPen( cg.shadow() );
00349 p->drawRect( r );
00350 break;
00351
00352 case PE_Indicator:
00353 const QBrush *fill;
00354 if (! (flags & Style_Enabled))
00355 fill = &cg.brush(QPalette::Background);
00356 else if (flags & Style_Down)
00357 fill = &cg.brush(QPalette::Mid);
00358 else
00359 fill = &cg.brush(QPalette::Base);
00360 drawLightBevel( p, r, cg, flags | Style_Sunken, 2, true, true, fill );
00361
00362 p->setPen(cg.text());
00363 if (flags & Style_NoChange) {
00364 p->drawLine(r.x() + 3, r.y() + r.height() / 2,
00365 r.x() + r.width() - 4, r.y() + r.height() / 2);
00366 p->drawLine(r.x() + 3, r.y() + 1 + r.height() / 2,
00367 r.x() + r.width() - 4, r.y() + 1 + r.height() / 2);
00368 p->drawLine(r.x() + 3, r.y() - 1 + r.height() / 2,
00369 r.x() + r.width() - 4, r.y() - 1 + r.height() / 2);
00370 } else if (flags & Style_On) {
00371 p->drawLine(r.x() + 4, r.y() + 3,
00372 r.x() + r.width() - 4, r.y() + r.height() - 5);
00373 p->drawLine(r.x() + 3, r.y() + 3,
00374 r.x() + r.width() - 4, r.y() + r.height() - 4);
00375 p->drawLine(r.x() + 3, r.y() + 4,
00376 r.x() + r.width() - 5, r.y() + r.height() - 4);
00377 p->drawLine(r.x() + 3, r.y() + r.height() - 5,
00378 r.x() + r.width() - 5, r.y() + 3);
00379 p->drawLine(r.x() + 3, r.y() + r.height() - 4,
00380 r.x() + r.width() - 4, r.y() + 3);
00381 p->drawLine(r.x() + 4, r.y() + r.height() - 4,
00382 r.x() + r.width() - 4, r.y() + 4);
00383 }
00384
00385 break;
00386
00387 case PE_ExclusiveIndicator:
00388 {
00389 QRect br = r,
00390 lr = r,
00391 cr = r,
00392 ir = r;
00393 lr.adjust( 1, 1, -1, -1 );
00394 cr.adjust( 2, 2, -2, -2 );
00395 ir.adjust( 3, 3, -3, -3 );
00396
00397 p->fillRect( r, cg.brush( QPalette::Background ) );
00398
00399 p->setPen( flags & Style_Down ? cg.mid() :
00400 ( flags & Style_Enabled ? cg.base() : cg.background() ) );
00401 p->setBrush( flags & Style_Down ? cg.mid() :
00402 ( flags & Style_Enabled ? cg.base() : cg.background() ) );
00403 p->drawEllipse( lr );
00404
00405 p->setPen( cg.background().dark( 115 ) );
00406 p->drawArc( br, 45*16, 180*16 );
00407 p->setPen( cg.background().light( 115 ) );
00408 p->drawArc( br, 235*16, 180*16 );
00409
00410 p->setPen( cg.dark() );
00411 p->drawArc( lr, 0, 16*360 );
00412
00413 if ( flags & Style_On ) {
00414 p->setPen( flags & Style_Down ? cg.mid() :
00415 ( flags & Style_Enabled ? cg.base() : cg.background() ) );
00416 p->setBrush( cg.text() );
00417 p->drawEllipse( ir );
00418 }
00419
00420 break;
00421 }
00422
00423 case PE_DockWindowHandle:
00424 {
00425 QString title;
00426 bool drawTitle = false;
00427 if ( p && p->device()->devType() == QInternal::Widget ) {
00428 QWidget *w = (QWidget *) p->device();
00429 QWidget *p = w->parentWidget();
00430 if (p->inherits("QDockWindow") && ! p->inherits("QToolBar")) {
00431 drawTitle = true;
00432 title = p->caption();
00433 }
00434 }
00435
00436 flags |= Style_Raised;
00437 if (flags & Style_Horizontal) {
00438 if (drawTitle) {
00439 QPixmap pm(r.height(), r.width());
00440 QPainter p2(&pm);
00441 p2.fillRect(0, 0, pm.width(), pm.height(),
00442 cg.brush(QPalette::Highlight));
00443 p2.setPen(cg.highlightedText());
00444 p2.drawText(0, 0, pm.width(), pm.height(), Qt::AlignCenter, title);
00445 p2.end();
00446
00447 QMatrix m;
00448 m.rotate(270.0);
00449 pm = pm.xForm(m);
00450 p->drawPixmap(r.x(), r.y(), pm);
00451 } else {
00452 for ( int i = r.left() - 1; i < r.right(); i += 3 ) {
00453 p->setPen( cg.midlight() );
00454 p->drawLine( i, r.top(), i, r.bottom() );
00455 p->setPen( cg.background() );
00456 p->drawLine( i + 1, r.top(), i + 1, r.bottom() );
00457 p->setPen( cg.mid() );
00458 p->drawLine( i + 2, r.top(), i + 2, r.bottom() );
00459 }
00460 }
00461 } else {
00462 if (drawTitle) {
00463 p->fillRect(r, cg.brush(QPalette::Highlight));
00464 p->setPen(cg.highlightedText());
00465 p->drawText(r, Qt::AlignCenter, title);
00466 } else {
00467 for ( int i = r.top() - 1; i < r.bottom(); i += 3 ) {
00468 p->setPen( cg.midlight() );
00469 p->drawLine( r.left(), i, r.right(), i );
00470 p->setPen( cg.background() );
00471 p->drawLine( r.left(), i + 1, r.right(), i + 1);
00472 p->setPen( cg.mid() );
00473 p->drawLine( r.left(), i + 2, r.right(), i + 2 );
00474 }
00475
00476 }
00477 }
00478 break;
00479 }
00480
00481 case PE_DockWindowSeparator:
00482 {
00483 if (flags & Style_Horizontal) {
00484 int hw = r.width() / 2;
00485 p->setPen( cg.mid() );
00486 p->drawLine( hw, r.top() + 6, hw, r.bottom() - 6 );
00487 p->setPen( cg.light() );
00488 p->drawLine( hw + 1, r.top() + 6, hw + 1, r.bottom() - 6 );
00489 } else {
00490 int hh = r.height() / 2;
00491 p->setPen( cg.mid() );
00492 p->drawLine( r.left() + 6, hh, r.right() - 6, hh );
00493 p->setPen( cg.light() );
00494 p->drawLine( r.left() + 6, hh + 1, r.right() - 6, hh + 1 );
00495 }
00496 break;
00497 }
00498
00499 case PE_Splitter:
00500 if (flags & Style_Horizontal)
00501 flags &= ~Style_Horizontal;
00502 else
00503 flags |= Style_Horizontal;
00504
00505
00506 case PE_DockWindowResizeHandle:
00507 {
00508 QRect br = r;
00509
00510 p->setPen( cg.shadow() );
00511 p->drawRect( br );
00512
00513 br.adjust( 1, 1, -1, -1 );
00514
00515 if ( ! br.isValid() )
00516 break;
00517 p->setPen( cg.light() );
00518 p->drawLine( br.left(), br.top(), br.right() - 1, br.top() );
00519 p->drawLine( br.left(), br.top() + 1, br.left(), br.bottom() );
00520 p->setPen( cg.mid() );
00521 p->drawLine( br.bottomLeft(), br.bottomRight() );
00522 p->drawLine( br.right(), br.top(), br.right(), br.bottom() - 1 );
00523
00524 br.adjust( 1, 1, -1, -1 );
00525
00526 if ( ! br.isValid() )
00527 break;
00528 p->fillRect( br, cg.brush( QPalette::Button ) );
00529 break;
00530 }
00531
00532 case PE_PanelPopup:
00533 drawLightBevel( p, r, cg, flags,
00534 ( data.isDefault() ? pixelMetric(PM_DefaultFrameWidth) :
00535 data.lineWidth() ), false, true );
00536 break;
00537
00538 case PE_Panel:
00539 case PE_PanelLineEdit:
00540 case PE_PanelTabWidget:
00541 case PE_WindowFrame:
00542 {
00543 QRect br = r;
00544
00545 int cover = 0;
00546 int reallw = ( data.isDefault() ?
00547 pixelMetric( PM_DefaultFrameWidth ) : data.lineWidth() );
00548 cover = reallw - 1;
00549
00550 if ( ! ( flags & Style_Sunken ) )
00551 flags |= Style_Raised;
00552 drawLightBevel( p, br, cg, flags, 1, false, false );
00553 br.adjust( 1, 1, -1, -1 );
00554
00555 while ( cover-- > 0 ) {
00556 Q3PointArray pts( 8 );
00557 pts.setPoint( 0, br.left(), br.bottom() - 1);
00558 pts.setPoint( 1, br.left(), br.top() );
00559 pts.setPoint( 2, br.left() + 1, br.top() );
00560 pts.setPoint( 3, br.right(), br.top() );
00561 pts.setPoint( 4, br.left(), br.bottom() );
00562 pts.setPoint( 5, br.right(), br.bottom() );
00563 pts.setPoint( 6, br.right(), br.bottom() - 1 );
00564 pts.setPoint( 7, br.right(), br.top() + 1 );
00565 p->setPen( cg.background() );
00566 p->drawLineSegments( pts );
00567
00568 br.adjust( 1, 1, -1, -1 );
00569 }
00570 break;
00571 }
00572
00573 case PE_PanelDockWindow:
00574 drawLightBevel( p, r, cg, flags, ( data.isDefault() ?
00575 pixelMetric(PM_DefaultFrameWidth) :
00576 data.lineWidth() ), false, false,
00577 &cg.brush( QPalette::Button ) );
00578 break;
00579
00580 case PE_PanelMenuBar:
00581 drawLightBevel( p, r, cg, flags, ( data.isDefault() ?
00582 pixelMetric(PM_MenuBarFrameWidth) :
00583 data.lineWidth() ), false, false,
00584 &cg.brush( QPalette::Button ) );
00585 break;
00586
00587 case PE_ScrollBarSubLine:
00588 {
00589 QRect br = r;
00590 PrimitiveElement pe;
00591
00592 p->setPen( cg.background() );
00593 if (flags & Style_Horizontal) {
00594 pe = PE_ArrowLeft;
00595 p->drawLine( br.topLeft(), br.topRight() );
00596 br.adjust( 0, 1, 0, 0 );
00597 } else {
00598 pe = PE_ArrowUp;
00599 p->drawLine( br.topLeft(), br.bottomLeft() );
00600 br.adjust( 1, 0, 0, 0 );
00601 }
00602
00603 if ( ! br.isValid() )
00604 break;
00605 drawLightEtch( p, br, cg.button(), false );
00606 br.adjust( 1, 1, -1, -1 );
00607
00608 if ( ! br.isValid() )
00609 break;
00610 p->fillRect( br, cg.brush( ( flags & Style_Down ) ?
00611 QPalette::Midlight :
00612 QPalette::Button ) );
00613 br.adjust( 2, 2, -2, -2 );
00614
00615 if ( ! br.isValid() )
00616 break;
00617 drawPrimitive( pe, p, br, cg, flags );
00618 break;
00619 }
00620
00621 case PE_ScrollBarAddLine:
00622 {
00623 QRect br = r;
00624 PrimitiveElement pe;
00625
00626 p->setPen( cg.background() );
00627 if (flags & Style_Horizontal) {
00628 pe = PE_ArrowRight;
00629 p->drawLine( br.topLeft(), br.topRight() );
00630 br.adjust( 0, 1, 0, 0 );
00631 } else {
00632 pe = PE_ArrowDown;
00633 p->drawLine( br.topLeft(), br.bottomLeft() );
00634 br.adjust( 1, 0, 0, 0 );
00635 }
00636
00637 if ( ! br.isValid() )
00638 break;
00639 drawLightEtch( p, br, cg.button(), false );
00640 br.adjust( 1, 1, -1, -1 );
00641
00642 if ( ! br.isValid() )
00643 break;
00644 p->fillRect( br, cg.brush( ( flags & Style_Down ) ?
00645 QPalette::Midlight :
00646 QPalette::Button ) );
00647 br.adjust( 2, 2, -2, -2 );
00648
00649 if ( ! br.isValid() )
00650 break;
00651 drawPrimitive( pe, p, br, cg, flags );
00652 break;
00653 }
00654
00655 case PE_ScrollBarSubPage:
00656 {
00657 QRect br = r;
00658
00659 p->setPen( cg.background() );
00660 if (flags & Style_Horizontal) {
00661 p->drawLine( br.topLeft(), br.topRight() );
00662 br.adjust( 0, 1, 0, 0 );
00663 } else {
00664 p->drawLine( br.topLeft(), br.bottomLeft() );
00665 br.adjust( 1, 0, 0, 0 );
00666 }
00667
00668 if ( ! br.isValid() )
00669 break;
00670 drawLightEtch( p, br, cg.button(), false );
00671 br.adjust( 1, 1, -1, -1 );
00672
00673 if ( ! br.isValid() )
00674 break;
00675 p->fillRect( br, cg.brush( ( flags & Style_Down ) ?
00676 QPalette::Midlight :
00677 QPalette::Button ) );
00678 break;
00679 }
00680
00681 case PE_ScrollBarAddPage:
00682 {
00683 QRect br = r;
00684
00685 p->setPen( cg.background() );
00686 if (flags & Style_Horizontal) {
00687 p->drawLine( br.topLeft(), br.topRight() );
00688 br.adjust( 0, 1, 0, 0 );
00689 } else {
00690 p->drawLine( br.topLeft(), br.bottomLeft() );
00691 br.adjust( 1, 0, 0, 0 );
00692 }
00693
00694 if ( ! br.isValid() )
00695 break;
00696 drawLightEtch( p, br, cg.button(), false );
00697 br.adjust( 1, 1, -1, -1 );
00698
00699 if ( ! br.isValid() )
00700 break;
00701 p->fillRect( br, cg.brush( ( flags & Style_Down ) ?
00702 QPalette::Midlight :
00703 QPalette::Button ) );
00704 break;
00705 }
00706
00707 case PE_ScrollBarSlider:
00708 {
00709 QRect br = r;
00710
00711 p->setPen( cg.background() );
00712 if (flags & Style_Horizontal) {
00713 p->drawLine( br.topLeft(), br.topRight() );
00714 br.adjust( 0, 1, 0, 0 );
00715 } else {
00716 p->drawLine( br.topLeft(), br.bottomLeft() );
00717 br.adjust( 1, 0, 0, 0 );
00718 }
00719
00720 if ( ! br.isValid() )
00721 break;
00722 p->setPen( cg.highlight().light() );
00723 p->drawLine( br.topLeft(), br.topRight() );
00724 p->drawLine( br.left(), br.top() + 1, br.left(), br.bottom() - 1 );
00725
00726 p->setPen( cg.highlight().dark() );
00727 p->drawLine( br.left(), br.bottom(), br.right() - 1, br.bottom() );
00728 p->drawLine( br.topRight(), br.bottomRight() );
00729 br.adjust( 1, 1, -1, -1 );
00730
00731 p->fillRect( br, cg.brush( QPalette::Highlight ) );
00732 break;
00733 }
00734
00735 case PE_FocusRect:
00736 p->setBrush( Qt::NoBrush );
00737 if ( flags & Style_FocusAtBorder )
00738 p->setPen( cg.shadow() );
00739 else
00740 p->setPen( cg.dark() );
00741 p->drawRect( r );
00742 break;
00743
00744 case PE_ProgressBarChunk:
00745 p->fillRect(r.x(), r.y() + 2, r.width(), r.height() - 4, cg.highlight());
00746 break;
00747
00748 default:
00749 if (pe == PE_HeaderArrow) {
00750 if (flags & Style_Down)
00751 pe = PE_ArrowDown;
00752 else
00753 pe = PE_ArrowUp;
00754 }
00755
00756 if (pe >= PE_ArrowUp && pe <= PE_ArrowLeft) {
00757 Q3PointArray a;
00758
00759 switch ( pe ) {
00760 case PE_ArrowUp:
00761 a.setPoints( 7, -4,1, 2,1, -3,0, 1,0, -2,-1, 0,-1, -1,-2 );
00762 break;
00763
00764 case PE_ArrowDown:
00765 a.setPoints( 7, -4,-2, 2,-2, -3,-1, 1,-1, -2,0, 0,0, -1,1 );
00766 break;
00767
00768 case PE_ArrowRight:
00769 a.setPoints( 7, -2,-3, -2,3, -1,-2, -1,2, 0,-1, 0,1, 1,0 );
00770 break;
00771
00772 case PE_ArrowLeft:
00773 a.setPoints( 7, 0,-3, 0,3, -1,-2, -1,2, -2,-1, -2,1, -3,0 );
00774 break;
00775
00776 default:
00777 break;
00778 }
00779
00780 if (a.isNull())
00781 return;
00782
00783 p->save();
00784 if ( flags & Style_Enabled ) {
00785 a.translate( r.x() + r.width() / 2, r.y() + r.height() / 2 );
00786 p->setPen( cg.buttonText() );
00787 p->drawLineSegments( a, 0, 3 );
00788 p->drawPoint( a[6] );
00789 } else {
00790 a.translate( r.x() + r.width() / 2 + 1, r.y() + r.height() / 2 + 1 );
00791 p->setPen( cg.light() );
00792 p->drawLineSegments( a, 0, 3 );
00793 p->drawPoint( a[6] );
00794 a.translate( -1, -1 );
00795 p->setPen( cg.mid() );
00796 p->drawLineSegments( a, 0, 3 );
00797 p->drawPoint( a[6] );
00798 }
00799 p->restore();
00800 } else
00801 QCommonStyle::drawPrimitive(pe, p, r, cg, flags, data);
00802 break;
00803 }
00804 }
00805
00806 void LightStyleV3::drawControl( ControlElement control,
00807 QPainter *p,
00808 const QWidget *widget,
00809 const QRect &r,
00810 const QColorGroup &cg,
00811 SFlags flags,
00812 const QStyleOption &data ) const
00813 {
00814 switch (control) {
00815 case CE_TabBarTab:
00816 {
00817 const QTabBar *tb = (const QTabBar *) widget;
00818 QRect br = r;
00819
00820 if ( tb->shape() == QTabBar::RoundedNorth ) {
00821 if ( ! ( flags & Style_Selected ) ) {
00822 p->setPen( cg.background() );
00823 p->drawLine( br.left(), br.bottom(),
00824 br.right(), br.bottom() );
00825 p->setPen( cg.light() );
00826 p->drawLine( br.left(), br.bottom() - 1,
00827 br.right(), br.bottom() - 1);
00828 br.adjust( 0, 2, -1, -2 );
00829 if ( br.left() == 0 )
00830 p->drawPoint( br.left(), br.bottom() + 2 );
00831 } else {
00832 p->setPen( cg.background() );
00833 p->drawLine( br.bottomLeft(), br.bottomRight() );
00834 if ( br.left() == 0 ) {
00835 p->setPen( cg.light() );
00836 p->drawPoint( br.bottomLeft() );
00837 }
00838 br.adjust( 0, 0, 0, -1 );
00839 }
00840
00841 p->setPen( cg.light() );
00842 p->drawLine( br.bottomLeft(), br.topLeft() );
00843 p->drawLine( br.topLeft(), br.topRight() );
00844 p->setPen( cg.dark() );
00845 p->drawLine( br.right(), br.top() + 1, br.right(), br.bottom() );
00846
00847 if ( flags & Style_Selected )
00848 {
00849 p->fillRect( br.right() - 3, br.top() + 1, 3, br.height() - 1, cg.brush(QPalette::Highlight));
00850 br.adjust( 1, 1, -4, 0 );
00851 }
00852 else
00853 br.adjust( 1, 1, -1, 0 );
00854 p->fillRect( br, cg.background() );
00855 } else if ( tb->shape() == QTabBar:: RoundedSouth ) {
00856 if ( ! ( flags & Style_Selected ) ) {
00857 p->setPen( cg.background() );
00858 p->drawLine( br.left(), br.top(),
00859 br.right(), br.top() );
00860 p->setPen( cg.dark() );
00861 p->drawLine( br.left(), br.top() + 1,
00862 br.right(), br.top() + 1);
00863 br.adjust( 0, 2, -1, -2 );
00864 if ( br.left() == 0 ) {
00865 p->setPen( cg.light() );
00866 p->drawPoint( br.left(), br.top() - 2 );
00867 }
00868 } else {
00869 p->setPen( cg.background() );
00870 p->drawLine( br.topLeft(), br.topRight() );
00871 if ( br.left() == 0 ) {
00872 p->setPen( cg.light() );
00873 p->drawPoint( br.topLeft() );
00874 }
00875 br.adjust( 0, 1, 0, 0 );
00876 }
00877
00878 p->setPen( cg.light() );
00879 p->drawLine( br.topLeft(), br.bottomLeft() );
00880 p->setPen( cg.dark() );
00881 p->drawLine( br.bottomLeft(), br.bottomRight() );
00882 p->drawLine( br.right(), br.top(), br.right(), br.bottom() - 1 );
00883 br.adjust( 1, 0, -1, -1 );
00884
00885 if ( flags & Style_Selected )
00886 {
00887 p->fillRect( br.right() - 2, br.top(), 3, br.height(), cg.brush(QPalette::Highlight));
00888 br.adjust( 1, 0, -3, -1 );
00889 }
00890 else
00891 br.adjust( 1, 0, -1, -1 );
00892
00893 p->fillRect( br, cg.background() );
00894 } else
00895 QCommonStyle::drawControl( control, p, widget, r, cg, flags, data );
00896 break;
00897 }
00898
00899 case CE_PopupMenuItem:
00900 {
00901 if (! widget || data.isDefault())
00902 break;
00903
00904 const QMenu *popupmenu = (const QMenu *) widget;
00905 QMenuItem *mi = data.menuItem();
00906 int tab = data.tabWidth();
00907 int maxpmw = data.maxIconWidth();
00908
00909 if ( mi && mi->isSeparator() ) {
00910 if ( widget->erasePixmap() && !widget->erasePixmap()->isNull() )
00911 p->drawPixmap( r.topLeft(), *widget->erasePixmap(), r );
00912 else
00913 p->fillRect(r, cg.brush(QPalette::Button));
00914 p->setPen( cg.mid() );
00915 p->drawLine(r.left() + 12, r.top() + 1,
00916 r.right() - 12, r.top() + 1);
00917 p->setPen( cg.light() );
00918 p->drawLine(r.left() + 12, r.top() + 2,
00919 r.right() - 12, r.top() + 2);
00920 break;
00921 }
00922
00923 if (flags & Style_Active)
00924 qDrawShadePanel(p, r, cg, true, 1,
00925 &cg.brush(QPalette::Midlight));
00926 else if ( widget->erasePixmap() && !widget->erasePixmap()->isNull() )
00927 p->drawPixmap( r.topLeft(), *widget->erasePixmap(), r );
00928 else
00929 p->fillRect(r, cg.brush(QPalette::Button));
00930
00931 if ( !mi )
00932 break;
00933
00934 maxpmw = qMax(maxpmw, 16);
00935
00936 QRect cr, ir, tr, sr;
00937
00938 cr.setRect(r.left(), r.top(), maxpmw, r.height());
00939
00940 sr.setCoords(r.right() - maxpmw, r.top(), r.right(), r.bottom());
00941
00942 tr.setCoords(sr.left() - tab - 4, r.top(), sr.left(), r.bottom());
00943
00944 ir.setCoords(cr.right() + 4, r.top(), tr.right() - 4, r.bottom());
00945
00946 bool reverse = QApplication::isRightToLeft();
00947 if ( reverse ) {
00948 cr = visualRect( cr, r );
00949 sr = visualRect( sr, r );
00950 tr = visualRect( tr, r );
00951 ir = visualRect( ir, r );
00952 }
00953
00954 if (mi->isChecked() &&
00955 ! (flags & Style_Active) &
00956 (flags & Style_Enabled))
00957 qDrawShadePanel(p, cr, cg, true, 1, &cg.brush(QPalette::Midlight));
00958
00959 if (mi->iconSet()) {
00960 QIcon::Mode mode =
00961 (flags & Style_Enabled) ? QIcon::Normal : QIcon::Disabled;
00962 if ((flags & Style_Active) && (flags & Style_Enabled))
00963 mode = QIcon::Active;
00964 QPixmap pixmap;
00965 if (popupmenu->isCheckable() && mi->isChecked())
00966 pixmap =
00967 mi->iconSet()->pixmap( QIcon::Small, mode, QIcon::On );
00968 else
00969 pixmap =
00970 mi->iconSet()->pixmap( QIcon::Small, mode );
00971 QRect pmr(QPoint(0, 0), pixmap.size());
00972 pmr.moveCenter(cr.center());
00973 p->setPen(cg.text());
00974 p->drawPixmap(pmr.topLeft(), pixmap);
00975 } else if (popupmenu->isCheckable() && mi->isChecked())
00976 drawPrimitive(PE_CheckMark, p, cr, cg,
00977 (flags & Style_Enabled) | Style_On);
00978
00979 QColor textcolor;
00980 QColor embosscolor;
00981 if (flags & Style_Active) {
00982 if (! (flags & Style_Enabled))
00983 textcolor = cg.midlight().dark();
00984 else
00985 textcolor = cg.buttonText();
00986 embosscolor = cg.midlight().light();
00987 } else if (! (flags & Style_Enabled)) {
00988 textcolor = cg.text();
00989 embosscolor = cg.light();
00990 } else
00991 textcolor = embosscolor = cg.buttonText();
00992 p->setPen(textcolor);
00993
00994 if (mi->custom()) {
00995 p->save();
00996 if (! (flags & Style_Enabled)) {
00997 p->setPen(cg.light());
00998 mi->custom()->paint(p, cg, flags & Style_Active,
00999 flags & Style_Enabled,
01000 ir.x() + 1, ir.y() + 1,
01001 ir.width() - 1, ir.height() - 1);
01002 p->setPen(textcolor);
01003 }
01004 mi->custom()->paint(p, cg, flags & Style_Active,
01005 flags & Style_Enabled,
01006 ir.x(), ir.y(),
01007 ir.width(), ir.height());
01008 p->restore();
01009 }
01010
01011 QString text = mi->text();
01012 if (! text.isNull()) {
01013 int t = text.find('\t');
01014
01015
01016 if (t >= 0) {
01017 int alignFlag = Qt::AlignVCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine;
01018 alignFlag |= ( reverse ? Qt::AlignLeft : Qt::AlignRight );
01019 if (! (flags & Style_Enabled)) {
01020 p->setPen(embosscolor);
01021 tr.translate(1, 1);
01022 p->drawText(tr, alignFlag, text.mid(t + 1));
01023 tr.translate(-1, -1);
01024 p->setPen(textcolor);
01025 }
01026
01027 p->drawText(tr, alignFlag, text.mid(t + 1));
01028 }
01029
01030 int alignFlag = Qt::AlignVCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine;
01031 alignFlag |= ( reverse ? Qt::AlignRight : Qt::AlignLeft );
01032
01033 if (! (flags & Style_Enabled)) {
01034 p->setPen(embosscolor);
01035 ir.translate(1, 1);
01036 p->drawText(ir, alignFlag, text, t);
01037 ir.translate(-1, -1);
01038 p->setPen(textcolor);
01039 }
01040
01041 p->drawText(ir, alignFlag, text, t);
01042 } else if (mi->pixmap()) {
01043 QPixmap pixmap = *mi->pixmap();
01044 if (pixmap.depth() == 1)
01045 p->setBackgroundMode(Qt::OpaqueMode);
01046 p->drawPixmap(ir.x(), ir.y() + (ir.height() - pixmap.height()) / 2, pixmap);
01047 if (pixmap.depth() == 1)
01048 p->setBackgroundMode(Qt::TransparentMode);
01049 }
01050
01051 if (mi->popup())
01052 drawPrimitive( (QApplication::isRightToLeft() ? PE_ArrowLeft : PE_ArrowRight),
01053 p, sr, cg, flags);
01054 break;
01055 }
01056
01057 case CE_MenuBarEmptyArea:
01058 {
01059 p->fillRect(r, cg.brush(QPalette::Button));
01060 break;
01061 }
01062
01063 case CE_MenuBarItem:
01064 {
01065 if ( flags & Style_Active )
01066 qDrawShadePanel(p, r, cg, true, 1, &cg.brush(QPalette::Midlight));
01067 else
01068 p->fillRect( r, cg.brush( QPalette::Button ) );
01069
01070 if (data.isDefault())
01071 break;
01072
01073 QMenuItem *mi = data.menuItem();
01074 drawItem(p, r, Qt::AlignCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine, cg,
01075 flags & Style_Enabled, mi->pixmap(), mi->text(), -1,
01076 &cg.buttonText());
01077 break;
01078 }
01079
01080 case CE_ProgressBarGroove:
01081 drawLightBevel( p, r, cg, Style_Sunken, pixelMetric( PM_DefaultFrameWidth ),
01082 true, true, &cg.brush( QPalette::Background ) );
01083 break;
01084
01085 default:
01086 QCommonStyle::drawControl(control, p, widget, r, cg, flags, data);
01087 break;
01088 }
01089 }
01090
01091 void LightStyleV3::drawControlMask( ControlElement control,
01092 QPainter *p,
01093 const QWidget *widget,
01094 const QRect &r,
01095 const QStyleOption &data ) const
01096 {
01097 switch (control) {
01098 case CE_PushButton:
01099 p->fillRect(r, Qt::color1);
01100 break;
01101
01102 default:
01103 QCommonStyle::drawControlMask(control, p, widget, r, data);
01104 break;
01105 }
01106 }
01107
01108 QRect LightStyleV3::subElementRect(SubElement subelement, const QWidget *widget) const
01109 {
01110 QRect rect;
01111
01112 switch (subelement) {
01113 case SR_PushButtonFocusRect:
01114 {
01115 rect = QCommonStyle::subElementRect( SR_PushButtonContents, widget );
01116 int bm = pixelMetric( PM_ButtonMargin, widget ), hbm = bm / 2;
01117 rect.adjust( hbm, hbm, -hbm, -hbm );
01118 break;
01119 }
01120
01121 case SR_ComboBoxFocusRect:
01122 {
01123 rect = QCommonStyle::subElementRect( SR_ComboBoxFocusRect, widget );
01124 rect.adjust( -1, -1, 1, 1 );
01125 break;
01126 }
01127
01128 case SR_CheckBoxFocusRect:
01129 {
01130 const QCheckBox* cb = static_cast<const QCheckBox*>(widget);
01131
01132
01133 if (cb->text().isEmpty() && (cb->pixmap() == 0) )
01134 {
01135 QRect bounding = cb->rect();
01136 QRect checkbox(bounding.x(), bounding.y() + (bounding.height() - 13)/2,
01137 13, 13);
01138
01139 return checkbox;
01140 }
01141
01142 }
01143
01144
01145 default:
01146 rect = QCommonStyle::subElementRect(subelement, widget);
01147 break;
01148 }
01149
01150 return rect;
01151 }
01152
01153 void LightStyleV3::drawComplexControl( ComplexControl control,
01154 QPainter* p,
01155 const QWidget* widget,
01156 const QRect& r,
01157 const QColorGroup& cg,
01158 SFlags flags,
01159 SCFlags controls,
01160 SCFlags active,
01161 const QStyleOption &data ) const
01162 {
01163 switch (control) {
01164 case CC_ComboBox:
01165 {
01166 const QComboBox *combobox = (const QComboBox *) widget;
01167 QRect frame, arrow, field;
01168 frame =
01169 QStyle::visualRect(querySubControlMetrics(CC_ComboBox, widget,
01170 SC_ComboBoxFrame, data),
01171 widget);
01172 arrow =
01173 QStyle::visualRect(querySubControlMetrics(CC_ComboBox, widget,
01174 SC_ComboBoxArrow, data),
01175 widget);
01176 field =
01177 QStyle::visualRect(querySubControlMetrics(CC_ComboBox, widget,
01178 SC_ComboBoxEditField, data),
01179 widget);
01180
01181 if ((controls & SC_ComboBoxFrame) && frame.isValid())
01182 drawPrimitive( PE_Panel, p, frame, cg, flags | Style_Sunken );
01183
01184 if ((controls & SC_ComboBoxArrow) && arrow.isValid()) {
01185 drawLightEtch( p, arrow, cg.button(), ( active == SC_ComboBoxArrow ) );
01186 arrow.adjust( 1, 1, -1, -1 );
01187 p->fillRect( arrow, cg.brush( QPalette::Button ) );
01188 arrow.adjust(3, 1, -1, -1);
01189 drawPrimitive(PE_ArrowDown, p, arrow, cg, flags);
01190 }
01191
01192 if ((controls & SC_ComboBoxEditField) && field.isValid()) {
01193 if (flags & Style_HasFocus) {
01194 if (! combobox->editable()) {
01195 QRect fr =
01196 QStyle::visualRect( subRect( SR_ComboBoxFocusRect, widget ),
01197 widget );
01198 p->fillRect( fr, cg.brush( QPalette::Highlight ) );
01199 drawPrimitive( PE_FocusRect, p, fr, cg,
01200 flags | Style_FocusAtBorder,
01201 QStyleOption(cg.highlight()));
01202 }
01203
01204 p->setPen(cg.highlightedText());
01205 } else {
01206 p->fillRect( field, ( ( flags & Style_Enabled ) ?
01207 cg.brush( QPalette::Base ) :
01208 cg.brush( QPalette::Background ) ) );
01209 p->setPen( cg.text() );
01210 }
01211 }
01212
01213 break;
01214 }
01215
01216 case CC_SpinWidget:
01217 {
01218 const Q3SpinWidget *spinwidget = (const Q3SpinWidget *) widget;
01219 QRect frame, up, down;
01220
01221 frame = querySubControlMetrics(CC_SpinWidget, widget,
01222 SC_SpinWidgetFrame, data);
01223 up = spinwidget->upRect();
01224 down = spinwidget->downRect();
01225
01226 if ((controls & SC_SpinWidgetFrame) && frame.isValid())
01227 drawPrimitive( PE_Panel, p, frame, cg, flags | Style_Sunken );
01228
01229 if ((controls & SC_SpinWidgetUp) && up.isValid()) {
01230 PrimitiveElement pe = PE_SpinWidgetUp;
01231 if ( spinwidget->buttonSymbols() == Q3SpinWidget::PlusMinus )
01232 pe = PE_SpinWidgetPlus;
01233
01234 p->setPen( cg.background() );
01235 p->drawLine( up.topLeft(), up.bottomLeft() );
01236
01237 up.adjust( 1, 0, 0, 0 );
01238 p->fillRect( up, cg.brush( QPalette::Button ) );
01239 drawLightEtch( p, up, cg.button(), ( active == SC_SpinWidgetUp ) );
01240
01241 up.addCoords( 1, 0, 0, 0 );
01242 drawPrimitive(pe, p, up, cg, flags |
01243 ((active == SC_SpinWidgetUp) ?
01244 Style_On | Style_Sunken : Style_Raised));
01245 }
01246
01247 if ((controls & SC_SpinWidgetDown) && down.isValid()) {
01248 PrimitiveElement pe = PE_SpinWidgetDown;
01249 if ( spinwidget->buttonSymbols() == Q3SpinWidget::PlusMinus )
01250 pe = PE_SpinWidgetMinus;
01251
01252 p->setPen( cg.background() );
01253 p->drawLine( down.topLeft(), down.bottomLeft() );
01254
01255 down.adjust( 1, 0, 0, 0 );
01256 p->fillRect( down, cg.brush( QPalette::Button ) );
01257 drawLightEtch( p, down, cg.button(), ( active == SC_SpinWidgetDown ) );
01258
01259 down.adjust( 1, 0, 0, 0 );
01260 drawPrimitive(pe, p, down, cg, flags |
01261 ((active == SC_SpinWidgetDown) ?
01262 Style_On | Style_Sunken : Style_Raised));
01263 }
01264
01265 break;
01266 }
01267
01268 case CC_ScrollBar:
01269 {
01270 const QScrollBar *scrollbar = (const QScrollBar *) widget;
01271 QRect addline, subline, subline2, addpage, subpage, slider, first, last;
01272 bool maxedOut = (scrollbar->minValue() == scrollbar->maxValue());
01273
01274 subline = querySubControlMetrics(control, widget, SC_ScrollBarSubLine, data);
01275 addline = querySubControlMetrics(control, widget, SC_ScrollBarAddLine, data);
01276 subpage = querySubControlMetrics(control, widget, SC_ScrollBarSubPage, data);
01277 addpage = querySubControlMetrics(control, widget, SC_ScrollBarAddPage, data);
01278 slider = querySubControlMetrics(control, widget, SC_ScrollBarSlider, data);
01279 first = querySubControlMetrics(control, widget, SC_ScrollBarFirst, data);
01280 last = querySubControlMetrics(control, widget, SC_ScrollBarLast, data);
01281
01282 subline2 = addline;
01283 if (scrollbar->orientation() == Qt::Horizontal)
01284 subline2.translate(-addline.width(), 0);
01285 else
01286 subline2.translate(0, -addline.height());
01287
01288 if ((controls & SC_ScrollBarSubLine) && subline.isValid()) {
01289 drawPrimitive(PE_ScrollBarSubLine, p, subline, cg,
01290 Style_Enabled | ((active == SC_ScrollBarSubLine) ?
01291 Style_Down : Style_Default) |
01292 ((scrollbar->orientation() == Qt::Horizontal) ?
01293 Style_Horizontal : 0));
01294
01295 if (subline2.isValid())
01296 drawPrimitive(PE_ScrollBarSubLine, p, subline2, cg,
01297 Style_Enabled | ((active == SC_ScrollBarSubLine) ?
01298 Style_Down : Style_Default) |
01299 ((scrollbar->orientation() == Qt::Horizontal) ?
01300 Style_Horizontal : 0));
01301 }
01302 if ((controls & SC_ScrollBarAddLine) && addline.isValid())
01303 drawPrimitive(PE_ScrollBarAddLine, p, addline, cg,
01304 Style_Enabled | ((active == SC_ScrollBarAddLine) ?
01305 Style_Down : Style_Default) |
01306 ((scrollbar->orientation() == Qt::Horizontal) ?
01307 Style_Horizontal : 0));
01308 if ((controls & SC_ScrollBarSubPage) && subpage.isValid())
01309 drawPrimitive(PE_ScrollBarSubPage, p, subpage, cg,
01310 Style_Enabled | ((active == SC_ScrollBarSubPage) ?
01311 Style_Down : Style_Default) |
01312 ((scrollbar->orientation() == Qt::Horizontal) ?
01313 Style_Horizontal : 0));
01314 if ((controls & SC_ScrollBarAddPage) && addpage.isValid())
01315 drawPrimitive(PE_ScrollBarAddPage, p, addpage, cg,
01316 ((maxedOut) ? Style_Default : Style_Enabled) |
01317 ((active == SC_ScrollBarAddPage) ?
01318 Style_Down : Style_Default) |
01319 ((scrollbar->orientation() == Qt::Horizontal) ?
01320 Style_Horizontal : 0));
01321 if ((controls & SC_ScrollBarFirst) && first.isValid())
01322 drawPrimitive(PE_ScrollBarFirst, p, first, cg,
01323 Style_Enabled | ((active == SC_ScrollBarFirst) ?
01324 Style_Down : Style_Default) |
01325 ((scrollbar->orientation() == Qt::Horizontal) ?
01326 Style_Horizontal : 0));
01327 if ((controls & SC_ScrollBarLast) && last.isValid())
01328 drawPrimitive(PE_ScrollBarLast, p, last, cg,
01329 Style_Enabled | ((active == SC_ScrollBarLast) ?
01330 Style_Down : Style_Default) |
01331 ((scrollbar->orientation() == Qt::Horizontal) ?
01332 Style_Horizontal : 0));
01333 if ((controls & SC_ScrollBarSlider) && slider.isValid()) {
01334 drawPrimitive(PE_ScrollBarSlider, p, slider, cg,
01335 Style_Enabled | ((active == SC_ScrollBarSlider) ?
01336 Style_Down : Style_Default) |
01337 ((scrollbar->orientation() == Qt::Horizontal) ?
01338 Style_Horizontal : 0));
01339
01340
01341 if (scrollbar->hasFocus()) {
01342 QRect fr(slider.x() + 2, slider.y() + 2,
01343 slider.width() - 5, slider.height() - 5);
01344 drawPrimitive(PE_FocusRect, p, fr, cg, Style_Default);
01345 }
01346 }
01347
01348 break;
01349 }
01350
01351 case CC_Slider:
01352 {
01353 const QSlider *slider = (const QSlider *) widget;
01354 QRect groove = querySubControlMetrics(CC_Slider, widget, SC_SliderGroove,
01355 data),
01356 handle = querySubControlMetrics(CC_Slider, widget, SC_SliderHandle,
01357 data);
01358
01359 if ((controls & SC_SliderGroove) && groove.isValid()) {
01360 QColor grooveColor = cg.midlight();
01361 if (!(flags & Style_Enabled))
01362 grooveColor = cg.background();
01363
01364
01365 QBrush brush(grooveColor);
01366 drawLightBevel( p, groove, cg,
01367 ( ( flags | Style_Raised ) ^ Style_Raised ) |
01368 ( ( flags & Style_Enabled ) ? Style_Sunken :
01369 Style_Default ), 2, true, true,
01370 &brush );
01371 groove.adjust( 2, 2, -2, -2 );
01372 drawLightEtch( p, groove, grooveColor, false );
01373
01374 if (flags & Style_HasFocus) {
01375 groove.adjust( -2, -2, 2, 2 );
01376 drawPrimitive( PE_FocusRect, p, groove, cg, flags );
01377 }
01378 }
01379
01380 if ((controls & SC_SliderHandle) && handle.isValid()) {
01381 QColor sliderColor = cg.highlight();
01382 if (!(flags & Style_Enabled))
01383 sliderColor = cg.button();
01384
01385 p->setPen( sliderColor.light() );
01386
01387 p->drawLine( handle.topLeft(), handle.topRight() );
01388 p->drawLine( handle.left(), handle.top() + 1,
01389 handle.left(), handle.bottom() - 1 );
01390 p->setPen( sliderColor.dark() );
01391 p->drawLine( handle.left(), handle.bottom(),
01392 handle.right() - 1, handle.bottom() );
01393 p->drawLine( handle.topRight(), handle.bottomRight() );
01394 handle.adjust( 1, 1, -1, -1 );
01395 p->fillRect( handle, sliderColor );
01396 p->setPen( cg.midlight() );
01397
01398 if ( slider->orientation() == Qt::Horizontal )
01399 p->drawLine( handle.left() + handle.width() / 2,
01400 handle.top() + 1,
01401 handle.left() + handle.width() / 2,
01402 handle.bottom() - 1 );
01403 else
01404 p->drawLine( handle.left() + 1,
01405 handle.top() + handle.height() / 2,
01406 handle.right() - 1,
01407 handle.top() + handle.height() / 2 );
01408 }
01409
01410 if (controls & SC_SliderTickmarks)
01411 QCommonStyle::drawComplexControl(control, p, widget, r, cg, flags,
01412 SC_SliderTickmarks, active, data );
01413 break;
01414 }
01415
01416 case CC_ListView:
01417
01418 basestyle->drawComplexControl(control, p, widget, r, cg, flags,
01419 controls, active, data);
01420 break;
01421
01422 default:
01423 QCommonStyle::drawComplexControl(control, p, widget, r, cg, flags,
01424 controls, active, data);
01425 break;
01426 }
01427 }
01428
01429 QRect LightStyleV3::querySubControlMetrics( ComplexControl control,
01430 const QWidget *widget,
01431 SubControl sc,
01432 const QStyleOption &data ) const
01433 {
01434 QRect ret;
01435
01436 switch (control) {
01437 case CC_ComboBox:
01438 {
01439 int fw = pixelMetric( PM_DefaultFrameWidth, widget );
01440 int sb = pixelMetric( PM_ScrollBarExtent );
01441
01442 switch ( sc ) {
01443 case SC_ComboBoxFrame:
01444 ret = widget->rect();
01445 break;
01446 case SC_ComboBoxArrow:
01447 ret.setRect( widget->width() - fw - sb, fw,
01448 sb, widget->height() - fw*2 );
01449 break;
01450 case SC_ComboBoxEditField:
01451 ret.setRect( fw, fw, widget->width() - fw*2 - sb - 1,
01452 widget->height() - fw*2 );
01453 break;
01454 default:
01455 break;
01456 }
01457
01458 break;
01459 }
01460
01461 case CC_ScrollBar:
01462 {
01463 const QScrollBar *scrollbar = (const QScrollBar *) widget;
01464 int sliderstart = scrollbar->sliderStart();
01465 int sbextent = pixelMetric(PM_ScrollBarExtent, widget);
01466 int maxlen = ((scrollbar->orientation() == Qt::Horizontal) ?
01467 scrollbar->width() : scrollbar->height()) - (sbextent * 3);
01468 int sliderlen;
01469
01470
01471 if (scrollbar->maxValue() != scrollbar->minValue()) {
01472 uint range = scrollbar->maxValue() - scrollbar->minValue();
01473 sliderlen = (scrollbar->pageStep() * maxlen) /
01474 (range + scrollbar->pageStep());
01475
01476 int slidermin = pixelMetric( PM_ScrollBarSliderMin, widget );
01477 if ( sliderlen < slidermin || range > INT_MAX / 2 )
01478 sliderlen = slidermin;
01479 if ( sliderlen > maxlen )
01480 sliderlen = maxlen;
01481 } else
01482 sliderlen = maxlen;
01483
01484 switch (sc) {
01485 case SC_ScrollBarSubLine:
01486
01487 ret.setRect(0, 0, sbextent, sbextent);
01488 break;
01489
01490 case SC_ScrollBarAddLine:
01491
01492 if (scrollbar->orientation() == Qt::Horizontal)
01493 ret.setRect(scrollbar->width() - sbextent, 0, sbextent, sbextent);
01494 else
01495 ret.setRect(0, scrollbar->height() - sbextent, sbextent, sbextent);
01496 break;
01497
01498 case SC_ScrollBarSubPage:
01499
01500 if (scrollbar->orientation() == Qt::Horizontal)
01501 ret.setRect(sbextent, 0, sliderstart - sbextent, sbextent);
01502 else
01503 ret.setRect(0, sbextent, sbextent, sliderstart - sbextent);
01504 break;
01505
01506 case SC_ScrollBarAddPage:
01507
01508 if (scrollbar->orientation() == Qt::Horizontal)
01509 ret.setRect(sliderstart + sliderlen, 0, maxlen - sliderstart -
01510 sliderlen + sbextent, sbextent);
01511 else
01512 ret.setRect(0, sliderstart + sliderlen, sbextent, maxlen -
01513 sliderstart - sliderlen + sbextent);
01514 break;
01515
01516 case SC_ScrollBarGroove:
01517 if (scrollbar->orientation() == Qt::Horizontal)
01518 ret.setRect(sbextent, 0, maxlen, sbextent );
01519 else
01520 ret.setRect(0, sbextent, sbextent, maxlen );
01521 break;
01522
01523 case SC_ScrollBarSlider:
01524 if (scrollbar->orientation() == Qt::Horizontal)
01525 ret.setRect(sliderstart, 0, sliderlen, sbextent);
01526 else
01527 ret.setRect(0, sliderstart, sbextent, sliderlen);
01528 break;
01529
01530 default:
01531 break;
01532 }
01533
01534 break;
01535 }
01536
01537 case CC_Slider:
01538 {
01539 const QSlider *slider = (const QSlider *) widget;
01540 int tickOffset = pixelMetric( PM_SliderTickmarkOffset, widget );
01541 int thickness = pixelMetric( PM_SliderControlThickness, widget );
01542
01543 switch ( sc ) {
01544 case SC_SliderGroove:
01545 if ( slider->orientation() == Qt::Horizontal )
01546 ret.setRect( 0, tickOffset, slider->width(), thickness );
01547 else
01548 ret.setRect( tickOffset, 0, thickness, slider->height() );
01549 break;
01550
01551 case SC_SliderHandle:
01552 {
01553 int pos = slider->sliderStart();
01554 int len = pixelMetric( PM_SliderLength, widget );
01555
01556 if ( slider->orientation() == Qt::Horizontal )
01557 ret.setRect( pos + 2, tickOffset + 2, len - 4, thickness - 4 );
01558 else
01559 ret.setRect( tickOffset + 2, pos + 2, thickness - 4, len - 4 );
01560 break;
01561 }
01562
01563 default:
01564 ret = QCommonStyle::querySubControlMetrics(control, widget, sc, data);
01565 break;
01566 }
01567
01568 break;
01569 }
01570
01571 default:
01572 ret = QCommonStyle::querySubControlMetrics(control, widget, sc, data);
01573 break;
01574 }
01575
01576 return ret;
01577 }
01578
01579 QStyle::SubControl LightStyleV3::querySubControl( ComplexControl control,
01580 const QWidget *widget,
01581 const QPoint &pos,
01582 const QStyleOption &data ) const
01583 {
01584 QStyle::SubControl ret =
01585 QCommonStyle::querySubControl(control, widget, pos, data);
01586
01587
01588
01589 if (control == CC_ScrollBar &&
01590 ret == SC_None)
01591 ret = SC_ScrollBarSubLine;
01592
01593 return ret;
01594 }
01595
01596 int LightStyleV3::pixelMetric( PixelMetric metric,
01597 const QWidget *widget ) const
01598 {
01599 int ret;
01600
01601 switch (metric) {
01602 case PM_ButtonMargin:
01603 ret = 6;
01604 break;
01605
01606 case PM_ButtonShiftHorizontal:
01607 case PM_ButtonShiftVertical:
01608 ret = 0;
01609 break;
01610
01611 case PM_ButtonDefaultIndicator:
01612 ret = 0;
01613 break;
01614
01615 case PM_DefaultFrameWidth:
01616 ret = 2;
01617 break;
01618
01619 case PM_IndicatorWidth:
01620 case PM_IndicatorHeight:
01621 case PM_ExclusiveIndicatorWidth:
01622 case PM_ExclusiveIndicatorHeight:
01623 ret = 13;
01624 break;
01625
01626 case PM_TabBarTabOverlap:
01627 case PM_TabBarBaseOverlap:
01628 ret = 0;
01629 break;
01630
01631 case PM_ScrollBarExtent:
01632 case PM_ScrollBarSliderMin:
01633 ret = 15;
01634 break;
01635
01636 case PM_MenuBarFrameWidth:
01637 ret = 1;
01638 break;
01639
01640 case PM_ProgressBarChunkWidth:
01641 ret = 1;
01642 break;
01643
01644 case PM_DockWindowHandleExtent:
01645 ret = 8;
01646 break;
01647
01648 case PM_DockWindowSeparatorExtent:
01649 ret = 8;
01650 break;
01651
01652 case PM_SplitterWidth:
01653 ret = 8;
01654 break;
01655
01656 case PM_SliderLength:
01657 ret = 25;
01658 break;
01659
01660 case PM_SliderThickness:
01661 ret = 11;
01662 break;
01663
01664 case PM_SliderControlThickness:
01665 {
01666 const QSlider * sl = (const QSlider *) widget;
01667 int space = (sl->orientation() == Qt::Horizontal) ? sl->height()
01668 : sl->width();
01669 int ticks = sl->tickmarks();
01670 int n = 0;
01671 if ( ticks & QSlider::TicksAbove ) n++;
01672 if ( ticks & QSlider::TicksBelow ) n++;
01673 if ( !n ) {
01674 ret = space;
01675 break;
01676 }
01677
01678 int thick = 6;
01679
01680 space -= thick;
01681
01682 if ( space > 0 )
01683 thick += (space * 2) / (n + 2);
01684 ret = thick;
01685 break;
01686 }
01687
01688 case PM_MaximumDragDistance:
01689 ret = -1;
01690 break;
01691
01692 default:
01693 ret = QCommonStyle::pixelMetric(metric, widget);
01694 break;
01695 }
01696
01697 return ret;
01698 }
01699
01700 QSize LightStyleV3::sizeFromContents( ContentsType contents,
01701 const QWidget *widget,
01702 const QSize &contentsSize,
01703 const QStyleOption &data ) const
01704 {
01705 QSize ret;
01706
01707 switch (contents) {
01708 case CT_ComboBox:
01709 {
01710 int fw = pixelMetric( PM_DefaultFrameWidth, widget ) * 2;
01711 int sb = pixelMetric( PM_ScrollBarExtent );
01712 int w = contentsSize.width();
01713 int h = contentsSize.height();
01714
01715 w += fw + sb + 1;
01716 h += fw;
01717
01718
01719 if ( h < 21 )
01720 h = 21;
01721
01722 ret = QSize( w, h );
01723 break;
01724 }
01725
01726 case CT_PushButton:
01727 {
01728 const QPushButton *button = (const QPushButton *) widget;
01729 ret = QCommonStyle::sizeFromContents( contents, widget, contentsSize, data );
01730 int w = ret.width(), h = ret.height();
01731 int dbi = pixelMetric( PM_ButtonDefaultIndicator, widget ) * 2;
01732 int mw = 80 - dbi, mh = 25 - dbi;
01733
01734
01735 if ( ! button->text().isEmpty() ) {
01736
01737 if ( w < mw )
01738 w = mw;
01739 if ( h < mh )
01740 h = mh;
01741 }
01742
01743 ret = QSize( w, h );
01744 break;
01745 }
01746
01747 case CT_PopupMenuItem:
01748 {
01749 if (! widget || data.isDefault())
01750 break;
01751
01752 QMenuItem *mi = data.menuItem();
01753 const QMenu *popupmenu = (const QMenu *) widget;
01754 int maxpmw = data.maxIconWidth();
01755 int w = contentsSize.width(), h = contentsSize.height();
01756
01757 if (mi->custom()) {
01758 w = mi->custom()->sizeHint().width();
01759 h = mi->custom()->sizeHint().height();
01760 if (! mi->custom()->fullSpan() && h < 22)
01761 h = 22;
01762 } else if(mi->widget()) {
01763 } else if (mi->isSeparator()) {
01764 w = 10;
01765 h = 4;
01766 } else {
01767
01768 if (h < 16)
01769 h = 16;
01770 if (mi->pixmap())
01771 h = qMax(h, mi->pixmap()->height());
01772 else if (! mi->text().isNull())
01773 h = qMax(h, popupmenu->fontMetrics().height() + 2);
01774 if (mi->iconSet() != 0)
01775 h = qMax(h, mi->iconSet()->pixmap(QIcon::Small,
01776 QIcon::Normal).height());
01777 h += 2;
01778 }
01779
01780
01781
01782
01783 maxpmw = qMax(maxpmw, 16);
01784 w += (maxpmw * 2) + 8;
01785
01786 if (! mi->text().isNull() && mi->text().find('\t') >= 0)
01787 w += 8;
01788
01789 ret = QSize(w, h);
01790 break;
01791 }
01792
01793 case CT_ProgressBar:
01794 {
01795 const QProgressBar* pb = static_cast<const QProgressBar*>(widget);
01796
01797
01798
01799
01800 if (pb->percentageVisible() &&
01801 (pb->indicatorFollowsStyle() || ! pb->centerIndicator()))
01802 {
01803 int addw = pb->fontMetrics().width("100%") + 6;
01804 return QSize(contentsSize.width() + addw, contentsSize.height());
01805 }
01806 else
01807 return contentsSize;
01808
01809 break;
01810 }
01811
01812 default:
01813 ret = QCommonStyle::sizeFromContents(contents, widget, contentsSize, data);
01814 break;
01815 }
01816
01817 return ret;
01818 }
01819
01820 int LightStyleV3::styleHint( StyleHint stylehint,
01821 const QWidget *widget,
01822 const QStyleOption &option,
01823 QStyleHintReturn* returnData ) const
01824 {
01825 int ret;
01826
01827 switch (stylehint) {
01828 case SH_EtchDisabledText:
01829 case SH_Slider_SnapToValue:
01830 case SH_PrintDialog_RightAlignButtons:
01831 case SH_FontDialog_SelectAssociatedText:
01832 case SH_MenuBar_AltKeyNavigation:
01833 case SH_MenuBar_MouseTracking:
01834 case SH_PopupMenu_MouseTracking:
01835 case SH_ComboBox_ListMouseTracking:
01836 case SH_ScrollBar_MiddleClickAbsolutePosition:
01837 ret = 1;
01838 break;
01839
01840 case SH_MainWindow_SpaceBelowMenuBar:
01841 ret = 0;
01842 break;
01843
01844 case SH_ScrollBar_BackgroundMode:
01845 ret = Qt::NoBackground;
01846 break;
01847
01848 default:
01849 ret = QCommonStyle::styleHint(stylehint, widget, option, returnData);
01850 break;
01851 }
01852
01853 return ret;
01854 }
01855
01856 QPixmap LightStyleV3::standardPixmap( StandardPixmap standardpixmap,
01857 const QWidget *widget,
01858 const QStyleOption &data ) const
01859 {
01860 return basestyle->standardPixmap( standardpixmap, widget, data );
01861 }
01862 #include "lightstyle-v3.moc"