breezestyle.cpp 288 KB
Newer Older
Hugo Pereira Da Costa's avatar
Hugo Pereira Da Costa committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/*************************************************************************
 * Copyright (C) 2014 by Hugo Pereira Da Costa <hugo.pereira@free.fr>    *
 *                                                                       *
 * This program is free software; you can redistribute it and/or modify  *
 * it under the terms of the GNU General Public License as published by  *
 * the Free Software Foundation; either version 2 of the License, or     *
 * (at your option) any later version.                                   *
 *                                                                       *
 * This program is distributed in the hope that it will be useful,       *
 * but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 * GNU General Public License for more details.                          *
 *                                                                       *
 * You should have received a copy of the GNU General Public License     *
 * along with this program; if not, write to the                         *
 * Free Software Foundation, Inc.,                                       *
 * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA .        *
 *************************************************************************/
19
20
21

#include "breezestyle.h"

22
#include "breeze.h"
23
#include "breezeanimations.h"
24
#include "breezeframeshadow.h"
25
#include "breezemdiwindowshadow.h"
26
#include "breezemnemonics.h"
27
#include "breezepropertynames.h"
28
#include "breezeshadowhelper.h"
Hugo Pereira Da Costa's avatar
Hugo Pereira Da Costa committed
29
#include "breezesplitterproxy.h"
30
#include "breezestyleconfigdata.h"
31
#include "breezewidgetexplorer.h"
32
#include "breezewindowmanager.h"
33
#include "breezeblurhelper.h"
34
35
36
37
38
39
40
41
42

#include <KColorUtils>

#include <QApplication>
#include <QCheckBox>
#include <QComboBox>
#include <QDial>
#include <QDBusConnection>
#include <QDockWidget>
43
#include <QFormLayout>
44
#include <QGraphicsView>
45
46
#include <QGroupBox>
#include <QLineEdit>
47
#include <QMainWindow>
48
#include <QMdiSubWindow>
49
#include <QMenu>
50
51
52
53
#include <QPainter>
#include <QPushButton>
#include <QRadioButton>
#include <QScrollBar>
54
#include <QItemDelegate>
55
56
#include <QSplitterHandle>
#include <QTextEdit>
57
#include <QToolBar>
58
59
#include <QToolBox>
#include <QToolButton>
60
#include <QTreeView>
61
#include <QWidgetAction>
62

63
64
65
66
#if BREEZE_HAVE_QTQUICK
#include <QQuickWindow>
#endif

67
68
namespace BreezePrivate
{
69

70
71
72
73
74
75
    // needed to keep track of tabbars when being dragged
    class TabBarData: public QObject
    {

        public:

Hugo Pereira Da Costa's avatar
doxygen    
Hugo Pereira Da Costa committed
76
        //* constructor
77
78
79
80
        explicit TabBarData( QObject* parent ):
            QObject( parent )
        {}

Hugo Pereira Da Costa's avatar
doxygen    
Hugo Pereira Da Costa committed
81
        //* assign target tabBar
82
83
84
        void lock( const QWidget* widget )
        { _tabBar = widget; }

Hugo Pereira Da Costa's avatar
doxygen    
Hugo Pereira Da Costa committed
85
        //* true if tabbar is locked
86
87
88
        bool isLocked( const QWidget* widget ) const
        { return _tabBar && _tabBar.data() == widget; }

Hugo Pereira Da Costa's avatar
doxygen    
Hugo Pereira Da Costa committed
89
        //* release
90
        void release()
91
92
93
94
        { _tabBar.clear(); }

        private:

Hugo Pereira Da Costa's avatar
doxygen    
Hugo Pereira Da Costa committed
95
        //* pointer to target tabBar
96
        Breeze::WeakPointer<const QWidget> _tabBar;
97
98
99

    };

100
    //* needed to have spacing added to items in combobox
101
102
103
104
105
    class ComboBoxItemDelegate: public QItemDelegate
    {

        public:

106
        //* constructor
107
        explicit ComboBoxItemDelegate( QAbstractItemView* parent ):
108
109
110
111
112
            QItemDelegate( parent ),
            _proxy( parent->itemDelegate() ),
            _itemMargin( Breeze::Metrics::ItemView_ItemMarginWidth )
        {}

113
        //* paint
114
        void paint( QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
115
116
117
118
119
120
        {
            // call either proxy or parent class
            if( _proxy ) _proxy.data()->paint( painter, option, index );
            else QItemDelegate::paint( painter, option, index );
        }

121
        //* size hint for index
122
        QSize sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const override
123
124
125
        {

            // get size from either proxy or parent class
126
            auto size( _proxy ?
127
128
129
130
131
132
133
134
135
136
137
                _proxy.data()->sizeHint( option, index ):
                QItemDelegate::sizeHint( option, index ) );

            // adjust and return
            if( size.isValid() ) { size.rheight() += _itemMargin*2; }
            return size;

        }

        private:

138
        //* proxy
139
140
        Breeze::WeakPointer<QAbstractItemDelegate> _proxy;

141
        //* margin
142
143
144
145
        int _itemMargin;

    };

146
147
148
149
150
151
    //_______________________________________________________________
    #if !BREEZE_USE_KDE4
    bool isProgressBarHorizontal( const QStyleOptionProgressBar* option )
    {  return option && ( (option->state & QStyle::State_Horizontal ) || option->orientation == Qt::Horizontal ); }
    #endif

152
153
}

154
155
156
157
namespace Breeze
{

    //______________________________________________________________
158
    Style::Style():
159

160
        #if BREEZE_USE_KDE4
161
        _helper( new Helper( "breeze" ) )
162
        #else
163
        _helper( new Helper( StyleConfigData::self()->sharedConfig() ) )
164
165
        #endif

166
167
168
        , _shadowHelper( new ShadowHelper( this, *_helper ) )
        , _animations( new Animations( this ) )
        , _mnemonics( new Mnemonics( this ) )
169
170
171
172
173

        #if !BREEZE_USE_KDE4
        , _blurHelper( new BlurHelper( this ) )
        #endif

174
175
176
177
        , _windowManager( new WindowManager( this ) )
        , _frameShadowFactory( new FrameShadowFactory( this ) )
        , _mdiWindowShadowFactory( new MdiWindowShadowFactory( this ) )
        , _splitterFactory( new SplitterFactory( this ) )
178
        , _widgetExplorer( new WidgetExplorer( this ) )
179
        , _tabBarData( new BreezePrivate::TabBarData( this ) )
180
        #if BREEZE_HAVE_KSTYLE||BREEZE_USE_KDE4
181
        , SH_ArgbDndWindow( newStyleHint( QStringLiteral( "SH_ArgbDndWindow" ) ) )
182
        , CE_CapacityBar( newControlElement( QStringLiteral( "CE_CapacityBar" ) ) )
183
        #endif
184
185
186
    {

        // use DBus connection to update on breeze configuration change
187
        auto dbus = QDBusConnection::sessionBus();
188
189
190
191
192
        dbus.connect( QString(),
            QStringLiteral( "/BreezeStyle" ),
            QStringLiteral( "org.kde.Breeze.Style" ),
            QStringLiteral( "reparseConfiguration" ), this, SLOT(configurationChanged()) );

193
194
195
196
        dbus.connect( QString(),
            QStringLiteral( "/BreezeDecoration" ),
            QStringLiteral( "org.kde.Breeze.Style" ),
            QStringLiteral( "reparseConfiguration" ), this, SLOT(configurationChanged()) );
197
198
199
200
        #if !BREEZE_USE_KDE4
        #if QT_VERSION < 0x050D00 // Check if Qt version < 5.13
        this->addEventFilter(qApp);
        #else
201
        connect(qApp, &QApplication::paletteChanged, this, &Style::configurationChanged);
202
203
        #endif
        #endif
204
205
206
207
208
209
210
        // call the slot directly; this initial call will set up things that also
        // need to be reset when the system palette changes
        loadConfiguration();

    }

    //______________________________________________________________
211
    Style::~Style()
212
213
214
215
    {
        delete _shadowHelper;
        delete _helper;
    }
216
217
218
219
220
221
222

    //______________________________________________________________
    void Style::polish( QWidget* widget )
    {
        if( !widget ) return;

        // register widget to animations
223
224
        _animations->registerWidget( widget );
        _windowManager->registerWidget( widget );
225
        _frameShadowFactory->registerWidget( widget, *_helper );
226
        _mdiWindowShadowFactory->registerWidget( widget );
Hugo Pereira Da Costa's avatar
Hugo Pereira Da Costa committed
227
228
        _shadowHelper->registerWidget( widget );
        _splitterFactory->registerWidget( widget );
229

230
        // enable mouse over effects for all necessary widgets
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
        if(
            qobject_cast<QAbstractItemView*>( widget )
            || qobject_cast<QAbstractSpinBox*>( widget )
            || qobject_cast<QCheckBox*>( widget )
            || qobject_cast<QComboBox*>( widget )
            || qobject_cast<QDial*>( widget )
            || qobject_cast<QLineEdit*>( widget )
            || qobject_cast<QPushButton*>( widget )
            || qobject_cast<QRadioButton*>( widget )
            || qobject_cast<QScrollBar*>( widget )
            || qobject_cast<QSlider*>( widget )
            || qobject_cast<QSplitterHandle*>( widget )
            || qobject_cast<QTabBar*>( widget )
            || qobject_cast<QTextEdit*>( widget )
            || qobject_cast<QToolButton*>( widget )
246
            || widget->inherits( "KTextEditor::View" )
247
248
249
            )
        { widget->setAttribute( Qt::WA_Hover ); }

250
251
252
253
254
255
256
        // enforce translucency for drag and drop window
        if( widget->testAttribute( Qt::WA_X11NetWmWindowTypeDND ) && _helper->compositingActive() )
        {
            widget->setAttribute( Qt::WA_TranslucentBackground );
            widget->clearMask();
        }

257
258
259
        // scrollarea polishing is somewhat complex. It is moved to a dedicated method
        polishScrollArea( qobject_cast<QAbstractScrollArea*>( widget ) );

260
        if( auto itemView = qobject_cast<QAbstractItemView*>( widget ) )
261
262
        {

263
            // enable mouse over effects in itemviews' viewport
264
265
            itemView->viewport()->setAttribute( Qt::WA_Hover );

266
        } else if( auto groupBox = qobject_cast<QGroupBox*>( widget ) )  {
267
268
269
270
271
272
273
274
275
276
277
278
279

            // checkable group boxes
            if( groupBox->isCheckable() )
            { groupBox->setAttribute( Qt::WA_Hover ); }

        } else if( qobject_cast<QAbstractButton*>( widget ) && qobject_cast<QDockWidget*>( widget->parent() ) ) {

            widget->setAttribute( Qt::WA_Hover );

        } else if( qobject_cast<QAbstractButton*>( widget ) && qobject_cast<QToolBox*>( widget->parent() ) ) {

            widget->setAttribute( Qt::WA_Hover );

280
281
282
        } else if( qobject_cast<QFrame*>( widget ) && widget->parent() && widget->parent()->inherits( "KTitleWidget" ) ) {

            widget->setAutoFillBackground( false );
283
284
            if( !StyleConfigData::titleWidgetDrawFrame() )
            { widget->setBackgroundRole( QPalette::Window ); }
285

286
287
288
289
        }

        if( qobject_cast<QScrollBar*>( widget ) )
        {
Hugo Pereira Da Costa's avatar
Hugo Pereira Da Costa committed
290

291
            // remove opaque painting for scrollbars
292
293
            widget->setAttribute( Qt::WA_OpaquePaintEvent, false );

294
295
296
297
        } else if( widget->inherits( "KTextEditor::View" ) ) {

            addEventFilter( widget );

298
        } else if( auto toolButton = qobject_cast<QToolButton*>( widget ) ) {
299

300
301
302
303
304
305
            if( toolButton->autoRaise() )
            {
                // for flat toolbuttons, adjust foreground and background role accordingly
                widget->setBackgroundRole( QPalette::NoRole );
                widget->setForegroundRole( QPalette::WindowText );
            }
306

307
308
309
310
311
            if( widget->parentWidget() &&
                widget->parentWidget()->parentWidget() &&
                widget->parentWidget()->parentWidget()->inherits( "Gwenview::SideBarGroup" ) )
            { widget->setProperty( PropertyNames::toolButtonAlignment, Qt::AlignLeft ); }

312
313
        } else if( qobject_cast<QDockWidget*>( widget ) ) {

314
315
            // add event filter on dock widgets
            // and alter palette
316
317
318
319
            widget->setAutoFillBackground( false );
            widget->setContentsMargins( Metrics::Frame_FrameWidth, Metrics::Frame_FrameWidth, Metrics::Frame_FrameWidth, Metrics::Frame_FrameWidth );
            addEventFilter( widget );

320
321
322
        } else if( qobject_cast<QMdiSubWindow*>( widget ) ) {

            widget->setAutoFillBackground( false );
323
            addEventFilter( widget );
324

325
326
327
328
329
330
331
332
333
334
335
        } else if( qobject_cast<QToolBox*>( widget ) ) {

            widget->setBackgroundRole( QPalette::NoRole );
            widget->setAutoFillBackground( false );

        } else if( widget->parentWidget() && widget->parentWidget()->parentWidget() && qobject_cast<QToolBox*>( widget->parentWidget()->parentWidget()->parentWidget() ) ) {

            widget->setBackgroundRole( QPalette::NoRole );
            widget->setAutoFillBackground( false );
            widget->parentWidget()->setAutoFillBackground( false );

336
337
338
339
        } else if( qobject_cast<QMenu*>( widget ) ) {

            setTranslucentBackground( widget );

340
341
342
343
344
345
            #if !BREEZE_USE_KDE4
            if ( _helper->hasAlphaChannel( widget ) && StyleConfigData::menuOpacity() < 100 ) {
                _blurHelper->registerWidget( widget->window() );
            }
            #endif

346
347
348
349
350
        #if QT_VERSION >= 0x050000
        } else if( qobject_cast<QCommandLinkButton*>( widget ) ) {

            addEventFilter( widget );
        #endif
351
        } else if( auto comboBox = qobject_cast<QComboBox*>( widget ) ) {
352

Hugo Pereira Da Costa's avatar
Hugo Pereira Da Costa committed
353
354
            if( !hasParent( widget, "QWebView" ) )
            {
355
                auto itemView( comboBox->view() );
Hugo Pereira Da Costa's avatar
Hugo Pereira Da Costa committed
356
357
358
                if( itemView && itemView->itemDelegate() && itemView->itemDelegate()->inherits( "QComboBoxDelegate" ) )
                { itemView->setItemDelegate( new BreezePrivate::ComboBoxItemDelegate( itemView ) ); }
            }
359

360
361
362
363
364
365
366
367
        } else if( widget->inherits( "QComboBoxPrivateContainer" ) ) {

            addEventFilter( widget );
            setTranslucentBackground( widget );

        } else if( widget->inherits( "QTipLabel" ) ) {

            setTranslucentBackground( widget );
368

369
370
371
        }

        // base class polishing
372
        ParentStyleClass::polish( widget );
373
374
375

    }

376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
    //______________________________________________________________
    void Style::polishScrollArea( QAbstractScrollArea* scrollArea )
    {

        // check argument
        if( !scrollArea ) return;

        // enable mouse over effect in sunken scrollareas that support focus
        if( scrollArea->frameShadow() == QFrame::Sunken && scrollArea->focusPolicy()&Qt::StrongFocus )
        { scrollArea->setAttribute( Qt::WA_Hover ); }

        if( scrollArea->viewport() && scrollArea->inherits( "KItemListContainer" ) && scrollArea->frameShape() == QFrame::NoFrame )
        {
            scrollArea->viewport()->setBackgroundRole( QPalette::Window );
            scrollArea->viewport()->setForegroundRole( QPalette::WindowText );
        }

        // add event filter, to make sure proper background is rendered behind scrollbars
        addEventFilter( scrollArea );

        // force side panels as flat, on option
        if( scrollArea->inherits( "KDEPrivate::KPageListView" ) || scrollArea->inherits( "KDEPrivate::KPageTreeView" ) )
        { scrollArea->setProperty( PropertyNames::sidePanelView, true ); }

        // for all side view panels, unbold font (design choice)
        if( scrollArea->property( PropertyNames::sidePanelView ).toBool() )
        {
            // upbold list font
404
            auto font( scrollArea->font() );
405
406
407
408
409
410
411
412
413
414
            font.setBold( false );
            scrollArea->setFont( font );
        }

        // disable autofill background for flat (== NoFrame) scrollareas, with QPalette::Window as a background
        // this fixes flat scrollareas placed in a tinted widget, such as groupboxes, tabwidgets or framed dock-widgets
        if( !(scrollArea->frameShape() == QFrame::NoFrame || scrollArea->backgroundRole() == QPalette::Window ) )
        { return; }

        // get viewport and check background role
415
        auto viewport( scrollArea->viewport() );
416
417
418
419
420
421
422
423
424
425
426
427
        if( !( viewport && viewport->backgroundRole() == QPalette::Window ) ) return;

        // change viewport autoFill background.
        // do the same for all children if the background role is QPalette::Window
        viewport->setAutoFillBackground( false );
        QList<QWidget*> children( viewport->findChildren<QWidget*>() );
        foreach( QWidget* child, children )
        {
            if( child->parent() == viewport && child->backgroundRole() == QPalette::Window )
            { child->setAutoFillBackground( false ); }
        }

428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
        /*
        QTreeView animates expanding/collapsing branches. It paints them into a
        temp pixmap whose background is unconditionally filled with the palette's
        *base* color which is usually different from the window's color
        cf. QTreeViewPrivate::renderTreeToPixmapForAnimation()
        */
        if( auto treeView = qobject_cast<QTreeView *>( scrollArea ) )
        {
            if (treeView->isAnimated())
            {
                QPalette pal( treeView->palette() );
                pal.setColor( QPalette::Active, QPalette::Base, treeView->palette().color( treeView->backgroundRole() ) );
                treeView->setPalette(pal);
            }
        }

444
445
    }

446
447
448
449
450
    //_______________________________________________________________
    void Style::unpolish( QWidget* widget )
    {

        // register widget to animations
451
452
        _animations->unregisterWidget( widget );
        _frameShadowFactory->unregisterWidget( widget );
453
        _mdiWindowShadowFactory->unregisterWidget( widget );
Hugo Pereira Da Costa's avatar
Hugo Pereira Da Costa committed
454
455
456
        _shadowHelper->unregisterWidget( widget );
        _windowManager->unregisterWidget( widget );
        _splitterFactory->unregisterWidget( widget );
457

458
459
460
461
        #if !BREEZE_USE_KDE4
        _blurHelper->unregisterWidget( widget );
        #endif

462
463
464
465
466
467
468
        // remove event filter
        if( qobject_cast<QAbstractScrollArea*>( widget ) ||
            qobject_cast<QDockWidget*>( widget ) ||
            qobject_cast<QMdiSubWindow*>( widget ) ||
            widget->inherits( "QComboBoxPrivateContainer" ) )
            { widget->removeEventFilter( this ); }

469
        ParentStyleClass::unpolish( widget );
470
471
472
473
474
475
476
477
478
479
480

    }

    //______________________________________________________________
    int Style::pixelMetric( PixelMetric metric, const QStyleOption* option, const QWidget* widget ) const
    {

        // handle special cases
        switch( metric )
        {

481
            // frame width
Hugo Pereira Da Costa's avatar
Hugo Pereira Da Costa committed
482
            case PM_DefaultFrameWidth:
483
            if( qobject_cast<const QMenu*>( widget ) ) return Metrics::Menu_FrameWidth;
484
            if( qobject_cast<const QLineEdit*>( widget ) ) return Metrics::LineEdit_FrameWidth;
485
            #if QT_VERSION >= 0x050000
486
            else if( isQtQuickControl( option, widget ) )
487
488
            {
                const QString &elementType = option->styleObject->property( "elementType" ).toString();
489
                if( elementType == QLatin1String( "edit" ) || elementType == QLatin1String( "spinbox" ) )
490
491
                {

492
                    return Metrics::LineEdit_FrameWidth;
493

494
                } else if( elementType == QLatin1String( "combobox" ) ) {
495

496
                    return Metrics::ComboBox_FrameWidth;
497
498
499
                }

            }
500
            #endif
501
502
503
504

            // fallback
            return Metrics::Frame_FrameWidth;

Hugo Pereira Da Costa's avatar
Hugo Pereira Da Costa committed
505
            case PM_ComboBoxFrameWidth:
506
            {
507
                const auto comboBoxOption( qstyleoption_cast< const QStyleOptionComboBox*>( option ) );
508
509
510
                return comboBoxOption && comboBoxOption->editable ? Metrics::LineEdit_FrameWidth : Metrics::ComboBox_FrameWidth;
            }

Hugo Pereira Da Costa's avatar
Hugo Pereira Da Costa committed
511
512
513
            case PM_SpinBoxFrameWidth: return Metrics::SpinBox_FrameWidth;
            case PM_ToolBarFrameWidth: return Metrics::ToolBar_FrameWidth;
            case PM_ToolTipLabelFrameWidth: return Metrics::ToolTip_FrameWidth;
514

515
516
517
518
519
520
521
            // layout
            case PM_LayoutLeftMargin:
            case PM_LayoutTopMargin:
            case PM_LayoutRightMargin:
            case PM_LayoutBottomMargin:
            {
                /*
Hugo Pereira Da Costa's avatar
Hugo Pereira Da Costa committed
522
523
524
                 * use either Child margin or TopLevel margin,
                 * depending on  widget type
                 */
525
526
527
528
529
                if( ( option && ( option->state & QStyle::State_Window ) ) || ( widget && widget->isWindow() ) )
                {

                    return Metrics::Layout_TopLevelMarginWidth;

530
531
532
533
                } else if( widget && widget->inherits( "KPageView" ) ) {

                    return 0;

534
535
536
537
538
539
540
541
                } else {

                    return Metrics::Layout_ChildMarginWidth;

                }

            }

542
543
            case PM_LayoutHorizontalSpacing: return Metrics::Layout_DefaultSpacing;
            case PM_LayoutVerticalSpacing: return Metrics::Layout_DefaultSpacing;
544

545
            // buttons
546
547
            case PM_ButtonMargin:
            {
Hugo Pereira Da Costa's avatar
Hugo Pereira Da Costa committed
548
                // needs special case for kcalc buttons, to prevent the application to set too small margins
549
550
551
552
                if( widget && widget->inherits( "KCalcButton" ) ) return Metrics::Button_MarginWidth + 4;
                else return Metrics::Button_MarginWidth;
            }

553
554
555
556
            case PM_ButtonDefaultIndicator: return 0;
            case PM_ButtonShiftHorizontal: return 0;
            case PM_ButtonShiftVertical: return 0;

Hugo Pereira Da Costa's avatar
Hugo Pereira Da Costa committed
557
558
559
560
561
562
563
            // menubars
            case PM_MenuBarPanelWidth: return 0;
            case PM_MenuBarHMargin: return 0;
            case PM_MenuBarVMargin: return 0;
            case PM_MenuBarItemSpacing: return 0;
            case PM_MenuDesktopFrameWidth: return 0;

564
            // menu buttons
565
            case PM_MenuButtonIndicator: return Metrics::MenuButton_IndicatorWidth;
566

Hugo Pereira Da Costa's avatar
Hugo Pereira Da Costa committed
567
            // toolbars
568
            case PM_ToolBarHandleExtent: return Metrics::ToolBar_HandleExtent;
Hugo Pereira Da Costa's avatar
Hugo Pereira Da Costa committed
569
            case PM_ToolBarSeparatorExtent: return Metrics::ToolBar_SeparatorWidth;
570
571
            case PM_ToolBarExtensionExtent:
            return pixelMetric( PM_SmallIconSize, option, widget ) + 2*Metrics::ToolButton_MarginWidth;
Hugo Pereira Da Costa's avatar
Hugo Pereira Da Costa committed
572
573
574
575
576

            case PM_ToolBarItemMargin: return 0;
            case PM_ToolBarItemSpacing: return Metrics::ToolBar_ItemSpacing;

            // tabbars
577
578
            case PM_TabBarTabShiftVertical: return 0;
            case PM_TabBarTabShiftHorizontal: return 0;
579
580
            case PM_TabBarTabOverlap: return Metrics::TabBar_TabOverlap;
            case PM_TabBarBaseOverlap: return Metrics::TabBar_BaseOverlap;
581
            case PM_TabBarTabHSpace: return 2*Metrics::TabBar_TabMarginWidth;
Hugo Pereira Da Costa's avatar
Hugo Pereira Da Costa committed
582
            case PM_TabBarTabVSpace: return 2*Metrics::TabBar_TabMarginHeight;
Hugo Pereira Da Costa's avatar
Hugo Pereira Da Costa committed
583
584
585
            case PM_TabCloseIndicatorWidth:
            case PM_TabCloseIndicatorHeight:
            return pixelMetric( PM_SmallIconSize, option, widget );
586

587
            // scrollbars
588
589
590
            case PM_ScrollBarExtent: return Metrics::ScrollBar_Extend;
            case PM_ScrollBarSliderMin: return Metrics::ScrollBar_MinSliderHeight;

591
592
593
            // title bar
            case PM_TitleBarHeight: return 2*Metrics::TitleBar_MarginWidth + pixelMetric( PM_SmallIconSize, option, widget );

594
            // sliders
595
            case PM_SliderThickness: return Metrics::Slider_ControlThickness;
596
597
598
            case PM_SliderControlThickness: return Metrics::Slider_ControlThickness;
            case PM_SliderLength: return Metrics::Slider_ControlThickness;

599
            // checkboxes and radio buttons
600
601
602
603
            case PM_IndicatorWidth: return Metrics::CheckBox_Size;
            case PM_IndicatorHeight: return Metrics::CheckBox_Size;
            case PM_ExclusiveIndicatorWidth: return Metrics::CheckBox_Size;
            case PM_ExclusiveIndicatorHeight: return Metrics::CheckBox_Size;
604

605
            // list heaaders
606
            case PM_HeaderMarkSize: return Metrics::Header_ArrowSize;
607
            case PM_HeaderMargin: return Metrics::Header_MarginWidth;
Hugo Pereira Da Costa's avatar
Hugo Pereira Da Costa committed
608

609
610
611
            // dock widget
            // return 0 here, since frame is handled directly in polish
            case PM_DockWidgetFrameWidth: return 0;
612
613
614
615
            case PM_DockWidgetTitleMargin: return Metrics::Frame_FrameWidth;
            case PM_DockWidgetTitleBarButtonMargin: return Metrics::ToolButton_MarginWidth;

            case PM_SplitterWidth: return Metrics::Splitter_SplitterWidth;
616
            case PM_DockWidgetSeparatorExtent: return Metrics::Splitter_SplitterWidth;
617

618
            // fallback
619
            default: return ParentStyleClass::pixelMetric( metric, option, widget );
620
621
622
623
624
625
626
627
628
629
630

        }

    }

    //______________________________________________________________
    int Style::styleHint( StyleHint hint, const QStyleOption* option, const QWidget* widget, QStyleHintReturn* returnData ) const
    {
        switch( hint )
        {

631
632
633
            case SH_RubberBand_Mask:
            {

634
                if( auto mask = qstyleoption_cast<QStyleHintReturnMask*>( returnData ) )
635
636
637
638
                {

                    mask->region = option->rect;

Hugo Pereira Da Costa's avatar
Hugo Pereira Da Costa committed
639
640
641
642
643
644
                    /*
                     * need to check on widget before removing inner region
                     * in order to still preserve rubberband in MainWindow and QGraphicsView
                     * in QMainWindow because it looks better
                     * in QGraphicsView because the painting fails completely otherwise
                     */
645
646
647
648
649
650
651
652
653
654
655
656
657
                    if( widget && (
                        qobject_cast<const QAbstractItemView*>( widget->parent() ) ||
                        qobject_cast<const QGraphicsView*>( widget->parent() ) ||
                        qobject_cast<const QMainWindow*>( widget->parent() ) ) )
                    { return true; }

                    // also check if widget's parent is some itemView viewport
                    if( widget && widget->parent() &&
                        qobject_cast<const QAbstractItemView*>( widget->parent()->parent() ) &&
                        static_cast<const QAbstractItemView*>( widget->parent()->parent() )->viewport() == widget->parent() )
                    { return true; }

                    // mask out center
Hugo Pereira Da Costa's avatar
Hugo Pereira Da Costa committed
658
                    mask->region -= insideMargin( option->rect, 1 );
659
660
661
662
663
664

                    return true;
                }
                return false;
            }

Hugo Pereira Da Costa's avatar
Hugo Pereira Da Costa committed
665
666
667
            case SH_ComboBox_ListMouseTracking: return true;
            case SH_MenuBar_MouseTracking: return true;
            case SH_Menu_MouseTracking: return true;
668
669
            case SH_Menu_SubMenuPopupDelay: return 150;
            case SH_Menu_SloppySubMenus: return true;
670
671

            #if QT_VERSION >= 0x050000
672
            // TODO Qt6: drop deprecated SH_Widget_Animate
Hugo Pereira Da Costa's avatar
Hugo Pereira Da Costa committed
673
            case SH_Widget_Animate: return StyleConfigData::animationsEnabled();
674
            case SH_Menu_SupportsSections: return true;
675
            #endif
676
677
678
            #if QT_VERSION >= 0x050A00
            case SH_Widget_Animation_Duration: return StyleConfigData::animationsEnabled() ? StyleConfigData::animationsDuration() : 0;
            #endif
679

680
681
            case SH_DialogButtonBox_ButtonsHaveIcons: return true;

682
            case SH_GroupBox_TextLabelVerticalAlignment: return Qt::AlignVCenter;
683
            case SH_TabBar_Alignment: return StyleConfigData::tabBarDrawCenteredTabs() ? Qt::AlignCenter:Qt::AlignLeft;
684
            case SH_ToolBox_SelectedPageTitleBold: return false;
685
            case SH_ScrollBar_MiddleClickAbsolutePosition: return true;
686
            case SH_ScrollView_FrameOnlyAroundContents: return false;
687
688
689
690
691
            case SH_FormLayoutFormAlignment: return Qt::AlignLeft | Qt::AlignTop;
            case SH_FormLayoutLabelAlignment: return Qt::AlignRight;
            case SH_FormLayoutFieldGrowthPolicy: return QFormLayout::ExpandingFieldsGrow;
            case SH_FormLayoutWrapPolicy: return QFormLayout::DontWrapRows;
            case SH_MessageBox_TextInteractionFlags: return Qt::TextSelectableByMouse | Qt::LinksAccessibleByMouse;
692
693
            case SH_ProgressDialog_CenterCancelButton: return false;
            case SH_MessageBox_CenterButtons: return false;
694
695

            case SH_RequestSoftwareInputPanel: return RSIP_OnMouseClick;
Hugo Pereira Da Costa's avatar
Hugo Pereira Da Costa committed
696
            case SH_TitleBar_NoBorder: return true;
697
            case SH_DockWidget_ButtonsHaveFrame: return false;
698
            default: return ParentStyleClass::styleHint( hint, option, widget, returnData );
699
700
701
702
703
704
705
706
707
708
709

        }

    }

    //______________________________________________________________
    QRect Style::subElementRect( SubElement element, const QStyleOption* option, const QWidget* widget ) const
    {
        switch( element )
        {

710
            case SE_PushButtonContents: return pushButtonContentsRect( option, widget );
711
            case SE_CheckBoxContents: return checkBoxContentsRect( option, widget );
712
            case SE_RadioButtonContents: return checkBoxContentsRect( option, widget );
713
            case SE_LineEditContents: return lineEditContentsRect( option, widget );
714
715
716
            case SE_ProgressBarGroove: return progressBarGrooveRect( option, widget );
            case SE_ProgressBarContents: return progressBarContentsRect( option, widget );
            case SE_ProgressBarLabel: return progressBarLabelRect( option, widget );
717
            case SE_FrameContents: return frameContentsRect( option, widget );
718
719
            case SE_HeaderArrow: return headerArrowRect( option, widget );
            case SE_HeaderLabel: return headerLabelRect( option, widget );
720
721
            case SE_TabBarTabLeftButton: return tabBarTabLeftButtonRect( option, widget );
            case SE_TabBarTabRightButton: return tabBarTabRightButtonRect( option, widget );
722
            case SE_TabWidgetTabBar: return tabWidgetTabBarRect( option, widget );
723
724
            case SE_TabWidgetTabContents: return tabWidgetTabContentsRect( option, widget );
            case SE_TabWidgetTabPane: return tabWidgetTabPaneRect( option, widget );
725
726
            case SE_TabWidgetLeftCorner: return tabWidgetCornerRect( SE_TabWidgetLeftCorner, option, widget );
            case SE_TabWidgetRightCorner: return tabWidgetCornerRect( SE_TabWidgetRightCorner, option, widget );
727
728
            case SE_ToolBoxTabContents: return toolBoxTabContentsRect( option, widget );

729
            // fallback
730
            default: return ParentStyleClass::subElementRect( element, option, widget );
731
732
733
734
735
736
737

        }
    }

    //______________________________________________________________
    QRect Style::subControlRect( ComplexControl element, const QStyleOptionComplex* option, SubControl subControl, const QWidget* widget ) const
    {
738

739
740
741
        switch( element )
        {

742
            case CC_GroupBox: return groupBoxSubControlRect( option, subControl, widget );
743
            case CC_ToolButton: return toolButtonSubControlRect( option, subControl, widget );
Hugo Pereira Da Costa's avatar
Hugo Pereira Da Costa committed
744
            case CC_ComboBox: return comboBoxSubControlRect( option, subControl, widget );
Hugo Pereira Da Costa's avatar
Hugo Pereira Da Costa committed
745
            case CC_SpinBox: return spinBoxSubControlRect( option, subControl, widget );
746
            case CC_ScrollBar: return scrollBarSubControlRect( option, subControl, widget );
747
            case CC_Dial: return dialSubControlRect( option, subControl, widget );
748
            case CC_Slider: return sliderSubControlRect( option, subControl, widget );
749
750

            // fallback
751
            default: return ParentStyleClass::subControlRect( element, option, subControl, widget );
752
753
754
755
756
757
758
759
760
761
762

        }

    }

    //______________________________________________________________
    QSize Style::sizeFromContents( ContentsType element, const QStyleOption* option, const QSize& size, const QWidget* widget ) const
    {

        switch( element )
        {
763
764
            case CT_CheckBox: return checkBoxSizeFromContents( option, size, widget );
            case CT_RadioButton: return checkBoxSizeFromContents( option, size, widget );
Hugo Pereira Da Costa's avatar
Hugo Pereira Da Costa committed
765
766
            case CT_LineEdit: return lineEditSizeFromContents( option, size, widget );
            case CT_ComboBox: return comboBoxSizeFromContents( option, size, widget );
Hugo Pereira Da Costa's avatar
Hugo Pereira Da Costa committed
767
            case CT_SpinBox: return spinBoxSizeFromContents( option, size, widget );
768
            case CT_Slider: return sliderSizeFromContents( option, size, widget );
Hugo Pereira Da Costa's avatar
Hugo Pereira Da Costa committed
769
            case CT_PushButton: return pushButtonSizeFromContents( option, size, widget );
770
            case CT_ToolButton: return toolButtonSizeFromContents( option, size, widget );
Hugo Pereira Da Costa's avatar
Hugo Pereira Da Costa committed
771
772
            case CT_MenuBar: return defaultSizeFromContents( option, size, widget );
            case CT_MenuBarItem: return menuBarItemSizeFromContents( option, size, widget );
773
            case CT_MenuItem: return menuItemSizeFromContents( option, size, widget );
774
            case CT_ProgressBar: return progressBarSizeFromContents( option, size, widget );
775
            case CT_TabWidget: return tabWidgetSizeFromContents( option, size, widget );
776
            case CT_TabBarTab: return tabBarTabSizeFromContents( option, size, widget );
777
778
779
            case CT_HeaderSection: return headerSectionSizeFromContents( option, size, widget );
            case CT_ItemViewItem: return itemViewItemSizeFromContents( option, size, widget );

780
            // fallback
781
            default: return ParentStyleClass::sizeFromContents( element, option, size, widget );
782
783
784
785
786
787
788
789
790
791
792
793
        }

    }

    //______________________________________________________________
    QStyle::SubControl Style::hitTestComplexControl( ComplexControl control, const QStyleOptionComplex* option, const QPoint& point, const QWidget* widget ) const
    {
        switch( control )
        {
            case CC_ScrollBar:
            {

794
                auto grooveRect = subControlRect( CC_ScrollBar, option, SC_ScrollBarGroove, widget );
Hugo Pereira Da Costa's avatar
Hugo Pereira Da Costa committed
795
                if( grooveRect.contains( point ) )
796
                {
Hugo Pereira Da Costa's avatar
Hugo Pereira Da Costa committed
797
                    // Must be either page up/page down, or just click on the slider.
798
                    auto sliderRect = subControlRect( CC_ScrollBar, option, SC_ScrollBarSlider, widget );
799

Hugo Pereira Da Costa's avatar
Hugo Pereira Da Costa committed
800
801
                    if( sliderRect.contains( point ) ) return SC_ScrollBarSlider;
                    else if( preceeds( point, sliderRect, option ) ) return SC_ScrollBarSubPage;
802
803
804
805
                    else return SC_ScrollBarAddPage;

                }

Hugo Pereira Da Costa's avatar
Hugo Pereira Da Costa committed
806
                // This is one of the up/down buttons. First, decide which one it is.
Hugo Pereira Da Costa's avatar
Hugo Pereira Da Costa committed
807
                if( preceeds( point, grooveRect, option ) )
808
809
810
811
                {

                    if( _subLineButtons == DoubleButton )
                    {
Hugo Pereira Da Costa's avatar
Hugo Pereira Da Costa committed
812

813
                        auto buttonRect = scrollBarInternalSubControlRect( option, SC_ScrollBarSubLine );
814
                        return scrollBarHitTest( buttonRect, point, option );
Hugo Pereira Da Costa's avatar
Hugo Pereira Da Costa committed
815

816
817
818
819
820
821
822
                    } else return SC_ScrollBarSubLine;

                }

                if( _addLineButtons == DoubleButton )
                {

823
                    auto buttonRect = scrollBarInternalSubControlRect( option, SC_ScrollBarAddLine );
824
825
826
827
828
829
                    return scrollBarHitTest( buttonRect, point, option );

                } else return SC_ScrollBarAddLine;
            }

            // fallback
830
            default: return ParentStyleClass::hitTestComplexControl( control, option, point, widget );
831
832
833
834
835
836
837
838
839

        }

    }

    //______________________________________________________________
    void Style::drawPrimitive( PrimitiveElement element, const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
    {

Hugo Pereira Da Costa's avatar
Hugo Pereira Da Costa committed
840
        StylePrimitive fcn;
841
842
843
        switch( element )
        {

844
            case PE_PanelButtonCommand: fcn = &Style::drawPanelButtonCommandPrimitive; break;
845
            case PE_PanelButtonTool: fcn = &Style::drawPanelButtonToolPrimitive; break;
846
            case PE_PanelScrollAreaCorner: fcn = &Style::drawPanelScrollAreaCornerPrimitive; break;
847
848
            case PE_PanelMenu: fcn = &Style::drawPanelMenuPrimitive; break;
            case PE_PanelTipLabel: fcn = &Style::drawPanelTipLabelPrimitive; break;
Hugo Pereira Da Costa's avatar
Hugo Pereira Da Costa committed
849
            case PE_PanelItemViewItem: fcn = &Style::drawPanelItemViewItemPrimitive; break;
850
851
            case PE_IndicatorCheckBox: fcn = &Style::drawIndicatorCheckBoxPrimitive; break;
            case PE_IndicatorRadioButton: fcn = &Style::drawIndicatorRadioButtonPrimitive; break;
852
            case PE_IndicatorButtonDropDown: fcn = &Style::drawIndicatorButtonDropDownPrimitive; break;
Hugo Pereira Da Costa's avatar
Hugo Pereira Da Costa committed
853
            case PE_IndicatorTabClose: fcn = &Style::drawIndicatorTabClosePrimitive; break;
854
            case PE_IndicatorTabTear: fcn = &Style::drawIndicatorTabTearPrimitive; break;
855
856
857
858
            case PE_IndicatorArrowUp: fcn = &Style::drawIndicatorArrowUpPrimitive; break;
            case PE_IndicatorArrowDown: fcn = &Style::drawIndicatorArrowDownPrimitive; break;
            case PE_IndicatorArrowLeft: fcn = &Style::drawIndicatorArrowLeftPrimitive; break;
            case PE_IndicatorArrowRight: fcn = &Style::drawIndicatorArrowRightPrimitive; break;
859
            case PE_IndicatorHeaderArrow: fcn = &Style::drawIndicatorHeaderArrowPrimitive; break;
860
            case PE_IndicatorToolBarHandle: fcn = &Style::drawIndicatorToolBarHandlePrimitive; break;
861
            case PE_IndicatorToolBarSeparator: fcn = &Style::drawIndicatorToolBarSeparatorPrimitive; break;
862
            case PE_IndicatorBranch: fcn = &Style::drawIndicatorBranchPrimitive; break;
Hugo Pereira Da Costa's avatar
Hugo Pereira Da Costa committed
863
864
            case PE_FrameStatusBar: fcn = &Style::emptyPrimitive; break;
            case PE_Frame: fcn = &Style::drawFramePrimitive; break;
865
            case PE_FrameLineEdit: fcn = &Style::drawFrameLineEditPrimitive; break;
866
            case PE_FrameMenu: fcn = &Style::drawFrameMenuPrimitive; break;
867
            case PE_FrameGroupBox: fcn = &Style::drawFrameGroupBoxPrimitive; break;
868
            case PE_FrameTabWidget: fcn = &Style::drawFrameTabWidgetPrimitive; break;
869
            case PE_FrameTabBarBase: fcn = &Style::drawFrameTabBarBasePrimitive; break;
870
            case PE_FrameWindow: fcn = &Style::drawFrameWindowPrimitive; break;
871
            case PE_FrameFocusRect: fcn = _frameFocusPrimitive; break;
872

873
            // fallback
874
            default: break;
875
876
877

        }

878
879
880
        painter->save();

        // call function if implemented
Hugo Pereira Da Costa's avatar
Hugo Pereira Da Costa committed
881
        if( !( fcn && fcn( *this, option, painter, widget ) ) )
882
        { ParentStyleClass::drawPrimitive( element, option, painter, widget ); }
883
884
885

        painter->restore();

886
887
888
889
890
891
    }

    //______________________________________________________________
    void Style::drawControl( ControlElement element, const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
    {

Hugo Pereira Da Costa's avatar
Hugo Pereira Da Costa committed
892
        StyleControl fcn;
893

894
        #if BREEZE_HAVE_KSTYLE||BREEZE_USE_KDE4
895
        if( element == CE_CapacityBar )
896
        {
897
898
899
900
901
902
            fcn = &Style::drawProgressBarControl;

        } else
        #endif

        switch( element ) {
903

904
905
            case CE_PushButtonBevel: fcn = &Style::drawPanelButtonCommandPrimitive; break;
            case CE_PushButtonLabel: fcn = &Style::drawPushButtonLabelControl; break;
906
907
            case CE_CheckBoxLabel: fcn = &Style::drawCheckBoxLabelControl; break;
            case CE_RadioButtonLabel: fcn = &Style::drawCheckBoxLabelControl; break;
908
            case CE_ToolButtonLabel: fcn = &Style::drawToolButtonLabelControl; break;
Hugo Pereira Da Costa's avatar
Hugo Pereira Da Costa committed
909
            case CE_ComboBoxLabel: fcn = &Style::drawComboBoxLabelControl; break;
910
            case CE_MenuBarEmptyArea: fcn = &Style::emptyControl; break;
Hugo Pereira Da Costa's avatar
Hugo Pereira Da Costa committed
911
            case CE_MenuBarItem: fcn = &Style::drawMenuBarItemControl; break;
912
            case CE_MenuItem: fcn = &Style::drawMenuItemControl; break;
913
            case CE_ToolBar: fcn = &Style::emptyControl; break;
914
915
916
917
            case CE_ProgressBar: fcn = &Style::drawProgressBarControl; break;
            case CE_ProgressBarContents: fcn = &Style::drawProgressBarContentsControl; break;
            case CE_ProgressBarGroove: fcn = &Style::drawProgressBarGrooveControl; break;
            case CE_ProgressBarLabel: fcn = &Style::drawProgressBarLabelControl; break;
918
919
920
            case CE_ScrollBarSlider: fcn = &Style::drawScrollBarSliderControl; break;
            case CE_ScrollBarAddLine: fcn = &Style::drawScrollBarAddLineControl; break;
            case CE_ScrollBarSubLine: fcn = &Style::drawScrollBarSubLineControl; break;
921
922
            case CE_ScrollBarAddPage: fcn = &Style::emptyControl; break;
            case CE_ScrollBarSubPage: fcn = &Style::emptyControl; break;
Hugo Pereira Da Costa's avatar
Hugo Pereira Da Costa committed
923
            case CE_ShapedFrame: fcn = &Style::drawShapedFrameControl; break;
924
            case CE_RubberBand: fcn = &Style::drawRubberBandControl; break;
Hugo Pereira Da Costa's avatar
Hugo Pereira Da Costa committed
925
            case CE_SizeGrip: fcn = &Style::emptyControl; break;
926
927
            case CE_HeaderSection: fcn = &Style::drawHeaderSectionControl; break;
            case CE_HeaderEmptyArea: fcn = &Style::drawHeaderEmptyAreaControl; break;
928
            case CE_TabBarTabLabel: fcn = &Style::drawTabBarTabLabelControl; break;
929
            case CE_TabBarTabShape: fcn = &Style::drawTabBarTabShapeControl; break;
930
931
            case CE_ToolBoxTabLabel: fcn = &Style::drawToolBoxTabLabelControl; break;
            case CE_ToolBoxTabShape: fcn = &Style::drawToolBoxTabShapeControl; break;
932
933
            case CE_DockWidgetTitle: fcn = &Style::drawDockWidgetTitleControl; break;

934
935
936
937
938
939
940
941
            // fallback
            default: break;

        }

        painter->save();

        // call function if implemented
Hugo Pereira Da Costa's avatar
Hugo Pereira Da Costa committed
942
        if( !( fcn && fcn( *this, option, painter, widget ) ) )
943
        { ParentStyleClass::drawControl( element, option, painter, widget ); }
944
945
946
947
948
949
950
951
952

        painter->restore();

    }

    //______________________________________________________________
    void Style::drawComplexControl( ComplexControl element, const QStyleOptionComplex* option, QPainter* painter, const QWidget* widget ) const
    {

Hugo Pereira Da Costa's avatar
Hugo Pereira Da Costa committed
953
        StyleComplexControl fcn;
954
955
        switch( element )
        {
956
            case CC_GroupBox: fcn = &Style::drawGroupBoxComplexControl; break;
957
            case CC_ToolButton: fcn = &Style::drawToolButtonComplexControl; break;
Hugo Pereira Da Costa's avatar
Hugo Pereira Da Costa committed
958
            case CC_ComboBox: fcn = &Style::drawComboBoxComplexControl; break;
Hugo Pereira Da Costa's avatar
Hugo Pereira Da Costa committed
959
            case CC_SpinBox: fcn = &Style::drawSpinBoxComplexControl; break;
960
            case CC_Slider: fcn = &Style::drawSliderComplexControl; break;
961
            case CC_Dial: fcn = &Style::drawDialComplexControl; break;
962
            case CC_ScrollBar: fcn = &Style::drawScrollBarComplexControl; break;
963
            case CC_TitleBar: fcn = &Style::drawTitleBarComplexControl; break;
964

965
            // fallback
966
            default: break;
967
968
        }

969
970
971
972

        painter->save();

        // call function if implemented
Hugo Pereira Da Costa's avatar
Hugo Pereira Da Costa committed
973
        if( !( fcn && fcn( *this, option, painter, widget ) ) )
974
        { ParentStyleClass::drawComplexControl( element, option, painter, widget ); }
975
976
977

        painter->restore();

978
979
980
981
982
    }


    //___________________________________________________________________________________
    void Style::drawItemText(
Hugo Pereira Da Costa's avatar
Hugo Pereira Da Costa committed
983
        QPainter* painter, const QRect& rect, int flags, const QPalette& palette, bool enabled,
984
985
986
        const QString &text, QPalette::ColorRole textRole ) const
    {

987
        // hide mnemonics if requested
Hugo Pereira Da Costa's avatar
Hugo Pereira Da Costa committed
988
        if( !_mnemonics->enabled() && ( flags&Qt::TextShowMnemonic ) && !( flags&Qt::TextHideMnemonic ) )
989
990
991
992
993
        {
            flags &= ~Qt::TextShowMnemonic;
            flags |= Qt::TextHideMnemonic;
        }

994
995
996
997
        // make sure vertical alignment is defined
        // fallback on Align::VCenter if not
        if( !(flags&Qt::AlignVertical_Mask) ) flags |= Qt::AlignVCenter;

998
999
1000
1001
        if( _animations->widgetEnabilityEngine().enabled() )
        {

            /*
Hugo Pereira Da Costa's avatar
Hugo Pereira Da Costa committed
1002
1003
1004
1005
             * check if painter engine is registered to WidgetEnabilityEngine, and animated
             * if yes, merge the palettes. Note: a static_cast is safe here, since only the address
             * of the pointer is used, not the actual content.
             */
1006
1007
1008
1009
            const QWidget* widget( static_cast<const QWidget*>( painter->device() ) );
            if( _animations->widgetEnabilityEngine().isAnimated( widget, AnimationEnable ) )
            {

Hugo Pereira Da Costa's avatar
Hugo Pereira Da Costa committed
1010
1011
                const QPalette copy( _helper->disabledPalette( palette, _animations->widgetEnabilityEngine().opacity( widget, AnimationEnable ) ) );
                return ParentStyleClass::drawItemText( painter, rect, flags, copy, enabled, text, textRole );
1012
1013
1014
1015
1016

            }

        }

1017
        // fallback
Hugo Pereira Da Costa's avatar
Hugo Pereira Da Costa committed
1018
        return ParentStyleClass::drawItemText( painter, rect, flags, palette, enabled, text, textRole );
1019
1020
1021
1022
1023
1024

    }

    //_____________________________________________________________________
    bool Style::eventFilter( QObject *object, QEvent *event )
    {
1025

1026
1027
        if( auto dockWidget = qobject_cast<QDockWidget*>( object ) ) { return eventFilterDockWidget( dockWidget, event ); }
        else if( auto subWindow = qobject_cast<QMdiSubWindow*>( object ) ) { return eventFilterMdiSubWindow( subWindow, event ); }
1028
        #if QT_VERSION >= 0x050000