source: trunk/src/styles/qmotifstyle.cpp@ 7

Last change on this file since 7 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: 66.7 KB
Line 
1/****************************************************************************
2** $Id: qmotifstyle.cpp 2 2005-11-16 15:49:26Z dmik $
3**
4** Implementation of Motif-like style 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 "qmotifstyle.h"
39
40#if !defined(QT_NO_STYLE_MOTIF) || defined(QT_PLUGIN)
41
42#include "qpopupmenu.h"
43#include "qapplication.h"
44#include "qpainter.h"
45#include "qdrawutil.h"
46#include "qpixmap.h"
47#include "qpalette.h"
48#include "qwidget.h"
49#include "qpushbutton.h"
50#include "qscrollbar.h"
51#include "qtabbar.h"
52#include "qtabwidget.h"
53#include "qlistview.h"
54#include "qsplitter.h"
55#include "qslider.h"
56#include "qcombobox.h"
57#include "qdockwindow.h"
58#include "qdockarea.h"
59#include "qprogressbar.h"
60#include "qimage.h"
61#include <limits.h>
62
63
64
65// old constants that might still be useful...
66static const int motifItemFrame = 2; // menu item frame width
67static const int motifSepHeight = 2; // separator item height
68static const int motifItemHMargin = 3; // menu item hor text margin
69static const int motifItemVMargin = 2; // menu item ver text margin
70static const int motifArrowHMargin = 6; // arrow horizontal margin
71static const int motifTabSpacing = 12; // space between text and tab
72static const int motifCheckMarkHMargin = 2; // horiz. margins of check mark
73static const int motifCheckMarkSpace = 12;
74
75
76/*!
77 \class QMotifStyle qmotifstyle.h
78 \brief The QMotifStyle class provides Motif look and feel.
79
80 \ingroup appearance
81
82 This class implements the Motif look and feel. It closely
83 resembles the original Motif look as defined by the Open Group,
84 but with some minor improvements. The Motif style is Qt's default
85 GUI style on UNIX platforms.
86*/
87
88/*!
89 Constructs a QMotifStyle.
90
91 If \a useHighlightCols is FALSE (the default), the style will
92 polish the application's color palette to emulate the Motif way of
93 highlighting, which is a simple inversion between the base and the
94 text color.
95*/
96QMotifStyle::QMotifStyle( bool useHighlightCols ) : QCommonStyle()
97{
98 highlightCols = useHighlightCols;
99}
100
101/*!\reimp
102*/
103QMotifStyle::~QMotifStyle()
104{
105}
106
107/*!
108 If \a arg is FALSE, the style will polish the application's color
109 palette to emulate the Motif way of highlighting, which is a
110 simple inversion between the base and the text color.
111
112 The effect will show up the next time an application palette is
113 set via QApplication::setPalette(). The current color palette of
114 the application remains unchanged.
115
116 \sa QStyle::polish()
117*/
118void QMotifStyle::setUseHighlightColors( bool arg )
119{
120 highlightCols = arg;
121}
122
123/*!
124 Returns TRUE if the style treats the highlight colors of the
125 palette in a Motif-like manner, which is a simple inversion
126 between the base and the text color; otherwise returns FALSE. The
127 default is FALSE.
128*/
129bool QMotifStyle::useHighlightColors() const
130{
131 return highlightCols;
132}
133
134/*! \reimp */
135
136void QMotifStyle::polish( QPalette& pal )
137{
138 if ( pal.active().light() == pal.active().base() ) {
139 QColor nlight = pal.active().light().dark(108 );
140 pal.setColor( QPalette::Active, QColorGroup::Light, nlight ) ;
141 pal.setColor( QPalette::Disabled, QColorGroup::Light, nlight ) ;
142 pal.setColor( QPalette::Inactive, QColorGroup::Light, nlight ) ;
143 }
144
145 if ( highlightCols )
146 return;
147
148 // force the ugly motif way of highlighting *sigh*
149 QColorGroup disabled = pal.disabled();
150 QColorGroup active = pal.active();
151
152 pal.setColor( QPalette::Active, QColorGroup::Highlight,
153 active.text() );
154 pal.setColor( QPalette::Active, QColorGroup::HighlightedText,
155 active.base());
156 pal.setColor( QPalette::Disabled, QColorGroup::Highlight,
157 disabled.text() );
158 pal.setColor( QPalette::Disabled, QColorGroup::HighlightedText,
159 disabled.base() );
160 pal.setColor( QPalette::Inactive, QColorGroup::Highlight,
161 active.text() );
162 pal.setColor( QPalette::Inactive, QColorGroup::HighlightedText,
163 active.base() );
164}
165
166/*!
167 \reimp
168 \internal
169 Keep QStyle::polish() visible.
170*/
171void QMotifStyle::polish( QWidget* w )
172{
173 QStyle::polish(w);
174}
175
176/*!
177 \reimp
178 \internal
179 Keep QStyle::polish() visible.
180*/
181void QMotifStyle::polish( QApplication* a )
182{
183 QStyle::polish(a);
184}
185
186static void rot(QPointArray& a, int n)
187{
188 QPointArray r(a.size());
189 for (int i = 0; i < (int)a.size(); i++) {
190 switch (n) {
191 case 1: r.setPoint(i,-a[i].y(),a[i].x()); break;
192 case 2: r.setPoint(i,-a[i].x(),-a[i].y()); break;
193 case 3: r.setPoint(i,a[i].y(),-a[i].x()); break;
194 }
195 }
196 a = r;
197}
198
199
200/*!\reimp
201*/
202void QMotifStyle::drawPrimitive( PrimitiveElement pe,
203 QPainter *p,
204 const QRect &r,
205 const QColorGroup &cg,
206 SFlags flags,
207 const QStyleOption& opt ) const
208{
209 switch( pe ) {
210#ifndef QT_NO_LISTVIEW
211 case PE_CheckListExclusiveIndicator: {
212 QCheckListItem *item = opt.checkListItem();
213 QListView *lv = item->listView();
214 if(!item)
215 return;
216
217 if ( item->isEnabled() )
218 p->setPen( QPen( cg.text() ) );
219 else
220 p->setPen( QPen( lv->palette().color( QPalette::Disabled, QColorGroup::Text ) ) );
221 QPointArray a;
222
223 int cx = r.width()/2 - 1;
224 int cy = r.height()/2;
225 int e = r.width()/2 - 1;
226 for ( int i = 0; i < 3; i++ ) { //penWidth 2 doesn't quite work
227 a.setPoints( 4, cx-e, cy, cx, cy-e, cx+e, cy, cx, cy+e );
228 p->drawPolygon( a );
229 e--;
230 }
231 if ( item->isOn() ) {
232 if ( item->isEnabled() )
233 p->setPen( QPen( cg.text()) );
234 else
235 p->setPen( QPen( item->listView()->palette().color( QPalette::Disabled,
236 QColorGroup::Text ) ) );
237 QBrush saveBrush = p->brush();
238 p->setBrush( cg.text() );
239 e = e - 2;
240 a.setPoints( 4, cx-e, cy, cx, cy-e, cx+e, cy, cx, cy+e );
241 p->drawPolygon( a );
242 p->setBrush( saveBrush );
243 }
244 break; }
245#endif
246 case PE_ButtonCommand:
247 case PE_ButtonBevel:
248 case PE_ButtonTool:
249 case PE_HeaderSection:
250 qDrawShadePanel( p, r, cg, bool(flags & (Style_Down | Style_On )),
251 pixelMetric(PM_DefaultFrameWidth),
252 &cg.brush(QColorGroup::Button) );
253 break;
254
255 case PE_Indicator: {
256#ifndef QT_NO_BUTTON
257 bool on = flags & Style_On;
258 bool down = flags & Style_Down;
259 bool showUp = !( down ^ on );
260 QBrush fill = showUp || flags & Style_NoChange ? cg.brush( QColorGroup::Button ) : cg.brush(QColorGroup::Mid );
261 if ( flags & Style_NoChange ) {
262 qDrawPlainRect( p, r, cg.text(),
263 1, &fill );
264 p->drawLine( r.x() + r.width() - 1, r.y(),
265 r.x(), r.y() + r.height() - 1);
266 } else
267 qDrawShadePanel( p, r, cg, !showUp,
268 pixelMetric(PM_DefaultFrameWidth), &fill );
269#endif
270 break;
271 }
272
273 case PE_ExclusiveIndicator:
274 {
275#define QCOORDARRLEN(x) sizeof(x)/(sizeof(QCOORD)*2)
276 QCOORD inner_pts[] = { // used for filling diamond
277 2,r.height()/2,
278 r.width()/2,2,
279 r.width()-3,r.height()/2,
280 r.width()/2,r.height()-3
281 };
282 QCOORD top_pts[] = { // top (^) of diamond
283 0,r.height()/2,
284 r.width()/2,0,
285 r.width()-2,r.height()/2-1,
286 r.width()-3,r.height()/2-1,
287 r.width()/2,1,
288 1,r.height()/2,
289 2,r.height()/2,
290 r.width()/2,2,
291 r.width()-4,r.height()/2-1
292 };
293 QCOORD bottom_pts[] = { // bottom (v) of diamond
294 1,r.height()/2+1,
295 r.width()/2,r.height()-1,
296 r.width()-1,r.height()/2,
297 r.width()-2,r.height()/2,
298 r.width()/2,r.height()-2,
299 2,r.height()/2+1,
300 3,r.height()/2+1,
301 r.width()/2,r.height()-3,
302 r.width()-3,r.height()/2
303 };
304 bool on = flags & Style_On;
305 bool down = flags & Style_Down;
306 bool showUp = !(down ^ on );
307 QPointArray a( QCOORDARRLEN(inner_pts), inner_pts );
308 p->eraseRect( r );
309 p->setPen( NoPen );
310 p->setBrush( showUp ? cg.brush( QColorGroup::Button ) :
311 cg.brush( QColorGroup::Mid ) );
312 a.translate( r.x(), r.y() );
313 p->drawPolygon( a );
314 p->setPen( showUp ? cg.light() : cg.dark() );
315 p->setBrush( NoBrush );
316 a.setPoints( QCOORDARRLEN(top_pts), top_pts );
317 a.translate( r.x(), r.y() );
318 p->drawPolyline( a );
319 p->setPen( showUp ? cg.dark() : cg.light() );
320 a.setPoints( QCOORDARRLEN(bottom_pts), bottom_pts );
321 a.translate( r.x(), r.y() );
322 p->drawPolyline( a );
323
324 break;
325 }
326
327 case PE_ExclusiveIndicatorMask:
328 {
329 static QCOORD inner_pts[] = { // used for filling diamond
330 0,r.height()/2,
331 r.width()/2,0,
332 r.width()-1,r.height()/2,
333 r.width()/2,r.height()-1
334 };
335 QPointArray a(QCOORDARRLEN(inner_pts), inner_pts);
336 p->setPen(color1);
337 p->setBrush(color1);
338 a.translate(r.x(), r.y());
339 p->drawPolygon(a);
340 break;
341 }
342
343 case PE_ArrowUp:
344 case PE_ArrowDown:
345 case PE_ArrowRight:
346 case PE_ArrowLeft:
347 {
348 QRect rect = r;
349 QPointArray bFill;
350 QPointArray bTop;
351 QPointArray bBot;
352 QPointArray bLeft;
353 bool vertical = pe == PE_ArrowUp || pe == PE_ArrowDown;
354 bool horizontal = !vertical;
355 int dim = rect.width() < rect.height() ? rect.width() : rect.height();
356 int colspec = 0x0000;
357
358 if ( dim < 2 )
359 break;
360
361 // adjust size and center (to fix rotation below)
362 if ( rect.width() > dim ) {
363 rect.setX( rect.x() + ((rect.width() - dim ) / 2) );
364 rect.setWidth( dim );
365 }
366 if ( rect.height() > dim ) {
367 rect.setY( rect.y() + ((rect.height() - dim ) / 2 ));
368 rect.setHeight( dim );
369 }
370
371 if ( dim > 3 ) {
372 if ( dim > 6 )
373 bFill.resize( dim & 1 ? 3 : 4 );
374 bTop.resize( (dim/2)*2 );
375 bBot.resize( dim & 1 ? dim + 1 : dim );
376 bLeft.resize( dim > 4 ? 4 : 2 );
377 bLeft.putPoints( 0, 2, 0,0, 0,dim-1 );
378 if ( dim > 4 )
379 bLeft.putPoints( 2, 2, 1,2, 1,dim-3 );
380 bTop.putPoints( 0, 4, 1,0, 1,1, 2,1, 3,1 );
381 bBot.putPoints( 0, 4, 1,dim-1, 1,dim-2, 2,dim-2, 3,dim-2 );
382
383 for( int i=0; i<dim/2-2 ; i++ ) {
384 bTop.putPoints( i*2+4, 2, 2+i*2,2+i, 5+i*2, 2+i );
385 bBot.putPoints( i*2+4, 2, 2+i*2,dim-3-i, 5+i*2,dim-3-i );
386 }
387 if ( dim & 1 ) // odd number size: extra line
388 bBot.putPoints( dim-1, 2, dim-3,dim/2, dim-1,dim/2 );
389 if ( dim > 6 ) { // dim>6: must fill interior
390 bFill.putPoints( 0, 2, 1,dim-3, 1,2 );
391 if ( dim & 1 ) // if size is an odd number
392 bFill.setPoint( 2, dim - 3, dim / 2 );
393 else
394 bFill.putPoints( 2, 2, dim-4,dim/2-1, dim-4,dim/2 );
395 }
396 }
397 else {
398 if ( dim == 3 ) { // 3x3 arrow pattern
399 bLeft.setPoints( 4, 0,0, 0,2, 1,1, 1,1 );
400 bTop .setPoints( 2, 1,0, 1,0 );
401 bBot .setPoints( 2, 1,2, 2,1 );
402 }
403 else { // 2x2 arrow pattern
404 bLeft.setPoints( 2, 0,0, 0,1 );
405 bTop .setPoints( 2, 1,0, 1,0 );
406 bBot .setPoints( 2, 1,1, 1,1 );
407 }
408 }
409
410 // We use rot() and translate() as it is more efficient that
411 // matrix transformations on the painter, and because it still
412 // works with QT_NO_TRANSFORMATIONS defined.
413
414 if ( pe == PE_ArrowUp || pe == PE_ArrowLeft ) {
415 if ( vertical ) {
416 rot(bFill,3);
417 rot(bLeft,3);
418 rot(bTop,3);
419 rot(bBot,3);
420 bFill.translate( 0, rect.height() - 1 );
421 bLeft.translate( 0, rect.height() - 1 );
422 bTop.translate( 0, rect.height() - 1 );
423 bBot.translate( 0, rect.height() - 1 );
424 } else {
425 rot(bFill,2);
426 rot(bLeft,2);
427 rot(bTop,2);
428 rot(bBot,2);
429 bFill.translate( rect.width() - 1, rect.height() - 1 );
430 bLeft.translate( rect.width() - 1, rect.height() - 1 );
431 bTop.translate( rect.width() - 1, rect.height() - 1 );
432 bBot.translate( rect.width() - 1, rect.height() - 1 );
433 }
434 if ( flags & Style_Down )
435 colspec = horizontal ? 0x2334 : 0x2343;
436 else
437 colspec = horizontal ? 0x1443 : 0x1434;
438 } else {
439 if ( vertical ) {
440 rot(bFill,1);
441 rot(bLeft,1);
442 rot(bTop,1);
443 rot(bBot,1);
444 bFill.translate( rect.width() - 1, 0 );
445 bLeft.translate( rect.width() - 1, 0 );
446 bTop.translate( rect.width() - 1, 0 );
447 bBot.translate( rect.width() - 1, 0 );
448 }
449 if ( flags & Style_Down )
450 colspec = horizontal ? 0x2443 : 0x2434;
451 else
452 colspec = horizontal ? 0x1334 : 0x1343;
453 }
454 bFill.translate( rect.x(), rect.y() );
455 bLeft.translate( rect.x(), rect.y() );
456 bTop.translate( rect.x(), rect.y() );
457 bBot.translate( rect.x(), rect.y() );
458
459 QColor *cols[5];
460 if ( flags & Style_Enabled ) {
461 cols[0] = 0;
462 cols[1] = (QColor *)&cg.button();
463 cols[2] = (QColor *)&cg.mid();
464 cols[3] = (QColor *)&cg.light();
465 cols[4] = (QColor *)&cg.dark();
466 } else {
467 cols[0] = 0;
468 cols[1] = (QColor *)&cg.button();
469 cols[2] = (QColor *)&cg.button();
470 cols[3] = (QColor *)&cg.button();
471 cols[4] = (QColor *)&cg.button();
472 }
473
474#define CMID *cols[ (colspec>>12) & 0xf ]
475#define CLEFT *cols[ (colspec>>8) & 0xf ]
476#define CTOP *cols[ (colspec>>4) & 0xf ]
477#define CBOT *cols[ colspec & 0xf ]
478
479 QPen savePen = p->pen();
480 QBrush saveBrush = p->brush();
481 QPen pen( NoPen );
482 QBrush brush = cg.brush( flags & Style_Enabled ? QColorGroup::Button :
483 QColorGroup::Mid );
484 p->setPen( pen );
485 p->setBrush( brush );
486 p->drawPolygon( bFill );
487 p->setBrush( NoBrush );
488
489 p->setPen( CLEFT );
490 p->drawLineSegments( bLeft );
491 p->setPen( CTOP );
492 p->drawLineSegments( bTop );
493 p->setPen( CBOT );
494 p->drawLineSegments( bBot );
495
496 p->setBrush( saveBrush );
497 p->setPen( savePen );
498#undef CMID
499#undef CLEFT
500#undef CTOP
501#undef CBOT
502 break;
503 }
504
505 case PE_SpinWidgetPlus:
506 case PE_SpinWidgetMinus:
507 {
508 p->save();
509 int fw = pixelMetric( PM_DefaultFrameWidth );
510 QRect br;
511 br.setRect( r.x() + fw, r.y() + fw, r.width() - fw*2,
512 r.height() - fw*2 );
513
514 if ( flags & Style_Sunken )
515 p->fillRect( r, cg.brush( QColorGroup::Dark ) );
516 else
517 p->fillRect( r, cg.brush( QColorGroup::Button ) );
518
519 p->setPen( cg.buttonText() );
520 p->setBrush( cg.buttonText() );
521
522 int length;
523 int x = r.x(), y = r.y(), w = r.width(), h = r.height();
524 if ( w <= 8 || h <= 6 )
525 length = QMIN( w-2, h-2 );
526 else
527 length = QMIN( 2*w / 3, 2*h / 3 );
528
529 if ( !(length & 1) )
530 length -=1;
531 int xmarg = ( w - length ) / 2;
532 int ymarg = ( h - length ) / 2;
533
534 p->drawLine( x + xmarg, ( y + h / 2 - 1 ),
535 x + xmarg + length - 1, ( y + h / 2 - 1 ) );
536 if ( pe == PE_SpinWidgetPlus )
537 p->drawLine( ( x+w / 2 ) - 1, y + ymarg,
538 ( x+w / 2 ) - 1, y + ymarg + length - 1 );
539 p->restore();
540 break;
541 }
542
543 case PE_SpinWidgetUp:
544 case PE_SpinWidgetDown:
545 {
546 p->save();
547 int fw = pixelMetric( PM_DefaultFrameWidth );
548 QRect br;
549 br.setRect( r.x() + fw, r.y() + fw, r.width() - fw*2,
550 r.height() - fw*2 );
551 if ( flags & Style_Sunken )
552 p->fillRect( br, cg.brush( QColorGroup::Mid ) );
553 else
554 p->fillRect( br, cg.brush( QColorGroup::Button ) );
555
556 int x = r.x(), y = r.y(), w = r.width(), h = r.height();
557 int sw = w-4;
558 if ( sw < 3 )
559 return;
560 else if ( !(sw & 1) )
561 sw--;
562 sw -= ( sw / 7 ) * 2; // Empty border
563 int sh = sw/2 + 2; // Must have empty row at foot of arrow
564
565 int sx = x + w / 2 - sw / 2 - 1;
566 int sy = y + h / 2 - sh / 2 - 1;
567
568 QPointArray a;
569 if ( pe == PE_SpinWidgetDown )
570 a.setPoints( 3, 0, 1, sw-1, 1, sh-2, sh-1 );
571 else
572 a.setPoints( 3, 0, sh-1, sw-1, sh-1, sh-2, 1 );
573 int bsx = 0;
574 int bsy = 0;
575 if ( flags & Style_Sunken ) {
576 bsx = pixelMetric(PM_ButtonShiftHorizontal);
577 bsy = pixelMetric(PM_ButtonShiftVertical);
578 }
579 p->translate( sx + bsx, sy + bsy );
580 p->setPen( cg.buttonText() );
581 p->setBrush( cg.buttonText() );
582 p->drawPolygon( a );
583 p->restore();
584 break;
585 }
586
587 case PE_DockWindowHandle:
588 {
589 p->save();
590 p->translate( r.x(), r.y() );
591
592 QColor dark( cg.dark() );
593 QColor light( cg.light() );
594 unsigned int i;
595 if ( flags & Style_Horizontal ) {
596 int h = r.height();
597 if ( h > 6 ) {
598 if ( flags & Style_On )
599 p->fillRect( 1, 1, 8, h - 2, cg.highlight() );
600 QPointArray a( 2 * ((h-6)/3) );
601 int y = 3 + (h%3)/2;
602 p->setPen( dark );
603 p->drawLine( 8, 1, 8, h-2 );
604 for( i=0; 2*i < a.size(); i ++ ) {
605 a.setPoint( 2*i, 5, y+1+3*i );
606 a.setPoint( 2*i+1, 2, y+2+3*i );
607 }
608 p->drawPoints( a );
609 p->setPen( light );
610 p->drawLine( 9, 1, 9, h-2 );
611 for( i=0; 2*i < a.size(); i++ ) {
612 a.setPoint( 2*i, 4, y+3*i );
613 a.setPoint( 2*i+1, 1, y+1+3*i );
614 }
615 p->drawPoints( a );
616 // if ( drawBorder ) {
617 // p->setPen( QPen( Qt::darkGray ) );
618 // p->drawLine( 0, r.height() - 1,
619 // tbExtent, r.height() - 1 );
620 // }
621 }
622 } else {
623 int w = r.width();
624 if ( w > 6 ) {
625 if ( flags & Style_On )
626 p->fillRect( 1, 1, w - 2, 9, cg.highlight() );
627 QPointArray a( 2 * ((w-6)/3) );
628
629 int x = 3 + (w%3)/2;
630 p->setPen( dark );
631 p->drawLine( 1, 8, w-2, 8 );
632 for( i=0; 2*i < a.size(); i ++ ) {
633 a.setPoint( 2*i, x+1+3*i, 6 );
634 a.setPoint( 2*i+1, x+2+3*i, 3 );
635 }
636 p->drawPoints( a );
637 p->setPen( light );
638 p->drawLine( 1, 9, w-2, 9 );
639 for( i=0; 2*i < a.size(); i++ ) {
640 a.setPoint( 2*i, x+3*i, 5 );
641 a.setPoint( 2*i+1, x+1+3*i, 2 );
642 }
643 p->drawPoints( a );
644 // if ( drawBorder ) {
645 // p->setPen( QPen( Qt::darkGray ) );
646 // p->drawLine( r.width() - 1, 0,
647 // r.width() - 1, tbExtent );
648 // }
649 }
650 }
651 p->restore();
652 break;
653 }
654
655 case PE_Splitter:
656 if (flags & Style_Horizontal)
657 flags &= ~Style_Horizontal;
658 else
659 flags |= Style_Horizontal;
660 // fall through intended
661
662 case PE_DockWindowResizeHandle:
663 {
664 const int motifOffset = 10;
665 int sw = pixelMetric( PM_SplitterWidth );
666 if ( flags & Style_Horizontal ) {
667 QCOORD yPos = r.y() + r.height() / 2;
668 QCOORD kPos = r.width() - motifOffset - sw;
669 QCOORD kSize = sw - 2;
670
671 qDrawShadeLine( p, 0, yPos, kPos, yPos, cg );
672 qDrawShadePanel( p, kPos, yPos - sw / 2 + 1, kSize, kSize,
673 cg, FALSE, 1, &cg.brush( QColorGroup::Button ) );
674 qDrawShadeLine( p, kPos + kSize - 1, yPos, r.width(), yPos, cg );
675 } else {
676 QCOORD xPos = r.x() + r.width() / 2;
677 QCOORD kPos = motifOffset;
678 QCOORD kSize = sw - 2;
679
680 qDrawShadeLine( p, xPos, kPos + kSize - 1, xPos, r.height(), cg );
681 qDrawShadePanel( p, xPos - sw / 2 + 1, kPos, kSize, kSize, cg,
682 FALSE, 1, &cg.brush( QColorGroup::Button ) );
683 qDrawShadeLine( p, xPos, 0, xPos, kPos, cg );
684 }
685 break;
686 }
687
688 case PE_CheckMark:
689 {
690 const int markW = 6;
691 const int markH = 6;
692 int posX = r.x() + ( r.width() - markW ) / 2 - 1;
693 int posY = r.y() + ( r.height() - markH ) / 2;
694 int dfw = pixelMetric(PM_DefaultFrameWidth);
695
696 if (dfw < 2) {
697 // Could do with some optimizing/caching...
698 QPointArray a( 7*2 );
699 int i, xx, yy;
700 xx = posX;
701 yy = 3 + posY;
702 for ( i=0; i<3; i++ ) {
703 a.setPoint( 2*i, xx, yy );
704 a.setPoint( 2*i+1, xx, yy+2 );
705 xx++; yy++;
706 }
707 yy -= 2;
708 for ( i=3; i<7; i++ ) {
709 a.setPoint( 2*i, xx, yy );
710 a.setPoint( 2*i+1, xx, yy+2 );
711 xx++; yy--;
712 }
713 if ( ! (flags & Style_Enabled) && ! (flags & Style_On) ) {
714 int pnt;
715 p->setPen( cg.highlightedText() );
716 QPoint offset(1,1);
717 for ( pnt = 0; pnt < (int)a.size(); pnt++ )
718 a[pnt] += offset;
719 p->drawLineSegments( a );
720 for ( pnt = 0; pnt < (int)a.size(); pnt++ )
721 a[pnt] -= offset;
722 }
723 p->setPen( cg.text() );
724 p->drawLineSegments( a );
725
726 qDrawShadePanel( p, posX-2, posY-2, markW+4, markH+6, cg, TRUE, dfw);
727 } else
728 qDrawShadePanel( p, posX, posY, markW, markH, cg, TRUE, dfw,
729 &cg.brush( QColorGroup::Mid ) );
730
731 break;
732 }
733
734 case PE_ScrollBarSubLine:
735 drawPrimitive(((flags & Style_Horizontal) ? PE_ArrowLeft : PE_ArrowUp),
736 p, r, cg, Style_Enabled | flags);
737 break;
738
739 case PE_ScrollBarAddLine:
740 drawPrimitive(((flags & Style_Horizontal) ? PE_ArrowRight : PE_ArrowDown),
741 p, r, cg, Style_Enabled | flags);
742 break;
743
744 case PE_ScrollBarSubPage:
745 case PE_ScrollBarAddPage:
746 p->fillRect(r, cg.brush(QColorGroup::Mid));
747 break;
748
749 case PE_ScrollBarSlider:
750 drawPrimitive(PE_ButtonBevel, p, r, cg,
751 (flags | Style_Raised) & ~Style_Down);
752 break;
753
754 case PE_ProgressBarChunk:
755 p->fillRect( r.x(), r.y() + 2, r.width() - 2,
756 r.height() - 4, cg.brush(QColorGroup::Highlight));
757 break;
758
759 default:
760 QCommonStyle::drawPrimitive( pe, p, r, cg, flags, opt );
761 break;
762 }
763}
764
765
766/*!\reimp
767*/
768void QMotifStyle::drawControl( ControlElement element,
769 QPainter *p,
770 const QWidget *widget,
771 const QRect &r,
772 const QColorGroup &cg,
773 SFlags flags,
774 const QStyleOption& opt ) const
775{
776 switch( element ) {
777 case CE_PushButton:
778 {
779#ifndef QT_NO_PUSHBUTTON
780 int diw, x1, y1, x2, y2;
781 const QPushButton *btn;
782 QColorGroup newCg = cg;
783 btn = ( const QPushButton * )widget;
784 p->setPen( cg.foreground() );
785 p->setBrush( QBrush( cg.button(), NoBrush ) );
786 diw = pixelMetric( PM_ButtonDefaultIndicator );
787 r.coords( &x1, &y1, &x2, &y2 );
788 if ( btn->isDefault() || btn->autoDefault() ) {
789 x1 += diw;
790 y1 += diw;
791 x2 -= diw;
792 y2 -= diw;
793 }
794 QBrush fill;
795 if ( btn->isDown() )
796 fill = newCg.brush( QColorGroup::Mid );
797 else if ( btn->isOn() )
798 fill = QBrush( newCg.mid(), Dense4Pattern );
799 else
800 fill = newCg.brush( QColorGroup::Button );
801
802 newCg.setBrush( QColorGroup::Button, fill );
803 if ( btn->isDefault() ) {
804 if ( diw == 0 ) {
805 QPointArray a;
806 a.setPoints( 9,
807 x1, y1, x2, y1, x2, y2, x1, y2, x1, y1+1,
808 x2-1, y1+1, x2-1, y2-1, x1+1, y2-1, x1+1, y1+1 );
809 p->setPen( newCg.shadow() );
810 p->drawPolygon( a );
811 x1 += 2;
812 y1 += 2;
813 x2 -= 2;
814 y2 -= 2;
815 } else {
816 qDrawShadePanel( p, r, newCg, TRUE );
817 }
818 }
819 if ( !btn->isFlat() || btn->isOn() || btn->isDown() ) {
820 QRect tmp( x1, y1, x2 - x1 + 1, y2 - y1 + 1 );
821 SFlags flags = Style_Default;
822 if ( btn->isOn())
823 flags |= Style_On;
824 if (btn->isDown())
825 flags |= Style_Down;
826 p->save();
827 p->setBrushOrigin( -widget->backgroundOffset().x(),
828 -widget->backgroundOffset().y() );
829 drawPrimitive( PE_ButtonCommand, p,
830 tmp, newCg,
831 flags );
832 p->restore();
833 }
834 if ( p->brush().style() != NoBrush )
835 p->setBrush( NoBrush );
836#endif
837 break;
838 }
839
840 case CE_TabBarTab:
841 {
842#ifndef QT_NO_TABBAR
843 if ( !widget || !widget->parentWidget() || !opt.tab() )
844 break;
845
846 const QTabBar * tb = (const QTabBar *) widget;
847 const QTab * t = opt.tab();
848
849 int dfw = pixelMetric( PM_DefaultFrameWidth, tb );
850 bool selected = flags & Style_Selected;
851 int o = dfw > 1 ? 1 : 0;
852 bool lastTab = FALSE;
853
854 QRect r2( r );
855 if ( tb->shape() == QTabBar::RoundedAbove ) {
856 if ( styleHint( SH_TabBar_Alignment, tb ) == AlignRight &&
857 tb->indexOf( t->identifier() ) == tb->count()-1 )
858 lastTab = TRUE;
859
860 if ( o ) {
861 p->setPen( tb->colorGroup().light() );
862 p->drawLine( r2.left(), r2.bottom(), r2.right(), r2.bottom() );
863 p->setPen( tb->colorGroup().light() );
864 p->drawLine( r2.left(), r2.bottom()-1, r2.right(), r2.bottom()-1 );
865 if ( r2.left() == 0 )
866 p->drawPoint( tb->rect().bottomLeft() );
867 }
868 else {
869 p->setPen( tb->colorGroup().light() );
870 p->drawLine( r2.left(), r2.bottom(), r2.right(), r2.bottom() );
871 }
872
873 if ( selected ) {
874 p->fillRect( QRect( r2.left()+1, r2.bottom()-o, r2.width()-3, 2),
875 tb->palette().active().brush( QColorGroup::Background ));
876 p->setPen( tb->colorGroup().background() );
877 // p->drawLine( r2.left()+1, r2.bottom(), r2.right()-2, r2.bottom() );
878 // if (o)
879 // p->drawLine( r2.left()+1, r2.bottom()-1, r2.right()-2, r2.bottom()-1 );
880 p->drawLine( r2.left()+1, r2.bottom(), r2.left()+1, r2.top()+2 );
881 p->setPen( tb->colorGroup().light() );
882 } else {
883 p->setPen( tb->colorGroup().light() );
884 r2.setRect( r2.left() + 2, r2.top() + 2,
885 r2.width() - 4, r2.height() - 2 );
886 }
887
888 p->drawLine( r2.left(), r2.bottom()-1, r2.left(), r2.top() + 2 );
889 p->drawPoint( r2.left()+1, r2.top() + 1 );
890 p->drawLine( r2.left()+2, r2.top(),
891 r2.right() - 2, r2.top() );
892 p->drawPoint( r2.left(), r2.bottom());
893
894 if ( o ) {
895 p->drawLine( r2.left()+1, r2.bottom(), r2.left()+1, r2.top() + 2 );
896 p->drawLine( r2.left()+2, r2.top()+1,
897 r2.right() - 2, r2.top()+1 );
898 }
899
900 p->setPen( tb->colorGroup().dark() );
901 p->drawLine( r2.right() - 1, r2.top() + 2,
902 r2.right() - 1, r2.bottom() - 1 + (selected ? o : -o));
903 if ( o ) {
904 p->drawPoint( r2.right() - 1, r2.top() + 1 );
905 p->drawLine( r2.right(), r2.top() + 2, r2.right(),
906 r2.bottom() -
907 (selected ? (lastTab ? 0:1):1+o));
908 p->drawPoint( r2.right() - 1, r2.top() + 1 );
909 }
910 } else if ( tb->shape() == QTabBar::RoundedBelow ) {
911 if ( styleHint( SH_TabBar_Alignment, tb ) == AlignLeft &&
912 tb->indexOf( t->identifier() ) == tb->count()-1 )
913 lastTab = TRUE;
914 if ( selected ) {
915 p->fillRect( QRect( r2.left()+1, r2.top(), r2.width()-3, 1),
916 tb->palette().active().brush( QColorGroup::Background ));
917 p->setPen( tb->colorGroup().background() );
918 // p->drawLine( r2.left()+1, r2.top(), r2.right()-2, r2.top() );
919 p->drawLine( r2.left()+1, r2.top(), r2.left()+1, r2.bottom()-2 );
920 p->setPen( tb->colorGroup().dark() );
921 } else {
922 p->setPen( tb->colorGroup().dark() );
923 p->drawLine( r2.left(), r2.top(), r2.right(), r2.top() );
924 p->drawLine( r2.left() + 1, r2.top() + 1,
925 r2.right() - (lastTab ? 0 : 2),
926 r2.top() + 1 );
927 r2.setRect( r2.left() + 2, r2.top(),
928 r2.width() - 4, r2.height() - 2 );
929 }
930
931 p->drawLine( r2.right() - 1, r2.top(),
932 r2.right() - 1, r2.bottom() - 2 );
933 p->drawPoint( r2.right() - 2, r2.bottom() - 2 );
934 p->drawLine( r2.right() - 2, r2.bottom() - 1,
935 r2.left() + 1, r2.bottom() - 1 );
936 p->drawPoint( r2.left() + 1, r2.bottom() - 2 );
937
938 if (dfw > 1) {
939 p->drawLine( r2.right(), r2.top(),
940 r2.right(), r2.bottom() - 1 );
941 p->drawPoint( r2.right() - 1, r2.bottom() - 1 );
942 p->drawLine( r2.right() - 1, r2.bottom(),
943 r2.left() + 2, r2.bottom() );
944 }
945
946 p->setPen( tb->colorGroup().light() );
947 p->drawLine( r2.left(), r2.top() + (selected ? 0 : 2),
948 r2.left(), r2.bottom() - 2 );
949 p->drawLine( r2.left() + 1, r2.top() + (selected ? 0 : 2),
950 r2.left() + 1, r2.bottom() - 3 );
951
952 } else {
953 QCommonStyle::drawControl( element, p, widget, r, cg, flags, opt );
954 }
955#endif
956 break;
957 }
958
959 case CE_ProgressBarGroove:
960 qDrawShadePanel(p, r, cg, TRUE, 2);
961 break;
962
963 case CE_ProgressBarLabel:
964 {
965#ifndef QT_NO_PROGRESSBAR
966 const QProgressBar * pb = (const QProgressBar *) widget;
967 const int unit_width = pixelMetric( PM_ProgressBarChunkWidth, pb );
968 int u = r.width() / unit_width;
969 int p_v = pb->progress();
970 int t_s = pb->totalSteps();
971 if ( u > 0 && pb->progress() >= INT_MAX / u && t_s >= u ) {
972 // scale down to something usable.
973 p_v /= u;
974 t_s /= u;
975 }
976 if ( pb->percentageVisible() && pb->totalSteps() ) {
977 int nu = ( u * p_v + t_s/2 ) / t_s;
978 int x = unit_width * nu;
979 if (pb->indicatorFollowsStyle() || pb->centerIndicator()) {
980 p->setPen( cg.highlightedText() );
981 p->setClipRect( r.x(), r.y(), x, r.height() );
982 p->drawText( r, AlignCenter | SingleLine, pb->progressString() );
983
984 if ( pb->progress() != pb->totalSteps() ) {
985 p->setClipRect( r.x() + x, r.y(), r.width() - x, r.height() );
986 p->setPen( cg.highlight() );
987 p->drawText( r, AlignCenter | SingleLine, pb->progressString() );
988 }
989 } else {
990 p->setPen( cg.text() );
991 p->drawText( r, AlignCenter | SingleLine, pb->progressString() );
992 }
993 }
994#endif
995 break;
996 }
997
998#ifndef QT_NO_POPUPMENU
999 case CE_PopupMenuItem:
1000 {
1001 if (! widget || opt.isDefault())
1002 break;
1003
1004 const QPopupMenu *popupmenu = (const QPopupMenu *) widget;
1005 QMenuItem *mi = opt.menuItem();
1006 if ( !mi )
1007 break;
1008
1009 int tab = opt.tabWidth();
1010 int maxpmw = opt.maxIconWidth();
1011 bool dis = ! (flags & Style_Enabled);
1012 bool checkable = popupmenu->isCheckable();
1013 bool act = flags & Style_Active;
1014 int x, y, w, h;
1015
1016 r.rect(&x, &y, &w, &h);
1017
1018 if ( checkable )
1019 maxpmw = QMAX( maxpmw, motifCheckMarkSpace );
1020
1021 int checkcol = maxpmw;
1022
1023 if ( mi && mi->isSeparator() ) { // draw separator
1024 p->setPen( cg.dark() );
1025 p->drawLine( x, y, x+w, y );
1026 p->setPen( cg.light() );
1027 p->drawLine( x, y+1, x+w, y+1 );
1028 return;
1029 }
1030
1031 int pw = motifItemFrame;
1032
1033 if ( act && !dis ) { // active item frame
1034 if (pixelMetric( PM_DefaultFrameWidth ) > 1)
1035 qDrawShadePanel( p, x, y, w, h, cg, FALSE, pw,
1036 &cg.brush( QColorGroup::Button ) );
1037 else
1038 qDrawShadePanel( p, x+1, y+1, w-2, h-2, cg, TRUE, 1,
1039 &cg.brush( QColorGroup::Button ) );
1040 }
1041 else // incognito frame
1042 p->fillRect(x, y, w, h, cg.brush( QColorGroup::Button ));
1043
1044 if ( !mi )
1045 return;
1046
1047 QRect vrect = visualRect( QRect( x+motifItemFrame, y+motifItemFrame, checkcol, h-2*motifItemFrame ), r );
1048 int xvis = vrect.x();
1049 if ( mi->isChecked() ) {
1050 if ( mi->iconSet() ) {
1051 qDrawShadePanel( p, xvis, y+motifItemFrame, checkcol, h-2*motifItemFrame,
1052 cg, TRUE, 1, &cg.brush( QColorGroup::Midlight ) );
1053 }
1054 } else if ( !act ) {
1055 p->fillRect(xvis, y+motifItemFrame, checkcol, h-2*motifItemFrame,
1056 cg.brush( QColorGroup::Button ));
1057 }
1058
1059 if ( mi->iconSet() ) { // draw iconset
1060 QIconSet::Mode mode = QIconSet::Normal; // no disabled icons in Motif
1061 if (act && !dis )
1062 mode = QIconSet::Active;
1063 QPixmap pixmap;
1064 if ( checkable && mi->isChecked() )
1065 pixmap = mi->iconSet()->pixmap( QIconSet::Small, mode, QIconSet::On );
1066 else
1067 pixmap = mi->iconSet()->pixmap( QIconSet::Small, mode );
1068
1069 int pixw = pixmap.width();
1070 int pixh = pixmap.height();
1071 QRect pmr( 0, 0, pixw, pixh );
1072 pmr.moveCenter( vrect.center() );
1073 p->setPen( cg.text() );
1074 p->drawPixmap( pmr.topLeft(), pixmap );
1075
1076 } else if ( checkable ) { // just "checking"...
1077 int mw = checkcol;
1078 int mh = h - 2*motifItemFrame;
1079 if ( mi->isChecked() ) {
1080 SFlags cflags = Style_Default;
1081 if (! dis)
1082 cflags |= Style_Enabled;
1083 if (act)
1084 cflags |= Style_On;
1085
1086 drawPrimitive(PE_CheckMark, p,
1087 QRect(xvis, y+motifItemFrame, mw, mh),
1088 cg, cflags);
1089 }
1090 }
1091
1092
1093 p->setPen( cg.buttonText() );
1094
1095 QColor discol;
1096 if ( dis ) {
1097 discol = cg.text();
1098 p->setPen( discol );
1099 }
1100
1101 int xm = motifItemFrame + checkcol + motifItemHMargin;
1102
1103 vrect = visualRect( QRect( x+xm, y+motifItemVMargin, w-xm-tab, h-2*motifItemVMargin ), r );
1104 xvis = vrect.x();
1105 if ( mi->custom() ) {
1106 int m = motifItemVMargin;
1107 p->save();
1108 mi->custom()->paint( p, cg, act, !dis,
1109 xvis, y+m, w-xm-tab+1, h-2*m );
1110 p->restore();
1111 }
1112 QString s = mi->text();
1113 if ( !s.isNull() ) { // draw text
1114 int t = s.find( '\t' );
1115 int m = motifItemVMargin;
1116 int text_flags = AlignVCenter|ShowPrefix | DontClip | SingleLine;
1117 text_flags |= (QApplication::reverseLayout() ? AlignRight : AlignLeft );
1118 if ( t >= 0 ) { // draw tab text
1119 QRect vr = visualRect( QRect( x+w-tab-motifItemHMargin-motifItemFrame,
1120 y+motifItemVMargin, tab, h-2*motifItemVMargin ), r );
1121 int xv = vr.x();
1122 p->drawText( xv, y+m, tab, h-2*m, text_flags, s.mid( t+1 ) );
1123 s = s.left( t );
1124 }
1125 p->drawText( xvis, y+m, w-xm-tab+1, h-2*m, text_flags, s, t );
1126 } else if ( mi->pixmap() ) { // draw pixmap
1127 QPixmap *pixmap = mi->pixmap();
1128 if ( pixmap->depth() == 1 )
1129 p->setBackgroundMode( OpaqueMode );
1130 p->drawPixmap( xvis, y+motifItemFrame, *pixmap );
1131 if ( pixmap->depth() == 1 )
1132 p->setBackgroundMode( TransparentMode );
1133 }
1134 if ( mi->popup() ) { // draw sub menu arrow
1135 int dim = (h-2*motifItemFrame) / 2;
1136 QStyle::PrimitiveElement arrow = (QApplication::reverseLayout() ? PE_ArrowLeft : PE_ArrowRight);
1137 QRect vr = visualRect( QRect(x+w - motifArrowHMargin - motifItemFrame - dim,
1138 y+h/2-dim/2, dim, dim), r );
1139 if ( act )
1140 drawPrimitive(arrow, p, vr, cg,
1141 (Style_Down |
1142 (dis ? Style_Default : Style_Enabled)) );
1143 else
1144 drawPrimitive(arrow, p, vr, cg,
1145 (dis ? Style_Default : Style_Enabled));
1146 }
1147
1148 break;
1149 }
1150#endif // QT_NO_POPUPMENU
1151
1152 case CE_MenuBarItem:
1153 {
1154 if ( flags & Style_Active ) // active item
1155 qDrawShadePanel( p, r, cg, FALSE, motifItemFrame,
1156 &cg.brush(QColorGroup::Button) );
1157 else // other item
1158 p->fillRect( r, cg.brush(QColorGroup::Button) );
1159 QCommonStyle::drawControl( element, p, widget, r, cg, flags, opt );
1160 break;
1161 }
1162
1163 default:
1164 QCommonStyle::drawControl( element, p, widget, r, cg, flags, opt );
1165 break;
1166 }
1167}
1168
1169static int get_combo_extra_width( int h, int w, int *return_awh=0 )
1170{
1171 int awh,
1172 tmp;
1173 if ( h < 8 ) {
1174 awh = 6;
1175 } else if ( h < 14 ) {
1176 awh = h - 2;
1177 } else {
1178 awh = h/2;
1179 }
1180 tmp = (awh * 3) / 2;
1181 if ( tmp > w / 2 ) {
1182 awh = w / 2 - 3;
1183 tmp = w / 2 + 3;
1184 }
1185
1186 if ( return_awh )
1187 *return_awh = awh;
1188
1189 return tmp;
1190}
1191
1192static void get_combo_parameters( const QRect &r,
1193 int &ew, int &awh, int &ax,
1194 int &ay, int &sh, int &dh,
1195 int &sy )
1196{
1197 ew = get_combo_extra_width( r.height(), r.width(), &awh );
1198
1199 sh = (awh+3)/4;
1200 if ( sh < 3 )
1201 sh = 3;
1202 dh = sh/2 + 1;
1203
1204 ay = r.y() + (r.height()-awh-sh-dh)/2;
1205 if ( ay < 0 ) {
1206 //panic mode
1207 ay = 0;
1208 sy = r.height();
1209 } else {
1210 sy = ay+awh+dh;
1211 }
1212 ax = r.x() + r.width() - ew;
1213 ax += (ew-awh)/2;
1214}
1215
1216/*!\reimp
1217*/
1218void QMotifStyle::drawComplexControl( ComplexControl control,
1219 QPainter *p,
1220 const QWidget *widget,
1221 const QRect &r,
1222 const QColorGroup &cg,
1223 SFlags flags,
1224 SCFlags sub,
1225 SCFlags subActive,
1226 const QStyleOption& opt ) const
1227{
1228 switch ( control ) {
1229 case CC_SpinWidget: {
1230 SCFlags drawSub = SC_None;
1231 if ( sub & SC_SpinWidgetFrame )
1232 qDrawShadePanel( p, r, cg, TRUE,
1233 pixelMetric( PM_DefaultFrameWidth) );
1234
1235 if ( sub & SC_SpinWidgetUp || sub & SC_SpinWidgetDown ) {
1236 if ( sub & SC_SpinWidgetUp )
1237 drawSub |= SC_SpinWidgetUp;
1238 if ( sub & SC_SpinWidgetDown )
1239 drawSub |= SC_SpinWidgetDown;
1240
1241 QCommonStyle::drawComplexControl( control, p, widget, r, cg, flags,
1242 drawSub, subActive, opt );
1243 }
1244 break; }
1245
1246 case CC_Slider:
1247 {
1248#ifndef QT_NO_SLIDER
1249 const QSlider * slider = (const QSlider *) widget;
1250
1251 QRect groove = querySubControlMetrics(CC_Slider, widget, SC_SliderGroove,
1252 opt),
1253 handle = querySubControlMetrics(CC_Slider, widget, SC_SliderHandle,
1254 opt);
1255
1256 if ((sub & SC_SliderGroove) && groove.isValid()) {
1257 qDrawShadePanel( p, groove, cg, TRUE, 2,
1258 &cg.brush( QColorGroup::Mid ) );
1259
1260
1261 if ( flags & Style_HasFocus ) {
1262 QRect fr = subRect( SR_SliderFocusRect, widget );
1263 drawPrimitive( PE_FocusRect, p, fr, cg );
1264 }
1265 }
1266
1267 if (( sub & SC_SliderHandle ) && handle.isValid()) {
1268 drawPrimitive( PE_ButtonBevel, p, handle, cg );
1269
1270 if ( slider->orientation() == Horizontal ) {
1271 QCOORD mid = handle.x() + handle.width() / 2;
1272 qDrawShadeLine( p, mid, handle.y(), mid,
1273 handle.y() + handle.height() - 2,
1274 cg, TRUE, 1);
1275 } else {
1276 QCOORD mid = handle.y() + handle.height() / 2;
1277 qDrawShadeLine( p, handle.x(), mid,
1278 handle.x() + handle.width() - 2, mid,
1279 cg, TRUE, 1);
1280 }
1281 }
1282
1283 if ( sub & SC_SliderTickmarks )
1284 QCommonStyle::drawComplexControl( control, p, widget, r, cg, flags,
1285 SC_SliderTickmarks, subActive,
1286 opt );
1287#endif
1288 break;
1289 }
1290
1291 case CC_ComboBox:
1292#ifndef QT_NO_COMBOBOX
1293 if ( sub & SC_ComboBoxArrow ) {
1294 const QComboBox * cb = (const QComboBox *) widget;
1295 int awh, ax, ay, sh, sy, dh, ew;
1296 int fw = pixelMetric( PM_DefaultFrameWidth, cb);
1297
1298 drawPrimitive( PE_ButtonCommand, p, r, cg, flags );
1299 QRect ar = QStyle::visualRect( querySubControlMetrics( CC_ComboBox, cb, SC_ComboBoxArrow,
1300 opt ), cb );
1301 drawPrimitive( PE_ArrowDown, p, ar, cg, flags | Style_Enabled );
1302
1303 QRect tr = r;
1304 tr.addCoords( fw, fw, -fw, -fw );
1305 get_combo_parameters( tr, ew, awh, ax, ay, sh, dh, sy );
1306
1307 // draws the shaded line under the arrow
1308 p->setPen( cg.light() );
1309 p->drawLine( ar.x(), sy, ar.x()+awh-1, sy );
1310 p->drawLine( ar.x(), sy, ar.x(), sy+sh-1 );
1311 p->setPen( cg.dark() );
1312 p->drawLine( ar.x()+1, sy+sh-1, ar.x()+awh-1, sy+sh-1 );
1313 p->drawLine( ar.x()+awh-1, sy+1, ar.x()+awh-1, sy+sh-1 );
1314
1315 if ( cb->hasFocus() ) {
1316 QRect re = QStyle::visualRect( subRect( SR_ComboBoxFocusRect, cb ), cb );
1317 drawPrimitive( PE_FocusRect, p, re, cg );
1318 }
1319 }
1320
1321 if ( sub & SC_ComboBoxEditField ) {
1322 QComboBox * cb = (QComboBox *) widget;
1323 if ( cb->editable() ) {
1324 QRect er = QStyle::visualRect( querySubControlMetrics( CC_ComboBox, cb,
1325 SC_ComboBoxEditField ), cb );
1326 er.addCoords( -1, -1, 1, 1);
1327 qDrawShadePanel( p, er, cg, TRUE, 1,
1328 &cg.brush( QColorGroup::Button ));
1329 }
1330 }
1331#endif
1332 p->setPen(cg.buttonText());
1333 break;
1334
1335 case CC_ScrollBar:
1336 {
1337 if (sub == (SC_ScrollBarAddLine | SC_ScrollBarSubLine | SC_ScrollBarAddPage |
1338 SC_ScrollBarSubPage | SC_ScrollBarFirst | SC_ScrollBarLast |
1339 SC_ScrollBarSlider))
1340 qDrawShadePanel(p, widget->rect(), cg, TRUE,
1341 pixelMetric(PM_DefaultFrameWidth, widget),
1342 &cg.brush(QColorGroup::Mid));
1343 QCommonStyle::drawComplexControl(control, p, widget, r, cg, flags, sub,
1344 subActive, opt);
1345 break;
1346 }
1347
1348#ifndef QT_NO_LISTVIEW
1349 case CC_ListView:
1350 {
1351 if ( sub & SC_ListView ) {
1352 QCommonStyle::drawComplexControl( control, p, widget, r, cg, flags, sub, subActive, opt );
1353 }
1354 if ( sub & ( SC_ListViewBranch | SC_ListViewExpand ) ) {
1355 if (opt.isDefault())
1356 break;
1357
1358 QListViewItem *item = opt.listViewItem();
1359 QListViewItem *child = item->firstChild();
1360
1361 int y = r.y();
1362 int c;
1363 QPointArray dotlines;
1364 if ( subActive == (uint)SC_All && sub == SC_ListViewExpand ) {
1365 c = 2;
1366 dotlines.resize(2);
1367 dotlines[0] = QPoint( r.right(), r.top() );
1368 dotlines[1] = QPoint( r.right(), r.bottom() );
1369 } else {
1370 int linetop = 0, linebot = 0;
1371 // each branch needs at most two lines, ie. four end points
1372 dotlines.resize( item->childCount() * 4 );
1373 c = 0;
1374
1375 // skip the stuff above the exposed rectangle
1376 while ( child && y + child->height() <= 0 ) {
1377 y += child->totalHeight();
1378 child = child->nextSibling();
1379 }
1380
1381 int bx = r.width() / 2;
1382
1383 // paint stuff in the magical area
1384 QListView* v = item->listView();
1385 while ( child && y < r.height() ) {
1386 if (child->isVisible()) {
1387 int lh;
1388 if ( !item->multiLinesEnabled() )
1389 lh = child->height();
1390 else
1391 lh = p->fontMetrics().height() + 2 * v->itemMargin();
1392 lh = QMAX( lh, QApplication::globalStrut().height() );
1393 if ( lh % 2 > 0 )
1394 lh++;
1395 linebot = y + lh/2;
1396 if ( (child->isExpandable() || child->childCount()) &&
1397 (child->height() > 0) ) {
1398 // needs a box
1399 p->setPen( cg.text() );
1400 p->drawRect( bx-4, linebot-4, 9, 9 );
1401 QPointArray a;
1402 if ( child->isOpen() )
1403 a.setPoints( 3, bx-2, linebot-2,
1404 bx, linebot+2,
1405 bx+2, linebot-2 ); //RightArrow
1406 else
1407 a.setPoints( 3, bx-2, linebot-2,
1408 bx+2, linebot,
1409 bx-2, linebot+2 ); //DownArrow
1410 p->setBrush( cg.text() );
1411 p->drawPolygon( a );
1412 p->setBrush( NoBrush );
1413 // dotlinery
1414 dotlines[c++] = QPoint( bx, linetop );
1415 dotlines[c++] = QPoint( bx, linebot - 5 );
1416 dotlines[c++] = QPoint( bx + 5, linebot );
1417 dotlines[c++] = QPoint( r.width(), linebot );
1418 linetop = linebot + 5;
1419 } else {
1420 // just dotlinery
1421 dotlines[c++] = QPoint( bx+1, linebot );
1422 dotlines[c++] = QPoint( r.width(), linebot );
1423 }
1424 y += child->totalHeight();
1425 }
1426 child = child->nextSibling();
1427 }
1428
1429 // Expand line height to edge of rectangle if there's any
1430 // visible child below
1431 while ( child && child->height() <= 0)
1432 child = child->nextSibling();
1433 if ( child )
1434 linebot = r.height();
1435
1436 if ( linetop < linebot ) {
1437 dotlines[c++] = QPoint( bx, linetop );
1438 dotlines[c++] = QPoint( bx, linebot );
1439 }
1440 }
1441
1442 int line; // index into dotlines
1443 p->setPen( cg.text() );
1444 if ( sub & SC_ListViewBranch ) for( line = 0; line < c; line += 2 ) {
1445 p->drawLine( dotlines[line].x(), dotlines[line].y(),
1446 dotlines[line+1].x(), dotlines[line+1].y() );
1447 }
1448 }
1449
1450 break;
1451 }
1452#endif // QT_NO_LISTVIEW
1453
1454 default:
1455 QCommonStyle::drawComplexControl( control, p, widget, r, cg, flags,
1456 sub, subActive, opt );
1457 }
1458}
1459
1460
1461/*! \reimp */
1462int QMotifStyle::pixelMetric( PixelMetric metric, const QWidget *widget ) const
1463{
1464 int ret;
1465
1466 switch( metric ) {
1467 case PM_ButtonDefaultIndicator:
1468 ret = 3;
1469 break;
1470
1471 case PM_ButtonShiftHorizontal:
1472 case PM_ButtonShiftVertical:
1473 ret = 0;
1474 break;
1475
1476 case PM_SplitterWidth:
1477 ret = QMAX( 10, QApplication::globalStrut().width() );
1478 break;
1479
1480 case PM_SliderLength:
1481 ret = 30;
1482 break;
1483
1484 case PM_SliderThickness:
1485 ret = 24;
1486 break;
1487
1488 case PM_SliderControlThickness:
1489 {
1490#ifndef QT_NO_SLIDER
1491 const QSlider * sl = (const QSlider *) widget;
1492 int space = (sl->orientation() == Horizontal) ? sl->height()
1493 : sl->width();
1494 int ticks = sl->tickmarks();
1495 int n = 0;
1496 if ( ticks & QSlider::Above ) n++;
1497 if ( ticks & QSlider::Below ) n++;
1498 if ( !n ) {
1499 ret = space;
1500 break;
1501 }
1502
1503 int thick = 6; // Magic constant to get 5 + 16 + 5
1504
1505 space -= thick;
1506 //### the two sides may be unequal in size
1507 if ( space > 0 )
1508 thick += (space * 2) / (n + 2);
1509 ret = thick;
1510#endif
1511 break;
1512 }
1513
1514 case PM_SliderSpaceAvailable:
1515 {
1516#ifndef QT_NO_SLIDER
1517 const QSlider * sl = (const QSlider *) widget;
1518 if ( sl->orientation() == Horizontal )
1519 ret = sl->width() - pixelMetric( PM_SliderLength, sl ) - 6;
1520 else
1521 ret = sl->height() - pixelMetric( PM_SliderLength, sl ) - 6;
1522#endif
1523 break;
1524 }
1525
1526 case PM_DockWindowHandleExtent:
1527 ret = 9;
1528 break;
1529
1530 case PM_ProgressBarChunkWidth:
1531 ret = 1;
1532 break;
1533
1534 case PM_ExclusiveIndicatorWidth:
1535 case PM_ExclusiveIndicatorHeight:
1536 ret = 13;
1537 break;
1538
1539 default:
1540 ret = QCommonStyle::pixelMetric( metric, widget );
1541 break;
1542 }
1543 return ret;
1544}
1545
1546
1547/*!\reimp
1548*/
1549QRect QMotifStyle::querySubControlMetrics( ComplexControl control,
1550 const QWidget *widget,
1551 SubControl sc,
1552 const QStyleOption& opt ) const
1553{
1554 switch ( control ) {
1555 case CC_SpinWidget: {
1556 if ( !widget )
1557 return QRect();
1558 int fw = pixelMetric( PM_SpinBoxFrameWidth, 0 );
1559 QSize bs;
1560 bs.setHeight( widget->height()/2 );
1561 if ( bs.height() < 8 )
1562 bs.setHeight( 8 );
1563 bs.setWidth( QMIN( bs.height() * 8 / 5, widget->width() / 4 ) ); // 1.6 -approximate golden mean
1564 bs = bs.expandedTo( QApplication::globalStrut() );
1565 int y = 0;
1566 int x, lx, rx;
1567 x = widget->width() - y - bs.width();
1568 lx = fw;
1569 rx = x - fw * 2;
1570 switch ( sc ) {
1571 case SC_SpinWidgetUp:
1572 return QRect(x, y, bs.width(), bs.height());
1573 case SC_SpinWidgetDown:
1574 return QRect(x, y + bs.height(), bs.width(), bs.height());
1575 case SC_SpinWidgetButtonField:
1576 return QRect(x, y, bs.width(), widget->height() - 2*fw);
1577 case SC_SpinWidgetEditField:
1578 return QRect(lx, fw, rx, widget->height() - 2*fw);
1579 case SC_SpinWidgetFrame:
1580 return QRect( 0, 0,
1581 widget->width() - bs.width(), widget->height() );
1582 default:
1583 break;
1584 }
1585 break; }
1586
1587#ifndef QT_NO_SLIDER
1588 case CC_Slider: {
1589 if (sc == SC_SliderHandle) {
1590 const QSlider * sl = (const QSlider *) widget;
1591 int tickOffset = pixelMetric( PM_SliderTickmarkOffset, sl );
1592 int thickness = pixelMetric( PM_SliderControlThickness, sl );
1593 int sliderPos = sl->sliderStart();
1594 int len = pixelMetric( PM_SliderLength, sl );
1595 int motifBorder = 3;
1596
1597 if ( sl->orientation() == Horizontal )
1598 return QRect( sliderPos + motifBorder, tickOffset + motifBorder, len,
1599 thickness - 2*motifBorder );
1600 return QRect( tickOffset + motifBorder, sliderPos + motifBorder,
1601 thickness - 2*motifBorder, len );
1602 }
1603 break; }
1604#endif
1605
1606#ifndef QT_NO_SCROLLBAR
1607 case CC_ScrollBar: {
1608 if (! widget)
1609 return QRect();
1610
1611 const QScrollBar *scrollbar = (const QScrollBar *) widget;
1612 int sliderstart = scrollbar->sliderStart();
1613 int sbextent = pixelMetric(PM_ScrollBarExtent, widget);
1614 int fw = pixelMetric(PM_DefaultFrameWidth, widget);
1615 int buttonw = sbextent - (fw * 2);
1616 int buttonh = sbextent - (fw * 2);
1617 int maxlen = ((scrollbar->orientation() == Qt::Horizontal) ?
1618 scrollbar->width() : scrollbar->height()) -
1619 (buttonw * 2) - (fw * 2);
1620 int sliderlen;
1621
1622 // calculate slider length
1623 if (scrollbar->maxValue() != scrollbar->minValue()) {
1624 uint range = scrollbar->maxValue() - scrollbar->minValue();
1625 sliderlen = (scrollbar->pageStep() * maxlen) /
1626 (range + scrollbar->pageStep());
1627
1628 if ( sliderlen < 9 || range > INT_MAX/2 )
1629 sliderlen = 9;
1630 if ( sliderlen > maxlen )
1631 sliderlen = maxlen;
1632 } else
1633 sliderlen = maxlen;
1634
1635 switch (sc) {
1636 case SC_ScrollBarSubLine:
1637 // top/left button
1638 if (scrollbar->orientation() == Qt::Horizontal) {
1639 if ( scrollbar->width()/2 < sbextent )
1640 buttonw = scrollbar->width()/2 - (fw*2);
1641 return QRect(fw, fw, buttonw, buttonh);
1642 } else {
1643 if ( scrollbar->height()/2 < sbextent )
1644 buttonh = scrollbar->height()/2 - (fw*2);
1645 return QRect(fw, fw, buttonw, buttonh);
1646 }
1647 case SC_ScrollBarAddLine:
1648 // bottom/right button
1649 if (scrollbar->orientation() == Qt::Horizontal) {
1650 if ( scrollbar->width()/2 < sbextent )
1651 buttonw = scrollbar->width()/2 - (fw*2);
1652 return QRect(scrollbar->width() - buttonw - fw, fw,
1653 buttonw, buttonh);
1654 } else {
1655 if ( scrollbar->height()/2 < sbextent )
1656 buttonh = scrollbar->height()/2 - (fw*2);
1657 return QRect(fw, scrollbar->height() - buttonh - fw,
1658 buttonw, buttonh);
1659 }
1660 case SC_ScrollBarSubPage:
1661 if (scrollbar->orientation() == Qt::Horizontal)
1662 return QRect(buttonw + fw, fw, sliderstart - buttonw - fw, buttonw);
1663 return QRect(fw, buttonw + fw, buttonw, sliderstart - buttonw - fw);
1664
1665 case SC_ScrollBarAddPage:
1666 if (scrollbar->orientation() == Qt::Horizontal)
1667 return QRect(sliderstart + sliderlen, fw,
1668 maxlen - sliderstart - sliderlen + buttonw + fw, buttonw);
1669 return QRect(fw, sliderstart + sliderlen, buttonw,
1670 maxlen - sliderstart - sliderlen + buttonw + fw);
1671
1672 case SC_ScrollBarGroove:
1673 if (scrollbar->orientation() == Qt::Horizontal)
1674 return QRect(buttonw + fw, fw, maxlen, buttonw);
1675 return QRect(fw, buttonw + fw, buttonw, maxlen);
1676
1677 case SC_ScrollBarSlider:
1678 if (scrollbar->orientation() == Qt::Horizontal)
1679 return QRect(sliderstart, fw, sliderlen, buttonw);
1680 return QRect(fw, sliderstart, buttonw, sliderlen);
1681
1682 default:
1683 break;
1684 }
1685 break; }
1686#endif
1687
1688#ifndef QT_NO_COMBOBOX
1689 case CC_ComboBox:
1690
1691 switch ( sc ) {
1692 case SC_ComboBoxArrow: {
1693 const QComboBox * cb = (const QComboBox *) widget;
1694 int ew, awh, sh, dh, ax, ay, sy;
1695 int fw = pixelMetric( PM_DefaultFrameWidth, cb );
1696 QRect cr = cb->rect();
1697 cr.addCoords( fw, fw, -fw, -fw );
1698 get_combo_parameters( cr, ew, awh, ax, ay, sh, dh, sy );
1699 return QRect( ax, ay, awh, awh ); }
1700
1701 case SC_ComboBoxEditField: {
1702 const QComboBox * cb = (const QComboBox *) widget;
1703 int fw = pixelMetric( PM_DefaultFrameWidth, cb );
1704 QRect rect = cb->rect();
1705 rect.addCoords( fw, fw, -fw, -fw );
1706 int ew = get_combo_extra_width( rect.height(), rect.width() );
1707 rect.addCoords( 1, 1, -1-ew, -1 );
1708 return rect; }
1709
1710 default:
1711 break;
1712 }
1713 break;
1714#endif
1715 default: break;
1716 }
1717 return QCommonStyle::querySubControlMetrics( control, widget, sc, opt );
1718}
1719
1720/*!\reimp
1721*/
1722QSize QMotifStyle::sizeFromContents( ContentsType contents,
1723 const QWidget *widget,
1724 const QSize &contentsSize,
1725 const QStyleOption& opt ) const
1726{
1727 QSize sz(contentsSize);
1728
1729 switch(contents) {
1730 case CT_PushButton:
1731 {
1732#ifndef QT_NO_PUSHBUTTON
1733 const QPushButton *button = (const QPushButton *) widget;
1734 sz = QCommonStyle::sizeFromContents(contents, widget, contentsSize, opt);
1735 if ((button->isDefault() || button->autoDefault()) &&
1736 sz.width() < 80 && ! button->pixmap())
1737 sz.setWidth(80);
1738#endif
1739 break;
1740 }
1741
1742 case CT_PopupMenuItem:
1743 {
1744#ifndef QT_NO_POPUPMENU
1745 if (! widget || opt.isDefault())
1746 break;
1747
1748 const QPopupMenu *popup = (QPopupMenu *) widget;
1749 bool checkable = popup->isCheckable();
1750 QMenuItem *mi = opt.menuItem();
1751 int maxpmw = opt.maxIconWidth();
1752 int w = sz.width(), h = sz.height();
1753
1754 if (mi->custom()) {
1755 w = mi->custom()->sizeHint().width();
1756 h = mi->custom()->sizeHint().height();
1757 if (! mi->custom()->fullSpan())
1758 h += 2*motifItemVMargin + 2*motifItemFrame;
1759 } else if ( mi->widget() ) {
1760 } else if ( mi->isSeparator() ) {
1761 w = 10;
1762 h = motifSepHeight;
1763 } else if (mi->pixmap() || ! mi->text().isNull())
1764 h += 2*motifItemVMargin + 2*motifItemFrame;
1765
1766 // a little bit of border can never harm
1767 w += 2*motifItemHMargin + 2*motifItemFrame;
1768
1769 if ( !mi->text().isNull() && mi->text().find('\t') >= 0 )
1770 // string contains tab
1771 w += motifTabSpacing;
1772 else if (mi->popup())
1773 // submenu indicator needs some room if we don't have a tab column
1774 w += motifArrowHMargin + 4*motifItemFrame;
1775
1776 if ( checkable && maxpmw <= 0)
1777 // if we are checkable and have no iconsets, add space for a checkmark
1778 w += motifCheckMarkSpace;
1779 else if (checkable && maxpmw < motifCheckMarkSpace)
1780 // make sure the check-column is wide enough if we have iconsets
1781 w += (motifCheckMarkSpace - maxpmw);
1782
1783 // if we have a check-column ( iconsets of checkmarks), add space
1784 // to separate the columns
1785 if ( maxpmw > 0 || checkable )
1786 w += motifCheckMarkHMargin;
1787
1788 sz = QSize(w, h);
1789#endif
1790 break;
1791 }
1792
1793 default:
1794 sz = QCommonStyle::sizeFromContents( contents, widget, contentsSize, opt );
1795 break;
1796 }
1797
1798 return sz;
1799}
1800
1801/*!\reimp
1802*/
1803QRect QMotifStyle::subRect( SubRect r, const QWidget *widget ) const
1804{
1805 QRect rect;
1806 QRect wrect = widget->rect();
1807
1808 switch ( r ) {
1809 case SR_SliderFocusRect:
1810 rect = QCommonStyle::subRect( r, widget );
1811 rect.addCoords( 2, 2, -2, -2 );
1812 break;
1813
1814 case SR_ComboBoxFocusRect:
1815 {
1816 int awh, ax, ay, sh, sy, dh, ew;
1817 int fw = pixelMetric( PM_DefaultFrameWidth, widget );
1818 QRect tr = wrect;
1819
1820 tr.addCoords( fw, fw, -fw, -fw );
1821 get_combo_parameters( tr, ew, awh, ax, ay, sh, dh, sy );
1822 rect.setRect(ax-2, ay-2, awh+4, awh+sh+dh+4);
1823 break;
1824 }
1825
1826 case SR_DockWindowHandleRect:
1827 {
1828#ifndef QT_NO_MAINWINDOW
1829 if ( !widget || !widget->parent() )
1830 break;
1831
1832 const QDockWindow * dw = (const QDockWindow *) widget->parent();
1833 if ( !dw->area() || !dw->isCloseEnabled() )
1834 rect.setRect( 0, 0, widget->width(), widget->height() );
1835 else {
1836 if ( dw->area()->orientation() == Horizontal )
1837 rect.setRect(2, 15, widget->width()-2, widget->height() - 15);
1838 else
1839 rect.setRect(0, 2, widget->width() - 15, widget->height() - 2);
1840 }
1841#endif
1842 break;
1843 }
1844
1845 case SR_ProgressBarGroove:
1846 case SR_ProgressBarContents:
1847 {
1848#ifndef QT_NO_PROGRESSBAR
1849 QFontMetrics fm( ( widget ? widget->fontMetrics() :
1850 QApplication::fontMetrics() ) );
1851 const QProgressBar *progressbar = (const QProgressBar *) widget;
1852 int textw = 0;
1853 if (progressbar->percentageVisible())
1854 textw = fm.width("100%") + 6;
1855
1856 if (progressbar->indicatorFollowsStyle() ||
1857 progressbar->centerIndicator())
1858 rect = wrect;
1859 else
1860 rect.setCoords(wrect.left(), wrect.top(),
1861 wrect.right() - textw, wrect.bottom());
1862#endif
1863 break;
1864 }
1865
1866 case SR_ProgressBarLabel:
1867 {
1868#ifndef QT_NO_PROGRESSBAR
1869 QFontMetrics fm( ( widget ? widget->fontMetrics() :
1870 QApplication::fontMetrics() ) );
1871 const QProgressBar *progressbar = (const QProgressBar *) widget;
1872 int textw = 0;
1873 if (progressbar->percentageVisible())
1874 textw = fm.width("100%") + 6;
1875
1876 if (progressbar->indicatorFollowsStyle() ||
1877 progressbar->centerIndicator())
1878 rect = wrect;
1879 else
1880 rect.setCoords(wrect.right() - textw, wrect.top(),
1881 wrect.right(), wrect.bottom());
1882#endif
1883 break;
1884 }
1885
1886 case SR_CheckBoxContents:
1887 {
1888#ifndef QT_NO_CHECKBOX
1889 QRect ir = subRect(SR_CheckBoxIndicator, widget);
1890 rect.setRect(ir.right() + 10, wrect.y(),
1891 wrect.width() - ir.width() - 10, wrect.height());
1892#endif
1893 break;
1894 }
1895
1896 case SR_RadioButtonContents:
1897 {
1898 QRect ir = subRect(SR_RadioButtonIndicator, widget);
1899 rect.setRect(ir.right() + 10, wrect.y(),
1900 wrect.width() - ir.width() - 10, wrect.height());
1901 break;
1902 }
1903
1904 default:
1905 rect = QCommonStyle::subRect( r, widget );
1906 }
1907
1908 return rect;
1909}
1910
1911/*! \reimp
1912*/
1913void QMotifStyle::polishPopupMenu( QPopupMenu* p)
1914{
1915#ifndef QT_NO_POPUPMENU
1916 if ( !p->testWState( WState_Polished ) )
1917 p->setCheckable( FALSE );
1918#endif
1919}
1920
1921
1922#ifndef QT_NO_IMAGEIO_XPM
1923static const char * const qt_close_xpm[] = {
1924"12 12 2 1",
1925" s None c None",
1926". c black",
1927" ",
1928" ",
1929" . . ",
1930" ... ... ",
1931" ...... ",
1932" .... ",
1933" .... ",
1934" ...... ",
1935" ... ... ",
1936" . . ",
1937" ",
1938" "};
1939
1940static const char * const qt_maximize_xpm[] = {
1941"12 12 2 1",
1942" s None c None",
1943". c black",
1944" ",
1945" ",
1946" ",
1947" . ",
1948" ... ",
1949" ..... ",
1950" ....... ",
1951" ......... ",
1952" ",
1953" ",
1954" ",
1955" "};
1956
1957static const char * const qt_minimize_xpm[] = {
1958"12 12 2 1",
1959" s None c None",
1960". c black",
1961" ",
1962" ",
1963" ",
1964" ",
1965" ......... ",
1966" ....... ",
1967" ..... ",
1968" ... ",
1969" . ",
1970" ",
1971" ",
1972" "};
1973
1974#if 0 // ### not used???
1975static const char * const qt_normalize_xpm[] = {
1976"12 12 2 1",
1977" s None c None",
1978". c black",
1979" ",
1980" ",
1981" . ",
1982" .. ",
1983" ... ",
1984" .... ",
1985" ..... ",
1986" ...... ",
1987" ....... ",
1988" ",
1989" ",
1990" "};
1991#endif
1992
1993static const char * const qt_normalizeup_xpm[] = {
1994"12 12 2 1",
1995" s None c None",
1996". c black",
1997" ",
1998" ",
1999" ",
2000" ....... ",
2001" ...... ",
2002" ..... ",
2003" .... ",
2004" ... ",
2005" .. ",
2006" . ",
2007" ",
2008" "};
2009
2010static const char * const qt_shade_xpm[] = {
2011"12 12 2 1", "# c #000000",
2012". c None",
2013"............",
2014"............",
2015".#########..",
2016".#########..",
2017"............",
2018"............",
2019"............",
2020"............",
2021"............",
2022"............",
2023"............",
2024"............"};
2025
2026
2027static const char * const qt_unshade_xpm[] = {
2028"12 12 2 1",
2029"# c #000000",
2030". c None",
2031"............",
2032"............",
2033".#########..",
2034".#########..",
2035".#.......#..",
2036".#.......#..",
2037".#.......#..",
2038".#.......#..",
2039".#.......#..",
2040".#########..",
2041"............",
2042"............"};
2043
2044
2045static const char * dock_window_close_xpm[] = {
2046"8 8 2 1",
2047"# c #000000",
2048". c None",
2049"##....##",
2050".##..##.",
2051"..####..",
2052"...##...",
2053"..####..",
2054".##..##.",
2055"##....##",
2056"........"};
2057
2058// Message box icons, from page 210 of the Windows style guide.
2059
2060// Hand-drawn to resemble Microsoft's icons, but in the Mac/Netscape palette.
2061// Thanks to TrueColor displays, it is slightly more efficient to have
2062// them duplicated.
2063/* XPM */
2064static const char * const information_xpm[]={
2065"32 32 5 1",
2066". c None",
2067"c c #000000",
2068"* c #999999",
2069"a c #ffffff",
2070"b c #0000ff",
2071"...........********.............",
2072"........***aaaaaaaa***..........",
2073"......**aaaaaaaaaaaaaa**........",
2074".....*aaaaaaaaaaaaaaaaaa*.......",
2075"....*aaaaaaaabbbbaaaaaaaac......",
2076"...*aaaaaaaabbbbbbaaaaaaaac.....",
2077"..*aaaaaaaaabbbbbbaaaaaaaaac....",
2078".*aaaaaaaaaaabbbbaaaaaaaaaaac...",
2079".*aaaaaaaaaaaaaaaaaaaaaaaaaac*..",
2080"*aaaaaaaaaaaaaaaaaaaaaaaaaaaac*.",
2081"*aaaaaaaaaabbbbbbbaaaaaaaaaaac*.",
2082"*aaaaaaaaaaaabbbbbaaaaaaaaaaac**",
2083"*aaaaaaaaaaaabbbbbaaaaaaaaaaac**",
2084"*aaaaaaaaaaaabbbbbaaaaaaaaaaac**",
2085"*aaaaaaaaaaaabbbbbaaaaaaaaaaac**",
2086"*aaaaaaaaaaaabbbbbaaaaaaaaaaac**",
2087".*aaaaaaaaaaabbbbbaaaaaaaaaac***",
2088".*aaaaaaaaaaabbbbbaaaaaaaaaac***",
2089"..*aaaaaaaaaabbbbbaaaaaaaaac***.",
2090"...caaaaaaabbbbbbbbbaaaaaac****.",
2091"....caaaaaaaaaaaaaaaaaaaac****..",
2092".....caaaaaaaaaaaaaaaaaac****...",
2093"......ccaaaaaaaaaaaaaacc****....",
2094".......*cccaaaaaaaaccc*****.....",
2095"........***cccaaaac*******......",
2096"..........****caaac*****........",
2097".............*caaac**...........",
2098"...............caac**...........",
2099"................cac**...........",
2100".................cc**...........",
2101"..................***...........",
2102"...................**..........."};
2103/* XPM */
2104static const char* const warning_xpm[]={
2105"32 32 4 1",
2106". c None",
2107"a c #ffff00",
2108"* c #000000",
2109"b c #999999",
2110".............***................",
2111"............*aaa*...............",
2112"...........*aaaaa*b.............",
2113"...........*aaaaa*bb............",
2114"..........*aaaaaaa*bb...........",
2115"..........*aaaaaaa*bb...........",
2116".........*aaaaaaaaa*bb..........",
2117".........*aaaaaaaaa*bb..........",
2118"........*aaaaaaaaaaa*bb.........",
2119"........*aaaa***aaaa*bb.........",
2120".......*aaaa*****aaaa*bb........",
2121".......*aaaa*****aaaa*bb........",
2122"......*aaaaa*****aaaaa*bb.......",
2123"......*aaaaa*****aaaaa*bb.......",
2124".....*aaaaaa*****aaaaaa*bb......",
2125".....*aaaaaa*****aaaaaa*bb......",
2126"....*aaaaaaaa***aaaaaaaa*bb.....",
2127"....*aaaaaaaa***aaaaaaaa*bb.....",
2128"...*aaaaaaaaa***aaaaaaaaa*bb....",
2129"...*aaaaaaaaaa*aaaaaaaaaa*bb....",
2130"..*aaaaaaaaaaa*aaaaaaaaaaa*bb...",
2131"..*aaaaaaaaaaaaaaaaaaaaaaa*bb...",
2132".*aaaaaaaaaaaa**aaaaaaaaaaa*bb..",
2133".*aaaaaaaaaaa****aaaaaaaaaa*bb..",
2134"*aaaaaaaaaaaa****aaaaaaaaaaa*bb.",
2135"*aaaaaaaaaaaaa**aaaaaaaaaaaa*bb.",
2136"*aaaaaaaaaaaaaaaaaaaaaaaaaaa*bbb",
2137"*aaaaaaaaaaaaaaaaaaaaaaaaaaa*bbb",
2138".*aaaaaaaaaaaaaaaaaaaaaaaaa*bbbb",
2139"..*************************bbbbb",
2140"....bbbbbbbbbbbbbbbbbbbbbbbbbbb.",
2141".....bbbbbbbbbbbbbbbbbbbbbbbbb.."};
2142/* XPM */
2143static const char* const critical_xpm[]={
2144"32 32 4 1",
2145". c None",
2146"a c #999999",
2147"* c #ff0000",
2148"b c #ffffff",
2149"...........********.............",
2150".........************...........",
2151".......****************.........",
2152"......******************........",
2153".....********************a......",
2154"....**********************a.....",
2155"...************************a....",
2156"..*******b**********b*******a...",
2157"..******bbb********bbb******a...",
2158".******bbbbb******bbbbb******a..",
2159".*******bbbbb****bbbbb*******a..",
2160"*********bbbbb**bbbbb*********a.",
2161"**********bbbbbbbbbb**********a.",
2162"***********bbbbbbbb***********aa",
2163"************bbbbbb************aa",
2164"************bbbbbb************aa",
2165"***********bbbbbbbb***********aa",
2166"**********bbbbbbbbbb**********aa",
2167"*********bbbbb**bbbbb*********aa",
2168".*******bbbbb****bbbbb*******aa.",
2169".******bbbbb******bbbbb******aa.",
2170"..******bbb********bbb******aaa.",
2171"..*******b**********b*******aa..",
2172"...************************aaa..",
2173"....**********************aaa...",
2174"....a********************aaa....",
2175".....a******************aaa.....",
2176"......a****************aaa......",
2177".......aa************aaaa.......",
2178".........aa********aaaaa........",
2179"...........aaaaaaaaaaa..........",
2180".............aaaaaaa............"};
2181/* XPM */
2182static const char *const question_xpm[] = {
2183"32 32 5 1",
2184". c None",
2185"c c #000000",
2186"* c #999999",
2187"a c #ffffff",
2188"b c #0000ff",
2189"...........********.............",
2190"........***aaaaaaaa***..........",
2191"......**aaaaaaaaaaaaaa**........",
2192".....*aaaaaaaaaaaaaaaaaa*.......",
2193"....*aaaaaaaaaaaaaaaaaaaac......",
2194"...*aaaaaaaabbbbbbaaaaaaaac.....",
2195"..*aaaaaaaabaaabbbbaaaaaaaac....",
2196".*aaaaaaaabbaaaabbbbaaaaaaaac...",
2197".*aaaaaaaabbbbaabbbbaaaaaaaac*..",
2198"*aaaaaaaaabbbbaabbbbaaaaaaaaac*.",
2199"*aaaaaaaaaabbaabbbbaaaaaaaaaac*.",
2200"*aaaaaaaaaaaaabbbbaaaaaaaaaaac**",
2201"*aaaaaaaaaaaaabbbaaaaaaaaaaaac**",
2202"*aaaaaaaaaaaaabbaaaaaaaaaaaaac**",
2203"*aaaaaaaaaaaaabbaaaaaaaaaaaaac**",
2204"*aaaaaaaaaaaaaaaaaaaaaaaaaaaac**",
2205".*aaaaaaaaaaaabbaaaaaaaaaaaac***",
2206".*aaaaaaaaaaabbbbaaaaaaaaaaac***",
2207"..*aaaaaaaaaabbbbaaaaaaaaaac***.",
2208"...caaaaaaaaaabbaaaaaaaaaac****.",
2209"....caaaaaaaaaaaaaaaaaaaac****..",
2210".....caaaaaaaaaaaaaaaaaac****...",
2211"......ccaaaaaaaaaaaaaacc****....",
2212".......*cccaaaaaaaaccc*****.....",
2213"........***cccaaaac*******......",
2214"..........****caaac*****........",
2215".............*caaac**...........",
2216"...............caac**...........",
2217"................cac**...........",
2218".................cc**...........",
2219"..................***...........",
2220"...................**...........",
2221};
2222#endif
2223
2224/*!
2225 \reimp
2226 */
2227QPixmap QMotifStyle::stylePixmap(StylePixmap sp,
2228 const QWidget *widget,
2229 const QStyleOption& opt) const
2230{
2231#ifndef QT_NO_IMAGEIO_XPM
2232 switch (sp) {
2233 case SP_TitleBarShadeButton:
2234 return QPixmap((const char **)qt_shade_xpm);
2235 case SP_TitleBarUnshadeButton:
2236 return QPixmap((const char **)qt_unshade_xpm);
2237 case SP_TitleBarNormalButton:
2238 return QPixmap((const char **)qt_normalizeup_xpm);
2239 case SP_TitleBarMinButton:
2240 return QPixmap((const char **)qt_minimize_xpm);
2241 case SP_TitleBarMaxButton:
2242 return QPixmap((const char **)qt_maximize_xpm);
2243 case SP_TitleBarCloseButton:
2244 return QPixmap((const char **)qt_close_xpm);
2245 case SP_DockWindowCloseButton:
2246 return QPixmap((const char **)dock_window_close_xpm );
2247
2248 case SP_MessageBoxInformation:
2249 case SP_MessageBoxWarning:
2250 case SP_MessageBoxCritical:
2251 case SP_MessageBoxQuestion:
2252 {
2253 const char * const * xpm_data;
2254 switch ( sp ) {
2255 case SP_MessageBoxInformation:
2256 xpm_data = information_xpm;
2257 break;
2258 case SP_MessageBoxWarning:
2259 xpm_data = warning_xpm;
2260 break;
2261 case SP_MessageBoxCritical:
2262 xpm_data = critical_xpm;
2263 break;
2264 case SP_MessageBoxQuestion:
2265 xpm_data = question_xpm;
2266 break;
2267 default:
2268 xpm_data = 0;
2269 break;
2270 }
2271 QPixmap pm;
2272 if ( xpm_data ) {
2273 QImage image( (const char **) xpm_data);
2274 // All that color looks ugly in Motif
2275 QColorGroup g = QApplication::palette().active();
2276 switch ( sp ) {
2277 case SP_MessageBoxInformation:
2278 case SP_MessageBoxQuestion:
2279 image.setColor( 2, 0xff000000 | g.dark().rgb() );
2280 image.setColor( 3, 0xff000000 | g.base().rgb() );
2281 image.setColor( 4, 0xff000000 | g.text().rgb() );
2282 break;
2283 case SP_MessageBoxWarning:
2284 image.setColor( 1, 0xff000000 | g.base().rgb() );
2285 image.setColor( 2, 0xff000000 | g.text().rgb() );
2286 image.setColor( 3, 0xff000000 | g.dark().rgb() );
2287 break;
2288 case SP_MessageBoxCritical:
2289 image.setColor( 1, 0xff000000 | g.dark().rgb() );
2290 image.setColor( 2, 0xff000000 | g.text().rgb() );
2291 image.setColor( 3, 0xff000000 | g.base().rgb() );
2292 break;
2293 default:
2294 break;
2295 }
2296 pm.convertFromImage(image);
2297 }
2298 return pm;
2299 }
2300
2301 default:
2302 break;
2303 }
2304#endif
2305
2306 return QCommonStyle::stylePixmap(sp, widget, opt);
2307}
2308
2309
2310/*! \reimp */
2311int QMotifStyle::styleHint(StyleHint hint,
2312 const QWidget *widget,
2313 const QStyleOption &opt,
2314 QStyleHintReturn *returnData) const
2315{
2316 int ret;
2317
2318 switch (hint) {
2319 case SH_GUIStyle:
2320 ret = MotifStyle;
2321 break;
2322
2323 case SH_ScrollBar_BackgroundMode:
2324 ret = QWidget::PaletteMid;
2325 break;
2326
2327 case SH_ScrollBar_MiddleClickAbsolutePosition:
2328 case SH_Slider_SloppyKeyEvents:
2329 case SH_ProgressDialog_CenterCancelButton:
2330 case SH_PopupMenu_SpaceActivatesItem:
2331 case SH_ScrollView_FrameOnlyAroundContents:
2332 ret = 1;
2333 break;
2334
2335 case SH_PopupMenu_SubMenuPopupDelay:
2336 ret = 96;
2337 break;
2338
2339 case SH_ProgressDialog_TextLabelAlignment:
2340 ret = AlignAuto | AlignVCenter;
2341 break;
2342
2343 case SH_ItemView_ChangeHighlightOnFocus:
2344 ret = 0;
2345 break;
2346
2347 default:
2348 ret = QCommonStyle::styleHint(hint, widget, opt, returnData);
2349 break;
2350 }
2351
2352 return ret;
2353}
2354
2355
2356#endif
Note: See TracBrowser for help on using the repository browser.