source: trunk/3.3.1/src/styles/qcommonstyle.cpp@ 5

Last change on this file since 5 was 2, checked in by dmik, 20 years ago

Imported xplatform parts of the official release 3.3.1 from Trolltech

  • Property svn:keywords set to Id
File size: 77.2 KB
Line 
1/****************************************************************************
2** $Id: qcommonstyle.cpp 2 2005-11-16 15:49:26Z dmik $
3**
4** Implementation of the QCommonStyle class
5**
6** Created : 981231
7**
8** Copyright (C) 1998-2000 Trolltech AS. All rights reserved.
9**
10** This file is part of the widgets module of the Qt GUI Toolkit.
11**
12** This file may be distributed under the terms of the Q Public License
13** as defined by Trolltech AS of Norway and appearing in the file
14** LICENSE.QPL included in the packaging of this file.
15**
16** This file may be distributed and/or modified under the terms of the
17** GNU General Public License version 2 as published by the Free Software
18** Foundation and appearing in the file LICENSE.GPL included in the
19** packaging of this file.
20**
21** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
22** licenses may use this file in accordance with the Qt Commercial License
23** Agreement provided with the Software.
24**
25** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
26** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27**
28** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
29** information about Qt Commercial License Agreements.
30** See http://www.trolltech.com/qpl/ for QPL licensing information.
31** See http://www.trolltech.com/gpl/ for GPL licensing information.
32**
33** Contact info@trolltech.com if any conditions of this licensing are
34** not clear to you.
35**
36**********************************************************************/
37
38#include "qcommonstyle.h"
39
40#ifndef QT_NO_STYLE
41
42#include "qmenubar.h"
43#include "qapplication.h"
44#include "qpainter.h"
45#include "qdrawutil.h"
46#include "qpixmap.h"
47#include "qpushbutton.h"
48#include "qtabbar.h"
49#include "qscrollbar.h"
50#include "qtoolbutton.h"
51#include "qtoolbar.h"
52#include "qdockarea.h"
53#include "qheader.h"
54#include "qspinbox.h"
55#include "qrangecontrol.h"
56#include "qgroupbox.h"
57#include "qslider.h"
58#include "qlistview.h"
59#include "qcheckbox.h"
60#include "qradiobutton.h"
61#include "qbitmap.h"
62#include "qprogressbar.h"
63#include "private/qdialogbuttons_p.h"
64#include <limits.h>
65#include <qpixmap.h>
66#include "../widgets/qtitlebar_p.h"
67#include <qtoolbox.h>
68
69/*!
70 \class QCommonStyle qcommonstyle.h
71 \brief The QCommonStyle class encapsulates the common Look and Feel of a GUI.
72
73 \ingroup appearance
74
75 This abstract class implements some of the widget's look and feel
76 that is common to all GUI styles provided and shipped as part of
77 Qt.
78
79 All the functions are documented in \l QStyle.
80*/
81
82/*!
83 \enum Qt::ArrowType
84
85 \value UpArrow
86 \value DownArrow
87 \value LeftArrow
88 \value RightArrow
89
90*/
91
92// the active painter, if any... this is used as an optimzation to
93// avoid creating a painter if we have an active one (since
94// QStyle::itemRect() needs a painter to operate correctly
95static QPainter *activePainter = 0;
96
97/*!
98 Constructs a QCommonStyle.
99*/
100QCommonStyle::QCommonStyle() : QStyle()
101{
102 activePainter = 0;
103}
104
105/*! \reimp */
106QCommonStyle::~QCommonStyle()
107{
108 activePainter = 0;
109}
110
111
112static const char * const check_list_controller_xpm[] = {
113"16 16 4 1",
114" c None",
115". c #000000000000",
116"X c #FFFFFFFF0000",
117"o c #C71BC30BC71B",
118" ",
119" ",
120" .......... ",
121" .XXXXXXXX. ",
122" .XXXXXXXX.oo ",
123" .XXXXXXXX.oo ",
124" .XXXXXXXX.oo ",
125" .XXXXXXXX.oo ",
126" .XXXXXXXX.oo ",
127" .XXXXXXXX.oo ",
128" .XXXXXXXX.oo ",
129" ..........oo ",
130" oooooooooo ",
131" oooooooooo ",
132" ",
133" "};
134
135/*! \reimp */
136void QCommonStyle::drawPrimitive( PrimitiveElement pe,
137 QPainter *p,
138 const QRect &r,
139 const QColorGroup &cg,
140 SFlags flags,
141 const QStyleOption& opt ) const
142{
143 activePainter = p;
144
145 switch (pe) {
146#ifndef QT_NO_LISTVIEW
147 case PE_CheckListController: {
148 p->drawPixmap(r, QPixmap((const char **)check_list_controller_xpm));
149 break; }
150 case PE_CheckListExclusiveIndicator: {
151 QCheckListItem *item = opt.checkListItem();
152 QListView *lv = item->listView();
153 if(!item)
154 return;
155 int x = r.x(), y = r.y();
156#define QCOORDARRLEN(x) sizeof(x)/(sizeof(QCOORD)*2)
157 static const QCOORD pts1[] = { // dark lines
158 1,9, 1,8, 0,7, 0,4, 1,3, 1,2, 2,1, 3,1, 4,0, 7,0, 8,1, 9,1 };
159 static const QCOORD pts2[] = { // black lines
160 2,8, 1,7, 1,4, 2,3, 2,2, 3,2, 4,1, 7,1, 8,2, 9,2 };
161 static const QCOORD pts3[] = { // background lines
162 2,9, 3,9, 4,10, 7,10, 8,9, 9,9, 9,8, 10,7, 10,4, 9,3 };
163 static const QCOORD pts4[] = { // white lines
164 2,10, 3,10, 4,11, 7,11, 8,10, 9,10, 10,9, 10,8, 11,7,
165 11,4, 10,3, 10,2 };
166 // static const QCOORD pts5[] = { // inner fill
167 // 4,2, 7,2, 9,4, 9,7, 7,9, 4,9, 2,7, 2,4 };
168 //QPointArray a;
169 // p->eraseRect( x, y, w, h );
170
171 if ( flags & Style_Enabled )
172 p->setPen( cg.text() );
173 else
174 p->setPen( QPen( lv->palette().color( QPalette::Disabled, QColorGroup::Text ) ) );
175 QPointArray a( QCOORDARRLEN(pts1), pts1 );
176 a.translate( x, y );
177 //p->setPen( cg.dark() );
178 p->drawPolyline( a );
179 a.setPoints( QCOORDARRLEN(pts2), pts2 );
180 a.translate( x, y );
181 p->drawPolyline( a );
182 a.setPoints( QCOORDARRLEN(pts3), pts3 );
183 a.translate( x, y );
184 // p->setPen( black );
185 p->drawPolyline( a );
186 a.setPoints( QCOORDARRLEN(pts4), pts4 );
187 a.translate( x, y );
188 // p->setPen( blue );
189 p->drawPolyline( a );
190 // a.setPoints( QCOORDARRLEN(pts5), pts5 );
191 // a.translate( x, y );
192 // QColor fillColor = isDown() ? g.background() : g.base();
193 // p->setPen( fillColor );
194 // p->setBrush( fillColor );
195 // p->drawPolygon( a );
196 if ( flags & Style_On ) {
197 p->setPen( NoPen );
198 p->setBrush( cg.text() );
199 p->drawRect( x+5, y+4, 2, 4 );
200 p->drawRect( x+4, y+5, 4, 2 );
201 }
202 break; }
203 case PE_CheckListIndicator: {
204 QCheckListItem *item = opt.checkListItem();
205 QListView *lv = item->listView();
206 if(!item)
207 return;
208 int x = r.x(), y = r.y(), w = r.width(), h = r.width(), marg = lv->itemMargin();
209
210 if ( flags & Style_Enabled )
211 p->setPen( QPen( cg.text(), 2 ) );
212 else
213 p->setPen( QPen( lv->palette().color( QPalette::Disabled, QColorGroup::Text ),
214 2 ) );
215 bool parentControl = FALSE;
216 if ( item->parent() && item->parent()->rtti() == 1 &&
217 ((QCheckListItem*) item->parent())->type() == QCheckListItem::Controller )
218 parentControl = TRUE;
219 if ( flags & Style_Selected && !lv->rootIsDecorated() && !parentControl ) {
220 p->fillRect( 0, 0, x + marg + w + 4, item->height(),
221 cg.brush( QColorGroup::Highlight ) );
222 if ( item->isEnabled() )
223 p->setPen( QPen( cg.highlightedText(), 2 ) );
224 }
225
226 if ( flags & Style_NoChange )
227 p->setBrush( cg.brush( QColorGroup::Button ) );
228 p->drawRect( x+marg, y+2, w-4, h-4 );
229 /////////////////////
230 x++;
231 y++;
232 if ( ( flags & Style_On) || ( flags & Style_NoChange ) ) {
233 QPointArray a( 7*2 );
234 int i, xx = x+1+marg, yy=y+5;
235 for ( i=0; i<3; i++ ) {
236 a.setPoint( 2*i, xx, yy );
237 a.setPoint( 2*i+1, xx, yy+2 );
238 xx++; yy++;
239 }
240 yy -= 2;
241 for ( i=3; i<7; i++ ) {
242 a.setPoint( 2*i, xx, yy );
243 a.setPoint( 2*i+1, xx, yy+2 );
244 xx++; yy--;
245 }
246 p->drawLineSegments( a );
247 }
248 break; }
249#endif
250 case PE_HeaderArrow:
251 p->save();
252 if ( flags & Style_Down ) {
253 QPointArray pa( 3 );
254 p->setPen( cg.light() );
255 p->drawLine( r.x() + r.width(), r.y(), r.x() + r.width() / 2, r.height() );
256 p->setPen( cg.dark() );
257 pa.setPoint( 0, r.x() + r.width() / 2, r.height() );
258 pa.setPoint( 1, r.x(), r.y() );
259 pa.setPoint( 2, r.x() + r.width(), r.y() );
260 p->drawPolyline( pa );
261 } else {
262 QPointArray pa( 3 );
263 p->setPen( cg.light() );
264 pa.setPoint( 0, r.x(), r.height() );
265 pa.setPoint( 1, r.x() + r.width(), r.height() );
266 pa.setPoint( 2, r.x() + r.width() / 2, r.y() );
267 p->drawPolyline( pa );
268 p->setPen( cg.dark() );
269 p->drawLine( r.x(), r.height(), r.x() + r.width() / 2, r.y() );
270 }
271 p->restore();
272 break;
273
274 case PE_StatusBarSection:
275 qDrawShadeRect( p, r, cg, TRUE, 1, 0, 0 );
276 break;
277
278 case PE_ButtonCommand:
279 case PE_ButtonBevel:
280 case PE_ButtonTool:
281 case PE_ButtonDropDown:
282 case PE_HeaderSection:
283 qDrawShadePanel(p, r, cg, flags & (Style_Sunken | Style_Down | Style_On) , 1,
284 &cg.brush(QColorGroup::Button));
285 break;
286
287 case PE_Separator:
288 qDrawShadeLine( p, r.left(), r.top(), r.right(), r.bottom(), cg,
289 flags & Style_Sunken, 1, 0);
290 break;
291
292 case PE_FocusRect: {
293 const QColor *bg = 0;
294
295 if (!opt.isDefault())
296 bg = &opt.color();
297
298 QPen oldPen = p->pen();
299
300 if (bg) {
301 int h, s, v;
302 bg->hsv(&h, &s, &v);
303 if (v >= 128)
304 p->setPen(Qt::black);
305 else
306 p->setPen(Qt::white);
307 } else
308 p->setPen(cg.foreground());
309
310 if (flags & Style_FocusAtBorder)
311 p->drawRect(QRect(r.x() + 1, r.y() + 1, r.width() - 2, r.height() - 2));
312 else
313 p->drawRect(r);
314
315 p->setPen(oldPen);
316 break; }
317
318 case PE_SpinWidgetPlus:
319 case PE_SpinWidgetMinus: {
320 p->save();
321 int fw = pixelMetric( PM_DefaultFrameWidth, 0 );
322 QRect br;
323 br.setRect( r.x() + fw, r.y() + fw, r.width() - fw*2,
324 r.height() - fw*2 );
325
326 p->fillRect( br, cg.brush( QColorGroup::Button ) );
327 p->setPen( cg.buttonText() );
328 p->setBrush( cg.buttonText() );
329
330 int length;
331 int x = r.x(), y = r.y(), w = r.width(), h = r.height();
332 if ( w <= 8 || h <= 6 )
333 length = QMIN( w-2, h-2 );
334 else
335 length = QMIN( 2*w / 3, 2*h / 3 );
336
337 if ( !(length & 1) )
338 length -=1;
339 int xmarg = ( w - length ) / 2;
340 int ymarg = ( h - length ) / 2;
341
342 p->drawLine( x + xmarg, ( y + h / 2 - 1 ),
343 x + xmarg + length - 1, ( y + h / 2 - 1 ) );
344 if ( pe == PE_SpinWidgetPlus )
345 p->drawLine( ( x+w / 2 ) - 1, y + ymarg,
346 ( x+w / 2 ) - 1, y + ymarg + length - 1 );
347 p->restore();
348 break; }
349
350 case PE_SpinWidgetUp:
351 case PE_SpinWidgetDown: {
352 int fw = pixelMetric( PM_DefaultFrameWidth, 0 );
353 QRect br;
354 br.setRect( r.x() + fw, r.y() + fw, r.width() - fw*2,
355 r.height() - fw*2 );
356 p->fillRect( br, cg.brush( QColorGroup::Button ) );
357 int x = r.x(), y = r.y(), w = r.width(), h = r.height();
358 int sw = w-4;
359 if ( sw < 3 )
360 break;
361 else if ( !(sw & 1) )
362 sw--;
363 sw -= ( sw / 7 ) * 2; // Empty border
364 int sh = sw/2 + 2; // Must have empty row at foot of arrow
365
366 int sx = x + w / 2 - sw / 2 - 1;
367 int sy = y + h / 2 - sh / 2 - 1;
368
369 QPointArray a;
370 if ( pe == PE_SpinWidgetDown )
371 a.setPoints( 3, 0, 1, sw-1, 1, sh-2, sh-1 );
372 else
373 a.setPoints( 3, 0, sh-1, sw-1, sh-1, sh-2, 1 );
374 int bsx = 0;
375 int bsy = 0;
376 if ( flags & Style_Sunken ) {
377 bsx = pixelMetric(PM_ButtonShiftHorizontal);
378 bsy = pixelMetric(PM_ButtonShiftVertical);
379 }
380 p->save();
381 p->translate( sx + bsx, sy + bsy );
382 p->setPen( cg.buttonText() );
383 p->setBrush( cg.buttonText() );
384 p->drawPolygon( a );
385 p->restore();
386 break; }
387
388 case PE_Indicator: {
389 if (flags & Style_NoChange) {
390 p->setPen(cg.foreground());
391 p->fillRect(r, cg.brush(QColorGroup::Button));
392 p->drawRect(r);
393 p->drawLine(r.topLeft(), r.bottomRight());
394 } else
395 qDrawShadePanel(p, r.x(), r.y(), r.width(), r.height(),
396 cg, flags & (Style_Sunken | Style_On), 1,
397 &cg.brush(QColorGroup::Button));
398 break; }
399
400 case PE_IndicatorMask: {
401 p->fillRect(r, color1);
402 break; }
403
404 case PE_ExclusiveIndicator: {
405 QRect ir = r;
406 p->setPen(cg.dark());
407 p->drawArc(r, 0, 5760);
408
409 if (flags & (Style_Sunken | Style_On)) {
410 ir.addCoords(2, 2, -2, -2);
411 p->setBrush(cg.foreground());
412 p->drawEllipse(ir);
413 }
414
415 break; }
416
417 case PE_ExclusiveIndicatorMask: {
418 p->setPen(color1);
419 p->setBrush(color1);
420 p->drawEllipse(r);
421 break; }
422
423 case PE_DockWindowHandle: {
424 bool highlight = flags & Style_On;
425
426 p->save();
427 p->translate( r.x(), r.y() );
428 if ( flags & Style_Horizontal ) {
429 int x = r.width() / 3;
430 if ( r.height() > 4 ) {
431 qDrawShadePanel( p, x, 2, 3, r.height() - 4,
432 cg, highlight, 1, 0 );
433 qDrawShadePanel( p, x+3, 2, 3, r.height() - 4,
434 cg, highlight, 1, 0 );
435 }
436 } else {
437 if ( r.width() > 4 ) {
438 int y = r.height() / 3;
439 qDrawShadePanel( p, 2, y, r.width() - 4, 3,
440 cg, highlight, 1, 0 );
441 qDrawShadePanel( p, 2, y+3, r.width() - 4, 3,
442 cg, highlight, 1, 0 );
443 }
444 }
445 p->restore();
446 break;
447 }
448
449 case PE_DockWindowSeparator: {
450 QPoint p1, p2;
451 if ( flags & Style_Horizontal ) {
452 p1 = QPoint( r.width()/2, 0 );
453 p2 = QPoint( p1.x(), r.height() );
454 } else {
455 p1 = QPoint( 0, r.height()/2 );
456 p2 = QPoint( r.width(), p1.y() );
457 }
458 qDrawShadeLine( p, p1, p2, cg, 1, 1, 0 );
459 break; }
460
461 case PE_Panel:
462 case PE_PanelPopup: {
463 int lw = opt.isDefault() ? pixelMetric(PM_DefaultFrameWidth)
464 : opt.lineWidth();
465
466 qDrawShadePanel(p, r, cg, (flags & Style_Sunken), lw);
467 break; }
468
469 case PE_PanelDockWindow: {
470 int lw = opt.isDefault() ? pixelMetric(PM_DockWindowFrameWidth)
471 : opt.lineWidth();
472
473 qDrawShadePanel(p, r, cg, FALSE, lw);
474 break; }
475
476 case PE_PanelMenuBar: {
477 int lw = opt.isDefault() ? pixelMetric(PM_MenuBarFrameWidth)
478 : opt.lineWidth();
479
480 qDrawShadePanel(p, r, cg, FALSE, lw, &cg.brush(QColorGroup::Button));
481 break; }
482
483 case PE_SizeGrip: {
484 p->save();
485
486 int x, y, w, h;
487 r.rect(&x, &y, &w, &h);
488
489 int sw = QMIN( h,w );
490 if ( h > w )
491 p->translate( 0, h - w );
492 else
493 p->translate( w - h, 0 );
494
495 int sx = x;
496 int sy = y;
497 int s = sw / 3;
498
499 if ( QApplication::reverseLayout() ) {
500 sx = x + sw;
501 for ( int i = 0; i < 4; ++i ) {
502 p->setPen( QPen( cg.light(), 1 ) );
503 p->drawLine( x, sy - 1 , sx + 1, sw );
504 p->setPen( QPen( cg.dark(), 1 ) );
505 p->drawLine( x, sy, sx, sw );
506 p->setPen( QPen( cg.dark(), 1 ) );
507 p->drawLine( x, sy + 1, sx - 1, sw );
508 sx -= s;
509 sy += s;
510 }
511 } else {
512 for ( int i = 0; i < 4; ++i ) {
513 p->setPen( QPen( cg.light(), 1 ) );
514 p->drawLine( sx-1, sw, sw, sy-1 );
515 p->setPen( QPen( cg.dark(), 1 ) );
516 p->drawLine( sx, sw, sw, sy );
517 p->setPen( QPen( cg.dark(), 1 ) );
518 p->drawLine( sx+1, sw, sw, sy+1 );
519 sx += s;
520 sy += s;
521 }
522 }
523
524 p->restore();
525 break; }
526
527 case PE_CheckMark: {
528 const int markW = r.width() > 7 ? 7 : r.width();
529 const int markH = markW;
530 int posX = r.x() + ( r.width() - markW )/2 + 1;
531 int posY = r.y() + ( r.height() - markH )/2;
532
533 // Could do with some optimizing/caching...
534 QPointArray a( markH*2 );
535 int i, xx, yy;
536 xx = posX;
537 yy = 3 + posY;
538 for ( i=0; i<markW/2; i++ ) {
539 a.setPoint( 2*i, xx, yy );
540 a.setPoint( 2*i+1, xx, yy+2 );
541 xx++; yy++;
542 }
543 yy -= 2;
544 for ( ; i<markH; i++ ) {
545 a.setPoint( 2*i, xx, yy );
546 a.setPoint( 2*i+1, xx, yy+2 );
547 xx++; yy--;
548 }
549 if ( !(flags & Style_Enabled) && !(flags & Style_On)) {
550 int pnt;
551 p->setPen( cg.highlightedText() );
552 QPoint offset(1,1);
553 for ( pnt = 0; pnt < (int)a.size(); pnt++ )
554 a[pnt] += offset;
555 p->drawLineSegments( a );
556 for ( pnt = 0; pnt < (int)a.size(); pnt++ )
557 a[pnt] -= offset;
558 }
559 p->setPen( cg.text() );
560 p->drawLineSegments( a );
561 break; }
562
563 case PE_PanelGroupBox: //We really do not need PE_GroupBoxFrame anymore, nasty holdover ###
564 drawPrimitive( PE_GroupBoxFrame, p, r, cg, flags, opt );
565 break;
566 case PE_GroupBoxFrame: {
567#ifndef QT_NO_FRAME
568 if ( opt.isDefault() )
569 break;
570 int lwidth = opt.lineWidth(), mlwidth = opt.midLineWidth();
571 if ( flags & (Style_Sunken|Style_Raised))
572 qDrawShadeRect( p, r.x(), r.y(), r.width(), r.height(), cg, flags & Style_Sunken, lwidth, mlwidth );
573 else
574 qDrawPlainRect( p, r.x(), r.y(), r.width(), r.height(), cg.foreground(), lwidth );
575#endif
576 break; }
577
578 case PE_ProgressBarChunk:
579 p->fillRect( r.x(), r.y() + 3, r.width() -2, r.height() - 6,
580 cg.brush(QColorGroup::Highlight));
581 break;
582
583 case PE_PanelLineEdit:
584 case PE_PanelTabWidget:
585 case PE_WindowFrame:
586 drawPrimitive( PE_Panel, p, r, cg, flags, opt );
587 break;
588
589 case PE_RubberBand:
590 drawPrimitive(PE_FocusRect, p, r, cg, flags, opt);
591 break;
592 default:
593 break;
594 }
595
596 activePainter = 0;
597}
598
599/*! \reimp */
600void QCommonStyle::drawControl( ControlElement element,
601 QPainter *p,
602 const QWidget *widget,
603 const QRect &r,
604 const QColorGroup &cg,
605 SFlags flags,
606 const QStyleOption& opt ) const
607{
608#if defined(QT_CHECK_STATE)
609 if (! widget) {
610 qWarning("QCommonStyle::drawControl: widget parameter cannot be zero!");
611 return;
612 }
613#endif
614
615 activePainter = p;
616
617 switch (element) {
618 case CE_MenuBarEmptyArea: {
619 QRegion reg;
620 if(p->hasClipping()) //ick
621 reg = p->clipRegion();
622 else
623 reg = r;
624 ((QWidget *)widget)->erase( reg );
625 break; }
626 case CE_PushButton:
627 {
628#ifndef QT_NO_PUSHBUTTON
629 const QPushButton *button = (const QPushButton *) widget;
630 QRect br = r;
631 int dbi = pixelMetric(PM_ButtonDefaultIndicator, widget);
632
633 if (button->isDefault() || button->autoDefault()) {
634 if ( button->isDefault())
635 drawPrimitive(PE_ButtonDefault, p, br, cg, flags);
636
637 br.setCoords(br.left() + dbi,
638 br.top() + dbi,
639 br.right() - dbi,
640 br.bottom() - dbi);
641 }
642
643 p->save();
644 p->setBrushOrigin( -widget->backgroundOffset().x(),
645 -widget->backgroundOffset().y() );
646 drawPrimitive(PE_ButtonCommand, p, br, cg, flags);
647 p->restore();
648#endif
649 break;
650 }
651
652 case CE_PushButtonLabel:
653 {
654#ifndef QT_NO_PUSHBUTTON
655 const QPushButton *button = (const QPushButton *) widget;
656 QRect ir = r;
657
658 if (button->isDown() || button->isOn()) {
659 flags |= Style_Sunken;
660 ir.moveBy(pixelMetric(PM_ButtonShiftHorizontal, widget),
661 pixelMetric(PM_ButtonShiftVertical, widget));
662 }
663
664 if (button->isMenuButton()) {
665 int mbi = pixelMetric(PM_MenuButtonIndicator, widget);
666 QRect ar(ir.right() - mbi, ir.y() + 2, mbi - 4, ir.height() - 4);
667 drawPrimitive(PE_ArrowDown, p, ar, cg, flags, opt);
668 ir.setWidth(ir.width() - mbi);
669 }
670
671 int tf=AlignVCenter | ShowPrefix;
672 if (!styleHint(SH_UnderlineAccelerator, widget, QStyleOption::Default, 0))
673 tf |= NoAccel;
674
675#ifndef QT_NO_ICONSET
676 if ( button->iconSet() && ! button->iconSet()->isNull() ) {
677 QIconSet::Mode mode =
678 button->isEnabled() ? QIconSet::Normal : QIconSet::Disabled;
679 if ( mode == QIconSet::Normal && button->hasFocus() )
680 mode = QIconSet::Active;
681
682 QIconSet::State state = QIconSet::Off;
683 if ( button->isToggleButton() && button->isOn() )
684 state = QIconSet::On;
685
686 QPixmap pixmap = button->iconSet()->pixmap( QIconSet::Small, mode, state );
687 int pixw = pixmap.width();
688 int pixh = pixmap.height();
689
690 //Center the icon if there is neither text nor pixmap
691 if ( button->text().isEmpty() && !button->pixmap() )
692 p->drawPixmap( ir.x() + ir.width() / 2 - pixw / 2, ir.y() + ir.height() / 2 - pixh / 2, pixmap );
693 else
694 p->drawPixmap( ir.x() + 2, ir.y() + ir.height() / 2 - pixh / 2, pixmap );
695
696 ir.moveBy(pixw + 4, 0);
697 ir.setWidth(ir.width() - (pixw + 4));
698 // left-align text if there is
699 if (!button->text().isEmpty())
700 tf |= AlignLeft;
701 else if (button->pixmap())
702 tf |= AlignHCenter;
703 } else
704#endif //QT_NO_ICONSET
705 tf |= AlignHCenter;
706 drawItem(p, ir, tf, cg,
707 flags & Style_Enabled, button->pixmap(), button->text(),
708 button->text().length(), &(cg.buttonText()) );
709
710 if (flags & Style_HasFocus)
711 drawPrimitive(PE_FocusRect, p, subRect(SR_PushButtonFocusRect, widget),
712 cg, flags);
713#endif
714 break;
715 }
716
717 case CE_CheckBox:
718 drawPrimitive(PE_Indicator, p, r, cg, flags, opt);
719 break;
720
721 case CE_CheckBoxLabel:
722 {
723#ifndef QT_NO_CHECKBOX
724 const QCheckBox *checkbox = (const QCheckBox *) widget;
725
726 int alignment = QApplication::reverseLayout() ? AlignRight : AlignLeft;
727 if (!styleHint(SH_UnderlineAccelerator, widget, QStyleOption::Default, 0))
728 alignment |= NoAccel;
729
730 drawItem(p, r, alignment | AlignVCenter | ShowPrefix, cg,
731 flags & Style_Enabled, checkbox->pixmap(), checkbox->text());
732
733 if (flags & Style_HasFocus) {
734 QRect fr = visualRect(subRect(SR_CheckBoxFocusRect, widget), widget);
735 drawPrimitive(PE_FocusRect, p, fr, cg, flags);
736 }
737#endif
738 break;
739 }
740
741 case CE_RadioButton:
742 drawPrimitive(PE_ExclusiveIndicator, p, r, cg, flags, opt);
743 break;
744
745 case CE_RadioButtonLabel:
746 {
747#ifndef QT_NO_RADIOBUTTON
748 const QRadioButton *radiobutton = (const QRadioButton *) widget;
749
750 int alignment = QApplication::reverseLayout() ? AlignRight : AlignLeft;
751 if (!styleHint(SH_UnderlineAccelerator, widget, QStyleOption::Default, 0))
752 alignment |= NoAccel;
753 drawItem(p, r, alignment | AlignVCenter | ShowPrefix, cg,
754 flags & Style_Enabled, radiobutton->pixmap(), radiobutton->text());
755
756 if (flags & Style_HasFocus) {
757 QRect fr = visualRect(subRect(SR_RadioButtonFocusRect, widget), widget);
758 drawPrimitive(PE_FocusRect, p, fr, cg, flags);
759 }
760#endif
761 break;
762 }
763
764#ifndef QT_NO_TABBAR
765 case CE_TabBarTab:
766 {
767 const QTabBar * tb = (const QTabBar *) widget;
768
769 if ( tb->shape() == QTabBar::TriangularAbove ||
770 tb->shape() == QTabBar::TriangularBelow ) {
771 // triangular, above or below
772 int y;
773 int x;
774 QPointArray a( 10 );
775 a.setPoint( 0, 0, -1 );
776 a.setPoint( 1, 0, 0 );
777 y = r.height()-2;
778 x = y/3;
779 a.setPoint( 2, x++, y-1 );
780 a.setPoint( 3, x++, y );
781 a.setPoint( 3, x++, y++ );
782 a.setPoint( 4, x, y );
783
784 int i;
785 int right = r.width() - 1;
786 for ( i = 0; i < 5; i++ )
787 a.setPoint( 9-i, right - a.point( i ).x(), a.point( i ).y() );
788
789 if ( tb->shape() == QTabBar::TriangularAbove )
790 for ( i = 0; i < 10; i++ )
791 a.setPoint( i, a.point(i).x(),
792 r.height() - 1 - a.point( i ).y() );
793
794 a.translate( r.left(), r.top() );
795
796 if ( flags & Style_Selected )
797 p->setBrush( cg.base() );
798 else
799 p->setBrush( cg.background() );
800 p->setPen( cg.foreground() );
801 p->drawPolygon( a );
802 p->setBrush( NoBrush );
803 }
804 break;
805 }
806
807 case CE_TabBarLabel:
808 {
809 if ( opt.isDefault() )
810 break;
811
812 const QTabBar * tb = (const QTabBar *) widget;
813 QTab * t = opt.tab();
814
815 QRect tr = r;
816 if ( t->identifier() == tb->currentTab() )
817 tr.setBottom( tr.bottom() -
818 pixelMetric( QStyle::PM_DefaultFrameWidth, tb ) );
819
820 int alignment = AlignCenter | ShowPrefix;
821 if (!styleHint(SH_UnderlineAccelerator, widget, QStyleOption::Default, 0))
822 alignment |= NoAccel;
823 drawItem( p, tr, alignment, cg,
824 flags & Style_Enabled, 0, t->text() );
825
826 if ( (flags & Style_HasFocus) && !t->text().isEmpty() )
827 drawPrimitive( PE_FocusRect, p, r, cg );
828 break;
829 }
830#endif // QT_NO_TABBAR
831#ifndef QT_NO_TOOLBOX
832 case CE_ToolBoxTab:
833 {
834 int d = 20 + r.height() - 3;
835 QPointArray a( 7 );
836 a.setPoint( 0, -1, r.height() + 1 );
837 a.setPoint( 1, -1, 1 );
838 a.setPoint( 2, r.width() - d, 1 );
839 a.setPoint( 3, r.width() - 20, r.height() - 2 );
840 a.setPoint( 4, r.width() - 1, r.height() - 2 );
841 a.setPoint( 5, r.width() - 1, r.height() + 1 );
842 a.setPoint( 6, -1, r.height() + 1 );
843
844 const QToolBox *tb = (const QToolBox*)widget;
845
846 if ( flags & Style_Selected && tb->currentItem() )
847 p->setBrush( tb->currentItem()->paletteBackgroundColor() );
848 else
849 p->setBrush( cg.background() );
850
851 p->setPen( cg.mid().dark( 150 ) );
852 p->drawPolygon( a );
853 p->setPen( cg.light() );
854 p->drawLine( 0, 2, r.width() - d, 2 );
855 p->drawLine( r.width() - d - 1, 2, r.width() - 21, r.height() - 1 );
856 p->drawLine( r.width() - 20, r.height() - 1, r.width(), r.height() - 1 );
857 p->setBrush( NoBrush );
858 break;
859 }
860#endif // QT_NO_TOOLBOX
861 case CE_ProgressBarGroove:
862 qDrawShadePanel(p, r, cg, TRUE, 1, &cg.brush(QColorGroup::Background));
863 break;
864
865#ifndef QT_NO_PROGRESSBAR
866 case CE_ProgressBarContents:
867 {
868 const QProgressBar *progressbar = (const QProgressBar *) widget;
869 // Correct the highlight color if same as background,
870 // or else we cannot see the progress...
871 QColorGroup cgh = cg;
872 if ( cgh.highlight() == cgh.background() )
873 cgh.setColor( QColorGroup::Highlight, progressbar->palette().active().highlight() );
874 bool reverse = QApplication::reverseLayout();
875 int fw = 2;
876 int w = r.width() - 2*fw;
877 if ( !progressbar->totalSteps() ) {
878 // draw busy indicator
879 int x = progressbar->progress() % (w * 2);
880 if (x > w)
881 x = 2 * w - x;
882 x = reverse ? r.right() - x : x + r.x();
883 p->setPen( QPen(cgh.highlight(), 4) );
884 p->drawLine(x, r.y() + 1, x, r.height() - fw);
885 } else {
886 const int unit_width = pixelMetric(PM_ProgressBarChunkWidth, widget);
887 int u;
888 if ( unit_width > 1 )
889 u = (r.width()+unit_width/3) / unit_width;
890 else
891 u = w / unit_width;
892 int p_v = progressbar->progress();
893 int t_s = progressbar->totalSteps() ? progressbar->totalSteps() : 1;
894
895 if ( u > 0 && p_v >= INT_MAX / u && t_s >= u ) {
896 // scale down to something usable.
897 p_v /= u;
898 t_s /= u;
899 }
900
901 // nu < tnu, if last chunk is only a partial chunk
902 int tnu, nu;
903 tnu = nu = p_v * u / t_s;
904
905 if (nu * unit_width > w)
906 nu--;
907
908 // Draw nu units out of a possible u of unit_width
909 // width, each a rectangle bordered by background
910 // color, all in a sunken panel with a percentage text
911 // display at the end.
912 int x = 0;
913 int x0 = reverse ? r.right() - ((unit_width > 1) ?
914 unit_width : fw) : r.x() + fw;
915 for (int i=0; i<nu; i++) {
916 drawPrimitive( PE_ProgressBarChunk, p,
917 QRect( x0+x, r.y(), unit_width, r.height() ),
918 cgh, Style_Default, opt );
919 x += reverse ? -unit_width: unit_width;
920 }
921
922 // Draw the last partial chunk to fill up the
923 // progressbar entirely
924 if (nu < tnu) {
925 int pixels_left = w - (nu*unit_width);
926 int offset = reverse ? x0+x+unit_width-pixels_left : x0+x;
927 drawPrimitive( PE_ProgressBarChunk, p,
928 QRect( offset, r.y(), pixels_left,
929 r.height() ), cgh, Style_Default,
930 opt );
931 }
932 }
933 }
934 break;
935
936 case CE_ProgressBarLabel:
937 {
938 const QProgressBar *progressbar = (const QProgressBar *) widget;
939 QColor penColor = cg.highlightedText();
940 QColor *pcolor = 0;
941 if ( progressbar->centerIndicator() && !progressbar->indicatorFollowsStyle() &&
942 progressbar->progress()*2 >= progressbar->totalSteps() )
943 pcolor = &penColor;
944 drawItem(p, r, AlignCenter | SingleLine, cg, flags & Style_Enabled, 0,
945 progressbar->progressString(), -1, pcolor );
946 }
947 break;
948#endif // QT_NO_PROGRESSBAR
949
950 case CE_MenuBarItem:
951 {
952#ifndef QT_NO_MENUDATA
953 if (opt.isDefault())
954 break;
955
956 QMenuItem *mi = opt.menuItem();
957 int alignment = AlignCenter|ShowPrefix|DontClip|SingleLine;
958 if (!styleHint(SH_UnderlineAccelerator, widget, QStyleOption::Default, 0))
959 alignment |= NoAccel;
960 drawItem( p, r, alignment, cg,
961 flags & Style_Enabled, mi->pixmap(), mi->text(), -1,
962 &cg.buttonText() );
963#endif
964 break;
965 }
966
967#ifndef QT_NO_TOOLBUTTON
968 case CE_ToolButtonLabel:
969 {
970 const QToolButton *toolbutton = (const QToolButton *) widget;
971 QRect rect = r;
972 Qt::ArrowType arrowType = opt.isDefault()
973 ? Qt::DownArrow : opt.arrowType();
974
975 if (flags & (Style_Down | Style_On))
976 rect.moveBy(pixelMetric(PM_ButtonShiftHorizontal, widget),
977 pixelMetric(PM_ButtonShiftVertical, widget));
978
979 if (!opt.isDefault()) {
980 PrimitiveElement pe;
981 switch (arrowType) {
982 case Qt::LeftArrow: pe = PE_ArrowLeft; break;
983 case Qt::RightArrow: pe = PE_ArrowRight; break;
984 case Qt::UpArrow: pe = PE_ArrowUp; break;
985 default:
986 case Qt::DownArrow: pe = PE_ArrowDown; break;
987 }
988
989 drawPrimitive(pe, p, rect, cg, flags, opt);
990 } else {
991 QColor btext = toolbutton->paletteForegroundColor();
992
993 if (toolbutton->iconSet().isNull() &&
994 ! toolbutton->text().isNull() &&
995 ! toolbutton->usesTextLabel()) {
996 int alignment = AlignCenter | ShowPrefix;
997 if (!styleHint(SH_UnderlineAccelerator, widget, QStyleOption::Default, 0))
998 alignment |= NoAccel;
999 drawItem(p, rect, alignment, cg,
1000 flags & Style_Enabled, 0, toolbutton->text(),
1001 toolbutton->text().length(), &btext);
1002 } else {
1003 QPixmap pm;
1004 QIconSet::Size size =
1005 toolbutton->usesBigPixmap() ? QIconSet::Large : QIconSet::Small;
1006 QIconSet::State state =
1007 toolbutton->isOn() ? QIconSet::On : QIconSet::Off;
1008 QIconSet::Mode mode;
1009 if (! toolbutton->isEnabled())
1010 mode = QIconSet::Disabled;
1011 else if (flags & (Style_Down | Style_On | Style_Raised))
1012 mode = QIconSet::Active;
1013 else
1014 mode = QIconSet::Normal;
1015 pm = toolbutton->iconSet().pixmap( size, mode, state );
1016
1017 if ( toolbutton->usesTextLabel() ) {
1018 if ( toolbutton->textPosition() == QToolButton::Under ) {
1019 p->setFont( toolbutton->font() );
1020
1021 QRect pr = rect, tr = rect;
1022 int fh = p->fontMetrics().height();
1023 pr.addCoords( 0, 1, 0, -fh-3 );
1024 tr.addCoords( 0, pr.bottom(), 0, -3 );
1025 drawItem( p, pr, AlignCenter, cg, TRUE, &pm, QString::null );
1026 int alignment = AlignCenter | ShowPrefix;
1027 if (!styleHint(SH_UnderlineAccelerator, widget, QStyleOption::Default, 0))
1028 alignment |= NoAccel;
1029
1030 drawItem( p, tr, alignment, cg,
1031 flags & Style_Enabled, 0, toolbutton->textLabel(),
1032 toolbutton->textLabel().length(), &btext);
1033 } else {
1034 p->setFont( toolbutton->font() );
1035
1036 QRect pr = rect, tr = rect;
1037 pr.setWidth( pm.width() + 8 );
1038 tr.addCoords( pr.right(), 0, 0, 0 );
1039 drawItem( p, pr, AlignCenter, cg, TRUE, &pm, QString::null );
1040 int alignment = AlignLeft | AlignVCenter | ShowPrefix;
1041 if (!styleHint(SH_UnderlineAccelerator, widget, QStyleOption::Default, 0))
1042 alignment |= NoAccel;
1043 drawItem( p, tr, alignment, cg,
1044 flags & Style_Enabled, 0, toolbutton->textLabel(),
1045 toolbutton->textLabel().length(), &btext);
1046 }
1047 } else
1048 drawItem( p, rect, AlignCenter, cg, TRUE, &pm, QString::null );
1049 }
1050 }
1051
1052 break;
1053 }
1054#endif // QT_NO_TOOLBUTTON
1055#ifndef QT_NO_HEADER
1056 case CE_HeaderLabel:
1057 {
1058 QRect rect = r;
1059 const QHeader* header = (const QHeader *) widget;
1060 int section = opt.headerSection();
1061
1062 QIconSet* icon = header->iconSet( section );
1063 if ( icon ) {
1064 QPixmap pixmap = icon->pixmap( QIconSet::Small,
1065 flags & Style_Enabled ?
1066 QIconSet::Normal : QIconSet::Disabled );
1067 int pixw = pixmap.width();
1068 int pixh = pixmap.height();
1069 // "pixh - 1" because of tricky integer division
1070
1071 QRect pixRect = rect;
1072 pixRect.setY( rect.center().y() - (pixh - 1) / 2 );
1073 drawItem ( p, pixRect, AlignVCenter, cg, flags & Style_Enabled,
1074 &pixmap, QString::null );
1075 rect.setLeft( rect.left() + pixw + 2 );
1076 }
1077
1078 drawItem ( p, rect, AlignVCenter, cg, flags & Style_Enabled,
1079 0, header->label( section ), -1, &(cg.buttonText()) );
1080 }
1081#endif // QT_NO_HEADER
1082 default:
1083 break;
1084 }
1085
1086 activePainter = 0;
1087}
1088
1089/*! \reimp */
1090void QCommonStyle::drawControlMask( ControlElement control,
1091 QPainter *p,
1092 const QWidget *widget,
1093 const QRect &r,
1094 const QStyleOption& opt ) const
1095{
1096 Q_UNUSED(widget);
1097
1098 activePainter = p;
1099
1100 QColorGroup cg(color1,color1,color1,color1,color1,color1,color1,color1,color0);
1101
1102 switch (control) {
1103 case CE_PushButton:
1104 drawPrimitive(PE_ButtonCommand, p, r, cg, Style_Default, opt);
1105 break;
1106
1107 case CE_CheckBox:
1108 drawPrimitive(PE_IndicatorMask, p, r, cg, Style_Default, opt);
1109 break;
1110
1111 case CE_RadioButton:
1112 drawPrimitive(PE_ExclusiveIndicatorMask, p, r, cg, Style_Default, opt);
1113 break;
1114
1115 default:
1116 p->fillRect(r, color1);
1117 break;
1118 }
1119
1120 activePainter = 0;
1121}
1122
1123/*! \reimp */
1124QRect QCommonStyle::subRect(SubRect r, const QWidget *widget) const
1125{
1126#if defined(QT_CHECK_STATE)
1127 if (! widget) {
1128 qWarning("QCommonStyle::subRect: widget parameter cannot be zero!");
1129 return QRect();
1130 }
1131#endif
1132
1133 QRect rect, wrect(widget->rect());
1134
1135 switch (r) {
1136#ifndef QT_NO_DIALOGBUTTONS
1137 case SR_DialogButtonAbort:
1138 case SR_DialogButtonRetry:
1139 case SR_DialogButtonIgnore:
1140 case SR_DialogButtonAccept:
1141 case SR_DialogButtonReject:
1142 case SR_DialogButtonApply:
1143 case SR_DialogButtonHelp:
1144 case SR_DialogButtonAll:
1145 case SR_DialogButtonCustom: {
1146 QDialogButtons::Button srch = QDialogButtons::None;
1147 if(r == SR_DialogButtonAccept)
1148 srch = QDialogButtons::Accept;
1149 else if(r == SR_DialogButtonReject)
1150 srch = QDialogButtons::Reject;
1151 else if(r == SR_DialogButtonAll)
1152 srch = QDialogButtons::All;
1153 else if(r == SR_DialogButtonApply)
1154 srch = QDialogButtons::Apply;
1155 else if(r == SR_DialogButtonHelp)
1156 srch = QDialogButtons::Help;
1157 else if(r == SR_DialogButtonRetry)
1158 srch = QDialogButtons::Retry;
1159 else if(r == SR_DialogButtonIgnore)
1160 srch = QDialogButtons::Ignore;
1161 else if(r == SR_DialogButtonAbort)
1162 srch = QDialogButtons::Abort;
1163
1164 const int bwidth = pixelMetric(PM_DialogButtonsButtonWidth, widget),
1165 bheight = pixelMetric(PM_DialogButtonsButtonHeight, widget),
1166 bspace = pixelMetric(PM_DialogButtonsSeparator, widget),
1167 fw = pixelMetric(PM_DefaultFrameWidth, widget);
1168 const QDialogButtons *dbtns = (const QDialogButtons *) widget;
1169 int start = fw;
1170 if(dbtns->orientation() == Horizontal)
1171 start = wrect.right() - fw;
1172 QDialogButtons::Button btns[] = { QDialogButtons::All, QDialogButtons::Reject, QDialogButtons::Accept, //reverse order (right to left)
1173 QDialogButtons::Apply, QDialogButtons::Retry, QDialogButtons::Ignore, QDialogButtons::Abort,
1174 QDialogButtons::Help };
1175 for(unsigned int i = 0, cnt = 0; i < (sizeof(btns)/sizeof(btns[0])); i++) {
1176 if(dbtns->isButtonVisible(btns[i])) {
1177 QSize szH = dbtns->sizeHint(btns[i]);
1178 int mwidth = QMAX(bwidth, szH.width()), mheight = QMAX(bheight, szH.height());
1179 if(dbtns->orientation() == Horizontal) {
1180 start -= mwidth;
1181 if(cnt)
1182 start -= bspace;
1183 } else if(cnt) {
1184 start += mheight;
1185 start += bspace;
1186 }
1187 cnt++;
1188 if(btns[i] == srch) {
1189 if(dbtns->orientation() == Horizontal)
1190 return QRect(start, wrect.bottom() - fw - mheight, mwidth, mheight);
1191 else
1192 return QRect(fw, start, mwidth, mheight);
1193 }
1194 }
1195 }
1196 if(r == SR_DialogButtonCustom) {
1197 if(dbtns->orientation() == Horizontal)
1198 return QRect(fw, fw, start - fw - bspace, wrect.height() - (fw*2));
1199 else
1200 return QRect(fw, start, wrect.width() - (fw*2), wrect.height() - start - (fw*2));
1201 }
1202 return QRect(); }
1203#endif //QT_NO_DIALOGBUTTONS
1204 case SR_PushButtonContents:
1205 {
1206#ifndef QT_NO_PUSHBUTTON
1207 const QPushButton *button = (const QPushButton *) widget;
1208 int dx1, dx2;
1209
1210 dx1 = pixelMetric(PM_DefaultFrameWidth, widget);
1211 if (button->isDefault() || button->autoDefault())
1212 dx1 += pixelMetric(PM_ButtonDefaultIndicator, widget);
1213 dx2 = dx1 * 2;
1214
1215 rect.setRect(wrect.x() + dx1,
1216 wrect.y() + dx1,
1217 wrect.width() - dx2,
1218 wrect.height() - dx2);
1219#endif
1220 break;
1221 }
1222
1223 case SR_PushButtonFocusRect:
1224 {
1225#ifndef QT_NO_PUSHBUTTON
1226 const QPushButton *button = (const QPushButton *) widget;
1227 int dbw1 = 0, dbw2 = 0;
1228 if (button->isDefault() || button->autoDefault()) {
1229 dbw1 = pixelMetric(PM_ButtonDefaultIndicator, widget);
1230 dbw2 = dbw1 * 2;
1231 }
1232
1233 int dfw1 = pixelMetric(PM_DefaultFrameWidth, widget) * 2,
1234 dfw2 = dfw1 * 2;
1235
1236 rect.setRect(wrect.x() + dfw1 + dbw1,
1237 wrect.y() + dfw1 + dbw1,
1238 wrect.width() - dfw2 - dbw2,
1239 wrect.height() - dfw2 - dbw2);
1240#endif
1241 break;
1242 }
1243
1244 case SR_CheckBoxIndicator:
1245 {
1246 int h = pixelMetric( PM_IndicatorHeight, widget );
1247 rect.setRect(0, ( wrect.height() - h ) / 2,
1248 pixelMetric( PM_IndicatorWidth, widget ), h );
1249 break;
1250 }
1251
1252 case SR_CheckBoxContents:
1253 {
1254#ifndef QT_NO_CHECKBOX
1255 QRect ir = subRect(SR_CheckBoxIndicator, widget);
1256 rect.setRect(ir.right() + 6, wrect.y(),
1257 wrect.width() - ir.width() - 6, wrect.height());
1258#endif
1259 break;
1260 }
1261
1262 case SR_CheckBoxFocusRect:
1263 {
1264#ifndef QT_NO_CHECKBOX
1265 const QCheckBox *checkbox = (const QCheckBox *) widget;
1266 if ( !checkbox->pixmap() && checkbox->text().isEmpty() ) {
1267 rect = subRect( SR_CheckBoxIndicator, widget );
1268 rect.addCoords( 1, 1, -1, -1 );
1269 break;
1270 }
1271 QRect cr = subRect(SR_CheckBoxContents, widget);
1272
1273 // don't create a painter if we have an active one
1274 QPainter *p = 0;
1275 if (! activePainter)
1276 p = new QPainter(checkbox);
1277 rect = itemRect((activePainter ? activePainter : p),
1278 cr, AlignLeft | AlignVCenter | ShowPrefix,
1279 checkbox->isEnabled(),
1280 checkbox->pixmap(),
1281 checkbox->text());
1282
1283 delete p;
1284
1285 rect.addCoords( -3, -2, 3, 2 );
1286 rect = rect.intersect(wrect);
1287#endif
1288 break;
1289 }
1290
1291 case SR_RadioButtonIndicator:
1292 {
1293 int h = pixelMetric( PM_ExclusiveIndicatorHeight, widget );
1294 rect.setRect(0, ( wrect.height() - h ) / 2,
1295 pixelMetric( PM_ExclusiveIndicatorWidth, widget ), h );
1296 break;
1297 }
1298
1299 case SR_RadioButtonContents:
1300 {
1301 QRect ir = subRect(SR_RadioButtonIndicator, widget);
1302 rect.setRect(ir.right() + 6, wrect.y(),
1303 wrect.width() - ir.width() - 6, wrect.height());
1304 break;
1305 }
1306
1307 case SR_RadioButtonFocusRect:
1308 {
1309#ifndef QT_NO_RADIOBUTTON
1310 const QRadioButton *radiobutton = (const QRadioButton *) widget;
1311 if ( !radiobutton->pixmap() && radiobutton->text().isEmpty() ) {
1312 rect = subRect( SR_RadioButtonIndicator, widget );
1313 rect.addCoords( 1, 1, -1, -1 );
1314 break;
1315 }
1316 QRect cr = subRect(SR_RadioButtonContents, widget);
1317
1318 // don't create a painter if we have an active one
1319 QPainter *p = 0;
1320 if (! activePainter)
1321 p = new QPainter(radiobutton);
1322 rect = itemRect((activePainter ? activePainter : p),
1323 cr, AlignLeft | AlignVCenter | ShowPrefix,
1324 radiobutton->isEnabled(),
1325 radiobutton->pixmap(),
1326 radiobutton->text());
1327 delete p;
1328
1329 rect.addCoords( -3, -2, 3, 2 );
1330 rect = rect.intersect(wrect);
1331#endif
1332 break;
1333 }
1334
1335 case SR_ComboBoxFocusRect:
1336 rect.setRect(3, 3, widget->width()-6-16, widget->height()-6);
1337 break;
1338
1339#ifndef QT_NO_SLIDER
1340 case SR_SliderFocusRect:
1341 {
1342 const QSlider * sl = (const QSlider *) widget;
1343 int tickOffset = pixelMetric( PM_SliderTickmarkOffset, sl );
1344 int thickness = pixelMetric( PM_SliderControlThickness, sl );
1345
1346 if ( sl->orientation() == Horizontal )
1347 rect.setRect( 0, tickOffset-1, sl->width(), thickness+2 );
1348 else
1349 rect.setRect( tickOffset-1, 0, thickness+2, sl->height() );
1350 rect = rect.intersect( sl->rect() ); // ## is this really necessary?
1351 break;
1352 }
1353#endif // QT_NO_SLIDER
1354
1355#ifndef QT_NO_MAINWINDOW
1356 case SR_DockWindowHandleRect:
1357 {
1358 if (! widget->parentWidget())
1359 break;
1360
1361 const QDockWindow * dw = (const QDockWindow *) widget->parentWidget();
1362
1363 if ( !dw->area() || !dw->isCloseEnabled() )
1364 rect.setRect( 0, 0, widget->width(), widget->height() );
1365 else {
1366 if ( dw->area()->orientation() == Horizontal )
1367 rect.setRect(0, 15, widget->width(), widget->height() - 15);
1368 else
1369 rect.setRect(0, 1, widget->width() - 15, widget->height() - 1);
1370 }
1371 break;
1372 }
1373#endif // QT_NO_MAINWINDOW
1374
1375 case SR_ProgressBarGroove:
1376 case SR_ProgressBarContents:
1377 {
1378#ifndef QT_NO_PROGRESSBAR
1379 QFontMetrics fm( ( widget ? widget->fontMetrics() :
1380 QApplication::fontMetrics() ) );
1381 const QProgressBar *progressbar = (const QProgressBar *) widget;
1382 int textw = 0;
1383 if (progressbar->percentageVisible())
1384 textw = fm.width("100%") + 6;
1385
1386 if (progressbar->indicatorFollowsStyle() ||
1387 ! progressbar->centerIndicator())
1388 rect.setCoords(wrect.left(), wrect.top(),
1389 wrect.right() - textw, wrect.bottom());
1390 else
1391 rect = wrect;
1392#endif
1393 break;
1394 }
1395
1396 case SR_ProgressBarLabel:
1397 {
1398#ifndef QT_NO_PROGRESSBAR
1399 QFontMetrics fm( ( widget ? widget->fontMetrics() :
1400 QApplication::fontMetrics() ) );
1401 const QProgressBar *progressbar = (const QProgressBar *) widget;
1402 int textw = 0;
1403 if (progressbar->percentageVisible())
1404 textw = fm.width("100%") + 6;
1405
1406 if (progressbar->indicatorFollowsStyle() ||
1407 ! progressbar->centerIndicator())
1408 rect.setCoords(wrect.right() - textw, wrect.top(),
1409 wrect.right(), wrect.bottom());
1410 else
1411 rect = wrect;
1412#endif
1413 break;
1414 }
1415
1416 case SR_ToolButtonContents:
1417 rect = querySubControlMetrics(CC_ToolButton, widget, SC_ToolButton);
1418 break;
1419
1420 case SR_ToolBoxTabContents:
1421 rect = wrect;
1422 rect.addCoords( 0, 0, -30, 0 );
1423 break;
1424
1425 default:
1426 rect = wrect;
1427 break;
1428 }
1429
1430 return rect;
1431}
1432
1433#ifndef QT_NO_RANGECONTROL
1434/*
1435 I really need this and I don't want to expose it in QRangeControl..
1436*/
1437static int qPositionFromValue( const QRangeControl * rc, int logical_val,
1438 int span )
1439{
1440 if ( span <= 0 || logical_val < rc->minValue() ||
1441 rc->maxValue() <= rc->minValue() )
1442 return 0;
1443 if ( logical_val > rc->maxValue() )
1444 return span;
1445
1446 uint range = rc->maxValue() - rc->minValue();
1447 uint p = logical_val - rc->minValue();
1448
1449 if ( range > (uint)INT_MAX/4096 ) {
1450 const int scale = 4096*2;
1451 return ( (p/scale) * span ) / (range/scale);
1452 // ### the above line is probably not 100% correct
1453 // ### but fixing it isn't worth the extreme pain...
1454 } else if ( range > (uint)span ) {
1455 return (2*p*span + range) / (2*range);
1456 } else {
1457 uint div = span / range;
1458 uint mod = span % range;
1459 return p*div + (2*p*mod + range) / (2*range);
1460 }
1461 //equiv. to (p*span)/range + 0.5
1462 // no overflow because of this implicit assumption:
1463 // span <= 4096
1464}
1465#endif // QT_NO_RANGECONTROL
1466
1467/*! \reimp */
1468void QCommonStyle::drawComplexControl( ComplexControl control,
1469 QPainter *p,
1470 const QWidget *widget,
1471 const QRect &r,
1472 const QColorGroup &cg,
1473 SFlags flags,
1474 SCFlags controls,
1475 SCFlags active,
1476 const QStyleOption& opt ) const
1477{
1478#if defined(QT_CHECK_STATE)
1479 if (! widget) {
1480 qWarning("QCommonStyle::drawComplexControl: widget parameter cannot be zero!");
1481 return;
1482 }
1483#endif
1484
1485 activePainter = p;
1486
1487 switch (control) {
1488#ifndef QT_NO_SCROLLBAR
1489 case CC_ScrollBar:
1490 {
1491 const QScrollBar *scrollbar = (const QScrollBar *) widget;
1492 QRect addline, subline, addpage, subpage, slider, first, last;
1493 bool maxedOut = (scrollbar->minValue() == scrollbar->maxValue());
1494
1495 subline = querySubControlMetrics(control, widget, SC_ScrollBarSubLine, opt);
1496 addline = querySubControlMetrics(control, widget, SC_ScrollBarAddLine, opt);
1497 subpage = querySubControlMetrics(control, widget, SC_ScrollBarSubPage, opt);
1498 addpage = querySubControlMetrics(control, widget, SC_ScrollBarAddPage, opt);
1499 slider = querySubControlMetrics(control, widget, SC_ScrollBarSlider, opt);
1500 first = querySubControlMetrics(control, widget, SC_ScrollBarFirst, opt);
1501 last = querySubControlMetrics(control, widget, SC_ScrollBarLast, opt);
1502
1503 if ((controls & SC_ScrollBarSubLine) && subline.isValid())
1504 drawPrimitive(PE_ScrollBarSubLine, p, subline, cg,
1505 ((maxedOut) ? Style_Default : Style_Enabled) |
1506 ((active == SC_ScrollBarSubLine) ?
1507 Style_Down : Style_Default) |
1508 ((scrollbar->orientation() == Qt::Horizontal) ?
1509 Style_Horizontal : 0));
1510 if ((controls & SC_ScrollBarAddLine) && addline.isValid())
1511 drawPrimitive(PE_ScrollBarAddLine, p, addline, cg,
1512 ((maxedOut) ? Style_Default : Style_Enabled) |
1513 ((active == SC_ScrollBarAddLine) ?
1514 Style_Down : Style_Default) |
1515 ((scrollbar->orientation() == Qt::Horizontal) ?
1516 Style_Horizontal : 0));
1517 if ((controls & SC_ScrollBarSubPage) && subpage.isValid())
1518 drawPrimitive(PE_ScrollBarSubPage, p, subpage, cg,
1519 ((maxedOut) ? Style_Default : Style_Enabled) |
1520 ((active == SC_ScrollBarSubPage) ?
1521 Style_Down : Style_Default) |
1522 ((scrollbar->orientation() == Qt::Horizontal) ?
1523 Style_Horizontal : 0));
1524 if ((controls & SC_ScrollBarAddPage) && addpage.isValid())
1525 drawPrimitive(PE_ScrollBarAddPage, p, addpage, cg,
1526 ((maxedOut) ? Style_Default : Style_Enabled) |
1527 ((active == SC_ScrollBarAddPage) ?
1528 Style_Down : Style_Default) |
1529 ((scrollbar->orientation() == Qt::Horizontal) ?
1530 Style_Horizontal : 0));
1531 if ((controls & SC_ScrollBarFirst) && first.isValid())
1532 drawPrimitive(PE_ScrollBarFirst, p, first, cg,
1533 ((maxedOut) ? Style_Default : Style_Enabled) |
1534 ((active == SC_ScrollBarFirst) ?
1535 Style_Down : Style_Default) |
1536 ((scrollbar->orientation() == Qt::Horizontal) ?
1537 Style_Horizontal : 0));
1538 if ((controls & SC_ScrollBarLast) && last.isValid())
1539 drawPrimitive(PE_ScrollBarLast, p, last, cg,
1540 ((maxedOut) ? Style_Default : Style_Enabled) |
1541 ((active == SC_ScrollBarLast) ?
1542 Style_Down : Style_Default) |
1543 ((scrollbar->orientation() == Qt::Horizontal) ?
1544 Style_Horizontal : 0));
1545 if ((controls & SC_ScrollBarSlider) && slider.isValid()) {
1546 drawPrimitive(PE_ScrollBarSlider, p, slider, cg,
1547 ((maxedOut) ? Style_Default : Style_Enabled) |
1548 ((active == SC_ScrollBarSlider) ?
1549 Style_Down : Style_Default) |
1550 ((scrollbar->orientation() == Qt::Horizontal) ?
1551 Style_Horizontal : 0));
1552
1553 // ### perhaps this should not be able to accept focus if maxedOut?
1554 if (scrollbar->hasFocus()) {
1555 QRect fr(slider.x() + 2, slider.y() + 2,
1556 slider.width() - 5, slider.height() - 5);
1557 drawPrimitive(PE_FocusRect, p, fr, cg, Style_Default);
1558 }
1559 }
1560
1561 break;
1562 }
1563#endif // QT_NO_SCROLLBAR
1564
1565#ifndef QT_NO_TOOLBUTTON
1566 case CC_ToolButton:
1567 {
1568 const QToolButton *toolbutton = (const QToolButton *) widget;
1569
1570 QColorGroup c = cg;
1571 if ( toolbutton->backgroundMode() != PaletteButton )
1572 c.setBrush( QColorGroup::Button,
1573 toolbutton->paletteBackgroundColor() );
1574 QRect button, menuarea;
1575 button = visualRect( querySubControlMetrics(control, widget, SC_ToolButton, opt), widget );
1576 menuarea = visualRect( querySubControlMetrics(control, widget, SC_ToolButtonMenu, opt), widget );
1577
1578 SFlags bflags = flags,
1579 mflags = flags;
1580
1581 if (active & SC_ToolButton)
1582 bflags |= Style_Down;
1583 if (active & SC_ToolButtonMenu)
1584 mflags |= Style_Down;
1585
1586 if (controls & SC_ToolButton) {
1587 if (bflags & (Style_Down | Style_On | Style_Raised)) {
1588 drawPrimitive(PE_ButtonTool, p, button, c, bflags, opt);
1589 } else if ( toolbutton->parentWidget() &&
1590 toolbutton->parentWidget()->backgroundPixmap() &&
1591 ! toolbutton->parentWidget()->backgroundPixmap()->isNull() ) {
1592 QPixmap pixmap =
1593 *(toolbutton->parentWidget()->backgroundPixmap());
1594
1595 p->drawTiledPixmap( r, pixmap, toolbutton->pos() );
1596 }
1597 }
1598
1599 if (controls & SC_ToolButtonMenu) {
1600 if (mflags & (Style_Down | Style_On | Style_Raised))
1601 drawPrimitive(PE_ButtonDropDown, p, menuarea, c, mflags, opt);
1602 drawPrimitive(PE_ArrowDown, p, menuarea, c, mflags, opt);
1603 }
1604
1605 if (toolbutton->hasFocus() && !toolbutton->focusProxy()) {
1606 QRect fr = toolbutton->rect();
1607 fr.addCoords(3, 3, -3, -3);
1608 drawPrimitive(PE_FocusRect, p, fr, c);
1609 }
1610
1611 break;
1612 }
1613#endif // QT_NO_TOOLBUTTON
1614
1615#ifndef QT_NO_TITLEBAR
1616 case CC_TitleBar:
1617 {
1618 const QTitleBar *titlebar = (const QTitleBar *) widget;
1619 if ( controls & SC_TitleBarLabel ) {
1620 QColorGroup cgroup = titlebar->usesActiveColor() ?
1621 titlebar->palette().active() : titlebar->palette().inactive();
1622
1623 QColor left = cgroup.highlight();
1624 QColor right = cgroup.base();
1625
1626 if ( left != right ) {
1627 double rS = left.red();
1628 double gS = left.green();
1629 double bS = left.blue();
1630
1631 const double rD = double(right.red() - rS) / titlebar->width();
1632 const double gD = double(right.green() - gS) / titlebar->width();
1633 const double bD = double(right.blue() - bS) / titlebar->width();
1634
1635 const int w = titlebar->width();
1636 for ( int sx = 0; sx < w; sx++ ) {
1637 rS+=rD;
1638 gS+=gD;
1639 bS+=bD;
1640 p->setPen( QColor( (int)rS, (int)gS, (int)bS ) );
1641 p->drawLine( sx, 0, sx, titlebar->height() );
1642 }
1643 } else {
1644 p->fillRect( titlebar->rect(), left );
1645 }
1646
1647 QRect ir = visualRect( querySubControlMetrics( CC_TitleBar, widget, SC_TitleBarLabel ), widget );
1648
1649 p->setPen( cgroup.highlightedText() );
1650 p->drawText(ir.x()+2, ir.y(), ir.width()-2, ir.height(),
1651 AlignAuto | AlignVCenter | SingleLine, titlebar->visibleText() );
1652 }
1653
1654 QRect ir;
1655 bool down = FALSE;
1656 QPixmap pm;
1657
1658 if ( controls & SC_TitleBarCloseButton ) {
1659 ir = visualRect( querySubControlMetrics( CC_TitleBar, widget, SC_TitleBarCloseButton ), widget );
1660 down = active & SC_TitleBarCloseButton;
1661 if ( widget->testWFlags( WStyle_Tool )
1662#ifndef QT_NO_MAINWINDOW
1663 || ::qt_cast<QDockWindow*>(widget)
1664#endif
1665 )
1666 pm = stylePixmap(SP_DockWindowCloseButton, widget);
1667 else
1668 pm = stylePixmap(SP_TitleBarCloseButton, widget);
1669 drawPrimitive(PE_ButtonTool, p, ir, titlebar->colorGroup(),
1670 down ? Style_Down : Style_Raised);
1671
1672 p->save();
1673 if( down )
1674 p->translate( pixelMetric(PM_ButtonShiftHorizontal, widget),
1675 pixelMetric(PM_ButtonShiftVertical, widget) );
1676 drawItem( p, ir, AlignCenter, titlebar->colorGroup(), TRUE, &pm, QString::null );
1677 p->restore();
1678 }
1679
1680 if ( titlebar->window() ) {
1681 if ( controls & SC_TitleBarMaxButton ) {
1682 ir = visualRect( querySubControlMetrics( CC_TitleBar, widget, SC_TitleBarMaxButton ), widget );
1683
1684 down = active & SC_TitleBarMaxButton;
1685 pm = QPixmap(stylePixmap(SP_TitleBarMaxButton, widget));
1686 drawPrimitive(PE_ButtonTool, p, ir, titlebar->colorGroup(),
1687 down ? Style_Down : Style_Raised);
1688
1689 p->save();
1690 if( down )
1691 p->translate( pixelMetric(PM_ButtonShiftHorizontal, widget),
1692 pixelMetric(PM_ButtonShiftVertical, widget) );
1693 drawItem( p, ir, AlignCenter, titlebar->colorGroup(), TRUE, &pm, QString::null );
1694 p->restore();
1695 }
1696
1697 if ( controls & SC_TitleBarNormalButton || controls & SC_TitleBarMinButton ) {
1698 ir = visualRect( querySubControlMetrics( CC_TitleBar, widget, SC_TitleBarMinButton ), widget );
1699 QStyle::SubControl ctrl = (controls & SC_TitleBarNormalButton ?
1700 SC_TitleBarNormalButton :
1701 SC_TitleBarMinButton);
1702 QStyle::StylePixmap spixmap = (controls & SC_TitleBarNormalButton ?
1703 SP_TitleBarNormalButton :
1704 SP_TitleBarMinButton);
1705 down = active & ctrl;
1706 pm = QPixmap(stylePixmap(spixmap, widget));
1707 drawPrimitive(PE_ButtonTool, p, ir, titlebar->colorGroup(),
1708 down ? Style_Down : Style_Raised);
1709
1710 p->save();
1711 if( down )
1712 p->translate( pixelMetric(PM_ButtonShiftHorizontal, widget),
1713 pixelMetric(PM_ButtonShiftVertical, widget) );
1714 drawItem( p, ir, AlignCenter, titlebar->colorGroup(), TRUE, &pm, QString::null );
1715 p->restore();
1716 }
1717
1718 if ( controls & SC_TitleBarShadeButton ) {
1719 ir = visualRect( querySubControlMetrics( CC_TitleBar, widget, SC_TitleBarShadeButton ), widget );
1720
1721 down = active & SC_TitleBarShadeButton;
1722 pm = QPixmap(stylePixmap(SP_TitleBarShadeButton, widget));
1723 drawPrimitive(PE_ButtonTool, p, ir, titlebar->colorGroup(),
1724 down ? Style_Down : Style_Raised);
1725 p->save();
1726 if( down )
1727 p->translate( pixelMetric(PM_ButtonShiftHorizontal, widget),
1728 pixelMetric(PM_ButtonShiftVertical, widget) );
1729 drawItem( p, ir, AlignCenter, titlebar->colorGroup(), TRUE, &pm, QString::null );
1730 p->restore();
1731 }
1732
1733 if ( controls & SC_TitleBarUnshadeButton ) {
1734 ir = visualRect( querySubControlMetrics( CC_TitleBar, widget, SC_TitleBarUnshadeButton ), widget );
1735
1736 down = active & SC_TitleBarUnshadeButton;
1737 pm = QPixmap(stylePixmap(SP_TitleBarUnshadeButton, widget));
1738 drawPrimitive(PE_ButtonTool, p, ir, titlebar->colorGroup(),
1739 down ? Style_Down : Style_Raised);
1740 p->save();
1741 if( down )
1742 p->translate( pixelMetric(PM_ButtonShiftHorizontal, widget),
1743 pixelMetric(PM_ButtonShiftVertical, widget) );
1744 drawItem( p, ir, AlignCenter, titlebar->colorGroup(), TRUE, &pm, QString::null );
1745 p->restore();
1746 }
1747 }
1748#ifndef QT_NO_WIDGET_TOPEXTRA
1749 if ( controls & SC_TitleBarSysMenu ) {
1750 if ( titlebar->icon() ) {
1751 ir = visualRect( querySubControlMetrics( CC_TitleBar, widget, SC_TitleBarSysMenu ), widget );
1752 drawItem( p, ir, AlignCenter, titlebar->colorGroup(), TRUE, titlebar->icon(), QString::null );
1753 }
1754 }
1755#endif
1756 break;
1757 }
1758#endif //QT_NO_TITLEBAR
1759
1760 case CC_SpinWidget: {
1761#ifndef QT_NO_SPINWIDGET
1762 const QSpinWidget * sw = (const QSpinWidget *) widget;
1763 SFlags flags;
1764 PrimitiveElement pe;
1765
1766 if ( controls & SC_SpinWidgetFrame )
1767 qDrawWinPanel( p, r, cg, TRUE ); //cstyle == Sunken );
1768
1769 if ( controls & SC_SpinWidgetUp ) {
1770 flags = Style_Default | Style_Enabled;
1771 if (active == SC_SpinWidgetUp ) {
1772 flags |= Style_On;
1773 flags |= Style_Sunken;
1774 } else
1775 flags |= Style_Raised;
1776 if ( sw->buttonSymbols() == QSpinWidget::PlusMinus )
1777 pe = PE_SpinWidgetPlus;
1778 else
1779 pe = PE_SpinWidgetUp;
1780
1781 QRect re = sw->upRect();
1782 QColorGroup ucg = sw->isUpEnabled() ? cg : sw->palette().disabled();
1783 drawPrimitive(PE_ButtonBevel, p, re, ucg, flags);
1784 drawPrimitive(pe, p, re, ucg, flags);
1785 }
1786
1787 if ( controls & SC_SpinWidgetDown ) {
1788 flags = Style_Default | Style_Enabled;
1789 if (active == SC_SpinWidgetDown ) {
1790 flags |= Style_On;
1791 flags |= Style_Sunken;
1792 } else
1793 flags |= Style_Raised;
1794 if ( sw->buttonSymbols() == QSpinWidget::PlusMinus )
1795 pe = PE_SpinWidgetMinus;
1796 else
1797 pe = PE_SpinWidgetDown;
1798
1799 QRect re = sw->downRect();
1800 QColorGroup dcg = sw->isDownEnabled() ? cg : sw->palette().disabled();
1801 drawPrimitive(PE_ButtonBevel, p, re, dcg, flags);
1802 drawPrimitive(pe, p, re, dcg, flags);
1803 }
1804#endif
1805 break; }
1806
1807#ifndef QT_NO_SLIDER
1808 case CC_Slider:
1809 switch ( controls ) {
1810 case SC_SliderTickmarks: {
1811 const QSlider * sl = (const QSlider *) widget;
1812 int tickOffset = pixelMetric( PM_SliderTickmarkOffset, sl );
1813 int ticks = sl->tickmarks();
1814 int thickness = pixelMetric( PM_SliderControlThickness, sl );
1815 int len = pixelMetric( PM_SliderLength, sl );
1816 int available = pixelMetric( PM_SliderSpaceAvailable, sl );
1817 int interval = sl->tickInterval();
1818
1819 if ( interval <= 0 ) {
1820 interval = sl->lineStep();
1821 if ( qPositionFromValue( sl, interval, available ) -
1822 qPositionFromValue( sl, 0, available ) < 3 )
1823 interval = sl->pageStep();
1824 }
1825
1826 int fudge = len / 2;
1827 int pos;
1828
1829 if ( ticks & QSlider::Above ) {
1830 if (sl->orientation() == Horizontal)
1831 p->fillRect(0, 0, sl->width(), tickOffset,
1832 cg.brush(QColorGroup::Background));
1833 else
1834 p->fillRect(0, 0, tickOffset, sl->width(),
1835 cg.brush(QColorGroup::Background));
1836 p->setPen( cg.foreground() );
1837 int v = sl->minValue();
1838 if ( !interval )
1839 interval = 1;
1840 while ( v <= sl->maxValue() + 1 ) {
1841 pos = qPositionFromValue( sl, v, available ) + fudge;
1842 if ( sl->orientation() == Horizontal )
1843 p->drawLine( pos, 0, pos, tickOffset-2 );
1844 else
1845 p->drawLine( 0, pos, tickOffset-2, pos );
1846 v += interval;
1847 }
1848 }
1849
1850 if ( ticks & QSlider::Below ) {
1851 if (sl->orientation() == Horizontal)
1852 p->fillRect(0, tickOffset + thickness, sl->width(), tickOffset,
1853 cg.brush(QColorGroup::Background));
1854 else
1855 p->fillRect(tickOffset + thickness, 0, tickOffset, sl->height(),
1856 cg.brush(QColorGroup::Background));
1857 p->setPen( cg.foreground() );
1858 int v = sl->minValue();
1859 if ( !interval )
1860 interval = 1;
1861 while ( v <= sl->maxValue() + 1 ) {
1862 pos = qPositionFromValue( sl, v, available ) + fudge;
1863 if ( sl->orientation() == Horizontal )
1864 p->drawLine( pos, tickOffset+thickness+1, pos,
1865 tickOffset+thickness+1 + available-2 );
1866 else
1867 p->drawLine( tickOffset+thickness+1, pos,
1868 tickOffset+thickness+1 + available-2,
1869 pos );
1870 v += interval;
1871 }
1872
1873 }
1874
1875 break; }
1876 }
1877 break;
1878#endif // QT_NO_SLIDER
1879#ifndef QT_NO_LISTVIEW
1880 case CC_ListView:
1881 if ( controls & SC_ListView ) {
1882 QListView *listview = (QListView*)widget;
1883 p->fillRect( r, listview->viewport()->backgroundBrush() );
1884 }
1885 break;
1886#endif //QT_NO_LISTVIEW
1887 default:
1888 break;
1889 }
1890
1891 activePainter = 0;
1892}
1893
1894
1895/*! \reimp */
1896void QCommonStyle::drawComplexControlMask( ComplexControl control,
1897 QPainter *p,
1898 const QWidget *widget,
1899 const QRect &r,
1900 const QStyleOption& opt ) const
1901{
1902 Q_UNUSED(control);
1903 Q_UNUSED(widget);
1904 Q_UNUSED(opt);
1905
1906 p->fillRect(r, color1);
1907}
1908
1909
1910/*! \reimp */
1911QRect QCommonStyle::querySubControlMetrics( ComplexControl control,
1912 const QWidget *widget,
1913 SubControl sc,
1914 const QStyleOption &opt ) const
1915{
1916#if defined(QT_CHECK_STATE)
1917 if (! widget) {
1918 qWarning("QCommonStyle::querySubControlMetrics: widget parameter cannot be zero!");
1919 return QRect();
1920 }
1921#endif
1922
1923 switch ( control ) {
1924 case CC_SpinWidget: {
1925 int fw = pixelMetric( PM_SpinBoxFrameWidth, widget);
1926 QSize bs;
1927 bs.setHeight( widget->height()/2 - fw );
1928 if ( bs.height() < 8 )
1929 bs.setHeight( 8 );
1930 bs.setWidth( QMIN( bs.height() * 8 / 5, widget->width() / 4 ) ); // 1.6 -approximate golden mean
1931 bs = bs.expandedTo( QApplication::globalStrut() );
1932 int y = fw;
1933 int x, lx, rx;
1934 x = widget->width() - y - bs.width();
1935 lx = fw;
1936 rx = x - fw;
1937 switch ( sc ) {
1938 case SC_SpinWidgetUp:
1939 return QRect(x, y, bs.width(), bs.height());
1940 case SC_SpinWidgetDown:
1941 return QRect(x, y + bs.height(), bs.width(), bs.height());
1942 case SC_SpinWidgetButtonField:
1943 return QRect(x, y, bs.width(), widget->height() - 2*fw);
1944 case SC_SpinWidgetEditField:
1945 return QRect(lx, fw, rx, widget->height() - 2*fw);
1946 case SC_SpinWidgetFrame:
1947 return widget->rect();
1948 default:
1949 break;
1950 }
1951 break; }
1952
1953 case CC_ComboBox: {
1954 int x = 0, y = 0, wi = widget->width(), he = widget->height();
1955 int xpos = x;
1956 xpos += wi - 2 - 16;
1957
1958 switch ( sc ) {
1959 case SC_ComboBoxFrame:
1960 return widget->rect();
1961 case SC_ComboBoxArrow:
1962 return QRect(xpos, y+2, 16, he-4);
1963 case SC_ComboBoxEditField:
1964 return QRect(x+3, y+3, wi-6-16, he-6);
1965 case SC_ComboBoxListBoxPopup:
1966 return opt.rect();
1967 default:
1968 break;
1969 }
1970 break; }
1971
1972#ifndef QT_NO_SCROLLBAR
1973 case CC_ScrollBar: {
1974 const QScrollBar *scrollbar = (const QScrollBar *) widget;
1975 int sliderstart = 0;
1976 int sbextent = pixelMetric(PM_ScrollBarExtent, widget);
1977 int maxlen = ((scrollbar->orientation() == Qt::Horizontal) ?
1978 scrollbar->width() : scrollbar->height()) - (sbextent * 2);
1979 int sliderlen;
1980
1981 sliderstart = scrollbar->sliderStart();
1982
1983 // calculate slider length
1984 if (scrollbar->maxValue() != scrollbar->minValue()) {
1985 uint range = scrollbar->maxValue() - scrollbar->minValue();
1986 sliderlen = (scrollbar->pageStep() * maxlen) /
1987 (range + scrollbar->pageStep());
1988
1989 int slidermin = pixelMetric( PM_ScrollBarSliderMin, widget );
1990 if ( sliderlen < slidermin || range > INT_MAX / 2 )
1991 sliderlen = slidermin;
1992 if ( sliderlen > maxlen )
1993 sliderlen = maxlen;
1994 } else
1995 sliderlen = maxlen;
1996
1997 switch (sc) {
1998 case SC_ScrollBarSubLine: // top/left button
1999 if (scrollbar->orientation() == Qt::Horizontal) {
2000 int buttonWidth = QMIN(scrollbar->width()/2, sbextent);
2001 return QRect( 0, 0, buttonWidth, sbextent );
2002 } else {
2003 int buttonHeight = QMIN(scrollbar->height()/2, sbextent);
2004 return QRect( 0, 0, sbextent, buttonHeight );
2005 }
2006
2007 case SC_ScrollBarAddLine: // bottom/right button
2008 if (scrollbar->orientation() == Qt::Horizontal) {
2009 int buttonWidth = QMIN(scrollbar->width()/2, sbextent);
2010 return QRect( scrollbar->width() - buttonWidth, 0, buttonWidth, sbextent );
2011 } else {
2012 int buttonHeight = QMIN(scrollbar->height()/2, sbextent);
2013 return QRect( 0, scrollbar->height() - buttonHeight, sbextent, buttonHeight );
2014 }
2015
2016 case SC_ScrollBarSubPage: // between top/left button and slider
2017 if (scrollbar->orientation() == Qt::Horizontal)
2018 return QRect(sbextent, 0, sliderstart - sbextent, sbextent);
2019 return QRect(0, sbextent, sbextent, sliderstart - sbextent);
2020
2021 case SC_ScrollBarAddPage: // between bottom/right button and slider
2022 if (scrollbar->orientation() == Qt::Horizontal)
2023 return QRect(sliderstart + sliderlen, 0,
2024 maxlen - sliderstart - sliderlen + sbextent, sbextent);
2025 return QRect(0, sliderstart + sliderlen,
2026 sbextent, maxlen - sliderstart - sliderlen + sbextent);
2027
2028 case SC_ScrollBarGroove:
2029 if (scrollbar->orientation() == Qt::Horizontal)
2030 return QRect(sbextent, 0, scrollbar->width() - sbextent * 2,
2031 scrollbar->height());
2032 return QRect(0, sbextent, scrollbar->width(),
2033 scrollbar->height() - sbextent * 2);
2034
2035 case SC_ScrollBarSlider:
2036 if (scrollbar->orientation() == Qt::Horizontal)
2037 return QRect(sliderstart, 0, sliderlen, sbextent);
2038 return QRect(0, sliderstart, sbextent, sliderlen);
2039
2040 default: break;
2041 }
2042
2043 break; }
2044#endif // QT_NO_SCROLLBAR
2045
2046#ifndef QT_NO_SLIDER
2047 case CC_Slider: {
2048 const QSlider * sl = (const QSlider *) widget;
2049 int tickOffset = pixelMetric( PM_SliderTickmarkOffset, sl );
2050 int thickness = pixelMetric( PM_SliderControlThickness, sl );
2051
2052 switch ( sc ) {
2053 case SC_SliderHandle: {
2054 int sliderPos = 0;
2055 int len = pixelMetric( PM_SliderLength, sl );
2056
2057 sliderPos = sl->sliderStart();
2058
2059 if ( sl->orientation() == Horizontal )
2060 return QRect( sliderPos, tickOffset, len, thickness );
2061 return QRect( tickOffset, sliderPos, thickness, len ); }
2062 case SC_SliderGroove: {
2063 if ( sl->orientation() == Horizontal )
2064 return QRect( 0, tickOffset, sl->width(), thickness );
2065 return QRect( tickOffset, 0, thickness, sl->height() ); }
2066
2067 default:
2068 break;
2069 }
2070 break; }
2071#endif // QT_NO_SLIDER
2072
2073#if !defined(QT_NO_TOOLBUTTON) && !defined(QT_NO_POPUPMENU)
2074 case CC_ToolButton: {
2075 const QToolButton *toolbutton = (const QToolButton *) widget;
2076 int mbi = pixelMetric(PM_MenuButtonIndicator, widget);
2077
2078 QRect rect = toolbutton->rect();
2079 switch (sc) {
2080 case SC_ToolButton:
2081 if (toolbutton->popup() && ! toolbutton->popupDelay())
2082 rect.addCoords(0, 0, -mbi, 0);
2083 return rect;
2084
2085 case SC_ToolButtonMenu:
2086 if (toolbutton->popup() && ! toolbutton->popupDelay())
2087 rect.addCoords(rect.width() - mbi, 0, 0, 0);
2088 return rect;
2089
2090 default: break;
2091 }
2092 break;
2093 }
2094#endif // QT_NO_TOOLBUTTON && QT_NO_POPUPMENU
2095
2096#ifndef QT_NO_TITLEBAR
2097 case CC_TitleBar: {
2098 const QTitleBar *titlebar = (const QTitleBar *) widget;
2099 const int controlTop = 2;
2100 const int controlHeight = widget->height() - controlTop * 2;
2101
2102 switch (sc) {
2103 case SC_TitleBarLabel: {
2104 const QTitleBar *titlebar = (QTitleBar*)widget;
2105 QRect ir( 0, 0, titlebar->width(), titlebar->height() );
2106 if ( titlebar->testWFlags( WStyle_Tool ) ) {
2107 if ( titlebar->testWFlags( WStyle_SysMenu ) )
2108 ir.addCoords( 0, 0, -controlHeight-3, 0 );
2109 if ( titlebar->testWFlags( WStyle_MinMax ) )
2110 ir.addCoords( 0, 0, -controlHeight-2, 0 );
2111 } else {
2112 if ( titlebar->testWFlags( WStyle_SysMenu ) )
2113 ir.addCoords( controlHeight+3, 0, -controlHeight-3, 0 );
2114 if ( titlebar->testWFlags( WStyle_Minimize ) )
2115 ir.addCoords( 0, 0, -controlHeight-2, 0 );
2116 if ( titlebar->testWFlags( WStyle_Maximize ) )
2117 ir.addCoords( 0, 0, -controlHeight-2, 0 );
2118 }
2119 return ir; }
2120
2121 case SC_TitleBarCloseButton:
2122 return QRect( titlebar->width() - ( controlHeight + controlTop ),
2123 controlTop, controlHeight, controlHeight );
2124
2125 case SC_TitleBarMaxButton:
2126 case SC_TitleBarShadeButton:
2127 case SC_TitleBarUnshadeButton:
2128 return QRect( titlebar->width() - ( ( controlHeight + controlTop ) * 2 ),
2129 controlTop, controlHeight, controlHeight );
2130
2131 case SC_TitleBarMinButton:
2132 case SC_TitleBarNormalButton: {
2133 int offset = controlHeight + controlTop;
2134 if ( !titlebar->testWFlags( WStyle_Maximize ) )
2135 offset *= 2;
2136 else
2137 offset *= 3;
2138 return QRect( titlebar->width() - offset, controlTop, controlHeight, controlHeight );
2139 }
2140
2141 case SC_TitleBarSysMenu:
2142 return QRect( 3, controlTop, controlHeight, controlHeight);
2143
2144 default: break;
2145 }
2146 break; }
2147#endif //QT_NO_TITLEBAR
2148
2149 default:
2150 break;
2151 }
2152 return QRect();
2153}
2154
2155
2156/*! \reimp */
2157QStyle::SubControl QCommonStyle::querySubControl(ComplexControl control,
2158 const QWidget *widget,
2159 const QPoint &pos,
2160 const QStyleOption& opt ) const
2161{
2162 SubControl ret = SC_None;
2163
2164 switch (control) {
2165#ifndef QT_NO_LISTVIEW
2166 case CC_ListView:
2167 {
2168 if(pos.x() >= 0 && pos.x() <
2169 opt.listViewItem()->listView()->treeStepSize())
2170 ret = SC_ListViewExpand;
2171 break;
2172 }
2173#endif
2174#ifndef QT_NO_SCROLLBAR
2175 case CC_ScrollBar:
2176 {
2177 QRect r;
2178 uint ctrl = SC_ScrollBarAddLine;
2179
2180 // we can do this because subcontrols were designed to be masks as well...
2181 while (ret == SC_None && ctrl <= SC_ScrollBarGroove) {
2182 r = querySubControlMetrics(control, widget,
2183 (QStyle::SubControl) ctrl, opt);
2184 if (r.isValid() && r.contains(pos))
2185 ret = (QStyle::SubControl) ctrl;
2186
2187 ctrl <<= 1;
2188 }
2189
2190 break;
2191 }
2192#endif
2193 case CC_TitleBar:
2194 {
2195#ifndef QT_NO_TITLEBAR
2196 const QTitleBar *titlebar = (QTitleBar*)widget;
2197 QRect r;
2198 uint ctrl = SC_TitleBarLabel;
2199
2200 // we can do this because subcontrols were designed to be masks as well...
2201 while (ret == SC_None && ctrl <= SC_TitleBarUnshadeButton) {
2202 r = visualRect( querySubControlMetrics( control, widget, (QStyle::SubControl) ctrl, opt ), widget );
2203 if (r.isValid() && r.contains(pos))
2204 ret = (QStyle::SubControl) ctrl;
2205
2206 ctrl <<= 1;
2207 }
2208 if ( titlebar->window() ) {
2209 if (titlebar->testWFlags( WStyle_Tool )) {
2210 if ( ret == SC_TitleBarMinButton || ret == SC_TitleBarMaxButton ) {
2211 if ( titlebar->window()->isMinimized() )
2212 ret = SC_TitleBarUnshadeButton;
2213 else
2214 ret = SC_TitleBarShadeButton;
2215 }
2216 } else if ( ret == SC_TitleBarMinButton && titlebar->window()->isMinimized() ) {
2217 ret = QStyle::SC_TitleBarNormalButton;
2218 }
2219 }
2220#endif
2221 break;
2222 }
2223
2224 default:
2225 break;
2226 }
2227
2228 return ret;
2229}
2230
2231
2232/*! \reimp */
2233int QCommonStyle::pixelMetric(PixelMetric m, const QWidget *widget) const
2234{
2235 int ret;
2236
2237 switch (m) {
2238 case PM_DialogButtonsSeparator:
2239 ret = 5;
2240 break;
2241 case PM_DialogButtonsButtonWidth:
2242 ret = 70;
2243 break;
2244 case PM_DialogButtonsButtonHeight:
2245 ret = 30;
2246 break;
2247 case PM_CheckListControllerSize:
2248 case PM_CheckListButtonSize:
2249 ret = 16;
2250 break;
2251 case PM_TitleBarHeight: {
2252 if ( widget ) {
2253 if ( widget->testWFlags( WStyle_Tool ) ) {
2254 ret = QMAX( widget->fontMetrics().lineSpacing(), 16 );
2255#ifndef QT_NO_MAINWINDOW
2256 } else if ( ::qt_cast<QDockWindow*>(widget) ) {
2257 ret = QMAX( widget->fontMetrics().lineSpacing(), 13 );
2258#endif
2259 } else {
2260 ret = QMAX( widget->fontMetrics().lineSpacing(), 18 );
2261 }
2262 } else {
2263 ret = 0;
2264 }
2265
2266 break; }
2267 case PM_ScrollBarSliderMin:
2268 ret = 9;
2269 break;
2270
2271 case PM_ButtonMargin:
2272 ret = 6;
2273 break;
2274
2275 case PM_ButtonDefaultIndicator:
2276 ret = 0;
2277 break;
2278
2279 case PM_MenuButtonIndicator:
2280 if (! widget)
2281 ret = 12;
2282 else
2283 ret = QMAX(12, (widget->height() - 4) / 3);
2284 break;
2285
2286 case PM_ButtonShiftHorizontal:
2287 case PM_ButtonShiftVertical:
2288 ret = 0;
2289 break;
2290
2291 case PM_SpinBoxFrameWidth:
2292 case PM_DefaultFrameWidth:
2293 ret = 2;
2294 break;
2295
2296 case PM_MDIFrameWidth:
2297 ret = 4;
2298 break;
2299
2300 case PM_MDIMinimizedWidth:
2301 ret = 196;
2302 break;
2303
2304#ifndef QT_NO_SCROLLBAR
2305 case PM_ScrollBarExtent:
2306 if ( !widget ) {
2307 ret = 16;
2308 } else {
2309 const QScrollBar *bar = (const QScrollBar*)widget;
2310 int s = bar->orientation() == Qt::Horizontal ?
2311 QApplication::globalStrut().height()
2312 : QApplication::globalStrut().width();
2313 ret = QMAX( 16, s );
2314 }
2315 break;
2316#endif
2317 case PM_MaximumDragDistance:
2318 ret = -1;
2319 break;
2320
2321#ifndef QT_NO_SLIDER
2322 case PM_SliderThickness:
2323 ret = 16;
2324 break;
2325
2326 case PM_SliderTickmarkOffset:
2327 {
2328 if (! widget) {
2329 ret = 0;
2330 break;
2331 }
2332
2333 const QSlider * sl = (const QSlider *) widget;
2334 int space = (sl->orientation() == Horizontal) ? sl->height() :
2335 sl->width();
2336 int thickness = pixelMetric( PM_SliderControlThickness, sl );
2337 int ticks = sl->tickmarks();
2338
2339 if ( ticks == QSlider::Both )
2340 ret = (space - thickness) / 2;
2341 else if ( ticks == QSlider::Above )
2342 ret = space - thickness;
2343 else
2344 ret = 0;
2345 break;
2346 }
2347
2348 case PM_SliderSpaceAvailable:
2349 {
2350 const QSlider * sl = (const QSlider *) widget;
2351 if ( sl->orientation() == Horizontal )
2352 ret = sl->width() - pixelMetric( PM_SliderLength, sl );
2353 else
2354 ret = sl->height() - pixelMetric( PM_SliderLength, sl );
2355 break;
2356 }
2357#endif // QT_NO_SLIDER
2358
2359 case PM_DockWindowSeparatorExtent:
2360 ret = 6;
2361 break;
2362
2363 case PM_DockWindowHandleExtent:
2364 ret = 8;
2365 break;
2366
2367 case PM_DockWindowFrameWidth:
2368 ret = 1;
2369 break;
2370
2371 case PM_MenuBarFrameWidth:
2372 ret = 2;
2373 break;
2374
2375 case PM_MenuBarItemSpacing:
2376 case PM_ToolBarItemSpacing:
2377 ret = 0;
2378 break;
2379
2380 case PM_TabBarTabOverlap:
2381 ret = 3;
2382 break;
2383
2384 case PM_TabBarBaseHeight:
2385 ret = 0;
2386 break;
2387
2388 case PM_TabBarBaseOverlap:
2389 ret = 0;
2390 break;
2391
2392 case PM_TabBarTabHSpace:
2393 ret = 24;
2394 break;
2395
2396 case PM_TabBarTabShiftHorizontal:
2397 case PM_TabBarTabShiftVertical:
2398 ret = 2;
2399 break;
2400
2401#ifndef QT_NO_TABBAR
2402 case PM_TabBarTabVSpace:
2403 {
2404 const QTabBar * tb = (const QTabBar *) widget;
2405 if ( tb && ( tb->shape() == QTabBar::RoundedAbove ||
2406 tb->shape() == QTabBar::RoundedBelow ) )
2407 ret = 10;
2408 else
2409 ret = 0;
2410 break;
2411 }
2412#endif
2413
2414 case PM_ProgressBarChunkWidth:
2415 ret = 9;
2416 break;
2417
2418 case PM_IndicatorWidth:
2419 ret = 13;
2420 break;
2421
2422 case PM_IndicatorHeight:
2423 ret = 13;
2424 break;
2425
2426 case PM_ExclusiveIndicatorWidth:
2427 ret = 12;
2428 break;
2429
2430 case PM_ExclusiveIndicatorHeight:
2431 ret = 12;
2432 break;
2433
2434 case PM_PopupMenuFrameHorizontalExtra:
2435 case PM_PopupMenuFrameVerticalExtra:
2436 ret = 0;
2437 break;
2438
2439 case PM_HeaderMargin:
2440 ret = 4;
2441 break;
2442 case PM_HeaderMarkSize:
2443 ret = 32;
2444 break;
2445 case PM_HeaderGripMargin:
2446 ret = 4;
2447 break;
2448 case PM_TabBarScrollButtonWidth:
2449 ret = 16;
2450 break;
2451 default:
2452 ret = 0;
2453 break;
2454 }
2455
2456 return ret;
2457}
2458
2459
2460/*! \reimp */
2461QSize QCommonStyle::sizeFromContents(ContentsType contents,
2462 const QWidget *widget,
2463 const QSize &contentsSize,
2464 const QStyleOption& opt ) const
2465{
2466 QSize sz(contentsSize);
2467
2468#if defined(QT_CHECK_STATE)
2469 if (! widget) {
2470 qWarning("QCommonStyle::sizeFromContents: widget parameter cannot be zero!");
2471 return sz;
2472 }
2473#endif
2474
2475 switch (contents) {
2476#ifndef QT_NO_DIALOGBUTTONS
2477 case CT_DialogButtons: {
2478 const QDialogButtons *dbtns = (const QDialogButtons *)widget;
2479 int w = contentsSize.width(), h = contentsSize.height();
2480 const int bwidth = pixelMetric(PM_DialogButtonsButtonWidth, widget),
2481 bspace = pixelMetric(PM_DialogButtonsSeparator, widget),
2482 bheight = pixelMetric(PM_DialogButtonsButtonHeight, widget);
2483 if(dbtns->orientation() == Horizontal) {
2484 if(!w)
2485 w = bwidth;
2486 } else {
2487 if(!h)
2488 h = bheight;
2489 }
2490 QDialogButtons::Button btns[] = { QDialogButtons::All, QDialogButtons::Reject, QDialogButtons::Accept, //reverse order (right to left)
2491 QDialogButtons::Apply, QDialogButtons::Retry, QDialogButtons::Ignore, QDialogButtons::Abort,
2492 QDialogButtons::Help };
2493 for(unsigned int i = 0, cnt = 0; i < (sizeof(btns)/sizeof(btns[0])); i++) {
2494 if(dbtns->isButtonVisible(btns[i])) {
2495 QSize szH = dbtns->sizeHint(btns[i]);
2496 int mwidth = QMAX(bwidth, szH.width()), mheight = QMAX(bheight, szH.height());
2497 if(dbtns->orientation() == Horizontal)
2498 h = QMAX(h, mheight);
2499 else
2500 w = QMAX(w, mwidth);
2501
2502 if(cnt)
2503 w += bspace;
2504 cnt++;
2505 if(dbtns->orientation() == Horizontal)
2506 w += mwidth;
2507 else
2508 h += mheight;
2509 }
2510 }
2511 const int fw = pixelMetric(PM_DefaultFrameWidth, widget) * 2;
2512 sz = QSize(w + fw, h + fw);
2513 break; }
2514#endif //QT_NO_DIALOGBUTTONS
2515 case CT_PushButton:
2516 {
2517#ifndef QT_NO_PUSHBUTTON
2518 const QPushButton *button = (const QPushButton *) widget;
2519 int w = contentsSize.width(),
2520 h = contentsSize.height(),
2521 bm = pixelMetric(PM_ButtonMargin, widget),
2522 fw = pixelMetric(PM_DefaultFrameWidth, widget) * 2;
2523
2524 w += bm + fw;
2525 h += bm + fw;
2526
2527 if (button->isDefault() || button->autoDefault()) {
2528 int dbw = pixelMetric(PM_ButtonDefaultIndicator, widget) * 2;
2529 w += dbw;
2530 h += dbw;
2531 }
2532
2533 sz = QSize(w, h);
2534#endif
2535 break;
2536 }
2537
2538 case CT_CheckBox:
2539 {
2540#ifndef QT_NO_CHECKBOX
2541 const QCheckBox *checkbox = (const QCheckBox *) widget;
2542 QRect irect = subRect(SR_CheckBoxIndicator, widget);
2543 int h = pixelMetric( PM_IndicatorHeight, widget );
2544 int margins = (!checkbox->pixmap() && checkbox->text().isEmpty()) ? 0 : 10;
2545 sz += QSize(irect.right() + margins, 4 );
2546 sz.setHeight( QMAX( sz.height(), h ) );
2547#endif
2548 break;
2549 }
2550
2551 case CT_RadioButton:
2552 {
2553#ifndef QT_NO_RADIOBUTTON
2554 const QRadioButton *radiobutton = (const QRadioButton *) widget;
2555 QRect irect = subRect(SR_RadioButtonIndicator, widget);
2556 int h = pixelMetric( PM_ExclusiveIndicatorHeight, widget );
2557 int margins = (!radiobutton->pixmap() && radiobutton->text().isEmpty()) ? 0 : 10;
2558 sz += QSize(irect.right() + margins, 4 );
2559 sz.setHeight( QMAX( sz.height(), h ) );
2560#endif
2561 break;
2562 }
2563
2564 case CT_ToolButton:
2565 {
2566 sz = QSize(sz.width() + 6, sz.height() + 5);
2567 break;
2568 }
2569
2570 case CT_ComboBox:
2571 {
2572 int dfw = pixelMetric(PM_DefaultFrameWidth, widget) * 2;
2573 sz = QSize(sz.width() + dfw + 21, sz.height() + dfw );
2574 break;
2575 }
2576
2577 case CT_PopupMenuItem:
2578 {
2579#ifndef QT_NO_POPUPMENU
2580 if (opt.isDefault())
2581 break;
2582
2583 const QPopupMenu *popup = (const QPopupMenu *) widget;
2584 bool checkable = popup->isCheckable();
2585 QMenuItem *mi = opt.menuItem();
2586 int maxpmw = opt.maxIconWidth();
2587 int w = sz.width(), h = sz.height();
2588
2589 if (mi->custom()) {
2590 w = mi->custom()->sizeHint().width();
2591 h = mi->custom()->sizeHint().height();
2592 if (! mi->custom()->fullSpan())
2593 h += 8;
2594 } else if ( mi->widget() ) {
2595 } else if (mi->isSeparator()) {
2596 w = 10;
2597 h = 2;
2598 } else {
2599 if (mi->pixmap())
2600 h = QMAX(h, mi->pixmap()->height() + 4);
2601 else
2602 h = QMAX(h, popup->fontMetrics().height() + 8);
2603
2604 if (mi->iconSet() != 0)
2605 h = QMAX(h, mi->iconSet()->pixmap(QIconSet::Small,
2606 QIconSet::Normal).height() + 4);
2607 }
2608
2609 if (! mi->text().isNull()) {
2610 if (mi->text().find('\t') >= 0)
2611 w += 12;
2612 }
2613
2614 if (maxpmw)
2615 w += maxpmw + 6;
2616 if (checkable && maxpmw < 20)
2617 w += 20 - maxpmw;
2618 if (checkable || maxpmw > 0)
2619 w += 2;
2620 w += 12;
2621
2622 sz = QSize(w, h);
2623#endif
2624 break;
2625 }
2626
2627 case CT_LineEdit:
2628 case CT_Header:
2629 case CT_Slider:
2630 case CT_ProgressBar:
2631 // just return the contentsSize for now
2632 // fall through intended
2633
2634 default:
2635 break;
2636 }
2637
2638 return sz;
2639}
2640
2641
2642/*! \reimp */
2643int QCommonStyle::styleHint(StyleHint sh, const QWidget * w, const QStyleOption &, QStyleHintReturn *) const
2644{
2645 int ret;
2646
2647 switch (sh) {
2648#ifndef QT_NO_DIALOGBUTTONS
2649 case SH_DialogButtons_DefaultButton:
2650 ret = QDialogButtons::Accept;
2651 break;
2652#endif
2653 case SH_GroupBox_TextLabelVerticalAlignment:
2654 ret = Qt::AlignVCenter;
2655 break;
2656
2657 case SH_GroupBox_TextLabelColor:
2658 ret = (int) ( w ? w->paletteForegroundColor().rgb() : 0 );
2659 break;
2660
2661 case SH_ListViewExpand_SelectMouseType:
2662 case SH_TabBar_SelectMouseType:
2663 ret = QEvent::MouseButtonPress;
2664 break;
2665
2666 case SH_GUIStyle:
2667 ret = WindowsStyle;
2668 break;
2669
2670 case SH_ScrollBar_BackgroundMode:
2671 ret = QWidget::PaletteBackground;
2672 break;
2673
2674 case SH_TabBar_Alignment:
2675 case SH_Header_ArrowAlignment:
2676 ret = Qt::AlignLeft;
2677 break;
2678
2679 case SH_PopupMenu_SubMenuPopupDelay:
2680 ret = 256;
2681 break;
2682
2683 case SH_ProgressDialog_TextLabelAlignment:
2684 ret = Qt::AlignCenter;
2685 break;
2686
2687 case SH_BlinkCursorWhenTextSelected:
2688 ret = 1;
2689 break;
2690
2691 case SH_Table_GridLineColor:
2692 ret = (int) ( w ? w->colorGroup().mid().rgb() : 0 );
2693 break;
2694
2695 case SH_LineEdit_PasswordCharacter:
2696 ret = '*';
2697 break;
2698
2699 case SH_ToolBox_SelectedPageTitleBold:
2700 ret = 1;
2701 break;
2702
2703 case SH_UnderlineAccelerator:
2704 ret = 1;
2705 break;
2706
2707 case SH_ToolButton_Uses3D:
2708 ret = 1;
2709 break;
2710
2711 default:
2712 ret = 0;
2713 break;
2714 }
2715
2716 return ret;
2717}
2718
2719/*! \reimp */
2720QPixmap QCommonStyle::stylePixmap(StylePixmap, const QWidget *, const QStyleOption&) const
2721{
2722 return QPixmap();
2723}
2724
2725
2726#endif // QT_NO_STYLE
Note: See TracBrowser for help on using the repository browser.