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

Last change on this file since 105 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: 67.2 KB
Line 
1/****************************************************************************
2** $Id: qmotifstyle.cpp 8 2005-11-16 19:36:46Z 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
1007 // QPopupMenu has WResizeNoErase and WRepaintNoErase flags, so we
1008 // must erase areas not covered by menu items (this is requested by
1009 // QPopupMenu using 0 as the menu item argument).
1010 // [Win32 version feels ok without this, because it doesn't actually
1011 // fully obey WResizeNoErase and WRepaintNoErase: WM_ERASEBKGND always
1012 // erases the background before WM_PAINT and after every resize].
1013#if !defined (Q_WS_PM)
1014 if ( !mi )
1015 break;
1016#endif
1017
1018 int tab = opt.tabWidth();
1019 int maxpmw = opt.maxIconWidth();
1020 bool dis = ! (flags & Style_Enabled);
1021 bool checkable = popupmenu->isCheckable();
1022 bool act = flags & Style_Active;
1023 int x, y, w, h;
1024
1025 r.rect(&x, &y, &w, &h);
1026
1027 if ( checkable )
1028 maxpmw = QMAX( maxpmw, motifCheckMarkSpace );
1029
1030 int checkcol = maxpmw;
1031
1032 if ( mi && mi->isSeparator() ) { // draw separator
1033 p->setPen( cg.dark() );
1034 p->drawLine( x, y, x+w, y );
1035 p->setPen( cg.light() );
1036 p->drawLine( x, y+1, x+w, y+1 );
1037 return;
1038 }
1039
1040 int pw = motifItemFrame;
1041
1042 if ( act && !dis ) { // active item frame
1043 if (pixelMetric( PM_DefaultFrameWidth ) > 1)
1044 qDrawShadePanel( p, x, y, w, h, cg, FALSE, pw,
1045 &cg.brush( QColorGroup::Button ) );
1046 else
1047 qDrawShadePanel( p, x+1, y+1, w-2, h-2, cg, TRUE, 1,
1048 &cg.brush( QColorGroup::Button ) );
1049 }
1050 else // incognito frame
1051 p->fillRect(x, y, w, h, cg.brush( QColorGroup::Button ));
1052
1053 if ( !mi )
1054 return;
1055
1056 QRect vrect = visualRect( QRect( x+motifItemFrame, y+motifItemFrame, checkcol, h-2*motifItemFrame ), r );
1057 int xvis = vrect.x();
1058 if ( mi->isChecked() ) {
1059 if ( mi->iconSet() ) {
1060 qDrawShadePanel( p, xvis, y+motifItemFrame, checkcol, h-2*motifItemFrame,
1061 cg, TRUE, 1, &cg.brush( QColorGroup::Midlight ) );
1062 }
1063 } else if ( !act ) {
1064 p->fillRect(xvis, y+motifItemFrame, checkcol, h-2*motifItemFrame,
1065 cg.brush( QColorGroup::Button ));
1066 }
1067
1068 if ( mi->iconSet() ) { // draw iconset
1069 QIconSet::Mode mode = QIconSet::Normal; // no disabled icons in Motif
1070 if (act && !dis )
1071 mode = QIconSet::Active;
1072 QPixmap pixmap;
1073 if ( checkable && mi->isChecked() )
1074 pixmap = mi->iconSet()->pixmap( QIconSet::Small, mode, QIconSet::On );
1075 else
1076 pixmap = mi->iconSet()->pixmap( QIconSet::Small, mode );
1077
1078 int pixw = pixmap.width();
1079 int pixh = pixmap.height();
1080 QRect pmr( 0, 0, pixw, pixh );
1081 pmr.moveCenter( vrect.center() );
1082 p->setPen( cg.text() );
1083 p->drawPixmap( pmr.topLeft(), pixmap );
1084
1085 } else if ( checkable ) { // just "checking"...
1086 int mw = checkcol;
1087 int mh = h - 2*motifItemFrame;
1088 if ( mi->isChecked() ) {
1089 SFlags cflags = Style_Default;
1090 if (! dis)
1091 cflags |= Style_Enabled;
1092 if (act)
1093 cflags |= Style_On;
1094
1095 drawPrimitive(PE_CheckMark, p,
1096 QRect(xvis, y+motifItemFrame, mw, mh),
1097 cg, cflags);
1098 }
1099 }
1100
1101
1102 p->setPen( cg.buttonText() );
1103
1104 QColor discol;
1105 if ( dis ) {
1106 discol = cg.text();
1107 p->setPen( discol );
1108 }
1109
1110 int xm = motifItemFrame + checkcol + motifItemHMargin;
1111
1112 vrect = visualRect( QRect( x+xm, y+motifItemVMargin, w-xm-tab, h-2*motifItemVMargin ), r );
1113 xvis = vrect.x();
1114 if ( mi->custom() ) {
1115 int m = motifItemVMargin;
1116 p->save();
1117 mi->custom()->paint( p, cg, act, !dis,
1118 xvis, y+m, w-xm-tab+1, h-2*m );
1119 p->restore();
1120 }
1121 QString s = mi->text();
1122 if ( !s.isNull() ) { // draw text
1123 int t = s.find( '\t' );
1124 int m = motifItemVMargin;
1125 int text_flags = AlignVCenter|ShowPrefix | DontClip | SingleLine;
1126 text_flags |= (QApplication::reverseLayout() ? AlignRight : AlignLeft );
1127 if ( t >= 0 ) { // draw tab text
1128 QRect vr = visualRect( QRect( x+w-tab-motifItemHMargin-motifItemFrame,
1129 y+motifItemVMargin, tab, h-2*motifItemVMargin ), r );
1130 int xv = vr.x();
1131 p->drawText( xv, y+m, tab, h-2*m, text_flags, s.mid( t+1 ) );
1132 s = s.left( t );
1133 }
1134 p->drawText( xvis, y+m, w-xm-tab+1, h-2*m, text_flags, s, t );
1135 } else if ( mi->pixmap() ) { // draw pixmap
1136 QPixmap *pixmap = mi->pixmap();
1137 if ( pixmap->depth() == 1 )
1138 p->setBackgroundMode( OpaqueMode );
1139 p->drawPixmap( xvis, y+motifItemFrame, *pixmap );
1140 if ( pixmap->depth() == 1 )
1141 p->setBackgroundMode( TransparentMode );
1142 }
1143 if ( mi->popup() ) { // draw sub menu arrow
1144 int dim = (h-2*motifItemFrame) / 2;
1145 QStyle::PrimitiveElement arrow = (QApplication::reverseLayout() ? PE_ArrowLeft : PE_ArrowRight);
1146 QRect vr = visualRect( QRect(x+w - motifArrowHMargin - motifItemFrame - dim,
1147 y+h/2-dim/2, dim, dim), r );
1148 if ( act )
1149 drawPrimitive(arrow, p, vr, cg,
1150 (Style_Down |
1151 (dis ? Style_Default : Style_Enabled)) );
1152 else
1153 drawPrimitive(arrow, p, vr, cg,
1154 (dis ? Style_Default : Style_Enabled));
1155 }
1156
1157 break;
1158 }
1159#endif // QT_NO_POPUPMENU
1160
1161 case CE_MenuBarItem:
1162 {
1163 if ( flags & Style_Active ) // active item
1164 qDrawShadePanel( p, r, cg, FALSE, motifItemFrame,
1165 &cg.brush(QColorGroup::Button) );
1166 else // other item
1167 p->fillRect( r, cg.brush(QColorGroup::Button) );
1168 QCommonStyle::drawControl( element, p, widget, r, cg, flags, opt );
1169 break;
1170 }
1171
1172 default:
1173 QCommonStyle::drawControl( element, p, widget, r, cg, flags, opt );
1174 break;
1175 }
1176}
1177
1178static int get_combo_extra_width( int h, int w, int *return_awh=0 )
1179{
1180 int awh,
1181 tmp;
1182 if ( h < 8 ) {
1183 awh = 6;
1184 } else if ( h < 14 ) {
1185 awh = h - 2;
1186 } else {
1187 awh = h/2;
1188 }
1189 tmp = (awh * 3) / 2;
1190 if ( tmp > w / 2 ) {
1191 awh = w / 2 - 3;
1192 tmp = w / 2 + 3;
1193 }
1194
1195 if ( return_awh )
1196 *return_awh = awh;
1197
1198 return tmp;
1199}
1200
1201static void get_combo_parameters( const QRect &r,
1202 int &ew, int &awh, int &ax,
1203 int &ay, int &sh, int &dh,
1204 int &sy )
1205{
1206 ew = get_combo_extra_width( r.height(), r.width(), &awh );
1207
1208 sh = (awh+3)/4;
1209 if ( sh < 3 )
1210 sh = 3;
1211 dh = sh/2 + 1;
1212
1213 ay = r.y() + (r.height()-awh-sh-dh)/2;
1214 if ( ay < 0 ) {
1215 //panic mode
1216 ay = 0;
1217 sy = r.height();
1218 } else {
1219 sy = ay+awh+dh;
1220 }
1221 ax = r.x() + r.width() - ew;
1222 ax += (ew-awh)/2;
1223}
1224
1225/*!\reimp
1226*/
1227void QMotifStyle::drawComplexControl( ComplexControl control,
1228 QPainter *p,
1229 const QWidget *widget,
1230 const QRect &r,
1231 const QColorGroup &cg,
1232 SFlags flags,
1233 SCFlags sub,
1234 SCFlags subActive,
1235 const QStyleOption& opt ) const
1236{
1237 switch ( control ) {
1238 case CC_SpinWidget: {
1239 SCFlags drawSub = SC_None;
1240 if ( sub & SC_SpinWidgetFrame )
1241 qDrawShadePanel( p, r, cg, TRUE,
1242 pixelMetric( PM_DefaultFrameWidth) );
1243
1244 if ( sub & SC_SpinWidgetUp || sub & SC_SpinWidgetDown ) {
1245 if ( sub & SC_SpinWidgetUp )
1246 drawSub |= SC_SpinWidgetUp;
1247 if ( sub & SC_SpinWidgetDown )
1248 drawSub |= SC_SpinWidgetDown;
1249
1250 QCommonStyle::drawComplexControl( control, p, widget, r, cg, flags,
1251 drawSub, subActive, opt );
1252 }
1253 break; }
1254
1255 case CC_Slider:
1256 {
1257#ifndef QT_NO_SLIDER
1258 const QSlider * slider = (const QSlider *) widget;
1259
1260 QRect groove = querySubControlMetrics(CC_Slider, widget, SC_SliderGroove,
1261 opt),
1262 handle = querySubControlMetrics(CC_Slider, widget, SC_SliderHandle,
1263 opt);
1264
1265 if ((sub & SC_SliderGroove) && groove.isValid()) {
1266 qDrawShadePanel( p, groove, cg, TRUE, 2,
1267 &cg.brush( QColorGroup::Mid ) );
1268
1269
1270 if ( flags & Style_HasFocus ) {
1271 QRect fr = subRect( SR_SliderFocusRect, widget );
1272 drawPrimitive( PE_FocusRect, p, fr, cg );
1273 }
1274 }
1275
1276 if (( sub & SC_SliderHandle ) && handle.isValid()) {
1277 drawPrimitive( PE_ButtonBevel, p, handle, cg );
1278
1279 if ( slider->orientation() == Horizontal ) {
1280 QCOORD mid = handle.x() + handle.width() / 2;
1281 qDrawShadeLine( p, mid, handle.y(), mid,
1282 handle.y() + handle.height() - 2,
1283 cg, TRUE, 1);
1284 } else {
1285 QCOORD mid = handle.y() + handle.height() / 2;
1286 qDrawShadeLine( p, handle.x(), mid,
1287 handle.x() + handle.width() - 2, mid,
1288 cg, TRUE, 1);
1289 }
1290 }
1291
1292 if ( sub & SC_SliderTickmarks )
1293 QCommonStyle::drawComplexControl( control, p, widget, r, cg, flags,
1294 SC_SliderTickmarks, subActive,
1295 opt );
1296#endif
1297 break;
1298 }
1299
1300 case CC_ComboBox:
1301#ifndef QT_NO_COMBOBOX
1302 if ( sub & SC_ComboBoxArrow ) {
1303 const QComboBox * cb = (const QComboBox *) widget;
1304 int awh, ax, ay, sh, sy, dh, ew;
1305 int fw = pixelMetric( PM_DefaultFrameWidth, cb);
1306
1307 drawPrimitive( PE_ButtonCommand, p, r, cg, flags );
1308 QRect ar = QStyle::visualRect( querySubControlMetrics( CC_ComboBox, cb, SC_ComboBoxArrow,
1309 opt ), cb );
1310 drawPrimitive( PE_ArrowDown, p, ar, cg, flags | Style_Enabled );
1311
1312 QRect tr = r;
1313 tr.addCoords( fw, fw, -fw, -fw );
1314 get_combo_parameters( tr, ew, awh, ax, ay, sh, dh, sy );
1315
1316 // draws the shaded line under the arrow
1317 p->setPen( cg.light() );
1318 p->drawLine( ar.x(), sy, ar.x()+awh-1, sy );
1319 p->drawLine( ar.x(), sy, ar.x(), sy+sh-1 );
1320 p->setPen( cg.dark() );
1321 p->drawLine( ar.x()+1, sy+sh-1, ar.x()+awh-1, sy+sh-1 );
1322 p->drawLine( ar.x()+awh-1, sy+1, ar.x()+awh-1, sy+sh-1 );
1323
1324 if ( cb->hasFocus() ) {
1325 QRect re = QStyle::visualRect( subRect( SR_ComboBoxFocusRect, cb ), cb );
1326 drawPrimitive( PE_FocusRect, p, re, cg );
1327 }
1328 }
1329
1330 if ( sub & SC_ComboBoxEditField ) {
1331 QComboBox * cb = (QComboBox *) widget;
1332 if ( cb->editable() ) {
1333 QRect er = QStyle::visualRect( querySubControlMetrics( CC_ComboBox, cb,
1334 SC_ComboBoxEditField ), cb );
1335 er.addCoords( -1, -1, 1, 1);
1336 qDrawShadePanel( p, er, cg, TRUE, 1,
1337 &cg.brush( QColorGroup::Button ));
1338 }
1339 }
1340#endif
1341 p->setPen(cg.buttonText());
1342 break;
1343
1344 case CC_ScrollBar:
1345 {
1346 if (sub == (SC_ScrollBarAddLine | SC_ScrollBarSubLine | SC_ScrollBarAddPage |
1347 SC_ScrollBarSubPage | SC_ScrollBarFirst | SC_ScrollBarLast |
1348 SC_ScrollBarSlider))
1349 qDrawShadePanel(p, widget->rect(), cg, TRUE,
1350 pixelMetric(PM_DefaultFrameWidth, widget),
1351 &cg.brush(QColorGroup::Mid));
1352 QCommonStyle::drawComplexControl(control, p, widget, r, cg, flags, sub,
1353 subActive, opt);
1354 break;
1355 }
1356
1357#ifndef QT_NO_LISTVIEW
1358 case CC_ListView:
1359 {
1360 if ( sub & SC_ListView ) {
1361 QCommonStyle::drawComplexControl( control, p, widget, r, cg, flags, sub, subActive, opt );
1362 }
1363 if ( sub & ( SC_ListViewBranch | SC_ListViewExpand ) ) {
1364 if (opt.isDefault())
1365 break;
1366
1367 QListViewItem *item = opt.listViewItem();
1368 QListViewItem *child = item->firstChild();
1369
1370 int y = r.y();
1371 int c;
1372 QPointArray dotlines;
1373 if ( subActive == (uint)SC_All && sub == SC_ListViewExpand ) {
1374 c = 2;
1375 dotlines.resize(2);
1376 dotlines[0] = QPoint( r.right(), r.top() );
1377 dotlines[1] = QPoint( r.right(), r.bottom() );
1378 } else {
1379 int linetop = 0, linebot = 0;
1380 // each branch needs at most two lines, ie. four end points
1381 dotlines.resize( item->childCount() * 4 );
1382 c = 0;
1383
1384 // skip the stuff above the exposed rectangle
1385 while ( child && y + child->height() <= 0 ) {
1386 y += child->totalHeight();
1387 child = child->nextSibling();
1388 }
1389
1390 int bx = r.width() / 2;
1391
1392 // paint stuff in the magical area
1393 QListView* v = item->listView();
1394 while ( child && y < r.height() ) {
1395 if (child->isVisible()) {
1396 int lh;
1397 if ( !item->multiLinesEnabled() )
1398 lh = child->height();
1399 else
1400 lh = p->fontMetrics().height() + 2 * v->itemMargin();
1401 lh = QMAX( lh, QApplication::globalStrut().height() );
1402 if ( lh % 2 > 0 )
1403 lh++;
1404 linebot = y + lh/2;
1405 if ( (child->isExpandable() || child->childCount()) &&
1406 (child->height() > 0) ) {
1407 // needs a box
1408 p->setPen( cg.text() );
1409 p->drawRect( bx-4, linebot-4, 9, 9 );
1410 QPointArray a;
1411 if ( child->isOpen() )
1412 a.setPoints( 3, bx-2, linebot-2,
1413 bx, linebot+2,
1414 bx+2, linebot-2 ); //RightArrow
1415 else
1416 a.setPoints( 3, bx-2, linebot-2,
1417 bx+2, linebot,
1418 bx-2, linebot+2 ); //DownArrow
1419 p->setBrush( cg.text() );
1420 p->drawPolygon( a );
1421 p->setBrush( NoBrush );
1422 // dotlinery
1423 dotlines[c++] = QPoint( bx, linetop );
1424 dotlines[c++] = QPoint( bx, linebot - 5 );
1425 dotlines[c++] = QPoint( bx + 5, linebot );
1426 dotlines[c++] = QPoint( r.width(), linebot );
1427 linetop = linebot + 5;
1428 } else {
1429 // just dotlinery
1430 dotlines[c++] = QPoint( bx+1, linebot );
1431 dotlines[c++] = QPoint( r.width(), linebot );
1432 }
1433 y += child->totalHeight();
1434 }
1435 child = child->nextSibling();
1436 }
1437
1438 // Expand line height to edge of rectangle if there's any
1439 // visible child below
1440 while ( child && child->height() <= 0)
1441 child = child->nextSibling();
1442 if ( child )
1443 linebot = r.height();
1444
1445 if ( linetop < linebot ) {
1446 dotlines[c++] = QPoint( bx, linetop );
1447 dotlines[c++] = QPoint( bx, linebot );
1448 }
1449 }
1450
1451 int line; // index into dotlines
1452 p->setPen( cg.text() );
1453 if ( sub & SC_ListViewBranch ) for( line = 0; line < c; line += 2 ) {
1454 p->drawLine( dotlines[line].x(), dotlines[line].y(),
1455 dotlines[line+1].x(), dotlines[line+1].y() );
1456 }
1457 }
1458
1459 break;
1460 }
1461#endif // QT_NO_LISTVIEW
1462
1463 default:
1464 QCommonStyle::drawComplexControl( control, p, widget, r, cg, flags,
1465 sub, subActive, opt );
1466 }
1467}
1468
1469
1470/*! \reimp */
1471int QMotifStyle::pixelMetric( PixelMetric metric, const QWidget *widget ) const
1472{
1473 int ret;
1474
1475 switch( metric ) {
1476 case PM_ButtonDefaultIndicator:
1477 ret = 3;
1478 break;
1479
1480 case PM_ButtonShiftHorizontal:
1481 case PM_ButtonShiftVertical:
1482 ret = 0;
1483 break;
1484
1485 case PM_SplitterWidth:
1486 ret = QMAX( 10, QApplication::globalStrut().width() );
1487 break;
1488
1489 case PM_SliderLength:
1490 ret = 30;
1491 break;
1492
1493 case PM_SliderThickness:
1494 ret = 24;
1495 break;
1496
1497 case PM_SliderControlThickness:
1498 {
1499#ifndef QT_NO_SLIDER
1500 const QSlider * sl = (const QSlider *) widget;
1501 int space = (sl->orientation() == Horizontal) ? sl->height()
1502 : sl->width();
1503 int ticks = sl->tickmarks();
1504 int n = 0;
1505 if ( ticks & QSlider::Above ) n++;
1506 if ( ticks & QSlider::Below ) n++;
1507 if ( !n ) {
1508 ret = space;
1509 break;
1510 }
1511
1512 int thick = 6; // Magic constant to get 5 + 16 + 5
1513
1514 space -= thick;
1515 //### the two sides may be unequal in size
1516 if ( space > 0 )
1517 thick += (space * 2) / (n + 2);
1518 ret = thick;
1519#endif
1520 break;
1521 }
1522
1523 case PM_SliderSpaceAvailable:
1524 {
1525#ifndef QT_NO_SLIDER
1526 const QSlider * sl = (const QSlider *) widget;
1527 if ( sl->orientation() == Horizontal )
1528 ret = sl->width() - pixelMetric( PM_SliderLength, sl ) - 6;
1529 else
1530 ret = sl->height() - pixelMetric( PM_SliderLength, sl ) - 6;
1531#endif
1532 break;
1533 }
1534
1535 case PM_DockWindowHandleExtent:
1536 ret = 9;
1537 break;
1538
1539 case PM_ProgressBarChunkWidth:
1540 ret = 1;
1541 break;
1542
1543 case PM_ExclusiveIndicatorWidth:
1544 case PM_ExclusiveIndicatorHeight:
1545 ret = 13;
1546 break;
1547
1548 default:
1549 ret = QCommonStyle::pixelMetric( metric, widget );
1550 break;
1551 }
1552 return ret;
1553}
1554
1555
1556/*!\reimp
1557*/
1558QRect QMotifStyle::querySubControlMetrics( ComplexControl control,
1559 const QWidget *widget,
1560 SubControl sc,
1561 const QStyleOption& opt ) const
1562{
1563 switch ( control ) {
1564 case CC_SpinWidget: {
1565 if ( !widget )
1566 return QRect();
1567 int fw = pixelMetric( PM_SpinBoxFrameWidth, 0 );
1568 QSize bs;
1569 bs.setHeight( widget->height()/2 );
1570 if ( bs.height() < 8 )
1571 bs.setHeight( 8 );
1572 bs.setWidth( QMIN( bs.height() * 8 / 5, widget->width() / 4 ) ); // 1.6 -approximate golden mean
1573 bs = bs.expandedTo( QApplication::globalStrut() );
1574 int y = 0;
1575 int x, lx, rx;
1576 x = widget->width() - y - bs.width();
1577 lx = fw;
1578 rx = x - fw * 2;
1579 switch ( sc ) {
1580 case SC_SpinWidgetUp:
1581 return QRect(x, y, bs.width(), bs.height());
1582 case SC_SpinWidgetDown:
1583 return QRect(x, y + bs.height(), bs.width(), bs.height());
1584 case SC_SpinWidgetButtonField:
1585 return QRect(x, y, bs.width(), widget->height() - 2*fw);
1586 case SC_SpinWidgetEditField:
1587 return QRect(lx, fw, rx, widget->height() - 2*fw);
1588 case SC_SpinWidgetFrame:
1589 return QRect( 0, 0,
1590 widget->width() - bs.width(), widget->height() );
1591 default:
1592 break;
1593 }
1594 break; }
1595
1596#ifndef QT_NO_SLIDER
1597 case CC_Slider: {
1598 if (sc == SC_SliderHandle) {
1599 const QSlider * sl = (const QSlider *) widget;
1600 int tickOffset = pixelMetric( PM_SliderTickmarkOffset, sl );
1601 int thickness = pixelMetric( PM_SliderControlThickness, sl );
1602 int sliderPos = sl->sliderStart();
1603 int len = pixelMetric( PM_SliderLength, sl );
1604 int motifBorder = 3;
1605
1606 if ( sl->orientation() == Horizontal )
1607 return QRect( sliderPos + motifBorder, tickOffset + motifBorder, len,
1608 thickness - 2*motifBorder );
1609 return QRect( tickOffset + motifBorder, sliderPos + motifBorder,
1610 thickness - 2*motifBorder, len );
1611 }
1612 break; }
1613#endif
1614
1615#ifndef QT_NO_SCROLLBAR
1616 case CC_ScrollBar: {
1617 if (! widget)
1618 return QRect();
1619
1620 const QScrollBar *scrollbar = (const QScrollBar *) widget;
1621 int sliderstart = scrollbar->sliderStart();
1622 int sbextent = pixelMetric(PM_ScrollBarExtent, widget);
1623 int fw = pixelMetric(PM_DefaultFrameWidth, widget);
1624 int buttonw = sbextent - (fw * 2);
1625 int buttonh = sbextent - (fw * 2);
1626 int maxlen = ((scrollbar->orientation() == Qt::Horizontal) ?
1627 scrollbar->width() : scrollbar->height()) -
1628 (buttonw * 2) - (fw * 2);
1629 int sliderlen;
1630
1631 // calculate slider length
1632 if (scrollbar->maxValue() != scrollbar->minValue()) {
1633 uint range = scrollbar->maxValue() - scrollbar->minValue();
1634 sliderlen = (scrollbar->pageStep() * maxlen) /
1635 (range + scrollbar->pageStep());
1636
1637 if ( sliderlen < 9 || range > INT_MAX/2 )
1638 sliderlen = 9;
1639 if ( sliderlen > maxlen )
1640 sliderlen = maxlen;
1641 } else
1642 sliderlen = maxlen;
1643
1644 switch (sc) {
1645 case SC_ScrollBarSubLine:
1646 // top/left button
1647 if (scrollbar->orientation() == Qt::Horizontal) {
1648 if ( scrollbar->width()/2 < sbextent )
1649 buttonw = scrollbar->width()/2 - (fw*2);
1650 return QRect(fw, fw, buttonw, buttonh);
1651 } else {
1652 if ( scrollbar->height()/2 < sbextent )
1653 buttonh = scrollbar->height()/2 - (fw*2);
1654 return QRect(fw, fw, buttonw, buttonh);
1655 }
1656 case SC_ScrollBarAddLine:
1657 // bottom/right button
1658 if (scrollbar->orientation() == Qt::Horizontal) {
1659 if ( scrollbar->width()/2 < sbextent )
1660 buttonw = scrollbar->width()/2 - (fw*2);
1661 return QRect(scrollbar->width() - buttonw - fw, fw,
1662 buttonw, buttonh);
1663 } else {
1664 if ( scrollbar->height()/2 < sbextent )
1665 buttonh = scrollbar->height()/2 - (fw*2);
1666 return QRect(fw, scrollbar->height() - buttonh - fw,
1667 buttonw, buttonh);
1668 }
1669 case SC_ScrollBarSubPage:
1670 if (scrollbar->orientation() == Qt::Horizontal)
1671 return QRect(buttonw + fw, fw, sliderstart - buttonw - fw, buttonw);
1672 return QRect(fw, buttonw + fw, buttonw, sliderstart - buttonw - fw);
1673
1674 case SC_ScrollBarAddPage:
1675 if (scrollbar->orientation() == Qt::Horizontal)
1676 return QRect(sliderstart + sliderlen, fw,
1677 maxlen - sliderstart - sliderlen + buttonw + fw, buttonw);
1678 return QRect(fw, sliderstart + sliderlen, buttonw,
1679 maxlen - sliderstart - sliderlen + buttonw + fw);
1680
1681 case SC_ScrollBarGroove:
1682 if (scrollbar->orientation() == Qt::Horizontal)
1683 return QRect(buttonw + fw, fw, maxlen, buttonw);
1684 return QRect(fw, buttonw + fw, buttonw, maxlen);
1685
1686 case SC_ScrollBarSlider:
1687 if (scrollbar->orientation() == Qt::Horizontal)
1688 return QRect(sliderstart, fw, sliderlen, buttonw);
1689 return QRect(fw, sliderstart, buttonw, sliderlen);
1690
1691 default:
1692 break;
1693 }
1694 break; }
1695#endif
1696
1697#ifndef QT_NO_COMBOBOX
1698 case CC_ComboBox:
1699
1700 switch ( sc ) {
1701 case SC_ComboBoxArrow: {
1702 const QComboBox * cb = (const QComboBox *) widget;
1703 int ew, awh, sh, dh, ax, ay, sy;
1704 int fw = pixelMetric( PM_DefaultFrameWidth, cb );
1705 QRect cr = cb->rect();
1706 cr.addCoords( fw, fw, -fw, -fw );
1707 get_combo_parameters( cr, ew, awh, ax, ay, sh, dh, sy );
1708 return QRect( ax, ay, awh, awh ); }
1709
1710 case SC_ComboBoxEditField: {
1711 const QComboBox * cb = (const QComboBox *) widget;
1712 int fw = pixelMetric( PM_DefaultFrameWidth, cb );
1713 QRect rect = cb->rect();
1714 rect.addCoords( fw, fw, -fw, -fw );
1715 int ew = get_combo_extra_width( rect.height(), rect.width() );
1716 rect.addCoords( 1, 1, -1-ew, -1 );
1717 return rect; }
1718
1719 default:
1720 break;
1721 }
1722 break;
1723#endif
1724 default: break;
1725 }
1726 return QCommonStyle::querySubControlMetrics( control, widget, sc, opt );
1727}
1728
1729/*!\reimp
1730*/
1731QSize QMotifStyle::sizeFromContents( ContentsType contents,
1732 const QWidget *widget,
1733 const QSize &contentsSize,
1734 const QStyleOption& opt ) const
1735{
1736 QSize sz(contentsSize);
1737
1738 switch(contents) {
1739 case CT_PushButton:
1740 {
1741#ifndef QT_NO_PUSHBUTTON
1742 const QPushButton *button = (const QPushButton *) widget;
1743 sz = QCommonStyle::sizeFromContents(contents, widget, contentsSize, opt);
1744 if ((button->isDefault() || button->autoDefault()) &&
1745 sz.width() < 80 && ! button->pixmap())
1746 sz.setWidth(80);
1747#endif
1748 break;
1749 }
1750
1751 case CT_PopupMenuItem:
1752 {
1753#ifndef QT_NO_POPUPMENU
1754 if (! widget || opt.isDefault())
1755 break;
1756
1757 const QPopupMenu *popup = (QPopupMenu *) widget;
1758 bool checkable = popup->isCheckable();
1759 QMenuItem *mi = opt.menuItem();
1760 int maxpmw = opt.maxIconWidth();
1761 int w = sz.width(), h = sz.height();
1762
1763 if (mi->custom()) {
1764 w = mi->custom()->sizeHint().width();
1765 h = mi->custom()->sizeHint().height();
1766 if (! mi->custom()->fullSpan())
1767 h += 2*motifItemVMargin + 2*motifItemFrame;
1768 } else if ( mi->widget() ) {
1769 } else if ( mi->isSeparator() ) {
1770 w = 10;
1771 h = motifSepHeight;
1772 } else if (mi->pixmap() || ! mi->text().isNull())
1773 h += 2*motifItemVMargin + 2*motifItemFrame;
1774
1775 // a little bit of border can never harm
1776 w += 2*motifItemHMargin + 2*motifItemFrame;
1777
1778 if ( !mi->text().isNull() && mi->text().find('\t') >= 0 )
1779 // string contains tab
1780 w += motifTabSpacing;
1781 else if (mi->popup())
1782 // submenu indicator needs some room if we don't have a tab column
1783 w += motifArrowHMargin + 4*motifItemFrame;
1784
1785 if ( checkable && maxpmw <= 0)
1786 // if we are checkable and have no iconsets, add space for a checkmark
1787 w += motifCheckMarkSpace;
1788 else if (checkable && maxpmw < motifCheckMarkSpace)
1789 // make sure the check-column is wide enough if we have iconsets
1790 w += (motifCheckMarkSpace - maxpmw);
1791
1792 // if we have a check-column ( iconsets of checkmarks), add space
1793 // to separate the columns
1794 if ( maxpmw > 0 || checkable )
1795 w += motifCheckMarkHMargin;
1796
1797 sz = QSize(w, h);
1798#endif
1799 break;
1800 }
1801
1802 default:
1803 sz = QCommonStyle::sizeFromContents( contents, widget, contentsSize, opt );
1804 break;
1805 }
1806
1807 return sz;
1808}
1809
1810/*!\reimp
1811*/
1812QRect QMotifStyle::subRect( SubRect r, const QWidget *widget ) const
1813{
1814 QRect rect;
1815 QRect wrect = widget->rect();
1816
1817 switch ( r ) {
1818 case SR_SliderFocusRect:
1819 rect = QCommonStyle::subRect( r, widget );
1820 rect.addCoords( 2, 2, -2, -2 );
1821 break;
1822
1823 case SR_ComboBoxFocusRect:
1824 {
1825 int awh, ax, ay, sh, sy, dh, ew;
1826 int fw = pixelMetric( PM_DefaultFrameWidth, widget );
1827 QRect tr = wrect;
1828
1829 tr.addCoords( fw, fw, -fw, -fw );
1830 get_combo_parameters( tr, ew, awh, ax, ay, sh, dh, sy );
1831 rect.setRect(ax-2, ay-2, awh+4, awh+sh+dh+4);
1832 break;
1833 }
1834
1835 case SR_DockWindowHandleRect:
1836 {
1837#ifndef QT_NO_MAINWINDOW
1838 if ( !widget || !widget->parent() )
1839 break;
1840
1841 const QDockWindow * dw = (const QDockWindow *) widget->parent();
1842 if ( !dw->area() || !dw->isCloseEnabled() )
1843 rect.setRect( 0, 0, widget->width(), widget->height() );
1844 else {
1845 if ( dw->area()->orientation() == Horizontal )
1846 rect.setRect(2, 15, widget->width()-2, widget->height() - 15);
1847 else
1848 rect.setRect(0, 2, widget->width() - 15, widget->height() - 2);
1849 }
1850#endif
1851 break;
1852 }
1853
1854 case SR_ProgressBarGroove:
1855 case SR_ProgressBarContents:
1856 {
1857#ifndef QT_NO_PROGRESSBAR
1858 QFontMetrics fm( ( widget ? widget->fontMetrics() :
1859 QApplication::fontMetrics() ) );
1860 const QProgressBar *progressbar = (const QProgressBar *) widget;
1861 int textw = 0;
1862 if (progressbar->percentageVisible())
1863 textw = fm.width("100%") + 6;
1864
1865 if (progressbar->indicatorFollowsStyle() ||
1866 progressbar->centerIndicator())
1867 rect = wrect;
1868 else
1869 rect.setCoords(wrect.left(), wrect.top(),
1870 wrect.right() - textw, wrect.bottom());
1871#endif
1872 break;
1873 }
1874
1875 case SR_ProgressBarLabel:
1876 {
1877#ifndef QT_NO_PROGRESSBAR
1878 QFontMetrics fm( ( widget ? widget->fontMetrics() :
1879 QApplication::fontMetrics() ) );
1880 const QProgressBar *progressbar = (const QProgressBar *) widget;
1881 int textw = 0;
1882 if (progressbar->percentageVisible())
1883 textw = fm.width("100%") + 6;
1884
1885 if (progressbar->indicatorFollowsStyle() ||
1886 progressbar->centerIndicator())
1887 rect = wrect;
1888 else
1889 rect.setCoords(wrect.right() - textw, wrect.top(),
1890 wrect.right(), wrect.bottom());
1891#endif
1892 break;
1893 }
1894
1895 case SR_CheckBoxContents:
1896 {
1897#ifndef QT_NO_CHECKBOX
1898 QRect ir = subRect(SR_CheckBoxIndicator, widget);
1899 rect.setRect(ir.right() + 10, wrect.y(),
1900 wrect.width() - ir.width() - 10, wrect.height());
1901#endif
1902 break;
1903 }
1904
1905 case SR_RadioButtonContents:
1906 {
1907 QRect ir = subRect(SR_RadioButtonIndicator, widget);
1908 rect.setRect(ir.right() + 10, wrect.y(),
1909 wrect.width() - ir.width() - 10, wrect.height());
1910 break;
1911 }
1912
1913 default:
1914 rect = QCommonStyle::subRect( r, widget );
1915 }
1916
1917 return rect;
1918}
1919
1920/*! \reimp
1921*/
1922void QMotifStyle::polishPopupMenu( QPopupMenu* p)
1923{
1924#ifndef QT_NO_POPUPMENU
1925 if ( !p->testWState( WState_Polished ) )
1926 p->setCheckable( FALSE );
1927#endif
1928}
1929
1930
1931#ifndef QT_NO_IMAGEIO_XPM
1932static const char * const qt_close_xpm[] = {
1933"12 12 2 1",
1934" s None c None",
1935". c black",
1936" ",
1937" ",
1938" . . ",
1939" ... ... ",
1940" ...... ",
1941" .... ",
1942" .... ",
1943" ...... ",
1944" ... ... ",
1945" . . ",
1946" ",
1947" "};
1948
1949static const char * const qt_maximize_xpm[] = {
1950"12 12 2 1",
1951" s None c None",
1952". c black",
1953" ",
1954" ",
1955" ",
1956" . ",
1957" ... ",
1958" ..... ",
1959" ....... ",
1960" ......... ",
1961" ",
1962" ",
1963" ",
1964" "};
1965
1966static const char * const qt_minimize_xpm[] = {
1967"12 12 2 1",
1968" s None c None",
1969". c black",
1970" ",
1971" ",
1972" ",
1973" ",
1974" ......... ",
1975" ....... ",
1976" ..... ",
1977" ... ",
1978" . ",
1979" ",
1980" ",
1981" "};
1982
1983#if 0 // ### not used???
1984static const char * const qt_normalize_xpm[] = {
1985"12 12 2 1",
1986" s None c None",
1987". c black",
1988" ",
1989" ",
1990" . ",
1991" .. ",
1992" ... ",
1993" .... ",
1994" ..... ",
1995" ...... ",
1996" ....... ",
1997" ",
1998" ",
1999" "};
2000#endif
2001
2002static const char * const qt_normalizeup_xpm[] = {
2003"12 12 2 1",
2004" s None c None",
2005". c black",
2006" ",
2007" ",
2008" ",
2009" ....... ",
2010" ...... ",
2011" ..... ",
2012" .... ",
2013" ... ",
2014" .. ",
2015" . ",
2016" ",
2017" "};
2018
2019static const char * const qt_shade_xpm[] = {
2020"12 12 2 1", "# c #000000",
2021". c None",
2022"............",
2023"............",
2024".#########..",
2025".#########..",
2026"............",
2027"............",
2028"............",
2029"............",
2030"............",
2031"............",
2032"............",
2033"............"};
2034
2035
2036static const char * const qt_unshade_xpm[] = {
2037"12 12 2 1",
2038"# c #000000",
2039". c None",
2040"............",
2041"............",
2042".#########..",
2043".#########..",
2044".#.......#..",
2045".#.......#..",
2046".#.......#..",
2047".#.......#..",
2048".#.......#..",
2049".#########..",
2050"............",
2051"............"};
2052
2053
2054static const char * dock_window_close_xpm[] = {
2055"8 8 2 1",
2056"# c #000000",
2057". c None",
2058"##....##",
2059".##..##.",
2060"..####..",
2061"...##...",
2062"..####..",
2063".##..##.",
2064"##....##",
2065"........"};
2066
2067// Message box icons, from page 210 of the Windows style guide.
2068
2069// Hand-drawn to resemble Microsoft's icons, but in the Mac/Netscape palette.
2070// Thanks to TrueColor displays, it is slightly more efficient to have
2071// them duplicated.
2072/* XPM */
2073static const char * const information_xpm[]={
2074"32 32 5 1",
2075". c None",
2076"c c #000000",
2077"* c #999999",
2078"a c #ffffff",
2079"b c #0000ff",
2080"...........********.............",
2081"........***aaaaaaaa***..........",
2082"......**aaaaaaaaaaaaaa**........",
2083".....*aaaaaaaaaaaaaaaaaa*.......",
2084"....*aaaaaaaabbbbaaaaaaaac......",
2085"...*aaaaaaaabbbbbbaaaaaaaac.....",
2086"..*aaaaaaaaabbbbbbaaaaaaaaac....",
2087".*aaaaaaaaaaabbbbaaaaaaaaaaac...",
2088".*aaaaaaaaaaaaaaaaaaaaaaaaaac*..",
2089"*aaaaaaaaaaaaaaaaaaaaaaaaaaaac*.",
2090"*aaaaaaaaaabbbbbbbaaaaaaaaaaac*.",
2091"*aaaaaaaaaaaabbbbbaaaaaaaaaaac**",
2092"*aaaaaaaaaaaabbbbbaaaaaaaaaaac**",
2093"*aaaaaaaaaaaabbbbbaaaaaaaaaaac**",
2094"*aaaaaaaaaaaabbbbbaaaaaaaaaaac**",
2095"*aaaaaaaaaaaabbbbbaaaaaaaaaaac**",
2096".*aaaaaaaaaaabbbbbaaaaaaaaaac***",
2097".*aaaaaaaaaaabbbbbaaaaaaaaaac***",
2098"..*aaaaaaaaaabbbbbaaaaaaaaac***.",
2099"...caaaaaaabbbbbbbbbaaaaaac****.",
2100"....caaaaaaaaaaaaaaaaaaaac****..",
2101".....caaaaaaaaaaaaaaaaaac****...",
2102"......ccaaaaaaaaaaaaaacc****....",
2103".......*cccaaaaaaaaccc*****.....",
2104"........***cccaaaac*******......",
2105"..........****caaac*****........",
2106".............*caaac**...........",
2107"...............caac**...........",
2108"................cac**...........",
2109".................cc**...........",
2110"..................***...........",
2111"...................**..........."};
2112/* XPM */
2113static const char* const warning_xpm[]={
2114"32 32 4 1",
2115". c None",
2116"a c #ffff00",
2117"* c #000000",
2118"b c #999999",
2119".............***................",
2120"............*aaa*...............",
2121"...........*aaaaa*b.............",
2122"...........*aaaaa*bb............",
2123"..........*aaaaaaa*bb...........",
2124"..........*aaaaaaa*bb...........",
2125".........*aaaaaaaaa*bb..........",
2126".........*aaaaaaaaa*bb..........",
2127"........*aaaaaaaaaaa*bb.........",
2128"........*aaaa***aaaa*bb.........",
2129".......*aaaa*****aaaa*bb........",
2130".......*aaaa*****aaaa*bb........",
2131"......*aaaaa*****aaaaa*bb.......",
2132"......*aaaaa*****aaaaa*bb.......",
2133".....*aaaaaa*****aaaaaa*bb......",
2134".....*aaaaaa*****aaaaaa*bb......",
2135"....*aaaaaaaa***aaaaaaaa*bb.....",
2136"....*aaaaaaaa***aaaaaaaa*bb.....",
2137"...*aaaaaaaaa***aaaaaaaaa*bb....",
2138"...*aaaaaaaaaa*aaaaaaaaaa*bb....",
2139"..*aaaaaaaaaaa*aaaaaaaaaaa*bb...",
2140"..*aaaaaaaaaaaaaaaaaaaaaaa*bb...",
2141".*aaaaaaaaaaaa**aaaaaaaaaaa*bb..",
2142".*aaaaaaaaaaa****aaaaaaaaaa*bb..",
2143"*aaaaaaaaaaaa****aaaaaaaaaaa*bb.",
2144"*aaaaaaaaaaaaa**aaaaaaaaaaaa*bb.",
2145"*aaaaaaaaaaaaaaaaaaaaaaaaaaa*bbb",
2146"*aaaaaaaaaaaaaaaaaaaaaaaaaaa*bbb",
2147".*aaaaaaaaaaaaaaaaaaaaaaaaa*bbbb",
2148"..*************************bbbbb",
2149"....bbbbbbbbbbbbbbbbbbbbbbbbbbb.",
2150".....bbbbbbbbbbbbbbbbbbbbbbbbb.."};
2151/* XPM */
2152static const char* const critical_xpm[]={
2153"32 32 4 1",
2154". c None",
2155"a c #999999",
2156"* c #ff0000",
2157"b c #ffffff",
2158"...........********.............",
2159".........************...........",
2160".......****************.........",
2161"......******************........",
2162".....********************a......",
2163"....**********************a.....",
2164"...************************a....",
2165"..*******b**********b*******a...",
2166"..******bbb********bbb******a...",
2167".******bbbbb******bbbbb******a..",
2168".*******bbbbb****bbbbb*******a..",
2169"*********bbbbb**bbbbb*********a.",
2170"**********bbbbbbbbbb**********a.",
2171"***********bbbbbbbb***********aa",
2172"************bbbbbb************aa",
2173"************bbbbbb************aa",
2174"***********bbbbbbbb***********aa",
2175"**********bbbbbbbbbb**********aa",
2176"*********bbbbb**bbbbb*********aa",
2177".*******bbbbb****bbbbb*******aa.",
2178".******bbbbb******bbbbb******aa.",
2179"..******bbb********bbb******aaa.",
2180"..*******b**********b*******aa..",
2181"...************************aaa..",
2182"....**********************aaa...",
2183"....a********************aaa....",
2184".....a******************aaa.....",
2185"......a****************aaa......",
2186".......aa************aaaa.......",
2187".........aa********aaaaa........",
2188"...........aaaaaaaaaaa..........",
2189".............aaaaaaa............"};
2190/* XPM */
2191static const char *const question_xpm[] = {
2192"32 32 5 1",
2193". c None",
2194"c c #000000",
2195"* c #999999",
2196"a c #ffffff",
2197"b c #0000ff",
2198"...........********.............",
2199"........***aaaaaaaa***..........",
2200"......**aaaaaaaaaaaaaa**........",
2201".....*aaaaaaaaaaaaaaaaaa*.......",
2202"....*aaaaaaaaaaaaaaaaaaaac......",
2203"...*aaaaaaaabbbbbbaaaaaaaac.....",
2204"..*aaaaaaaabaaabbbbaaaaaaaac....",
2205".*aaaaaaaabbaaaabbbbaaaaaaaac...",
2206".*aaaaaaaabbbbaabbbbaaaaaaaac*..",
2207"*aaaaaaaaabbbbaabbbbaaaaaaaaac*.",
2208"*aaaaaaaaaabbaabbbbaaaaaaaaaac*.",
2209"*aaaaaaaaaaaaabbbbaaaaaaaaaaac**",
2210"*aaaaaaaaaaaaabbbaaaaaaaaaaaac**",
2211"*aaaaaaaaaaaaabbaaaaaaaaaaaaac**",
2212"*aaaaaaaaaaaaabbaaaaaaaaaaaaac**",
2213"*aaaaaaaaaaaaaaaaaaaaaaaaaaaac**",
2214".*aaaaaaaaaaaabbaaaaaaaaaaaac***",
2215".*aaaaaaaaaaabbbbaaaaaaaaaaac***",
2216"..*aaaaaaaaaabbbbaaaaaaaaaac***.",
2217"...caaaaaaaaaabbaaaaaaaaaac****.",
2218"....caaaaaaaaaaaaaaaaaaaac****..",
2219".....caaaaaaaaaaaaaaaaaac****...",
2220"......ccaaaaaaaaaaaaaacc****....",
2221".......*cccaaaaaaaaccc*****.....",
2222"........***cccaaaac*******......",
2223"..........****caaac*****........",
2224".............*caaac**...........",
2225"...............caac**...........",
2226"................cac**...........",
2227".................cc**...........",
2228"..................***...........",
2229"...................**...........",
2230};
2231#endif
2232
2233/*!
2234 \reimp
2235 */
2236QPixmap QMotifStyle::stylePixmap(StylePixmap sp,
2237 const QWidget *widget,
2238 const QStyleOption& opt) const
2239{
2240#ifndef QT_NO_IMAGEIO_XPM
2241 switch (sp) {
2242 case SP_TitleBarShadeButton:
2243 return QPixmap((const char **)qt_shade_xpm);
2244 case SP_TitleBarUnshadeButton:
2245 return QPixmap((const char **)qt_unshade_xpm);
2246 case SP_TitleBarNormalButton:
2247 return QPixmap((const char **)qt_normalizeup_xpm);
2248 case SP_TitleBarMinButton:
2249 return QPixmap((const char **)qt_minimize_xpm);
2250 case SP_TitleBarMaxButton:
2251 return QPixmap((const char **)qt_maximize_xpm);
2252 case SP_TitleBarCloseButton:
2253 return QPixmap((const char **)qt_close_xpm);
2254 case SP_DockWindowCloseButton:
2255 return QPixmap((const char **)dock_window_close_xpm );
2256
2257 case SP_MessageBoxInformation:
2258 case SP_MessageBoxWarning:
2259 case SP_MessageBoxCritical:
2260 case SP_MessageBoxQuestion:
2261 {
2262 const char * const * xpm_data;
2263 switch ( sp ) {
2264 case SP_MessageBoxInformation:
2265 xpm_data = information_xpm;
2266 break;
2267 case SP_MessageBoxWarning:
2268 xpm_data = warning_xpm;
2269 break;
2270 case SP_MessageBoxCritical:
2271 xpm_data = critical_xpm;
2272 break;
2273 case SP_MessageBoxQuestion:
2274 xpm_data = question_xpm;
2275 break;
2276 default:
2277 xpm_data = 0;
2278 break;
2279 }
2280 QPixmap pm;
2281 if ( xpm_data ) {
2282 QImage image( (const char **) xpm_data);
2283 // All that color looks ugly in Motif
2284 QColorGroup g = QApplication::palette().active();
2285 switch ( sp ) {
2286 case SP_MessageBoxInformation:
2287 case SP_MessageBoxQuestion:
2288 image.setColor( 2, 0xff000000 | g.dark().rgb() );
2289 image.setColor( 3, 0xff000000 | g.base().rgb() );
2290 image.setColor( 4, 0xff000000 | g.text().rgb() );
2291 break;
2292 case SP_MessageBoxWarning:
2293 image.setColor( 1, 0xff000000 | g.base().rgb() );
2294 image.setColor( 2, 0xff000000 | g.text().rgb() );
2295 image.setColor( 3, 0xff000000 | g.dark().rgb() );
2296 break;
2297 case SP_MessageBoxCritical:
2298 image.setColor( 1, 0xff000000 | g.dark().rgb() );
2299 image.setColor( 2, 0xff000000 | g.text().rgb() );
2300 image.setColor( 3, 0xff000000 | g.base().rgb() );
2301 break;
2302 default:
2303 break;
2304 }
2305 pm.convertFromImage(image);
2306 }
2307 return pm;
2308 }
2309
2310 default:
2311 break;
2312 }
2313#endif
2314
2315 return QCommonStyle::stylePixmap(sp, widget, opt);
2316}
2317
2318
2319/*! \reimp */
2320int QMotifStyle::styleHint(StyleHint hint,
2321 const QWidget *widget,
2322 const QStyleOption &opt,
2323 QStyleHintReturn *returnData) const
2324{
2325 int ret;
2326
2327 switch (hint) {
2328 case SH_GUIStyle:
2329 ret = MotifStyle;
2330 break;
2331
2332 case SH_ScrollBar_BackgroundMode:
2333 ret = QWidget::PaletteMid;
2334 break;
2335
2336 case SH_ScrollBar_MiddleClickAbsolutePosition:
2337 case SH_Slider_SloppyKeyEvents:
2338 case SH_ProgressDialog_CenterCancelButton:
2339 case SH_PopupMenu_SpaceActivatesItem:
2340 case SH_ScrollView_FrameOnlyAroundContents:
2341 ret = 1;
2342 break;
2343
2344 case SH_PopupMenu_SubMenuPopupDelay:
2345 ret = 96;
2346 break;
2347
2348 case SH_ProgressDialog_TextLabelAlignment:
2349 ret = AlignAuto | AlignVCenter;
2350 break;
2351
2352 case SH_ItemView_ChangeHighlightOnFocus:
2353 ret = 0;
2354 break;
2355
2356 default:
2357 ret = QCommonStyle::styleHint(hint, widget, opt, returnData);
2358 break;
2359 }
2360
2361 return ret;
2362}
2363
2364
2365#endif
Note: See TracBrowser for help on using the repository browser.