[2] | 1 | /****************************************************************************
|
---|
| 2 | ** $Id: qsgistyle.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 "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
|
---|
| 61 | struct 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
|
---|
| 70 | struct ScrollbarLastPosition
|
---|
| 71 | {
|
---|
| 72 | ScrollbarLastPosition() : rect( 0,-1, 0,-1 ), scrollbar(0) {}
|
---|
| 73 | QRect rect;
|
---|
| 74 | const QScrollBar *scrollbar;
|
---|
| 75 | };
|
---|
| 76 | #endif
|
---|
| 77 |
|
---|
| 78 | class QSGIStylePrivate
|
---|
| 79 | {
|
---|
| 80 | public:
|
---|
| 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 | */
|
---|
| 116 | QSGIStyle::QSGIStyle( bool useHighlightCols ) : QMotifStyle( useHighlightCols ), isApplicationStyle( 0 )
|
---|
| 117 | {
|
---|
| 118 | d = new QSGIStylePrivate;
|
---|
| 119 | }
|
---|
| 120 |
|
---|
| 121 | /*!
|
---|
| 122 | Destroys the style.
|
---|
| 123 | */
|
---|
| 124 | QSGIStyle::~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 | */
|
---|
| 135 | void
|
---|
| 136 | QSGIStyle::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 | */
|
---|
| 180 | void
|
---|
| 181 | QSGIStyle::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 | */
|
---|
| 193 | void
|
---|
| 194 | QSGIStyle::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 */
|
---|
| 266 | void
|
---|
| 267 | QSGIStyle::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 */
|
---|
| 284 | bool 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 |
|
---|
| 365 | static const int sgiItemFrame = 2; // menu item frame width
|
---|
| 366 | // static const int sgiSepHeight = 1; // separator item height
|
---|
| 367 | static const int sgiItemHMargin = 3; // menu item hor text margin
|
---|
| 368 | static const int sgiItemVMargin = 2; // menu item ver text margin
|
---|
| 369 | static const int sgiArrowHMargin = 6; // arrow horizontal margin
|
---|
| 370 | static const int sgiTabSpacing = 12; // space between text and tab
|
---|
| 371 | // static const int sgiCheckMarkHMargin = 2; // horiz. margins of check mark ### not used?!?
|
---|
| 372 | static const int sgiCheckMarkSpace = 20;
|
---|
| 373 |
|
---|
| 374 | /*! \reimp */
|
---|
| 375 | int 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 |
|
---|
| 404 | static 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 |
|
---|
| 466 | static 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 |
|
---|
| 482 | static 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 |
|
---|
| 507 | static 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 |
|
---|
| 522 | static 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 */
|
---|
| 550 | void 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 */
|
---|
| 883 | void 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();
|
---|
[8] | 948 |
|
---|
| 949 | // QPopupMenu has WResizeNoErase and WRepaintNoErase flags, so we
|
---|
| 950 | // must erase areas not covered by menu items (this is requested by
|
---|
| 951 | // QPopupMenu using 0 as the menu item argument).
|
---|
| 952 | // [Win32 version feels ok without this, because it doesn't actually
|
---|
| 953 | // fully obey WResizeNoErase and WRepaintNoErase: WM_ERASEBKGND always
|
---|
| 954 | // erases the background before WM_PAINT and after every resize].
|
---|
| 955 | #if !defined (Q_WS_PM)
|
---|
[2] | 956 | if ( !mi )
|
---|
| 957 | break;
|
---|
[8] | 958 | #endif
|
---|
[2] | 959 | const QPopupMenu *popupmenu = (const QPopupMenu *) widget;
|
---|
| 960 | int tab = opt.tabWidth();
|
---|
| 961 | int maxpmw = opt.maxIconWidth();
|
---|
| 962 | bool dis = ! (flags & Style_Enabled);
|
---|
| 963 | bool checkable = popupmenu->isCheckable();
|
---|
| 964 | bool act = flags & Style_Active;
|
---|
| 965 | int x, y, w, h;
|
---|
| 966 |
|
---|
| 967 | r.rect(&x, &y, &w, &h);
|
---|
| 968 |
|
---|
| 969 | if ( checkable )
|
---|
| 970 | maxpmw = QMAX( maxpmw, sgiCheckMarkSpace );
|
---|
| 971 | int checkcol = maxpmw;
|
---|
| 972 |
|
---|
| 973 | if (mi && mi->isSeparator() ) {
|
---|
| 974 | p->setPen( cg.mid() );
|
---|
| 975 | p->drawLine(x, y, x+w, y );
|
---|
| 976 | return;
|
---|
| 977 | }
|
---|
| 978 |
|
---|
| 979 | int pw = sgiItemFrame;
|
---|
| 980 |
|
---|
| 981 | if ( act && !dis ) {
|
---|
| 982 | if ( pixelMetric( PM_DefaultFrameWidth ) > 1 )
|
---|
| 983 | drawPanel( p, x, y, w, h, cg, FALSE, pw,
|
---|
| 984 | &cg.brush( QColorGroup::Light ) );
|
---|
| 985 | else
|
---|
| 986 | drawPanel( p, x+1, y+1, w-2, h-2, cg, FALSE, 1,
|
---|
| 987 | &cg.brush( QColorGroup::Light ) );
|
---|
| 988 | } else {
|
---|
| 989 | p->fillRect( x, y, w, h, cg.brush( QColorGroup::Button ) );
|
---|
| 990 | }
|
---|
| 991 |
|
---|
| 992 | if ( !mi )
|
---|
| 993 | return;
|
---|
| 994 |
|
---|
| 995 | if ( mi->isChecked() ) {
|
---|
| 996 | if ( mi->iconSet() ) {
|
---|
| 997 | drawPanel( p, x+sgiItemFrame, y+sgiItemFrame, checkcol, h-2*sgiItemFrame,
|
---|
| 998 | cg, TRUE, 1, &cg.brush( QColorGroup::Light ) );
|
---|
| 999 | }
|
---|
| 1000 | } else {
|
---|
| 1001 | if ( !act )
|
---|
| 1002 | p->fillRect( x+sgiItemFrame, y+sgiItemFrame, checkcol, h-2*sgiItemFrame,
|
---|
| 1003 | cg.brush( QColorGroup::Button ) );
|
---|
| 1004 | }
|
---|
| 1005 |
|
---|
| 1006 | if ( mi->iconSet() ) {
|
---|
| 1007 | QIconSet::Mode mode = QIconSet::Normal;
|
---|
| 1008 | if ( act && !dis )
|
---|
| 1009 | mode = QIconSet::Active;
|
---|
| 1010 | QPixmap pixmap;
|
---|
| 1011 | if ( checkable && mi->isChecked() )
|
---|
| 1012 | pixmap = mi->iconSet()->pixmap( QIconSet::Small, mode, QIconSet::On );
|
---|
| 1013 | else
|
---|
| 1014 | pixmap = mi->iconSet()->pixmap( QIconSet::Small, mode );
|
---|
| 1015 |
|
---|
| 1016 | int pixw = pixmap.width();
|
---|
| 1017 | int pixh = pixmap.height();
|
---|
| 1018 | QRect cr( x+sgiItemFrame, y+sgiItemFrame, checkcol, h-2*sgiItemFrame );
|
---|
| 1019 | QRect pmr( 0, 0, pixw, pixh );
|
---|
| 1020 | pmr.moveCenter( cr.center() );
|
---|
| 1021 | p->setPen( cg.text() );
|
---|
| 1022 | p->drawPixmap( pmr.topLeft(), pixmap );
|
---|
| 1023 | } else {
|
---|
| 1024 | if ( checkable ) {
|
---|
| 1025 | SFlags cflags = Style_Default;
|
---|
| 1026 | if (! dis)
|
---|
| 1027 | cflags |= Style_Enabled;
|
---|
| 1028 | if (act)
|
---|
| 1029 | cflags |= Style_On;
|
---|
| 1030 |
|
---|
| 1031 | if ( mi->isChecked() ) {
|
---|
| 1032 | QRect er( x+sgiItemFrame+1, y+sgiItemFrame+3,
|
---|
| 1033 | pixelMetric(PM_IndicatorWidth),
|
---|
| 1034 | pixelMetric(PM_IndicatorHeight) );
|
---|
| 1035 | er.addCoords( 1, 1, -1, -1 );
|
---|
| 1036 | drawPrimitive( PE_ButtonBevel, p, er, cg, cflags, opt );
|
---|
| 1037 | er.addCoords( 0, 1, 1, 1 );
|
---|
| 1038 | drawPrimitive( PE_CheckMark, p, er, cg, cflags | Style_On, opt );
|
---|
| 1039 | }
|
---|
| 1040 | }
|
---|
| 1041 | }
|
---|
| 1042 |
|
---|
| 1043 | p->setPen( cg.buttonText() );
|
---|
| 1044 |
|
---|
| 1045 | QColor discol;
|
---|
| 1046 | if ( dis ) {
|
---|
| 1047 | discol = cg.text();
|
---|
| 1048 | p->setPen( discol );
|
---|
| 1049 | }
|
---|
| 1050 |
|
---|
| 1051 | int xm = sgiItemFrame + checkcol + sgiItemHMargin;
|
---|
| 1052 |
|
---|
| 1053 | if ( mi->custom() ) {
|
---|
| 1054 | int m = sgiItemVMargin;
|
---|
| 1055 | p->save();
|
---|
| 1056 | mi->custom()->paint( p, cg, act, !dis,
|
---|
| 1057 | x+xm, y+m, w-xm-tab+1, h-2*m );
|
---|
| 1058 | p->restore();
|
---|
| 1059 | }
|
---|
| 1060 |
|
---|
| 1061 | QString s = mi->text();
|
---|
| 1062 | if ( !!s ) {
|
---|
| 1063 | int t = s.find( '\t' );
|
---|
| 1064 | int m = sgiItemVMargin;
|
---|
| 1065 | const int text_flags = AlignVCenter | DontClip | SingleLine; //special underline for &x
|
---|
| 1066 |
|
---|
| 1067 | QString miText = s;
|
---|
| 1068 | if ( t>=0 ) {
|
---|
| 1069 | p->drawText(x+w-tab-sgiItemHMargin-sgiItemFrame,
|
---|
| 1070 | y+m, tab, h-2*m, text_flags, miText.mid( t+1 ) );
|
---|
| 1071 | miText = s.mid( 0, t );
|
---|
| 1072 | }
|
---|
| 1073 | QRect br = p->fontMetrics().boundingRect( x+xm, y+m, w-xm-tab+1, h-2*m,
|
---|
| 1074 | text_flags, mi->text() );
|
---|
| 1075 |
|
---|
| 1076 | drawSGIPrefix( p, br.x()+p->fontMetrics().leftBearing(miText[0]),
|
---|
| 1077 | br.y()+br.height()+p->fontMetrics().underlinePos()-2, &miText );
|
---|
| 1078 | p->drawText( x+xm, y+m, w-xm-tab+1, h-2*m, text_flags, miText, miText.length() );
|
---|
| 1079 | } else {
|
---|
| 1080 | if ( mi->pixmap() ) {
|
---|
| 1081 | QPixmap *pixmap = mi->pixmap();
|
---|
| 1082 | if ( pixmap->depth() == 1 )
|
---|
| 1083 | p->setBackgroundMode( OpaqueMode );
|
---|
| 1084 | p->drawPixmap( x+xm, y+sgiItemFrame, *pixmap );
|
---|
| 1085 | if ( pixmap->depth() == 1 )
|
---|
| 1086 | p->setBackgroundMode( TransparentMode );
|
---|
| 1087 | }
|
---|
| 1088 | }
|
---|
| 1089 | if ( mi->popup() ) {
|
---|
| 1090 | int dim = (h-2*sgiItemFrame) / 2;
|
---|
| 1091 | drawPrimitive( PE_ArrowRight, p, QRect( x+w-sgiArrowHMargin-sgiItemFrame-dim, y+h/2-dim/2, dim, dim ), cg, flags );
|
---|
| 1092 | }
|
---|
| 1093 | #endif
|
---|
| 1094 | }
|
---|
| 1095 | break;
|
---|
| 1096 |
|
---|
| 1097 | case CE_MenuBarItem:
|
---|
| 1098 | {
|
---|
| 1099 | #ifndef QT_NO_MENUDATA
|
---|
| 1100 | if (opt.isDefault())
|
---|
| 1101 | break;
|
---|
| 1102 |
|
---|
| 1103 | QMenuItem *mi = opt.menuItem();
|
---|
| 1104 |
|
---|
| 1105 | bool active = flags & Style_Active;
|
---|
| 1106 | int x, y, w, h;
|
---|
| 1107 | r.rect( &x, &y, &w, &h );
|
---|
| 1108 |
|
---|
| 1109 | if ( active ) {
|
---|
| 1110 | p->setPen( QPen( cg.shadow(), 1) );
|
---|
| 1111 | p->drawRect( x, y, w, h );
|
---|
| 1112 | qDrawShadePanel( p, QRect(x+1,y+1,w-2,h-2), cg, FALSE, 2,
|
---|
| 1113 | &cg.brush( QColorGroup::Light ));
|
---|
| 1114 | } else {
|
---|
| 1115 | p->fillRect( x, y, w, h, cg.brush( QColorGroup::Button ));
|
---|
| 1116 | }
|
---|
| 1117 |
|
---|
| 1118 | if ( mi->pixmap() )
|
---|
| 1119 | drawItem( p, r, AlignCenter|DontClip|SingleLine,
|
---|
| 1120 | cg, mi->isEnabled(), mi->pixmap(), "", -1, &cg.buttonText() );
|
---|
| 1121 |
|
---|
| 1122 | if ( !!mi->text() ) {
|
---|
| 1123 | QString* text = new QString(mi->text());
|
---|
| 1124 | QRect br = p->fontMetrics().boundingRect( x, y-2, w+1, h,
|
---|
| 1125 | AlignCenter|DontClip|SingleLine|ShowPrefix, mi->text() );
|
---|
| 1126 |
|
---|
| 1127 | drawSGIPrefix( p, br.x()+p->fontMetrics().leftBearing((*text)[0]),
|
---|
| 1128 | br.y()+br.height()+p->fontMetrics().underlinePos()-2, text );
|
---|
| 1129 | p->drawText( x, y-2, w+1, h, AlignCenter|DontClip|SingleLine, *text, text->length() );
|
---|
| 1130 | delete text;
|
---|
| 1131 | }
|
---|
| 1132 | #endif
|
---|
| 1133 | }
|
---|
| 1134 | break;
|
---|
| 1135 |
|
---|
| 1136 | case CE_CheckBox:
|
---|
| 1137 | QMotifStyle::drawControl( element, p, widget, r, cg, flags, opt );
|
---|
| 1138 | break;
|
---|
| 1139 |
|
---|
| 1140 | default:
|
---|
| 1141 | QMotifStyle::drawControl( element, p, widget, r, cg, flags, opt );
|
---|
| 1142 | break;
|
---|
| 1143 | }
|
---|
| 1144 | }
|
---|
| 1145 |
|
---|
| 1146 | /*! \reimp */
|
---|
| 1147 | void QSGIStyle::drawComplexControl( ComplexControl control,
|
---|
| 1148 | QPainter *p,
|
---|
| 1149 | const QWidget* widget,
|
---|
| 1150 | const QRect& r,
|
---|
| 1151 | const QColorGroup& cg,
|
---|
| 1152 | SFlags flags,
|
---|
| 1153 | SCFlags sub,
|
---|
| 1154 | SCFlags subActive,
|
---|
| 1155 | const QStyleOption& opt ) const
|
---|
| 1156 | {
|
---|
| 1157 | if ( widget == d->hotWidget )
|
---|
| 1158 | flags |= Style_MouseOver;
|
---|
| 1159 |
|
---|
| 1160 | switch ( control ) {
|
---|
| 1161 | case CC_Slider:
|
---|
| 1162 | {
|
---|
| 1163 | #ifndef QT_NO_SLIDER
|
---|
| 1164 | const QSlider * slider = (const QSlider *) widget;
|
---|
| 1165 |
|
---|
| 1166 | QRect groove = querySubControlMetrics(CC_Slider, widget, SC_SliderGroove,
|
---|
| 1167 | opt),
|
---|
| 1168 | handle = querySubControlMetrics(CC_Slider, widget, SC_SliderHandle,
|
---|
| 1169 | opt);
|
---|
| 1170 |
|
---|
| 1171 | if ((sub & SC_SliderGroove) && groove.isValid()) {
|
---|
| 1172 | QRegion region( groove );
|
---|
| 1173 | if ( ( sub & SC_SliderHandle ) && handle.isValid() )
|
---|
| 1174 | region = region.subtract( handle );
|
---|
| 1175 | if ( d->lastSliderRect.slider == slider && d->lastSliderRect.rect.isValid() )
|
---|
| 1176 | region = region.subtract( d->lastSliderRect.rect );
|
---|
| 1177 | p->setClipRegion( region );
|
---|
| 1178 |
|
---|
| 1179 | QRect grooveTop = groove;
|
---|
| 1180 | grooveTop.addCoords( 1, 1, -1, -1 );
|
---|
| 1181 | drawPrimitive( PE_ButtonBevel, p, grooveTop, cg, flags & ~Style_MouseOver, opt );
|
---|
| 1182 |
|
---|
| 1183 | if ( flags & Style_HasFocus ) {
|
---|
| 1184 | QRect fr = subRect( SR_SliderFocusRect, widget );
|
---|
| 1185 | drawPrimitive( PE_FocusRect, p, fr, cg, flags & ~Style_MouseOver );
|
---|
| 1186 | }
|
---|
| 1187 |
|
---|
| 1188 | if ( d->lastSliderRect.slider == slider && d->lastSliderRect.rect.isValid() ) {
|
---|
| 1189 | if ( ( sub & SC_SliderHandle ) && handle.isValid() ) {
|
---|
| 1190 | region = widget->rect();
|
---|
| 1191 | region = region.subtract( handle );
|
---|
| 1192 | p->setClipRegion( region );
|
---|
| 1193 | } else {
|
---|
| 1194 | p->setClipping( FALSE );
|
---|
| 1195 | }
|
---|
| 1196 | qDrawShadePanel( p, d->lastSliderRect.rect, cg, TRUE, 1, &cg.brush( QColorGroup::Dark ) );
|
---|
| 1197 | }
|
---|
| 1198 | p->setClipping( FALSE );
|
---|
| 1199 | }
|
---|
| 1200 |
|
---|
| 1201 | if (( sub & SC_SliderHandle ) && handle.isValid()) {
|
---|
| 1202 | if ( flags & Style_MouseOver && !handle.contains( d->mousePos ) && subActive != SC_SliderHandle )
|
---|
| 1203 | flags &= ~Style_MouseOver;
|
---|
| 1204 | drawPrimitive( PE_ButtonBevel, p, handle, cg, flags );
|
---|
| 1205 |
|
---|
| 1206 | if ( slider->orientation() == Horizontal ) {
|
---|
| 1207 | QCOORD mid = handle.x() + handle.width() / 2;
|
---|
| 1208 | qDrawShadeLine( p, mid, handle.y(), mid,
|
---|
| 1209 | handle.y() + handle.height() - 2,
|
---|
| 1210 | cg, TRUE, 1);
|
---|
| 1211 | } else {
|
---|
| 1212 | QCOORD mid = handle.y() + handle.height() / 2;
|
---|
| 1213 | qDrawShadeLine( p, handle.x(), mid,
|
---|
| 1214 | handle.x() + handle.width() - 2, mid,
|
---|
| 1215 | cg, TRUE, 1);
|
---|
| 1216 | }
|
---|
| 1217 | }
|
---|
| 1218 |
|
---|
| 1219 | if ( sub & SC_SliderTickmarks )
|
---|
| 1220 | QMotifStyle::drawComplexControl( control, p, widget, r, cg, flags,
|
---|
| 1221 | SC_SliderTickmarks, subActive,
|
---|
| 1222 | opt );
|
---|
| 1223 | #endif
|
---|
| 1224 | break;
|
---|
| 1225 | }
|
---|
| 1226 | case CC_ComboBox:
|
---|
| 1227 | {
|
---|
| 1228 | #ifndef QT_NO_COMBOBOX
|
---|
| 1229 | const QComboBox * cb = (QComboBox *) widget;
|
---|
| 1230 |
|
---|
| 1231 | if (sub & SC_ComboBoxFrame) {
|
---|
| 1232 | QRect fr =
|
---|
| 1233 | QStyle::visualRect( querySubControlMetrics( CC_ComboBox, cb,
|
---|
| 1234 | SC_ComboBoxFrame ), cb );
|
---|
| 1235 | drawPrimitive( PE_ButtonBevel, p, fr, cg, flags );
|
---|
| 1236 | }
|
---|
| 1237 |
|
---|
| 1238 | if ( sub & SC_ComboBoxArrow ) {
|
---|
| 1239 | p->save();
|
---|
| 1240 | QRect er =
|
---|
| 1241 | QStyle::visualRect( querySubControlMetrics( CC_ComboBox, cb, SC_ComboBoxArrow ), cb );
|
---|
| 1242 |
|
---|
| 1243 | er.addCoords( 0, 3, 0, 0 );
|
---|
| 1244 |
|
---|
| 1245 | drawPrimitive( PE_ArrowDown, p, er, cg, flags | Style_Enabled, opt );
|
---|
| 1246 |
|
---|
| 1247 | int awh, ax, ay, sh, sy, dh, ew;
|
---|
| 1248 | get_combo_parameters( widget->rect(), ew, awh, ax, ay, sh, dh, sy );
|
---|
| 1249 |
|
---|
| 1250 | QBrush arrow = cg.brush( QColorGroup::Dark );
|
---|
| 1251 | p->fillRect( ax, sy-1, awh, sh, arrow );
|
---|
| 1252 |
|
---|
| 1253 | p->restore();
|
---|
| 1254 | if ( cb->hasFocus() ) {
|
---|
| 1255 | QRect re = QStyle::visualRect( subRect( SR_ComboBoxFocusRect, cb ), cb );
|
---|
| 1256 | drawPrimitive( PE_FocusRect, p, re, cg );
|
---|
| 1257 | }
|
---|
| 1258 | }
|
---|
| 1259 | if ( sub & SC_ComboBoxEditField ) {
|
---|
| 1260 | if ( cb->editable() ) {
|
---|
| 1261 | QRect er =
|
---|
| 1262 | QStyle::visualRect( querySubControlMetrics( CC_ComboBox, cb,
|
---|
| 1263 | SC_ComboBoxEditField ), cb );
|
---|
| 1264 | er.addCoords( -1, -1, 1, 1);
|
---|
| 1265 | qDrawShadePanel( p, QRect( er.x()-1, er.y()-1,
|
---|
| 1266 | er.width()+2, er.height()+2 ),
|
---|
| 1267 | cg, TRUE, 1, &cg.brush( QColorGroup::Button ) );
|
---|
| 1268 | }
|
---|
| 1269 | }
|
---|
| 1270 | #endif
|
---|
| 1271 | p->setPen(cg.buttonText());
|
---|
| 1272 | break;
|
---|
| 1273 | }
|
---|
| 1274 |
|
---|
| 1275 | case CC_ScrollBar:
|
---|
| 1276 | {
|
---|
| 1277 | #ifndef QT_NO_SCROLLBAR
|
---|
| 1278 | QScrollBar *scrollbar = (QScrollBar*)widget;
|
---|
| 1279 | bool maxedOut = (scrollbar->minValue() == scrollbar->maxValue());
|
---|
| 1280 | if ( maxedOut )
|
---|
| 1281 | flags &= ~Style_Enabled;
|
---|
| 1282 |
|
---|
| 1283 | QRect handle = QStyle::visualRect( querySubControlMetrics( CC_ScrollBar, widget, SC_ScrollBarSlider, opt ), widget );
|
---|
| 1284 |
|
---|
| 1285 | if ( sub & SC_ScrollBarGroove ) {
|
---|
| 1286 | }
|
---|
| 1287 | if ( sub & SC_ScrollBarAddLine ) {
|
---|
| 1288 | QRect er = QStyle::visualRect( querySubControlMetrics( CC_ScrollBar, widget, SC_ScrollBarAddLine, opt ), widget );
|
---|
| 1289 | drawPrimitive( PE_ScrollBarAddLine, p, er, cg, flags, opt );
|
---|
| 1290 | }
|
---|
| 1291 | if ( sub & SC_ScrollBarSubLine ) {
|
---|
| 1292 | QRect er = QStyle::visualRect( querySubControlMetrics( CC_ScrollBar, widget, SC_ScrollBarSubLine, opt ), widget );
|
---|
| 1293 | drawPrimitive( PE_ScrollBarSubLine, p, er, cg, flags, opt );
|
---|
| 1294 | }
|
---|
| 1295 | if ( sub & SC_ScrollBarAddPage ) {
|
---|
| 1296 | QRect er = QStyle::visualRect( querySubControlMetrics( CC_ScrollBar, widget, SC_ScrollBarAddPage, opt ), widget );
|
---|
| 1297 | QRegion region( er );
|
---|
| 1298 | if ( d->lastScrollbarRect.scrollbar == scrollbar &&
|
---|
| 1299 | d->lastScrollbarRect.rect.isValid() &&
|
---|
| 1300 | er.intersects( d->lastScrollbarRect.rect ) ) {
|
---|
| 1301 | region = region.subtract( d->lastScrollbarRect.rect );
|
---|
| 1302 | p->setClipRegion( region );
|
---|
| 1303 | }
|
---|
| 1304 | if ( sub & SC_ScrollBarSlider && er.intersects( handle ) ) {
|
---|
| 1305 | region = region.subtract( handle );
|
---|
| 1306 | p->setClipRegion( region );
|
---|
| 1307 | }
|
---|
| 1308 |
|
---|
| 1309 | drawPrimitive( PE_ScrollBarAddPage, p, er, cg, flags & ~Style_MouseOver, opt );
|
---|
| 1310 |
|
---|
| 1311 | if ( d->lastScrollbarRect.scrollbar == scrollbar &&
|
---|
| 1312 | d->lastScrollbarRect.rect.isValid() &&
|
---|
| 1313 | er.intersects( d->lastScrollbarRect.rect ) ) {
|
---|
| 1314 | if ( sub & SC_ScrollBarSlider && handle.isValid() ) {
|
---|
| 1315 | region = er;
|
---|
| 1316 | region.subtract( handle );
|
---|
| 1317 | p->setClipRegion( region );
|
---|
| 1318 | } else {
|
---|
| 1319 | p->setClipping( FALSE );
|
---|
| 1320 | }
|
---|
| 1321 | qDrawShadePanel( p, d->lastScrollbarRect.rect, cg, TRUE, 1, &cg.brush( QColorGroup::Dark ) );
|
---|
| 1322 | }
|
---|
| 1323 | p->setClipping( FALSE );
|
---|
| 1324 | }
|
---|
| 1325 | if ( sub & SC_ScrollBarSubPage ) {
|
---|
| 1326 | QRect er = QStyle::visualRect( querySubControlMetrics( CC_ScrollBar, widget, SC_ScrollBarSubPage, opt ), widget );
|
---|
| 1327 | QRegion region( er );
|
---|
| 1328 | if ( d->lastScrollbarRect.scrollbar == scrollbar &&
|
---|
| 1329 | d->lastScrollbarRect.rect.isValid() &&
|
---|
| 1330 | er.intersects( d->lastScrollbarRect.rect ) ) {
|
---|
| 1331 | region = region.subtract( d->lastScrollbarRect.rect );
|
---|
| 1332 | p->setClipRegion( region );
|
---|
| 1333 | }
|
---|
| 1334 | if ( sub & SC_ScrollBarSlider && er.intersects( handle ) ) {
|
---|
| 1335 | region = region.subtract( handle );
|
---|
| 1336 | p->setClipRegion( region );
|
---|
| 1337 | }
|
---|
| 1338 | drawPrimitive( PE_ScrollBarSubPage, p, er, cg, flags & ~Style_MouseOver, opt );
|
---|
| 1339 | if ( d->lastScrollbarRect.scrollbar == scrollbar &&
|
---|
| 1340 | d->lastScrollbarRect.rect.isValid() &&
|
---|
| 1341 | er.intersects( d->lastScrollbarRect.rect ) ) {
|
---|
| 1342 | if ( sub & SC_ScrollBarSlider && handle.isValid() ) {
|
---|
| 1343 | region = er;
|
---|
| 1344 | region.subtract( handle );
|
---|
| 1345 | p->setClipRegion( region );
|
---|
| 1346 | } else {
|
---|
| 1347 | p->setClipping( FALSE );
|
---|
| 1348 | }
|
---|
| 1349 | qDrawShadePanel( p, d->lastScrollbarRect.rect, cg, TRUE, 1, &cg.brush( QColorGroup::Dark ) );
|
---|
| 1350 | }
|
---|
| 1351 | p->setClipping( FALSE );
|
---|
| 1352 | }
|
---|
| 1353 | if ( sub & SC_ScrollBarSlider ) {
|
---|
| 1354 | p->setClipping( FALSE );
|
---|
| 1355 | if ( subActive == SC_ScrollBarSlider )
|
---|
| 1356 | flags |= Style_Active;
|
---|
| 1357 |
|
---|
| 1358 | drawPrimitive( PE_ScrollBarSlider, p, handle, cg, flags, opt );
|
---|
| 1359 | }
|
---|
| 1360 | #endif
|
---|
| 1361 | }
|
---|
| 1362 | break;
|
---|
| 1363 |
|
---|
| 1364 | default:
|
---|
| 1365 | QMotifStyle::drawComplexControl( control, p, widget, r, cg, flags, sub, subActive, opt );
|
---|
| 1366 | break;
|
---|
| 1367 | }
|
---|
| 1368 | }
|
---|
| 1369 |
|
---|
| 1370 | /*!\reimp
|
---|
| 1371 | */
|
---|
| 1372 | QSize QSGIStyle::sizeFromContents( ContentsType contents,
|
---|
| 1373 | const QWidget *widget,
|
---|
| 1374 | const QSize &contentsSize,
|
---|
| 1375 | const QStyleOption& opt ) const
|
---|
| 1376 | {
|
---|
| 1377 | QSize sz(contentsSize);
|
---|
| 1378 |
|
---|
| 1379 | switch(contents) {
|
---|
| 1380 | case CT_PopupMenuItem:
|
---|
| 1381 | {
|
---|
| 1382 | #ifndef QT_NO_POPUPMENU
|
---|
| 1383 | if (! widget || opt.isDefault())
|
---|
| 1384 | break;
|
---|
| 1385 |
|
---|
| 1386 | QMenuItem *mi = opt.menuItem();
|
---|
| 1387 | sz = QMotifStyle::sizeFromContents( contents, widget, contentsSize,
|
---|
| 1388 | opt );
|
---|
| 1389 | // SGI checkmark items needs a bit more room
|
---|
| 1390 | const QPopupMenu *popup = (QPopupMenu *) widget;
|
---|
| 1391 | if ( popup && popup->isCheckable() )
|
---|
| 1392 | sz.setWidth( sz.width() + 8 );
|
---|
| 1393 | // submenu indicator needs a bit more room
|
---|
| 1394 | if (mi->popup())
|
---|
| 1395 | sz.setWidth( sz.width() + sgiTabSpacing );
|
---|
| 1396 | #endif
|
---|
| 1397 | break;
|
---|
| 1398 | }
|
---|
| 1399 |
|
---|
| 1400 | default:
|
---|
| 1401 | sz = QMotifStyle::sizeFromContents( contents, widget, contentsSize, opt );
|
---|
| 1402 | break;
|
---|
| 1403 | }
|
---|
| 1404 |
|
---|
| 1405 | return sz;
|
---|
| 1406 | }
|
---|
| 1407 |
|
---|
| 1408 | /*! \reimp */
|
---|
| 1409 | QRect QSGIStyle::subRect( SubRect r, const QWidget *widget ) const
|
---|
| 1410 | {
|
---|
| 1411 | QRect rect;
|
---|
| 1412 |
|
---|
| 1413 | switch ( r ) {
|
---|
| 1414 | case SR_ComboBoxFocusRect:
|
---|
| 1415 | {
|
---|
| 1416 | int awh, ax, ay, sh, sy, dh, ew;
|
---|
| 1417 | int fw = pixelMetric( PM_DefaultFrameWidth, widget );
|
---|
| 1418 | QRect tr = widget->rect();
|
---|
| 1419 |
|
---|
| 1420 | tr.addCoords( fw, fw, -fw, -fw );
|
---|
| 1421 | get_combo_parameters( tr, ew, awh, ax, ay, sh, dh, sy );
|
---|
| 1422 | rect.setRect(ax-2, ay-2, awh+4, awh+sh+dh+4);
|
---|
| 1423 | }
|
---|
| 1424 | break;
|
---|
| 1425 | default:
|
---|
| 1426 | return QMotifStyle::subRect( r, widget );
|
---|
| 1427 | }
|
---|
| 1428 |
|
---|
| 1429 | return rect;
|
---|
| 1430 | }
|
---|
| 1431 |
|
---|
| 1432 | /*! \reimp */
|
---|
| 1433 | QRect QSGIStyle::querySubControlMetrics( ComplexControl control,
|
---|
| 1434 | const QWidget *widget,
|
---|
| 1435 | SubControl sub,
|
---|
| 1436 | const QStyleOption& opt ) const
|
---|
| 1437 | {
|
---|
| 1438 | switch ( control ) {
|
---|
| 1439 | case CC_ComboBox:
|
---|
| 1440 | switch ( sub ) {
|
---|
| 1441 | case SC_ComboBoxFrame:
|
---|
| 1442 | return widget->rect();
|
---|
| 1443 |
|
---|
| 1444 | case SC_ComboBoxArrow: {
|
---|
| 1445 | int ew, awh, sh, dh, ax, ay, sy;
|
---|
| 1446 | int fw = pixelMetric( PM_DefaultFrameWidth, widget );
|
---|
| 1447 | QRect cr = widget->rect();
|
---|
| 1448 | cr.addCoords( fw, fw, -fw, -fw );
|
---|
| 1449 | get_combo_parameters( cr, ew, awh, ax, ay, sh, dh, sy );
|
---|
| 1450 | return QRect( ax, ay, awh, awh ); }
|
---|
| 1451 |
|
---|
| 1452 | case SC_ComboBoxEditField: {
|
---|
| 1453 | int fw = pixelMetric( PM_DefaultFrameWidth, widget );
|
---|
| 1454 | QRect rect = widget->rect();
|
---|
| 1455 | rect.addCoords( fw, fw, -fw, -fw );
|
---|
| 1456 | int ew = get_combo_extra_width( rect.height() );
|
---|
| 1457 | rect.addCoords( 1, 1, -1-ew, -1 );
|
---|
| 1458 | return rect; }
|
---|
| 1459 |
|
---|
| 1460 | default:
|
---|
| 1461 | break;
|
---|
| 1462 | }
|
---|
| 1463 | break;
|
---|
| 1464 | case CC_ScrollBar:
|
---|
| 1465 | return QCommonStyle::querySubControlMetrics( control, widget, sub, opt );
|
---|
| 1466 | default: break;
|
---|
| 1467 | }
|
---|
| 1468 | return QMotifStyle::querySubControlMetrics( control, widget, sub, opt );
|
---|
| 1469 | }
|
---|
| 1470 |
|
---|
| 1471 | #endif // QT_NO_STYLE_SGI
|
---|