Make a branch to make krunner Good Enough For Aaron™.
[kdebase/uwolfer.git] / runtime / kstyles / light / lightstyle-v2.cpp
blob51eef03a6470cc7c2e6aacb57532ffd69d598570
1 /*
2 Copyright (c) 2000-2001 Trolltech AS (info@trolltech.com)
4 Permission is hereby granted, free of charge, to any person obtaining a
5 copy of this software and associated documentation files (the "Software"),
6 to deal in the Software without restriction, including without limitation
7 the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 and/or sell copies of the Software, and to permit persons to whom the
9 Software is furnished to do so, subject to the following conditions:
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 DEALINGS IN THE SOFTWARE.
23 #include "lightstyle-v2.h"
25 #include "QtGui/QMenuBar"
26 #include "QtGui/QApplication"
27 #include "QtGui/QPainter"
28 #include "QtGui/QColorGroup"
29 #include "QtGui/QPushButton"
30 #include "QtGui/qdrawutil.h"
31 #include "QtGui/QProgressBar"
32 #include "QtGui/QScrollBar"
33 #include "QtGui/QTabBar"
34 #include "QtCore/QPointer"
35 #include "QtGui/QLayout"
36 #include "QtGui/QLineEdit"
37 #include "QtGui/QImage"
38 #include "QtGui/QComboBox"
39 #include "QtGui/QSlider"
40 #include "QtGui/QStyleFactory"
41 #include <Qt3Support/Q3PointArray>
44 class LightStyleV2Private
46 public:
47 LightStyleV2Private()
48 : ref(1)
50 basestyle = QStyleFactory::create( "Windows" );
51 if ( ! basestyle )
52 basestyle = QStyleFactory::create( QStyleFactory::keys().first() );
53 if ( ! basestyle )
54 qFatal( "LightStyle: could not find a basestyle!" );
57 ~LightStyleV2Private()
59 delete basestyle;
62 QStyle *basestyle;
63 int ref;
66 static LightStyleV2Private *singleton = 0;
69 LightStyleV2::LightStyleV2()
70 : KStyle(AllowMenuTransparency)
72 if (! singleton)
73 singleton = new LightStyleV2Private;
74 else
75 singleton->ref++;
78 LightStyleV2::~LightStyleV2()
80 if (singleton && --singleton->ref <= 0) {
81 delete singleton;
82 singleton = 0;
86 void LightStyleV2::polishPopupMenu( QMenu * menu )
88 KStyle::polishPopupMenu(menu);
91 static void drawLightBevel(QPainter *p, const QRect &r, const QColorGroup &cg,
92 QStyle::State flags, const QBrush *fill = 0)
94 QRect br = r;
95 bool sunken = (flags & (QStyle::State_Down | QStyle::State_On |
96 QStyle::State_Sunken));
98 p->setPen(cg.dark());
99 p->drawRect(r);
101 if (flags & (QStyle::State_Down | QStyle::State_On |
102 QStyle::State_Sunken | QStyle::State_Raised)) {
103 // button bevel
104 if (sunken)
105 p->setPen(cg.mid());
106 else
107 p->setPen(cg.light());
109 p->drawLine(r.x() + 1, r.y() + 2,
110 r.x() + 1, r.y() + r.height() - 3); // left
111 p->drawLine(r.x() + 1, r.y() + 1,
112 r.x() + r.width() - 2, r.y() + 1); // top
114 if (sunken)
115 p->setPen(cg.light());
116 else
117 p->setPen(cg.mid());
119 p->drawLine(r.x() + r.width() - 2, r.y() + 2,
120 r.x() + r.width() - 2, r.y() + r.height() - 3); // right
121 p->drawLine(r.x() + 1, r.y() + r.height() - 2,
122 r.x() + r.width() - 2, r.y() + r.height() - 2); // bottom
124 br.adjust(2, 2, -2, -2);
125 } else
126 br.adjust(1, 1, -1, -1);
128 // fill
129 if (fill) p->fillRect(br, *fill);
132 void LightStyleV2::drawPrimitive( PrimitiveElement pe,
133 QPainter *p,
134 const QRect &r,
135 const QColorGroup &cg,
136 SFlags flags,
137 const QStyleOption &data ) const
139 switch (pe) {
140 case PE_HeaderSection:
142 flags = ((flags | Style_Sunken) ^ Style_Sunken) | Style_Raised;
143 //Don't show pressed too often (as in light 3)
144 QBrush fill(cg.background());
145 if (flags & QStyle::State_Enabled)
146 fill.setColor(cg.button());
148 drawLightBevel(p, r, cg, flags, &fill);
149 p->setPen( cg.buttonText() );
150 break;
153 case PE_ButtonCommand:
154 case PE_ButtonBevel:
155 case PE_ButtonTool:
157 const QBrush *fill;
158 if (flags & QStyle::State_Enabled) {
159 if (flags & (QStyle::State_Down |
160 QStyle::State_On |
161 QStyle::State_Sunken))
162 fill = &cg.brush(QPalette::Midlight);
163 else
164 fill = &cg.brush(QPalette::Button);
165 } else
166 fill = &cg.brush(QPalette::Background);
167 drawLightBevel(p, r, cg, flags, fill);
168 break;
171 case PE_ButtonDropDown:
173 QBrush thefill;
174 bool sunken =
175 (flags & (QStyle::State_Down | QStyle::State_On | QStyle::State_Sunken));
177 if (flags & QStyle::State_Enabled) {
178 if (sunken)
179 thefill = cg.brush(QPalette::Midlight);
180 else
181 thefill = cg.brush(QPalette::Button);
182 } else
183 thefill = cg.brush(QPalette::Background);
185 p->setPen(cg.dark());
186 p->drawLine(r.topLeft(), r.topRight());
187 p->drawLine(r.topRight(), r.bottomRight());
188 p->drawLine(r.bottomRight(), r.bottomLeft());
190 if (flags & (QStyle::State_Down | QStyle::State_On |
191 QStyle::State_Sunken | QStyle::State_Raised)) {
192 // button bevel
193 if (sunken)
194 p->setPen(cg.mid());
195 else
196 p->setPen(cg.light());
198 p->drawLine(r.x(), r.y() + 2,
199 r.x(), r.y() + r.height() - 3); // left
200 p->drawLine(r.x(), r.y() + 1,
201 r.x() + r.width() - 2, r.y() + 1); // top
203 if (sunken)
204 p->setPen(cg.light());
205 else
206 p->setPen(cg.mid());
208 p->drawLine(r.x() + r.width() - 2, r.y() + 2,
209 r.x() + r.width() - 2, r.y() + r.height() - 3); // right
210 p->drawLine(r.x() + 1, r.y() + r.height() - 2,
211 r.x() + r.width() - 2, r.y() + r.height() - 2); // bottom
214 p->fillRect(r.x() + 1, r.y() + 2, r.width() - 3, r.height() - 4, thefill);
215 break;
218 case PE_ButtonDefault:
219 p->setPen(cg.dark());
220 p->setBrush(cg.light());
221 p->drawRect(r);
222 break;
224 case PE_Indicator:
225 const QBrush *fill;
226 if (! (flags & Style_Enabled))
227 fill = &cg.brush(QPalette::Background);
228 else if (flags & Style_Down)
229 fill = &cg.brush(QPalette::Mid);
230 else
231 fill = &cg.brush(QPalette::Base);
232 drawLightBevel(p, r, cg, flags | Style_Sunken, fill);
234 p->setPen(cg.text());
235 if (flags & Style_NoChange) {
236 p->drawLine(r.x() + 3, r.y() + r.height() / 2,
237 r.x() + r.width() - 4, r.y() + r.height() / 2);
238 p->drawLine(r.x() + 3, r.y() + 1 + r.height() / 2,
239 r.x() + r.width() - 4, r.y() + 1 + r.height() / 2);
240 p->drawLine(r.x() + 3, r.y() - 1 + r.height() / 2,
241 r.x() + r.width() - 4, r.y() - 1 + r.height() / 2);
242 } else if (flags & Style_On) {
243 p->drawLine(r.x() + 4, r.y() + 3,
244 r.x() + r.width() - 4, r.y() + r.height() - 5);
245 p->drawLine(r.x() + 3, r.y() + 3,
246 r.x() + r.width() - 4, r.y() + r.height() - 4);
247 p->drawLine(r.x() + 3, r.y() + 4,
248 r.x() + r.width() - 5, r.y() + r.height() - 4);
249 p->drawLine(r.x() + 3, r.y() + r.height() - 5,
250 r.x() + r.width() - 5, r.y() + 3);
251 p->drawLine(r.x() + 3, r.y() + r.height() - 4,
252 r.x() + r.width() - 4, r.y() + 3);
253 p->drawLine(r.x() + 4, r.y() + r.height() - 4,
254 r.x() + r.width() - 4, r.y() + 4);
257 break;
259 case PE_ExclusiveIndicator:
261 QRect br = r, // bevel rect
262 cr = r, // contents rect
263 ir = r; // indicator rect
264 br.adjust(1, 1, -1, -1);
265 cr.adjust(2, 2, -2, -2);
266 ir.adjust(3, 3, -3, -3);
268 p->fillRect(r, cg.brush(QPalette::Background));
270 p->setPen(cg.dark());
271 p->drawArc(r, 0, 16*360);
272 p->setPen(cg.mid());
273 p->drawArc(br, 45*16, 180*16);
274 p->setPen(cg.light());
275 p->drawArc(br, 235*16, 180*16);
277 p->setPen(flags & Style_Down ? cg.mid() :
278 (flags & Style_Enabled ? cg.base() : cg.background()));
279 p->setBrush(flags & Style_Down ? cg.mid() :
280 (flags & Style_Enabled ? cg.base() : cg.background()));
281 p->drawEllipse(cr);
283 if (flags & Style_On) {
284 p->setBrush(cg.text());
285 p->drawEllipse(ir);
288 break;
291 case PE_DockWindowHandle:
293 QString title;
294 bool drawTitle = false;
295 if ( p && p->device()->devType() == QInternal::Widget ) {
296 QWidget *w = (QWidget *) p->device();
297 QWidget *p = w->parentWidget();
298 if (p->inherits("QDockWindow") && ! p->inherits("QToolBar")) {
299 drawTitle = true;
300 title = p->caption();
304 flags |= Style_Raised;
305 if (flags & Style_Horizontal) {
306 if (drawTitle) {
307 QPixmap pm(r.height(), r.width());
308 QPainter p2(&pm);
309 p2.fillRect(0, 0, pm.width(), pm.height(),
310 cg.brush(QPalette::Highlight));
311 p2.setPen(cg.highlightedText());
312 p2.drawText(0, 0, pm.width(), pm.height(), Qt::AlignCenter, title);
313 p2.end();
315 QMatrix m;
316 m.rotate(270.0);
317 pm = pm.xForm(m);
318 p->drawPixmap(r.x(), r.y(), pm);
319 } else {
320 p->fillRect(r, cg.background());
321 p->setPen(cg.mid().dark());
322 p->drawLine(r.right() - 6, r.top() + 2,
323 r.right() - 6, r.bottom() - 2);
324 p->drawLine(r.right() - 3, r.top() + 2,
325 r.right() - 3, r.bottom() - 2);
326 p->setPen(cg.light());
327 p->drawLine(r.right() - 5, r.top() + 2,
328 r.right() - 5, r.bottom() - 2);
329 p->drawLine(r.right() - 2, r.top() + 2,
330 r.right() - 2, r.bottom() - 2);
332 } else {
333 if (drawTitle) {
334 p->fillRect(r, cg.brush(QPalette::Highlight));
335 p->setPen(cg.highlightedText());
336 p->drawText(r, Qt::AlignCenter, title);
337 } else {
338 p->fillRect(r, cg.background());
339 p->setPen(cg.mid().dark());
340 p->drawLine(r.left() + 2, r.bottom() - 6,
341 r.right() - 2, r.bottom() - 6);
342 p->drawLine(r.left() + 2, r.bottom() - 3,
343 r.right() - 2, r.bottom() - 3);
344 p->setPen(cg.light());
345 p->drawLine(r.left() + 2, r.bottom() - 5,
346 r.right() - 2, r.bottom() - 5);
347 p->drawLine(r.left() + 2, r.bottom() - 2,
348 r.right() - 2, r.bottom() - 2);
351 break;
354 case PE_DockWindowSeparator:
356 if (r.width() > 20 || r.height() > 20) {
357 if (flags & Style_Horizontal) {
358 p->setPen(cg.mid().dark(120));
359 p->drawLine(r.left() + 1, r.top() + 6, r.left() + 1, r.bottom() - 6);
360 p->setPen(cg.light());
361 p->drawLine(r.left() + 2, r.top() + 6, r.left() + 2, r.bottom() - 6);
362 } else {
363 p->setPen(cg.mid().dark(120));
364 p->drawLine(r.left() + 6, r.top() + 1, r.right() - 6, r.top() + 1);
365 p->setPen(cg.light());
366 p->drawLine(r.left() + 6, r.top() + 2, r.right() - 6, r.top() + 2);
368 } else
369 QCommonStyle::drawPrimitive(pe, p, r, cg, flags, data);
370 break;
373 case PE_Splitter:
374 if (flags & Style_Horizontal)
375 flags &= ~Style_Horizontal;
376 else
377 flags |= Style_Horizontal;
378 // fall through intended
380 case PE_DockWindowResizeHandle:
382 p->fillRect(r, cg.background());
383 if (flags & Style_Horizontal) {
384 p->setPen(cg.highlight().light());
385 p->drawLine(r.left() + 1, r.top() + 1, r.right() - 1, r.top() + 1);
386 p->setPen(cg.highlight());
387 p->drawLine(r.left() + 1, r.top() + 2, r.right() - 1, r.top() + 2);
388 p->setPen(cg.highlight().dark());
389 p->drawLine(r.left() + 1, r.top() + 3, r.right() - 1, r.top() + 3);
390 } else {
391 p->setPen(cg.highlight().light());
392 p->drawLine(r.left() + 1, r.top() + 1, r.left() + 1, r.bottom() - 1);
393 p->setPen(cg.highlight());
394 p->drawLine(r.left() + 2, r.top() + 1, r.left() + 2, r.bottom() - 1);
395 p->setPen(cg.highlight().dark());
396 p->drawLine(r.left() + 3, r.top() + 1, r.left() + 3, r.bottom() - 1);
398 break;
401 case PE_Panel:
402 case PE_PanelPopup:
403 case PE_PanelLineEdit:
404 case PE_PanelTabWidget:
405 case PE_WindowFrame:
407 int lw = data.isDefault() ?
408 pixelMetric(PM_DefaultFrameWidth) : data.lineWidth();
410 if ( ! ( flags & Style_Sunken ) )
411 flags |= Style_Raised;
412 if (lw == 2)
413 drawLightBevel(p, r, cg, flags);
414 else
415 QCommonStyle::drawPrimitive(pe, p, r, cg, flags, data);
416 break;
419 case PE_PanelDockWindow:
421 int lw = data.isDefault() ?
422 pixelMetric(PM_DockWindowFrameWidth) : data.lineWidth();
424 if (lw == 2)
425 drawLightBevel(p, r, cg, flags | Style_Raised,
426 &cg.brush(QPalette::Button));
427 else
428 QCommonStyle::drawPrimitive(pe, p, r, cg, flags, data);
429 break;
432 case PE_PanelMenuBar:
434 int lw = data.isDefault() ?
435 pixelMetric(PM_MenuBarFrameWidth) : data.lineWidth();
437 if (lw == 2)
438 drawLightBevel(p, r, cg, flags, &cg.brush(QPalette::Button));
439 else
440 QCommonStyle::drawPrimitive(pe, p, r, cg, flags, data);
441 break;
444 case PE_ScrollBarSubLine:
446 QRect fr = r, ar = r;
447 PrimitiveElement pe;
449 p->setPen(cg.dark());
450 if (flags & Style_Horizontal) {
451 p->drawLine(r.topLeft(), r.topRight());
452 fr.adjust(0, 1, 0, 0);
453 ar.adjust(0, 1, 0, 0);
454 pe = PE_ArrowLeft;
455 } else {
456 p->drawLine(r.topLeft(), r.bottomLeft());
457 fr.adjust(1, 0, 0, 0);
458 ar.adjust(2, 0, 0, 0);
459 pe = PE_ArrowUp;
462 p->fillRect(fr, cg.brush((flags & Style_Down) ?
463 QPalette::Midlight :
464 QPalette::Background));
465 drawPrimitive(pe, p, ar, cg, flags);
466 break;
469 case PE_ScrollBarAddLine:
471 QRect fr = r, ar = r;
472 PrimitiveElement pe;
474 p->setPen(cg.dark());
475 if (flags & Style_Horizontal) {
476 p->drawLine(r.topLeft(), r.topRight());
477 fr.adjust(0, 1, 0, 0);
478 ar.adjust(0, 1, 0, 0);
479 pe = PE_ArrowRight;
480 } else {
481 p->drawLine(r.topLeft(), r.bottomLeft());
482 fr.adjust(1, 0, 0, 0);
483 ar.adjust(2, 0, 0, 0);
484 pe = PE_ArrowDown;
487 p->fillRect(fr, cg.brush((flags & Style_Down) ?
488 QPalette::Midlight :
489 QPalette::Background));
490 drawPrimitive(pe, p, ar, cg, flags);
491 break;
494 case PE_ScrollBarSubPage:
495 case PE_ScrollBarAddPage:
497 QRect fr = r;
499 p->setPen(cg.dark());
500 if (flags & Style_Horizontal) {
501 p->drawLine(r.topLeft(), r.topRight());
502 p->setPen(cg.background());
503 p->drawLine(r.left(), r.top() + 1, r.right(), r.top() + 1);
504 fr.adjust(0, 2, 0, 0);
505 } else {
506 p->drawLine(r.topLeft(), r.bottomLeft());
507 p->setPen(cg.background());
508 p->drawLine(r.left() + 1, r.top(), r.left() + 1, r.bottom());
509 fr.adjust(2, 0, 0, 0);
512 p->fillRect(fr, cg.brush((flags & Style_Down) ?
513 QPalette::Midlight :
514 QPalette::Mid));
515 break;
518 case PE_ScrollBarSlider:
520 QRect fr = r;
522 p->setPen(cg.dark());
523 if (flags & Style_Horizontal) {
524 p->drawLine(r.topLeft(), r.topRight());
525 p->setPen(cg.background());
526 p->drawLine(r.left(), r.top() + 1, r.right(), r.top() + 1);
527 fr.adjust(0, 2, 0, -1);
528 } else {
529 p->drawLine(r.topLeft(), r.bottomLeft());
530 p->setPen(cg.background());
531 p->drawLine(r.left() + 1, r.top(), r.left() + 1, r.bottom());
532 fr.adjust(2, 0, -1, 0);
535 drawLightBevel(p, fr, cg, ((flags | Style_Down) ^ Style_Down) |
536 ((flags & Style_Enabled) ? Style_Raised : Style_Default),
537 &cg.brush(QPalette::Button));
538 break;
541 case PE_FocusRect:
543 p->setBrush(Qt::NoBrush);
544 if (flags & Style_FocusAtBorder)
545 p->setPen(cg.shadow());
546 else
547 p->setPen(cg.dark());
548 p->drawRect(r);
549 break;
552 case PE_ProgressBarChunk:
553 p->fillRect(r.x(), r.y() + 2, r.width(), r.height() - 4, cg.highlight());
554 break;
556 default:
557 if (pe == PE_HeaderArrow) {
558 if (flags & Style_Down)
559 pe = PE_ArrowDown;
560 else
561 pe = PE_ArrowUp;
565 if (pe >= PE_ArrowUp && pe <= PE_ArrowLeft) {
566 Q3PointArray a;
568 switch ( pe ) {
569 case PE_ArrowUp:
570 a.setPoints( 7, -4,1, 2,1, -3,0, 1,0, -2,-1, 0,-1, -1,-2 );
571 break;
573 case PE_ArrowDown:
574 a.setPoints( 7, -4,-2, 2,-2, -3,-1, 1,-1, -2,0, 0,0, -1,1 );
575 break;
577 case PE_ArrowRight:
578 a.setPoints( 7, -2,-3, -2,3, -1,-2, -1,2, 0,-1, 0,1, 1,0 );
579 break;
581 case PE_ArrowLeft:
582 a.setPoints( 7, 0,-3, 0,3, -1,-2, -1,2, -2,-1, -2,1, -3,0 );
583 break;
585 default:
586 break;
589 if (a.isNull())
590 return;
592 p->save();
593 if ( flags & Style_Enabled ) {
594 a.translate( r.x() + r.width() / 2, r.y() + r.height() / 2 );
595 p->setPen( cg.buttonText() );
596 p->drawLineSegments( a, 0, 3 ); // draw arrow
597 p->drawPoint( a[6] );
598 } else {
599 a.translate( r.x() + r.width() / 2 + 1, r.y() + r.height() / 2 + 1 );
600 p->setPen( cg.light() );
601 p->drawLineSegments( a, 0, 3 ); // draw arrow
602 p->drawPoint( a[6] );
603 a.translate( -1, -1 );
604 p->setPen( cg.mid() );
605 p->drawLineSegments( a, 0, 3 ); // draw arrow
606 p->drawPoint( a[6] );
608 p->restore();
609 } else
610 QCommonStyle::drawPrimitive(pe, p, r, cg, flags, data);
611 break;
615 void LightStyleV2::drawControl( ControlElement control,
616 QPainter *p,
617 const QWidget *widget,
618 const QRect &r,
619 const QColorGroup &cg,
620 SFlags flags,
621 const QStyleOption &data ) const
623 switch (control) {
624 case CE_TabBarTab:
626 const QTabBar* tb = static_cast<const QTabBar*>(widget);
627 bool below = false;
628 QRect tr(r);
629 QRect fr(r);
631 tr.adjust(0, 0, 0, -1);
632 fr.adjust(2, 2, -2, -2);
634 if ( tb->shape() == QTabBar:: RoundedSouth || tb->shape() == QTabBar:: TriangularSouth) {
635 tr = r; tr.adjust(0, 1, 0, 0);
636 fr = r; fr.adjust(2, 2,-2, -4);
637 below = true;
640 if (! (flags & Style_Selected)) {
641 if (below) {
642 tr.adjust(0, 0, 0, -1);
643 tr.adjust(0, 0, 0, -1);
644 } else {
645 tr.adjust(0, 1, 0, 0);
646 fr.adjust(0, 1, 0, 0);
649 p->setPen(cg.dark());
650 p->drawRect(tr);
652 if (tr.left() == 0)
653 if (below)
654 p->drawPoint(tr.left(), tr.top() - 1);
655 else
656 p->drawPoint(tr.left(), tr.bottom() + 1);
658 p->setPen(cg.light());
659 if (below) {
660 p->drawLine(tr.left() + 1, tr.top() + 1,
661 tr.left() + 1, tr.bottom() - 2);
662 p->drawLine(tr.left() + 1, tr.bottom() - 1,
663 tr.right() - 1, tr.bottom() - 1);
664 } else {
665 p->drawLine(tr.left() + 1, tr.bottom() - 1,
666 tr.left() + 1, tr.top() + 2);
667 p->drawLine(tr.left() + 1, tr.top() + 1,
668 tr.right() - 1, tr.top() + 1);
671 if (below) {
672 if (tr.left() == 0)
673 p->drawLine(tr.left() + 1, tr.top() - 1,
674 tr.right(), tr.top() - 1);
675 else
677 p->setPen(cg.mid()); //To match lower border of the frame
678 p->drawLine(tr.left(), tr.top() - 1,
679 tr.right(), tr.top() - 1);
681 } else {
682 if (tr.left() == 0)
683 p->drawLine(tr.left() + 1, tr.bottom() + 1,
684 tr.right(), tr.bottom() + 1);
685 else
686 p->drawLine(tr.left(), tr.bottom() + 1,
687 tr.right(), tr.bottom() + 1);
690 p->setPen(cg.mid());
692 if (below) {
693 p->drawLine(tr.right() - 1, tr.bottom() - 2,
694 tr.right() - 1, tr.top() + 1);
695 } else {
696 p->drawLine(tr.right() - 1, tr.top() + 2,
697 tr.right() - 1, tr.bottom() - 1);
699 } else {
700 p->setPen(cg.dark());
701 if (tr.left() == 0)
702 if (below)
703 p->drawLine(tr.left(), tr.top() - 1,
704 tr.left(), tr.bottom() - 1);
705 else
706 p->drawLine(tr.left(), tr.bottom() + 1,
707 tr.left(), tr.top() + 1);
708 else
709 if (below)
710 p->drawLine(tr.left(), tr.bottom(),
711 tr.left(), tr.top() + 1);
712 else
713 p->drawLine(tr.left(), tr.bottom(),
714 tr.left(), tr.top() + 1);
716 if (below) {
717 p->drawLine(tr.left(), tr.bottom(),
718 tr.right(), tr.bottom());
719 p->drawLine(tr.right(), tr.bottom() - 1,
720 tr.right(), tr.top());
722 } else {
723 p->drawLine(tr.left(), tr.top(),
724 tr.right(), tr.top());
725 p->drawLine(tr.right(), tr.top() + 1,
726 tr.right(), tr.bottom());
729 p->setPen(cg.light());
730 if (tr.left() == 0)
731 if (below)
732 p->drawLine(tr.left() + 1, tr.top() - 2,
733 tr.left() + 1, tr.bottom() - 2);
734 else
735 p->drawLine(tr.left() + 1, tr.bottom() + 2,
736 tr.left() + 1, tr.top() + 2);
737 else {
738 if (below) {
739 p->drawLine(tr.left() + 1, tr.top(),
740 tr.left() + 1, tr.bottom() - 2);
741 p->drawPoint(tr.left(), tr.top() - 1);
743 } else {
744 p->drawLine(tr.left() + 1, tr.bottom(),
745 tr.left() + 1, tr.top() + 2);
746 p->drawPoint(tr.left(), tr.bottom() + 1);
750 if (below) {
751 p->drawLine(tr.left() + 1, tr.bottom() - 1,
752 tr.right() - 1, tr.bottom() - 1);
753 p->drawPoint(tr.right(), tr.top() - 1);
755 p->setPen(cg.mid());
756 p->drawLine(tr.right() - 1, tr.bottom() - 2,
757 tr.right() - 1, tr.top());
758 } else {
759 p->drawLine(tr.left() + 1, tr.top() + 1,
760 tr.right() - 1, tr.top() + 1);
761 p->drawPoint(tr.right(), tr.bottom() + 1);
763 p->setPen(cg.mid());
764 p->drawLine(tr.right() - 1, tr.top() + 2,
765 tr.right() - 1, tr.bottom());
769 p->fillRect(fr, ((flags & Style_Selected) ?
770 cg.background() : cg.mid()));
771 break;
774 case CE_PopupMenuItem:
776 if (! widget || data.isDefault())
777 break;
779 const QMenu *popupmenu = (const QMenu *) widget;
780 QMenuItem *mi = data.menuItem();
781 int tab = data.tabWidth();
782 int maxpmw = data.maxIconWidth();
784 if ( mi && mi->isSeparator() ) {
785 // draw separator (bg first, though)
786 if ( widget->erasePixmap() && !widget->erasePixmap()->isNull() )
787 p->drawPixmap( r.topLeft(), *widget->erasePixmap(), r );
788 else
789 p->fillRect(r, cg.brush(QPalette::Button));
791 p->setPen(cg.mid().dark(120));
792 p->drawLine(r.left() + 12, r.top() + 1,
793 r.right() - 12, r.top() + 1);
794 p->setPen(cg.light());
795 p->drawLine(r.left() + 12, r.top() + 2,
796 r.right() - 12, r.top() + 2);
797 break;
800 if (flags & Style_Active)
801 qDrawShadePanel(p, r, cg, true, 1,
802 &cg.brush(QPalette::Midlight));
803 else if ( widget->erasePixmap() && !widget->erasePixmap()->isNull() )
804 p->drawPixmap( r.topLeft(), *widget->erasePixmap(), r );
805 else
806 p->fillRect(r, cg.brush(QPalette::Button));
808 if ( !mi )
809 break;
811 maxpmw = qMax(maxpmw, 16);
813 QRect cr, ir, tr, sr;
814 // check column
815 cr.setRect(r.left(), r.top(), maxpmw, r.height());
816 // submenu indicator column
817 sr.setCoords(r.right() - maxpmw, r.top(), r.right(), r.bottom());
818 // tab/accelerator column
819 tr.setCoords(sr.left() - tab - 4, r.top(), sr.left(), r.bottom());
820 // item column
821 ir.setCoords(cr.right() + 4, r.top(), tr.right() - 4, r.bottom());
823 bool reverse = QApplication::isRightToLeft();
824 if ( reverse ) {
825 cr = visualRect( cr, r );
826 sr = visualRect( sr, r );
827 tr = visualRect( tr, r );
828 ir = visualRect( ir, r );
831 if (mi->isChecked() &&
832 ! (flags & Style_Active) &
833 (flags & Style_Enabled))
834 qDrawShadePanel(p, cr, cg, true, 1, &cg.brush(QPalette::Midlight));
836 if (mi->iconSet()) {
837 QIcon::Mode mode =
838 (flags & Style_Enabled) ? QIcon::Normal : QIcon::Disabled;
839 if ((flags & Style_Active) && (flags & Style_Enabled))
840 mode = QIcon::Active;
841 QPixmap pixmap;
842 if (popupmenu->isCheckable() && mi->isChecked())
843 pixmap =
844 mi->iconSet()->pixmap( QIcon::Small, mode, QIcon::On );
845 else
846 pixmap =
847 mi->iconSet()->pixmap( QIcon::Small, mode );
848 QRect pmr(QPoint(0, 0), pixmap.size());
849 pmr.moveCenter(cr.center());
850 p->setPen(cg.text());
851 p->drawPixmap(pmr.topLeft(), pixmap);
852 } else if (popupmenu->isCheckable() && mi->isChecked())
853 drawPrimitive(PE_CheckMark, p, cr, cg,
854 (flags & Style_Enabled) | Style_On);
856 QColor textcolor;
857 QColor embosscolor;
858 if (flags & Style_Active) {
859 if (! (flags & Style_Enabled))
860 textcolor = cg.midlight().dark();
861 else
862 textcolor = cg.buttonText();
863 embosscolor = cg.midlight().light();
864 } else if (! (flags & Style_Enabled)) {
865 textcolor = cg.text();
866 embosscolor = cg.light();
867 } else
868 textcolor = embosscolor = cg.buttonText();
869 p->setPen(textcolor);
871 if (mi->custom()) {
872 p->save();
873 if (! (flags & Style_Enabled)) {
874 p->setPen(cg.light());
875 mi->custom()->paint(p, cg, flags & Style_Active,
876 flags & Style_Enabled,
877 ir.x() + 1, ir.y() + 1,
878 ir.width() - 1, ir.height() - 1);
879 p->setPen(textcolor);
881 mi->custom()->paint(p, cg, flags & Style_Active,
882 flags & Style_Enabled,
883 ir.x(), ir.y(),
884 ir.width(), ir.height());
885 p->restore();
888 QString text = mi->text();
889 if (! text.isNull()) {
890 int t = text.find('\t');
892 // draw accelerator/tab-text
893 if (t >= 0) {
894 int alignFlag = Qt::AlignVCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine;
895 alignFlag |= ( reverse ? Qt::AlignLeft : Qt::AlignRight );
896 if (! (flags & Style_Enabled)) {
897 p->setPen(embosscolor);
898 tr.translate(1, 1);
899 p->drawText(tr, alignFlag, text.mid(t + 1));
900 tr.translate(-1, -1);
901 p->setPen(textcolor);
904 p->drawText(tr, alignFlag, text.mid(t + 1));
907 int alignFlag = Qt::AlignVCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine;
908 alignFlag |= ( reverse ? Qt::AlignRight : Qt::AlignLeft );
910 if (! (flags & Style_Enabled)) {
911 p->setPen(embosscolor);
912 ir.translate(1, 1);
913 p->drawText(ir, alignFlag, text, t);
914 ir.translate(-1, -1);
915 p->setPen(textcolor);
918 p->drawText(ir, alignFlag, text, t);
919 } else if (mi->pixmap()) {
920 QPixmap pixmap = *mi->pixmap();
921 if (pixmap.depth() == 1)
922 p->setBackgroundMode(Qt::OpaqueMode);
923 p->drawPixmap(ir.x(), ir.y() + (ir.height() - pixmap.height()) / 2, pixmap);
924 if (pixmap.depth() == 1)
925 p->setBackgroundMode(Qt::TransparentMode);
928 if (mi->popup())
929 drawPrimitive( (reverse ? PE_ArrowLeft : PE_ArrowRight), p, sr, cg, flags);
930 break;
933 case CE_MenuBarEmptyArea:
935 p->fillRect(r, cg.brush(QPalette::Button));
936 break;
939 case CE_DockWindowEmptyArea:
941 p->fillRect(r, cg.brush(QPalette::Button));
942 break;
946 case CE_MenuBarItem:
948 if (flags & Style_Active)
949 qDrawShadePanel(p, r, cg, true, 1, &cg.brush(QPalette::Midlight));
950 else
951 p->fillRect(r, cg.brush(QPalette::Button));
953 if (data.isDefault())
954 break;
956 QMenuItem *mi = data.menuItem();
957 drawItem(p, r, Qt::AlignCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine, cg,
958 flags & Style_Enabled, mi->pixmap(), mi->text(), -1,
959 &cg.buttonText());
960 break;
963 case CE_ProgressBarGroove:
964 drawLightBevel(p, r, cg, Style_Sunken, &cg.brush(QPalette::Background));
965 break;
967 default:
968 QCommonStyle::drawControl(control, p, widget, r, cg, flags, data);
969 break;
973 void LightStyleV2::drawControlMask( ControlElement control,
974 QPainter *p,
975 const QWidget *widget,
976 const QRect &r,
977 const QStyleOption &data ) const
979 switch (control) {
980 case CE_PushButton:
981 p->fillRect(r, Qt::color1);
982 break;
984 default:
985 QCommonStyle::drawControlMask(control, p, widget, r, data);
986 break;
990 QRect LightStyleV2::subRect(SubRect subrect, const QWidget *widget) const
992 QRect rect, wrect(widget->rect());
994 switch (subrect) {
995 case SR_PushButtonFocusRect:
997 const QPushButton *button = (const QPushButton *) widget;
998 int dbw1 = 0, dbw2 = 0;
999 if (button->isDefault() || button->autoDefault()) {
1000 dbw1 = pixelMetric(PM_ButtonDefaultIndicator, widget);
1001 dbw2 = dbw1 * 2;
1004 rect.setRect(wrect.x() + 3 + dbw1,
1005 wrect.y() + 3 + dbw1,
1006 wrect.width() - 6 - dbw2,
1007 wrect.height() - 6 - dbw2);
1008 break;
1011 default:
1012 rect = QCommonStyle::subRect(subrect, widget);
1015 return rect;
1018 void LightStyleV2::drawComplexControl( ComplexControl control,
1019 QPainter* p,
1020 const QWidget* widget,
1021 const QRect& r,
1022 const QColorGroup& cg,
1023 SFlags flags,
1024 SCFlags controls,
1025 SCFlags active,
1026 const QStyleOption &data ) const
1028 switch (control) {
1029 case CC_ComboBox:
1031 const QComboBox *combobox = (const QComboBox *) widget;
1032 QRect frame, arrow, field;
1033 frame =
1034 QStyle::visualRect(querySubControlMetrics(CC_ComboBox, widget,
1035 SC_ComboBoxFrame, data),
1036 widget);
1037 arrow =
1038 QStyle::visualRect(querySubControlMetrics(CC_ComboBox, widget,
1039 SC_ComboBoxArrow, data),
1040 widget);
1041 field =
1042 QStyle::visualRect(querySubControlMetrics(CC_ComboBox, widget,
1043 SC_ComboBoxEditField, data),
1044 widget);
1046 if ((controls & SC_ComboBoxFrame) && frame.isValid())
1047 drawLightBevel(p, frame, cg, flags | Style_Raised,
1048 &cg.brush(QPalette::Button));
1050 if ((controls & SC_ComboBoxArrow) && arrow.isValid()) {
1051 if (active == SC_ComboBoxArrow)
1052 p->fillRect(arrow, cg.brush(QPalette::Mid));
1053 arrow.adjust(4, 2, -2, -2);
1054 drawPrimitive(PE_ArrowDown, p, arrow, cg, flags);
1057 if ((controls & SC_ComboBoxEditField) && field.isValid()) {
1058 p->setPen(cg.dark());
1059 if (combobox->editable()) {
1060 field.adjust(-1, -1, 1, 1);
1061 p->drawRect(field);
1062 } else
1063 p->drawLine(field.right() + 1, field.top(),
1064 field.right() + 1, field.bottom());
1066 if (flags & Style_HasFocus) {
1067 if (! combobox->editable()) {
1068 p->fillRect( field, cg.brush( QPalette::Highlight ) );
1069 QRect fr =
1070 QStyle::visualRect( subRect( SR_ComboBoxFocusRect, widget ),
1071 widget );
1072 drawPrimitive( PE_FocusRect, p, fr, cg,
1073 flags | Style_FocusAtBorder,
1074 QStyleOption(cg.highlight()));
1077 p->setPen(cg.highlightedText());
1078 } else
1079 p->setPen(cg.buttonText());
1082 break;
1085 case CC_SpinWidget:
1087 const Q3SpinWidget *spinwidget = (const Q3SpinWidget *) widget;
1088 QRect frame, up, down;
1090 frame = querySubControlMetrics(CC_SpinWidget, widget,
1091 SC_SpinWidgetFrame, data);
1092 up = spinwidget->upRect();
1093 down = spinwidget->downRect();
1095 if ((controls & SC_SpinWidgetFrame) && frame.isValid())
1096 drawLightBevel(p, frame, cg, flags | Style_Sunken,
1097 &cg.brush(QPalette::Base));
1099 if ((controls & SC_SpinWidgetUp) && up.isValid()) {
1100 PrimitiveElement pe = PE_SpinWidgetUp;
1101 if ( spinwidget->buttonSymbols() == Q3SpinWidget::PlusMinus )
1102 pe = PE_SpinWidgetPlus;
1104 p->setPen(cg.dark());
1105 p->drawLine(up.topLeft(), up.bottomLeft());
1107 up.adjust(1, 0, 0, 0);
1108 p->fillRect(up, cg.brush(QPalette::Button));
1109 if (active == SC_SpinWidgetUp)
1110 p->setPen(cg.mid());
1111 else
1112 p->setPen(cg.light());
1113 p->drawLine(up.left(), up.top(),
1114 up.right() - 1, up.top());
1115 p->drawLine(up.left(), up.top() + 1,
1116 up.left(), up.bottom() - 1);
1117 if (active == SC_SpinWidgetUp)
1118 p->setPen(cg.light());
1119 else
1120 p->setPen(cg.mid());
1121 p->drawLine(up.right(), up.top(),
1122 up.right(), up.bottom());
1123 p->drawLine(up.left(), up.bottom(),
1124 up.right() - 1, up.bottom());
1126 up.adjust(1, 0, 0, 0);
1127 drawPrimitive(pe, p, up, cg, flags |
1128 ((active == SC_SpinWidgetUp) ?
1129 Style_On | Style_Sunken : Style_Raised));
1132 if ((controls & SC_SpinWidgetDown) && down.isValid()) {
1133 PrimitiveElement pe = PE_SpinWidgetDown;
1134 if ( spinwidget->buttonSymbols() == Q3SpinWidget::PlusMinus )
1135 pe = PE_SpinWidgetMinus;
1137 p->setPen(cg.dark());
1138 p->drawLine(down.topLeft(), down.bottomLeft());
1140 down.adjust(1, 0, 0, 0);
1141 p->fillRect(down, cg.brush(QPalette::Button));
1142 if (active == SC_SpinWidgetDown)
1143 p->setPen(cg.mid());
1144 else
1145 p->setPen(cg.light());
1146 p->drawLine(down.left(), down.top(),
1147 down.right() - 1, down.top());
1148 p->drawLine(down.left(), down.top() + 1,
1149 down.left(), down.bottom() - 1);
1150 if (active == SC_SpinWidgetDown)
1151 p->setPen(cg.light());
1152 else
1153 p->setPen(cg.mid());
1154 p->drawLine(down.right(), down.top(),
1155 down.right(), down.bottom());
1156 p->drawLine(down.left(), down.bottom(),
1157 down.right() - 1, down.bottom());
1159 down.adjust(1, 0, 0, 0);
1160 drawPrimitive(pe, p, down, cg, flags |
1161 ((active == SC_SpinWidgetDown) ?
1162 Style_On | Style_Sunken : Style_Raised));
1165 break;
1168 case CC_ScrollBar:
1170 const QScrollBar *scrollbar = (const QScrollBar *) widget;
1171 QRect addline, subline, subline2, addpage, subpage, slider, first, last;
1172 bool maxedOut = (scrollbar->minValue() == scrollbar->maxValue());
1174 subline = querySubControlMetrics(control, widget, SC_ScrollBarSubLine, data);
1175 addline = querySubControlMetrics(control, widget, SC_ScrollBarAddLine, data);
1176 subpage = querySubControlMetrics(control, widget, SC_ScrollBarSubPage, data);
1177 addpage = querySubControlMetrics(control, widget, SC_ScrollBarAddPage, data);
1178 slider = querySubControlMetrics(control, widget, SC_ScrollBarSlider, data);
1179 first = querySubControlMetrics(control, widget, SC_ScrollBarFirst, data);
1180 last = querySubControlMetrics(control, widget, SC_ScrollBarLast, data);
1182 subline2 = addline;
1183 if (scrollbar->orientation() == Qt::Horizontal)
1184 subline2.translate(-addline.width(), 0);
1185 else
1186 subline2.translate(0, -addline.height());
1188 if ((controls & SC_ScrollBarSubLine) && subline.isValid()) {
1189 drawPrimitive(PE_ScrollBarSubLine, p, subline, cg,
1190 Style_Enabled | ((active == SC_ScrollBarSubLine) ?
1191 Style_Down : Style_Default) |
1192 ((scrollbar->orientation() == Qt::Horizontal) ?
1193 Style_Horizontal : 0));
1195 if (subline2.isValid())
1196 drawPrimitive(PE_ScrollBarSubLine, p, subline2, cg,
1197 Style_Enabled | ((active == SC_ScrollBarSubLine) ?
1198 Style_Down : Style_Default) |
1199 ((scrollbar->orientation() == Qt::Horizontal) ?
1200 Style_Horizontal : 0));
1202 if ((controls & SC_ScrollBarAddLine) && addline.isValid())
1203 drawPrimitive(PE_ScrollBarAddLine, p, addline, cg,
1204 Style_Enabled | ((active == SC_ScrollBarAddLine) ?
1205 Style_Down : Style_Default) |
1206 ((scrollbar->orientation() == Qt::Horizontal) ?
1207 Style_Horizontal : 0));
1208 if ((controls & SC_ScrollBarSubPage) && subpage.isValid())
1209 drawPrimitive(PE_ScrollBarSubPage, p, subpage, cg,
1210 Style_Enabled | ((active == SC_ScrollBarSubPage) ?
1211 Style_Down : Style_Default) |
1212 ((scrollbar->orientation() == Qt::Horizontal) ?
1213 Style_Horizontal : 0));
1214 if ((controls & SC_ScrollBarAddPage) && addpage.isValid())
1215 drawPrimitive(PE_ScrollBarAddPage, p, addpage, cg,
1216 ((maxedOut) ? Style_Default : Style_Enabled) |
1217 ((active == SC_ScrollBarAddPage) ?
1218 Style_Down : Style_Default) |
1219 ((scrollbar->orientation() == Qt::Horizontal) ?
1220 Style_Horizontal : 0));
1221 if ((controls & SC_ScrollBarFirst) && first.isValid())
1222 drawPrimitive(PE_ScrollBarFirst, p, first, cg,
1223 Style_Enabled | ((active == SC_ScrollBarFirst) ?
1224 Style_Down : Style_Default) |
1225 ((scrollbar->orientation() == Qt::Horizontal) ?
1226 Style_Horizontal : 0));
1227 if ((controls & SC_ScrollBarLast) && last.isValid())
1228 drawPrimitive(PE_ScrollBarLast, p, last, cg,
1229 Style_Enabled | ((active == SC_ScrollBarLast) ?
1230 Style_Down : Style_Default) |
1231 ((scrollbar->orientation() == Qt::Horizontal) ?
1232 Style_Horizontal : 0));
1233 if ((controls & SC_ScrollBarSlider) && slider.isValid()) {
1234 drawPrimitive(PE_ScrollBarSlider, p, slider, cg,
1235 Style_Enabled | ((active == SC_ScrollBarSlider) ?
1236 Style_Down : Style_Default) |
1237 ((scrollbar->orientation() == Qt::Horizontal) ?
1238 Style_Horizontal : 0));
1240 // ### perhaps this should not be able to accept focus if maxedOut?
1241 if (scrollbar->hasFocus()) {
1242 QRect fr(slider.x() + 2, slider.y() + 2,
1243 slider.width() - 5, slider.height() - 5);
1244 drawPrimitive(PE_FocusRect, p, fr, cg, Style_Default);
1248 break;
1251 case CC_Slider:
1253 const QSlider *slider = (const QSlider *) widget;
1254 QRect groove = querySubControlMetrics(CC_Slider, widget, SC_SliderGroove,
1255 data),
1256 handle = querySubControlMetrics(CC_Slider, widget, SC_SliderHandle,
1257 data);
1259 if ((controls & SC_SliderGroove) && groove.isValid()) {
1260 if (flags & Style_HasFocus)
1261 drawPrimitive( PE_FocusRect, p, groove, cg );
1263 if (slider->orientation() == Qt::Horizontal) {
1264 int dh = (groove.height() - 5) / 2;
1265 groove.adjust(0, dh, 0, -dh);
1266 } else {
1267 int dw = (groove.width() - 5) / 2;
1268 groove.adjust(dw, 0, -dw, 0);
1271 drawLightBevel(p, groove, cg, ((flags | Style_Raised) ^ Style_Raised) |
1272 ((flags & Style_Enabled) ? Style_Sunken : Style_Default),
1273 &cg.brush(QPalette::Midlight));
1276 if ((controls & SC_SliderHandle) && handle.isValid()) {
1277 drawLightBevel(p, handle, cg, ((flags | Style_Down) ^ Style_Down) |
1278 ((flags & Style_Enabled) ? Style_Raised : Style_Default),
1279 &cg.brush(QPalette::Button));
1283 if (controls & SC_SliderTickmarks)
1284 QCommonStyle::drawComplexControl(control, p, widget, r, cg, flags,
1285 SC_SliderTickmarks, active, data );
1286 break;
1289 case CC_ListView:
1290 // use the base style for CC_ListView
1291 singleton->basestyle->drawComplexControl(control, p, widget, r, cg, flags,
1292 controls, active, data);
1293 break;
1295 default:
1296 QCommonStyle::drawComplexControl(control, p, widget, r, cg, flags,
1297 controls, active, data);
1298 break;
1302 QRect LightStyleV2::querySubControlMetrics( ComplexControl control,
1303 const QWidget *widget,
1304 SubControl sc,
1305 const QStyleOption &data ) const
1307 QRect ret;
1309 switch (control) {
1310 case CC_ScrollBar:
1312 const QScrollBar *scrollbar = (const QScrollBar *) widget;
1313 int sliderstart = scrollbar->sliderStart();
1314 int sbextent = pixelMetric(PM_ScrollBarExtent, widget);
1315 int maxlen = ((scrollbar->orientation() == Qt::Horizontal) ?
1316 scrollbar->width() : scrollbar->height()) - (sbextent * 3);
1317 int sliderlen;
1319 // calculate slider length
1320 if (scrollbar->maxValue() != scrollbar->minValue()) {
1321 uint range = scrollbar->maxValue() - scrollbar->minValue();
1322 sliderlen = (scrollbar->pageStep() * maxlen) /
1323 (range + scrollbar->pageStep());
1325 int slidermin = pixelMetric( PM_ScrollBarSliderMin, widget );
1326 if ( sliderlen < slidermin || range > INT_MAX / 2 )
1327 sliderlen = slidermin;
1328 if ( sliderlen > maxlen )
1329 sliderlen = maxlen;
1330 } else
1331 sliderlen = maxlen;
1333 switch (sc) {
1334 case SC_ScrollBarSubLine:
1335 // top/left button
1336 ret.setRect(0, 0, sbextent, sbextent);
1337 break;
1339 case SC_ScrollBarAddLine:
1340 // bottom/right button
1341 if (scrollbar->orientation() == Qt::Horizontal)
1342 ret.setRect(scrollbar->width() - sbextent, 0, sbextent, sbextent);
1343 else
1344 ret.setRect(0, scrollbar->height() - sbextent, sbextent, sbextent);
1345 break;
1347 case SC_ScrollBarSubPage:
1348 // between top/left button and slider
1349 if (scrollbar->orientation() == Qt::Horizontal)
1350 ret.setRect(sbextent, 0, sliderstart - sbextent, sbextent);
1351 else
1352 ret.setRect(0, sbextent, sbextent, sliderstart - sbextent);
1353 break;
1355 case SC_ScrollBarAddPage:
1356 // between bottom/right button and slider
1357 if (scrollbar->orientation() == Qt::Horizontal)
1358 ret.setRect(sliderstart + sliderlen, 0,
1359 maxlen - sliderstart - sliderlen + sbextent, sbextent);
1360 else
1361 ret.setRect(0, sliderstart + sliderlen,
1362 sbextent, maxlen - sliderstart - sliderlen + sbextent);
1363 break;
1365 case SC_ScrollBarGroove:
1366 if (scrollbar->orientation() == Qt::Horizontal)
1367 ret.setRect(sbextent, 0, scrollbar->width() - sbextent * 3,
1368 scrollbar->height());
1369 else
1370 ret.setRect(0, sbextent, scrollbar->width(),
1371 scrollbar->height() - sbextent * 3);
1372 break;
1374 case SC_ScrollBarSlider:
1375 if (scrollbar->orientation() == Qt::Horizontal)
1376 ret.setRect(sliderstart, 0, sliderlen, sbextent);
1377 else
1378 ret.setRect(0, sliderstart, sbextent, sliderlen);
1379 break;
1381 default:
1382 break;
1385 break;
1388 default:
1389 ret = QCommonStyle::querySubControlMetrics(control, widget, sc, data);
1390 break;
1393 return ret;
1396 QStyle::SubControl LightStyleV2::querySubControl( ComplexControl control,
1397 const QWidget *widget,
1398 const QPoint &pos,
1399 const QStyleOption &data ) const
1401 QStyle::SubControl ret = QCommonStyle::querySubControl(control, widget, pos, data);
1403 // this is an ugly hack, but i really don't care, it's the quickest way to
1404 // enabled the third button
1405 if (control == CC_ScrollBar &&
1406 ret == SC_None)
1407 ret = SC_ScrollBarSubLine;
1409 return ret;
1412 int LightStyleV2::pixelMetric( PixelMetric metric,
1413 const QWidget *widget ) const
1415 int ret;
1417 switch (metric) {
1418 case PM_ButtonMargin:
1419 ret = 4;
1420 break;
1422 case PM_ButtonShiftHorizontal:
1423 case PM_ButtonShiftVertical:
1424 ret = 0;
1425 break;
1427 case PM_ButtonDefaultIndicator:
1428 case PM_DefaultFrameWidth:
1429 ret = 2;
1430 break;
1432 case PM_IndicatorWidth:
1433 case PM_IndicatorHeight:
1434 case PM_ExclusiveIndicatorWidth:
1435 case PM_ExclusiveIndicatorHeight:
1436 ret = 13;
1437 break;
1439 case PM_TabBarTabOverlap:
1440 ret = 0;
1441 break;
1443 case PM_ScrollBarExtent:
1444 case PM_ScrollBarSliderMin:
1445 ret = 14;
1446 break;
1448 case PM_MenuBarFrameWidth:
1449 ret = 1;
1450 break;
1452 case PM_ProgressBarChunkWidth:
1453 ret = 1;
1454 break;
1456 case PM_DockWindowSeparatorExtent:
1457 ret = 4;
1458 break;
1460 case PM_SplitterWidth:
1461 ret = 6;
1462 break;
1465 case PM_SliderLength:
1466 case PM_SliderControlThickness:
1467 ret = singleton->basestyle->pixelMetric( metric, widget );
1468 break;
1470 case PM_MaximumDragDistance:
1471 ret = -1;
1472 break;
1474 default:
1475 ret = QCommonStyle::pixelMetric(metric, widget);
1476 break;
1479 return ret;
1482 QSize LightStyleV2::sizeFromContents( ContentsType contents,
1483 const QWidget *widget,
1484 const QSize &contentsSize,
1485 const QStyleOption &data ) const
1487 QSize ret;
1489 switch (contents) {
1490 case CT_PushButton:
1492 const QPushButton *button = (const QPushButton *) widget;
1493 ret = QCommonStyle::sizeFromContents( contents, widget, contentsSize, data );
1494 int w = ret.width(), h = ret.height();
1496 // only expand the button if we are displaying text...
1497 if ( ! button->text().isEmpty() ) {
1498 if ( button->isDefault() || button->autoDefault() ) {
1499 // default button minimum size
1500 if ( w < 80 )
1501 w = 80;
1502 if ( h < 25 )
1503 h = 25;
1504 } else {
1505 // regular button minimum size
1506 if ( w < 76 )
1507 w = 76;
1508 if ( h < 21 )
1509 h = 21;
1513 ret = QSize( w, h );
1514 break;
1517 case CT_PopupMenuItem:
1519 if (! widget || data.isDefault())
1520 break;
1522 QMenuItem *mi = data.menuItem();
1523 const QMenu *popupmenu = (const QMenu *) widget;
1524 int maxpmw = data.maxIconWidth();
1525 int w = contentsSize.width(), h = contentsSize.height();
1527 if (mi->custom()) {
1528 w = mi->custom()->sizeHint().width();
1529 h = mi->custom()->sizeHint().height();
1530 if (! mi->custom()->fullSpan() && h < 22)
1531 h = 22;
1532 } else if(mi->widget()) {
1533 } else if (mi->isSeparator()) {
1534 w = 10;
1535 h = 4;
1536 } else {
1537 // check is at least 16x16
1538 if (h < 16)
1539 h = 16;
1540 if (mi->pixmap())
1541 h = qMax(h, mi->pixmap()->height());
1542 else if (! mi->text().isNull())
1543 h = qMax(h, popupmenu->fontMetrics().height() + 2);
1544 if (mi->iconSet() != 0)
1545 h = qMax(h, mi->iconSet()->pixmap(QIcon::Small,
1546 QIcon::Normal).height());
1547 h += 2;
1550 // check | 4 pixels | item | 8 pixels | accel | 4 pixels | check
1552 // check is at least 16x16
1553 maxpmw = qMax(maxpmw, 16);
1554 w += (maxpmw * 2) + 8;
1556 if (! mi->text().isNull() && mi->text().find('\t') >= 0)
1557 w += 8;
1559 ret = QSize(w, h);
1560 break;
1562 case CT_ProgressBar:
1564 const QProgressBar* pb = static_cast<const QProgressBar*>(widget);
1566 //If we have to display the indicator, and we do it on RHS, give some more room
1567 //for it. This tries to match the logic and the spacing in SR_ProgressBarGroove/Contents
1568 //sizing in QCommonStyle.
1569 if (pb->percentageVisible() &&
1570 (pb->indicatorFollowsStyle() || ! pb->centerIndicator()))
1572 int addw = pb->fontMetrics().width("100%") + 6;
1573 return QSize(contentsSize.width() + addw, contentsSize.height());
1575 else
1576 return contentsSize; //Otherwise leave unchanged
1578 break;
1581 default:
1582 ret = QCommonStyle::sizeFromContents(contents, widget, contentsSize, data);
1583 break;
1586 return ret;
1589 int LightStyleV2::styleHint( StyleHint stylehint,
1590 const QWidget *widget,
1591 const QStyleOption &option,
1592 QStyleHintReturn* returnData ) const
1594 int ret;
1596 switch (stylehint) {
1597 case SH_EtchDisabledText:
1598 case SH_Slider_SnapToValue:
1599 case SH_PrintDialog_RightAlignButtons:
1600 case SH_FontDialog_SelectAssociatedText:
1601 case SH_MenuBar_AltKeyNavigation:
1602 case SH_MenuBar_MouseTracking:
1603 case SH_PopupMenu_MouseTracking:
1604 case SH_ComboBox_ListMouseTracking:
1605 case SH_ScrollBar_MiddleClickAbsolutePosition:
1606 ret = 1;
1607 break;
1609 case SH_MainWindow_SpaceBelowMenuBar:
1610 ret = 0;
1611 break;
1613 default:
1614 ret = QCommonStyle::styleHint(stylehint, widget, option, returnData);
1615 break;
1618 return ret;
1621 QPixmap LightStyleV2::stylePixmap( StylePixmap stylepixmap,
1622 const QWidget *widget,
1623 const QStyleOption &data ) const
1625 return singleton->basestyle->stylePixmap( stylepixmap, widget, data );
1627 #include "lightstyle-v2.moc"