source: trunk/src/styles/qcommonstyle.cpp@ 8

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

Transferred Qt for OS/2 version 3.3.1-rc5 sources from the CVS

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