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/QPalette"
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
50 basestyle
= QStyleFactory::create( "Windows" );
52 basestyle
= QStyleFactory::create( QStyleFactory::keys().first() );
54 qFatal( "LightStyle: could not find a basestyle!" );
57 ~LightStyleV2Private()
66 static LightStyleV2Private
*singleton
= 0;
69 LightStyleV2::LightStyleV2()
70 : KStyle(AllowMenuTransparency
)
73 singleton
= new LightStyleV2Private
;
78 LightStyleV2::~LightStyleV2()
80 if (singleton
&& --singleton
->ref
<= 0) {
86 void LightStyleV2::polishPopupMenu( QMenu
* menu
)
88 KStyle::polishPopupMenu(menu
);
91 static void drawLightBevel(QPainter
*p
, const QRect
&r
, const QPalette
&cg
,
92 QStyle::State flags
, const QBrush
*fill
= 0)
95 bool sunken
= (flags
& (QStyle::State_Down
| QStyle::State_On
|
96 QStyle::State_Sunken
));
101 if (flags
& (QStyle::State_Down
| QStyle::State_On
|
102 QStyle::State_Sunken
| QStyle::State_Raised
)) {
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
115 p
->setPen(cg
.light());
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);
126 br
.adjust(1, 1, -1, -1);
129 if (fill
) p
->fillRect(br
, *fill
);
132 void LightStyleV2::drawPrimitive( PrimitiveElement pe
,
133 const QStyleOption
*option
,
135 const QWidget
*widget
) const
137 QRect r
= option
->rect();
139 case PE_HeaderSection
:
141 flags
= ((flags
| Style_Sunken
) ^ Style_Sunken
) | Style_Raised
;
142 //Don't show pressed too often (as in light 3)
143 QBrush
fill(cg
.background());
144 if (flags
& QStyle::State_Enabled
)
145 fill
.setColor(cg
.button());
147 drawLightBevel(p
, r
, cg
, flags
, &fill
);
148 p
->setPen( cg
.buttonText() );
152 case PE_ButtonCommand
:
157 if (flags
& QStyle::State_Enabled
) {
158 if (flags
& (QStyle::State_Down
|
160 QStyle::State_Sunken
))
161 fill
= &cg
.brush(QPalette::Midlight
);
163 fill
= &cg
.brush(QPalette::Button
);
165 fill
= &cg
.brush(QPalette::Background
);
166 drawLightBevel(p
, r
, cg
, flags
, fill
);
170 case PE_ButtonDropDown
:
174 (flags
& (QStyle::State_Down
| QStyle::State_On
| QStyle::State_Sunken
));
176 if (flags
& QStyle::State_Enabled
) {
178 thefill
= cg
.brush(QPalette::Midlight
);
180 thefill
= cg
.brush(QPalette::Button
);
182 thefill
= cg
.brush(QPalette::Background
);
184 p
->setPen(cg
.dark());
185 p
->drawLine(r
.topLeft(), r
.topRight());
186 p
->drawLine(r
.topRight(), r
.bottomRight());
187 p
->drawLine(r
.bottomRight(), r
.bottomLeft());
189 if (flags
& (QStyle::State_Down
| QStyle::State_On
|
190 QStyle::State_Sunken
| QStyle::State_Raised
)) {
195 p
->setPen(cg
.light());
197 p
->drawLine(r
.x(), r
.y() + 2,
198 r
.x(), r
.y() + r
.height() - 3); // left
199 p
->drawLine(r
.x(), r
.y() + 1,
200 r
.x() + r
.width() - 2, r
.y() + 1); // top
203 p
->setPen(cg
.light());
207 p
->drawLine(r
.x() + r
.width() - 2, r
.y() + 2,
208 r
.x() + r
.width() - 2, r
.y() + r
.height() - 3); // right
209 p
->drawLine(r
.x() + 1, r
.y() + r
.height() - 2,
210 r
.x() + r
.width() - 2, r
.y() + r
.height() - 2); // bottom
213 p
->fillRect(r
.x() + 1, r
.y() + 2, r
.width() - 3, r
.height() - 4, thefill
);
217 case PE_ButtonDefault
:
218 p
->setPen(cg
.dark());
219 p
->setBrush(cg
.light());
225 if (! (flags
& Style_Enabled
))
226 fill
= &cg
.brush(QPalette::Background
);
227 else if (flags
& Style_Down
)
228 fill
= &cg
.brush(QPalette::Mid
);
230 fill
= &cg
.brush(QPalette::Base
);
231 drawLightBevel(p
, r
, cg
, flags
| Style_Sunken
, fill
);
233 p
->setPen(cg
.text());
234 if (flags
& Style_NoChange
) {
235 p
->drawLine(r
.x() + 3, r
.y() + r
.height() / 2,
236 r
.x() + r
.width() - 4, r
.y() + r
.height() / 2);
237 p
->drawLine(r
.x() + 3, r
.y() + 1 + r
.height() / 2,
238 r
.x() + r
.width() - 4, r
.y() + 1 + r
.height() / 2);
239 p
->drawLine(r
.x() + 3, r
.y() - 1 + r
.height() / 2,
240 r
.x() + r
.width() - 4, r
.y() - 1 + r
.height() / 2);
241 } else if (flags
& Style_On
) {
242 p
->drawLine(r
.x() + 4, r
.y() + 3,
243 r
.x() + r
.width() - 4, r
.y() + r
.height() - 5);
244 p
->drawLine(r
.x() + 3, r
.y() + 3,
245 r
.x() + r
.width() - 4, r
.y() + r
.height() - 4);
246 p
->drawLine(r
.x() + 3, r
.y() + 4,
247 r
.x() + r
.width() - 5, r
.y() + r
.height() - 4);
248 p
->drawLine(r
.x() + 3, r
.y() + r
.height() - 5,
249 r
.x() + r
.width() - 5, r
.y() + 3);
250 p
->drawLine(r
.x() + 3, r
.y() + r
.height() - 4,
251 r
.x() + r
.width() - 4, r
.y() + 3);
252 p
->drawLine(r
.x() + 4, r
.y() + r
.height() - 4,
253 r
.x() + r
.width() - 4, r
.y() + 4);
258 case PE_ExclusiveIndicator
:
260 QRect br
= r
, // bevel rect
261 cr
= r
, // contents rect
262 ir
= r
; // indicator rect
263 br
.adjust(1, 1, -1, -1);
264 cr
.adjust(2, 2, -2, -2);
265 ir
.adjust(3, 3, -3, -3);
267 p
->fillRect(r
, cg
.brush(QPalette::Background
));
269 p
->setPen(cg
.dark());
270 p
->drawArc(r
, 0, 16*360);
272 p
->drawArc(br
, 45*16, 180*16);
273 p
->setPen(cg
.light());
274 p
->drawArc(br
, 235*16, 180*16);
276 p
->setPen(flags
& Style_Down
? cg
.mid() :
277 (flags
& Style_Enabled
? cg
.base() : cg
.background()));
278 p
->setBrush(flags
& Style_Down
? cg
.mid() :
279 (flags
& Style_Enabled
? cg
.base() : cg
.background()));
282 if (flags
& Style_On
) {
283 p
->setBrush(cg
.text());
290 case PE_DockWindowHandle
:
293 bool drawTitle
= false;
294 if ( p
&& p
->device()->devType() == QInternal::Widget
) {
295 QWidget
*w
= (QWidget
*) p
->device();
296 QWidget
*p
= w
->parentWidget();
297 if (p
->inherits("QDockWindow") && ! p
->inherits("QToolBar")) {
299 title
= p
->caption();
303 flags
|= Style_Raised
;
304 if (flags
& Style_Horizontal
) {
306 QPixmap
pm(r
.height(), r
.width());
308 p2
.fillRect(0, 0, pm
.width(), pm
.height(),
309 cg
.brush(QPalette::Highlight
));
310 p2
.setPen(cg
.highlightedText());
311 p2
.drawText(0, 0, pm
.width(), pm
.height(), Qt::AlignCenter
, title
);
317 p
->drawPixmap(r
.x(), r
.y(), pm
);
319 p
->fillRect(r
, cg
.background());
320 p
->setPen(cg
.mid().dark());
321 p
->drawLine(r
.right() - 6, r
.top() + 2,
322 r
.right() - 6, r
.bottom() - 2);
323 p
->drawLine(r
.right() - 3, r
.top() + 2,
324 r
.right() - 3, r
.bottom() - 2);
325 p
->setPen(cg
.light());
326 p
->drawLine(r
.right() - 5, r
.top() + 2,
327 r
.right() - 5, r
.bottom() - 2);
328 p
->drawLine(r
.right() - 2, r
.top() + 2,
329 r
.right() - 2, r
.bottom() - 2);
333 p
->fillRect(r
, cg
.brush(QPalette::Highlight
));
334 p
->setPen(cg
.highlightedText());
335 p
->drawText(r
, Qt::AlignCenter
, title
);
337 p
->fillRect(r
, cg
.background());
338 p
->setPen(cg
.mid().dark());
339 p
->drawLine(r
.left() + 2, r
.bottom() - 6,
340 r
.right() - 2, r
.bottom() - 6);
341 p
->drawLine(r
.left() + 2, r
.bottom() - 3,
342 r
.right() - 2, r
.bottom() - 3);
343 p
->setPen(cg
.light());
344 p
->drawLine(r
.left() + 2, r
.bottom() - 5,
345 r
.right() - 2, r
.bottom() - 5);
346 p
->drawLine(r
.left() + 2, r
.bottom() - 2,
347 r
.right() - 2, r
.bottom() - 2);
353 case PE_DockWindowSeparator
:
355 if (r
.width() > 20 || r
.height() > 20) {
356 if (flags
& Style_Horizontal
) {
357 p
->setPen(cg
.mid().dark(120));
358 p
->drawLine(r
.left() + 1, r
.top() + 6, r
.left() + 1, r
.bottom() - 6);
359 p
->setPen(cg
.light());
360 p
->drawLine(r
.left() + 2, r
.top() + 6, r
.left() + 2, r
.bottom() - 6);
362 p
->setPen(cg
.mid().dark(120));
363 p
->drawLine(r
.left() + 6, r
.top() + 1, r
.right() - 6, r
.top() + 1);
364 p
->setPen(cg
.light());
365 p
->drawLine(r
.left() + 6, r
.top() + 2, r
.right() - 6, r
.top() + 2);
368 QCommonStyle::drawPrimitive(pe
, p
, r
, cg
, flags
, data
);
373 if (flags
& Style_Horizontal
)
374 flags
&= ~Style_Horizontal
;
376 flags
|= Style_Horizontal
;
377 // fall through intended
379 case PE_DockWindowResizeHandle
:
381 p
->fillRect(r
, cg
.background());
382 if (flags
& Style_Horizontal
) {
383 p
->setPen(cg
.highlight().light());
384 p
->drawLine(r
.left() + 1, r
.top() + 1, r
.right() - 1, r
.top() + 1);
385 p
->setPen(cg
.highlight());
386 p
->drawLine(r
.left() + 1, r
.top() + 2, r
.right() - 1, r
.top() + 2);
387 p
->setPen(cg
.highlight().dark());
388 p
->drawLine(r
.left() + 1, r
.top() + 3, r
.right() - 1, r
.top() + 3);
390 p
->setPen(cg
.highlight().light());
391 p
->drawLine(r
.left() + 1, r
.top() + 1, r
.left() + 1, r
.bottom() - 1);
392 p
->setPen(cg
.highlight());
393 p
->drawLine(r
.left() + 2, r
.top() + 1, r
.left() + 2, r
.bottom() - 1);
394 p
->setPen(cg
.highlight().dark());
395 p
->drawLine(r
.left() + 3, r
.top() + 1, r
.left() + 3, r
.bottom() - 1);
402 case PE_PanelLineEdit
:
403 case PE_PanelTabWidget
:
406 int lw
= data
.isDefault() ?
407 pixelMetric(PM_DefaultFrameWidth
) : data
.lineWidth();
409 if ( ! ( flags
& Style_Sunken
) )
410 flags
|= Style_Raised
;
412 drawLightBevel(p
, r
, cg
, flags
);
414 QCommonStyle::drawPrimitive(pe
, p
, r
, cg
, flags
, data
);
418 case PE_PanelDockWindow
:
420 int lw
= data
.isDefault() ?
421 pixelMetric(PM_DockWindowFrameWidth
) : data
.lineWidth();
424 drawLightBevel(p
, r
, cg
, flags
| Style_Raised
,
425 &cg
.brush(QPalette::Button
));
427 QCommonStyle::drawPrimitive(pe
, p
, r
, cg
, flags
, data
);
431 case PE_PanelMenuBar
:
433 int lw
= data
.isDefault() ?
434 pixelMetric(PM_MenuBarFrameWidth
) : data
.lineWidth();
437 drawLightBevel(p
, r
, cg
, flags
, &cg
.brush(QPalette::Button
));
439 QCommonStyle::drawPrimitive(pe
, p
, r
, cg
, flags
, data
);
443 case PE_ScrollBarSubLine
:
445 QRect fr
= r
, ar
= r
;
448 p
->setPen(cg
.dark());
449 if (flags
& Style_Horizontal
) {
450 p
->drawLine(r
.topLeft(), r
.topRight());
451 fr
.adjust(0, 1, 0, 0);
452 ar
.adjust(0, 1, 0, 0);
455 p
->drawLine(r
.topLeft(), r
.bottomLeft());
456 fr
.adjust(1, 0, 0, 0);
457 ar
.adjust(2, 0, 0, 0);
461 p
->fillRect(fr
, cg
.brush((flags
& Style_Down
) ?
463 QPalette::Background
));
464 drawPrimitive(pe
, p
, ar
, cg
, flags
);
468 case PE_ScrollBarAddLine
:
470 QRect fr
= r
, ar
= r
;
473 p
->setPen(cg
.dark());
474 if (flags
& Style_Horizontal
) {
475 p
->drawLine(r
.topLeft(), r
.topRight());
476 fr
.adjust(0, 1, 0, 0);
477 ar
.adjust(0, 1, 0, 0);
480 p
->drawLine(r
.topLeft(), r
.bottomLeft());
481 fr
.adjust(1, 0, 0, 0);
482 ar
.adjust(2, 0, 0, 0);
486 p
->fillRect(fr
, cg
.brush((flags
& Style_Down
) ?
488 QPalette::Background
));
489 drawPrimitive(pe
, p
, ar
, cg
, flags
);
493 case PE_ScrollBarSubPage
:
494 case PE_ScrollBarAddPage
:
498 p
->setPen(cg
.dark());
499 if (flags
& Style_Horizontal
) {
500 p
->drawLine(r
.topLeft(), r
.topRight());
501 p
->setPen(cg
.background());
502 p
->drawLine(r
.left(), r
.top() + 1, r
.right(), r
.top() + 1);
503 fr
.adjust(0, 2, 0, 0);
505 p
->drawLine(r
.topLeft(), r
.bottomLeft());
506 p
->setPen(cg
.background());
507 p
->drawLine(r
.left() + 1, r
.top(), r
.left() + 1, r
.bottom());
508 fr
.adjust(2, 0, 0, 0);
511 p
->fillRect(fr
, cg
.brush((flags
& Style_Down
) ?
517 case PE_ScrollBarSlider
:
521 p
->setPen(cg
.dark());
522 if (flags
& Style_Horizontal
) {
523 p
->drawLine(r
.topLeft(), r
.topRight());
524 p
->setPen(cg
.background());
525 p
->drawLine(r
.left(), r
.top() + 1, r
.right(), r
.top() + 1);
526 fr
.adjust(0, 2, 0, -1);
528 p
->drawLine(r
.topLeft(), r
.bottomLeft());
529 p
->setPen(cg
.background());
530 p
->drawLine(r
.left() + 1, r
.top(), r
.left() + 1, r
.bottom());
531 fr
.adjust(2, 0, -1, 0);
534 drawLightBevel(p
, fr
, cg
, ((flags
| Style_Down
) ^ Style_Down
) |
535 ((flags
& Style_Enabled
) ? Style_Raised
: Style_Default
),
536 &cg
.brush(QPalette::Button
));
542 p
->setBrush(Qt::NoBrush
);
543 if (flags
& Style_FocusAtBorder
)
544 p
->setPen(cg
.shadow());
546 p
->setPen(cg
.dark());
551 case PE_ProgressBarChunk
:
552 p
->fillRect(r
.x(), r
.y() + 2, r
.width(), r
.height() - 4, cg
.highlight());
556 if (pe
== PE_HeaderArrow
) {
557 if (flags
& Style_Down
)
564 if (pe
>= PE_ArrowUp
&& pe
<= PE_ArrowLeft
) {
569 a
.setPoints( 7, -4,1, 2,1, -3,0, 1,0, -2,-1, 0,-1, -1,-2 );
573 a
.setPoints( 7, -4,-2, 2,-2, -3,-1, 1,-1, -2,0, 0,0, -1,1 );
577 a
.setPoints( 7, -2,-3, -2,3, -1,-2, -1,2, 0,-1, 0,1, 1,0 );
581 a
.setPoints( 7, 0,-3, 0,3, -1,-2, -1,2, -2,-1, -2,1, -3,0 );
592 if ( flags
& Style_Enabled
) {
593 a
.translate( r
.x() + r
.width() / 2, r
.y() + r
.height() / 2 );
594 p
->setPen( cg
.buttonText() );
595 p
->drawLineSegments( a
, 0, 3 ); // draw arrow
596 p
->drawPoint( a
[6] );
598 a
.translate( r
.x() + r
.width() / 2 + 1, r
.y() + r
.height() / 2 + 1 );
599 p
->setPen( cg
.light() );
600 p
->drawLineSegments( a
, 0, 3 ); // draw arrow
601 p
->drawPoint( a
[6] );
602 a
.translate( -1, -1 );
603 p
->setPen( cg
.mid() );
604 p
->drawLineSegments( a
, 0, 3 ); // draw arrow
605 p
->drawPoint( a
[6] );
609 QCommonStyle::drawPrimitive(pe
, p
, r
, cg
, flags
, data
);
614 void LightStyleV2::drawControl( ControlElement control
,
615 const QStyleOption
*option
,
617 const QWidget
*widget
) const
619 QRect r
= option
->rect();
623 const QTabBar
* tb
= static_cast<const QTabBar
*>(widget
);
628 tr
.adjust(0, 0, 0, -1);
629 fr
.adjust(2, 2, -2, -2);
631 if ( tb
->shape() == QTabBar:: RoundedSouth
|| tb
->shape() == QTabBar:: TriangularSouth
) {
632 tr
= r
; tr
.adjust(0, 1, 0, 0);
633 fr
= r
; fr
.adjust(2, 2,-2, -4);
637 if (! (flags
& Style_Selected
)) {
639 tr
.adjust(0, 0, 0, -1);
640 tr
.adjust(0, 0, 0, -1);
642 tr
.adjust(0, 1, 0, 0);
643 fr
.adjust(0, 1, 0, 0);
646 p
->setPen(cg
.dark());
651 p
->drawPoint(tr
.left(), tr
.top() - 1);
653 p
->drawPoint(tr
.left(), tr
.bottom() + 1);
655 p
->setPen(cg
.light());
657 p
->drawLine(tr
.left() + 1, tr
.top() + 1,
658 tr
.left() + 1, tr
.bottom() - 2);
659 p
->drawLine(tr
.left() + 1, tr
.bottom() - 1,
660 tr
.right() - 1, tr
.bottom() - 1);
662 p
->drawLine(tr
.left() + 1, tr
.bottom() - 1,
663 tr
.left() + 1, tr
.top() + 2);
664 p
->drawLine(tr
.left() + 1, tr
.top() + 1,
665 tr
.right() - 1, tr
.top() + 1);
670 p
->drawLine(tr
.left() + 1, tr
.top() - 1,
671 tr
.right(), tr
.top() - 1);
674 p
->setPen(cg
.mid()); //To match lower border of the frame
675 p
->drawLine(tr
.left(), tr
.top() - 1,
676 tr
.right(), tr
.top() - 1);
680 p
->drawLine(tr
.left() + 1, tr
.bottom() + 1,
681 tr
.right(), tr
.bottom() + 1);
683 p
->drawLine(tr
.left(), tr
.bottom() + 1,
684 tr
.right(), tr
.bottom() + 1);
690 p
->drawLine(tr
.right() - 1, tr
.bottom() - 2,
691 tr
.right() - 1, tr
.top() + 1);
693 p
->drawLine(tr
.right() - 1, tr
.top() + 2,
694 tr
.right() - 1, tr
.bottom() - 1);
697 p
->setPen(cg
.dark());
700 p
->drawLine(tr
.left(), tr
.top() - 1,
701 tr
.left(), tr
.bottom() - 1);
703 p
->drawLine(tr
.left(), tr
.bottom() + 1,
704 tr
.left(), tr
.top() + 1);
707 p
->drawLine(tr
.left(), tr
.bottom(),
708 tr
.left(), tr
.top() + 1);
710 p
->drawLine(tr
.left(), tr
.bottom(),
711 tr
.left(), tr
.top() + 1);
714 p
->drawLine(tr
.left(), tr
.bottom(),
715 tr
.right(), tr
.bottom());
716 p
->drawLine(tr
.right(), tr
.bottom() - 1,
717 tr
.right(), tr
.top());
720 p
->drawLine(tr
.left(), tr
.top(),
721 tr
.right(), tr
.top());
722 p
->drawLine(tr
.right(), tr
.top() + 1,
723 tr
.right(), tr
.bottom());
726 p
->setPen(cg
.light());
729 p
->drawLine(tr
.left() + 1, tr
.top() - 2,
730 tr
.left() + 1, tr
.bottom() - 2);
732 p
->drawLine(tr
.left() + 1, tr
.bottom() + 2,
733 tr
.left() + 1, tr
.top() + 2);
736 p
->drawLine(tr
.left() + 1, tr
.top(),
737 tr
.left() + 1, tr
.bottom() - 2);
738 p
->drawPoint(tr
.left(), tr
.top() - 1);
741 p
->drawLine(tr
.left() + 1, tr
.bottom(),
742 tr
.left() + 1, tr
.top() + 2);
743 p
->drawPoint(tr
.left(), tr
.bottom() + 1);
748 p
->drawLine(tr
.left() + 1, tr
.bottom() - 1,
749 tr
.right() - 1, tr
.bottom() - 1);
750 p
->drawPoint(tr
.right(), tr
.top() - 1);
753 p
->drawLine(tr
.right() - 1, tr
.bottom() - 2,
754 tr
.right() - 1, tr
.top());
756 p
->drawLine(tr
.left() + 1, tr
.top() + 1,
757 tr
.right() - 1, tr
.top() + 1);
758 p
->drawPoint(tr
.right(), tr
.bottom() + 1);
761 p
->drawLine(tr
.right() - 1, tr
.top() + 2,
762 tr
.right() - 1, tr
.bottom());
766 p
->fillRect(fr
, ((flags
& Style_Selected
) ?
767 cg
.background() : cg
.mid()));
771 case CE_PopupMenuItem
:
773 if (! widget
|| data
.isDefault())
776 const QMenu
*popupmenu
= (const QMenu
*) widget
;
777 QMenuItem
*mi
= data
.menuItem();
778 int tab
= data
.tabWidth();
779 int maxpmw
= data
.maxIconWidth();
781 if ( mi
&& mi
->isSeparator() ) {
782 // draw separator (bg first, though)
783 if ( widget
->erasePixmap() && !widget
->erasePixmap()->isNull() )
784 p
->drawPixmap( r
.topLeft(), *widget
->erasePixmap(), r
);
786 p
->fillRect(r
, cg
.brush(QPalette::Button
));
788 p
->setPen(cg
.mid().dark(120));
789 p
->drawLine(r
.left() + 12, r
.top() + 1,
790 r
.right() - 12, r
.top() + 1);
791 p
->setPen(cg
.light());
792 p
->drawLine(r
.left() + 12, r
.top() + 2,
793 r
.right() - 12, r
.top() + 2);
797 if (flags
& Style_Active
)
798 qDrawShadePanel(p
, r
, cg
, true, 1,
799 &cg
.brush(QPalette::Midlight
));
800 else if ( widget
->erasePixmap() && !widget
->erasePixmap()->isNull() )
801 p
->drawPixmap( r
.topLeft(), *widget
->erasePixmap(), r
);
803 p
->fillRect(r
, cg
.brush(QPalette::Button
));
808 maxpmw
= qMax(maxpmw
, 16);
810 QRect cr
, ir
, tr
, sr
;
812 cr
.setRect(r
.left(), r
.top(), maxpmw
, r
.height());
813 // submenu indicator column
814 sr
.setCoords(r
.right() - maxpmw
, r
.top(), r
.right(), r
.bottom());
815 // tab/accelerator column
816 tr
.setCoords(sr
.left() - tab
- 4, r
.top(), sr
.left(), r
.bottom());
818 ir
.setCoords(cr
.right() + 4, r
.top(), tr
.right() - 4, r
.bottom());
820 bool reverse
= QApplication::isRightToLeft();
822 cr
= visualRect( cr
, r
);
823 sr
= visualRect( sr
, r
);
824 tr
= visualRect( tr
, r
);
825 ir
= visualRect( ir
, r
);
828 if (mi
->isChecked() &&
829 ! (flags
& Style_Active
) &
830 (flags
& Style_Enabled
))
831 qDrawShadePanel(p
, cr
, cg
, true, 1, &cg
.brush(QPalette::Midlight
));
835 (flags
& Style_Enabled
) ? QIcon::Normal
: QIcon::Disabled
;
836 if ((flags
& Style_Active
) && (flags
& Style_Enabled
))
837 mode
= QIcon::Active
;
839 if (popupmenu
->isCheckable() && mi
->isChecked())
841 mi
->iconSet()->pixmap( QIcon::Small
, mode
, QIcon::On
);
844 mi
->iconSet()->pixmap( QIcon::Small
, mode
);
845 QRect
pmr(QPoint(0, 0), pixmap
.size());
846 pmr
.moveCenter(cr
.center());
847 p
->setPen(cg
.text());
848 p
->drawPixmap(pmr
.topLeft(), pixmap
);
849 } else if (popupmenu
->isCheckable() && mi
->isChecked())
850 drawPrimitive(PE_CheckMark
, p
, cr
, cg
,
851 (flags
& Style_Enabled
) | Style_On
);
855 if (flags
& Style_Active
) {
856 if (! (flags
& Style_Enabled
))
857 textcolor
= cg
.midlight().dark();
859 textcolor
= cg
.buttonText();
860 embosscolor
= cg
.midlight().light();
861 } else if (! (flags
& Style_Enabled
)) {
862 textcolor
= cg
.text();
863 embosscolor
= cg
.light();
865 textcolor
= embosscolor
= cg
.buttonText();
866 p
->setPen(textcolor
);
870 if (! (flags
& Style_Enabled
)) {
871 p
->setPen(cg
.light());
872 mi
->custom()->paint(p
, cg
, flags
& Style_Active
,
873 flags
& Style_Enabled
,
874 ir
.x() + 1, ir
.y() + 1,
875 ir
.width() - 1, ir
.height() - 1);
876 p
->setPen(textcolor
);
878 mi
->custom()->paint(p
, cg
, flags
& Style_Active
,
879 flags
& Style_Enabled
,
881 ir
.width(), ir
.height());
885 QString text
= mi
->text();
886 if (! text
.isNull()) {
887 int t
= text
.find('\t');
889 // draw accelerator/tab-text
891 int alignFlag
= Qt::AlignVCenter
| Qt::TextShowMnemonic
| Qt::TextDontClip
| Qt::TextSingleLine
;
892 alignFlag
|= ( reverse
? Qt::AlignLeft
: Qt::AlignRight
);
893 if (! (flags
& Style_Enabled
)) {
894 p
->setPen(embosscolor
);
896 p
->drawText(tr
, alignFlag
, text
.mid(t
+ 1));
897 tr
.translate(-1, -1);
898 p
->setPen(textcolor
);
901 p
->drawText(tr
, alignFlag
, text
.mid(t
+ 1));
904 int alignFlag
= Qt::AlignVCenter
| Qt::TextShowMnemonic
| Qt::TextDontClip
| Qt::TextSingleLine
;
905 alignFlag
|= ( reverse
? Qt::AlignRight
: Qt::AlignLeft
);
907 if (! (flags
& Style_Enabled
)) {
908 p
->setPen(embosscolor
);
910 p
->drawText(ir
, alignFlag
, text
, t
);
911 ir
.translate(-1, -1);
912 p
->setPen(textcolor
);
915 p
->drawText(ir
, alignFlag
, text
, t
);
916 } else if (mi
->pixmap()) {
917 QPixmap pixmap
= *mi
->pixmap();
918 if (pixmap
.depth() == 1)
919 p
->setBackgroundMode(Qt::OpaqueMode
);
920 p
->drawPixmap(ir
.x(), ir
.y() + (ir
.height() - pixmap
.height()) / 2, pixmap
);
921 if (pixmap
.depth() == 1)
922 p
->setBackgroundMode(Qt::TransparentMode
);
926 drawPrimitive( (reverse
? PE_ArrowLeft
: PE_ArrowRight
), p
, sr
, cg
, flags
);
930 case CE_MenuBarEmptyArea
:
932 p
->fillRect(r
, cg
.brush(QPalette::Button
));
936 case CE_DockWindowEmptyArea
:
938 p
->fillRect(r
, cg
.brush(QPalette::Button
));
945 if (flags
& Style_Active
)
946 qDrawShadePanel(p
, r
, cg
, true, 1, &cg
.brush(QPalette::Midlight
));
948 p
->fillRect(r
, cg
.brush(QPalette::Button
));
950 if (data
.isDefault())
953 QMenuItem
*mi
= data
.menuItem();
954 drawItem(p
, r
, Qt::AlignCenter
| Qt::TextShowMnemonic
| Qt::TextDontClip
| Qt::TextSingleLine
, cg
,
955 flags
& Style_Enabled
, mi
->pixmap(), mi
->text(), -1,
960 case CE_ProgressBarGroove
:
961 drawLightBevel(p
, r
, cg
, Style_Sunken
, &cg
.brush(QPalette::Background
));
965 QCommonStyle::drawControl(control
, p
, widget
, r
, cg
, flags
, data
);
970 void LightStyleV2::drawControlMask( ControlElement control
,
972 const QWidget
*widget
,
974 const QStyleOption
&data
) const
978 p
->fillRect(r
, Qt::color1
);
982 QCommonStyle::drawControlMask(control
, p
, widget
, r
, data
);
987 QRect
LightStyleV2::subElementRect(SubElement subelement
, const QWidget
*widget
) const
989 QRect rect
, wrect(widget
->rect());
991 switch (subelement
) {
992 case SR_PushButtonFocusRect
:
994 const QPushButton
*button
= (const QPushButton
*) widget
;
995 int dbw1
= 0, dbw2
= 0;
996 if (button
->isDefault() || button
->autoDefault()) {
997 dbw1
= pixelMetric(PM_ButtonDefaultIndicator
, widget
);
1001 rect
.setRect(wrect
.x() + 3 + dbw1
,
1002 wrect
.y() + 3 + dbw1
,
1003 wrect
.width() - 6 - dbw2
,
1004 wrect
.height() - 6 - dbw2
);
1009 rect
= QCommonStyle::subElementRect(subelement
, widget
);
1015 void LightStyleV2::drawComplexControl( ComplexControl control
,
1017 const QWidget
* widget
,
1020 const QStyleOption
&data
) const
1025 const QComboBox
*combobox
= (const QComboBox
*) widget
;
1026 QRect frame
, arrow
, field
;
1028 QStyle::visualRect(querySubControlMetrics(CC_ComboBox
, widget
,
1029 SC_ComboBoxFrame
, data
),
1032 QStyle::visualRect(querySubControlMetrics(CC_ComboBox
, widget
,
1033 SC_ComboBoxArrow
, data
),
1036 QStyle::visualRect(querySubControlMetrics(CC_ComboBox
, widget
,
1037 SC_ComboBoxEditField
, data
),
1040 if ((controls
& SC_ComboBoxFrame
) && frame
.isValid())
1041 drawLightBevel(p
, frame
, cg
, flags
| Style_Raised
,
1042 &cg
.brush(QPalette::Button
));
1044 if ((controls
& SC_ComboBoxArrow
) && arrow
.isValid()) {
1045 if (active
== SC_ComboBoxArrow
)
1046 p
->fillRect(arrow
, cg
.brush(QPalette::Mid
));
1047 arrow
.adjust(4, 2, -2, -2);
1048 drawPrimitive(PE_ArrowDown
, p
, arrow
, cg
, flags
);
1051 if ((controls
& SC_ComboBoxEditField
) && field
.isValid()) {
1052 p
->setPen(cg
.dark());
1053 if (combobox
->editable()) {
1054 field
.adjust(-1, -1, 1, 1);
1057 p
->drawLine(field
.right() + 1, field
.top(),
1058 field
.right() + 1, field
.bottom());
1060 if (flags
& Style_HasFocus
) {
1061 if (! combobox
->editable()) {
1062 p
->fillRect( field
, cg
.brush( QPalette::Highlight
) );
1064 QStyle::visualRect( subRect( SR_ComboBoxFocusRect
, widget
),
1066 drawPrimitive( PE_FocusRect
, p
, fr
, cg
,
1067 flags
| Style_FocusAtBorder
,
1068 QStyleOption(cg
.highlight()));
1071 p
->setPen(cg
.highlightedText());
1073 p
->setPen(cg
.buttonText());
1081 const Q3SpinWidget
*spinwidget
= (const Q3SpinWidget
*) widget
;
1082 QRect frame
, up
, down
;
1084 frame
= querySubControlMetrics(CC_SpinWidget
, widget
,
1085 SC_SpinWidgetFrame
, data
);
1086 up
= spinwidget
->upRect();
1087 down
= spinwidget
->downRect();
1089 if ((controls
& SC_SpinWidgetFrame
) && frame
.isValid())
1090 drawLightBevel(p
, frame
, cg
, flags
| Style_Sunken
,
1091 &cg
.brush(QPalette::Base
));
1093 if ((controls
& SC_SpinWidgetUp
) && up
.isValid()) {
1094 PrimitiveElement pe
= PE_SpinWidgetUp
;
1095 if ( spinwidget
->buttonSymbols() == Q3SpinWidget::PlusMinus
)
1096 pe
= PE_SpinWidgetPlus
;
1098 p
->setPen(cg
.dark());
1099 p
->drawLine(up
.topLeft(), up
.bottomLeft());
1101 up
.adjust(1, 0, 0, 0);
1102 p
->fillRect(up
, cg
.brush(QPalette::Button
));
1103 if (active
== SC_SpinWidgetUp
)
1104 p
->setPen(cg
.mid());
1106 p
->setPen(cg
.light());
1107 p
->drawLine(up
.left(), up
.top(),
1108 up
.right() - 1, up
.top());
1109 p
->drawLine(up
.left(), up
.top() + 1,
1110 up
.left(), up
.bottom() - 1);
1111 if (active
== SC_SpinWidgetUp
)
1112 p
->setPen(cg
.light());
1114 p
->setPen(cg
.mid());
1115 p
->drawLine(up
.right(), up
.top(),
1116 up
.right(), up
.bottom());
1117 p
->drawLine(up
.left(), up
.bottom(),
1118 up
.right() - 1, up
.bottom());
1120 up
.adjust(1, 0, 0, 0);
1121 drawPrimitive(pe
, p
, up
, cg
, flags
|
1122 ((active
== SC_SpinWidgetUp
) ?
1123 Style_On
| Style_Sunken
: Style_Raised
));
1126 if ((controls
& SC_SpinWidgetDown
) && down
.isValid()) {
1127 PrimitiveElement pe
= PE_SpinWidgetDown
;
1128 if ( spinwidget
->buttonSymbols() == Q3SpinWidget::PlusMinus
)
1129 pe
= PE_SpinWidgetMinus
;
1131 p
->setPen(cg
.dark());
1132 p
->drawLine(down
.topLeft(), down
.bottomLeft());
1134 down
.adjust(1, 0, 0, 0);
1135 p
->fillRect(down
, cg
.brush(QPalette::Button
));
1136 if (active
== SC_SpinWidgetDown
)
1137 p
->setPen(cg
.mid());
1139 p
->setPen(cg
.light());
1140 p
->drawLine(down
.left(), down
.top(),
1141 down
.right() - 1, down
.top());
1142 p
->drawLine(down
.left(), down
.top() + 1,
1143 down
.left(), down
.bottom() - 1);
1144 if (active
== SC_SpinWidgetDown
)
1145 p
->setPen(cg
.light());
1147 p
->setPen(cg
.mid());
1148 p
->drawLine(down
.right(), down
.top(),
1149 down
.right(), down
.bottom());
1150 p
->drawLine(down
.left(), down
.bottom(),
1151 down
.right() - 1, down
.bottom());
1153 down
.adjust(1, 0, 0, 0);
1154 drawPrimitive(pe
, p
, down
, cg
, flags
|
1155 ((active
== SC_SpinWidgetDown
) ?
1156 Style_On
| Style_Sunken
: Style_Raised
));
1164 const QScrollBar
*scrollbar
= (const QScrollBar
*) widget
;
1165 QRect addline
, subline
, subline2
, addpage
, subpage
, slider
, first
, last
;
1166 bool maxedOut
= (scrollbar
->minValue() == scrollbar
->maxValue());
1168 subline
= querySubControlMetrics(control
, widget
, SC_ScrollBarSubLine
, data
);
1169 addline
= querySubControlMetrics(control
, widget
, SC_ScrollBarAddLine
, data
);
1170 subpage
= querySubControlMetrics(control
, widget
, SC_ScrollBarSubPage
, data
);
1171 addpage
= querySubControlMetrics(control
, widget
, SC_ScrollBarAddPage
, data
);
1172 slider
= querySubControlMetrics(control
, widget
, SC_ScrollBarSlider
, data
);
1173 first
= querySubControlMetrics(control
, widget
, SC_ScrollBarFirst
, data
);
1174 last
= querySubControlMetrics(control
, widget
, SC_ScrollBarLast
, data
);
1177 if (scrollbar
->orientation() == Qt::Horizontal
)
1178 subline2
.translate(-addline
.width(), 0);
1180 subline2
.translate(0, -addline
.height());
1182 if ((controls
& SC_ScrollBarSubLine
) && subline
.isValid()) {
1183 drawPrimitive(PE_ScrollBarSubLine
, p
, subline
, cg
,
1184 Style_Enabled
| ((active
== SC_ScrollBarSubLine
) ?
1185 Style_Down
: Style_Default
) |
1186 ((scrollbar
->orientation() == Qt::Horizontal
) ?
1187 Style_Horizontal
: 0));
1189 if (subline2
.isValid())
1190 drawPrimitive(PE_ScrollBarSubLine
, p
, subline2
, cg
,
1191 Style_Enabled
| ((active
== SC_ScrollBarSubLine
) ?
1192 Style_Down
: Style_Default
) |
1193 ((scrollbar
->orientation() == Qt::Horizontal
) ?
1194 Style_Horizontal
: 0));
1196 if ((controls
& SC_ScrollBarAddLine
) && addline
.isValid())
1197 drawPrimitive(PE_ScrollBarAddLine
, p
, addline
, cg
,
1198 Style_Enabled
| ((active
== SC_ScrollBarAddLine
) ?
1199 Style_Down
: Style_Default
) |
1200 ((scrollbar
->orientation() == Qt::Horizontal
) ?
1201 Style_Horizontal
: 0));
1202 if ((controls
& SC_ScrollBarSubPage
) && subpage
.isValid())
1203 drawPrimitive(PE_ScrollBarSubPage
, p
, subpage
, cg
,
1204 Style_Enabled
| ((active
== SC_ScrollBarSubPage
) ?
1205 Style_Down
: Style_Default
) |
1206 ((scrollbar
->orientation() == Qt::Horizontal
) ?
1207 Style_Horizontal
: 0));
1208 if ((controls
& SC_ScrollBarAddPage
) && addpage
.isValid())
1209 drawPrimitive(PE_ScrollBarAddPage
, p
, addpage
, cg
,
1210 ((maxedOut
) ? Style_Default
: Style_Enabled
) |
1211 ((active
== SC_ScrollBarAddPage
) ?
1212 Style_Down
: Style_Default
) |
1213 ((scrollbar
->orientation() == Qt::Horizontal
) ?
1214 Style_Horizontal
: 0));
1215 if ((controls
& SC_ScrollBarFirst
) && first
.isValid())
1216 drawPrimitive(PE_ScrollBarFirst
, p
, first
, cg
,
1217 Style_Enabled
| ((active
== SC_ScrollBarFirst
) ?
1218 Style_Down
: Style_Default
) |
1219 ((scrollbar
->orientation() == Qt::Horizontal
) ?
1220 Style_Horizontal
: 0));
1221 if ((controls
& SC_ScrollBarLast
) && last
.isValid())
1222 drawPrimitive(PE_ScrollBarLast
, p
, last
, cg
,
1223 Style_Enabled
| ((active
== SC_ScrollBarLast
) ?
1224 Style_Down
: Style_Default
) |
1225 ((scrollbar
->orientation() == Qt::Horizontal
) ?
1226 Style_Horizontal
: 0));
1227 if ((controls
& SC_ScrollBarSlider
) && slider
.isValid()) {
1228 drawPrimitive(PE_ScrollBarSlider
, p
, slider
, cg
,
1229 Style_Enabled
| ((active
== SC_ScrollBarSlider
) ?
1230 Style_Down
: Style_Default
) |
1231 ((scrollbar
->orientation() == Qt::Horizontal
) ?
1232 Style_Horizontal
: 0));
1234 // ### perhaps this should not be able to accept focus if maxedOut?
1235 if (scrollbar
->hasFocus()) {
1236 QRect
fr(slider
.x() + 2, slider
.y() + 2,
1237 slider
.width() - 5, slider
.height() - 5);
1238 drawPrimitive(PE_FocusRect
, p
, fr
, cg
, Style_Default
);
1247 const QSlider
*slider
= (const QSlider
*) widget
;
1248 QRect groove
= querySubControlMetrics(CC_Slider
, widget
, SC_SliderGroove
,
1250 handle
= querySubControlMetrics(CC_Slider
, widget
, SC_SliderHandle
,
1253 if ((controls
& SC_SliderGroove
) && groove
.isValid()) {
1254 if (flags
& Style_HasFocus
)
1255 drawPrimitive( PE_FocusRect
, p
, groove
, cg
);
1257 if (slider
->orientation() == Qt::Horizontal
) {
1258 int dh
= (groove
.height() - 5) / 2;
1259 groove
.adjust(0, dh
, 0, -dh
);
1261 int dw
= (groove
.width() - 5) / 2;
1262 groove
.adjust(dw
, 0, -dw
, 0);
1265 drawLightBevel(p
, groove
, cg
, ((flags
| Style_Raised
) ^ Style_Raised
) |
1266 ((flags
& Style_Enabled
) ? Style_Sunken
: Style_Default
),
1267 &cg
.brush(QPalette::Midlight
));
1270 if ((controls
& SC_SliderHandle
) && handle
.isValid()) {
1271 drawLightBevel(p
, handle
, cg
, ((flags
| Style_Down
) ^ Style_Down
) |
1272 ((flags
& Style_Enabled
) ? Style_Raised
: Style_Default
),
1273 &cg
.brush(QPalette::Button
));
1277 if (controls
& SC_SliderTickmarks
)
1278 QCommonStyle::drawComplexControl(control
, p
, widget
, r
, cg
, flags
,
1279 SC_SliderTickmarks
, active
, data
);
1284 // use the base style for CC_ListView
1285 singleton
->basestyle
->drawComplexControl(control
, p
, widget
, r
, cg
, flags
,
1286 controls
, active
, data
);
1290 QCommonStyle::drawComplexControl(control
, p
, widget
, r
, cg
, flags
,
1291 controls
, active
, data
);
1296 QRect
LightStyleV2::querySubControlMetrics( ComplexControl control
,
1297 const QWidget
*widget
,
1299 const QStyleOption
&data
) const
1306 const QScrollBar
*scrollbar
= (const QScrollBar
*) widget
;
1307 int sliderstart
= scrollbar
->sliderStart();
1308 int sbextent
= pixelMetric(PM_ScrollBarExtent
, widget
);
1309 int maxlen
= ((scrollbar
->orientation() == Qt::Horizontal
) ?
1310 scrollbar
->width() : scrollbar
->height()) - (sbextent
* 3);
1313 // calculate slider length
1314 if (scrollbar
->maxValue() != scrollbar
->minValue()) {
1315 uint range
= scrollbar
->maxValue() - scrollbar
->minValue();
1316 sliderlen
= (scrollbar
->pageStep() * maxlen
) /
1317 (range
+ scrollbar
->pageStep());
1319 int slidermin
= pixelMetric( PM_ScrollBarSliderMin
, widget
);
1320 if ( sliderlen
< slidermin
|| range
> INT_MAX
/ 2 )
1321 sliderlen
= slidermin
;
1322 if ( sliderlen
> maxlen
)
1328 case SC_ScrollBarSubLine
:
1330 ret
.setRect(0, 0, sbextent
, sbextent
);
1333 case SC_ScrollBarAddLine
:
1334 // bottom/right button
1335 if (scrollbar
->orientation() == Qt::Horizontal
)
1336 ret
.setRect(scrollbar
->width() - sbextent
, 0, sbextent
, sbextent
);
1338 ret
.setRect(0, scrollbar
->height() - sbextent
, sbextent
, sbextent
);
1341 case SC_ScrollBarSubPage
:
1342 // between top/left button and slider
1343 if (scrollbar
->orientation() == Qt::Horizontal
)
1344 ret
.setRect(sbextent
, 0, sliderstart
- sbextent
, sbextent
);
1346 ret
.setRect(0, sbextent
, sbextent
, sliderstart
- sbextent
);
1349 case SC_ScrollBarAddPage
:
1350 // between bottom/right button and slider
1351 if (scrollbar
->orientation() == Qt::Horizontal
)
1352 ret
.setRect(sliderstart
+ sliderlen
, 0,
1353 maxlen
- sliderstart
- sliderlen
+ sbextent
, sbextent
);
1355 ret
.setRect(0, sliderstart
+ sliderlen
,
1356 sbextent
, maxlen
- sliderstart
- sliderlen
+ sbextent
);
1359 case SC_ScrollBarGroove
:
1360 if (scrollbar
->orientation() == Qt::Horizontal
)
1361 ret
.setRect(sbextent
, 0, scrollbar
->width() - sbextent
* 3,
1362 scrollbar
->height());
1364 ret
.setRect(0, sbextent
, scrollbar
->width(),
1365 scrollbar
->height() - sbextent
* 3);
1368 case SC_ScrollBarSlider
:
1369 if (scrollbar
->orientation() == Qt::Horizontal
)
1370 ret
.setRect(sliderstart
, 0, sliderlen
, sbextent
);
1372 ret
.setRect(0, sliderstart
, sbextent
, sliderlen
);
1383 ret
= QCommonStyle::querySubControlMetrics(control
, widget
, sc
, data
);
1390 QStyle::SubControl
LightStyleV2::querySubControl( ComplexControl control
,
1391 const QWidget
*widget
,
1393 const QStyleOption
&data
) const
1395 QStyle::SubControl ret
= QCommonStyle::querySubControl(control
, widget
, pos
, data
);
1397 // this is an ugly hack, but i really don't care, it's the quickest way to
1398 // enabled the third button
1399 if (control
== CC_ScrollBar
&&
1401 ret
= SC_ScrollBarSubLine
;
1406 int LightStyleV2::pixelMetric( PixelMetric metric
,
1407 const QWidget
*widget
) const
1412 case PM_ButtonMargin
:
1416 case PM_ButtonShiftHorizontal
:
1417 case PM_ButtonShiftVertical
:
1421 case PM_ButtonDefaultIndicator
:
1422 case PM_DefaultFrameWidth
:
1426 case PM_IndicatorWidth
:
1427 case PM_IndicatorHeight
:
1428 case PM_ExclusiveIndicatorWidth
:
1429 case PM_ExclusiveIndicatorHeight
:
1433 case PM_TabBarTabOverlap
:
1437 case PM_ScrollBarExtent
:
1438 case PM_ScrollBarSliderMin
:
1442 case PM_MenuBarFrameWidth
:
1446 case PM_ProgressBarChunkWidth
:
1450 case PM_DockWindowSeparatorExtent
:
1454 case PM_SplitterWidth
:
1459 case PM_SliderLength
:
1460 case PM_SliderControlThickness
:
1461 ret
= singleton
->basestyle
->pixelMetric( metric
, widget
);
1464 case PM_MaximumDragDistance
:
1469 ret
= QCommonStyle::pixelMetric(metric
, widget
);
1476 QSize
LightStyleV2::sizeFromContents( ContentsType contents
,
1477 const QWidget
*widget
,
1478 const QSize
&contentsSize
,
1479 const QStyleOption
&data
) const
1486 const QPushButton
*button
= (const QPushButton
*) widget
;
1487 ret
= QCommonStyle::sizeFromContents( contents
, widget
, contentsSize
, data
);
1488 int w
= ret
.width(), h
= ret
.height();
1490 // only expand the button if we are displaying text...
1491 if ( ! button
->text().isEmpty() ) {
1492 if ( button
->isDefault() || button
->autoDefault() ) {
1493 // default button minimum size
1499 // regular button minimum size
1507 ret
= QSize( w
, h
);
1511 case CT_PopupMenuItem
:
1513 if (! widget
|| data
.isDefault())
1516 QMenuItem
*mi
= data
.menuItem();
1517 const QMenu
*popupmenu
= (const QMenu
*) widget
;
1518 int maxpmw
= data
.maxIconWidth();
1519 int w
= contentsSize
.width(), h
= contentsSize
.height();
1522 w
= mi
->custom()->sizeHint().width();
1523 h
= mi
->custom()->sizeHint().height();
1524 if (! mi
->custom()->fullSpan() && h
< 22)
1526 } else if(mi
->widget()) {
1527 } else if (mi
->isSeparator()) {
1531 // check is at least 16x16
1535 h
= qMax(h
, mi
->pixmap()->height());
1536 else if (! mi
->text().isNull())
1537 h
= qMax(h
, popupmenu
->fontMetrics().height() + 2);
1538 if (mi
->iconSet() != 0)
1539 h
= qMax(h
, mi
->iconSet()->pixmap(QIcon::Small
,
1540 QIcon::Normal
).height());
1544 // check | 4 pixels | item | 8 pixels | accel | 4 pixels | check
1546 // check is at least 16x16
1547 maxpmw
= qMax(maxpmw
, 16);
1548 w
+= (maxpmw
* 2) + 8;
1550 if (! mi
->text().isNull() && mi
->text().find('\t') >= 0)
1556 case CT_ProgressBar
:
1558 const QProgressBar
* pb
= static_cast<const QProgressBar
*>(widget
);
1560 //If we have to display the indicator, and we do it on RHS, give some more room
1561 //for it. This tries to match the logic and the spacing in SR_ProgressBarGroove/Contents
1562 //sizing in QCommonStyle.
1563 if (pb
->percentageVisible() &&
1564 (pb
->indicatorFollowsStyle() || ! pb
->centerIndicator()))
1566 int addw
= pb
->fontMetrics().width("100%") + 6;
1567 return QSize(contentsSize
.width() + addw
, contentsSize
.height());
1570 return contentsSize
; //Otherwise leave unchanged
1576 ret
= QCommonStyle::sizeFromContents(contents
, widget
, contentsSize
, data
);
1583 int LightStyleV2::styleHint( StyleHint stylehint
,
1584 const QWidget
*widget
,
1585 const QStyleOption
&option
,
1586 QStyleHintReturn
* returnData
) const
1590 switch (stylehint
) {
1591 case SH_EtchDisabledText
:
1592 case SH_Slider_SnapToValue
:
1593 case SH_PrintDialog_RightAlignButtons
:
1594 case SH_FontDialog_SelectAssociatedText
:
1595 case SH_MenuBar_AltKeyNavigation
:
1596 case SH_MenuBar_MouseTracking
:
1597 case SH_PopupMenu_MouseTracking
:
1598 case SH_ComboBox_ListMouseTracking
:
1599 case SH_ScrollBar_MiddleClickAbsolutePosition
:
1603 case SH_MainWindow_SpaceBelowMenuBar
:
1608 ret
= QCommonStyle::styleHint(stylehint
, widget
, option
, returnData
);
1615 QPixmap
LightStyleV2::standardPixmap( StylePixmap standardpixmap
,
1616 const QWidget
*widget
,
1617 const QStyleOption
&data
) const
1619 return singleton
->basestyle
->standardPixmap( stylepixmap
, widget
, data
);
1621 #include "lightstyle-v2.moc"