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