source: trunk/src/styles/qsgistyle.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: 43.2 KB
Line 
1/****************************************************************************
2** $Id: qsgistyle.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 "qsgistyle.h"
39
40#if !defined(QT_NO_STYLE_SGI) || defined(QT_PLUGIN)
41
42#include "qpopupmenu.h"
43#include "qapplication.h"
44#include "qbutton.h"
45#include "qpainter.h"
46#include "qdrawutil.h"
47#include "qpixmap.h"
48#include "qpalette.h"
49#include "qwidget.h"
50#include "qpushbutton.h"
51#include "qscrollbar.h"
52#include "qcombobox.h"
53#include "qslider.h"
54#include "qtextedit.h"
55#include "qtoolbar.h"
56#include "qlineedit.h"
57#include "qmenubar.h"
58#include <limits.h>
59
60#ifndef QT_NO_SLIDER
61struct SliderLastPosition
62{
63 SliderLastPosition() : rect(0,-1,0,-1), slider(0) {}
64 QRect rect;
65 const QSlider* slider;
66};
67#endif
68
69#ifndef QT_NO_SCROLLBAR
70struct ScrollbarLastPosition
71{
72 ScrollbarLastPosition() : rect( 0,-1, 0,-1 ), scrollbar(0) {}
73 QRect rect;
74 const QScrollBar *scrollbar;
75};
76#endif
77
78class QSGIStylePrivate
79{
80public:
81 QSGIStylePrivate()
82 : hotWidget( 0 ), mousePos( -1, -1 )
83 {
84 }
85
86 const QWidget *hotWidget;
87 QPoint mousePos;
88#ifndef QT_NO_SCROLLBAR
89 ScrollbarLastPosition lastScrollbarRect;
90#endif
91#ifndef QT_NO_SLIDER
92 SliderLastPosition lastSliderRect;
93#endif
94};
95
96/*!
97 \class QSGIStyle qsgistyle.h
98 \brief The QSGIStyle class provides SGI/Irix look and feel.
99
100 \ingroup appearance
101
102 This class implements the SGI look and feel. It resembles the
103 SGI/Irix Motif GUI style as closely as QStyle allows.
104*/
105
106/*!
107 Constructs a QSGIStyle.
108
109 If \a useHighlightCols is FALSE (default value), the style will
110 polish the application's color palette to emulate the Motif way of
111 highlighting, which is a simple inversion between the base and the
112 text color.
113
114 \sa QMotifStyle::useHighlightColors()
115*/
116QSGIStyle::QSGIStyle( bool useHighlightCols ) : QMotifStyle( useHighlightCols ), isApplicationStyle( 0 )
117{
118 d = new QSGIStylePrivate;
119}
120
121/*!
122 Destroys the style.
123*/
124QSGIStyle::~QSGIStyle()
125{
126 delete d;
127}
128
129/*!
130 \reimp
131
132 Changes some application-wide settings to be SGI-like, e.g. sets a
133 bold italic font for menu options.
134*/
135void
136QSGIStyle::polish( QApplication* app)
137{
138 isApplicationStyle = 1;
139 QMotifStyle::polish( app );
140
141 QPalette pal = QApplication::palette();
142 // check this on SGI-Boxes
143 //pal.setColor( QColorGroup::Background, pal.active().midlight() );
144 if (pal.active().button() == pal.active().background())
145 pal.setColor( QColorGroup::Button, pal.active().button().dark(120) );
146 // darker basecolor in list-widgets
147 pal.setColor( QColorGroup::Base, pal.active().base().dark(130) );
148 if (! useHighlightColors() ) {
149 pal.setColor( QPalette::Active, QColorGroup::Highlight, pal.active().text() );
150 pal.setColor( QPalette::Active, QColorGroup::HighlightedText, pal.active().base() );
151 pal.setColor( QPalette::Inactive, QColorGroup::Highlight, pal.inactive().text() );
152 pal.setColor( QPalette::Inactive, QColorGroup::HighlightedText, pal.inactive().base() );
153 pal.setColor( QPalette::Disabled, QColorGroup::Highlight, pal.disabled().text() );
154 pal.setColor( QPalette::Disabled, QColorGroup::HighlightedText, pal.disabled().base() );
155 }
156 QApplication::setPalette( pal, TRUE );
157
158 // different basecolor and highlighting in Q(Multi)LineEdit
159 pal.setColor( QColorGroup::Base, QColor(211,181,181) );
160 pal.setColor( QPalette::Active, QColorGroup::Highlight, pal.active().midlight() );
161 pal.setColor( QPalette::Active, QColorGroup::HighlightedText, pal.active().text() );
162 pal.setColor( QPalette::Inactive, QColorGroup::Highlight, pal.inactive().midlight() );
163 pal.setColor( QPalette::Inactive, QColorGroup::HighlightedText, pal.inactive().text() );
164 pal.setColor( QPalette::Disabled, QColorGroup::Highlight, pal.disabled().midlight() );
165 pal.setColor( QPalette::Disabled, QColorGroup::HighlightedText, pal.disabled().text() );
166
167 QApplication::setPalette( pal, TRUE, "QLineEdit" );
168 QApplication::setPalette( pal, TRUE, "QTextEdit" );
169 QApplication::setPalette( pal, TRUE, "QDateTimeEditBase" );
170
171 pal = QApplication::palette();
172 pal.setColor( QColorGroup::Button, pal.active().background() );
173 QApplication::setPalette( pal, TRUE, "QMenuBar" );
174 QApplication::setPalette( pal, TRUE, "QToolBar" );
175 QApplication::setPalette( pal, TRUE, "QPopupMenu" );
176}
177
178/*! \reimp
179*/
180void
181QSGIStyle::unPolish( QApplication* /* app */ )
182{
183 QFont f = QApplication::font();
184 QApplication::setFont( f, TRUE ); // get rid of the special fonts for special widget classes
185}
186
187/*!
188 \reimp
189
190 Installs an event filter for several widget classes to enable
191 hovering.
192*/
193void
194QSGIStyle::polish( QWidget* w )
195{
196 QMotifStyle::polish(w);
197
198 if ( !isApplicationStyle ) {
199 QPalette sgiPal = QApplication::palette();
200
201 sgiPal.setColor( QColorGroup::Background, sgiPal.active().midlight() );
202 if (sgiPal.active().button() == sgiPal.active().background())
203 sgiPal.setColor( QColorGroup::Button, sgiPal.active().button().dark(110) );
204 sgiPal.setColor( QColorGroup::Base, sgiPal.active().base().dark(130) );
205 if (! useHighlightColors() ) {
206 sgiPal.setColor( QPalette::Active, QColorGroup::Highlight, sgiPal.active().text() );
207 sgiPal.setColor( QPalette::Active, QColorGroup::HighlightedText, sgiPal.active().base() );
208 sgiPal.setColor( QPalette::Inactive, QColorGroup::Highlight, sgiPal.inactive().text() );
209 sgiPal.setColor( QPalette::Inactive, QColorGroup::HighlightedText, sgiPal.inactive().base() );
210 sgiPal.setColor( QPalette::Disabled, QColorGroup::Highlight, sgiPal.disabled().text() );
211 sgiPal.setColor( QPalette::Disabled, QColorGroup::HighlightedText, sgiPal.disabled().base() );
212 }
213
214 if ( ::qt_cast<QLineEdit*>(w) || ::qt_cast<QTextEdit*>(w) ) {
215 // different basecolor and highlighting in Q(Multi)LineEdit
216 sgiPal.setColor( QColorGroup::Base, QColor(211,181,181) );
217 sgiPal.setColor( QPalette::Active, QColorGroup::Highlight, sgiPal.active().midlight() );
218 sgiPal.setColor( QPalette::Active, QColorGroup::HighlightedText, sgiPal.active().text() );
219 sgiPal.setColor( QPalette::Inactive, QColorGroup::Highlight, sgiPal.inactive().midlight() );
220 sgiPal.setColor( QPalette::Inactive, QColorGroup::HighlightedText, sgiPal.inactive().text() );
221 sgiPal.setColor( QPalette::Disabled, QColorGroup::Highlight, sgiPal.disabled().midlight() );
222 sgiPal.setColor( QPalette::Disabled, QColorGroup::HighlightedText, sgiPal.disabled().text() );
223
224 } else if ( ::qt_cast<QMenuBar*>(w) || ::qt_cast<QToolBar*>(w) ) {
225 sgiPal.setColor( QColorGroup::Button, sgiPal.active().midlight() );
226 }
227
228 w->setPalette( sgiPal );
229 }
230
231 if ( ::qt_cast<QButton*>(w) || ::qt_cast<QSlider*>(w) || ::qt_cast<QScrollBar*>(w) ) {
232 w->installEventFilter( this );
233 w->setMouseTracking( TRUE );
234#ifndef QT_NO_SCROLLBAR
235 if ( ::qt_cast<QScrollBar*>(w) )
236 w->setBackgroundMode( QWidget::NoBackground );
237#endif
238 } else if ( ::qt_cast<QComboBox*>(w) ) {
239 QFont f = QApplication::font();
240 f.setBold( TRUE );
241 f.setItalic( TRUE );
242 w->setFont( f );
243#ifndef QT_NO_MENUBAR
244 } else if ( ::qt_cast<QMenuBar*>(w) ) {
245 ((QFrame*) w)->setFrameStyle(QFrame::StyledPanel | QFrame::Raised);
246 w->setBackgroundMode( QWidget::PaletteBackground );
247 QFont f = QApplication::font();
248 f.setBold( TRUE );
249 f.setItalic( TRUE );
250 w->setFont( f );
251#endif
252#ifndef QT_NO_POPUPMENU
253 } else if ( ::qt_cast<QPopupMenu*>(w) ) {
254 ((QFrame*) w)->setLineWidth( pixelMetric( PM_DefaultFrameWidth ) + 1 );
255 QFont f = QApplication::font();
256 f.setBold( TRUE );
257 f.setItalic( TRUE );
258 w->setFont( f );
259#endif
260 } else if ( ::qt_cast<QToolBar*>(w) || w->inherits("QToolBarSeparator") ) {
261 w->setBackgroundMode( QWidget::PaletteBackground );
262 }
263}
264
265/*! \reimp */
266void
267QSGIStyle::unPolish( QWidget* w )
268{
269 if ( ::qt_cast<QButton*>(w) || ::qt_cast<QSlider*>(w) || ::qt_cast<QScrollBar*>(w) ) {
270 w->removeEventFilter( this );
271#ifndef QT_NO_POPUPMENU
272 } else if ( ::qt_cast<QPopupMenu*>(w) ) {
273 ((QFrame*)w)->setLineWidth( pixelMetric( PM_DefaultFrameWidth ) );
274 w->setFont( QApplication::font() );
275#endif
276#if !defined(QT_NO_MENUBAR) || !defined(QT_NO_COMBOBOX)
277 } else if ( ::qt_cast<QMenuBar*>(w) || ::qt_cast<QComboBox*>(w) ) {
278 w->setFont( QApplication::font() );
279#endif
280 }
281}
282
283/*! \reimp */
284bool QSGIStyle::eventFilter( QObject* o, QEvent* e )
285{
286 if ( !o->isWidgetType() || e->type() == QEvent::Paint )
287 return QMotifStyle::eventFilter( o, e );
288
289 QWidget *widget = (QWidget*)o;
290
291 switch ( e->type() ) {
292 case QEvent::MouseButtonPress:
293 {
294#ifndef QT_NO_SCROLLBAR
295 if ( ::qt_cast<QScrollBar*>(widget) ) {
296 d->lastScrollbarRect.rect = ((QScrollBar*)widget)->sliderRect();
297 d->lastScrollbarRect.scrollbar = ((QScrollBar*)widget);
298 widget->repaint( FALSE );
299 } else
300#endif
301 {
302#ifndef QT_NO_SLIDER
303 if ( ::qt_cast<QSlider*>(widget) ) {
304 d->lastSliderRect.rect = ((QSlider*)widget)->sliderRect();
305 d->lastSliderRect.slider = ((QSlider*)widget);
306 widget->repaint( FALSE );
307 }
308#endif
309 }
310 }
311 break;
312
313 case QEvent::MouseButtonRelease:
314 {
315 if ( 0 ) {
316#ifndef QT_NO_SCROLLBAR
317 } else if ( ::qt_cast<QScrollBar*>(widget) ) {
318 QRect oldRect = d->lastScrollbarRect.rect;
319 d->lastScrollbarRect.rect = QRect( 0, -1, 0, -1 );
320 widget->repaint( oldRect, FALSE );
321#endif
322#ifndef QT_NO_SLIDER
323 } else if ( ::qt_cast<QSlider*>(widget) ) {
324 QRect oldRect = d->lastSliderRect.rect;
325 d->lastSliderRect.rect = QRect( 0, -1, 0, -1 );
326 widget->repaint( oldRect, FALSE );
327#endif
328 }
329 }
330 break;
331
332 case QEvent::MouseMove:
333 if ( !widget->isActiveWindow() )
334 break;
335 if ( ((QMouseEvent*)e)->button() )
336 break;
337
338 d->hotWidget = widget;
339 d->mousePos = ((QMouseEvent*)e)->pos();
340 widget->repaint( FALSE );
341 break;
342
343 case QEvent::Enter:
344 if ( !widget->isActiveWindow() )
345 break;
346 d->hotWidget = widget;
347 widget->repaint( FALSE );
348 break;
349
350 case QEvent::Leave:
351 if ( !widget->isActiveWindow() )
352 break;
353 if ( widget == d->hotWidget) {
354 d->hotWidget = 0;
355 widget->repaint( FALSE );
356 }
357 break;
358
359 default:
360 break;
361 }
362 return QMotifStyle::eventFilter( o, e );
363}
364
365static const int sgiItemFrame = 2; // menu item frame width
366// static const int sgiSepHeight = 1; // separator item height
367static const int sgiItemHMargin = 3; // menu item hor text margin
368static const int sgiItemVMargin = 2; // menu item ver text margin
369static const int sgiArrowHMargin = 6; // arrow horizontal margin
370static const int sgiTabSpacing = 12; // space between text and tab
371// static const int sgiCheckMarkHMargin = 2; // horiz. margins of check mark ### not used?!?
372static const int sgiCheckMarkSpace = 20;
373
374/*! \reimp */
375int QSGIStyle::pixelMetric( PixelMetric metric, const QWidget *widget ) const
376{
377 switch ( metric ) {
378 case PM_DefaultFrameWidth:
379 return 2;
380
381 case PM_ButtonDefaultIndicator:
382 return 4;
383
384 case PM_ScrollBarExtent:
385 return 21;
386
387 case PM_IndicatorWidth:
388 case PM_IndicatorHeight:
389 return 14;
390
391 case PM_ExclusiveIndicatorWidth:
392 case PM_ExclusiveIndicatorHeight:
393 return 12;
394
395 case PM_SplitterWidth:
396 return QMAX( 10, QApplication::globalStrut().width() );
397
398 default:
399 break;
400 }
401 return QMotifStyle::pixelMetric( metric, widget );
402}
403
404static void drawPanel( QPainter *p, int x, int y, int w, int h,
405 const QColorGroup &g, bool sunken,
406 int lineWidth, const QBrush* fill)
407{
408 if ( w == 0 || h == 0 )
409 return;
410#if defined(CHECK_RANGE)
411 ASSERT( w > 0 && h > 0 && lineWidth >= 0 );
412#endif
413 QPen oldPen = p->pen(); // save pen
414 QPointArray a( 4*lineWidth );
415 if ( sunken )
416 p->setPen( g.dark() );
417 else
418 p->setPen( g.light() );
419 int x1, y1, x2, y2;
420 int i;
421 int n = 0;
422 x1 = x;
423 y1 = y2 = y;
424 x2 = x+w-2;
425 for ( i=0; i<lineWidth; i++ ) { // top shadow
426 a.setPoint( n++, x1, y1++ );
427 a.setPoint( n++, x2--, y2++ );
428 }
429 x2 = x1;
430 y1 = y+h-2;
431 for ( i=0; i<lineWidth; i++ ) { // left shadow
432 a.setPoint( n++, x1++, y1 );
433 a.setPoint( n++, x2++, y2-- );
434 }
435 p->drawLineSegments( a );
436 n = 0;
437 if ( sunken )
438 p->setPen( g.light() );
439 else
440 p->setPen( g.dark() );
441 x1 = x;
442 y1 = y2 = y+h-1;
443 x2 = x+w-1;
444 for ( i=0; i<lineWidth; i++ ) { // bottom shadow
445 a.setPoint( n++, x1++, y1-- );
446 a.setPoint( n++, x2, y2-- );
447 }
448 x1 = x2;
449 y1 = y;
450 y2 = y+h-lineWidth-1;
451 for ( i=0; i<lineWidth; i++ ) { // right shadow
452 a.setPoint( n++, x1--, y1++ );
453 a.setPoint( n++, x2--, y2 );
454 }
455 p->drawLineSegments( a );
456 if ( fill ) { // fill with fill color
457 QBrush oldBrush = p->brush();
458 p->setPen( Qt::NoPen );
459 p->setBrush( *fill );
460 p->drawRect( x+lineWidth, y+lineWidth, w-lineWidth*2, h-lineWidth*2 );
461 p->setBrush( oldBrush );
462 }
463 p->setPen( oldPen ); // restore pen
464}
465
466static void drawSeparator( QPainter *p, int x1, int y1, int x2, int y2,
467 const QColorGroup &g )
468{
469 QPen oldPen = p->pen();
470
471 p->setPen( g.midlight() );
472 p->drawLine( x1, y1, x2, y2 );
473 p->setPen( g.shadow() );
474 if ( y2-y1 < x2-x1 )
475 p->drawLine( x1, y1+1, x2, y2+1 );
476 else
477 p->drawLine( x1+1, y1, x2+1, y2 );
478
479 p->setPen( oldPen );
480}
481
482static void drawSGIPrefix( QPainter *p, int x, int y, QString* miText )
483{
484 if ( miText && (!!(*miText)) ) {
485 int amp = 0;
486 bool nextAmp = FALSE;
487 while ( ( amp = miText->find( '&', amp ) ) != -1 ) {
488 if ( (uint)amp == miText->length()-1 )
489 return;
490 miText->remove( amp,1 );
491 nextAmp = (*miText)[amp] == '&'; // next time if &&
492
493 if ( !nextAmp ) { // draw special underlining
494 uint ulx = p->fontMetrics().width(*miText, amp);
495
496 uint ulw = p->fontMetrics().width(*miText, amp+1) - ulx;
497
498 p->drawLine( x+ulx, y, x+ulx+ulw, y );
499 p->drawLine( x+ulx, y+1, x+ulx+ulw/2, y+1 );
500 p->drawLine( x+ulx, y+2, x+ulx+ulw/4, y+2 );
501 }
502 amp++;
503 }
504 }
505}
506
507static int get_combo_extra_width( int h, int *return_awh=0 )
508{
509 int awh;
510 if ( h < 8 ) {
511 awh = 6;
512 } else if ( h < 14 ) {
513 awh = h - 2;
514 } else {
515 awh = h/2;
516 }
517 if ( return_awh )
518 *return_awh = awh;
519 return awh*2;
520}
521
522static void get_combo_parameters( const QRect &r,
523 int &ew, int &awh, int &ax,
524 int &ay, int &sh, int &dh,
525 int &sy )
526{
527 ew = get_combo_extra_width( r.height(), &awh );
528
529 sh = (awh+3)/4;
530 if ( sh < 3 )
531 sh = 3;
532 dh = sh/2 + 1;
533
534 ay = r.y() + (r.height()-awh-sh-dh)/2;
535 if ( ay < 0 ) {
536 //panic mode
537 ay = 0;
538 sy = r.height();
539 } else {
540 sy = ay+awh+dh;
541 }
542 if( QApplication::reverseLayout() )
543 ax = r.x();
544 else
545 ax = r.x() + r.width() - ew;
546 ax += (ew-awh)/2;
547}
548
549/*! \reimp */
550void QSGIStyle::drawPrimitive( PrimitiveElement pe,
551 QPainter *p,
552 const QRect &r,
553 const QColorGroup &cg,
554 SFlags flags,
555 const QStyleOption& opt ) const
556{
557 const int x = r.x();
558 const int y = r.y();
559 const int w = r.width();
560 const int h = r.height();
561 const bool sunken = flags & ( Style_Sunken | Style_Down | Style_On );
562 const int defaultFrameWidth = pixelMetric( PM_DefaultFrameWidth );
563 bool hot = ( flags & Style_MouseOver ) && ( flags & Style_Enabled );
564
565 switch ( pe ) {
566 case PE_ButtonCommand:
567 {
568 QBrush fill;
569 if ( hot ) {
570 if ( sunken )
571 fill = cg.brush( QColorGroup::Dark );
572 else
573 fill = cg.brush( QColorGroup::Midlight );
574 } else if ( sunken ) {
575 fill = cg.brush( QColorGroup::Mid );
576 } else {
577 fill = cg.brush( QColorGroup::Button );
578 }
579
580 drawPanel( p, x, y, w, h, cg, sunken, defaultFrameWidth, &fill );
581 }
582 break;
583
584 case PE_PanelPopup:
585 case PE_ButtonBevel:
586 case PE_ButtonTool:
587 {
588 drawPrimitive( PE_ButtonCommand, p, QRect( x+1, y+1, w-2, h-2 ), cg, flags, opt );
589
590 QPen oldPen = p->pen();
591 QPointArray a;
592
593 // draw twocolored rectangle
594 p->setPen( sunken ? cg.light() : cg.dark().dark(200) );
595 a.setPoints( 3, x, y+h-1, x+w-1, y+h-1, x+w-1, y );
596 p->drawPolyline( a );
597 p->setPen( cg.dark() );
598 a.setPoints( 3, x, y+h-2, x, y, x+w-2, y );
599 p->drawPolyline( a );
600
601 p->setPen( oldPen );
602 }
603 break;
604
605 case PE_ArrowUp:
606 case PE_ArrowDown:
607 case PE_ArrowLeft:
608 case PE_ArrowRight:
609 {
610 QPointArray a; // arrow polygon
611 switch ( pe ) {
612 case PE_ArrowUp:
613 a.setPoints( 3, 0,-5, -5,4, 4,4 );
614 break;
615 case PE_ArrowDown:
616 a.setPoints( 3, 0,4, -4,-4, 4,-4 );
617 break;
618 case PE_ArrowLeft:
619 a.setPoints( 3, -4,0, 4,-5, 4,4 );
620 break;
621 case PE_ArrowRight:
622 a.setPoints( 3, 4,0, -4,-5, -4,4 );
623 break;
624 default:
625 return;
626 }
627
628 p->save();
629 p->setPen( Qt::NoPen );
630 a.translate( x+w/2, y+h/2 );
631 p->setBrush( flags & Style_Enabled ? cg.dark() : cg.light() );
632 p->drawPolygon( a ); // draw arrow
633 p->restore();
634 }
635 break;
636
637 case PE_Indicator:
638 {
639 QRect er = r;
640 er.addCoords( 1, 1, -1, -1 );
641 int iflags = flags & ~Style_On;
642 drawPrimitive( PE_ButtonBevel, p, er, cg, iflags, opt );
643 if ( !(flags & QStyle::Style_Off) ) {
644 er = r;
645 er.addCoords( 1, 2, 1, 1 );
646 drawPrimitive( PE_CheckMark, p, er, cg, flags, opt );
647 }
648 }
649 break;
650
651 case PE_IndicatorMask:
652 {
653 QPen oldPen = p->pen();
654 QBrush oldBrush = p->brush();
655
656 p->setPen( Qt::color1 );
657 p->setBrush( Qt::color1 );
658 p->fillRect( x, y, w, h, QBrush( Qt::color0 ) );
659 QRect er = r;
660 er.addCoords( 1, 1, -1, -1 );
661 p->fillRect(er, QBrush(Qt::color1));
662
663 if ( !(flags & QStyle::Style_Off) ) {
664 er = r;
665 er.addCoords( 1, 2, 1, 1 );
666 static const QCOORD check_mark[] = {
667 14,0, 10,0, 11,1, 8,1, 9,2, 7,2, 8,3, 6,3,
668 7,4, 1,4, 6,5, 1,5, 6,6, 3,6, 5,7, 4,7,
669 5,8, 5,8, 4,3, 2,3, 3,2, 3,2 };
670
671 QPointArray amark;
672 amark = QPointArray( sizeof(check_mark)/(sizeof(QCOORD)*2), check_mark );
673 amark.translate( er.x()+1, er.y()+1 );
674 p->drawLineSegments( amark );
675 amark.translate( -1, -1 );
676 p->drawLineSegments( amark );
677 }
678
679 p->setBrush( oldBrush );
680 p->setPen( oldPen );
681 }
682 break;
683
684 case PE_CheckMark:
685 {
686 static const QCOORD check_mark[] = {
687 14,0, 10,0, 11,1, 8,1, 9,2, 7,2, 8,3, 6,3,
688 7,4, 1,4, 6,5, 1,5, 6,6, 3,6, 5,7, 4,7,
689 5,8, 5,8, 4,3, 2,3, 3,2, 3,2 };
690
691 QPen oldPen = p->pen();
692
693 QPointArray amark;
694 amark = QPointArray( sizeof(check_mark)/(sizeof(QCOORD)*2), check_mark );
695 amark.translate( x+1, y+1 );
696
697 if ( flags & Style_On ) {
698 p->setPen( flags & Style_Enabled ? cg.shadow() : cg.dark() );
699 p->drawLineSegments( amark );
700 amark.translate( -1, -1 );
701 p->setPen( flags & Style_Enabled ? QColor(255,0,0) : cg.dark() );
702 p->drawLineSegments( amark );
703 p->setPen( oldPen );
704 } else {
705 p->setPen( flags & Style_Enabled ? cg.dark() : cg.mid() );
706 p->drawLineSegments( amark );
707 amark.translate( -1, -1 );
708 p->setPen( flags & Style_Enabled ? QColor(230,120,120) : cg.dark() );
709 p->drawLineSegments( amark );
710 p->setPen( oldPen );
711 }
712 }
713 break;
714
715 case PE_ExclusiveIndicator:
716 {
717 p->save();
718 p->eraseRect( x, y, w, h );
719 p->translate( x, y );
720
721 p->setPen( cg.button() );
722 p->setBrush( hot ? cg.midlight() : cg.button() );
723 QPointArray a;
724 a.setPoints( 4, 5,0, 11,6, 6,11, 0,5);
725 p->drawPolygon( a );
726
727 p->setPen( cg.dark() );
728 p->drawLine( 0,5, 5,0 );
729 p->drawLine( 6,0, 11,5 );
730 p->setPen( flags & Style_Down ? cg.light() : cg.dark() );
731 p->drawLine( 11,6, 6,11 );
732 p->drawLine( 5,11, 0,6 );
733 p->drawLine( 2,7, 5,10 );
734 p->drawLine( 6,10, 9,7 );
735 p->setPen( cg.light() );
736 p->drawLine( 2,5, 5,2 );
737
738 if ( flags & Style_On ) {
739 p->setPen( flags & Style_Enabled ? Qt::blue : Qt::darkGray );
740 p->setBrush( flags & Style_Enabled ? Qt::blue : Qt::darkGray );
741 a.setPoints(3, 6,2, 8,4, 6,6 );
742 p->drawPolygon( a );
743 p->setBrush( Qt::NoBrush );
744
745 p->setPen( cg.shadow() );
746 p->drawLine( 7,7, 9,5 );
747 } else {
748 p->drawLine( 6,2, 9,5 );
749 }
750 p->restore();
751 }
752 break;
753
754 case PE_ExclusiveIndicatorMask:
755 {
756 p->save();
757 QPen oldPen = p->pen();
758 QBrush oldBrush = p->brush();
759
760 p->setPen( Qt::color1 );
761 p->setBrush( Qt::color1 );
762 QPointArray a;
763 a.setPoints( 8, 0,5, 5,0, 6,0, 11,5, 11,6, 6,11, 5,11, 0,6 );
764 a.translate( x, y );
765 p->drawPolygon( a );
766
767 p->setBrush( oldBrush );
768 p->setPen( oldPen );
769 p->restore();
770 }
771 break;
772
773 case PE_Panel:
774 {
775 const int lineWidth = opt.isDefault() ? defaultFrameWidth : opt.lineWidth();
776 drawPanel( p, x, y, w, h, cg, flags & (Style_Sunken | Style_Down | Style_On), lineWidth, 0 );
777 if ( lineWidth <= 1 )
778 return;
779
780 // draw extra shadinglines
781 QPen oldPen = p->pen();
782 p->setPen( cg.midlight() );
783 p->drawLine( x+1, y+h-3, x+1, y+1 );
784 p->drawLine( x+1, y+1, x+w-3, y+1 );
785 p->setPen( cg.mid() );
786 p->drawLine( x+1, y+h-2, x+w-2, y+h-2 );
787 p->drawLine( x+w-2, y+h-2, x+w-2, y+1 );
788 p->setPen(oldPen);
789 }
790 break;
791
792 case PE_ScrollBarSubLine:
793 if ( !r.contains( d->mousePos ) && !(flags & Style_Active) )
794 flags &= ~Style_MouseOver;
795 drawPrimitive( PE_ButtonCommand, p, r, cg, flags, opt );
796 drawPrimitive(((flags & Style_Horizontal) ? PE_ArrowLeft : PE_ArrowUp),
797 p, r, cg, Style_Enabled | flags);
798 break;
799
800 case PE_ScrollBarAddLine:
801 if ( !r.contains( d->mousePos ) )
802 flags &= ~Style_MouseOver;
803 drawPrimitive( PE_ButtonCommand, p, r, cg, flags, opt );
804 drawPrimitive(((flags & Style_Horizontal) ? PE_ArrowRight : PE_ArrowDown),
805 p, r, cg, Style_Enabled | flags);
806 break;
807
808 case PE_ScrollBarSubPage:
809 case PE_ScrollBarAddPage:
810 if ( !r.contains( d->mousePos ) )
811 flags &= ~Style_MouseOver;
812 if ( r.isValid() )
813 qDrawShadePanel( p, x, y, w, h, cg, FALSE, 1, hot ? &cg.brush( QColorGroup::Midlight ) : &cg.brush( QColorGroup::Button ) );
814 break;
815
816 case PE_ScrollBarSlider:
817 {
818 if ( !r.isValid() )
819 break;
820 if ( !(r.contains( d->mousePos ) || flags & Style_Active) || !(flags & Style_Enabled ) )
821 flags &= ~Style_MouseOver;
822
823 QPixmap pm( r.width(), r.height() );
824 QPainter bp( &pm );
825 drawPrimitive(PE_ButtonBevel, &bp, QRect(0,0,r.width(),r.height()), cg, flags | Style_Enabled | Style_Raised);
826 if ( flags & Style_Horizontal ) {
827 const int sliderM = r.width() / 2;
828 if ( r.width() > 20 ) {
829 drawSeparator( &bp, sliderM-5, 2, sliderM-5, r.height()-3, cg );
830 drawSeparator( &bp, sliderM+3, 2, sliderM+3, r.height()-3, cg );
831 }
832 if ( r.width() > 10 )
833 drawSeparator( &bp, sliderM-1, 2, sliderM-1, r.height()-3, cg );
834
835 } else {
836 const int sliderM = r.height() / 2;
837 if ( r.height() > 20 ) {
838 drawSeparator( &bp, 2, sliderM-5, r.width()-3, sliderM-5, cg );
839 drawSeparator( &bp, 2, sliderM+3, r.width()-3, sliderM+3, cg );
840 }
841 if ( r.height() > 10 )
842 drawSeparator( &bp, 2, sliderM-1, r.width()-3, sliderM-1, cg );
843 }
844 bp.end();
845 p->drawPixmap( r.x(), r.y(), pm );
846 }
847
848 break;
849
850 case PE_Splitter:
851 {
852 const int motifOffset = 10;
853 int sw = pixelMetric( PM_SplitterWidth );
854 if ( flags & Style_Horizontal ) {
855 int xPos = x + w/2;
856 int kPos = motifOffset;
857 int kSize = sw - 2;
858
859 qDrawShadeLine( p, xPos, kPos + kSize - 1 ,
860 xPos, h, cg );
861
862 drawPrimitive( PE_ButtonBevel, p, QRect(xPos-sw/2+1, kPos, kSize, kSize+1), cg, flags, opt );
863 qDrawShadeLine( p, xPos+2, 0, xPos, kPos, cg );
864 } else {
865 int yPos = y + h/2;
866 int kPos = w - motifOffset - sw;
867 int kSize = sw - 2;
868
869 qDrawShadeLine( p, 0, yPos, kPos, yPos, cg );
870 drawPrimitive( PE_ButtonBevel, p, QRect( kPos, yPos-sw/2+1, kSize+1, kSize ), cg, flags, opt );
871 qDrawShadeLine( p, kPos + kSize+1, yPos, w, yPos, cg );
872 }
873 }
874 break;
875
876 default:
877 QMotifStyle::drawPrimitive( pe, p, r, cg, flags, opt );
878 break;
879 }
880}
881
882/*! \reimp */
883void QSGIStyle::drawControl( ControlElement element,
884 QPainter *p,
885 const QWidget *widget,
886 const QRect &r,
887 const QColorGroup &cg,
888 SFlags flags,
889 const QStyleOption& opt ) const
890{
891 if ( widget == d->hotWidget )
892 flags |= Style_MouseOver;
893
894 switch ( element ) {
895 case CE_PushButton:
896 {
897#ifndef QT_NO_PUSHBUTTON
898 const QPushButton *btn = (QPushButton*)widget;
899 int x1, y1, x2, y2;
900 r.coords( &x1, &y1, &x2, &y2 );
901
902 p->setPen( cg.foreground() );
903 p->setBrush( QBrush( cg.button(),Qt::NoBrush ) );
904 p->setBrushOrigin( -widget->backgroundOffset().x(),
905 -widget->backgroundOffset().y() );
906
907 int diw = pixelMetric( QStyle::PM_ButtonDefaultIndicator );
908 if ( btn->isDefault() || btn->autoDefault() ) {
909 x1 += diw;
910 y1 += diw;
911 x2 -= diw;
912 y2 -= diw;
913 }
914
915 QPointArray a;
916 if ( btn->isDefault() ) {
917 if ( diw == 0 ) {
918 a.setPoints( 9,
919 x1, y1, x2, y1, x2, y2, x1, y2, x1, y1+1,
920 x2-1, y1+1, x2-1, y2-1, x1+1, y2-1, x1+1, y1+1 );
921 p->setPen( cg.shadow() );
922 p->drawPolyline( a );
923 x1 += 2;
924 y1 += 2;
925 x2 -= 2;
926 y2 -= 2;
927 } else {
928 qDrawShadePanel( p, btn->rect(), cg, TRUE );
929 }
930 }
931
932 QBrush fill = cg.brush( QColorGroup::Button );
933 if ( !btn->isFlat() || btn->isOn() || btn->isDown() )
934 drawPrimitive( PE_ButtonBevel, p, QRect( x1, y1, x2-x1+1, y2-y1+1 ), cg, flags, opt );
935
936 if ( p->brush().style() != Qt::NoBrush )
937 p->setBrush( Qt::NoBrush );
938#endif
939 }
940 break;
941
942 case CE_PopupMenuItem:
943 {
944#ifndef QT_NO_POPUPMENU
945 if (! widget || opt.isDefault())
946 break;
947 QMenuItem *mi = opt.menuItem();
948 if ( !mi )
949 break;
950 const QPopupMenu *popupmenu = (const QPopupMenu *) widget;
951 int tab = opt.tabWidth();
952 int maxpmw = opt.maxIconWidth();
953 bool dis = ! (flags & Style_Enabled);
954 bool checkable = popupmenu->isCheckable();
955 bool act = flags & Style_Active;
956 int x, y, w, h;
957
958 r.rect(&x, &y, &w, &h);
959
960 if ( checkable )
961 maxpmw = QMAX( maxpmw, sgiCheckMarkSpace );
962 int checkcol = maxpmw;
963
964 if (mi && mi->isSeparator() ) {
965 p->setPen( cg.mid() );
966 p->drawLine(x, y, x+w, y );
967 return;
968 }
969
970 int pw = sgiItemFrame;
971
972 if ( act && !dis ) {
973 if ( pixelMetric( PM_DefaultFrameWidth ) > 1 )
974 drawPanel( p, x, y, w, h, cg, FALSE, pw,
975 &cg.brush( QColorGroup::Light ) );
976 else
977 drawPanel( p, x+1, y+1, w-2, h-2, cg, FALSE, 1,
978 &cg.brush( QColorGroup::Light ) );
979 } else {
980 p->fillRect( x, y, w, h, cg.brush( QColorGroup::Button ) );
981 }
982
983 if ( !mi )
984 return;
985
986 if ( mi->isChecked() ) {
987 if ( mi->iconSet() ) {
988 drawPanel( p, x+sgiItemFrame, y+sgiItemFrame, checkcol, h-2*sgiItemFrame,
989 cg, TRUE, 1, &cg.brush( QColorGroup::Light ) );
990 }
991 } else {
992 if ( !act )
993 p->fillRect( x+sgiItemFrame, y+sgiItemFrame, checkcol, h-2*sgiItemFrame,
994 cg.brush( QColorGroup::Button ) );
995 }
996
997 if ( mi->iconSet() ) {
998 QIconSet::Mode mode = QIconSet::Normal;
999 if ( act && !dis )
1000 mode = QIconSet::Active;
1001 QPixmap pixmap;
1002 if ( checkable && mi->isChecked() )
1003 pixmap = mi->iconSet()->pixmap( QIconSet::Small, mode, QIconSet::On );
1004 else
1005 pixmap = mi->iconSet()->pixmap( QIconSet::Small, mode );
1006
1007 int pixw = pixmap.width();
1008 int pixh = pixmap.height();
1009 QRect cr( x+sgiItemFrame, y+sgiItemFrame, checkcol, h-2*sgiItemFrame );
1010 QRect pmr( 0, 0, pixw, pixh );
1011 pmr.moveCenter( cr.center() );
1012 p->setPen( cg.text() );
1013 p->drawPixmap( pmr.topLeft(), pixmap );
1014 } else {
1015 if ( checkable ) {
1016 SFlags cflags = Style_Default;
1017 if (! dis)
1018 cflags |= Style_Enabled;
1019 if (act)
1020 cflags |= Style_On;
1021
1022 if ( mi->isChecked() ) {
1023 QRect er( x+sgiItemFrame+1, y+sgiItemFrame+3,
1024 pixelMetric(PM_IndicatorWidth),
1025 pixelMetric(PM_IndicatorHeight) );
1026 er.addCoords( 1, 1, -1, -1 );
1027 drawPrimitive( PE_ButtonBevel, p, er, cg, cflags, opt );
1028 er.addCoords( 0, 1, 1, 1 );
1029 drawPrimitive( PE_CheckMark, p, er, cg, cflags | Style_On, opt );
1030 }
1031 }
1032 }
1033
1034 p->setPen( cg.buttonText() );
1035
1036 QColor discol;
1037 if ( dis ) {
1038 discol = cg.text();
1039 p->setPen( discol );
1040 }
1041
1042 int xm = sgiItemFrame + checkcol + sgiItemHMargin;
1043
1044 if ( mi->custom() ) {
1045 int m = sgiItemVMargin;
1046 p->save();
1047 mi->custom()->paint( p, cg, act, !dis,
1048 x+xm, y+m, w-xm-tab+1, h-2*m );
1049 p->restore();
1050 }
1051
1052 QString s = mi->text();
1053 if ( !!s ) {
1054 int t = s.find( '\t' );
1055 int m = sgiItemVMargin;
1056 const int text_flags = AlignVCenter | DontClip | SingleLine; //special underline for &x
1057
1058 QString miText = s;
1059 if ( t>=0 ) {
1060 p->drawText(x+w-tab-sgiItemHMargin-sgiItemFrame,
1061 y+m, tab, h-2*m, text_flags, miText.mid( t+1 ) );
1062 miText = s.mid( 0, t );
1063 }
1064 QRect br = p->fontMetrics().boundingRect( x+xm, y+m, w-xm-tab+1, h-2*m,
1065 text_flags, mi->text() );
1066
1067 drawSGIPrefix( p, br.x()+p->fontMetrics().leftBearing(miText[0]),
1068 br.y()+br.height()+p->fontMetrics().underlinePos()-2, &miText );
1069 p->drawText( x+xm, y+m, w-xm-tab+1, h-2*m, text_flags, miText, miText.length() );
1070 } else {
1071 if ( mi->pixmap() ) {
1072 QPixmap *pixmap = mi->pixmap();
1073 if ( pixmap->depth() == 1 )
1074 p->setBackgroundMode( OpaqueMode );
1075 p->drawPixmap( x+xm, y+sgiItemFrame, *pixmap );
1076 if ( pixmap->depth() == 1 )
1077 p->setBackgroundMode( TransparentMode );
1078 }
1079 }
1080 if ( mi->popup() ) {
1081 int dim = (h-2*sgiItemFrame) / 2;
1082 drawPrimitive( PE_ArrowRight, p, QRect( x+w-sgiArrowHMargin-sgiItemFrame-dim, y+h/2-dim/2, dim, dim ), cg, flags );
1083 }
1084#endif
1085 }
1086 break;
1087
1088 case CE_MenuBarItem:
1089 {
1090#ifndef QT_NO_MENUDATA
1091 if (opt.isDefault())
1092 break;
1093
1094 QMenuItem *mi = opt.menuItem();
1095
1096 bool active = flags & Style_Active;
1097 int x, y, w, h;
1098 r.rect( &x, &y, &w, &h );
1099
1100 if ( active ) {
1101 p->setPen( QPen( cg.shadow(), 1) );
1102 p->drawRect( x, y, w, h );
1103 qDrawShadePanel( p, QRect(x+1,y+1,w-2,h-2), cg, FALSE, 2,
1104 &cg.brush( QColorGroup::Light ));
1105 } else {
1106 p->fillRect( x, y, w, h, cg.brush( QColorGroup::Button ));
1107 }
1108
1109 if ( mi->pixmap() )
1110 drawItem( p, r, AlignCenter|DontClip|SingleLine,
1111 cg, mi->isEnabled(), mi->pixmap(), "", -1, &cg.buttonText() );
1112
1113 if ( !!mi->text() ) {
1114 QString* text = new QString(mi->text());
1115 QRect br = p->fontMetrics().boundingRect( x, y-2, w+1, h,
1116 AlignCenter|DontClip|SingleLine|ShowPrefix, mi->text() );
1117
1118 drawSGIPrefix( p, br.x()+p->fontMetrics().leftBearing((*text)[0]),
1119 br.y()+br.height()+p->fontMetrics().underlinePos()-2, text );
1120 p->drawText( x, y-2, w+1, h, AlignCenter|DontClip|SingleLine, *text, text->length() );
1121 delete text;
1122 }
1123#endif
1124 }
1125 break;
1126
1127 case CE_CheckBox:
1128 QMotifStyle::drawControl( element, p, widget, r, cg, flags, opt );
1129 break;
1130
1131 default:
1132 QMotifStyle::drawControl( element, p, widget, r, cg, flags, opt );
1133 break;
1134 }
1135}
1136
1137/*! \reimp */
1138void QSGIStyle::drawComplexControl( ComplexControl control,
1139 QPainter *p,
1140 const QWidget* widget,
1141 const QRect& r,
1142 const QColorGroup& cg,
1143 SFlags flags,
1144 SCFlags sub,
1145 SCFlags subActive,
1146 const QStyleOption& opt ) const
1147{
1148 if ( widget == d->hotWidget )
1149 flags |= Style_MouseOver;
1150
1151 switch ( control ) {
1152 case CC_Slider:
1153 {
1154#ifndef QT_NO_SLIDER
1155 const QSlider * slider = (const QSlider *) widget;
1156
1157 QRect groove = querySubControlMetrics(CC_Slider, widget, SC_SliderGroove,
1158 opt),
1159 handle = querySubControlMetrics(CC_Slider, widget, SC_SliderHandle,
1160 opt);
1161
1162 if ((sub & SC_SliderGroove) && groove.isValid()) {
1163 QRegion region( groove );
1164 if ( ( sub & SC_SliderHandle ) && handle.isValid() )
1165 region = region.subtract( handle );
1166 if ( d->lastSliderRect.slider == slider && d->lastSliderRect.rect.isValid() )
1167 region = region.subtract( d->lastSliderRect.rect );
1168 p->setClipRegion( region );
1169
1170 QRect grooveTop = groove;
1171 grooveTop.addCoords( 1, 1, -1, -1 );
1172 drawPrimitive( PE_ButtonBevel, p, grooveTop, cg, flags & ~Style_MouseOver, opt );
1173
1174 if ( flags & Style_HasFocus ) {
1175 QRect fr = subRect( SR_SliderFocusRect, widget );
1176 drawPrimitive( PE_FocusRect, p, fr, cg, flags & ~Style_MouseOver );
1177 }
1178
1179 if ( d->lastSliderRect.slider == slider && d->lastSliderRect.rect.isValid() ) {
1180 if ( ( sub & SC_SliderHandle ) && handle.isValid() ) {
1181 region = widget->rect();
1182 region = region.subtract( handle );
1183 p->setClipRegion( region );
1184 } else {
1185 p->setClipping( FALSE );
1186 }
1187 qDrawShadePanel( p, d->lastSliderRect.rect, cg, TRUE, 1, &cg.brush( QColorGroup::Dark ) );
1188 }
1189 p->setClipping( FALSE );
1190 }
1191
1192 if (( sub & SC_SliderHandle ) && handle.isValid()) {
1193 if ( flags & Style_MouseOver && !handle.contains( d->mousePos ) && subActive != SC_SliderHandle )
1194 flags &= ~Style_MouseOver;
1195 drawPrimitive( PE_ButtonBevel, p, handle, cg, flags );
1196
1197 if ( slider->orientation() == Horizontal ) {
1198 QCOORD mid = handle.x() + handle.width() / 2;
1199 qDrawShadeLine( p, mid, handle.y(), mid,
1200 handle.y() + handle.height() - 2,
1201 cg, TRUE, 1);
1202 } else {
1203 QCOORD mid = handle.y() + handle.height() / 2;
1204 qDrawShadeLine( p, handle.x(), mid,
1205 handle.x() + handle.width() - 2, mid,
1206 cg, TRUE, 1);
1207 }
1208 }
1209
1210 if ( sub & SC_SliderTickmarks )
1211 QMotifStyle::drawComplexControl( control, p, widget, r, cg, flags,
1212 SC_SliderTickmarks, subActive,
1213 opt );
1214#endif
1215 break;
1216 }
1217 case CC_ComboBox:
1218 {
1219#ifndef QT_NO_COMBOBOX
1220 const QComboBox * cb = (QComboBox *) widget;
1221
1222 if (sub & SC_ComboBoxFrame) {
1223 QRect fr =
1224 QStyle::visualRect( querySubControlMetrics( CC_ComboBox, cb,
1225 SC_ComboBoxFrame ), cb );
1226 drawPrimitive( PE_ButtonBevel, p, fr, cg, flags );
1227 }
1228
1229 if ( sub & SC_ComboBoxArrow ) {
1230 p->save();
1231 QRect er =
1232 QStyle::visualRect( querySubControlMetrics( CC_ComboBox, cb, SC_ComboBoxArrow ), cb );
1233
1234 er.addCoords( 0, 3, 0, 0 );
1235
1236 drawPrimitive( PE_ArrowDown, p, er, cg, flags | Style_Enabled, opt );
1237
1238 int awh, ax, ay, sh, sy, dh, ew;
1239 get_combo_parameters( widget->rect(), ew, awh, ax, ay, sh, dh, sy );
1240
1241 QBrush arrow = cg.brush( QColorGroup::Dark );
1242 p->fillRect( ax, sy-1, awh, sh, arrow );
1243
1244 p->restore();
1245 if ( cb->hasFocus() ) {
1246 QRect re = QStyle::visualRect( subRect( SR_ComboBoxFocusRect, cb ), cb );
1247 drawPrimitive( PE_FocusRect, p, re, cg );
1248 }
1249 }
1250 if ( sub & SC_ComboBoxEditField ) {
1251 if ( cb->editable() ) {
1252 QRect er =
1253 QStyle::visualRect( querySubControlMetrics( CC_ComboBox, cb,
1254 SC_ComboBoxEditField ), cb );
1255 er.addCoords( -1, -1, 1, 1);
1256 qDrawShadePanel( p, QRect( er.x()-1, er.y()-1,
1257 er.width()+2, er.height()+2 ),
1258 cg, TRUE, 1, &cg.brush( QColorGroup::Button ) );
1259 }
1260 }
1261#endif
1262 p->setPen(cg.buttonText());
1263 break;
1264 }
1265
1266 case CC_ScrollBar:
1267 {
1268#ifndef QT_NO_SCROLLBAR
1269 QScrollBar *scrollbar = (QScrollBar*)widget;
1270 bool maxedOut = (scrollbar->minValue() == scrollbar->maxValue());
1271 if ( maxedOut )
1272 flags &= ~Style_Enabled;
1273
1274 QRect handle = QStyle::visualRect( querySubControlMetrics( CC_ScrollBar, widget, SC_ScrollBarSlider, opt ), widget );
1275
1276 if ( sub & SC_ScrollBarGroove ) {
1277 }
1278 if ( sub & SC_ScrollBarAddLine ) {
1279 QRect er = QStyle::visualRect( querySubControlMetrics( CC_ScrollBar, widget, SC_ScrollBarAddLine, opt ), widget );
1280 drawPrimitive( PE_ScrollBarAddLine, p, er, cg, flags, opt );
1281 }
1282 if ( sub & SC_ScrollBarSubLine ) {
1283 QRect er = QStyle::visualRect( querySubControlMetrics( CC_ScrollBar, widget, SC_ScrollBarSubLine, opt ), widget );
1284 drawPrimitive( PE_ScrollBarSubLine, p, er, cg, flags, opt );
1285 }
1286 if ( sub & SC_ScrollBarAddPage ) {
1287 QRect er = QStyle::visualRect( querySubControlMetrics( CC_ScrollBar, widget, SC_ScrollBarAddPage, opt ), widget );
1288 QRegion region( er );
1289 if ( d->lastScrollbarRect.scrollbar == scrollbar &&
1290 d->lastScrollbarRect.rect.isValid() &&
1291 er.intersects( d->lastScrollbarRect.rect ) ) {
1292 region = region.subtract( d->lastScrollbarRect.rect );
1293 p->setClipRegion( region );
1294 }
1295 if ( sub & SC_ScrollBarSlider && er.intersects( handle ) ) {
1296 region = region.subtract( handle );
1297 p->setClipRegion( region );
1298 }
1299
1300 drawPrimitive( PE_ScrollBarAddPage, p, er, cg, flags & ~Style_MouseOver, opt );
1301
1302 if ( d->lastScrollbarRect.scrollbar == scrollbar &&
1303 d->lastScrollbarRect.rect.isValid() &&
1304 er.intersects( d->lastScrollbarRect.rect ) ) {
1305 if ( sub & SC_ScrollBarSlider && handle.isValid() ) {
1306 region = er;
1307 region.subtract( handle );
1308 p->setClipRegion( region );
1309 } else {
1310 p->setClipping( FALSE );
1311 }
1312 qDrawShadePanel( p, d->lastScrollbarRect.rect, cg, TRUE, 1, &cg.brush( QColorGroup::Dark ) );
1313 }
1314 p->setClipping( FALSE );
1315 }
1316 if ( sub & SC_ScrollBarSubPage ) {
1317 QRect er = QStyle::visualRect( querySubControlMetrics( CC_ScrollBar, widget, SC_ScrollBarSubPage, opt ), widget );
1318 QRegion region( er );
1319 if ( d->lastScrollbarRect.scrollbar == scrollbar &&
1320 d->lastScrollbarRect.rect.isValid() &&
1321 er.intersects( d->lastScrollbarRect.rect ) ) {
1322 region = region.subtract( d->lastScrollbarRect.rect );
1323 p->setClipRegion( region );
1324 }
1325 if ( sub & SC_ScrollBarSlider && er.intersects( handle ) ) {
1326 region = region.subtract( handle );
1327 p->setClipRegion( region );
1328 }
1329 drawPrimitive( PE_ScrollBarSubPage, p, er, cg, flags & ~Style_MouseOver, opt );
1330 if ( d->lastScrollbarRect.scrollbar == scrollbar &&
1331 d->lastScrollbarRect.rect.isValid() &&
1332 er.intersects( d->lastScrollbarRect.rect ) ) {
1333 if ( sub & SC_ScrollBarSlider && handle.isValid() ) {
1334 region = er;
1335 region.subtract( handle );
1336 p->setClipRegion( region );
1337 } else {
1338 p->setClipping( FALSE );
1339 }
1340 qDrawShadePanel( p, d->lastScrollbarRect.rect, cg, TRUE, 1, &cg.brush( QColorGroup::Dark ) );
1341 }
1342 p->setClipping( FALSE );
1343 }
1344 if ( sub & SC_ScrollBarSlider ) {
1345 p->setClipping( FALSE );
1346 if ( subActive == SC_ScrollBarSlider )
1347 flags |= Style_Active;
1348
1349 drawPrimitive( PE_ScrollBarSlider, p, handle, cg, flags, opt );
1350 }
1351#endif
1352 }
1353 break;
1354
1355 default:
1356 QMotifStyle::drawComplexControl( control, p, widget, r, cg, flags, sub, subActive, opt );
1357 break;
1358 }
1359}
1360
1361/*!\reimp
1362*/
1363QSize QSGIStyle::sizeFromContents( ContentsType contents,
1364 const QWidget *widget,
1365 const QSize &contentsSize,
1366 const QStyleOption& opt ) const
1367{
1368 QSize sz(contentsSize);
1369
1370 switch(contents) {
1371 case CT_PopupMenuItem:
1372 {
1373#ifndef QT_NO_POPUPMENU
1374 if (! widget || opt.isDefault())
1375 break;
1376
1377 QMenuItem *mi = opt.menuItem();
1378 sz = QMotifStyle::sizeFromContents( contents, widget, contentsSize,
1379 opt );
1380 // SGI checkmark items needs a bit more room
1381 const QPopupMenu *popup = (QPopupMenu *) widget;
1382 if ( popup && popup->isCheckable() )
1383 sz.setWidth( sz.width() + 8 );
1384 // submenu indicator needs a bit more room
1385 if (mi->popup())
1386 sz.setWidth( sz.width() + sgiTabSpacing );
1387#endif
1388 break;
1389 }
1390
1391 default:
1392 sz = QMotifStyle::sizeFromContents( contents, widget, contentsSize, opt );
1393 break;
1394 }
1395
1396 return sz;
1397}
1398
1399/*! \reimp */
1400QRect QSGIStyle::subRect( SubRect r, const QWidget *widget ) const
1401{
1402 QRect rect;
1403
1404 switch ( r ) {
1405 case SR_ComboBoxFocusRect:
1406 {
1407 int awh, ax, ay, sh, sy, dh, ew;
1408 int fw = pixelMetric( PM_DefaultFrameWidth, widget );
1409 QRect tr = widget->rect();
1410
1411 tr.addCoords( fw, fw, -fw, -fw );
1412 get_combo_parameters( tr, ew, awh, ax, ay, sh, dh, sy );
1413 rect.setRect(ax-2, ay-2, awh+4, awh+sh+dh+4);
1414 }
1415 break;
1416 default:
1417 return QMotifStyle::subRect( r, widget );
1418 }
1419
1420 return rect;
1421}
1422
1423/*! \reimp */
1424QRect QSGIStyle::querySubControlMetrics( ComplexControl control,
1425 const QWidget *widget,
1426 SubControl sub,
1427 const QStyleOption& opt ) const
1428{
1429 switch ( control ) {
1430 case CC_ComboBox:
1431 switch ( sub ) {
1432 case SC_ComboBoxFrame:
1433 return widget->rect();
1434
1435 case SC_ComboBoxArrow: {
1436 int ew, awh, sh, dh, ax, ay, sy;
1437 int fw = pixelMetric( PM_DefaultFrameWidth, widget );
1438 QRect cr = widget->rect();
1439 cr.addCoords( fw, fw, -fw, -fw );
1440 get_combo_parameters( cr, ew, awh, ax, ay, sh, dh, sy );
1441 return QRect( ax, ay, awh, awh ); }
1442
1443 case SC_ComboBoxEditField: {
1444 int fw = pixelMetric( PM_DefaultFrameWidth, widget );
1445 QRect rect = widget->rect();
1446 rect.addCoords( fw, fw, -fw, -fw );
1447 int ew = get_combo_extra_width( rect.height() );
1448 rect.addCoords( 1, 1, -1-ew, -1 );
1449 return rect; }
1450
1451 default:
1452 break;
1453 }
1454 break;
1455 case CC_ScrollBar:
1456 return QCommonStyle::querySubControlMetrics( control, widget, sub, opt );
1457 default: break;
1458 }
1459 return QMotifStyle::querySubControlMetrics( control, widget, sub, opt );
1460}
1461
1462#endif // QT_NO_STYLE_SGI
Note: See TracBrowser for help on using the repository browser.