1
// krazy:excludeall=qclasses
3
//////////////////////////////////////////////////////////////////////////////
5
// Oxygen widget style for KDE 4
8
// Copyright ( C ) 2009-2010 Hugo Pereira Da Costa <hugo@oxygen-icons.org>
9
// Copyright ( C ) 2008 Long Huynh Huu <long.upcase@googlemail.com>
10
// Copyright ( C ) 2007-2008 Casper Boemann <cbr@boemann.dk>
11
// Copyright ( C ) 2007 Matthew Woehlke <mw_triad@users.sourceforge.net>
12
// Copyright ( C ) 2003-2005 Sandro Giessl <sandro@giessl.com>
14
// based on the KDE style "dotNET":
15
// Copyright ( C ) 2001-2002, Chris Lee <clee@kde.org>
16
// Carsten Pfeiffer <pfeiffer@kde.org>
17
// Karol Szwed <gallium@kde.org>
18
// Drawing routines completely reimplemented from KDE3 HighColor, which was
19
// originally based on some stuff from the KDE2 HighColor.
21
// based on drawing routines of the style "Keramik":
22
// Copyright ( c ) 2002 Malte Starostik <malte@kde.org>
23
// ( c ) 2002,2003 Maksim Orlovich <mo002j@mail.rochester.edu>
24
// based on the KDE3 HighColor Style
25
// Copyright ( C ) 2001-2002 Karol Szwed <gallium@kde.org>
26
// ( C ) 2001-2002 Fredrik Höglund <fredrik@kde.org>
27
// Drawing routines adapted from the KDE2 HCStyle,
28
// Copyright ( C ) 2000 Daniel M. Duley <mosfet@kde.org>
29
// ( C ) 2000 Dirk Mueller <mueller@kde.org>
30
// ( C ) 2001 Martijn Klingens <klingens@kde.org>
31
// Progressbar code based on KStyle,
32
// Copyright ( C ) 2001-2002 Karol Szwed <gallium@kde.org>
34
// This library is free software; you can redistribute it and/or
35
// modify it under the terms of the GNU Library General Public
36
// License version 2 as published by the Free Software Foundation.
38
// This library is distributed in the hope that it will be useful,
39
// but WITHOUT ANY WARRANTY; without even the implied warranty of
40
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
41
// Library General Public License for more details.
43
// You should have received a copy of the GNU Library General Public License
44
// along with this library; see the file COPYING.LIB. If not, write to
45
// the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
46
// Boston, MA 02110-1301, USA.
47
//////////////////////////////////////////////////////////////////////////////
49
#include "oxygenstyle.h"
50
#include "oxygenstyle.moc"
52
#include "oxygenanimations.h"
53
#include "oxygenframeshadow.h"
54
#include "oxygenmdiwindowshadow.h"
55
#include "oxygenshadowhelper.h"
56
#include "oxygenstyleconfigdata.h"
57
#include "oxygentransitions.h"
58
#include "oxygenwidgetexplorer.h"
59
#include "oxygenwindowmanager.h"
61
#include <QtCore/QDebug>
62
#include <QtGui/QAbstractButton>
63
#include <QtGui/QAbstractItemView>
64
#include <QtGui/QApplication>
65
#include <QtGui/QCheckBox>
66
#include <QtGui/QComboBox>
67
#include <QtGui/QDial>
68
#include <QtGui/QDialogButtonBox>
69
#include <QtGui/QDockWidget>
70
#include <QtGui/QDoubleSpinBox>
71
#include <QtGui/QFormLayout>
72
#include <QtGui/QFrame>
73
#include <QtGui/QGraphicsView>
74
#include <QtGui/QGroupBox>
75
#include <QtGui/QLayout>
76
#include <QtGui/QLineEdit>
77
#include <QtGui/QMainWindow>
78
#include <QtGui/QMdiSubWindow>
79
#include <QtGui/QPushButton>
80
#include <QtGui/QRadioButton>
81
#include <QtGui/QScrollBar>
82
#include <QtGui/QSpinBox>
83
#include <QtGui/QSplitterHandle>
84
#include <QtGui/QStylePlugin>
85
#include <QtGui/QStyleOption>
86
#include <QtGui/QTextEdit>
87
#include <QtGui/QToolBar>
88
#include <QtGui/QToolBox>
89
#include <QtGui/QToolButton>
91
#include <QtDBus/QDBusConnection>
93
#include <KColorUtils>
95
#include <KGlobalSettings>
96
#include <KIconLoader>
98
#include <kdeversion.h>
102
/* These are to link libkio even if 'smart' linker is used */
103
#include <kio/authinfo.h>
104
extern "C" KIO::AuthInfo* _oxygen_init_kio() { return new KIO::AuthInfo(); }
107
//_____________________________________________
112
class StylePlugin : public QStylePlugin
116
//! returns list of valid keys
117
QStringList keys() const
118
{ return QStringList( QLatin1String( "Oxygen" ) ); }
121
QStyle *create( const QString &key )
124
if( key.toLower() == QLatin1String( "oxygen" ) ) return new Style;
131
Q_EXPORT_PLUGIN2( oxygen-qt, Oxygen::StylePlugin )
136
// hardcoded index offsets for custom widgets
137
// copied from e.g. kstyle.cxx
138
static const QStyle::StyleHint SH_KCustomStyleElement = ( QStyle::StyleHint )0xff000001;
139
static const int X_KdeBase = 0xff000000;
141
//_____________________________________________________________________
142
bool TopLevelManager::eventFilter( QObject *object, QEvent *event )
146
QWidget *widget = static_cast<QWidget*>( object );
147
if( event->type() == QEvent::Show && _helper.hasDecoration( widget ) )
149
_helper.setHasBackgroundGradient( widget->winId(), true );
150
_helper.setHasBackgroundPixmap( widget->winId(), _helper.hasBackgroundPixmap() );
156
//______________________________________________________________
157
Style::Style( void ):
158
_kGlobalSettingsInitialized( false ),
159
_addLineButtons( DoubleButton ),
160
_subLineButtons( SingleButton ),
161
_singleButtonHeight( 14 ),
162
_doubleButtonHeight( 28 ),
163
_showMnemonics( true ),
164
_helper( new StyleHelper( "oxygen" ) ),
165
_shadowHelper( new ShadowHelper( this, *_helper ) ),
166
_animations( new Animations( this ) ),
167
_transitions( new Transitions( this ) ),
168
_windowManager( new WindowManager( this ) ),
169
_topLevelManager( new TopLevelManager( this, *_helper ) ),
170
_frameShadowFactory( new FrameShadowFactory( this ) ),
171
_mdiWindowShadowFactory( new MdiWindowShadowFactory( this, *_helper ) ),
172
_widgetExplorer( new WidgetExplorer( this ) ),
173
_tabBarData( new TabBarData( this ) ),
174
_frameFocusPrimitive( 0 ),
175
_tabBarTabShapeControl( 0 ),
176
_hintCounter( X_KdeBase+1 ),
177
_controlCounter( X_KdeBase ),
178
_subElementCounter( X_KdeBase ),
179
CE_CapacityBar( newControlElement( "CE_CapacityBar" ) )
183
// use DBus connection to update on oxygen configuration change
184
QDBusConnection dbus = QDBusConnection::sessionBus();
185
dbus.connect( QString(), "/OxygenStyle", "org.kde.Oxygen.Style", "reparseConfiguration", this, SLOT( oxygenConfigurationChanged( void ) ) );
187
// call the slot directly; this initial call will set up things that also
188
// need to be reset when the system palette changes
189
oxygenConfigurationChanged();
193
//______________________________________________________________
194
Style::~Style( void )
197
//______________________________________________________________
198
void Style::polish( QWidget* widget )
200
if( !widget ) return;
202
// register widget to animations
203
animations().registerWidget( widget );
204
transitions().registerWidget( widget );
205
windowManager().registerWidget( widget );
206
frameShadowFactory().registerWidget( widget, helper() );
207
mdiWindowShadowFactory().registerWidget( widget );
208
shadowHelper().registerWidget( widget );
211
if( QAbstractScrollArea* scrollArea = qobject_cast<QAbstractScrollArea*>( widget ) )
214
polishScrollArea( scrollArea );
216
} else if( widget->inherits( "Q3ListView" ) ) {
218
addEventFilter( widget );
219
widget->setAttribute( Qt::WA_Hover );
223
// several widgets set autofill background to false, which effectively breaks the background
224
// gradient rendering. Instead of patching all concerned applications,
225
// we change the background here
226
if( widget->inherits( "MessageList::Core::Widget" ) )
227
{ widget->setAutoFillBackground( false ); }
230
// static cast is safe here, since isKTextEdit already checks that widget inherits from QFrame
231
if( isKTextEditFrame( widget ) && static_cast<QFrame*>( widget )->frameStyle() == ( QFrame::StyledPanel | QFrame::Sunken ) )
234
widget->setAttribute( Qt::WA_Hover );
235
animations().lineEditEngine().registerWidget( widget, AnimationHover|AnimationFocus );
239
// adjust layout for K3B themed headers
240
// FIXME: to be removed when fixed upstream
241
if( widget->inherits( "K3b::ThemedHeader" ) && widget->layout() )
243
widget->layout()->setMargin( 0 );
244
frameShadowFactory().setHasContrast( widget, true );
247
// adjust flags for windows and dialogs
248
switch( widget->windowFlags() & Qt::WindowType_Mask )
254
// set background as styled
255
widget->setAttribute( Qt::WA_StyledBackground );
256
widget->installEventFilter( _topLevelManager );
258
// initialize connections to kGlobalSettings
260
this musts be done in ::polish and not before,
261
in order to be able to detect Qt-KDE vs Qt-only applications
263
if( !_kGlobalSettingsInitialized ) initializeKGlobalSettings();
272
qobject_cast<QAbstractItemView*>( widget )
273
|| qobject_cast<QAbstractSpinBox*>( widget )
274
|| qobject_cast<QCheckBox*>( widget )
275
|| qobject_cast<QComboBox*>( widget )
276
|| qobject_cast<QDial*>( widget )
277
|| qobject_cast<QLineEdit*>( widget )
278
|| qobject_cast<QPushButton*>( widget )
279
|| qobject_cast<QRadioButton*>( widget )
280
|| qobject_cast<QScrollBar*>( widget )
281
|| qobject_cast<QSlider*>( widget )
282
|| qobject_cast<QSplitterHandle*>( widget )
283
|| qobject_cast<QTabBar*>( widget )
284
|| qobject_cast<QTextEdit*>( widget )
285
|| qobject_cast<QToolButton*>( widget )
287
{ widget->setAttribute( Qt::WA_Hover ); }
289
// transparent tooltips
290
if( widget->inherits( "QTipLabel" ) )
292
widget->setAttribute( Qt::WA_TranslucentBackground );
295
//FramelessWindowHint is needed on windows to make WA_TranslucentBackground work properly
296
widget->setWindowFlags( widget->windowFlags() | Qt::FramelessWindowHint );
300
// also enable hover effects in itemviews' viewport
301
if( QAbstractItemView *itemView = qobject_cast<QAbstractItemView*>( widget ) )
302
{ itemView->viewport()->setAttribute( Qt::WA_Hover ); }
304
// checkable group boxes
305
if( QGroupBox* groupBox = qobject_cast<QGroupBox*>( widget ) )
308
if( groupBox->isCheckable() )
309
{ groupBox->setAttribute( Qt::WA_Hover ); }
311
} else if( qobject_cast<QAbstractButton*>( widget ) && qobject_cast<QDockWidget*>( widget->parent() ) ) {
313
widget->setAttribute( Qt::WA_Hover );
315
} else if( qobject_cast<QAbstractButton*>( widget ) && qobject_cast<QToolBox*>( widget->parent() ) ) {
317
widget->setAttribute( Qt::WA_Hover );
322
add extra margins for widgets in toolbars
323
this allows to preserve alignment with respect to actions
325
if( qobject_cast<QToolBar*>( widget->parent() ) )
326
{ widget->setContentsMargins( 0,0,0,1 ); }
328
if( qobject_cast<QToolButton*>( widget ) )
330
if( qobject_cast<QToolBar*>( widget->parent() ) )
332
// this hack is needed to have correct text color
333
// rendered in toolbars. This does not really update nicely when changing styles
334
// but is the best I can do for now since setting the palette color at painting
335
// time is not doable
336
QPalette palette( widget->palette() );
337
palette.setColor( QPalette::Disabled, QPalette::ButtonText, palette.color( QPalette::Disabled, QPalette::WindowText ) );
338
palette.setColor( QPalette::Active, QPalette::ButtonText, palette.color( QPalette::Active, QPalette::WindowText ) );
339
palette.setColor( QPalette::Inactive, QPalette::ButtonText, palette.color( QPalette::Inactive, QPalette::WindowText ) );
340
widget->setPalette( palette );
343
widget->setBackgroundRole( QPalette::NoRole );
345
} else if( qobject_cast<QMenuBar*>( widget ) ) {
347
widget->setBackgroundRole( QPalette::NoRole );
349
} else if( widget->inherits( "KMultiTabBar" ) ) {
351
// kMultiTabBar margins are set to unity for alignment
352
// with ( usually sunken ) neighbor frames
353
widget->setContentsMargins( 1, 1, 1, 1 );
355
} else if( widget->inherits( "Q3ToolBar" ) || qobject_cast<QToolBar*>( widget ) ) {
357
widget->setBackgroundRole( QPalette::NoRole );
358
widget->setAttribute( Qt::WA_TranslucentBackground );
359
addEventFilter( widget );
362
//FramelessWindowHint is needed on windows to make WA_TranslucentBackground work properly
363
widget->setWindowFlags( widget->windowFlags() | Qt::FramelessWindowHint );
366
} else if( qobject_cast<QTabBar*>( widget ) ) {
368
addEventFilter( widget );
370
} else if( widget->inherits( "QTipLabel" ) ) {
372
widget->setBackgroundRole( QPalette::NoRole );
373
widget->setAttribute( Qt::WA_TranslucentBackground );
376
//FramelessWindowHint is needed on windows to make WA_TranslucentBackground work properly
377
widget->setWindowFlags( widget->windowFlags() | Qt::FramelessWindowHint );
380
} else if( qobject_cast<QScrollBar*>( widget ) ) {
382
widget->setAttribute( Qt::WA_OpaquePaintEvent, false );
384
// when painted in konsole, one needs to paint the window background below
385
// the scrollarea, otherwise an ugly flat background is used
386
if( widget->parent() && widget->parent()->inherits( "Konsole::TerminalDisplay" ) )
387
{ addEventFilter( widget ); }
389
} else if( qobject_cast<QDockWidget*>( widget ) ) {
391
widget->setBackgroundRole( QPalette::NoRole );
392
widget->setAttribute( Qt::WA_TranslucentBackground );
393
widget->setContentsMargins( 3,3,3,3 );
394
addEventFilter( widget );
396
} else if( qobject_cast<QMdiSubWindow*>( widget ) ) {
398
widget->setAutoFillBackground( false );
399
addEventFilter( widget );
401
} else if( qobject_cast<QToolBox*>( widget ) ) {
403
widget->setBackgroundRole( QPalette::NoRole );
404
widget->setAutoFillBackground( false );
405
widget->setContentsMargins( 5,5,5,5 );
406
addEventFilter( widget );
408
} else if( widget->parentWidget() && widget->parentWidget()->parentWidget() && qobject_cast<QToolBox*>( widget->parentWidget()->parentWidget()->parentWidget() ) ) {
410
widget->setBackgroundRole( QPalette::NoRole );
411
widget->setAutoFillBackground( false );
412
widget->parentWidget()->setAutoFillBackground( false );
414
} else if( qobject_cast<QMenu*>( widget ) ) {
416
widget->setAttribute( Qt::WA_TranslucentBackground );
418
//FramelessWindowHint is needed on windows to make WA_TranslucentBackground work properly
419
widget->setWindowFlags( widget->windowFlags() | Qt::FramelessWindowHint );
422
} else if( widget->inherits( "QComboBoxPrivateContainer" ) ) {
424
addEventFilter( widget );
425
widget->setAttribute( Qt::WA_TranslucentBackground );
427
//FramelessWindowHint is needed on windows to make WA_TranslucentBackground work properly
428
widget->setWindowFlags( widget->windowFlags() | Qt::FramelessWindowHint );
431
} else if( widget->inherits( "KWin::GeometryTip" ) ) {
433
// special handling of kwin geometry tip widget
434
addEventFilter( widget );
435
widget->setAttribute( Qt::WA_NoSystemBackground );
436
widget->setAttribute( Qt::WA_TranslucentBackground );
437
if( QLabel* label = qobject_cast<QLabel*>( widget ) )
439
label->setFrameStyle( QFrame::NoFrame );
440
label->setMargin( 5 );
444
widget->setWindowFlags( widget->windowFlags() | Qt::FramelessWindowHint );
447
} else if( qobject_cast<QFrame*>( widget ) && widget->parent() && widget->parent()->inherits( "KTitleWidget" ) ) {
449
widget->setAutoFillBackground( false );
450
widget->setBackgroundRole( QPalette::Window );
454
// base class polishing
455
QCommonStyle::polish( widget );
459
//_______________________________________________________________
460
void Style::unpolish( QWidget* widget )
463
// register widget to animations
464
animations().unregisterWidget( widget );
465
transitions().unregisterWidget( widget );
466
windowManager().unregisterWidget( widget );
467
frameShadowFactory().unregisterWidget( widget );
468
mdiWindowShadowFactory().unregisterWidget( widget );
469
shadowHelper().unregisterWidget( widget );
471
if( isKTextEditFrame( widget ) )
472
{ widget->setAttribute( Qt::WA_Hover, false ); }
474
if( widget && widget->inherits( "Q3ListView" ) ) {
476
widget->removeEventFilter( this );
477
widget->setAttribute( Qt::WA_Hover, false );
482
switch ( widget->windowFlags() & Qt::WindowType_Mask )
487
widget->removeEventFilter( this );
488
widget->setAttribute( Qt::WA_StyledBackground, false );
496
// checkable group boxes
497
if( QGroupBox* groupBox = qobject_cast<QGroupBox*>( widget ) )
499
if( groupBox->isCheckable() )
500
{ groupBox->setAttribute( Qt::WA_Hover, false ); }
505
qobject_cast<QAbstractItemView*>( widget )
506
|| qobject_cast<QAbstractSpinBox*>( widget )
507
|| qobject_cast<QCheckBox*>( widget )
508
|| qobject_cast<QComboBox*>( widget )
509
|| qobject_cast<QDial*>( widget )
510
|| qobject_cast<QLineEdit*>( widget )
511
|| qobject_cast<QPushButton*>( widget )
512
|| qobject_cast<QRadioButton*>( widget )
513
|| qobject_cast<QScrollBar*>( widget )
514
|| qobject_cast<QSlider*>( widget )
515
|| qobject_cast<QSplitterHandle*>( widget )
516
|| qobject_cast<QTabBar*>( widget )
517
|| qobject_cast<QTextEdit*>( widget )
518
|| qobject_cast<QToolButton*>( widget )
520
{ widget->setAttribute( Qt::WA_Hover, false ); }
522
// checkable group boxes
523
if( QGroupBox* groupBox = qobject_cast<QGroupBox*>( widget ) )
525
if( groupBox->isCheckable() )
526
{ groupBox->setAttribute( Qt::WA_Hover, false ); }
529
if( qobject_cast<QMenuBar*>( widget )
530
|| ( widget && widget->inherits( "Q3ToolBar" ) )
531
|| qobject_cast<QToolBar*>( widget )
532
|| ( widget && qobject_cast<QToolBar *>( widget->parent() ) )
533
|| qobject_cast<QToolBox*>( widget ) )
535
widget->setBackgroundRole( QPalette::Button );
536
widget->removeEventFilter( this );
540
if( qobject_cast<QTabBar*>( widget ) )
543
widget->removeEventFilter( this );
545
} else if( widget->inherits( "QTipLabel" ) ) {
547
widget->setAttribute( Qt::WA_PaintOnScreen, false );
548
widget->setAttribute( Qt::WA_NoSystemBackground, false );
551
} else if( qobject_cast<QScrollBar*>( widget ) ) {
553
widget->setAttribute( Qt::WA_OpaquePaintEvent );
555
} else if( qobject_cast<QDockWidget*>( widget ) ) {
557
widget->setContentsMargins( 0,0,0,0 );
560
} else if( qobject_cast<QToolBox*>( widget ) ) {
562
widget->setBackgroundRole( QPalette::Button );
563
widget->setContentsMargins( 0,0,0,0 );
564
widget->removeEventFilter( this );
566
} else if( qobject_cast<QMenu*>( widget ) ) {
568
widget->setAttribute( Qt::WA_PaintOnScreen, false );
569
widget->setAttribute( Qt::WA_NoSystemBackground, false );
572
} else if( widget->inherits( "QComboBoxPrivateContainer" ) ) widget->removeEventFilter( this );
574
QCommonStyle::unpolish( widget );
578
//______________________________________________________________
579
int Style::pixelMetric( PixelMetric metric, const QStyleOption* option, const QWidget* widget ) const
582
// handle special cases
586
// rely on QCommonStyle here
587
case PM_SmallIconSize:
588
case PM_ButtonIconSize:
589
return KIconLoader::global()->currentSize( KIconLoader::Small );
591
case PM_ToolBarIconSize:
592
return KIconLoader::global()->currentSize( KIconLoader::Toolbar );
594
case PM_LargeIconSize:
595
return KIconLoader::global()->currentSize( KIconLoader::Dialog );
597
case PM_MessageBoxIconSize:
598
return KIconLoader::SizeHuge;
600
case PM_DefaultFrameWidth:
603
if( qobject_cast<const QLineEdit*>( widget ) ) return LineEdit_FrameWidth;
604
else if( qobject_cast<const QComboBox*>( widget ) ) return ComboBox_FrameWidth;
605
else if( qobject_cast<const QFrame*>( widget ) )
608
// special case for KTitleWidget: frameWidth is set to zero, since
609
// no frame, nor background is painted for these
610
if( widget->parent() && widget->parent()->inherits( "KTitleWidget" ) ) return 0;
611
else return Frame_FrameWidth;
614
else if( qstyleoption_cast<const QStyleOptionGroupBox *>( option ) ) return GroupBox_FrameWidth;
619
case PM_LayoutLeftMargin:
620
case PM_LayoutTopMargin:
621
case PM_LayoutRightMargin:
622
case PM_LayoutBottomMargin:
624
// use either Child margin or TopLevel margin, depending on
626
if( ( option && ( option->state & QStyle::State_Window ) ) || ( widget && widget->isWindow() ) )
629
return pixelMetric( PM_DefaultTopLevelMargin, option, widget );
633
return pixelMetric( PM_DefaultChildMargin, option, widget );
640
/* HACK: needs special case for kcalc buttons, to prevent the application to set too small margins */
641
case PM_ButtonMargin:
642
{ return ( widget && widget->inherits( "KCalcButton" ) ) ? 8:5; }
644
case PM_MenuButtonIndicator:
646
if( qstyleoption_cast<const QStyleOptionToolButton*>( option ) ) return ToolButton_MenuIndicatorSize;
647
else return PushButton_MenuIndicatorSize;
650
case PM_ScrollBarExtent:
651
return StyleConfigData::scrollBarWidth() + 2;
653
case PM_ScrollBarSliderMin: return ScrollBar_MinimumSliderHeight;
656
case PM_ToolTipLabelFrameWidth:
658
if( StyleConfigData::toolTipDrawStyledFrames() ) return 3;
662
case PM_DefaultChildMargin: return 4;
663
case PM_DefaultTopLevelMargin: return 11;
664
case PM_DefaultLayoutSpacing: return 4;
665
case PM_LayoutHorizontalSpacing: return -1;
666
case PM_LayoutVerticalSpacing: return -1;
669
case PM_ButtonDefaultIndicator: return 0;
670
case PM_ButtonShiftHorizontal: return 0;
671
case PM_ButtonShiftVertical: return 0;
673
// checkboxes: return radiobutton sizes
674
case PM_IndicatorWidth: return CheckBox_Size;
675
case PM_IndicatorHeight: return CheckBox_Size;
676
case PM_ExclusiveIndicatorWidth: return CheckBox_Size;
677
case PM_ExclusiveIndicatorHeight: return CheckBox_Size;
678
case PM_CheckListControllerSize: return CheckBox_Size;
679
case PM_CheckListButtonSize: return CheckBox_Size;
681
// splitters and dock widgets
682
case PM_SplitterWidth: return Splitter_Width;
683
case PM_DockWidgetFrameWidth: return DockWidget_FrameWidth;
684
case PM_DockWidgetSeparatorExtent: return DockWidget_SeparatorExtend;
685
case PM_DockWidgetTitleMargin: return DockWidget_TitleMargin;
688
case PM_ProgressBarChunkWidth: return 1;
691
case PM_MenuBarPanelWidth: return 0;
692
case PM_MenuBarHMargin: return 0;
693
case PM_MenuBarVMargin: return 0;
694
case PM_MenuBarItemSpacing: return 0;
695
case PM_MenuDesktopFrameWidth: return 0;
696
case PM_MenuPanelWidth: return 5;
698
case PM_MenuScrollerHeight: return 10;
699
case PM_MenuTearoffHeight: return 10;
702
case PM_TabBarTabHSpace: return 0;
703
case PM_TabBarTabVSpace: return 0;
704
case PM_TabBarBaseHeight: return TabBar_BaseHeight;
705
case PM_TabBarBaseOverlap: return TabBar_BaseOverlap;
706
case PM_TabBarTabOverlap: return 0;
707
case PM_TabBarScrollButtonWidth: return TabBar_ScrollButtonWidth;
710
disable shifts: return because last time I checked it did not work well
711
for South and East tabs. Instead the shifts are added directly in
712
drawTabBarTabLabel. ( Hugo )
714
case PM_TabBarTabShiftVertical: return 0;
715
case PM_TabBarTabShiftHorizontal: return 0;
718
case PM_SliderThickness: return 23;
719
case PM_SliderControlThickness: return 23;
720
case PM_SliderLength: return 21;
723
case PM_SpinBoxFrameWidth: return SpinBox_FrameWidth;
726
case PM_ComboBoxFrameWidth: return ComboBox_FrameWidth;
729
case PM_HeaderMarkSize: return 9;
730
case PM_HeaderMargin: return 3;
733
case PM_ToolBarFrameWidth: return 0;
734
case PM_ToolBarHandleExtent: return 6;
735
case PM_ToolBarSeparatorExtent: return 6;
737
case PM_ToolBarExtensionExtent: return 16;
738
case PM_ToolBarItemMargin: return 1;
739
case PM_ToolBarItemSpacing: return 1;
741
// MDI windows titlebars
742
case PM_TitleBarHeight: return 20;
744
// spacing between widget and scrollbars
745
case PM_ScrollView_ScrollBarSpacing:
746
if( const QFrame* frame = qobject_cast<const QFrame*>( widget ) )
749
const bool framed( frame->frameShape() != QFrame::NoFrame );
750
return framed ? -2:0;
758
return QCommonStyle::pixelMetric( metric, option, widget );
762
//______________________________________________________________
763
int Style::styleHint( StyleHint hint, const QStyleOption* option, const QWidget* widget, QStyleHintReturn* returnData ) const
766
// handles SH_KCustomStyleElement out of switch statement,
767
// to avoid warning at compilation
768
if( hint == SH_KCustomStyleElement )
770
if( widget ) return _styleElements.value( widget->objectName(), 0 );
775
special cases, that cannot be registered in styleHint map,
776
because of conditional statements
781
case SH_DialogButtonBox_ButtonsHaveIcons:
782
return KGlobalSettings::showIconsOnPushButtons();
784
case SH_GroupBox_TextLabelColor:
785
if( option ) return option->palette.color( QPalette::WindowText ).rgba();
786
else return qApp->palette().color( QPalette::WindowText ).rgba();
788
case SH_ItemView_ActivateItemOnSingleClick:
789
return helper().config()->group( "KDE" ).readEntry( "SingleClick", KDE_DEFAULT_SINGLECLICK );
792
case SH_RubberBand_Mask:
795
const QStyleOptionRubberBand *opt = qstyleoption_cast<const QStyleOptionRubberBand *>( option );
796
if( !opt ) return false;
798
if( QStyleHintReturnMask *mask = qstyleoption_cast<QStyleHintReturnMask*>( returnData ) )
801
mask->region = option->rect;
803
// need to check on widget before removing inner region
804
// in order to still preserve rubberband in MainWindow and QGraphicsView
805
// in QMainWindow because it looks better
806
// in QGraphicsView because the painting fails completely otherwise
808
qobject_cast<const QGraphicsView*>( widget->parent() ) ||
809
qobject_cast<const QMainWindow*>( widget->parent() ) ) ) )
810
{ mask->region -= option->rect.adjusted( 1,1,-1,-1 ); }
817
case SH_ToolTip_Mask:
821
if( !helper().hasAlphaChannel( widget ) && ( !widget || widget->isWindow() ) )
824
// mask should be set only if compositing is disabled
825
if( QStyleHintReturnMask *mask = qstyleoption_cast<QStyleHintReturnMask *>( returnData ) )
826
{ mask->region = helper().roundedMask( option->rect ); }
835
case SH_ComboBox_ListMouseTracking: return true;
836
case SH_MenuBar_MouseTracking: return true;
837
case SH_Menu_MouseTracking: return true;
839
case SH_Menu_SubMenuPopupDelay: return 150;
841
case SH_TitleBar_NoBorder: return 0;
842
case SH_GroupBox_TextLabelVerticalAlignment: return Qt::AlignVCenter;
843
case SH_DialogButtonLayout: return QDialogButtonBox::KdeLayout;
844
case SH_ScrollBar_MiddleClickAbsolutePosition: return true;
845
case SH_ItemView_ShowDecorationSelected: return false;
846
case SH_ItemView_ArrowKeysNavigateIntoChildren: return true;
847
case SH_ScrollView_FrameOnlyAroundContents: return true;
848
case SH_FormLayoutFormAlignment: return Qt::AlignLeft | Qt::AlignTop;
849
case SH_FormLayoutLabelAlignment: return Qt::AlignRight;
850
case SH_FormLayoutFieldGrowthPolicy: return QFormLayout::ExpandingFieldsGrow;
851
case SH_FormLayoutWrapPolicy: return QFormLayout::DontWrapRows;
852
case SH_MessageBox_TextInteractionFlags: return true;
853
case SH_WindowFrame_Mask: return false;
855
default: return QCommonStyle::styleHint( hint, option, widget, returnData );
860
//______________________________________________________________
861
QRect Style::subElementRect( SubElement element, const QStyleOption* option, const QWidget* widget ) const
869
case SE_PushButtonContents: return pushButtonContentsRect( option, widget );
870
case SE_PushButtonFocusRect: return defaultSubElementRect( option, widget );
873
case SE_CheckBoxContents: return checkBoxContentsRect( option, widget );
874
case SE_CheckBoxFocusRect: return defaultSubElementRect( option, widget );
877
case SE_ProgressBarGroove: return defaultSubElementRect( option, widget );
878
case SE_ProgressBarContents: return progressBarContentsRect( option, widget );
879
case SE_ProgressBarLabel: return defaultSubElementRect( option, widget );
882
case SE_RadioButtonContents: return checkBoxContentsRect( option, widget );
883
case SE_RadioButtonFocusRect: return defaultSubElementRect( option, widget );
886
case SE_TabBarTabLeftButton: return tabBarTabLeftButtonRect( option, widget );
887
case SE_TabBarTabRightButton: return tabBarTabRightButtonRect( option, widget );
888
case SE_TabBarTabText: return tabBarTabTextRect( option, widget );
889
case SE_TabWidgetTabContents: return tabWidgetTabContentsRect( option, widget );
890
case SE_TabWidgetTabPane: return tabWidgetTabPaneRect( option, widget );
891
case SE_TabWidgetLeftCorner: return tabWidgetLeftCornerRect( option, widget );
892
case SE_TabWidgetRightCorner: return tabWidgetRightCornerRect( option, widget );
895
case SE_ToolBoxTabContents: return toolBoxTabContentsRect( option, widget );
897
default: return QCommonStyle::subElementRect( element, option, widget );
903
//______________________________________________________________
904
QRect Style::subControlRect( ComplexControl element, const QStyleOptionComplex* option, SubControl subControl, const QWidget* widget ) const
910
case CC_GroupBox: return groupBoxSubControlRect( option, subControl, widget );
911
case CC_ComboBox: return comboBoxSubControlRect( option, subControl, widget );
912
case CC_Slider: return sliderSubControlRect( option, subControl, widget );
913
case CC_ScrollBar: return scrollBarSubControlRect( option, subControl, widget );
914
case CC_SpinBox: return spinBoxSubControlRect( option, subControl, widget );
915
default: return QCommonStyle::subControlRect( element, option, subControl, widget );
920
//______________________________________________________________
921
QSize Style::sizeFromContents( ContentsType element, const QStyleOption* option, const QSize& size, const QWidget* widget ) const
926
case CT_CheckBox: return checkBoxSizeFromContents( option, size, widget );
927
case CT_ComboBox: return comboBoxSizeFromContents( option, size, widget );
928
case CT_HeaderSection: return headerSectionSizeFromContents( option, size, widget );
929
case CT_PushButton: return pushButtonSizeFromContents( option, size, widget );
930
case CT_MenuBar: return menuBarSizeFromContents( option, size, widget );
931
case CT_MenuBarItem: return menuBarItemSizeFromContents( option, size, widget );
932
case CT_MenuItem: return menuItemSizeFromContents( option, size, widget );
933
case CT_RadioButton: return checkBoxSizeFromContents( option, size, widget );
934
case CT_TabBarTab: return tabBarTabSizeFromContents( option, size, widget );
935
case CT_TabWidget: return tabWidgetSizeFromContents( option, size, widget );
936
case CT_ToolButton: return toolButtonSizeFromContents( option, size, widget );
937
default: return QCommonStyle::sizeFromContents( element, option, size, widget );
942
//______________________________________________________________
943
QStyle::SubControl Style::hitTestComplexControl( ComplexControl control, const QStyleOptionComplex* option, const QPoint& point, const QWidget* widget ) const
950
QRect groove = scrollBarSubControlRect( option, SC_ScrollBarGroove, widget );
951
if ( groove.contains( point ) )
953
//Must be either page up/page down, or just click on the slider.
954
//Grab the slider to compare
955
QRect slider = scrollBarSubControlRect( option, SC_ScrollBarSlider, widget );
957
if( slider.contains( point ) ) return SC_ScrollBarSlider;
958
else if( preceeds( point, slider, option ) ) return SC_ScrollBarSubPage;
959
else return SC_ScrollBarAddPage;
963
//This is one of the up/down buttons. First, decide which one it is.
964
if( preceeds( point, groove, option ) )
967
if( _subLineButtons == DoubleButton )
969
QRect buttonRect = scrollBarInternalSubControlRect( option, SC_ScrollBarSubLine );
970
return scrollBarHitTest( buttonRect, point, option );
971
} else return SC_ScrollBarSubLine;
975
if( _addLineButtons == DoubleButton )
978
QRect buttonRect = scrollBarInternalSubControlRect( option, SC_ScrollBarAddLine );
979
return scrollBarHitTest( buttonRect, point, option );
981
} else return SC_ScrollBarAddLine;
984
default: return QCommonStyle::hitTestComplexControl( control, option, point, widget );
989
//______________________________________________________________
990
void Style::drawPrimitive( PrimitiveElement element, const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
995
StylePrimitive fcn( 0 );
999
// register primitives for which nothing is done
1000
case PE_FrameStatusBar: fcn = &Style::emptyPrimitive; break;
1002
case PE_Frame: fcn = &Style::drawFramePrimitive; break;
1004
// frame focus primitive is set at run time, in oxygenConfigurationChanged
1005
case PE_FrameFocusRect: fcn = _frameFocusPrimitive; break;
1007
case PE_FrameGroupBox: fcn = &Style::drawFrameGroupBoxPrimitive; break;
1008
case PE_FrameLineEdit: fcn = &Style::drawFramePrimitive; break;
1009
case PE_FrameMenu: fcn = &Style::drawFrameMenuPrimitive; break;
1012
case PE_FrameTabBarBase: fcn = &Style::drawFrameTabBarBasePrimitive; break;
1013
case PE_FrameTabWidget: fcn = &Style::drawFrameTabWidgetPrimitive; break;
1015
case PE_FrameWindow: fcn = &Style::drawFrameWindowPrimitive; break;
1018
case PE_IndicatorArrowUp: fcn = &Style::drawIndicatorArrowUpPrimitive; break;
1019
case PE_IndicatorArrowDown: fcn = &Style::drawIndicatorArrowDownPrimitive; break;
1020
case PE_IndicatorArrowLeft: fcn = &Style::drawIndicatorArrowLeftPrimitive; break;
1021
case PE_IndicatorArrowRight: fcn = &Style::drawIndicatorArrowRightPrimitive; break;
1023
case PE_IndicatorDockWidgetResizeHandle: fcn = &Style::drawIndicatorDockWidgetResizeHandlePrimitive; break;
1024
case PE_IndicatorHeaderArrow: fcn = &Style::drawIndicatorHeaderArrowPrimitive; break;
1026
case PE_PanelButtonCommand: fcn = &Style::drawPanelButtonCommandPrimitive; break;
1027
case PE_PanelButtonTool: fcn = &Style::drawPanelButtonToolPrimitive; break;
1029
case PE_PanelItemViewItem: fcn = &Style::drawPanelItemViewItemPrimitive; break;
1030
case PE_PanelLineEdit: fcn = &Style::drawPanelLineEditPrimitive; break;
1031
case PE_PanelMenu: fcn = &Style::drawPanelMenuPrimitive; break;
1032
case PE_PanelScrollAreaCorner: fcn = &Style::drawPanelScrollAreaCornerPrimitive; break;
1033
case PE_PanelTipLabel: fcn = &Style::drawPanelTipLabelPrimitive; break;
1035
case PE_IndicatorMenuCheckMark: fcn = &Style::drawIndicatorMenuCheckMarkPrimitive; break;
1036
case PE_Q3CheckListIndicator: fcn = &Style::drawQ3CheckListIndicatorPrimitive; break;
1037
case PE_Q3CheckListExclusiveIndicator: fcn = &Style::drawQ3CheckListExclusiveIndicatorPrimitive; break;
1038
case PE_IndicatorBranch: fcn = &Style::drawIndicatorBranchPrimitive; break;
1039
case PE_IndicatorButtonDropDown: fcn = &Style::drawIndicatorButtonDropDownPrimitive; break;
1040
case PE_IndicatorCheckBox: fcn = &Style::drawIndicatorCheckBoxPrimitive; break;
1041
case PE_IndicatorRadioButton: fcn = &Style::drawIndicatorRadioButtonPrimitive; break;
1042
case PE_IndicatorTabTear: fcn = &Style::drawIndicatorTabTearPrimitive; break;
1043
case PE_IndicatorToolBarHandle: fcn = &Style::drawIndicatorToolBarHandlePrimitive; break;
1044
case PE_IndicatorToolBarSeparator: fcn = &Style::drawIndicatorToolBarSeparatorPrimitive; break;
1046
case PE_Widget: fcn = &Style::drawWidgetPrimitive; break;
1052
// try find primitive in map, and run.
1053
// exit if result is true, otherwise fallback to generic case
1054
if( !( fcn && ( this->*fcn )( option, painter, widget ) ) )
1055
{ QCommonStyle::drawPrimitive( element, option, painter, widget ); }
1061
//______________________________________________________________
1062
void Style::drawControl( ControlElement element, const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
1067
StyleControl fcn( 0 );
1068
if( element == CE_CapacityBar )
1071
fcn = &Style::drawCapacityBarControl;
1073
} else switch( element ) {
1075
case CE_ComboBoxLabel: fcn = &Style::drawComboBoxLabelControl; break;
1076
case CE_DockWidgetTitle: fcn = &Style::drawDockWidgetTitleControl; break;
1077
case CE_HeaderEmptyArea: fcn = &Style::drawHeaderEmptyAreaControl; break;
1078
case CE_HeaderLabel: fcn = &Style::drawHeaderLabelControl; break;
1079
case CE_HeaderSection: fcn = &Style::drawHeaderSectionControl; break;
1080
case CE_MenuBarEmptyArea: fcn = &Style::emptyControl; break;
1081
case CE_MenuBarItem: fcn = &Style::drawMenuBarItemControl; break;
1082
case CE_MenuItem: fcn = &Style::drawMenuItemControl; break;
1083
case CE_ProgressBar: fcn = &Style::drawProgressBarControl; break;
1084
case CE_ProgressBarContents: fcn = &Style::drawProgressBarContentsControl; break;
1085
case CE_ProgressBarGroove: fcn = &Style::drawProgressBarGrooveControl; break;
1086
case CE_ProgressBarLabel: fcn = &Style::drawProgressBarLabelControl; break;
1089
for CE_PushButtonBevel the only thing that is done is draw the PanelButtonCommand primitive
1090
since the prototypes are identical we register the second directly in the control map: fcn = without
1091
using an intermediate function
1093
case CE_PushButtonBevel: fcn = &Style::drawPanelButtonCommandPrimitive; break;
1094
case CE_PushButtonLabel: fcn = &Style::drawPushButtonLabelControl; break;
1096
case CE_RubberBand: fcn = &Style::drawRubberBandControl; break;
1097
case CE_ScrollBarSlider: fcn = &Style::drawScrollBarSliderControl; break;
1098
case CE_ScrollBarAddLine: fcn = &Style::drawScrollBarAddLineControl; break;
1099
case CE_ScrollBarAddPage: fcn = &Style::drawScrollBarAddPageControl; break;
1100
case CE_ScrollBarSubLine: fcn = &Style::drawScrollBarSubLineControl; break;
1101
case CE_ScrollBarSubPage: fcn = &Style::drawScrollBarSubPageControl; break;
1103
case CE_ShapedFrame: fcn = &Style::drawShapedFrameControl; break;
1104
case CE_SizeGrip: fcn = &Style::drawSizeGripControl; break;
1105
case CE_Splitter: fcn = &Style::drawSplitterControl; break;
1106
case CE_TabBarTabLabel: fcn = &Style::drawTabBarTabLabelControl; break;
1108
// default tab style is 'SINGLE'
1109
case CE_TabBarTabShape: fcn = _tabBarTabShapeControl; break;
1111
case CE_ToolBar: fcn = &Style::drawToolBarControl; break;
1112
case CE_ToolBoxTabLabel: fcn = &Style::drawToolBoxTabLabelControl; break;
1113
case CE_ToolBoxTabShape: fcn = &Style::drawToolBoxTabShapeControl; break;
1114
case CE_ToolButtonLabel: fcn = &Style::drawToolButtonLabelControl; break;
1120
if( !( fcn && ( this->*fcn )( option, painter, widget ) ) )
1121
{ QCommonStyle::drawControl( element, option, painter, widget ); }
1127
//______________________________________________________________
1128
void Style::drawComplexControl( ComplexControl element, const QStyleOptionComplex* option, QPainter* painter, const QWidget* widget ) const
1133
StyleComplexControl fcn( 0 );
1137
case CC_ComboBox: fcn = &Style::drawComboBoxComplexControl; break;
1138
case CC_Dial: fcn = &Style::drawDialComplexControl; break;
1139
case CC_GroupBox: fcn = &Style::drawGroupBoxComplexControl; break;
1140
case CC_Q3ListView: fcn = &Style::drawQ3ListViewComplexControl; break;
1141
case CC_Slider: fcn = &Style::drawSliderComplexControl; break;
1142
case CC_SpinBox: fcn = &Style::drawSpinBoxComplexControl; break;
1143
case CC_TitleBar: fcn = &Style::drawTitleBarComplexControl; break;
1144
case CC_ToolButton: fcn = &Style::drawToolButtonComplexControl; break;
1149
if( !( fcn && ( this->*fcn )( option, painter, widget ) ) )
1150
{ QCommonStyle::drawComplexControl( element, option, painter, widget ); }
1157
//___________________________________________________________________________________
1158
void Style::drawItemText(
1159
QPainter* painter, const QRect& r, int flags, const QPalette& palette, bool enabled,
1160
const QString &text, QPalette::ColorRole textRole ) const
1163
// hide mnemonics if requested
1164
if( (!_showMnemonics) && ( flags & Qt::TextShowMnemonic ) && !( flags&Qt::TextHideMnemonic ) )
1166
flags &= ~Qt::TextShowMnemonic;
1167
flags |= Qt::TextHideMnemonic;
1170
if( animations().widgetEnabilityEngine().enabled() )
1174
check if painter engine is registered to WidgetEnabilityEngine, and animated
1175
if yes, merge the palettes. Note: a static_cast is safe here, since only the address
1176
of the pointer is used, not the actual content.
1178
const QWidget* widget( static_cast<const QWidget*>( painter->device() ) );
1179
if( animations().widgetEnabilityEngine().isAnimated( widget, AnimationEnable ) )
1182
const QPalette pal = helper().mergePalettes( palette, animations().widgetEnabilityEngine().opacity( widget, AnimationEnable ) );
1183
return QCommonStyle::drawItemText( painter, r, flags, pal, enabled, text, textRole );
1189
return QCommonStyle::drawItemText( painter, r, flags, palette, enabled, text, textRole );
1194
//_____________________________________________________________________
1195
bool Style::eventFilter( QObject *object, QEvent *event )
1198
if( QTabBar* tabBar = qobject_cast<QTabBar*>( object ) ) { return eventFilterTabBar( tabBar, event ); }
1199
if( QToolBar* toolBar = qobject_cast<QToolBar*>( object ) ) { return eventFilterToolBar( toolBar, event ); }
1200
if( QDockWidget* dockWidget = qobject_cast<QDockWidget*>( object ) ) { return eventFilterDockWidget( dockWidget, event ); }
1201
if( QToolBox* toolBox = qobject_cast<QToolBox*>( object ) ) { return eventFilterToolBox( toolBox, event ); }
1202
if( QMdiSubWindow* subWindow = qobject_cast<QMdiSubWindow*>( object ) ) { return eventFilterMdiSubWindow( subWindow, event ); }
1203
if( QScrollBar* scrollBar = qobject_cast<QScrollBar*>( object ) ) { return eventFilterScrollBar( scrollBar, event ); }
1206
QWidget *widget = static_cast<QWidget*>( object );
1208
if( widget->inherits( "Q3ListView" ) ) { return eventFilterQ3ListView( widget, event ); }
1209
if( widget->inherits( "QComboBoxPrivateContainer" ) ) { return eventFilterComboBoxContainer( widget, event ); }
1210
if( widget->inherits( "KWin::GeometryTip" ) ) { return eventFilterGeometryTip( widget, event ); }
1212
return QCommonStyle::eventFilter( object, event );
1216
//_________________________________________________________
1217
bool Style::eventFilterComboBoxContainer( QWidget* widget, QEvent* event )
1219
switch( event->type() )
1223
case QEvent::Resize:
1225
if( !helper().hasAlphaChannel( widget ) ) widget->setMask( helper().roundedMask( widget->rect() ) );
1226
else widget->clearMask();
1233
QPainter painter( widget );
1234
QPaintEvent *paintEvent = static_cast<QPaintEvent*>( event );
1235
painter.setClipRegion( paintEvent->region() );
1237
const QRect r( widget->rect() );
1238
const QColor color( widget->palette().color( widget->window()->backgroundRole() ) );
1239
const bool hasAlpha( helper().hasAlphaChannel( widget ) );
1244
TileSet *tileSet( helper().roundCorner( color ) );
1245
tileSet->render( r, &painter );
1246
painter.setCompositionMode( QPainter::CompositionMode_SourceOver );
1247
painter.setClipRegion( helper().roundedMask( r.adjusted( 1, 1, -1, -1 ) ), Qt::IntersectClip );
1252
helper().renderMenuBackground( &painter, paintEvent->rect(), widget, widget->palette() );
1255
if( hasAlpha ) painter.setClipping( false );
1257
helper().drawFloatFrame( &painter, r, color, !hasAlpha );
1261
default: return false;
1265
//____________________________________________________________________________
1266
bool Style::eventFilterDockWidget( QDockWidget* dockWidget, QEvent* event )
1268
switch( event->type() )
1271
case QEvent::Resize:
1273
// make sure mask is appropriate
1274
if( dockWidget->isFloating() && !helper().hasAlphaChannel( dockWidget ) )
1277
dockWidget->setMask( helper().roundedMask( dockWidget->rect() ) );
1279
} else dockWidget->clearMask();
1286
QPainter painter( dockWidget );
1287
QPaintEvent *paintEvent = static_cast<QPaintEvent*>( event );
1288
painter.setClipRegion( paintEvent->region() );
1290
const QColor color( dockWidget->palette().color( QPalette::Window ) );
1291
const QRect r( dockWidget->rect() );
1292
if( dockWidget->isWindow() )
1296
bool hasAlpha( helper().hasAlphaChannel( dockWidget ) );
1299
painter.setCompositionMode( QPainter::CompositionMode_Source );
1300
TileSet *tileSet( helper().roundCorner( color ) );
1301
tileSet->render( r, &painter );
1304
painter.setCompositionMode( QPainter::CompositionMode_SourceOver );
1305
painter.setClipRegion( helper().roundedMask( r.adjusted( 1, 1, -1, -1 ) ), Qt::IntersectClip );
1309
helper().renderWindowBackground( &painter, r, dockWidget, color );
1312
if( hasAlpha ) painter.setClipping( false );
1314
helper().drawFloatFrame( &painter, r, color, !hasAlpha );
1319
// need to draw window background for autoFilled dockWidgets for better rendering
1320
if( dockWidget->autoFillBackground() )
1321
{ helper().renderWindowBackground( &painter, r, dockWidget, color ); }
1324
QColor top( helper().backgroundColor( color, dockWidget, r.topLeft() ) );
1325
QColor bottom( helper().backgroundColor( color, dockWidget, r.bottomLeft() ) );
1326
TileSet *tileSet = helper().dockFrame( top, bottom );
1327
tileSet->render( r, &painter );
1334
default: return false;
1340
//____________________________________________________________________________
1341
bool Style::eventFilterGeometryTip( QWidget* widget, QEvent* event )
1343
switch( event->type() )
1347
case QEvent::Resize:
1350
// make sure mask is appropriate
1351
if( !helper().hasAlphaChannel( widget ) ) widget->setMask( helper().roundedMask( widget->rect() ) );
1352
else widget->clearMask();
1359
const QColor color( widget->palette().window().color() );
1360
const QRect r( widget->rect() );
1362
QPainter painter( widget );
1363
QPaintEvent *paintEvent = static_cast<QPaintEvent*>( event );
1364
painter.setClipRegion( paintEvent->region() );
1366
const bool hasAlpha( helper().hasAlphaChannel( widget ) );
1370
painter.setCompositionMode( QPainter::CompositionMode_Source );
1371
TileSet *tileSet( helper().roundCorner( color ) );
1372
tileSet->render( r, &painter );
1374
painter.setCompositionMode( QPainter::CompositionMode_SourceOver );
1375
painter.setClipRegion( helper().roundedMask( r.adjusted( 1, 1, -1, -1 ) ), Qt::IntersectClip );
1379
helper().renderMenuBackground( &painter, r, widget,color );
1382
if( hasAlpha ) painter.setClipping( false );
1383
helper().drawFloatFrame( &painter, r, color, !hasAlpha );
1389
default: return false;
1393
// continue with normal painting
1398
//____________________________________________________________________________
1399
bool Style::eventFilterMdiSubWindow( QMdiSubWindow* subWindow, QEvent* event )
1402
if( event->type() == QEvent::Paint )
1405
QPainter painter( subWindow );
1406
QRect clip( static_cast<QPaintEvent*>( event )->rect() );
1407
if( subWindow->isMaximized() ) helper().renderWindowBackground( &painter, clip, subWindow, subWindow->palette() );
1410
painter.setClipRect( clip );
1412
const QRect r( subWindow->rect() );
1413
TileSet *tileSet( helper().roundCorner( subWindow->palette().color( subWindow->backgroundRole() ) ) );
1414
tileSet->render( r, &painter );
1416
painter.setClipRegion( helper().roundedMask( r.adjusted( 1, 1, -1, -1 ) ), Qt::IntersectClip );
1417
helper().renderWindowBackground( &painter, clip, subWindow, subWindow, subWindow->palette(), 0, 58 );
1423
// continue with normal painting
1428
//__________________________________________________________________________________
1429
bool Style::eventFilterQ3ListView( QWidget* widget, QEvent* event )
1431
// this apparently fixes a Qt bug with Q3ListView, consisting in
1432
// the fact that Focus events do not trigger repaint of these
1433
switch( event->type() )
1435
case QEvent::FocusIn: widget->update(); return false;
1436
case QEvent::FocusOut: widget->update(); return false;
1437
default: return false;
1442
//_________________________________________________________
1443
bool Style::eventFilterScrollBar( QWidget* widget, QEvent* event )
1446
if( event->type() == QEvent::Paint )
1448
QPainter painter( widget );
1449
painter.setClipRegion( static_cast<QPaintEvent*>( event )->region() );
1450
helper().renderWindowBackground( &painter, widget->rect(), widget,widget->palette() );
1456
//_____________________________________________________________________
1457
bool Style::eventFilterTabBar( QWidget* widget, QEvent* event )
1459
if( event->type() == QEvent::Paint && tabBarData().locks( widget ) )
1462
this makes sure that tabBar base is drawn ( and drawn only once )
1463
every time a replaint is triggered by dragging a tab around
1465
tabBarData().setDirty();
1471
//_____________________________________________________________________
1472
bool Style::eventFilterToolBar( QToolBar* toolBar, QEvent* event )
1474
switch( event->type() )
1477
case QEvent::Resize:
1479
// make sure mask is appropriate
1480
if( toolBar->isFloating() && !helper().hasAlphaChannel( toolBar ) )
1483
toolBar->setMask( helper().roundedMask( toolBar->rect() ) );
1485
} else toolBar->clearMask();
1492
QPainter painter( toolBar );
1493
QPaintEvent *paintEvent = static_cast<QPaintEvent*>( event );
1494
painter.setClipRegion( paintEvent->region() );
1496
const QRect r( toolBar->rect() );
1497
const QColor color( toolBar->palette().window().color() );
1499
// default painting when not qrealing
1500
if( !toolBar->isFloating() )
1503
// background has to be rendered explicitly
1504
// when one of the parent has autofillBackground set to true
1505
if( helper().checkAutoFillBackground( toolBar ) )
1506
{ helper().renderWindowBackground( &painter, r, toolBar, color ); }
1512
const bool hasAlpha( helper().hasAlphaChannel( toolBar ) );
1515
painter.setCompositionMode( QPainter::CompositionMode_Source );
1516
TileSet *tileSet( helper().roundCorner( color ) );
1517
tileSet->render( r, &painter );
1519
painter.setCompositionMode( QPainter::CompositionMode_SourceOver );
1520
painter.setClipRegion( helper().roundedMask( r.adjusted( 1, 1, -1, -1 ) ), Qt::IntersectClip );
1524
helper().renderWindowBackground( &painter, r, toolBar, color );
1526
if( toolBar->isMovable() )
1528
// remaining painting: need to add handle
1529
// this is copied from QToolBar::paintEvent
1530
QStyleOptionToolBar opt;
1531
opt.initFrom( toolBar );
1532
if( toolBar->orientation() == Qt::Horizontal )
1535
opt.rect = handleRTL( &opt, QRect( r.topLeft(), QSize( 8, r.height() ) ) );
1536
opt.state |= QStyle::State_Horizontal;
1540
opt.rect = handleRTL( &opt, QRect( r.topLeft(), QSize( r.width(), 8 ) ) );
1544
drawIndicatorToolBarHandlePrimitive( &opt, &painter, toolBar );
1549
if( hasAlpha ) painter.setClipping( false );
1550
helper().drawFloatFrame( &painter, r, color, !hasAlpha );
1555
default: return false;
1560
//____________________________________________________________________________
1561
bool Style::eventFilterToolBox( QToolBox* toolBox, QEvent* event )
1564
if( event->type() == QEvent::Paint )
1566
if( toolBox->frameShape() != QFrame::NoFrame )
1569
const QRect r( toolBox->rect() );
1570
const StyleOptions opts( NoFill );
1572
QPainter painter( toolBox );
1573
painter.setClipRegion( static_cast<QPaintEvent*>( event )->region() );
1574
renderSlab( &painter, r, toolBox->palette().color( QPalette::Button ), opts );
1582
//____________________________________________________________________
1583
QRect Style::progressBarContentsRect( const QStyleOption* option, const QWidget* ) const
1585
const QRect out( insideMargin( option->rect, ProgressBar_GrooveMargin ) );
1586
const QStyleOptionProgressBarV2 *pbOpt( qstyleoption_cast<const QStyleOptionProgressBarV2 *>( option ) );
1587
if( pbOpt && pbOpt->orientation == Qt::Vertical ) return out.adjusted( 0, 1, 0, -1 );
1588
else return out.adjusted( 1, 0, -1, 0 );
1591
//____________________________________________________________________
1592
QRect Style::tabBarTabButtonRect( SubElement element, const QStyleOption* option, const QWidget* widget ) const
1595
const QStyleOptionTab* tabOpt( qstyleoption_cast<const QStyleOptionTab*>( option ) );
1596
if ( !tabOpt ) return QRect();
1598
QRect r( QCommonStyle::subElementRect( element, option, widget ) );
1599
const bool selected( option->state&State_Selected );
1601
switch( tabOpt->shape )
1604
case QTabBar::RoundedNorth:
1605
case QTabBar::TriangularNorth:
1606
r.translate( 0, -1 );
1607
if( selected ) r.translate( 0, -1 );
1610
case QTabBar::RoundedSouth:
1611
case QTabBar::TriangularSouth:
1612
r.translate( 0, -1 );
1613
if( selected ) r.translate( 0, 1 );
1616
case QTabBar::RoundedWest:
1617
case QTabBar::TriangularWest:
1618
r.translate( 0, 1 );
1619
if( selected ) r.translate( -1, 0 );
1622
case QTabBar::RoundedEast:
1623
case QTabBar::TriangularEast:
1624
r.translate( 0, -2 );
1625
if( selected ) r.translate( 1, 0 );
1634
//____________________________________________________________________
1635
QRect Style::tabWidgetTabContentsRect( const QStyleOption* option, const QWidget* widget ) const
1638
// cast option and check
1639
const QStyleOptionTabWidgetFrame* tabOpt = qstyleoption_cast<const QStyleOptionTabWidgetFrame*>( option );
1640
if( !tabOpt ) return option->rect;
1642
// do nothing if tabbar is hidden
1643
if( tabOpt->tabBarSize.isEmpty() ) return option->rect;
1645
QRect r( option->rect );
1649
r = tabWidgetTabPaneRect( option, widget );
1652
const bool documentMode( tabOpt->lineWidth == 0 );
1656
r = insideMargin( r, TabWidget_ContentsMargin );
1657
r.translate( 0, -1 );
1664
//____________________________________________________________________
1665
QRect Style::tabWidgetTabPaneRect( const QStyleOption* option, const QWidget* ) const
1669
const QStyleOptionTabWidgetFrame* tabOpt = qstyleoption_cast<const QStyleOptionTabWidgetFrame*>( option );
1670
if( !tabOpt ) return option->rect;
1672
QRect r( option->rect );
1673
const bool documentMode( tabOpt->lineWidth == 0 );
1674
int overlap( TabBar_BaseOverlap );
1675
if( documentMode ) overlap -= TabWidget_ContentsMargin;
1677
switch( tabOpt->shape )
1679
case QTabBar::RoundedNorth:
1680
case QTabBar::TriangularNorth:
1682
if( documentMode ) overlap++;
1683
r.setTop( r.top() + qMax( tabOpt->tabBarSize.height() - overlap, 0 ) );
1687
case QTabBar::RoundedSouth:
1688
case QTabBar::TriangularSouth:
1690
if( documentMode ) overlap--;
1691
r.setBottom( r.bottom() - qMax( tabOpt->tabBarSize.height() - overlap, 0 ) );
1695
case QTabBar::RoundedWest:
1696
case QTabBar::TriangularWest:
1698
r.setLeft( r.left() + qMax( tabOpt->tabBarSize.width() - overlap, 0 ) );
1702
case QTabBar::RoundedEast:
1703
case QTabBar::TriangularEast:
1705
r.setRight( r.right() - qMax( tabOpt->tabBarSize.width() - overlap, 0 ) );
1715
//____________________________________________________________________
1716
QRect Style::tabWidgetLeftCornerRect( const QStyleOption* option, const QWidget* widget ) const
1719
const QStyleOptionTabWidgetFrame *tabOpt = qstyleoption_cast<const QStyleOptionTabWidgetFrame *>( option );
1720
if( !tabOpt ) return QRect();
1722
QRect r( option->rect );
1723
const QRect paneRect( subElementRect( SE_TabWidgetTabPane, option, widget ) );
1725
const QTabWidget* tabWidget( qobject_cast<const QTabWidget*>( widget ) );
1726
const bool documentMode( tabWidget ? tabWidget->documentMode() : false );
1728
const QSize& size( tabOpt->leftCornerWidgetSize );
1729
const int h( size.height() );
1730
const int w( size.width() );
1732
switch( tabOpt->shape )
1734
case QTabBar::RoundedNorth:
1735
case QTabBar::TriangularNorth:
1736
r = QRect( QPoint( paneRect.x(), paneRect.y() - h ), size );
1737
r = visualRect( tabOpt->direction, tabOpt->rect, r );
1738
if( !documentMode ) r.translate( 0, 3 );
1741
case QTabBar::RoundedSouth:
1742
case QTabBar::TriangularSouth:
1743
r = QRect( QPoint( paneRect.x(), paneRect.height() ), size );
1744
r = visualRect( tabOpt->direction, tabOpt->rect, r );
1745
if( !documentMode ) r.translate( 0, -3 );
1746
else r.translate( 0, 2 );
1749
case QTabBar::RoundedWest:
1750
case QTabBar::TriangularWest:
1751
r = QRect( QPoint( paneRect.x() - w, paneRect.y() ), size );
1752
r = visualRect( tabOpt->direction, tabOpt->rect, r );
1753
if( !documentMode ) r.translate( 2, 0 );
1754
else r.translate( -2, 0 );
1757
case QTabBar::RoundedEast:
1758
case QTabBar::TriangularEast:
1759
r = QRect( QPoint( paneRect.x() + paneRect.width(), paneRect.y() ), size );
1760
r = visualRect( tabOpt->direction, tabOpt->rect, r );
1761
if( !documentMode ) r.translate( -2, 0 );
1762
else r.translate( 2, 0 );
1773
//____________________________________________________________________
1774
QRect Style::tabWidgetRightCornerRect( const QStyleOption* option, const QWidget* widget ) const
1777
const QStyleOptionTabWidgetFrame *tabOpt = qstyleoption_cast<const QStyleOptionTabWidgetFrame *>( option );
1778
if( !tabOpt ) return QRect();
1780
QRect r( option->rect );
1781
const QRect paneRect( subElementRect( SE_TabWidgetTabPane, option, widget ) );
1783
const QTabWidget* tabWidget( qobject_cast<const QTabWidget*>( widget ) );
1784
const bool documentMode( tabWidget ? tabWidget->documentMode() : false );
1786
const QSize& size( tabOpt->rightCornerWidgetSize );
1787
const int h( size.height() );
1788
const int w( size.width() );
1790
switch( tabOpt->shape )
1792
case QTabBar::RoundedNorth:
1793
case QTabBar::TriangularNorth:
1794
r = QRect( QPoint( paneRect.right() - w + 1, paneRect.y() - h ), size );
1795
r = visualRect( tabOpt->direction, tabOpt->rect, r );
1796
if( !documentMode ) r.translate( 0, 3 );
1799
case QTabBar::RoundedSouth:
1800
case QTabBar::TriangularSouth:
1801
r = QRect( QPoint( paneRect.right() - w + 1, paneRect.height() ), size );
1802
r = visualRect( tabOpt->direction, tabOpt->rect, r );
1803
if( !documentMode ) r.translate( 0, -3 );
1804
else r.translate( 0, 2 );
1807
case QTabBar::RoundedWest:
1808
case QTabBar::TriangularWest:
1809
r = QRect( QPoint( paneRect.x() - w, paneRect.bottom() - h + 1 ), size );
1810
r = visualRect( tabOpt->direction, tabOpt->rect, r );
1811
if( !documentMode ) r.translate( 2, 0 );
1812
else r.translate( -2, 0 );
1815
case QTabBar::RoundedEast:
1816
case QTabBar::TriangularEast:
1817
r = QRect( QPoint( paneRect.x() + paneRect.width(), paneRect.bottom() - h + 1 ), size );
1818
r = visualRect( tabOpt->direction, tabOpt->rect, r );
1819
if( !documentMode ) r.translate( -2, 0 );
1820
else r.translate( 2, 0 );
1831
//______________________________________________________________
1832
QRect Style::groupBoxSubControlRect( const QStyleOptionComplex* option, SubControl subControl, const QWidget* widget ) const
1835
QRect r = option->rect;
1838
switch ( subControl )
1841
case SC_GroupBoxFrame: return r.adjusted( -1, -2, 1, 0 );
1843
case SC_GroupBoxContents:
1846
// cast option and check
1847
const QStyleOptionGroupBox *gbOpt = qstyleoption_cast<const QStyleOptionGroupBox *>( option );
1850
const bool isFlat( gbOpt->features & QStyleOptionFrameV2::Flat );
1851
const int th( gbOpt->fontMetrics.height() + 8 );
1852
const QRect cr( subElementRect( SE_CheckBoxIndicator, option, widget ) );
1853
const int fw( pixelMetric( PM_DefaultFrameWidth, option, widget ) );
1854
const bool checkable( gbOpt->subControls & QStyle::SC_GroupBoxCheckBox );
1855
const bool emptyText( gbOpt->text.isEmpty() );
1857
r.adjust( fw, fw, -fw, -fw );
1858
if( checkable && !emptyText ) r.adjust( 0, qMax( th, cr.height() ), 0, 0 );
1859
else if( checkable ) r.adjust( 0, cr.height(), 0, 0 );
1860
else if( !emptyText ) r.adjust( 0, th, 0, 0 );
1862
// add additional indentation to flat group boxes
1865
const int leftMarginExtension( 16 );
1866
r = visualRect( option->direction, r, r.adjusted( leftMarginExtension,0,0,0 ) );
1872
case SC_GroupBoxCheckBox:
1873
case SC_GroupBoxLabel:
1875
// cast option and check
1876
const QStyleOptionGroupBox *gbOpt = qstyleoption_cast<const QStyleOptionGroupBox *>( option );
1879
const bool isFlat( gbOpt->features & QStyleOptionFrameV2::Flat );
1880
QFont font = widget->font();
1882
// calculate text width assuming bold text in flat group boxes
1883
if( isFlat ) font.setBold( true );
1885
QFontMetrics fontMetrics = QFontMetrics( font );
1886
const int h( fontMetrics.height() );
1887
const int tw( fontMetrics.size( Qt::TextShowMnemonic, gbOpt->text + QLatin1String( " " ) ).width() );
1890
// translate down by 6 pixels in non flat mode,
1891
// to avoid collision with groupbox frame
1892
if( !isFlat ) r.moveTop( 6 );
1895
if( gbOpt->subControls & QStyle::SC_GroupBoxCheckBox )
1897
cr = subElementRect( SE_CheckBoxIndicator, option, widget );
1898
QRect gcr( ( gbOpt->rect.width() - tw -cr.width() )/2 , ( h-cr.height() )/2+r.y(), cr.width(), cr.height() );
1899
if( subControl == SC_GroupBoxCheckBox )
1901
if( !isFlat ) return visualRect( option->direction, option->rect, gcr );
1902
else return visualRect( option->direction, option->rect, QRect( 0,0,cr.width(),cr.height() ) );
1906
// left align labels in flat group boxes, center align labels in framed group boxes
1907
if( isFlat ) r = QRect( cr.width(),r.y(),tw,r.height() );
1908
else r = QRect( ( gbOpt->rect.width() - tw - cr.width() )/2 + cr.width(), r.y(), tw, r.height() );
1910
return visualRect( option->direction, option->rect, r );
1917
return QCommonStyle::subControlRect( CC_GroupBox, option, subControl, widget );
1920
//___________________________________________________________________________________________________________________
1921
QRect Style::comboBoxSubControlRect( const QStyleOptionComplex* option, SubControl subControl, const QWidget* widget ) const
1924
const QRect& r( option->rect );
1925
const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>( option );
1926
if( !cb ) return QCommonStyle::subControlRect( CC_ComboBox, option, subControl, widget );
1928
switch( subControl )
1930
case SC_ComboBoxFrame:
1931
{ return cb->frame ? r : QRect(); }
1933
case SC_ComboBoxListBoxPopup:
1934
{ return r.adjusted( 1,0,-1,0 ); }
1936
case SC_ComboBoxArrow:
1937
case SC_ComboBoxEditField:
1940
int fw = ComboBox_FrameWidth;
1943
int bw = ComboBox_ButtonWidth;
1946
int bm = ComboBox_ButtonMargin;
1947
int bml = bm + ComboBox_ButtonMargin_Left;
1948
int bmr = bm + ComboBox_ButtonMargin_Right;
1949
int bmt = bm + ComboBox_ButtonMargin_Top;
1950
int bmb = bm + ComboBox_ButtonMargin_Bottom;
1952
// ComboBox without a frame, set the corresponding layout values to 0, reduce button width.
1955
bw = bw - bmr; // reduce button with as the right button margin will be ignored.
1958
// TODO: why is bml not also set to 0
1962
if( subControl == SC_ComboBoxArrow )
1967
QRect( r.right()-bw+bml+1, r.top()+bmt, bw-bml-bmr, r.height()-bmt-bmb ) );
1971
QRect labelRect( r.left()+fw, r.top()+fw, r.width()-fw-bw, r.height()-2*fw );
1972
labelRect = insideMargin( labelRect,
1973
ComboBox_ContentsMargin,
1974
ComboBox_ContentsMargin_Left,
1975
ComboBox_ContentsMargin_Top,
1976
ComboBox_ContentsMargin_Right,
1977
ComboBox_ContentsMargin_Bottom );
1978
return handleRTL( option, labelRect );
1988
return QCommonStyle::subControlRect( CC_ComboBox, option, subControl, widget );
1992
//___________________________________________________________________________________________________________________
1993
QRect Style::scrollBarInternalSubControlRect( const QStyleOptionComplex* option, SubControl subControl ) const
1996
const QRect& r = option->rect;
1997
const State& flags( option->state );
1998
const bool horizontal( flags&State_Horizontal );
2000
switch ( subControl )
2003
case SC_ScrollBarSubLine:
2005
int majorSize( scrollBarButtonHeight( _subLineButtons ) );
2006
if( horizontal ) return handleRTL( option, QRect( r.x(), r.y(), majorSize, r.height() ) );
2007
else return handleRTL( option, QRect( r.x(), r.y(), r.width(), majorSize ) );
2011
case SC_ScrollBarAddLine:
2013
int majorSize( scrollBarButtonHeight( _addLineButtons ) );
2014
if( horizontal ) return handleRTL( option, QRect( r.right() - majorSize, r.y(), majorSize, r.height() ) );
2015
else return handleRTL( option, QRect( r.x(), r.bottom() - majorSize, r.width(), majorSize ) );
2018
default: return QRect();
2023
//___________________________________________________________________________________________________________________
2024
QRect Style::sliderSubControlRect( const QStyleOptionComplex* option, SubControl subControl, const QWidget* widget ) const
2026
switch( subControl )
2028
case SC_SliderHandle:
2029
return QCommonStyle::subControlRect( CC_Slider, option, subControl, widget );
2031
case SC_SliderGroove:
2033
QRect groove( QCommonStyle::subControlRect( CC_Slider, option, subControl, widget ) );
2034
if( const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>( option ) )
2036
const bool horizontal( slider->orientation == Qt::Horizontal );
2040
const int center( groove.center().y() );
2041
groove = QRect( groove.left(), center-Slider_GrooveWidth/2, groove.width(), Slider_GrooveWidth ).adjusted( 3, 0, -3, 0 );
2042
groove.adjust( 2, 1, -2, 0 );
2046
const int center( groove.center().x() );
2047
groove = QRect( center-Slider_GrooveWidth/2, groove.top(), Slider_GrooveWidth, groove.height() ).adjusted( 0, 3, 0, -3 );
2048
groove.adjust( 0, 2, 0, -2 );
2059
return QCommonStyle::subControlRect( CC_Slider, option, subControl, widget );
2065
//___________________________________________________________________________________________________________________
2066
QRect Style::scrollBarSubControlRect( const QStyleOptionComplex* option, SubControl subControl, const QWidget* widget ) const
2068
const QRect& r = option->rect;
2069
const State& flags( option->state );
2070
const bool horizontal( flags&State_Horizontal );
2072
switch ( subControl )
2074
//For both arrows, we return -everything-,
2075
//to get stuff to repaint right. See scrollBarInternalSubControlRect
2076
//for the real thing
2077
case SC_ScrollBarSubLine:
2078
case SC_ScrollBarAddLine:
2079
if( horizontal ) return r.adjusted( 0, 1, 0, -1 );
2080
else return r.adjusted( 1, 0, -1, 0 );
2082
//The main groove area. This is used to compute the others...
2083
case SC_ScrollBarGroove:
2085
QRect top = handleRTL( option, scrollBarInternalSubControlRect( option, SC_ScrollBarSubLine ) );
2086
QRect bot = handleRTL( option, scrollBarInternalSubControlRect( option, SC_ScrollBarAddLine ) );
2088
QPoint topLeftCorner;
2089
QPoint botRightCorner;
2094
topLeftCorner = QPoint( top.right() + 1, top.top() );
2095
botRightCorner = QPoint( bot.left() - 1, top.bottom() );
2098
topLeftCorner = QPoint( top.left(), top.bottom() + 1 );
2099
botRightCorner = QPoint( top.right(), bot.top() - 1 );
2102
// define rect, and reduce margins
2103
QRect r( topLeftCorner, botRightCorner );
2104
if( horizontal ) r.adjust( 0, 1, 0, -1 );
2105
else r.adjust( 1, 0, -1, 0 );
2107
return handleRTL( option, r );
2110
case SC_ScrollBarSlider:
2112
const QStyleOptionSlider* slOpt = qstyleoption_cast<const QStyleOptionSlider*>( option );
2113
if( !slOpt ) return QRect();
2115
//We do handleRTL here to unreflect things if need be
2116
QRect groove = handleRTL( option, scrollBarSubControlRect( option, SC_ScrollBarGroove, widget ) );
2118
if ( slOpt->minimum == slOpt->maximum ) return groove;
2120
//Figure out how much room we have..
2121
int space( horizontal ? groove.width() : groove.height() );
2123
//Calculate the portion of this space that the slider should take up.
2124
int sliderSize = space * qreal( slOpt->pageStep ) / ( slOpt->maximum - slOpt->minimum + slOpt->pageStep );
2125
sliderSize = qMax( sliderSize, ( int )ScrollBar_MinimumSliderHeight );
2126
sliderSize = qMin( sliderSize, space );
2128
space -= sliderSize;
2129
if( space <= 0 ) return groove;
2131
int pos = qRound( qreal( slOpt->sliderPosition - slOpt->minimum )/ ( slOpt->maximum - slOpt->minimum )*space );
2132
if( slOpt->upsideDown ) pos = space - pos;
2133
if( horizontal ) return handleRTL( option, QRect( groove.x() + pos, groove.y(), sliderSize, groove.height() ) );
2134
else return handleRTL( option, QRect( groove.x(), groove.y() + pos, groove.width(), sliderSize ) );
2137
case SC_ScrollBarSubPage:
2140
//We do handleRTL here to unreflect things if need be
2141
QRect slider = handleRTL( option, scrollBarSubControlRect( option, SC_ScrollBarSlider, widget ) );
2142
QRect groove = handleRTL( option, scrollBarSubControlRect( option, SC_ScrollBarGroove, widget ) );
2144
if( horizontal ) return handleRTL( option, QRect( groove.x(), groove.y(), slider.x() - groove.x(), groove.height() ) );
2145
else return handleRTL( option, QRect( groove.x(), groove.y(), groove.width(), slider.y() - groove.y() ) );
2148
case SC_ScrollBarAddPage:
2151
//We do handleRTL here to unreflect things if need be
2152
QRect slider = handleRTL( option, scrollBarSubControlRect( option, SC_ScrollBarSlider, widget ) );
2153
QRect groove = handleRTL( option, scrollBarSubControlRect( option, SC_ScrollBarGroove, widget ) );
2155
if( horizontal ) return handleRTL( option, QRect( slider.right() + 1, groove.y(), groove.right() - slider.right(), groove.height() ) );
2156
else return handleRTL( option, QRect( groove.x(), slider.bottom() + 1, groove.width(), groove.bottom() - slider.bottom() ) );
2160
default: return QRect();
2164
//___________________________________________________________________________________________________________________
2165
QRect Style::spinBoxSubControlRect( const QStyleOptionComplex* option, SubControl subControl, const QWidget* widget ) const
2168
const QRect& r( option->rect );
2169
const QStyleOptionSpinBox *sb = qstyleoption_cast<const QStyleOptionSpinBox *>( option );
2172
int fw = SpinBox_FrameWidth;
2173
int bw = SpinBox_ButtonWidth;
2174
int bm = SpinBox_ButtonMargin;
2175
int bml = bm + SpinBox_ButtonMargin_Left;
2176
int bmt = bm + SpinBox_ButtonMargin_Top;
2177
int bmr = bm + SpinBox_ButtonMargin_Right;
2178
int bmb = bm + SpinBox_ButtonMargin_Bottom;
2186
// TODO: why is bml not also set to 0
2187
bmt = bmb = bmr = 0;
2190
const int buttonsWidth = bw-bml-bmr;
2191
const int buttonsLeft = r.right()-bw+bml+1;
2193
// compute the height of each button...
2194
const int availableButtonHeight = r.height()-bmt-bmb - bs;
2195
const int heightUp = availableButtonHeight / 2;
2196
const int heightDown = availableButtonHeight - heightUp;
2198
switch ( subControl )
2202
return handleRTL( option, QRect( buttonsLeft, r.top()+bmt, buttonsWidth, heightUp ) );
2204
case SC_SpinBoxDown:
2205
return handleRTL( option, QRect( buttonsLeft, r.bottom()-bmb-heightDown, buttonsWidth, heightDown ) );
2207
case SC_SpinBoxEditField:
2209
const QRect labelRect( r.left()+fw, r.top()+fw, r.width()-fw-bw, r.height()-2*fw );
2210
return handleRTL( option, labelRect );
2213
case SC_SpinBoxFrame:
2214
return sb->frame ? r : QRect();
2221
return QCommonStyle::subControlRect( CC_SpinBox, option, subControl, widget );
2225
//______________________________________________________________
2226
QSize Style::checkBoxSizeFromContents( const QStyleOption*, const QSize& contentsSize, const QWidget* ) const
2229
//Add size for indicator
2230
const int indicator( CheckBox_Size );
2232
//Make sure we can fit the indicator
2233
QSize size( contentsSize );
2234
size.setHeight( qMax( size.height(), indicator ) );
2236
//Add space for the indicator and the icon
2237
const int spacer( CheckBox_BoxTextSpace );
2238
size.rwidth() += indicator + spacer;
2244
//______________________________________________________________
2245
QSize Style::comboBoxSizeFromContents( const QStyleOption* option, const QSize& contentsSize, const QWidget* ) const
2248
QSize size = expandSize( contentsSize,
2249
ComboBox_ContentsMargin,
2250
ComboBox_ContentsMargin_Left,
2251
ComboBox_ContentsMargin_Top,
2252
ComboBox_ContentsMargin_Right,
2253
ComboBox_ContentsMargin_Bottom );
2256
size = expandSize( size, ComboBox_FrameWidth );
2258
// Add the button width
2259
size.rwidth() += ComboBox_ButtonWidth;
2261
// TODO: For some reason the size is not right in the following configurations
2262
// this is still to be understood and might reveal some deeper issue.
2263
// notably, should compare to zhqt is done for PushButtons
2264
const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>( option );
2265
if( cb && !cb->editable && ( !cb->currentIcon.isNull() || cb->fontMetrics.height() > 13 ) ) size.rheight()+=1;
2267
// also expand to account for scrollbar
2268
size.rwidth() += StyleConfigData::scrollBarWidth() - 6;
2273
//______________________________________________________________
2274
QSize Style::headerSectionSizeFromContents( const QStyleOption* option, const QSize& contentsSize, const QWidget* ) const
2277
const QStyleOptionHeader* headerOpt( qstyleoption_cast<const QStyleOptionHeader *>( option ) );
2278
if( !headerOpt ) return contentsSize;
2280
//TODO: check if hardcoded icon size is the right thing to do
2281
QSize iconSize = headerOpt->icon.isNull() ? QSize( 0,0 ) : QSize( 22,22 );
2282
QSize textSize = headerOpt->fontMetrics.size( 0, headerOpt->text );
2284
int iconSpacing = Header_TextToIconSpace;
2285
int w = iconSize.width() + iconSpacing + textSize.width();
2286
int h = qMax( iconSize.height(), textSize.height() );
2288
return expandSize( QSize( w, h ), Header_ContentsMargin );
2292
//______________________________________________________________
2293
QSize Style::menuItemSizeFromContents( const QStyleOption* option, const QSize& contentsSize, const QWidget* widget ) const
2295
const QStyleOptionMenuItem* menuItemOption = qstyleoption_cast<const QStyleOptionMenuItem*>( option );
2296
if( !menuItemOption ) return contentsSize;
2298
// First, we calculate the intrinsic size of the item.
2299
// this must be kept consistent with what's in drawMenuItemContol
2302
switch ( menuItemOption->menuItemType )
2304
case QStyleOptionMenuItem::Normal:
2305
case QStyleOptionMenuItem::DefaultItem:
2306
case QStyleOptionMenuItem::SubMenu:
2308
int iconColW = qMax( menuItemOption->maxIconWidth, ( int ) MenuItem_IconWidth );
2309
int leftColW = iconColW;
2310
if( menuItemOption->menuHasCheckableItems )
2311
{ leftColW += MenuItem_CheckWidth + MenuItem_CheckSpace; }
2313
leftColW += MenuItem_IconSpace;
2315
int rightColW = MenuItem_ArrowSpace + MenuItem_ArrowWidth;
2317
QFontMetrics fm( menuItemOption->font );
2319
int tabPos = menuItemOption->text.indexOf( QLatin1Char( '\t' ) );
2320
if( tabPos == -1 ) textW = contentsSize.width();
2323
// The width of the accelerator is not included here since
2324
// Qt will add that on separately after obtaining the
2325
// sizeFromContents() for each menu item in the menu to be shown
2326
// ( see QMenuPrivate::calcActionRects() )
2327
textW = contentsSize.width() + MenuItem_AccelSpace;
2331
int h = qMax( contentsSize.height(), ( int ) MenuItem_MinHeight );
2332
insideSize = QSize( leftColW + textW + rightColW, h );
2336
case QStyleOptionMenuItem::Separator:
2339
// separator can have a title and an icon
2340
// in that case they are rendered as menubar 'title', which
2341
// corresponds to checked toolbuttons.
2342
// a rectangle identical to the one of normal items is returned.
2343
if( !( menuItemOption->text.isEmpty() && menuItemOption->icon.isNull() ) )
2346
QStyleOptionMenuItem local( *menuItemOption );
2347
local.menuItemType = QStyleOptionMenuItem::Normal;
2348
return menuItemSizeFromContents( &local, contentsSize, widget );
2352
insideSize = QSize( 10, 0 );
2359
case QStyleOptionMenuItem::Scroller:
2360
case QStyleOptionMenuItem::TearOff:
2361
case QStyleOptionMenuItem::Margin:
2362
case QStyleOptionMenuItem::EmptyArea:
2363
return contentsSize;
2366
// apply the outermost margin.
2367
return expandSize( insideSize, MenuItem_Margin );
2371
//______________________________________________________________
2372
QSize Style::pushButtonSizeFromContents( const QStyleOption* option, const QSize& contentsSize, const QWidget* ) const
2375
const QStyleOptionButton* bOpt = qstyleoption_cast<const QStyleOptionButton*>( option );
2376
if( !bOpt ) return contentsSize;
2378
// adjust to handle button margins
2379
QSize size = expandSize( contentsSize,
2380
PushButton_ContentsMargin,
2381
PushButton_ContentsMargin_Left,
2382
PushButton_ContentsMargin_Top,
2383
PushButton_ContentsMargin_Right,
2384
PushButton_ContentsMargin_Bottom );
2386
if( bOpt->features & QStyleOptionButton::HasMenu )
2387
{ size.rwidth() += PushButton_TextToIconSpace; }
2389
if( !bOpt->text.isEmpty() && !bOpt->icon.isNull() )
2392
// Incorporate the spacing between the icon and text. Qt sticks 4 there,
2393
// but we use PushButton::TextToIconSpace.
2394
size.rwidth() += PushButton_TextToIconSpace -4;
2401
//______________________________________________________________
2402
QSize Style::tabBarTabSizeFromContents( const QStyleOption* option, const QSize& contentsSize, const QWidget* widget ) const
2405
const QStyleOptionTab *tabOpt( qstyleoption_cast<const QStyleOptionTab*>( option ) );
2408
const bool verticalTabs( tabOpt && isVerticalTab( tabOpt ) );
2412
size = expandSize( contentsSize,
2413
TabBar_TabContentsMargin,
2414
TabBar_TabContentsMargin_Top,
2415
TabBar_TabContentsMargin_Right,
2416
TabBar_TabContentsMargin_Bottom,
2417
TabBar_TabContentsMargin_Left );
2421
size = expandSize( contentsSize,
2422
TabBar_TabContentsMargin,
2423
TabBar_TabContentsMargin_Left,
2424
TabBar_TabContentsMargin_Top,
2425
TabBar_TabContentsMargin_Right,
2426
TabBar_TabContentsMargin_Bottom );
2430
// need to add extra size to match corner buttons
2431
// try cast parent for tabWidget
2432
const QTabWidget* tabWidget( widget ? qobject_cast<const QTabWidget*>( widget->parent() ):0 );
2433
if( !tabWidget ) return size;
2435
// try get corner widgets
2436
const QWidget* leftWidget( tabWidget->cornerWidget( Qt::TopLeftCorner ) );
2437
const QWidget* rightWidget( tabWidget->cornerWidget( Qt::TopRightCorner ) );
2439
if( leftWidget && leftWidget->isVisible() ) cornerSize = leftWidget->minimumSizeHint();
2440
if( rightWidget && rightWidget->isVisible() ) cornerSize = cornerSize.expandedTo( rightWidget->minimumSizeHint() );
2441
if( !cornerSize.isValid() ) return size;
2444
// note: the extra pixels added to the relevant dimension are fine-tuned.
2445
if( verticalTabs ) size.setWidth( qMax( size.width(), cornerSize.width() + 6 ) );
2446
else size.setHeight( qMax( size.height(), cornerSize.height() + 4 ) );
2452
//______________________________________________________________
2453
QSize Style::toolButtonSizeFromContents( const QStyleOption* option, const QSize& contentsSize, const QWidget* widget ) const
2456
QSize size = contentsSize;
2457
const QStyleOptionToolButton* tbOpt = qstyleoption_cast<const QStyleOptionToolButton*>( option );
2458
if( tbOpt && !tbOpt->icon.isNull() && !tbOpt->text.isEmpty() && tbOpt->toolButtonStyle == Qt::ToolButtonTextUnderIcon )
2459
{ size.rheight() -= 5; }
2461
// We want to avoid super-skiny buttons, for things like "up" when icons + text
2462
// For this, we would like to make width >= height.
2463
// However, once we get here, QToolButton may have already put in the menu area
2464
// ( PM_MenuButtonIndicator ) into the width. So we may have to take it out, fix things
2465
// up, and add it back in. So much for class-independent rendering...
2466
int menuAreaWidth = 0;
2470
if( tbOpt->features & QStyleOptionToolButton::MenuButtonPopup )
2473
menuAreaWidth = pixelMetric( QStyle::PM_MenuButtonIndicator, option, widget );
2475
} else if( tbOpt->features & QStyleOptionToolButton::HasMenu ) {
2477
// TODO: something wrong here: The size is not properly accounted for
2478
// when drawing the slab.
2479
size.rwidth() += ToolButton_InlineMenuIndicatorSize;
2485
size.rwidth() -= menuAreaWidth;
2486
if( size.width() < size.height() ) size.setWidth( size.height() );
2488
size.rwidth() += menuAreaWidth;
2490
const QToolButton* t( qobject_cast<const QToolButton*>( widget ) );
2491
if( t && t->autoRaise() ) return expandSize( size, ToolButton_ContentsMargin ); // these are toolbutton margins
2492
else return expandSize( size,
2493
PushButton_ContentsMargin, 0,
2494
PushButton_ContentsMargin_Top, 0,
2495
PushButton_ContentsMargin_Bottom );
2499
//___________________________________________________________________________________
2500
bool Style::drawFramePrimitive( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
2502
const State& flags( option->state );
2503
const QRect& r( option->rect );
2504
const QPalette& palette( option->palette );
2506
const bool enabled( flags & State_Enabled );
2507
const bool isInputWidget( widget && widget->testAttribute( Qt::WA_Hover ) );
2508
const bool hoverHighlight( enabled && isInputWidget && ( flags&State_MouseOver ) );
2511
//const bool focusHighlight( enabled && isInputWidget && ( flags&State_HasFocus ) );
2512
bool focusHighlight( false );
2513
if( enabled && isInputWidget && ( flags&State_HasFocus ) ) focusHighlight = true;
2514
else if( isKTextEditFrame( widget ) && widget->parentWidget()->hasFocus() )
2515
{ focusHighlight = true; }
2517
// assume focus takes precedence over hover
2518
animations().lineEditEngine().updateState( widget, AnimationFocus, focusHighlight );
2519
animations().lineEditEngine().updateState( widget, AnimationHover, hoverHighlight && !focusHighlight );
2521
if( flags & State_Sunken )
2523
const QRect local( r.adjusted( 1, 1, -1, -1 ) );
2524
qreal opacity( -1 );
2525
AnimationMode mode = AnimationNone;
2526
if( enabled && animations().lineEditEngine().isAnimated( widget, AnimationFocus ) )
2529
opacity = animations().lineEditEngine().opacity( widget, AnimationFocus );
2530
mode = AnimationFocus;
2532
} else if( enabled && animations().lineEditEngine().isAnimated( widget, AnimationHover ) ) {
2534
opacity = animations().lineEditEngine().opacity( widget, AnimationHover );
2535
mode = AnimationHover;
2539
if( frameShadowFactory().isRegistered( widget ) )
2542
frameShadowFactory().updateState( widget, focusHighlight, hoverHighlight, opacity, mode );
2546
HoleOptions options( 0 );
2547
if( focusHighlight ) options |= HoleFocus;
2548
if( hoverHighlight ) options |= HoleHover;
2550
helper().renderHole(
2551
painter, palette.color( QPalette::Window ), local, options,
2552
opacity, mode, TileSet::Ring );
2556
} else if( flags & State_Raised ) {
2558
const QRect local( r.adjusted( -1, -1, 1, 1 ) );
2559
renderSlab( painter, local, palette.color( QPalette::Background ), NoFill );
2566
//___________________________________________________________________________________
2567
bool Style::drawFrameFocusRectPrimitive( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
2570
if( !widget ) return true;
2572
// focus indicators are painted only in Q3ListView and QAbstractItemView
2573
if( !( qobject_cast<const QAbstractItemView*>( widget ) || widget->inherits( "Q3ListView" ) ) ) return true;
2575
const State& flags( option->state );
2576
const QRect r( option->rect.adjusted( 0, 0, 0, -1 ) );
2577
const QPalette& palette( option->palette );
2579
if( r.width() < 10 ) return true;
2581
QLinearGradient lg( r.bottomLeft(), r.bottomRight() );
2583
lg.setColorAt( 0.0, Qt::transparent );
2584
lg.setColorAt( 1.0, Qt::transparent );
2585
if( flags & State_Selected )
2588
lg.setColorAt( 0.2, palette.color( QPalette::BrightText ) );
2589
lg.setColorAt( 0.8, palette.color( QPalette::BrightText ) );
2593
lg.setColorAt( 0.2, palette.color( QPalette::Text ) );
2594
lg.setColorAt( 0.8, palette.color( QPalette::Text ) );
2598
painter->setRenderHint( QPainter::Antialiasing, false );
2599
painter->setPen( QPen( lg, 1 ) );
2600
painter->drawLine( r.bottomLeft(), r.bottomRight() );
2606
//______________________________________________________________
2607
bool Style::drawFrameGroupBoxPrimitive( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
2610
// cast option and check
2611
const QStyleOptionFrame *fOpt = qstyleoption_cast<const QStyleOptionFrame *>( option );
2612
if( !fOpt ) return true;
2614
// no frame for flat groupboxes
2615
QStyleOptionFrameV2 fOpt2( *fOpt );
2616
if( fOpt2.features & QStyleOptionFrameV2::Flat ) return true;
2619
const QPalette& palette( option->palette );
2620
const QRect& r( option->rect );
2621
const QColor base( helper().backgroundColor( palette.color( QPalette::Window ), widget, r.center() ) );
2624
painter->setRenderHint( QPainter::Antialiasing );
2625
painter->setPen( Qt::NoPen );
2627
QLinearGradient innerGradient( 0, r.top()-r.height()+12, 0, r.bottom()+r.height()-19 );
2628
QColor light( helper().calcLightColor( base ) );
2629
light.setAlphaF( 0.4 ); innerGradient.setColorAt( 0.0, light );
2630
light.setAlphaF( 0.0 ); innerGradient.setColorAt( 1.0, light );
2631
painter->setBrush( innerGradient );
2632
painter->setClipRect( r.adjusted( 0, 0, 0, -19 ) );
2633
helper().fillSlab( *painter, r );
2635
painter->setClipping( false );
2636
helper().slope( base, 0.0 )->render( r, painter );
2643
//___________________________________________________________________________________
2644
bool Style::drawFrameMenuPrimitive( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
2646
// only draw frame for ( expanded ) toolbars
2647
// do nothing for other cases
2648
if( qobject_cast<const QToolBar*>( widget ) )
2650
helper().renderWindowBackground( painter, option->rect, widget, option->palette );
2651
helper().drawFloatFrame( painter, option->rect, option->palette.window().color(), true );
2658
//___________________________________________________________________________________
2659
bool Style::drawFrameTabBarBasePrimitive( const QStyleOption* option, QPainter* painter, const QWidget* ) const
2662
// cast option and check
2663
const QStyleOptionTabBarBase* tabOpt( qstyleoption_cast<const QStyleOptionTabBarBase*>( option ) );
2664
if( !tabOpt ) return true;
2666
if( tabOpt->tabBarRect.isValid() )
2669
// if tabBar rect is valid, all the frame is handled in tabBarTabShapeControl
2670
// nothing to be done here.
2671
// on the other hand, invalid tabBarRect corresponds to buttons in tabbars ( e.g. corner buttons ),
2672
// and the appropriate piece of frame needs to be drawn
2677
// store palette and rect
2678
const QPalette& palette( option->palette );
2679
const QRect& r( option->rect );
2681
QRect frameRect( r );
2683
switch( tabOpt->shape )
2685
case QTabBar::RoundedNorth:
2686
case QTabBar::TriangularNorth:
2688
frameRect.adjust( -7, -GlowWidth, 7, GlowWidth );
2689
frameRect.translate( 0, 4 );
2690
slab = SlabRect( frameRect, TileSet::Top );
2694
case QTabBar::RoundedSouth:
2695
case QTabBar::TriangularSouth:
2697
frameRect.adjust( -7, -GlowWidth, 7, GlowWidth );
2698
frameRect.translate( 0, -4 );
2699
slab = SlabRect( frameRect, TileSet::Bottom );
2703
case QTabBar::RoundedWest:
2704
case QTabBar::TriangularWest:
2706
frameRect.adjust( -GlowWidth, -7, GlowWidth, 7 + 1 );
2707
frameRect.translate( 5, 0 );
2708
slab = SlabRect( frameRect, TileSet::Left );
2712
case QTabBar::RoundedEast:
2713
case QTabBar::TriangularEast:
2715
frameRect.adjust( -GlowWidth, -7, GlowWidth, 7 + 1 );
2716
frameRect.translate( -5, 0 );
2717
slab = SlabRect( frameRect, TileSet::Right );
2721
default: return true;
2724
// render registered slabs
2725
renderSlab( painter, slab, palette.color( QPalette::Window ), NoFill );
2730
//___________________________________________________________________________________
2731
bool Style::drawFrameTabWidgetPrimitive( const QStyleOption* option, QPainter* painter, const QWidget* ) const
2734
// cast option and check
2735
const QStyleOptionTabWidgetFrame* tabOpt( qstyleoption_cast<const QStyleOptionTabWidgetFrame*>( option ) );
2736
if( !tabOpt ) return true;
2738
const QRect& r( option->rect );
2739
const QPalette& palette( option->palette );
2740
const bool reverseLayout( option->direction == Qt::RightToLeft );
2743
no frame is drawn when tabbar is empty.
2744
this is consistent with the tabWidgetTabContents subelementRect
2746
if( tabOpt->tabBarSize.isEmpty() ) return true;
2748
// get tabbar dimentions
2749
const int w( tabOpt->tabBarSize.width() );
2750
const int h( tabOpt->tabBarSize.height() );
2752
// left corner widget
2753
const int lw( tabOpt->leftCornerWidgetSize.width() );
2754
const int lh( tabOpt->leftCornerWidgetSize.height() );
2757
const int rw( tabOpt->rightCornerWidgetSize.width() );
2758
const int rh( tabOpt->rightCornerWidgetSize.height() );
2760
// list of slabs to be drawn
2763
// expand rect by glow width.
2764
QRect baseSlabRect( insideMargin( r, -GlowWidth ) );
2766
// render the three free sides
2767
switch( tabOpt->shape )
2769
case QTabBar::RoundedNorth:
2770
case QTabBar::TriangularNorth:
2773
slabs << SlabRect( baseSlabRect, ( TileSet::Ring & ~TileSet::Top ) );
2780
QRect slabRect( baseSlabRect );
2781
slabRect.setRight( qMax( slabRect.right() - w - lw, slabRect.left() + rw ) + 7 );
2782
slabRect.setHeight( 7 );
2783
slabs << SlabRect( slabRect, TileSet::TopLeft );
2788
QRect slabRect( baseSlabRect );
2789
slabRect.setLeft( slabRect.right() - rw - 7 );
2790
slabRect.setHeight( 7 );
2791
slabs << SlabRect( slabRect, TileSet::TopRight );
2800
QRect slabRect( baseSlabRect );
2801
slabRect.setRight( baseSlabRect.left() + lw + 7 );
2802
slabRect.setHeight( 7 );
2803
slabs << SlabRect( slabRect, TileSet::TopLeft );
2809
QRect slabRect( baseSlabRect );
2810
slabRect.setLeft( qMin( slabRect.left() + w + lw + 1, slabRect.right() - rw ) -7 );
2811
slabRect.setHeight( 7 );
2812
slabs << SlabRect( slabRect, TileSet::TopRight );
2818
case QTabBar::RoundedSouth:
2819
case QTabBar::TriangularSouth:
2822
slabs << SlabRect( baseSlabRect, TileSet::Ring & ~TileSet::Bottom );
2828
QRect slabRect( baseSlabRect );
2829
slabRect.setRight( qMax( slabRect.right() - w - lw, slabRect.left() + rw ) + 7 );
2830
slabRect.setTop( slabRect.bottom() - 7 );
2831
slabs << SlabRect( slabRect, TileSet::BottomLeft );
2836
QRect slabRect( baseSlabRect );
2837
slabRect.setLeft( slabRect.right() - rw - 7 );
2838
slabRect.setTop( slabRect.bottom() - 7 );
2839
slabs << SlabRect( slabRect, TileSet::BottomRight );
2848
QRect slabRect( baseSlabRect );
2849
slabRect.setRight( baseSlabRect.left() + lw + 7 );
2850
slabRect.setTop( slabRect.bottom() - 7 );
2851
slabs << SlabRect( slabRect, TileSet::BottomLeft );
2856
QRect slabRect( baseSlabRect );
2857
slabRect.setLeft( qMin( slabRect.left() + w + lw + 1, slabRect.right() - rw ) -7 );
2858
slabRect.setTop( slabRect.bottom() - 7 );
2859
slabs << SlabRect( slabRect, TileSet::BottomRight );
2866
case QTabBar::RoundedWest:
2867
case QTabBar::TriangularWest:
2869
slabs << SlabRect( baseSlabRect, TileSet::Ring & ~TileSet::Left );
2875
QRect slabRect( baseSlabRect );
2876
slabRect.setBottom( baseSlabRect.top() + lh + 7 + 1 );
2877
slabRect.setWidth( 7 );
2878
slabs << SlabRect( slabRect, TileSet::TopLeft );
2883
QRect slabRect( baseSlabRect );
2884
slabRect.setTop( qMin( slabRect.top() + h + lh, slabRect.bottom() - rh ) -7 + 1 );
2885
slabRect.setWidth( 7 );
2886
slabs << SlabRect( slabRect, TileSet::BottomLeft );
2891
case QTabBar::RoundedEast:
2892
case QTabBar::TriangularEast:
2894
slabs << SlabRect( baseSlabRect, TileSet::Ring & ~TileSet::Right );
2900
QRect slabRect( baseSlabRect );
2901
slabRect.setBottom( baseSlabRect.top() + lh + 7 + 1 );
2902
slabRect.setLeft( slabRect.right()-7 );
2903
slabs << SlabRect( slabRect, TileSet::TopRight );
2908
QRect slabRect( baseSlabRect );
2909
slabRect.setTop( qMin( slabRect.top() + h + lh, slabRect.bottom() - rh ) -7 + 1 );
2910
slabRect.setLeft( slabRect.right()-7 );
2911
slabs << SlabRect( slabRect, TileSet::BottomRight );
2920
// render registered slabs
2921
foreach( const SlabRect& slab, slabs )
2922
{ renderSlab( painter, slab, palette.color( QPalette::Window ), NoFill ); }
2928
//___________________________________________________________________________________
2929
bool Style::drawFrameWindowPrimitive( const QStyleOption* option, QPainter* painter, const QWidget* ) const
2932
const QRect& r( option->rect );
2933
const QPalette& palette( option->palette );
2934
helper().drawFloatFrame( painter, r, palette.window().color(), false );
2940
//___________________________________________________________________________________
2941
bool Style::drawIndicatorArrowPrimitive( ArrowOrientation orientation, const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
2943
QRect r( option->rect );
2944
const QPalette& palette( option->palette );
2945
const State& flags( option->state );
2946
const bool enabled( flags & State_Enabled );
2947
const bool mouseOver( enabled && ( flags & State_MouseOver ) );
2949
// define gradient and polygon for drawing arrow
2950
const QPolygonF a = genericArrow( orientation, ArrowNormal );
2952
const qreal penThickness = 1.6;
2953
const qreal offset( qMin( penThickness, qreal( 1.0 ) ) );
2956
const QToolButton* toolButton( qobject_cast<const QToolButton*>( widget ) );
2957
if( toolButton && toolButton->arrowType() != Qt::NoArrow )
2961
arrows painted in toolbutton need a re-centered rect,
2962
and have no highlight
2965
r.translate( 1, 0 );
2967
// set color properly
2968
color = (toolButton->autoRaise() ? palette.color( QPalette::WindowText ):palette.color( QPalette::ButtonText ) );
2970
} else if( mouseOver ) {
2972
color = helper().viewHoverBrush().brush( palette ).color();
2976
color = palette.color( QPalette::WindowText );
2980
painter->translate( r.center() );
2981
painter->setRenderHint( QPainter::Antialiasing );
2983
painter->translate( 0,offset );
2984
const QColor background = palette.color( QPalette::Window );
2985
painter->setPen( QPen( helper().calcLightColor( background ), penThickness, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) );
2986
painter->drawPolyline( a );
2987
painter->translate( 0,-offset );
2989
painter->setPen( QPen( helper().decoColor( background, color ) , penThickness, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) );
2990
painter->drawPolyline( a );
2995
//___________________________________________________________________________________
2996
bool Style::drawIndicatorHeaderArrowPrimitive( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
2998
const QStyleOptionHeader *headerOpt = qstyleoption_cast<const QStyleOptionHeader *>( option );
2999
const State& flags( option->state );
3001
// arrow orientation
3002
ArrowOrientation orientation( ArrowNone );
3003
if( flags&State_UpArrow || ( headerOpt && headerOpt->sortIndicator==QStyleOptionHeader::SortUp ) ) orientation = ArrowUp;
3004
else if( flags&State_DownArrow || ( headerOpt && headerOpt->sortIndicator==QStyleOptionHeader::SortDown ) ) orientation = ArrowDown;
3005
if( orientation == ArrowNone ) return true;
3007
// flags, rect and palette
3008
const QRect& r( option->rect );
3009
const QPalette& palette( option->palette );
3010
const bool enabled( flags & State_Enabled );
3011
const bool mouseOver( enabled && ( flags & State_MouseOver ) );
3013
animations().headerViewEngine().updateState( widget, r.topLeft(), mouseOver );
3014
const bool animated( enabled && animations().headerViewEngine().isAnimated( widget, r.topLeft() ) );
3016
// define gradient and polygon for drawing arrow
3017
const QPolygonF a = genericArrow( orientation, ArrowNormal );
3018
QColor color = palette.color( QPalette::WindowText );
3019
const QColor background = palette.color( QPalette::Window );
3020
const QColor highlight( helper().viewHoverBrush().brush( palette ).color() );
3021
const qreal penThickness = 1.6;
3022
const qreal offset( qMin( penThickness, qreal( 1.0 ) ) );
3027
const qreal opacity( animations().headerViewEngine().opacity( widget, r.topLeft() ) );
3028
color = KColorUtils::mix( color, highlight, opacity );
3030
} else if( mouseOver ) color = highlight;
3032
painter->translate( r.center() );
3033
painter->translate( 0, 1 );
3034
painter->setRenderHint( QPainter::Antialiasing );
3036
painter->translate( 0,offset );
3037
painter->setPen( QPen( helper().calcLightColor( background ), penThickness, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) );
3038
painter->drawPolyline( a );
3039
painter->translate( 0,-offset );
3041
painter->setPen( QPen( helper().decoColor( background, color ) , penThickness, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) );
3042
painter->drawPolyline( a );
3047
//______________________________________________________________
3048
bool Style::drawPanelButtonCommandPrimitive( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
3050
const State& flags( option->state );
3051
const bool enabled( flags & State_Enabled );
3052
const bool mouseOver( enabled && ( flags & State_MouseOver ) );
3053
const bool hasFocus( enabled && ( flags & State_HasFocus ) );
3054
const QPalette& palette( option->palette );
3056
StyleOptions opts = 0;
3057
if( flags & ( State_On|State_Sunken ) ) opts |= Sunken;
3058
if( flags & State_HasFocus ) opts |= Focus;
3059
if( enabled && ( flags & State_MouseOver ) ) opts |= Hover;
3061
// update animation state
3062
animations().widgetStateEngine().updateState( widget, AnimationHover, mouseOver );
3063
animations().widgetStateEngine().updateState( widget, AnimationFocus, hasFocus && !mouseOver );
3065
// store animation state
3066
const bool hoverAnimated( animations().widgetStateEngine().isAnimated( widget, AnimationHover ) );
3067
const bool focusAnimated( animations().widgetStateEngine().isAnimated( widget, AnimationFocus ) );
3068
const qreal hoverOpacity( animations().widgetStateEngine().opacity( widget, AnimationHover ) );
3069
const qreal focusOpacity( animations().widgetStateEngine().opacity( widget, AnimationFocus ) );
3071
// decide if widget must be rendered flat.
3073
The decision is made depending on
3074
- whether the "flat" flag is set in the option
3075
- whether the widget is hight enough to render both icons and normal margins
3076
Note: in principle one should also check for the button text height
3079
const QRect& r( option->rect );
3080
const QStyleOptionButton* bOpt( qstyleoption_cast< const QStyleOptionButton* >( option ) );
3081
bool flat = ( bOpt && (
3082
bOpt->features.testFlag( QStyleOptionButton::Flat ) ||
3083
( ( !bOpt->icon.isNull() ) && sizeFromContents( CT_PushButton, option, bOpt->iconSize, widget ).height() > r.height() ) ) );
3088
QRect slitRect( r );
3089
if( !( opts & Sunken ) )
3092
if( enabled && hoverAnimated )
3095
QColor glow( helper().alphaColor( helper().viewFocusBrush().brush( QPalette::Active ).color(), hoverOpacity ) );
3096
helper().slitFocused( glow )->render( slitRect, painter );
3098
} else if( mouseOver ) {
3100
helper().slitFocused( helper().viewFocusBrush().brush( QPalette::Active ).color() )->render( slitRect, painter );
3106
slitRect.adjust( 0, 0, 0, -1 );
3108
HoleOptions options( 0 );
3109
if( mouseOver ) options |= HoleHover;
3111
// flat pressed-down buttons do not get focus effect,
3112
// consistently with tool buttons
3113
if( enabled && hoverAnimated )
3116
helper().renderHole( painter, palette.color( QPalette::Window ), slitRect, options, hoverOpacity, AnimationHover, TileSet::Ring );
3120
helper().renderHole( painter, palette.color( QPalette::Window ), slitRect, options );
3128
const QRect slabRect( r.adjusted( -1, 0, 1, 0 ) );
3130
// match color to the window background
3131
const QColor buttonColor( helper().backgroundColor( palette.color( QPalette::Button ), widget, r.center() ) );
3133
if( enabled && hoverAnimated && !( opts & Sunken ) )
3136
renderButtonSlab( painter, slabRect, buttonColor, opts, hoverOpacity, AnimationHover, TileSet::Ring );
3138
} else if( enabled && !mouseOver && focusAnimated && !( opts & Sunken ) ) {
3140
renderButtonSlab( painter, slabRect, buttonColor, opts, focusOpacity, AnimationFocus, TileSet::Ring );
3144
renderButtonSlab( painter, slabRect, buttonColor, opts );
3154
//______________________________________________________________
3155
bool Style::drawPanelButtonToolPrimitive( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
3159
For toolbutton in TabBars, corresponding to expanding arrows, no frame is drawn
3160
However one needs to draw the window background, because the button rect might
3161
overlap with some tab below. ( this is a Qt bug )
3163
const bool isInTabBar( widget && qobject_cast<const QTabBar*>( widget->parent() ) );
3167
const QPalette& palette( option->palette );
3168
QRect r( option->rect );
3170
// adjust rect depending on shape
3171
const QTabBar* tabBar( static_cast<const QTabBar*>( widget->parent() ) );
3172
switch( tabBar->shape() )
3174
case QTabBar::RoundedNorth:
3175
case QTabBar::TriangularNorth:
3176
r.setBottom( r.bottom()-6 );
3179
case QTabBar::RoundedSouth:
3180
case QTabBar::TriangularSouth:
3181
r.setTop( r.top() + 6 );
3184
case QTabBar::RoundedWest:
3185
case QTabBar::TriangularWest:
3186
r.setRight( r.right() - 6 );
3189
case QTabBar::RoundedEast:
3190
case QTabBar::TriangularEast:
3191
r.setLeft( r.left() + 6 );
3198
const QPalette local( widget->parentWidget() ? widget->parentWidget()->palette() : palette );
3200
// check whether parent has autofill background flag
3201
const QWidget* parent = helper().checkAutoFillBackground( widget );
3202
if( parent && !qobject_cast<const QDockWidget*>( parent ) ) painter->fillRect( r, parent->palette().color( parent->backgroundRole() ) );
3203
else helper().renderWindowBackground( painter, r, widget, local );
3209
const QRect& r( option->rect );
3210
const State& flags( option->state );
3211
const QPalette& palette( option->palette );
3213
const bool enabled( flags & State_Enabled );
3214
const bool mouseOver( enabled && ( flags & State_MouseOver ) );
3215
const bool hasFocus( enabled && ( flags & State_HasFocus ) );
3216
const bool reverseLayout( option->direction == Qt::RightToLeft );
3217
const bool autoRaised( flags & State_AutoRaise );
3219
// check whether toolbutton is in toolbar
3220
const bool isInToolBar( widget && qobject_cast<const QToolBar*>( widget->parent() ) );
3223
const bool toolBarAnimated( isInToolBar && widget && ( animations().toolBarEngine().isAnimated( widget->parentWidget() ) || animations().toolBarEngine().isFollowMouseAnimated( widget->parentWidget() ) ) );
3224
const QRect animatedRect( ( isInToolBar && widget ) ? animations().toolBarEngine().animatedRect( widget->parentWidget() ):QRect() );
3225
const QRect childRect( ( widget && widget->parentWidget() ) ? r.translated( widget->mapToParent( QPoint( 0,0 ) ) ):QRect() );
3226
const QRect currentRect( widget ? animations().toolBarEngine().currentRect( widget->parentWidget() ):QRect() );
3227
const bool current( isInToolBar && widget && widget->parentWidget() && currentRect.intersects( r.translated( widget->mapToParent( QPoint( 0,0 ) ) ) ) );
3228
const bool toolBarTimerActive( isInToolBar && widget && animations().toolBarEngine().isTimerActive( widget->parentWidget() ) );
3229
const qreal toolBarOpacity( ( isInToolBar && widget ) ? animations().toolBarEngine().opacity( widget->parentWidget() ):0 );
3231
// toolbutton engine
3232
if( isInToolBar && !toolBarAnimated )
3235
animations().widgetStateEngine().updateState( widget, AnimationHover, mouseOver );
3239
// mouseOver has precedence over focus
3240
animations().widgetStateEngine().updateState( widget, AnimationHover, mouseOver );
3241
animations().widgetStateEngine().updateState( widget, AnimationFocus, hasFocus && !mouseOver );
3245
bool hoverAnimated( animations().widgetStateEngine().isAnimated( widget, AnimationHover ) );
3246
bool focusAnimated( animations().widgetStateEngine().isAnimated( widget, AnimationFocus ) );
3248
qreal hoverOpacity( animations().widgetStateEngine().opacity( widget, AnimationHover ) );
3249
qreal focusOpacity( animations().widgetStateEngine().opacity( widget, AnimationFocus ) );
3252
QRect slitRect( r );
3254
// non autoraised tool buttons get same slab as regular buttons
3255
if( widget && !autoRaised )
3258
StyleOptions opts = 0;
3259
slitRect.adjust( -1, 0, 1, 0 );
3261
// "normal" parent, and non "autoraised" ( that is: always raised ) buttons
3262
if( flags & ( State_On|State_Sunken ) ) opts |= Sunken;
3263
if( flags & State_HasFocus ) opts |= Focus;
3264
if( enabled && ( flags & State_MouseOver ) ) opts |= Hover;
3266
TileSet::Tiles tiles( TileSet::Ring );
3268
// adjust tiles and rect in case of menubutton
3269
const QToolButton* t = qobject_cast<const QToolButton*>( widget );
3270
if( t && t->popupMode()==QToolButton::MenuButtonPopup )
3275
tiles = TileSet::Bottom | TileSet::Top | TileSet::Right;
3276
slitRect.adjust( -4, 0, 0, 0 );
3279
tiles = TileSet::Bottom | TileSet::Top | TileSet::Left;
3280
slitRect.adjust( 0, 0, 4, 0 );
3284
// adjust opacity and animation mode
3285
qreal opacity( -1 );
3286
AnimationMode mode( AnimationNone );
3287
if( enabled && hoverAnimated )
3289
opacity = hoverOpacity;
3290
mode = AnimationHover;
3292
} else if( enabled && !hasFocus && focusAnimated ) {
3294
opacity = focusOpacity;
3295
mode = AnimationFocus;
3299
// match button color to window background
3300
const QColor buttonColor( helper().backgroundColor( palette.color( QPalette::Button ), widget, r.center() ) );
3303
renderButtonSlab( painter, slitRect, buttonColor, opts, opacity, mode, tiles );
3309
//! fine tuning of slitRect geometry
3310
if( widget && widget->inherits( "QDockWidgetTitleButton" ) ) slitRect.adjust( 1, 0, 0, 0 );
3311
else if( widget && widget->inherits( "QToolBarExtension" ) ) slitRect.adjust( 1, 1, -1, -1 );
3312
else if( widget && widget->objectName() == "qt_menubar_ext_button" ) slitRect.adjust( -1, -1, 0, 0 );
3314
// normal ( auto-raised ) toolbuttons
3315
if( flags & ( State_Sunken|State_On ) )
3321
qreal opacity = 1.0;
3322
const qreal bias = 0.75;
3323
if( enabled && hoverAnimated )
3326
opacity = 1.0 - bias*hoverOpacity;
3328
} else if( toolBarAnimated && enabled && animatedRect.isNull() && current ) {
3330
opacity = 1.0 - bias*toolBarOpacity;
3332
} else if( enabled && (( toolBarTimerActive && current ) || mouseOver ) ) {
3334
opacity = 1.0 - bias;
3340
QColor color( helper().backgroundColor( helper().calcMidColor( palette.color( QPalette::Window ) ), widget, slitRect.center() ) );
3341
color = helper().alphaColor( color, opacity );
3343
painter->setRenderHint( QPainter::Antialiasing );
3344
painter->setPen( Qt::NoPen );
3345
painter->setBrush( color );
3346
painter->drawRoundedRect( slitRect.adjusted( 1, 1, -1, -1 ), 3.5, 3.5 );
3353
HoleOptions options( HoleContrast );
3354
if( hasFocus && enabled ) options |= HoleFocus;
3355
if( mouseOver && enabled ) options |= HoleHover;
3357
if( enabled && hoverAnimated )
3360
helper().renderHole( painter, palette.color( QPalette::Window ), slitRect, options, hoverOpacity, AnimationHover, TileSet::Ring );
3362
} else if( toolBarAnimated ) {
3364
if( enabled && animatedRect.isNull() && current )
3367
helper().renderHole( painter, palette.color( QPalette::Window ), slitRect, options, toolBarOpacity, AnimationHover, TileSet::Ring );
3371
helper().renderHole( painter, palette.color( QPalette::Window ), slitRect, HoleContrast );
3375
} else if( toolBarTimerActive && current ) {
3377
helper().renderHole( painter, palette.color( QPalette::Window ), slitRect, options | HoleHover );
3381
helper().renderHole( painter, palette.color( QPalette::Window ), slitRect, options );
3387
if( enabled && hoverAnimated )
3390
QColor glow( helper().alphaColor( helper().viewFocusBrush().brush( QPalette::Active ).color(), hoverOpacity ) );
3391
helper().slitFocused( glow )->render( slitRect, painter );
3393
} else if( toolBarAnimated ) {
3395
if( enabled && animatedRect.isNull() && current )
3397
QColor glow( helper().alphaColor( helper().viewFocusBrush().brush( QPalette::Active ).color(), toolBarOpacity ) );
3398
helper().slitFocused( glow )->render( slitRect, painter );
3401
} else if( hasFocus || mouseOver || ( toolBarTimerActive && current ) ) {
3403
helper().slitFocused( helper().viewFocusBrush().brush( QPalette::Active ).color() )->render( slitRect, painter );
3412
//___________________________________________________________________________________
3413
bool Style::drawPanelItemViewItemPrimitive( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
3416
const QStyleOptionViewItemV4 *opt = qstyleoption_cast<const QStyleOptionViewItemV4*>( option );
3417
const QAbstractItemView *view = qobject_cast<const QAbstractItemView *>( widget );
3418
const bool hover = ( option->state & State_MouseOver ) && ( !view || view->selectionMode() != QAbstractItemView::NoSelection );
3420
const bool hasCustomBackground = opt->backgroundBrush.style() != Qt::NoBrush && !( option->state & State_Selected );
3421
const bool hasSolidBackground = !hasCustomBackground || opt->backgroundBrush.style() == Qt::SolidPattern;
3423
if( !hover && !( option->state & State_Selected ) && !hasCustomBackground && !( opt->features & QStyleOptionViewItemV2::Alternate ) )
3426
QPalette::ColorGroup cg;
3427
if( option->state & State_Enabled ) cg = ( option->state & State_Active ) ? QPalette::Normal : QPalette::Inactive;
3428
else cg = QPalette::Disabled;
3431
if( hasCustomBackground && hasSolidBackground ) color = opt->backgroundBrush.color();
3432
else color = option->palette.color( cg, QPalette::Highlight );
3434
if( hover && !hasCustomBackground )
3436
if( !( option->state & State_Selected ) ) color.setAlphaF( 0.2 );
3437
else color = color.lighter( 110 );
3440
if( opt && ( opt->features & QStyleOptionViewItemV2::Alternate ) )
3441
{ painter->fillRect( option->rect, option->palette.brush( cg, QPalette::AlternateBase ) ); }
3443
if( !hover && !( option->state & State_Selected ) && !hasCustomBackground )
3446
if( hasCustomBackground && !hasSolidBackground )
3449
const QPointF oldBrushOrigin = painter->brushOrigin();
3450
painter->setBrushOrigin( opt->rect.topLeft() );
3451
painter->setBrush( opt->backgroundBrush );
3452
painter->setPen( Qt::NoPen );
3453
painter->drawRect( opt->rect );
3454
painter->setBrushOrigin( oldBrushOrigin );
3458
// get selection tileset
3459
QRect r = option->rect;
3460
TileSet *tileSet( helper().selection( color, r.height(), hasCustomBackground ) );
3462
bool roundedLeft = false;
3463
bool roundedRight = false;
3467
roundedLeft = ( opt->viewItemPosition == QStyleOptionViewItemV4::Beginning );
3468
roundedRight = ( opt->viewItemPosition == QStyleOptionViewItemV4::End );
3469
if( opt->viewItemPosition == QStyleOptionViewItemV4::OnlyOne ||
3470
opt->viewItemPosition == QStyleOptionViewItemV4::Invalid ||
3471
( view && view->selectionBehavior() != QAbstractItemView::SelectRows ) )
3474
roundedRight = true;
3479
const bool reverseLayout( option->direction == Qt::RightToLeft );
3481
TileSet::Tiles tiles( TileSet::Center );
3482
if( !reverseLayout ? roundedLeft : roundedRight ) tiles |= TileSet::Left;
3483
else r.adjust( -8, 0, 0, 0 );
3485
if( !reverseLayout ? roundedRight : roundedLeft ) tiles |= TileSet::Right;
3486
else r.adjust( 0, 0, 8, 0 );
3488
if( r.isValid() ) tileSet->render( r, painter, tiles );
3494
//___________________________________________________________________________________
3495
bool Style::drawPanelLineEditPrimitive( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
3498
const QRect& r( option->rect );
3499
const QPalette& palette( option->palette );
3501
// cast option and check
3502
const QStyleOptionFrame *panel = qstyleoption_cast<const QStyleOptionFrame*>( option );
3503
if( !panel ) return true;
3505
const QBrush inputBrush( palette.base() );
3506
const int lineWidth( panel->lineWidth );
3511
painter->setRenderHint( QPainter::Antialiasing );
3512
painter->setPen( Qt::NoPen );
3513
painter->setBrush( inputBrush );
3515
helper().fillHole( *painter, r.adjusted( 0, -1, 0, 0 ) );
3516
drawFramePrimitive( panel, painter, widget );
3522
painter->fillRect( r.adjusted( 2,2,-2,-2 ), inputBrush );
3530
//___________________________________________________________________________________
3531
bool Style::drawPanelMenuPrimitive( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
3534
// do nothing if menu is embedded in another widget
3535
// this corresponds to having a transparent background
3536
if( widget && !widget->isWindow() ) return true;
3538
const QStyleOptionMenuItem* mOpt( qstyleoption_cast<const QStyleOptionMenuItem*>( option ) );
3539
if( !( mOpt && widget ) ) return true;
3540
const QRect& r = mOpt->rect;
3541
const QColor color = mOpt->palette.color( widget->window()->backgroundRole() );
3543
const bool hasAlpha( helper().hasAlphaChannel( widget ) );
3547
painter->setCompositionMode( QPainter::CompositionMode_Source );
3548
TileSet *tileSet( helper().roundCorner( color ) );
3549
tileSet->render( r, painter );
3551
painter->setCompositionMode( QPainter::CompositionMode_SourceOver );
3552
painter->setClipRegion( helper().roundedMask( r.adjusted( 1, 1, -1, -1 ) ), Qt::IntersectClip );
3556
helper().renderMenuBackground( painter, r, widget, mOpt->palette );
3558
if( hasAlpha ) painter->setClipping( false );
3559
helper().drawFloatFrame( painter, r, color, !hasAlpha );
3565
//___________________________________________________________________________________
3566
bool Style::drawPanelScrollAreaCornerPrimitive( const QStyleOption*, QPainter*, const QWidget* widget ) const
3568
// disable painting of PE_PanelScrollAreaCorner
3569
// the default implementation fills the rect with the window background color
3570
// which does not work for windows that have gradients.
3571
// unfortunately, this does not work when scrollbars are children of QWebView,
3572
// in which case, false is returned, in order to fall back to the parent style implementation
3573
return !( widget && widget->inherits( "QWebView" ) );
3576
//___________________________________________________________________________________
3577
bool Style::drawPanelTipLabelPrimitive( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
3580
// force registration of widget
3581
if( widget && widget->window() )
3582
{ shadowHelper().registerWidget( widget->window(), true ); }
3584
// parent style painting if frames should not be styled
3585
if( !StyleConfigData::toolTipDrawStyledFrames() ) return false;
3587
const QRect& r( option->rect );
3588
const QColor color( option->palette.brush( QPalette::ToolTipBase ).color() );
3589
QColor topColor( helper().backgroundTopColor( color ) );
3590
QColor bottomColor( helper().backgroundBottomColor( color ) );
3592
// make tooltip semi transparents when possible
3593
// alpha is copied from "kdebase/apps/dolphin/tooltips/filemetadatatooltip.cpp"
3594
const bool hasAlpha( helper().hasAlphaChannel( widget ) );
3595
if( hasAlpha && StyleConfigData::toolTipTransparent() )
3597
topColor.setAlpha( 220 );
3598
bottomColor.setAlpha( 220 );
3601
QLinearGradient gr( 0, r.top(), 0, r.bottom() );
3602
gr.setColorAt( 0, topColor );
3603
gr.setColorAt( 1, bottomColor );
3606
QLinearGradient gr2( 0, r.top(), 0, r.bottom() );
3607
gr2.setColorAt( 0.5, helper().calcLightColor( bottomColor ) );
3608
gr2.setColorAt( 0.9, bottomColor );
3614
painter->setRenderHint( QPainter::Antialiasing );
3617
local.adjust( 0.5, 0.5, -0.5, -0.5 );
3619
painter->setPen( Qt::NoPen );
3620
painter->setBrush( gr );
3621
painter->drawRoundedRect( local, 4, 4 );
3623
painter->setBrush( Qt::NoBrush );
3624
painter->setPen( QPen( gr2, 1.1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) );
3625
painter->drawRoundedRect( local, 3.5, 3.5 );
3629
painter->setPen( Qt::NoPen );
3630
painter->setBrush( gr );
3631
painter->drawRect( r );
3633
painter->setBrush( Qt::NoBrush );
3634
painter->setPen( QPen( gr2, 1.1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) );
3635
painter->drawRect( r );
3645
//___________________________________________________________________________________
3646
bool Style::drawIndicatorMenuCheckMarkPrimitive( const QStyleOption *option, QPainter *painter, const QWidget * ) const
3648
const QRect& r( option->rect );
3649
const State& flags( option->state );
3650
const QPalette& palette( option->palette );
3651
const bool enabled( flags & State_Enabled );
3653
StyleOptions opts( NoFill );
3654
if( !enabled ) opts |= Disabled;
3655
CheckBoxState state = CheckOn;
3657
renderCheckBox( painter, r, palette, opts, state );
3662
//___________________________________________________________________________________
3663
bool Style::drawQ3CheckListIndicatorPrimitive( const QStyleOption *option, QPainter *painter, const QWidget *widget ) const
3665
const QStyleOptionQ3ListView* listViewOpt( qstyleoption_cast<const QStyleOptionQ3ListView*>( option ) );
3666
if( !listViewOpt || listViewOpt->items.isEmpty() ) return true;
3668
QStyleOptionButton buttonOption;
3669
buttonOption.QStyleOption::operator=( *option );
3671
QSize size( CheckBox_Size, CheckBox_Size );
3672
buttonOption.rect = centerRect( option->rect, size ).translated( 0, 4 );
3673
drawIndicatorCheckBoxPrimitive( &buttonOption, painter, widget );
3677
//___________________________________________________________________________________
3678
bool Style::drawQ3CheckListExclusiveIndicatorPrimitive( const QStyleOption *option, QPainter *painter, const QWidget *widget ) const
3680
const QStyleOptionQ3ListView* listViewOpt( qstyleoption_cast<const QStyleOptionQ3ListView*>( option ) );
3681
if( !listViewOpt || listViewOpt->items.isEmpty() ) return true;
3683
QStyleOptionButton buttonOption;
3684
buttonOption.QStyleOption::operator=( *option );
3686
QSize size( CheckBox_Size, CheckBox_Size );
3687
buttonOption.rect = centerRect( option->rect, size ).translated( 0, 4 );
3688
drawIndicatorRadioButtonPrimitive( &buttonOption, painter, widget );
3692
//___________________________________________________________________________________
3693
bool Style::drawIndicatorBranchPrimitive( const QStyleOption* option, QPainter* painter, const QWidget* ) const
3696
const State& flags( option->state );
3697
const QRect& r( option->rect );
3698
const QPalette& palette( option->palette );
3699
const QPoint center( r.center() );
3701
const bool reverseLayout( option->direction == Qt::RightToLeft );
3703
const int centerX = center.x();
3704
const int centerY = center.y();
3706
int expanderAdjust = 0;
3709
if ( flags & State_Children )
3712
int sizeLimit = qMin( qMin( r.width(), r.height() ), ( int ) Tree_MaxExpanderSize );
3713
const bool expanderOpen( flags & State_Open );
3715
// make sure size limit is odd
3716
if( !( sizeLimit&1 ) ) --sizeLimit;
3717
expanderAdjust = sizeLimit/2 + 1;
3719
QRect expanderRect = centerRect( r, sizeLimit, sizeLimit );
3720
const int radius( ( expanderRect.width() - 4 ) / 2 );
3723
const bool enabled( flags & State_Enabled );
3724
const bool mouseOver( enabled && ( flags & State_MouseOver ) );
3727
const QColor expanderColor( mouseOver ? helper().viewHoverBrush().brush( palette ).color():palette.color( QPalette::Text ) );
3729
if( !StyleConfigData::viewDrawTriangularExpander() )
3732
// plus or minus sign used for expanders
3734
painter->setPen( expanderColor );
3735
painter->drawLine( center - QPoint( radius, 0 ), center + QPoint( radius, 0 ) );
3738
{ painter->drawLine( center - QPoint( 0, radius ), center + QPoint( 0, radius ) ); }
3746
painter->translate( center );
3748
// get size from option
3750
ArrowSize size = ArrowSmall;
3751
qreal penThickness( 1.2 );
3752
qreal offset( 0.5 );
3754
switch( StyleConfigData::viewTriangularExpanderSize() )
3756
case StyleConfigData::TE_TINY:
3761
case StyleConfigData::TE_SMALL:
3765
case StyleConfigData::TE_NORMAL:
3776
painter->translate( 0, offset );
3777
a = genericArrow( ArrowDown, size );
3781
painter->translate( offset, 0 );
3782
a = genericArrow( reverseLayout ? ArrowLeft:ArrowRight, size );
3786
painter->setPen( QPen( expanderColor, penThickness, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) );
3787
painter->setRenderHint( QPainter::Antialiasing );
3788
painter->drawPolyline( a );
3796
if( !StyleConfigData::viewDrawTreeBranchLines() ) return true;
3798
painter->setPen( KColorUtils::mix( palette.color( QPalette::Text ), palette.color( QPalette::Background ), 0.8 ) );
3799
if ( flags & ( State_Item | State_Children | State_Sibling ) )
3801
const QLine line( QPoint( centerX, r.top() ), QPoint( centerX, centerY - expanderAdjust ) );
3802
painter->drawLine( line );
3805
//The right/left ( depending on dir ) line gets drawn if we have an item
3806
if ( flags & State_Item )
3808
const QLine line = reverseLayout ?
3809
QLine( QPoint( r.left(), centerY ), QPoint( centerX - expanderAdjust, centerY ) ):
3810
QLine( QPoint( centerX + expanderAdjust, centerY ), QPoint( r.right(), centerY ) );
3811
painter->drawLine( line );
3815
//The bottom if we have a sibling
3816
if ( flags & State_Sibling )
3818
const QLine line( QPoint( centerX, centerY + expanderAdjust ), QPoint( centerX, r.bottom() ) );
3819
painter->drawLine( line );
3825
//___________________________________________________________________________________
3826
bool Style::drawIndicatorButtonDropDownPrimitive( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
3829
const QPalette& palette( option->palette );
3830
const QRect& r( option->rect );
3831
const State& flags( option->state );
3833
const bool enabled( flags & State_Enabled );
3834
const bool mouseOver( enabled && ( flags & State_MouseOver ) );
3835
const bool reverseLayout( option->direction == Qt::RightToLeft );
3836
const bool autoRaise( flags & State_AutoRaise );
3837
const bool sunken( enabled && ( flags & State_Sunken ) );
3839
// match button color to window background
3840
const QColor highlight( helper().viewHoverBrush().brush( palette ).color() );
3841
QColor color = palette.color( autoRaise ? QPalette::WindowText:QPalette::ButtonText );
3842
QColor background = palette.color( QPalette::Window );
3843
StyleOptions opts = 0;
3845
// define gradient and polygon for drawing arrow
3846
QPolygonF a = genericArrow( ArrowDown, ArrowNormal );
3848
qreal penThickness = 1.6;
3851
const QToolButton *tool( qobject_cast<const QToolButton *>( widget ) );
3852
if( tool && tool->popupMode()==QToolButton::MenuButtonPopup )
3858
const bool hasFocus( enabled && ( flags & State_HasFocus ) );
3860
// handle animations
3861
// mouseOver has precedence over focus
3862
animations().widgetStateEngine().updateState( widget, AnimationHover, mouseOver );
3863
animations().widgetStateEngine().updateState( widget, AnimationFocus, hasFocus && !mouseOver );
3865
const bool hoverAnimated( animations().widgetStateEngine().isAnimated( widget, AnimationHover ) );
3866
const bool focusAnimated( animations().widgetStateEngine().isAnimated( widget, AnimationFocus ) );
3868
const qreal hoverOpacity( animations().widgetStateEngine().opacity( widget, AnimationHover ) );
3869
const qreal focusOpacity( animations().widgetStateEngine().opacity( widget, AnimationFocus ) );
3871
color = palette.color( QPalette::ButtonText );
3872
background = helper().backgroundColor( palette.color( QPalette::Button ), widget, r.center() );
3874
if( hasFocus ) opts |= Focus;
3875
if( mouseOver ) opts |= Hover;
3877
// adjust opacity and animation mode
3878
qreal opacity( -1 );
3879
AnimationMode mode( AnimationNone );
3880
if( enabled && hoverAnimated )
3883
opacity = hoverOpacity;
3884
mode = AnimationHover;
3886
} else if( enabled && !hasFocus && focusAnimated ) {
3888
opacity = focusOpacity;
3889
mode = AnimationFocus;
3898
QRect frameRect( r.adjusted( 0, 0, 10, 0 ) );
3899
if( flags & ( State_On|State_Sunken ) ) opts |= Sunken;
3901
painter->setClipRect( frameRect.adjusted( 0, 0, -8, 0 ), Qt::IntersectClip );
3902
renderButtonSlab( painter, frameRect, background, opts, opacity, mode, TileSet::Bottom | TileSet::Top | TileSet::Left );
3907
QRect frameRect( r.adjusted( -10,0,0,0 ) );
3908
if( flags & ( State_On|State_Sunken ) ) opts |= Sunken;
3910
painter->setClipRect( frameRect.adjusted( 8, 0, 0, 0 ), Qt::IntersectClip );
3911
renderButtonSlab( painter, frameRect, background, opts, opacity, mode, TileSet::Bottom | TileSet::Top | TileSet::Right );
3917
// draw separating vertical line
3918
const QColor color( palette.color( QPalette::Button ) );
3919
QColor light =helper().alphaColor( helper().calcLightColor( color ), 0.6 );
3920
QColor dark = helper().calcDarkColor( color );
3921
dark.setAlpha( 200 );
3923
int yTop( r.top()+2 );
3924
if( sunken ) yTop += 1;
3926
const int yBottom( r.bottom()-4 );
3927
painter->setPen( QPen( light,1 ) );
3932
painter->drawLine( r.right()+5, yTop+1, r.right()+5, yBottom );
3933
painter->drawLine( r.right()+3, yTop+2, r.right()+3, yBottom );
3934
painter->setPen( QPen( dark,1 ) );
3935
painter->drawLine( r.right()+4, yTop, r.right()+4, yBottom );
3937
a.translate( 3, 1 );
3941
painter->drawLine( r.x()-5, yTop+1, r.x()-5, yBottom-1 );
3942
painter->drawLine( r.x()-3, yTop+1, r.x()-3, yBottom-1 );
3943
painter->setPen( QPen( dark,1 ) );
3944
painter->drawLine( r.x()-4, yTop, r.x()-4, yBottom );
3946
a.translate( -3,1 );
3950
} else if( const QStyleOptionToolButton *tbOption = qstyleoption_cast<const QStyleOptionToolButton *>( option ) ) {
3952
// handle arrow over animation
3953
const bool arrowHover( enabled && mouseOver && ( tbOption->activeSubControls & SC_ToolButtonMenu ) );
3954
animations().toolButtonEngine().updateState( widget, AnimationHover, arrowHover );
3956
const bool animated( enabled && animations().toolButtonEngine().isAnimated( widget, AnimationHover ) );
3957
const qreal opacity( animations().toolButtonEngine().opacity( widget, AnimationHover ) );
3959
if( animated ) color = KColorUtils::mix( color, highlight, opacity );
3960
else if( arrowHover ) color = highlight;
3961
else color = palette.color( autoRaise ? QPalette::WindowText:QPalette::ButtonText );
3967
color = palette.color( autoRaise ? QPalette::WindowText:QPalette::ButtonText );
3969
// smaller down arrow for menu indication on toolbuttons
3971
a = genericArrow( ArrowDown, ArrowSmall );
3975
painter->translate( r.center() );
3976
painter->setRenderHint( QPainter::Antialiasing );
3979
const qreal offset( qMin( penThickness, qreal( 1.0 ) ) );
3980
painter->translate( 0,offset );
3981
painter->setPen( QPen( helper().calcLightColor( background ), penThickness, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) );
3982
painter->drawPolyline( a );
3983
painter->translate( 0,-offset );
3985
painter->setPen( QPen( helper().decoColor( background, color ) , penThickness, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) );
3986
painter->drawPolyline( a );
3991
//___________________________________________________________________________________
3992
bool Style::drawIndicatorCheckBoxPrimitive( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
3996
const QRect& r( option->rect );
3997
const State& flags( option->state );
3998
const bool enabled( flags & State_Enabled );
3999
const bool mouseOver( enabled && ( flags & State_MouseOver ) );
4000
const bool hasFocus( flags & State_HasFocus );
4002
StyleOptions opts( 0 );
4003
if( !enabled ) opts |= Disabled;
4004
if( mouseOver ) opts |= Hover;
4005
if( hasFocus ) opts |= Focus;
4007
// get checkbox state
4008
CheckBoxState state;
4009
if( flags & State_NoChange ) state = CheckTriState;
4010
else if( flags & State_On ) state = CheckOn;
4011
else state = CheckOff;
4013
// match button color to window background
4014
QPalette palette( option->palette );
4017
helper().backgroundColor(
4018
palette.color( QPalette::Button ), widget, r.center() ) );
4020
// mouseOver has precedence over focus
4021
animations().widgetStateEngine().updateState( widget, AnimationHover, mouseOver );
4022
animations().widgetStateEngine().updateState( widget, AnimationFocus, hasFocus&&!mouseOver );
4024
if( enabled && animations().widgetStateEngine().isAnimated( widget, AnimationHover ) )
4027
const qreal opacity( animations().widgetStateEngine().opacity( widget, AnimationHover ) );
4028
renderCheckBox( painter, r, palette, opts, state, opacity, AnimationHover );
4030
} else if( enabled && !hasFocus && animations().widgetStateEngine().isAnimated( widget, AnimationFocus ) ) {
4032
const qreal opacity( animations().widgetStateEngine().opacity( widget, AnimationFocus ) );
4033
renderCheckBox( painter, r, palette, opts, state, opacity, AnimationFocus );
4035
} else renderCheckBox( painter, r, palette, opts, state );
4040
//___________________________________________________________________________________
4041
bool Style::drawIndicatorRadioButtonPrimitive( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
4045
const QRect& r( option->rect );
4046
const State& flags( option->state );
4047
const bool enabled( flags & State_Enabled );
4048
const bool mouseOver( enabled && ( flags & State_MouseOver ) );
4049
const bool hasFocus( flags & State_HasFocus );
4051
StyleOptions opts( 0 );
4052
if( !enabled ) opts |= Disabled;
4053
if( mouseOver ) opts |= Hover;
4054
if( hasFocus ) opts |= Focus;
4056
// match button color to window background
4057
QPalette palette( option->palette );
4058
palette.setColor( QPalette::Button, helper().backgroundColor( palette.color( QPalette::Button ), widget, r.center() ) );
4060
// mouseOver has precedence over focus
4061
animations().widgetStateEngine().updateState( widget, AnimationHover, mouseOver );
4062
animations().widgetStateEngine().updateState( widget, AnimationFocus, hasFocus && !mouseOver );
4064
const CheckBoxState state( ( flags & State_On ) ? CheckOn:CheckOff );
4065
if( enabled && animations().widgetStateEngine().isAnimated( widget, AnimationHover ) )
4068
const qreal opacity( animations().widgetStateEngine().opacity( widget, AnimationHover ) );
4069
renderRadioButton( painter, r, palette, opts, state, opacity, AnimationHover );
4071
} else if( enabled && animations().widgetStateEngine().isAnimated( widget, AnimationFocus ) ) {
4073
const qreal opacity( animations().widgetStateEngine().opacity( widget, AnimationFocus ) );
4074
renderRadioButton( painter, r, palette, opts, state, opacity, AnimationFocus );
4076
} else renderRadioButton( painter, r, palette, opts, state );
4082
//___________________________________________________________________________________
4083
bool Style::drawIndicatorTabTearPrimitive( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
4086
const QStyleOptionTab* tabOpt( qstyleoption_cast<const QStyleOptionTab*>( option ) );
4087
if( !tabOpt ) return true;
4089
const QRect& r( option->rect );
4090
const QPalette& palette( option->palette );
4091
const bool reverseLayout( option->direction == Qt::RightToLeft );
4093
// in fact with current version of Qt ( 4.6.0 ) the cast fails and document mode is always false
4094
// this will hopefully be fixed in later versions
4095
const QStyleOptionTabV3* tabOptV3( qstyleoption_cast<const QStyleOptionTabV3*>( option ) );
4096
bool documentMode( tabOptV3 ? tabOptV3->documentMode : false );
4098
const QTabWidget *tabWidget = ( widget && widget->parentWidget() ) ? qobject_cast<const QTabWidget *>( widget->parentWidget() ) : NULL;
4099
documentMode |= ( tabWidget ? tabWidget->documentMode() : true );
4101
QRect gradientRect( r );
4102
switch( tabOpt->shape )
4105
case QTabBar::TriangularNorth:
4106
case QTabBar::RoundedNorth:
4107
gradientRect.adjust( 0, 0, 0, -5 );
4108
if( !reverseLayout ) gradientRect.translate( -GlowWidth,0 );
4111
case QTabBar::TriangularSouth:
4112
case QTabBar::RoundedSouth:
4113
gradientRect.adjust( 0, 5, 0, 0 );
4114
if( !reverseLayout ) gradientRect.translate( -GlowWidth,0 );
4117
case QTabBar::TriangularWest:
4118
case QTabBar::RoundedWest:
4119
gradientRect.adjust( 0, 0, -5, 0 );
4120
gradientRect.translate( 0,-GlowWidth );
4123
case QTabBar::TriangularEast:
4124
case QTabBar::RoundedEast:
4125
gradientRect.adjust( 5, 0, 0, 0 );
4126
gradientRect.translate( 0,-GlowWidth );
4129
default: return true;
4133
QPixmap pm( gradientRect.size() );
4134
pm.fill( Qt::transparent );
4137
const bool verticalTabs( isVerticalTab( tabOpt ) );
4140
if( verticalTabs ) h = gradientRect.height();
4141
else w = gradientRect.width();
4143
QLinearGradient grad;
4144
if( reverseLayout && !verticalTabs ) grad = QLinearGradient( 0, 0, w, h );
4145
else grad = QLinearGradient( w, h, 0, 0 );
4147
grad.setColorAt( 0, Qt::transparent );
4148
grad.setColorAt( 0.6, Qt::black );
4150
helper().renderWindowBackground( &pp, pm.rect(), widget, palette );
4151
pp.setCompositionMode( QPainter::CompositionMode_DestinationAtop );
4152
pp.fillRect( pm.rect(), QBrush( grad ) );
4156
painter->drawPixmap( gradientRect.topLeft()+QPoint( 0,-1 ),pm );
4161
//___________________________________________________________________________________
4162
bool Style::drawIndicatorToolBarHandlePrimitive( const QStyleOption* option, QPainter* painter, const QWidget* ) const
4164
const State& flags( option->state );
4165
const bool horizontal( flags & State_Horizontal );
4166
const QRect& r( option->rect );
4167
const QPalette& palette( option->palette );
4173
const int center( r.left()+r.width()/2 );
4174
for( int j = r.top()+2; j <= r.bottom()-3; j+=3, ++counter )
4176
if( counter%2 == 0 ) helper().renderDot( painter, QPoint( center+1, j ), palette.color( QPalette::Background ) );
4177
else helper().renderDot( painter, QPoint( center-2, j ), palette.color( QPalette::Background ) );
4182
const int center( r.top()+r.height()/2 );
4183
for( int j = r.left()+2; j <= r.right()-3; j+=3, ++counter )
4185
if( counter%2 == 0 ) helper().renderDot( painter, QPoint( j, center+1 ), palette.color( QPalette::Background ) );
4186
else helper().renderDot( painter, QPoint( j, center-2 ), palette.color( QPalette::Background ) );
4194
//___________________________________________________________________________________
4195
bool Style::drawIndicatorToolBarSeparatorPrimitive( const QStyleOption* option, QPainter* painter, const QWidget* ) const
4198
const State& flags( option->state );
4199
const QRect& r( option->rect );
4200
const QPalette& palette( option->palette );
4201
if( StyleConfigData::toolBarDrawItemSeparator() )
4203
const QColor color( palette.color( QPalette::Window ) );
4204
if( flags & State_Horizontal ) helper().drawSeparator( painter, r, color, Qt::Vertical );
4205
else helper().drawSeparator( painter, r, color, Qt::Horizontal );
4211
//___________________________________________________________________________________
4212
bool Style::drawWidgetPrimitive( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
4215
// check widget and attributes
4216
if( !widget || !widget->testAttribute( Qt::WA_StyledBackground ) || widget->testAttribute( Qt::WA_NoSystemBackground ) ) return false;
4217
if( !( ( widget->windowFlags() & Qt::WindowType_Mask ) & ( Qt::Window|Qt::Dialog ) ) ) return false;
4218
if( !widget->isWindow() ) return false;
4220
// normal "window" background
4221
const QPalette& palette( option->palette );
4223
// do not render background if palette brush has a texture (pixmap or image)
4224
const QBrush brush( palette.brush( widget->backgroundRole() ) );
4225
if( !( brush.texture().isNull() && brush.textureImage().isNull() ) )
4228
helper().renderWindowBackground( painter, option->rect, widget, palette );
4233
//___________________________________________________________________________________
4234
bool Style::drawCapacityBarControl( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
4238
const QStyleOptionProgressBar* cbOption( qstyleoption_cast<const QStyleOptionProgressBar*>( option ) );
4239
if( !cbOption ) return true;
4242
QStyleOptionProgressBarV2 sub_opt( *cbOption );
4243
sub_opt.rect = subElementRect( QStyle::SE_ProgressBarGroove, cbOption, widget );
4244
drawProgressBarGrooveControl( &sub_opt, painter, widget );
4247
sub_opt.rect = subElementRect( QStyle::SE_ProgressBarContents, cbOption, widget );
4248
drawProgressBarContentsControl( &sub_opt, painter, widget );
4251
sub_opt.rect = subElementRect( QStyle::SE_ProgressBarLabel, cbOption, widget );
4252
drawProgressBarLabelControl( &sub_opt, painter, widget );
4258
//___________________________________________________________________________________
4259
bool Style::drawComboBoxLabelControl( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
4262
//same as CommonStyle, except for filling behind icon
4263
if( const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>( option ) )
4266
QRect editRect( subControlRect( CC_ComboBox, cb, SC_ComboBoxEditField, widget ) );
4269
if( !cb->currentIcon.isNull() )
4272
QIcon::Mode mode = cb->state & State_Enabled ? QIcon::Normal : QIcon::Disabled;
4273
QPixmap pixmap( cb->currentIcon.pixmap( cb->iconSize, mode ) );
4274
QRect iconRect( editRect );
4275
iconRect.setWidth( cb->iconSize.width() + 4 );
4276
iconRect = alignedRect(
4278
Qt::AlignLeft | Qt::AlignVCenter,
4279
iconRect.size(), editRect );
4281
drawItemPixmap( painter, iconRect, Qt::AlignCenter, pixmap );
4283
if( cb->direction == Qt::RightToLeft ) editRect.translate( -4 - cb->iconSize.width(), 0 );
4284
else editRect.translate( cb->iconSize.width() + 4, 0 );
4287
if( !cb->currentText.isEmpty() && !cb->editable )
4289
const bool& hasFrame( cb->frame );
4290
const QPalette::ColorRole role( hasFrame ? QPalette::ButtonText : QPalette::WindowText );
4292
painter, editRect.adjusted( 1, 0, -1, 0 ),
4293
visualAlignment( cb->direction, Qt::AlignLeft | Qt::AlignVCenter ),
4294
cb->palette, cb->state & State_Enabled, cb->currentText, role );
4299
} else return false;
4303
//___________________________________________________________________________________
4304
bool Style::drawDockWidgetTitleControl( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
4307
// cast option and check
4308
const QStyleOptionDockWidget* dwOpt = ::qstyleoption_cast<const QStyleOptionDockWidget*>( option );
4309
if ( !dwOpt ) return true;
4311
const QPalette& palette( option->palette );
4312
const State& flags( option->state );
4313
const bool enabled( flags & State_Enabled );
4314
const bool reverseLayout( option->direction == Qt::RightToLeft );
4316
// cast to v2 to check vertical bar
4317
const QStyleOptionDockWidgetV2 *v2 = qstyleoption_cast<const QStyleOptionDockWidgetV2*>( option );
4318
const bool verticalTitleBar( v2 ? v2->verticalTitleBar : false );
4320
const QRect btnr( subElementRect( dwOpt->floatable ? SE_DockWidgetFloatButton : SE_DockWidgetCloseButton, option, widget ) );
4322
// get rectangle and adjust to properly accounts for buttons
4323
QRect r( insideMargin( dwOpt->rect, DockWidget_TitleMargin ) );
4324
if( verticalTitleBar )
4327
if( btnr.isValid() ) r.setTop( btnr.bottom()+1 );
4329
} else if( reverseLayout ) {
4331
if( btnr.isValid() ) r.setLeft( btnr.right()+1 );
4332
r.adjust( 0,0,-4,0 );
4336
if( btnr.isValid() ) r.setRight( btnr.left()-1 );
4337
r.adjust( 4,0,0,0 );
4341
QString title( dwOpt->title );
4342
QString tmpTitle = title;
4344
// this is quite suboptimal
4345
// and does not really work
4346
if( tmpTitle.contains( "&" ) )
4348
int pos = tmpTitle.indexOf( "&" );
4349
if( !( tmpTitle.size()-1 > pos && tmpTitle.at( pos+1 ) == QChar( '&' ) ) ) tmpTitle.remove( pos, 1 );
4353
int tw = dwOpt->fontMetrics.width( tmpTitle );
4354
int width = verticalTitleBar ? r.height() : r.width();
4355
if( width < tw ) title = dwOpt->fontMetrics.elidedText( title, Qt::ElideRight, width, Qt::TextShowMnemonic );
4357
if( verticalTitleBar )
4365
painter->translate( r.left(), r.top() + r.width() );
4366
painter->rotate( -90 );
4367
painter->translate( -r.left(), -r.top() );
4368
drawItemText( painter, r, Qt::AlignLeft | Qt::AlignVCenter | Qt::TextShowMnemonic, palette, enabled, title, QPalette::WindowText );
4374
drawItemText( painter, r, Qt::AlignLeft | Qt::AlignVCenter | Qt::TextShowMnemonic, palette, enabled, title, QPalette::WindowText );
4383
//___________________________________________________________________________________
4384
bool Style::drawHeaderEmptyAreaControl( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
4387
// use the same background as in drawHeaderPrimitive
4388
QPalette palette( option->palette );
4390
if( widget && animations().widgetEnabilityEngine().isAnimated( widget, AnimationEnable ) )
4391
{ palette = helper().mergePalettes( palette, animations().widgetEnabilityEngine().opacity( widget, AnimationEnable ) ); }
4393
const bool horizontal( option->state & QStyle::State_Horizontal );
4394
const bool reverseLayout( option->direction == Qt::RightToLeft );
4395
renderHeaderBackground( option->rect, palette, painter, widget, horizontal, reverseLayout );
4401
//___________________________________________________________________________________
4402
bool Style::drawHeaderLabelControl( const QStyleOption* option, QPainter* painter, const QWidget* ) const
4404
const QStyleOptionHeader* headerOpt( qstyleoption_cast<const QStyleOptionHeader *>( option ) );
4405
if( !headerOpt ) return true;
4407
QRect rect( headerOpt->rect );
4409
if ( !headerOpt->icon.isNull() )
4411
const QPixmap pixmap( headerOpt->icon.pixmap(
4412
pixelMetric( PM_SmallIconSize ),
4413
( headerOpt->state & State_Enabled ) ? QIcon::Normal : QIcon::Disabled ) );
4415
int pixw = pixmap.width();
4417
QRect aligned = alignedRect( headerOpt->direction, QFlag( headerOpt->iconAlignment ), pixmap.size(), rect );
4418
QRect inter = aligned.intersected( rect );
4419
painter->drawPixmap( inter.x(), inter.y(), pixmap, inter.x() - aligned.x(), inter.y() - aligned.y(), inter.width(), inter.height() );
4421
if ( headerOpt->direction == Qt::LeftToRight ) rect.setLeft( rect.left() + pixw + 2 );
4422
else rect.setRight( rect.right() - pixw - 2 );
4427
painter, rect, headerOpt->textAlignment, headerOpt->palette,
4428
( headerOpt->state & State_Enabled ), headerOpt->text, QPalette::WindowText );
4433
//___________________________________________________________________________________
4434
bool Style::drawHeaderSectionControl( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
4437
const QRect& r( option->rect );
4438
const QPalette& palette( option->palette );
4440
const QStyleOptionHeader* headerOpt( qstyleoption_cast<const QStyleOptionHeader *>( option ) );
4441
if( !headerOpt ) return true;
4443
const bool horizontal( headerOpt->orientation == Qt::Horizontal );
4444
const bool reverseLayout( option->direction == Qt::RightToLeft );
4445
const bool isFirst( horizontal && ( headerOpt->position == QStyleOptionHeader::Beginning ) );
4446
const bool isCorner( widget && widget->inherits( "QTableCornerButton" ) );
4448
// corner header lines
4452
if( widget ) helper().renderWindowBackground( painter, r, widget, palette );
4453
else painter->fillRect( r, palette.color( QPalette::Window ) );
4454
if( reverseLayout ) renderHeaderLines( r, palette, painter, TileSet::BottomLeft );
4455
else renderHeaderLines( r, palette, painter, TileSet::BottomRight );
4457
} else renderHeaderBackground( r, palette, painter, widget, horizontal, reverseLayout );
4460
const QColor color( palette.color( QPalette::Window ) );
4464
if( headerOpt->section != 0 || isFirst )
4466
const int center( r.center().y() );
4467
const int pos( reverseLayout ? r.left()+1 : r.right()-1 );
4468
helper().renderDot( painter, QPoint( pos, center-3 ), color );
4469
helper().renderDot( painter, QPoint( pos, center ), color );
4470
helper().renderDot( painter, QPoint( pos, center+3 ), color );
4475
const int center( r.center().x() );
4476
const int pos( r.bottom()-1 );
4477
helper().renderDot( painter, QPoint( center-3, pos ), color );
4478
helper().renderDot( painter, QPoint( center, pos ), color );
4479
helper().renderDot( painter, QPoint( center+3, pos ), color );
4487
//___________________________________________________________________________________
4488
bool Style::drawMenuBarItemControl( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
4491
const QStyleOptionMenuItem* menuOpt = ::qstyleoption_cast<const QStyleOptionMenuItem*>( option );
4492
if ( !menuOpt ) return true;
4494
const State& flags( option->state );
4495
const bool enabled( flags & State_Enabled );
4497
const QRect& r( option->rect );
4498
const QPalette& palette( option->palette );
4502
const bool active( flags & State_Selected );
4503
const bool animated( animations().menuBarEngine().isAnimated( widget, r.topLeft() ) );
4504
const qreal opacity( animations().menuBarEngine().opacity( widget, r.topLeft() ) );
4505
const QRect currentRect( animations().menuBarEngine().currentRect( widget, r.topLeft() ) );
4506
const QRect animatedRect( animations().menuBarEngine().animatedRect( widget ) );
4508
const bool intersected( animatedRect.intersects( r ) );
4509
const bool current( currentRect.contains( r.topLeft() ) );
4510
const bool timerIsActive( animations().menuBarEngine().isTimerActive( widget ) );
4512
// do nothing in case of empty intersection between animated rect and current
4513
if( ( intersected || !animated || animatedRect.isNull() ) && ( active || animated || timerIsActive ) )
4516
QColor color( helper().calcMidColor( palette.color( QPalette::Window ) ) );
4517
if( StyleConfigData::menuHighlightMode() != StyleConfigData::MM_DARK )
4520
if( flags & State_Sunken )
4523
if( StyleConfigData::menuHighlightMode() == StyleConfigData::MM_STRONG ) color = palette.color( QPalette::Highlight );
4524
else color = KColorUtils::mix( color, KColorUtils::tint( color, palette.color( QPalette::Highlight ), 0.6 ) );
4528
if( StyleConfigData::menuHighlightMode() == StyleConfigData::MM_STRONG ) color = KColorUtils::tint( color, helper().viewHoverBrush().brush( palette ).color() );
4529
else color = KColorUtils::mix( color, KColorUtils::tint( color, helper().viewHoverBrush().brush( palette ).color() ) );
4532
} else color = helper().backgroundColor( color, widget, r.center() );
4535
if( animated && intersected )
4538
helper().holeFlat( color, 0.0 )->render( animatedRect.adjusted( 1,1,-1,-1 ), painter, TileSet::Full );
4540
} else if( timerIsActive && current ) {
4542
helper().holeFlat( color, 0.0 )->render( r.adjusted( 1,1,-1,-1 ), painter, TileSet::Full );
4544
} else if( animated && current ) {
4546
color.setAlphaF( opacity );
4547
helper().holeFlat( color, 0.0 )->render( r.adjusted( 1,1,-1,-1 ), painter, TileSet::Full );
4549
} else if( active ) {
4551
helper().holeFlat( color, 0.0 )->render( r.adjusted( 1,1,-1,-1 ), painter, TileSet::Full );
4560
QPalette::ColorRole role( QPalette::WindowText );
4561
if( StyleConfigData::menuHighlightMode() == StyleConfigData::MM_STRONG && ( flags & State_Sunken ) && enabled )
4562
{ role = QPalette::HighlightedText; }
4564
drawItemText( painter, r, Qt::AlignCenter | Qt::TextShowMnemonic, palette, enabled, menuOpt->text, role );
4570
//___________________________________________________________________________________
4571
bool Style::drawMenuItemControl( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
4573
const QRect& r( option->rect );
4574
const QPalette& palette( option->palette );
4575
const State& flags( option->state );
4576
const bool active( flags & State_Selected );
4577
const bool enabled( flags & State_Enabled );
4578
const bool hasFocus( enabled && ( flags & State_HasFocus ) );
4579
const bool mouseOver( enabled && ( flags & State_MouseOver ) );
4581
//First of all,render the background.
4582
renderMenuItemBackground( option, painter, widget );
4584
// do nothing if invalid option, or empty area
4585
const QStyleOptionMenuItem* menuItemOption = qstyleoption_cast<const QStyleOptionMenuItem*>( option );
4586
if( !menuItemOption || menuItemOption->menuItemType == QStyleOptionMenuItem::EmptyArea ) return true;
4588
//First, figure out the left column width.
4589
const int iconColW = qMax( menuItemOption->maxIconWidth, ( int )MenuItem_IconWidth );
4590
const int checkColW = MenuItem_CheckWidth;
4591
const int checkSpace = MenuItem_CheckSpace;
4593
int leftColW = iconColW;
4595
// only use the additional check row if the menu has checkable menuItems.
4596
bool hasCheckableItems = menuItemOption->menuHasCheckableItems;
4597
if( hasCheckableItems ) leftColW += checkColW + checkSpace;
4599
// right arrow column...
4600
int rightColW = MenuItem_ArrowSpace + MenuItem_ArrowWidth;
4602
//Separators: done with the bg, can paint them and bail them out.
4603
if( menuItemOption->menuItemType == QStyleOptionMenuItem::Separator )
4605
// check text and icon
4606
// separators with non empty text are rendered as checked toolbuttons
4607
if( !menuItemOption->text.isEmpty() )
4610
QStyleOptionToolButton toolButtonOpt;
4611
toolButtonOpt.features = QStyleOptionToolButton::None;
4612
toolButtonOpt.state = State_On|State_Sunken|State_Enabled;
4613
toolButtonOpt.rect = r.adjusted( 0, 0, 0, 1 );
4614
toolButtonOpt.subControls = SC_ToolButton;
4615
toolButtonOpt.icon = menuItemOption->icon;
4617
toolButtonOpt.font = widget->font();
4618
toolButtonOpt.font.setBold( true );
4620
toolButtonOpt.iconSize = QSize(
4621
pixelMetric( QStyle::PM_SmallIconSize,0,0 ),
4622
pixelMetric( QStyle::PM_SmallIconSize,0,0 ) );
4624
// for now menu size is not calculated properly
4625
// ( meaning it doesn't account for titled separators width
4626
// as a fallback, we elide the text to be displayed
4627
int width( r.width() );
4628
if( !menuItemOption->icon.isNull() )
4629
{ width -= toolButtonOpt.iconSize.width() + 2; }
4630
width -= 2*ToolButton_ContentsMargin;
4631
toolButtonOpt.text = QFontMetrics( toolButtonOpt.font ).elidedText( menuItemOption->text, Qt::ElideRight, width );
4633
toolButtonOpt.toolButtonStyle = Qt::ToolButtonTextBesideIcon;
4634
drawToolButtonComplexControl( &toolButtonOpt, painter, widget );
4639
// in all other cases draw regular separator
4640
const QColor color( helper().menuBackgroundColor( palette.color( QPalette::Window ), widget, r.center() ) );
4641
helper().drawSeparator( painter, r, color, Qt::Horizontal );
4648
//Remove the margin ( for everything but the column background )
4649
const QRect ir( insideMargin( r, MenuItem_Margin ) );
4651
//Active indicator...
4652
if( active && enabled )
4655
// check if there is a 'sliding' animation in progress, in which case, do nothing
4656
const QRect animatedRect( animations().menuEngine().animatedRect( widget ) );
4657
if( animatedRect.isNull() )
4660
const bool animated( animations().menuEngine().isAnimated( widget, Current ) );
4661
const QRect currentRect( animations().menuEngine().currentRect( widget, Current ) );
4662
const bool intersected( currentRect.contains( r.topLeft() ) );
4664
const QColor color( helper().menuBackgroundColor( helper().calcMidColor( palette.color( QPalette::Window ) ), widget, r.center() ) );
4666
if( animated && intersected ) renderMenuItemRect( option, r, color, palette, painter, animations().menuEngine().opacity( widget, Current ) );
4667
else renderMenuItemRect( option, r, color, palette, painter );
4674
QPalette::ColorRole textRole( ( active && enabled && StyleConfigData::menuHighlightMode() == StyleConfigData::MM_STRONG ) ?
4675
QPalette::HighlightedText:
4676
QPalette::WindowText );
4678
//Readjust the column rectangle back to proper height
4679
QRect leftColRect( ir.x(), ir.y(), leftColW, ir.height() );
4681
// paint a normal check- resp. radiomark.
4682
const QRect checkColRect(
4683
leftColRect.x(), leftColRect.y(),
4684
checkColW, leftColRect.height() );
4686
const CheckBoxState checkBoxState( menuItemOption->checked ? CheckOn:CheckOff );
4687
if( menuItemOption->checkType == QStyleOptionMenuItem::NonExclusive )
4690
StyleOptions opts( 0 );
4692
if( !enabled ) opts |= Disabled;
4693
if( mouseOver ) opts |= Hover;
4694
if( hasFocus ) opts |= Focus;
4696
const QRect r( handleRTL( option, checkColRect ) );
4697
QPalette localPalette( palette );
4698
localPalette.setColor( QPalette::Window, helper().menuBackgroundColor( palette.color( QPalette::Window ), widget, r.topLeft() ) );
4699
renderCheckBox( painter, r.adjusted( 2,-2,2,2 ), localPalette, opts, checkBoxState );
4701
} else if( menuItemOption->checkType == QStyleOptionMenuItem::Exclusive ) {
4703
StyleOptions opts( 0 );
4704
if( !enabled ) opts |= Disabled;
4705
if( mouseOver ) opts |= Hover;
4706
if( hasFocus ) opts |= Focus;
4708
const QRect r( handleRTL( option, checkColRect ) );
4709
QPalette localPalette( palette );
4710
localPalette.setColor( QPalette::Window, helper().menuBackgroundColor( palette.color( QPalette::Window ), widget, r.topLeft() ) );
4711
renderRadioButton( painter, r.adjusted( 2,-2,2,2 ), localPalette, opts, checkBoxState );
4715
// Paint the menu icon.
4716
if( !menuItemOption->icon.isNull() )
4721
if( hasCheckableItems )
4724
iconColRect = QRect(
4725
leftColRect.x()+checkColW+checkSpace, leftColRect.y(),
4726
leftColRect.width()-( checkColW+checkSpace ), leftColRect.height() );
4728
} else iconColRect = leftColRect;
4732
if( enabled ) mode = active ? QIcon::Active: QIcon::Normal;
4733
else mode = QIcon::Disabled;
4736
const QIcon::State iconState(
4737
( ( flags & State_On ) || ( flags & State_Sunken ) ) ?
4738
QIcon::On:QIcon::Off );
4741
const QSize size( pixelMetric( PM_SmallIconSize ), pixelMetric( PM_SmallIconSize ) );
4742
const QRect r( handleRTL( option, centerRect( iconColRect, size ) ) );
4743
const QPixmap icon = menuItemOption->icon.pixmap( size, mode, iconState );
4744
painter->drawPixmap( centerRect( r, size ), icon );
4749
//Now include the spacing when calculating the next columns
4750
leftColW += MenuItem_IconSpace;
4752
//Render the text, including any accel.
4753
QString text = menuItemOption->text;
4754
const QRect textRect( handleRTL( option, QRect( ir.x() + leftColW, ir.y(), ir.width() - leftColW - rightColW, ir.height() ) ) );
4756
painter->setFont( menuItemOption->font );
4758
int tabPos = menuItemOption->text.indexOf( QLatin1Char( '\t' ) );
4762
text = menuItemOption->text.left( tabPos );
4763
QString accl = menuItemOption->text.mid( tabPos + 1 );
4766
painter, textRect, Qt::AlignVCenter | Qt::TextShowMnemonic | Qt::AlignRight, palette,
4767
enabled, accl, textRole );
4773
painter, textRect, Qt::AlignVCenter | Qt::TextShowMnemonic, palette,
4774
enabled, text, textRole );
4776
//Render arrow, if need be.
4777
if( menuItemOption->menuItemType == QStyleOptionMenuItem::SubMenu )
4780
const qreal penThickness = 1.6;
4781
const QColor color = palette.color( textRole );
4782
const QColor background = palette.color( QPalette::Window );
4784
const int aw = MenuItem_ArrowWidth;
4785
QRect arrowRect = handleRTL( option, QRect( ir.x() + ir.width() - aw, ir.y(), aw, ir.height() ) );
4788
QPolygonF a = genericArrow( option->direction == Qt::LeftToRight ? ArrowRight : ArrowLeft, ArrowNormal );
4790
painter->translate( arrowRect.center() );
4791
painter->setRenderHint( QPainter::Antialiasing );
4794
const qreal offset( qMin( penThickness, qreal( 1.0 ) ) );
4795
painter->translate( 0,offset );
4796
painter->setPen( QPen( helper().calcLightColor( background ), penThickness, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) );
4797
painter->drawPolyline( a );
4798
painter->translate( 0,-offset );
4800
painter->setPen( QPen( helper().decoColor( background, color ) , penThickness, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) );
4801
painter->drawPolyline( a );
4809
//___________________________________________________________________________________
4810
bool Style::drawProgressBarControl( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
4813
if( const QStyleOptionProgressBar *pb = qstyleoption_cast<const QStyleOptionProgressBar *>( option ) )
4816
// same as QCommonStyle::drawControl, except that it handles animations
4817
QStyleOptionProgressBarV2 subopt = *pb;
4818
subopt.rect = subElementRect( SE_ProgressBarGroove, pb, widget );
4819
drawProgressBarGrooveControl( &subopt, painter, widget );
4821
if( animations().progressBarEngine().busyIndicatorEnabled() && pb->maximum == 0 && pb->minimum == 0 )
4822
{ animations().progressBarEngine().startBusyTimer(); }
4824
if( animations().progressBarEngine().isAnimated( widget ) )
4825
{ subopt.progress = animations().progressBarEngine().value( widget ); }
4827
subopt.rect = subElementRect( SE_ProgressBarContents, &subopt, widget );
4828
drawProgressBarContentsControl( &subopt, painter, widget );
4830
if( pb->textVisible )
4832
subopt.rect = subElementRect( SE_ProgressBarLabel, pb, widget );
4833
drawProgressBarLabelControl( &subopt, painter, widget );
4842
//___________________________________________________________________________________
4843
bool Style::drawProgressBarContentsControl( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
4846
const QStyleOptionProgressBar* pbOpt = qstyleoption_cast<const QStyleOptionProgressBar*>( option );
4847
if ( !pbOpt ) return true;
4849
const QStyleOptionProgressBarV2* pbOpt2 = qstyleoption_cast<const QStyleOptionProgressBarV2*>( option );
4851
const QRect& r( option->rect );
4852
const QPalette& palette( option->palette );
4854
// check if anything is to be drawn
4855
qreal progress = pbOpt->progress - pbOpt->minimum;
4856
const bool busyIndicator = ( pbOpt->minimum == 0 && pbOpt->maximum == 0 );
4857
if( busyIndicator && widget )
4859
// load busy value from widget property
4860
QVariant busyValue( widget->property( ProgressBarEngine::busyValuePropertyName ) );
4861
if( busyValue.isValid() ) progress = busyValue.toReal();
4864
if( !( progress || busyIndicator ) ) return true;
4866
const int steps = qMax( pbOpt->maximum - pbOpt->minimum, 1 );
4867
const bool horizontal = !pbOpt2 || pbOpt2->orientation == Qt::Horizontal;
4869
//Calculate width fraction
4870
qreal widthFrac( busyIndicator ? ProgressBar_BusyIndicatorSize/100.0 : progress/steps );
4871
widthFrac = qMin( (qreal)1.0, widthFrac );
4873
// And now the pixel width
4874
const int indicatorSize( widthFrac*( horizontal ? r.width():r.height() ) );
4876
// do nothing if indicator size is too small
4877
if( indicatorSize < 4 ) return true;
4879
QRect indicatorRect;
4880
if ( busyIndicator )
4883
// The space around which we move around...
4884
int remSize = ( ( 1.0 - widthFrac )*( horizontal ? r.width():r.height() ) );
4885
remSize = qMax( remSize, 1 );
4887
int pstep = int( progress )%( 2*remSize );
4888
if ( pstep > remSize )
4890
// Bounce about.. We're remWidth + some delta, we want to be remWidth - delta...
4891
// - ( ( remWidth + some delta ) - 2* remWidth ) = - ( some delta - remWidth ) = remWidth - some delta..
4892
pstep = -( pstep - 2*remSize );
4895
if ( horizontal ) indicatorRect = QRect( r.x() + pstep, r.y(), indicatorSize, r.height() );
4896
else indicatorRect = QRect( r.x(), r.y() + pstep, r.width(), indicatorSize );
4900
if ( horizontal ) indicatorRect = QRect( r.x(), r.y(), indicatorSize, r.height() );
4901
else indicatorRect = QRect( r.x(), r.bottom()- indicatorSize + 1, r.width(), indicatorSize );
4905
// handle right to left
4906
indicatorRect = handleRTL( option, indicatorRect );
4907
indicatorRect.adjust( 1, 0, -1, -1 );
4909
if( indicatorRect.isValid() )
4911
QPixmap pixmap( helper().progressBarIndicator( palette, indicatorRect ) );
4912
painter->drawPixmap( indicatorRect.topLeft(), pixmap );
4919
//___________________________________________________________________________________
4920
bool Style::drawProgressBarGrooveControl( const QStyleOption* option, QPainter* painter, const QWidget* ) const
4923
const QStyleOptionProgressBarV2 *pbOpt = qstyleoption_cast<const QStyleOptionProgressBarV2 *>( option );
4924
const Qt::Orientation orientation( pbOpt? pbOpt->orientation : Qt::Horizontal );
4926
// ajust rect for alignment
4927
QRect rect( option->rect );
4928
if( orientation == Qt::Horizontal ) rect.adjust( 1, 0, -1, 0 );
4929
else rect.adjust( 0, 1, 0, -1 );
4931
renderScrollBarHole( painter, rect, option->palette.color( QPalette::Window ), orientation );
4936
//___________________________________________________________________________________
4937
bool Style::drawProgressBarLabelControl( const QStyleOption* option, QPainter* painter, const QWidget* ) const
4939
const QStyleOptionProgressBar* pbOpt = qstyleoption_cast<const QStyleOptionProgressBar*>( option );
4940
if( !pbOpt ) return true;
4942
const QRect& r( option->rect );
4943
const QPalette& palette( option->palette );
4944
const State& flags( option->state );
4945
const bool enabled( flags&State_Enabled );
4947
const QStyleOptionProgressBarV2* pbOpt2 = qstyleoption_cast<const QStyleOptionProgressBarV2*>( option );
4948
const bool horizontal = !pbOpt2 || pbOpt2->orientation == Qt::Horizontal;
4949
const bool reverseLayout = ( option->direction == Qt::RightToLeft );
4951
// rotate label for vertical layout
4952
if( ! ( horizontal || reverseLayout ) )
4955
painter->translate( r.topRight() );
4956
painter->rotate( 90.0 );
4958
} else if( !horizontal ) {
4960
painter->translate( r.bottomLeft() );
4961
painter->rotate( -90.0 );
4965
Qt::Alignment hAlign( ( pbOpt->textAlignment == Qt::AlignLeft ) ? Qt::AlignHCenter : pbOpt->textAlignment );
4968
Figure out the geometry of the indicator.
4969
This is copied from drawProgressBarContentsControl
4972
const QRect textRect( horizontal? r : QRect( 0, 0, r.height(), r.width() ) );
4973
const qreal progress = pbOpt->progress - pbOpt->minimum;
4974
const int steps = qMax( pbOpt->maximum - pbOpt->minimum, 1 );
4975
const bool busyIndicator = ( steps <= 1 );
4977
int indicatorSize( 0 );
4978
if( !busyIndicator )
4980
const qreal widthFrac = qMin( (qreal)1.0, progress / steps );
4981
indicatorSize = widthFrac*( horizontal ? r.width() : r.height() );
4986
if ( horizontal ) painter->setClipRect( handleRTL( option, QRect( r.x(), r.y(), indicatorSize, r.height() ) ) );
4987
else if ( !reverseLayout ) painter->setClipRect( QRect( r.height()-indicatorSize, 0, r.height(), r.width() ) );
4988
else painter->setClipRect( QRect( 0, 0, indicatorSize, r.width() ) );
4990
// first pass ( highlighted )
4991
drawItemText( painter, textRect, Qt::AlignVCenter | hAlign, palette, enabled, pbOpt->text, QPalette::HighlightedText );
4993
// second pass ( normal )
4994
if( horizontal ) painter->setClipRect( handleRTL( option, QRect( r.x() + indicatorSize, r.y(), r.width() - indicatorSize, r.height() ) ) );
4995
else if( !reverseLayout ) painter->setClipRect( QRect( 0, 0, r.height() - indicatorSize, r.width() ) );
4996
else painter->setClipRect( QRect( indicatorSize, 0, r.height()- indicatorSize, r.width() ) );
4997
drawItemText( painter, textRect, Qt::AlignVCenter | hAlign, palette, enabled, pbOpt->text, QPalette::WindowText );
5001
drawItemText( painter, textRect, Qt::AlignVCenter | hAlign, palette, enabled, pbOpt->text, QPalette::WindowText );
5008
//___________________________________________________________________________________
5009
bool Style::drawPushButtonLabelControl( const QStyleOption* option, QPainter* painter, const QWidget* ) const
5012
// cast option and check
5013
const QStyleOptionButton* bOpt = qstyleoption_cast<const QStyleOptionButton*>( option );
5014
if ( !bOpt ) return true;
5016
const QRect& r( option->rect );
5017
const QPalette& palette( option->palette );
5018
const State& flags( option->state );
5019
const bool active( ( flags & State_On ) || ( flags & State_Sunken ) );
5020
const bool enabled( flags & State_Enabled );
5021
const bool hasFocus( flags & State_HasFocus );
5022
const bool flat( bOpt->features.testFlag( QStyleOptionButton::Flat ) );
5024
//Extract out coordinates for easier manipulation
5026
r.getRect( &x, &y, &w, &h );
5029
if ( bOpt->features & QStyleOptionButton::HasMenu )
5032
const int indicatorWidth( PushButton_MenuIndicatorSize );
5033
const int indicatorSpacing = PushButton_TextToIconSpace;
5034
w -= indicatorWidth + indicatorSpacing;
5037
const QRect arrowRect( x + w + indicatorSpacing, y+1, indicatorWidth, h );
5038
const qreal penThickness = 1.6;
5039
QPolygonF a = genericArrow( ArrowDown, ArrowNormal );
5041
const QColor color = palette.color( flat ? QPalette::WindowText:QPalette::ButtonText );
5042
const QColor background = palette.color( flat ? QPalette::Window:QPalette::Button );
5045
painter->translate( arrowRect.center() );
5046
painter->setRenderHint( QPainter::Antialiasing );
5048
const qreal offset( qMin( penThickness, qreal( 1.0 ) ) );
5049
painter->translate( 0,offset );
5050
painter->setPen( QPen( helper().calcLightColor( background ), penThickness, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) );
5051
painter->drawPolyline( a );
5052
painter->translate( 0,-offset );
5054
painter->setPen( QPen( helper().decoColor( background, color ) , penThickness, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) );
5055
painter->drawPolyline( a );
5060
// Draw the icon if there is one
5061
if( !bOpt->icon.isNull() )
5064
if ( !bOpt->text.isEmpty() )
5067
const int margin = PushButton_TextToIconSpace;
5068
const int length = bOpt->iconSize.width() + margin + painter->fontMetrics().size( Qt::TextShowMnemonic, bOpt->text ).width();
5071
const int offset = ( w - length )/2;
5073
const QRect iconRect( handleRTL( bOpt, QRect( QPoint( x + offset, y + h/2 - bOpt->iconSize.height()/2 ), bOpt->iconSize ) ) );
5076
if( enabled ) mode = ( hasFocus ) ? QIcon::Active: QIcon::Normal;
5077
else mode = QIcon::Disabled;
5079
QIcon::State iconState = active ? QIcon::On : QIcon::Off;
5081
QSize size = bOpt->iconSize;
5082
if( !size.isValid() ) size = QSize( pixelMetric( PM_SmallIconSize ), pixelMetric( PM_SmallIconSize ) );
5083
QPixmap icon = bOpt->icon.pixmap( size, mode, iconState );
5084
painter->drawPixmap( centerRect( iconRect, icon.size() ), icon );
5086
//new bounding rect for the text
5087
x += offset + bOpt->iconSize.width() + margin;
5088
w = length - bOpt->iconSize.width() - margin;
5092
const QRect iconRect( x, y, w, h );
5094
if( enabled ) mode = ( hasFocus ) ? QIcon::Active: QIcon::Normal;
5095
else mode = QIcon::Disabled;
5097
QIcon::State iconState = active ? QIcon::On : QIcon::Off;
5099
QSize size = bOpt->iconSize;
5100
if( !size.isValid() ) size = QSize( pixelMetric( PM_SmallIconSize ), pixelMetric( PM_SmallIconSize ) );
5101
QPixmap icon = bOpt->icon.pixmap( size, mode, iconState );
5102
painter->drawPixmap( centerRect( iconRect, icon.size() ), icon );
5109
int textW = painter->fontMetrics().size( Qt::TextShowMnemonic, bOpt->text ).width();
5110
x += ( w - textW )/2;
5115
QRect textRect( handleRTL( bOpt, QRect( x, y, w, h ) ) );
5116
if( !bOpt->icon.isNull() ) textRect.adjust( 0, 0, 0, 1 );
5118
const QPalette::ColorRole role( flat ? QPalette::WindowText : QPalette::ButtonText );
5119
drawItemText( painter, textRect, Qt::AlignCenter | Qt::TextShowMnemonic, palette, enabled, bOpt->text, role );
5124
//___________________________________________________________________________________
5125
bool Style::drawRubberBandControl( const QStyleOption* option, QPainter* painter, const QWidget* ) const
5128
if( const QStyleOptionRubberBand *rbOpt = qstyleoption_cast<const QStyleOptionRubberBand *>( option ) )
5132
QColor color = rbOpt->palette.color( QPalette::Highlight );
5133
painter->setPen( KColorUtils::mix( color, rbOpt->palette.color( QPalette::Active, QPalette::WindowText ) ) );
5134
color.setAlpha( 50 );
5135
painter->setBrush( color );
5136
painter->setClipRegion( rbOpt->rect );
5137
painter->drawRect( rbOpt->rect.adjusted( 0,0,-1,-1 ) );
5141
} else return false;
5145
//___________________________________________________________________________________
5146
bool Style::drawScrollBarSliderControl( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
5149
// cast option and check
5150
const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>( option );
5151
if( !slider ) return true;
5153
const QRect& r( option->rect );
5154
const QPalette& palette( option->palette );
5156
const State& flags( option->state );
5157
const bool horizontal( flags & State_Horizontal );
5158
const bool enabled( flags&State_Enabled );
5159
const bool mouseOver( enabled && ( flags&State_MouseOver ) );
5161
// enable animation state
5162
animations().scrollBarEngine().updateState( widget, enabled && slider && ( slider->activeSubControls & SC_ScrollBarSlider ) );
5164
const bool animated( enabled && animations().scrollBarEngine().isAnimated( widget, SC_ScrollBarSlider ) );
5168
if( animated ) renderScrollBarHandle( painter, r, palette, Qt::Horizontal, mouseOver, animations().scrollBarEngine().opacity( widget, SC_ScrollBarSlider ) );
5169
else renderScrollBarHandle( painter, r, palette, Qt::Horizontal, mouseOver );
5173
if( animated ) renderScrollBarHandle( painter, r, palette, Qt::Vertical, mouseOver, animations().scrollBarEngine().opacity( widget, SC_ScrollBarSlider ) );
5174
else renderScrollBarHandle( painter, r, palette, Qt::Vertical, mouseOver );
5181
//___________________________________________________________________________________
5182
bool Style::drawScrollBarAddLineControl( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
5185
// cast option and check
5186
const QStyleOptionSlider* slOpt = qstyleoption_cast<const QStyleOptionSlider*>( option );
5187
if ( !slOpt ) return true;
5189
const State& flags( option->state );
5190
const bool horizontal( flags & State_Horizontal );
5191
const bool reverseLayout( option->direction == Qt::RightToLeft );
5194
const QPalette& palette( option->palette );
5195
const QColor background( palette.color( QPalette::Window ) );
5197
// adjust rect, based on number of buttons to be drawn
5198
const QRect r( scrollBarInternalSubControlRect( slOpt, SC_ScrollBarAddLine ) );
5200
// draw the end of the scrollbar groove
5204
if( reverseLayout ) renderScrollBarHole( painter, QRect( r.right()+1, r.top(), 5, r.height() ), background, Qt::Horizontal, TileSet::Vertical | TileSet::Left );
5205
else renderScrollBarHole( painter, QRect( r.left()-5, r.top(), 5, r.height() ), background, Qt::Horizontal, TileSet::Vertical | TileSet::Right );
5207
} else renderScrollBarHole( painter, QRect( r.left(), r.top()-5, r.width(), 5 ), background, Qt::Vertical, TileSet::Bottom | TileSet::Horizontal );
5209
// stop here if no buttons are defined
5210
if( _addLineButtons == NoButton ) return true;
5213
QStyleOption localOption( *option );
5214
if( _addLineButtons == DoubleButton )
5221
const QSize halfSize( r.width()/2, r.height() );
5222
const QRect leftSubButton( r.topLeft(), halfSize );
5223
const QRect rightSubButton( leftSubButton.topRight() + QPoint( 1, 0 ), halfSize );
5225
localOption.rect = leftSubButton;
5226
color = scrollBarArrowColor( &localOption, reverseLayout ? SC_ScrollBarAddLine:SC_ScrollBarSubLine, widget );
5227
renderScrollBarArrow( painter, leftSubButton, color, background, ArrowLeft );
5229
localOption.rect = rightSubButton;
5230
color = scrollBarArrowColor( &localOption, reverseLayout ? SC_ScrollBarSubLine:SC_ScrollBarAddLine, widget );
5231
renderScrollBarArrow( painter, rightSubButton, color, background, ArrowRight );
5235
const QSize halfSize( r.width(), r.height()/2 );
5236
const QRect topSubButton( r.topLeft(), halfSize );
5237
const QRect botSubButton( topSubButton.bottomLeft() + QPoint( 0, 1 ), halfSize );
5239
localOption.rect = topSubButton;
5240
color = scrollBarArrowColor( &localOption, SC_ScrollBarSubLine, widget );
5241
renderScrollBarArrow( painter, topSubButton, color, background, ArrowUp );
5243
localOption.rect = botSubButton;
5244
color = scrollBarArrowColor( &localOption, SC_ScrollBarAddLine, widget );
5245
renderScrollBarArrow( painter, botSubButton, color, background, ArrowDown );
5249
} else if( _addLineButtons == SingleButton ) {
5251
localOption.rect = r;
5252
color = scrollBarArrowColor( &localOption, SC_ScrollBarAddLine, widget );
5253
if( horizontal ) renderScrollBarArrow( painter, r, color, background, reverseLayout ? ArrowLeft : ArrowRight );
5254
else renderScrollBarArrow( painter, r, color, background, ArrowDown );
5261
//___________________________________________________________________________________
5262
bool Style::drawScrollBarAddPageControl( const QStyleOption* option, QPainter* painter, const QWidget* ) const
5265
// cast option and check
5266
const QStyleOptionSlider* slOpt = qstyleoption_cast<const QStyleOptionSlider*>( option );
5267
if ( !slOpt ) return true;
5269
const QRect& r( option->rect );
5270
const QPalette& palette( option->palette );
5271
const QColor color( palette.color( QPalette::Window ) );
5273
const State& flags( option->state );
5274
const bool horizontal( flags & State_Horizontal );
5275
const bool reverseLayout( slOpt->direction == Qt::RightToLeft );
5279
if( reverseLayout ) renderScrollBarHole( painter, r.adjusted( 0,0,10,0 ), color, Qt::Horizontal, TileSet::Vertical );
5280
else renderScrollBarHole( painter, r.adjusted( -10, 0,0,0 ), color, Qt::Horizontal, TileSet::Vertical );
5281
} else renderScrollBarHole( painter, r.adjusted( 0,-10,0,0 ), color, Qt::Vertical, TileSet::Horizontal );
5287
//___________________________________________________________________________________
5288
bool Style::drawScrollBarSubLineControl( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
5291
// cast option and check
5292
const QStyleOptionSlider* slOpt = qstyleoption_cast<const QStyleOptionSlider*>( option );
5293
if ( !slOpt ) return true;
5295
const State& flags( option->state );
5296
const bool horizontal( flags & State_Horizontal );
5297
const bool reverseLayout( option->direction == Qt::RightToLeft );
5300
const QPalette& palette( option->palette );
5301
const QColor background( palette.color( QPalette::Window ) );
5304
// adjust rect, based on number of buttons to be drawn
5305
QRect r( scrollBarInternalSubControlRect( slOpt, SC_ScrollBarSubLine ) );
5307
// draw the end of the scrollbar groove
5311
if( reverseLayout ) renderScrollBarHole( painter, QRect( r.left()-5, r.top(), 5, r.height() ), background, Qt::Horizontal, TileSet::Vertical | TileSet::Right );
5312
else renderScrollBarHole( painter, QRect( r.right()+1, r.top(), 5, r.height() ), background, Qt::Horizontal, TileSet::Vertical | TileSet::Left );
5314
r.translate( 1, 0 );
5318
renderScrollBarHole( painter, QRect( r.left(), r.bottom()+3, r.width(), 5 ), background, Qt::Vertical, TileSet::Top | TileSet::Horizontal );
5319
r.translate( 0, 2 );
5323
// stop here if no buttons are defined
5324
if( _subLineButtons == NoButton ) return true;
5327
QStyleOption localOption( *option );
5328
if( _subLineButtons == DoubleButton )
5335
const QSize halfSize( r.width()/2, r.height() );
5336
const QRect leftSubButton( r.topLeft(), halfSize );
5337
const QRect rightSubButton( leftSubButton.topRight() + QPoint( 1, 0 ), halfSize );
5339
localOption.rect = leftSubButton;
5340
color = scrollBarArrowColor( &localOption, reverseLayout ? SC_ScrollBarAddLine:SC_ScrollBarSubLine, widget );
5341
renderScrollBarArrow( painter, leftSubButton, color, background, ArrowLeft );
5343
localOption.rect = rightSubButton;
5344
color = scrollBarArrowColor( &localOption, reverseLayout ? SC_ScrollBarSubLine:SC_ScrollBarAddLine, widget );
5345
renderScrollBarArrow( painter, rightSubButton, color, background, ArrowRight );
5349
const QSize halfSize( r.width(), r.height()/2 );
5350
const QRect topSubButton( r.topLeft(), halfSize );
5351
const QRect botSubButton( topSubButton.bottomLeft() + QPoint( 0, 1 ), halfSize );
5353
localOption.rect = topSubButton;
5354
color = scrollBarArrowColor( &localOption, SC_ScrollBarSubLine, widget );
5355
renderScrollBarArrow( painter, topSubButton, color, background, ArrowUp );
5357
localOption.rect = botSubButton;
5358
color = scrollBarArrowColor( &localOption, SC_ScrollBarAddLine, widget );
5359
renderScrollBarArrow( painter, botSubButton, color, background, ArrowDown );
5363
} else if( _subLineButtons == SingleButton ) {
5365
localOption.rect = r;
5366
color = scrollBarArrowColor( &localOption, SC_ScrollBarSubLine, widget );
5367
if( horizontal ) renderScrollBarArrow( painter, r, color, background, reverseLayout ? ArrowRight : ArrowLeft );
5368
else renderScrollBarArrow( painter, r, color, background, ArrowUp );
5375
//___________________________________________________________________________________
5376
bool Style::drawScrollBarSubPageControl( const QStyleOption* option, QPainter* painter, const QWidget* ) const
5379
// cast option and check
5380
const QStyleOptionSlider* slOpt = qstyleoption_cast<const QStyleOptionSlider*>( option );
5381
if ( !slOpt ) return true;
5383
const QRect& r( option->rect );
5384
const QPalette& palette( option->palette );
5385
const QColor color( palette.color( QPalette::Window ) );
5387
const State& flags( option->state );
5388
const bool horizontal( flags & State_Horizontal );
5389
const bool reverseLayout( slOpt->direction == Qt::RightToLeft );
5393
if( reverseLayout ) renderScrollBarHole( painter, r.adjusted( -10, 0,0,0 ), color, Qt::Horizontal, TileSet::Vertical );
5394
else renderScrollBarHole( painter, r.adjusted( 0,0,10,0 ), color, Qt::Horizontal, TileSet::Vertical );
5395
} else renderScrollBarHole( painter, r.adjusted( 0,2,0,12 ), color, Qt::Vertical, TileSet::Horizontal );
5401
//___________________________________________________________________________________
5402
bool Style::drawShapedFrameControl( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
5405
// cast option and check
5406
const QStyleOptionFrameV3* frameOpt = qstyleoption_cast<const QStyleOptionFrameV3*>( option );
5407
if( !frameOpt ) return false;
5409
switch( frameOpt->frameShape )
5414
if( option->state & State_Sunken ) return true;
5420
const QColor color( helper().backgroundColor( option->palette.color( QPalette::Window ), widget, option->rect.center() ) );
5421
helper().drawSeparator( painter, option->rect, color, Qt::Horizontal );
5427
const QColor color( helper().backgroundColor( option->palette.color( QPalette::Window ), widget, option->rect.center() ) );
5428
helper().drawSeparator( painter, option->rect, color, Qt::Vertical );
5440
//___________________________________________________________________________________
5441
bool Style::drawTabBarTabLabelControl( const QStyleOption* option, QPainter* painter, const QWidget* ) const
5444
const QStyleOptionTab *tabOpt = qstyleoption_cast< const QStyleOptionTab* >( option );
5445
if( !tabOpt ) return true;
5447
// add extra offset for selected tas
5448
QStyleOptionTabV3 tabOptV3( *tabOpt );
5450
const bool selected( option->state&State_Selected );
5453
QRect r( option->rect );
5455
// handle selection and orientation
5457
painter is rotated and translated to deal with various orientations
5458
rect is translated to 0,0, and possibly transposed
5460
switch( tabOptV3.shape )
5464
case QTabBar::RoundedNorth:
5465
case QTabBar::TriangularNorth:
5467
if( selected ) r.translate( 0, -1 );
5468
painter->translate( r.topLeft() );
5469
r.moveTopLeft( QPoint( 0,0 ) );
5474
case QTabBar::RoundedSouth:
5475
case QTabBar::TriangularSouth:
5477
if( selected ) r.translate( 0, 1 );
5478
painter->translate( r.topLeft() );
5479
r.moveTopLeft( QPoint( 0,0 ) );
5484
case QTabBar::RoundedWest:
5485
case QTabBar::TriangularWest:
5488
if( selected ) r.translate( -1, 0 );
5489
painter->translate( r.bottomLeft() );
5490
painter->rotate( -90 );
5491
r = QRect( QPoint( 0, 0 ), QSize( r.height(), r.width() ) );
5496
case QTabBar::RoundedEast:
5497
case QTabBar::TriangularEast:
5500
if( selected ) r.translate( 1, 0 );
5501
painter->translate( r.topRight() );
5502
painter->rotate( 90 );
5503
r = QRect( QPoint( 0, 0 ), QSize( r.height(), r.width() ) );
5512
// make room for left and right widgets
5514
const bool verticalTabs( isVerticalTab( tabOpt ) );
5515
const bool hasLeftButton( !( option->direction == Qt::RightToLeft ? tabOptV3.rightButtonSize.isEmpty():tabOptV3.leftButtonSize.isEmpty() ) );
5516
const bool hasRightButton( !( option->direction == Qt::RightToLeft ? tabOptV3.leftButtonSize.isEmpty():tabOptV3.rightButtonSize.isEmpty() ) );
5519
{ r.setLeft( r.left() + 4 + ( verticalTabs ? tabOptV3.leftButtonSize.height() : tabOptV3.leftButtonSize.width() ) ); }
5521
// make room for left and right widgets
5523
if( hasRightButton )
5524
{ r.setRight( r.right() - 4 - ( verticalTabs ? tabOptV3.rightButtonSize.height() : tabOptV3.rightButtonSize.width() ) ); }
5526
// compute textRect and iconRect
5527
// now that orientation is properly dealt with, everything is handled as a 'north' orientation
5531
if( tabOptV3.icon.isNull() )
5534
textRect = r.adjusted( 6, 0, -6, 0 );
5538
const QSize& iconSize( tabOptV3.iconSize );
5539
iconRect = centerRect( r, iconSize );
5540
if( !tabOptV3.text.isEmpty() )
5543
iconRect.moveLeft( r.left() + 8 );
5545
textRect.setLeft( iconRect.right()+3 );
5546
textRect.setRight( r.right() - 6 );
5553
textRect = visualRect(option->direction, r, textRect );
5554
iconRect = visualRect(option->direction, r, iconRect );
5558
if( !iconRect.isNull() )
5561
// not sure why this is necessary
5562
if( tabOptV3.shape == QTabBar::RoundedNorth || tabOptV3.shape == QTabBar::TriangularNorth )
5563
{ iconRect.translate( 0, -1 ); }
5565
const QPixmap tabIcon = tabOptV3.icon.pixmap(
5567
( tabOptV3.state & State_Enabled ) ? QIcon::Normal : QIcon::Disabled,
5568
( tabOptV3.state & State_Selected ) ? QIcon::On : QIcon::Off );
5570
painter->drawPixmap( iconRect.x(), iconRect.y(), tabIcon );
5574
if( !textRect.isNull() )
5577
const QPalette& palette( option->palette );
5578
const QString& text( tabOptV3.text );
5579
const bool enabled( option->state & State_Enabled );
5580
const int alignment( Qt::AlignCenter|Qt::TextShowMnemonic );
5581
drawItemText( painter, textRect, alignment, palette, enabled, text, QPalette::WindowText );
5589
//___________________________________________________________________________________
5590
bool Style::drawTabBarTabShapeControl_Single( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
5593
const QStyleOptionTab* tabOpt( qstyleoption_cast<const QStyleOptionTab*>( option ) );
5594
if( !tabOpt ) return true;
5596
const State& flags( option->state );
5597
const QRect& r( option->rect );
5598
const QPalette& palette( option->palette );
5600
const bool enabled( flags & State_Enabled );
5601
const bool selected( flags&State_Selected );
5602
const bool reverseLayout( option->direction == Qt::RightToLeft );
5604
// this is needed to complete the base frame when there are widgets in tabbar
5605
const QTabBar* tabBar( qobject_cast<const QTabBar*>( widget ) );
5606
const QRect tabBarRect( tabBar ? insideMargin( tabBar->rect(), -GlowWidth ):QRect() );
5608
// check if tab is being dragged
5609
const bool isDragged( selected && painter->device() != tabBar );
5611
// hover and animation flags
5612
/* all are disabled when tabBar is locked ( drag in progress ) */
5613
const bool tabBarLocked( tabBarData().locks( tabBar ) );
5614
const bool mouseOver( enabled && !tabBarLocked && ( flags & State_MouseOver ) );
5617
animations().tabBarEngine().updateState( widget, r.topLeft(), mouseOver );
5618
const bool animated( enabled && !selected && !tabBarLocked && animations().tabBarEngine().isAnimated( widget, r.topLeft() ) );
5620
// handle base frame painting, for tabbars in which tab is being dragged
5621
tabBarData().drawTabBarBaseControl( tabOpt, painter, widget );
5622
if( selected && tabBar && isDragged ) tabBarData().lock( tabBar );
5623
else if( selected && tabBarData().locks( tabBar ) ) tabBarData().release();
5625
// tab position and flags
5626
const QStyleOptionTab::TabPosition& position = tabOpt->position;
5627
const bool isFirst( position == QStyleOptionTab::OnlyOneTab || position == QStyleOptionTab::Beginning );
5628
const bool isRightOfSelected( tabOpt->selectedPosition == QStyleOptionTab::PreviousIsSelected );
5631
const QStyleOptionTabV3 *tabOptV3 = qstyleoption_cast<const QStyleOptionTabV3 *>( option );
5632
bool documentMode = tabOptV3 ? tabOptV3->documentMode : false;
5633
const QTabWidget *tabWidget = ( widget && widget->parentWidget() ) ? qobject_cast<const QTabWidget *>( widget->parentWidget() ) : NULL;
5634
documentMode |= ( tabWidget ? tabWidget->documentMode() : true );
5636
const bool verticalTabs( isVerticalTab( tabOpt ) );
5637
const QRect tabWidgetRect( tabWidget ?
5638
insideMargin( tabWidget->rect(), -GlowWidth ).translated( -widget->geometry().topLeft() ) :
5642
const bool hasLeftCornerWidget( tabOpt->cornerWidgets & QStyleOptionTab::LeftCornerWidget );
5643
const bool hasRightCornerWidget( tabOpt->cornerWidgets & QStyleOptionTab::RightCornerWidget );
5645
// true if widget is aligned to the frame
5646
/* need to check for 'isRightOfSelected' because for some reason the isFirst flag is set when active tab is being moved */
5647
const bool isFrameAligned( !documentMode && isFirst && !hasLeftCornerWidget && !isRightOfSelected && !isDragged );
5648
bool fillBackground( selected && isDragged );
5650
bool isLeftFrameAligned( false );
5651
bool isRightFrameAligned( false );
5657
1/ leftFrameAligned corresponds to top side
5658
2/ rightFrameAligned corresponds to the bottom side
5659
3/ their value does not depend on reverseLayout
5661
isLeftFrameAligned = isFrameAligned;
5662
isRightFrameAligned = (!documentMode) && tabWidget && ( r.bottom() >= tabWidgetRect.bottom() - 2 );;
5663
fillBackground |= selected && isRightFrameAligned;
5665
} else if( reverseLayout ) {
5667
isLeftFrameAligned = (!documentMode) && tabWidget && ( r.left() <= tabWidgetRect.left() + 2 );
5668
isRightFrameAligned = isFrameAligned;
5669
fillBackground |= selected && isLeftFrameAligned;
5673
isLeftFrameAligned = isFrameAligned;
5674
isRightFrameAligned = (!documentMode) && tabWidget && ( r.right() >= tabWidgetRect.right() - 2 );
5675
fillBackground |= selected && isRightFrameAligned;
5679
// part of the tab in which the text is drawn
5682
// connection to the frame
5685
switch( tabOpt->shape )
5687
case QTabBar::RoundedNorth:
5688
case QTabBar::TriangularNorth:
5691
// part of the tab in which the text is drawn
5692
// larger tabs when selected
5693
if( selected ) tabRect.adjust( 0, -1, 0, 2 );
5694
else tabRect.adjust( 0, 1, 0, 2 );
5696
// reduces the space between tabs
5697
tabRect.adjust( -GlowWidth,0,GlowWidth,0 );
5699
// connection to the main frame
5703
// do nothing if dragged
5704
if( isDragged ) break;
5707
if( isLeftFrameAligned )
5710
QRect frameRect( r );
5711
frameRect.setLeft( frameRect.left() - GlowWidth );
5712
frameRect.setRight( tabRect.left() + 7 );
5713
frameRect.setTop( tabRect.bottom() - 13 );
5714
frameRect.setBottom( frameRect.bottom() + 7 - 1 );
5715
slabs << SlabRect( frameRect, TileSet::Left );
5719
QRect frameRect( r );
5720
frameRect.setLeft( frameRect.left() - 7 );
5721
frameRect.setRight( tabRect.left() + 7 + 3 );
5722
frameRect.setTop( r.bottom() - 7 );
5723
slabs << SlabRect( frameRect, TileSet::Top );
5727
if( isRightFrameAligned )
5730
QRect frameRect( r );
5731
frameRect.setLeft( tabRect.right() - 7 );
5732
frameRect.setRight( frameRect.right() + GlowWidth );
5733
frameRect.setTop( tabRect.bottom() - 13 );
5734
frameRect.setBottom( frameRect.bottom() + 7 - 1 );
5735
slabs << SlabRect( frameRect, TileSet::Right );
5739
QRect frameRect( r );
5740
frameRect.setLeft( tabRect.right() - 7 - 3 );
5741
frameRect.setRight( frameRect.right() + 7 );
5742
frameRect.setTop( r.bottom() - 7 );
5743
slabs << SlabRect( frameRect, TileSet::Top );
5747
// extra base, to extend below inactive tabs and buttons
5750
if( r.left() > tabBarRect.left() + 1 )
5752
QRect frameRect( r );
5753
frameRect.setLeft( tabBarRect.left() - 7 + 1 );
5754
frameRect.setRight( r.left() + 7 - 1 );
5755
frameRect.setTop( r.bottom() - 7 );
5756
if( documentMode || reverseLayout ) slabs << SlabRect( frameRect, TileSet::Top );
5757
else slabs << SlabRect( frameRect, TileSet::TopLeft );
5761
if( r.right() < tabBarRect.right() - 1 )
5764
QRect frameRect( r );
5765
frameRect.setLeft( r.right() - 7 + 1 );
5766
frameRect.setRight( tabBarRect.right() + 7 - 1 );
5767
frameRect.setTop( r.bottom() - 7 );
5768
if( documentMode || !reverseLayout ) slabs << SlabRect( frameRect, TileSet::Top );
5769
else slabs << SlabRect( frameRect, TileSet::TopRight );
5775
if( isRightFrameAligned )
5778
QRect frameRect( r );
5779
frameRect.setLeft( tabRect.right() - 7 );
5780
frameRect.setRight( frameRect.right() + GlowWidth );
5781
frameRect.setTop( tabRect.bottom() - 13 );
5782
frameRect.setBottom( frameRect.bottom() + 7 - 2 );
5783
slabs << SlabRect( frameRect, TileSet::Right );
5787
if( isLeftFrameAligned )
5790
QRect frameRect( r );
5791
frameRect.setLeft( frameRect.left() - GlowWidth );
5792
frameRect.setRight( tabRect.left() + 7 );
5793
frameRect.setTop( tabRect.bottom() - 13 );
5794
frameRect.setBottom( frameRect.bottom() + 7 - 2 );
5795
slabs << SlabRect( frameRect, TileSet::Left );
5805
case QTabBar::RoundedSouth:
5806
case QTabBar::TriangularSouth:
5809
// larger tabs when selected
5810
if( selected ) tabRect.adjust( 0, -2, 0, 1 );
5811
else tabRect.adjust( 0, -2, 0, -1 );
5813
// reduces the space between tabs
5814
tabRect.adjust( -GlowWidth,0,GlowWidth,0 );
5816
// connection to the main frame
5820
// do nothing if dragged
5821
if( isDragged ) break;
5824
if( isLeftFrameAligned )
5827
QRect frameRect( r );
5828
frameRect.setLeft( frameRect.left() - GlowWidth );
5829
frameRect.setRight( tabRect.left() + 7 );
5830
frameRect.setTop( frameRect.top() - 7 + 1 );
5831
frameRect.setBottom( tabRect.top() + 13 );
5832
slabs << SlabRect( frameRect, TileSet::Left );
5836
QRect frameRect( r );
5837
frameRect.setLeft( frameRect.left() - 7 );
5838
frameRect.setRight( tabRect.left() + 7 + 3 );
5839
frameRect.setBottom( r.top() + 7 );
5840
slabs << SlabRect( frameRect, TileSet::Bottom );
5844
if( isRightFrameAligned )
5847
QRect frameRect( r );
5848
frameRect.setLeft( tabRect.right() - 7 );
5849
frameRect.setRight( frameRect.right() + GlowWidth );
5850
frameRect.setTop( frameRect.top() - 7 + 1 );
5851
frameRect.setBottom( tabRect.top() + 13 );
5852
slabs << SlabRect( frameRect, TileSet::Right );
5856
QRect frameRect( r );
5857
frameRect.setLeft( tabRect.right() - 7 - 3 );
5858
frameRect.setRight( frameRect.right() + 7 );
5859
frameRect.setBottom( r.top() + 7 );
5860
slabs << SlabRect( frameRect, TileSet::Bottom );
5864
// extra base, to extend below tabbar buttons
5867
if( r.left() > tabBarRect.left() + 1 )
5869
QRect frameRect( r );
5870
frameRect.setLeft( tabBarRect.left() - 7 + 1 );
5871
frameRect.setRight( r.left() + 7 - 1 );
5872
frameRect.setBottom( r.top() + 7 );
5873
if( documentMode || reverseLayout ) slabs << SlabRect( frameRect, TileSet::Bottom );
5874
else slabs << SlabRect( frameRect, TileSet::BottomLeft );
5877
if( r.right() < tabBarRect.right() - 1 )
5880
QRect frameRect( r );
5881
frameRect.setLeft( r.right() - 7 + 1 );
5882
frameRect.setRight( tabBarRect.right() + 7 - 1 );
5883
frameRect.setBottom( r.top() + 7 );
5884
if( documentMode || !reverseLayout ) slabs << SlabRect( frameRect, TileSet::Bottom );
5885
else slabs << SlabRect( frameRect, TileSet::BottomRight );
5892
if( isRightFrameAligned )
5895
QRect frameRect( r );
5896
frameRect.setLeft( tabRect.right() - 7 );
5897
frameRect.setRight( frameRect.right() + GlowWidth );
5898
frameRect.setTop( frameRect.top() - 7 + 2 );
5899
frameRect.setBottom( tabRect.top() + 13 );
5900
slabs << SlabRect( frameRect, TileSet::Right );
5904
if( isLeftFrameAligned )
5907
QRect frameRect( r );
5908
frameRect.setLeft( frameRect.left() - GlowWidth );
5909
frameRect.setRight( tabRect.left() + 7 );
5910
frameRect.setTop( frameRect.top() - 7 + 2 );
5911
frameRect.setBottom( tabRect.top() + 13 );
5912
slabs << SlabRect( frameRect, TileSet::Left );
5922
case QTabBar::RoundedWest:
5923
case QTabBar::TriangularWest:
5926
// larger tabs when selected
5927
if( selected ) tabRect.adjust( -1, 0, 2, 0 );
5928
else tabRect.adjust( 1, 0, 2, 0 );
5930
// reduces the space between tabs
5931
tabRect.adjust( 0, -GlowWidth,0,GlowWidth );
5933
// connection to the main frame
5937
// do nothing if dragged
5938
if( isDragged ) break;
5941
if( isLeftFrameAligned )
5944
QRect frameRect( r );
5945
frameRect.setLeft( tabRect.right() - 13 );
5946
frameRect.setRight( frameRect.right() + 7 - 1 );
5947
frameRect.setTop( frameRect.top() - GlowWidth );
5948
frameRect.setBottom( tabRect.top() + 7 );
5949
slabs << SlabRect( frameRect, TileSet::Top );
5953
QRect frameRect( r );
5954
frameRect.setLeft( r.right() - 7 );
5955
frameRect.setTop( frameRect.top() - 7 );
5956
frameRect.setBottom( tabRect.top() + 7 + 3 );
5957
slabs << SlabRect( frameRect, TileSet::Left );
5961
if( isRightFrameAligned )
5965
QRect frameRect( r );
5966
frameRect.setLeft( tabRect.right() - 13 );
5967
frameRect.setRight( frameRect.right() + 7 - 1 );
5968
frameRect.setTop( tabRect.bottom() - 7 );
5969
frameRect.setBottom( frameRect.bottom() + GlowWidth );
5970
slabs << SlabRect( frameRect, TileSet::Bottom );
5974
QRect frameRect( r );
5975
frameRect.setLeft( r.right() - 7 );
5976
frameRect.setTop( tabRect.bottom() - 7 - 3 );
5977
frameRect.setBottom( frameRect.bottom() + 7 );
5978
slabs << SlabRect( frameRect, TileSet::Left );
5982
// extra base, to extend below tabbar buttons
5985
if( r.top() > tabBarRect.top() + 1 )
5988
QRect frameRect( r );
5989
frameRect.setTop( tabBarRect.top() - 7 + 1 );
5990
frameRect.setBottom( r.top() + 7 - 1 );
5991
frameRect.setLeft( r.right() - 7 );
5992
if( documentMode ) slabs << SlabRect( frameRect, TileSet::Left );
5993
else slabs << SlabRect( frameRect, TileSet::TopLeft );
5996
if( r.bottom() < tabBarRect.bottom() - 1 )
5999
QRect frameRect( r );
6000
frameRect.setTop( r.bottom() - 7 + 1 );
6001
if( hasRightCornerWidget && documentMode ) frameRect.setBottom( tabBarRect.bottom() + 7 - 1 );
6002
else frameRect.setBottom( tabBarRect.bottom() + 7 );
6003
frameRect.setLeft( r.right() - 7 );
6004
slabs << SlabRect( frameRect, TileSet::Left );
6011
if( isLeftFrameAligned )
6014
QRect frameRect( r );
6015
frameRect.setLeft( tabRect.right() - 13 );
6016
frameRect.setRight( frameRect.right() + 7 - 2 );
6017
frameRect.setTop( frameRect.top() - GlowWidth );
6018
frameRect.setBottom( tabRect.top() + 7 );
6019
slabs << SlabRect( frameRect, TileSet::Top );
6023
if( isRightFrameAligned )
6027
QRect frameRect( r );
6028
frameRect.setLeft( tabRect.right() - 13 );
6029
frameRect.setRight( frameRect.right() + 7 - 2 );
6030
frameRect.setTop( tabRect.bottom() - 7 );
6031
frameRect.setBottom( frameRect.bottom() + GlowWidth );
6032
slabs << SlabRect( frameRect, TileSet::Bottom );
6040
case QTabBar::RoundedEast:
6041
case QTabBar::TriangularEast:
6044
// larger tabs when selected
6045
if( selected ) tabRect.adjust( -2, 0, 1, 0 );
6046
else tabRect.adjust( -2, 0, -1, 0 );
6048
// reduces the space between tabs
6049
tabRect.adjust( 0, -GlowWidth,0,GlowWidth );
6051
// connection to the main frame
6055
// do nothing if dragged
6056
if( isDragged ) break;
6059
if( isLeftFrameAligned )
6062
QRect frameRect( r );
6063
frameRect.setLeft( frameRect.left() - 7 + 1 );
6064
frameRect.setRight( tabRect.left() + 13 );
6065
frameRect.setTop( frameRect.top() - GlowWidth );
6066
frameRect.setBottom( tabRect.top() + 7 );
6067
slabs << SlabRect( frameRect, TileSet::Top );
6071
QRect frameRect( r );
6072
frameRect.setRight( r.left() + 7 );
6073
frameRect.setTop( frameRect.top() - 7 );
6074
frameRect.setBottom( tabRect.top() + 7 + 3 );
6075
slabs << SlabRect( frameRect, TileSet::Right );
6079
if( isRightFrameAligned )
6083
QRect frameRect( r );
6084
frameRect.setLeft( frameRect.left() - 7 + 1 );
6085
frameRect.setRight( tabRect.left() + 13 );
6086
frameRect.setTop( tabRect.bottom() - 7 );
6087
frameRect.setBottom( frameRect.bottom() + GlowWidth );
6088
slabs << SlabRect( frameRect, TileSet::Bottom );
6092
QRect frameRect( r );
6093
frameRect.setRight( r.left() + 7 );
6094
frameRect.setTop( tabRect.bottom() - 7 - 3 );
6095
frameRect.setBottom( frameRect.bottom() + 7 );
6096
slabs << SlabRect( frameRect, TileSet::Right );
6100
// extra base, to extend below tabbar buttons
6103
if( r.top() > tabBarRect.top() + 1 )
6106
QRect frameRect( r );
6107
frameRect.setTop( tabBarRect.top() - 7 + 1 );
6108
frameRect.setBottom( r.top() + 7 - 1 );
6109
frameRect.setRight( r.left() + 7 );
6110
if( documentMode ) slabs << SlabRect( frameRect, TileSet::Right );
6111
else slabs << SlabRect( frameRect, TileSet::TopRight );
6114
if( r.bottom() < tabBarRect.bottom() - 1 )
6117
QRect frameRect( r );
6118
frameRect.setTop( r.bottom() - 7 + 1 );
6119
if( hasRightCornerWidget && documentMode ) frameRect.setBottom( tabBarRect.bottom() + 7 - 1 );
6120
else frameRect.setBottom( tabBarRect.bottom() + 7 );
6121
frameRect.setRight( r.left() + 7 );
6122
slabs << SlabRect( frameRect, TileSet::Right );
6129
if( isLeftFrameAligned )
6132
QRect frameRect( r );
6133
frameRect.setLeft( frameRect.left() - 7 + 2 );
6134
frameRect.setRight( tabRect.left() + 13 );
6135
frameRect.setTop( frameRect.top() - GlowWidth );
6136
frameRect.setBottom( tabRect.top() + 7 );
6137
slabs << SlabRect( frameRect, TileSet::Top );
6141
if( isRightFrameAligned )
6145
QRect frameRect( r );
6146
frameRect.setLeft( frameRect.left() - 7 + 2 );
6147
frameRect.setRight( tabRect.left() + 13 );
6148
frameRect.setTop( tabRect.bottom() - 7 );
6149
frameRect.setBottom( frameRect.bottom() + GlowWidth );
6150
slabs << SlabRect( frameRect, TileSet::Bottom );
6164
StyleOptions slabOptions( NoFill );
6165
if( StyleConfigData::tabSubtleShadow() ) slabOptions |= SubtleShadow;
6166
if( ( !selected ) && ( mouseOver || animated ) ) slabOptions |= Hover;
6169
const QColor color( palette.color( QPalette::Window ) );
6171
// render connections to frame
6172
// extra care must be taken care of so that no slab
6173
// extends beyond tabWidget frame, if any
6174
foreach( SlabRect slab, slabs ) // krazy:exclude=foreach
6176
adjustSlabRect( slab, tabWidgetRect, documentMode, verticalTabs );
6177
if( selected || !animated ) renderSlab( painter, slab, color, slabOptions );
6180
const qreal opacity( animations().tabBarEngine().opacity( widget, r.topLeft() ) );
6181
renderSlab( painter, slab, color, slabOptions, opacity, AnimationHover );
6187
// adjust clip rect and render tabs
6191
painter->setClipRegion( tabBarClipRegion( tabBar ) );
6195
TileSet::Tiles tiles( tilesByShape( tabOpt->shape ) );
6199
// render window background first, if needed
6200
if( fillBackground ) fillTabBackground( painter, tabRect, color, tabOpt->shape, widget );
6202
// render window background in case of dragged tabwidget
6203
renderSlab( painter, tabRect, color, slabOptions, tiles );
6205
} else if( animated ) {
6207
const qreal opacity( animations().tabBarEngine().opacity( widget, r.topLeft() ) );
6208
renderSlab( painter, tabRect, color, slabOptions, opacity, AnimationHover, tiles );
6210
} else renderSlab( painter, tabRect, color, slabOptions, tiles );
6213
fillTab( painter, tabRect, color, tabOpt->shape, selected );
6215
// restore clip region
6216
if( tabBar ) painter->restore();
6222
//___________________________________________________________________________________
6223
bool Style::drawTabBarTabShapeControl_Plain( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
6226
const QStyleOptionTab* tabOpt( qstyleoption_cast<const QStyleOptionTab*>( option ) );
6227
if( !tabOpt ) return true;
6229
const State& flags( option->state );
6230
const QRect& r( option->rect );
6231
const QPalette& palette( option->palette );
6233
const bool enabled( flags & State_Enabled );
6234
const bool selected( flags&State_Selected );
6235
const bool reverseLayout( option->direction == Qt::RightToLeft );
6237
// tab position and flags
6238
const QStyleOptionTab::TabPosition& position = tabOpt->position;
6239
bool isFirst( position == QStyleOptionTab::OnlyOneTab || position == QStyleOptionTab::Beginning );
6240
bool isLast( position == QStyleOptionTab::OnlyOneTab || position == QStyleOptionTab::End );
6241
bool isLeftOfSelected( tabOpt->selectedPosition == QStyleOptionTab::NextIsSelected );
6242
bool isRightOfSelected( tabOpt->selectedPosition == QStyleOptionTab::PreviousIsSelected );
6245
const QStyleOptionTabV3 *tabOptV3 = qstyleoption_cast<const QStyleOptionTabV3 *>( option );
6246
bool documentMode = tabOptV3 ? tabOptV3->documentMode : false;
6247
const QTabWidget *tabWidget = ( widget && widget->parentWidget() ) ? qobject_cast<const QTabWidget *>( widget->parentWidget() ) : NULL;
6248
documentMode |= ( tabWidget ? tabWidget->documentMode() : true );
6250
// this is needed to complete the base frame when there are widgets in tabbar
6251
const QTabBar* tabBar( qobject_cast<const QTabBar*>( widget ) );
6252
const QRect tabBarRect( tabBar ? insideMargin( tabBar->rect(), -GlowWidth ):QRect() );
6254
// check if tab is being dragged
6255
const bool isDragged( selected && painter->device() != tabBar );
6257
// hover and animation flags
6258
/* all are disabled when tabBar is locked ( drag in progress ) */
6259
const bool tabBarLocked( tabBarData().locks( tabBar ) );
6260
const bool mouseOver( enabled && !tabBarLocked && ( flags & State_MouseOver ) );
6263
animations().tabBarEngine().updateState( widget, r.topLeft(), mouseOver );
6264
const bool animated( enabled && !selected && !tabBarLocked && animations().tabBarEngine().isAnimated( widget, r.topLeft() ) );
6266
// handle base frame painting, for tabbars in which tab is being dragged
6267
tabBarData().drawTabBarBaseControl( tabOpt, painter, widget );
6268
if( selected && tabBar && isDragged ) tabBarData().lock( tabBar );
6269
else if( selected && tabBarData().locks( tabBar ) ) tabBarData().release();
6272
const bool hasLeftCornerWidget( tabOpt->cornerWidgets & QStyleOptionTab::LeftCornerWidget );
6273
const bool hasRightCornerWidget( tabOpt->cornerWidgets & QStyleOptionTab::RightCornerWidget );
6275
// true if widget is aligned to the frame
6276
/* need to check for 'isRightOfSelected' because for some reason the isFirst flag is set when active tab is being moved */
6277
const bool isFrameAligned( !documentMode && isFirst && !hasLeftCornerWidget && !isRightOfSelected && !isDragged );
6278
isFirst &= !isRightOfSelected;
6279
isLast &= !isLeftOfSelected;
6281
// swap flags based on reverse layout, so that they become layout independent
6282
const bool verticalTabs( isVerticalTab( tabOpt ) );
6283
if( reverseLayout && !verticalTabs )
6285
qSwap( isFirst, isLast );
6286
qSwap( isLeftOfSelected, isRightOfSelected );
6289
const qreal radius = 5;
6291
// part of the tab in which the text is drawn
6295
// connection to the frame
6298
// highlighted slab ( if any )
6299
SlabRect highlightSlab;
6301
switch( tabOpt->shape )
6303
case QTabBar::RoundedNorth:
6304
case QTabBar::TriangularNorth:
6307
// part of the tab in which the text is drawn
6308
// larger tabs when selected
6309
if( selected ) tabRect.adjust( 0, -1, 0, 2 );
6310
else tabRect.adjust( 0, 3, 1, -7 + 1 );
6312
// connection to the main frame
6316
// reduces the space between tabs
6317
tabRect.adjust( -GlowWidth,0,GlowWidth,0 );
6319
// do nothing if dragged
6320
if( isDragged ) break;
6323
if( isFrameAligned && !reverseLayout )
6326
QRect frameRect( r );
6327
frameRect.setLeft( frameRect.left() - GlowWidth );
6328
frameRect.setRight( tabRect.left() + 7 );
6329
frameRect.setTop( tabRect.bottom() - 13 );
6330
frameRect.setBottom( frameRect.bottom() + 7 - 1 );
6331
slabs << SlabRect( frameRect, TileSet::Left );
6335
QRect frameRect( r );
6336
frameRect.setLeft( frameRect.left() - 7 );
6337
frameRect.setRight( tabRect.left() + 7 + 3 );
6338
frameRect.setTop( r.bottom() - 7 );
6339
slabs << SlabRect( frameRect, TileSet::Top );
6343
if( isFrameAligned && reverseLayout )
6346
QRect frameRect( r );
6347
frameRect.setLeft( tabRect.right() - 7 );
6348
frameRect.setRight( frameRect.right() + GlowWidth );
6349
frameRect.setTop( tabRect.bottom() - 13 );
6350
frameRect.setBottom( frameRect.bottom() + 7 - 1 );
6351
slabs << SlabRect( frameRect, TileSet::Right );
6355
QRect frameRect( r );
6356
frameRect.setLeft( tabRect.right() - 7 - 3 );
6357
frameRect.setRight( frameRect.right() + 7 );
6358
frameRect.setTop( r.bottom() - 7 );
6359
slabs << SlabRect( frameRect, TileSet::Top );
6363
// extra base, to extend below inactive tabs and buttons
6366
if( r.left() > tabBarRect.left() + 1 )
6368
QRect frameRect( r );
6369
frameRect.setLeft( tabBarRect.left() - 7 + 1 );
6370
frameRect.setRight( r.left() + 7 - 1 );
6371
frameRect.setTop( r.bottom() - 7 );
6372
if( documentMode || reverseLayout ) slabs << SlabRect( frameRect, TileSet::Top );
6373
else slabs << SlabRect( frameRect, TileSet::TopLeft );
6377
if( r.right() < tabBarRect.right() - 1 )
6380
QRect frameRect( r );
6381
frameRect.setLeft( r.right() - 7 + 1 );
6382
frameRect.setRight( tabBarRect.right() + 7 - 1 );
6383
frameRect.setTop( r.bottom() - 7 );
6384
if( documentMode || !reverseLayout ) slabs << SlabRect( frameRect, TileSet::Top );
6385
else slabs << SlabRect( frameRect, TileSet::TopRight );
6391
// adjust sides when slab is adjacent to selected slab
6392
if( isLeftOfSelected ) tabRect.setRight( tabRect.right() + 2 );
6393
else if( isRightOfSelected ) tabRect.setLeft( tabRect.left() - 2 );
6398
tabRect.adjust( GlowWidth, 0, 0, 0 );
6399
if( isFrameAligned ) path.moveTo( tabRect.bottomLeft() + QPoint( 0, 2 ) );
6400
else path.moveTo( tabRect.bottomLeft() );
6401
path.lineTo( tabRect.topLeft() + QPointF( 0, radius ) );
6402
path.quadTo( tabRect.topLeft(), tabRect.topLeft() + QPoint( radius, 0 ) );
6403
path.lineTo( tabRect.topRight() );
6404
path.lineTo( tabRect.bottomRight() );
6407
} else if( isLast ) {
6409
tabRect.adjust( 0, 0, -GlowWidth-1, 0 );
6410
path.moveTo( tabRect.bottomLeft() );
6411
path.lineTo( tabRect.topLeft() );
6412
path.lineTo( tabRect.topRight() - QPointF( radius, 0 ) );
6413
path.quadTo( tabRect.topRight(), tabRect.topRight() + QPointF( 0, radius ) );
6414
if( isFrameAligned ) path.lineTo( tabRect.bottomRight() + QPointF( 0, 2 ) );
6415
else path.lineTo( tabRect.bottomRight() );
6419
path.moveTo( tabRect.bottomLeft() );
6420
path.lineTo( tabRect.topLeft() );
6421
path.lineTo( tabRect.topRight() );
6422
path.lineTo( tabRect.bottomRight() );
6427
QRect highlightRect( tabRect.left(), tabRect.bottom()-1, tabRect.width(), 7 );
6428
if( isFrameAligned && isFirst ) highlightSlab = SlabRect( highlightRect.adjusted( -2, 0, 7 + 1, 0 ), TileSet::TopLeft );
6429
else if( isFrameAligned && isLast ) highlightSlab = SlabRect( highlightRect.adjusted( -7, 0, 2, 0 ), TileSet::TopRight );
6430
else highlightSlab = SlabRect( highlightRect.adjusted( -7, 0, 7, 0 ), TileSet::Top );
6438
case QTabBar::RoundedSouth:
6439
case QTabBar::TriangularSouth:
6442
// larger tabs when selected
6443
if( selected ) tabRect.adjust( 0, -2, 0, 1 );
6444
else tabRect.adjust( 0, 7 - 1, 1, -3 );
6446
// connection to the main frame
6450
// reduces the space between tabs
6451
tabRect.adjust( -GlowWidth,0,GlowWidth,0 );
6453
// do nothing if dragged
6454
if( isDragged ) break;
6457
if( isFrameAligned && !reverseLayout )
6460
QRect frameRect( r );
6461
frameRect.setLeft( frameRect.left() - GlowWidth );
6462
frameRect.setRight( tabRect.left() + 7 );
6463
frameRect.setTop( frameRect.top() - 7 + 1 );
6464
frameRect.setBottom( tabRect.top() + 13 );
6465
slabs << SlabRect( frameRect, TileSet::Left );
6469
QRect frameRect( r );
6470
frameRect.setLeft( frameRect.left() - 7 );
6471
frameRect.setRight( tabRect.left() + 7 + 3 );
6472
frameRect.setBottom( r.top() + 7 );
6473
slabs << SlabRect( frameRect, TileSet::Bottom );
6477
if( isFrameAligned && reverseLayout )
6480
QRect frameRect( r );
6481
frameRect.setLeft( tabRect.right() - 7 );
6482
frameRect.setRight( frameRect.right() + GlowWidth );
6483
frameRect.setTop( frameRect.top() - 7 + 1 );
6484
frameRect.setBottom( tabRect.top() + 13 );
6485
slabs << SlabRect( frameRect, TileSet::Right );
6489
QRect frameRect( r );
6490
frameRect.setLeft( tabRect.right() - 7 - 3 );
6491
frameRect.setRight( frameRect.right() + 7 );
6492
frameRect.setBottom( r.top() + 7 );
6493
slabs << SlabRect( frameRect, TileSet::Bottom );
6497
// extra base, to extend below tabbar buttons
6500
if( r.left() > tabBarRect.left() + 1 )
6502
QRect frameRect( r );
6503
frameRect.setLeft( tabBarRect.left() - 7 + 1 );
6504
frameRect.setRight( r.left() + 7 - 1 );
6505
frameRect.setBottom( r.top() + 7 );
6506
if( documentMode || reverseLayout ) slabs << SlabRect( frameRect, TileSet::Bottom );
6507
else slabs << SlabRect( frameRect, TileSet::BottomLeft );
6510
if( r.right() < tabBarRect.right() - 1 )
6513
QRect frameRect( r );
6514
frameRect.setLeft( r.right() - 7 + 1 );
6515
frameRect.setRight( tabBarRect.right() + 7 - 1 );
6516
frameRect.setBottom( r.top() + 7 );
6517
if( documentMode || !reverseLayout ) slabs << SlabRect( frameRect, TileSet::Bottom );
6518
else slabs << SlabRect( frameRect, TileSet::BottomRight );
6525
// adjust sides when slab is adjacent to selected slab
6526
if( isLeftOfSelected ) tabRect.setRight( tabRect.right() + 2 );
6527
else if( isRightOfSelected ) tabRect.setLeft( tabRect.left() - 2 );
6532
tabRect.adjust( GlowWidth, 0, 0, 0 );
6533
if( isFrameAligned ) path.moveTo( tabRect.topLeft() - QPoint( 0, 2 ) );
6534
else path.moveTo( tabRect.topLeft() );
6535
path.lineTo( tabRect.bottomLeft() - QPointF( 0, radius ) );
6536
path.quadTo( tabRect.bottomLeft(), tabRect.bottomLeft() + QPoint( radius, 0 ) );
6537
path.lineTo( tabRect.bottomRight() );
6538
path.lineTo( tabRect.topRight() );
6540
} else if( isLast ) {
6542
tabRect.adjust( 0, 0, -GlowWidth-1, 0 );
6543
path.moveTo( tabRect.topLeft() );
6544
path.lineTo( tabRect.bottomLeft() );
6545
path.lineTo( tabRect.bottomRight() - QPointF( radius, 0 ) );
6546
path.quadTo( tabRect.bottomRight(), tabRect.bottomRight() - QPointF( 0, radius ) );
6547
if( isFrameAligned ) path.lineTo( tabRect.topRight() - QPointF( 0, 2 ) );
6548
else path.lineTo( tabRect.topRight() );
6552
path.moveTo( tabRect.topLeft() );
6553
path.lineTo( tabRect.bottomLeft() );
6554
path.lineTo( tabRect.bottomRight() );
6555
path.lineTo( tabRect.topRight() );
6560
QRect highlightRect( tabRect.left(), tabRect.top()-5, tabRect.width(), 7 );
6561
if( isFrameAligned && isFirst ) highlightSlab = SlabRect( highlightRect.adjusted( -2, 0, 7 + 1, 0 ), TileSet::BottomLeft );
6562
else if( isFrameAligned && isLast ) highlightSlab = SlabRect( highlightRect.adjusted( -7, 0, 2, 0 ), TileSet::BottomRight );
6563
else highlightSlab = SlabRect( highlightRect.adjusted( -7, 0, 7, 0 ), TileSet::Bottom );
6571
case QTabBar::RoundedWest:
6572
case QTabBar::TriangularWest:
6575
// larger tabs when selected
6576
if( selected ) tabRect.adjust( -1, 0, 2, 0 );
6577
else tabRect.adjust( 3, 0, -7 + 1, 1 );
6579
// connection to the main frame
6583
// reduces the space between tabs
6584
tabRect.adjust( 0, -GlowWidth,0,GlowWidth );
6586
// do nothing if dragged
6587
if( isDragged ) break;
6590
if( isFrameAligned )
6593
QRect frameRect( r );
6594
frameRect.setLeft( tabRect.right() - 13 );
6595
frameRect.setRight( frameRect.right() + 7 - 1 );
6596
frameRect.setTop( frameRect.top() - GlowWidth );
6597
frameRect.setBottom( tabRect.top() + 7 );
6598
slabs << SlabRect( frameRect, TileSet::Top );
6602
QRect frameRect( r );
6603
frameRect.setLeft( r.right() - 7 );
6604
frameRect.setTop( frameRect.top() - 7 );
6605
frameRect.setBottom( tabRect.top() + 7 + 3 );
6606
slabs << SlabRect( frameRect, TileSet::Left );
6610
QRect frameRect( r );
6611
frameRect.setLeft( r.right() - 7 );
6612
frameRect.setTop( tabRect.bottom() - 7 - 3 );
6613
frameRect.setBottom( frameRect.bottom() + 7 );
6614
slabs << SlabRect( frameRect, TileSet::Left );
6616
// extra base, to extend below tabbar buttons
6619
if( r.top() > tabBarRect.top() + 1 )
6622
QRect frameRect( r );
6623
frameRect.setTop( tabBarRect.top() - 7 + 1 );
6624
frameRect.setBottom( r.top() + 7 - 1 );
6625
frameRect.setLeft( r.right() - 7 );
6626
if( documentMode ) slabs << SlabRect( frameRect, TileSet::Left );
6627
else slabs << SlabRect( frameRect, TileSet::TopLeft );
6630
if( r.bottom() < tabBarRect.bottom() - 1 )
6633
QRect frameRect( r );
6634
frameRect.setTop( r.bottom() - 7 + 1 );
6635
if( hasRightCornerWidget && documentMode ) frameRect.setBottom( tabBarRect.bottom() + 7 - 1 );
6636
else frameRect.setBottom( tabBarRect.bottom() + 7 );
6637
frameRect.setLeft( r.right() - 7 );
6638
slabs << SlabRect( frameRect, TileSet::Left );
6645
// adjust sides when slab is adjacent to selected slab
6646
if( isLeftOfSelected ) tabRect.setBottom( tabRect.bottom() + 2 );
6647
else if( isRightOfSelected ) tabRect.setTop( tabRect.top() - 2 );
6652
tabRect.adjust( 0, GlowWidth, 0, 0 );
6653
if( isFrameAligned ) path.moveTo( tabRect.topRight() + QPoint( 2, 0 ) );
6654
else path.moveTo( tabRect.topRight() );
6655
path.lineTo( tabRect.topLeft() + QPointF( radius, 0 ) );
6656
path.quadTo( tabRect.topLeft(), tabRect.topLeft() + QPoint( 0, radius ) );
6657
path.lineTo( tabRect.bottomLeft() );
6658
path.lineTo( tabRect.bottomRight() );
6660
} else if( isLast ) {
6662
tabRect.adjust( 0, 0, 0, -GlowWidth );
6663
path.moveTo( tabRect.topRight() );
6664
path.lineTo( tabRect.topLeft() );
6665
path.lineTo( tabRect.bottomLeft() - QPointF( 0, radius ) );
6666
path.quadTo( tabRect.bottomLeft(), tabRect.bottomLeft() + QPointF( radius, 0 ) );
6667
path.lineTo( tabRect.bottomRight() );
6671
path.moveTo( tabRect.topRight() );
6672
path.lineTo( tabRect.topLeft() );
6673
path.lineTo( tabRect.bottomLeft() );
6674
path.lineTo( tabRect.bottomRight() );
6679
QRect highlightRect( tabRect.right()-1, tabRect.top(), 7, tabRect.height() );
6680
if( isFrameAligned && isFirst ) highlightSlab = SlabRect( highlightRect.adjusted( 0, -2, 0, 7 + 1 ), TileSet::TopLeft );
6681
else if( isFrameAligned && isLast ) highlightSlab = SlabRect( highlightRect.adjusted( 0, -7, 0, 2 ), TileSet::BottomLeft );
6682
else highlightSlab = SlabRect( highlightRect.adjusted( 0, -7 + 1, 0, 7 + 1 ), TileSet::Left );
6689
case QTabBar::RoundedEast:
6690
case QTabBar::TriangularEast:
6693
// larger tabs when selected
6694
if( selected ) tabRect.adjust( -2, 0, 1, 0 );
6695
else tabRect.adjust( 7 - 1, 0, -3, 1 );
6697
// connection to the main frame
6701
// reduces the space between tabs
6702
tabRect.adjust( 0, -GlowWidth,0,GlowWidth );
6704
// do nothing if dragged
6705
if( isDragged ) break;
6708
if( isFrameAligned )
6711
QRect frameRect( r );
6712
frameRect.setLeft( frameRect.left() - 7 + 1 );
6713
frameRect.setRight( tabRect.left() + 13 );
6714
frameRect.setTop( frameRect.top() - GlowWidth );
6715
frameRect.setBottom( tabRect.top() + 7 );
6716
slabs << SlabRect( frameRect, TileSet::Top );
6720
QRect frameRect( r );
6721
frameRect.setRight( r.left() + 7 );
6722
frameRect.setTop( frameRect.top() - 7 );
6723
frameRect.setBottom( tabRect.top() + 7 + 3 );
6724
slabs << SlabRect( frameRect, TileSet::Right );
6728
QRect frameRect( r );
6729
frameRect.setRight( r.left() + 7 );
6730
frameRect.setTop( tabRect.bottom() - 7 - 3 );
6731
frameRect.setBottom( frameRect.bottom() + 7 );
6732
slabs << SlabRect( frameRect, TileSet::Right );
6734
// extra base, to extend below tabbar buttons
6737
if( r.top() > tabBarRect.top() + 1 )
6740
QRect frameRect( r );
6741
frameRect.setTop( tabBarRect.top() - 7 + 1 );
6742
frameRect.setBottom( r.top() + 7 - 1 );
6743
frameRect.setRight( r.left() + 7 );
6744
if( documentMode ) slabs << SlabRect( frameRect, TileSet::Right );
6745
else slabs << SlabRect( frameRect, TileSet::TopRight );
6748
if( r.bottom() < tabBarRect.bottom() - 1 )
6751
QRect frameRect( r );
6752
frameRect.setTop( r.bottom() - 7 + 1 );
6753
if( hasRightCornerWidget && documentMode ) frameRect.setBottom( tabBarRect.bottom() + 7 - 1 );
6754
else frameRect.setBottom( tabBarRect.bottom() + 7 );
6755
frameRect.setRight( r.left() + 7 );
6756
slabs << SlabRect( frameRect, TileSet::Right );
6763
// adjust sides when slab is adjacent to selected slab
6764
if( isLeftOfSelected ) tabRect.setBottom( tabRect.bottom() + 2 );
6765
else if( isRightOfSelected ) tabRect.setTop( tabRect.top() - 2 );
6770
tabRect.adjust( 0, GlowWidth, 0, 0 );
6771
if( isFrameAligned ) path.moveTo( tabRect.topLeft() - QPoint( 2, 0 ) );
6772
else path.moveTo( tabRect.topLeft() );
6773
path.lineTo( tabRect.topRight() - QPointF( radius, 0 ) );
6774
path.quadTo( tabRect.topRight(), tabRect.topRight() + QPoint( 0, radius ) );
6775
path.lineTo( tabRect.bottomRight() );
6776
path.lineTo( tabRect.bottomLeft() );
6778
} else if( isLast ) {
6780
tabRect.adjust( 0, 0, 0, -GlowWidth );
6781
path.moveTo( tabRect.topLeft() );
6782
path.lineTo( tabRect.topRight() );
6783
path.lineTo( tabRect.bottomRight() - QPointF( 0, radius ) );
6784
path.quadTo( tabRect.bottomRight(), tabRect.bottomRight() - QPointF( radius, 0 ) );
6785
path.lineTo( tabRect.bottomLeft() );
6789
path.moveTo( tabRect.topLeft() );
6790
path.lineTo( tabRect.topRight() );
6791
path.lineTo( tabRect.bottomRight() );
6792
path.lineTo( tabRect.bottomLeft() );
6797
QRect highlightRect( tabRect.left()-5, tabRect.top(), 7, tabRect.height() );
6798
if( isFrameAligned && isFirst ) highlightSlab = SlabRect( highlightRect.adjusted( 0, -2, 0, 7 + 1 ), TileSet::TopRight );
6799
else if( isFrameAligned && isLast ) highlightSlab = SlabRect( highlightRect.adjusted( 0, -7, 0, 2 ), TileSet::BottomRight );
6800
else highlightSlab = SlabRect( highlightRect.adjusted( 0, -7 + 1, 0, 7 + 1 ), TileSet::Right );
6810
const QColor color( palette.color( QPalette::Window ) );
6812
// render connections to frame
6813
// extra care must be taken care of so that no slab
6814
// extends beyond tabWidget frame, if any
6815
const QRect tabWidgetRect( tabWidget ?
6816
insideMargin( tabWidget->rect(), -GlowWidth ).translated( -widget->geometry().topLeft() ) :
6819
foreach( SlabRect slab, slabs ) // krazy:exclude=foreach
6821
adjustSlabRect( slab, tabWidgetRect, documentMode, verticalTabs );
6822
renderSlab( painter, slab, color, NoFill );
6825
// adjust clip rect and render tab
6829
painter->setClipRegion( tabBarClipRegion( tabBar ) );
6836
// render window background in case of dragged tabwidget
6837
if( isDragged ) fillTabBackground( painter, tabRect, color, tabOpt->shape, widget );
6840
StyleOptions selectedTabOpts( NoFill );
6841
if( StyleConfigData::tabSubtleShadow() ) selectedTabOpts |= SubtleShadow;
6843
TileSet::Tiles tiles( tilesByShape( tabOpt->shape ) );
6844
renderSlab( painter, tabRect, color, selectedTabOpts, tiles );
6845
fillTab( painter, tabRect, color, tabOpt->shape, selected );
6849
const QColor backgroundColor = helper().backgroundColor( color, widget, r.center() );
6850
const QColor midColor = helper().alphaColor( helper().calcDarkColor( backgroundColor ), 0.4 );
6851
const QColor darkColor = helper().alphaColor( helper().calcDarkColor( backgroundColor ), 0.6 );
6854
painter->translate( 0.5, 0.5 );
6855
painter->setRenderHints( QPainter::Antialiasing );
6856
painter->setPen( darkColor );
6857
painter->setBrush( midColor );
6858
painter->drawPath( path );
6863
// restore clip region
6864
if( tabBar ) painter->restore();
6866
// hovered highlight
6867
if( ( animated || mouseOver ) && highlightSlab._r.isValid() )
6870
const qreal opacity( animations().tabBarEngine().opacity( widget, r.topLeft() ) );
6871
const StyleOptions hoverTabOpts( NoFill | Hover );
6872
adjustSlabRect( highlightSlab, tabWidgetRect, documentMode, verticalTabs );
6874
// pass an invalid color to have only the glow painted
6875
if( animated ) renderSlab( painter, highlightSlab, QColor(), hoverTabOpts, opacity, AnimationHover );
6876
else renderSlab( painter, highlightSlab, QColor(), hoverTabOpts );
6885
//___________________________________________________________________________________
6886
void Style::TabBarData::drawTabBarBaseControl( const QStyleOptionTab* tabOpt, QPainter* painter, const QWidget* widget )
6890
if( !_style ) return;
6892
// make sure widget is locked
6893
if( !locks( widget ) ) return;
6895
// make sure dirty flag is set
6896
if( !_dirty ) return;
6898
// cast to TabBar and check
6899
const QTabBar* tabBar( qobject_cast<const QTabBar*>( widget ) );
6900
if( !tabBar ) return;
6902
// get reverseLayout flag
6903
const bool reverseLayout( tabOpt->direction == Qt::RightToLeft );
6905
// get documentMode flag
6906
const QStyleOptionTabV3 *tabOptV3 = qstyleoption_cast<const QStyleOptionTabV3 *>( tabOpt );
6907
bool documentMode = tabOptV3 ? tabOptV3->documentMode : false;
6908
const QTabWidget *tabWidget = ( widget && widget->parentWidget() ) ? qobject_cast<const QTabWidget *>( widget->parentWidget() ) : NULL;
6909
documentMode |= ( tabWidget ? tabWidget->documentMode() : true );
6911
const QRect tabBarRect( _style.data()->insideMargin( tabBar->rect(), -GlowWidth ) );
6914
Style::SlabRect slab;
6916
// switch on tab shape
6917
switch( tabOpt->shape )
6919
case QTabBar::RoundedNorth:
6920
case QTabBar::TriangularNorth:
6922
TileSet::Tiles tiles( TileSet::Top );
6924
frameRect.setLeft( tabBarRect.left() - 7 + 1 );
6925
frameRect.setRight( tabBarRect.right() + 7 - 1 );
6926
frameRect.setTop( tabBarRect.bottom() - 8 );
6927
frameRect.setHeight( 4 );
6928
if( !( documentMode || reverseLayout ) ) tiles |= TileSet::Left;
6929
if( !documentMode && reverseLayout ) tiles |= TileSet::Right;
6930
slab = SlabRect( frameRect, tiles );
6934
case QTabBar::RoundedSouth:
6935
case QTabBar::TriangularSouth:
6937
TileSet::Tiles tiles( TileSet::Bottom );
6939
frameRect.setLeft( tabBarRect.left() - 7 + 1 );
6940
frameRect.setRight( tabBarRect.right() + 7 - 1 );
6941
frameRect.setBottom( tabBarRect.top() + 8 );
6942
frameRect.setTop( frameRect.bottom() - 4 );
6943
if( !( documentMode || reverseLayout ) ) tiles |= TileSet::Left;
6944
if( !documentMode && reverseLayout ) tiles |= TileSet::Right;
6945
slab = SlabRect( frameRect, tiles );
6949
case QTabBar::RoundedWest:
6950
case QTabBar::TriangularWest:
6952
TileSet::Tiles tiles( TileSet::Left );
6954
frameRect.setTop( tabBarRect.top() - 7 + 1 );
6955
frameRect.setBottom( tabBarRect.bottom() + 7 - 1 );
6956
frameRect.setLeft( tabBarRect.right() - 8 );
6957
frameRect.setWidth( 4 );
6958
if( !( documentMode || reverseLayout ) ) tiles |= TileSet::Top;
6959
if( !documentMode && reverseLayout ) tiles |= TileSet::Bottom;
6960
slab = SlabRect( frameRect, tiles );
6964
case QTabBar::RoundedEast:
6965
case QTabBar::TriangularEast:
6967
TileSet::Tiles tiles( TileSet::Right );
6969
frameRect.setTop( tabBarRect.top() - 7 + 1 );
6970
frameRect.setBottom( tabBarRect.bottom() + 7 - 1 );
6971
frameRect.setRight( tabBarRect.left() + 8 );
6972
frameRect.setLeft( frameRect.right() - 4 );
6973
if( !( documentMode || reverseLayout ) ) tiles |= TileSet::Top;
6974
if( !documentMode && reverseLayout ) tiles |= TileSet::Bottom;
6975
slab = SlabRect( frameRect, tiles );
6983
const bool verticalTabs( _style.data()->isVerticalTab( tabOpt ) );
6984
const QRect tabWidgetRect( tabWidget ?
6985
_style.data()->insideMargin( tabWidget->rect(), -GlowWidth ).translated( -widget->geometry().topLeft() ) :
6988
const QPalette& palette( tabOpt->palette );
6989
const QColor color( palette.color( QPalette::Window ) );
6990
_style.data()->adjustSlabRect( slab, tabWidgetRect, documentMode, verticalTabs );
6991
_style.data()->renderSlab( painter, slab, color, NoFill );
6998
//___________________________________________________________________________________
6999
bool Style::drawToolBarControl( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
7002
const QRect& r( option->rect );
7004
// when timeLine is running draw border event if not hovered
7005
const bool toolBarAnimated( animations().toolBarEngine().isFollowMouseAnimated( widget ) );
7006
const QRect animatedRect( animations().toolBarEngine().animatedRect( widget ) );
7007
const bool toolBarIntersected( toolBarAnimated && animatedRect.intersects( r ) );
7008
if( toolBarIntersected )
7009
{ helper().slitFocused( helper().viewFocusBrush().brush( QPalette::Active ).color() )->render( animatedRect, painter ); }
7011
// draw nothing otherwise ( toolbars are transparent )
7017
//___________________________________________________________________________________
7018
bool Style::drawToolBoxTabLabelControl( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
7021
const QStyleOptionToolBox* toolBoxOption( qstyleoption_cast<const QStyleOptionToolBox *>( option ) );
7022
const bool enabled( toolBoxOption->state & State_Enabled );
7023
const bool selected( toolBoxOption->state & State_Selected );
7025
toolBoxOption->icon.pixmap( pixelMetric( QStyle::PM_SmallIconSize, toolBoxOption, widget ),
7026
enabled ? QIcon::Normal : QIcon::Disabled ) );
7028
const QRect cr( toolBoxTabContentsRect( toolBoxOption, widget ) );
7033
if( pm.isNull() ) tr = cr.adjusted( -1, 0, -8, 0 );
7036
int iw = pm.width() + 4;
7038
ir = QRect( cr.left() - 1, cr.top(), iw + 2, ih );
7039
tr = QRect( ir.right(), cr.top(), cr.width() - ir.right() - 4, cr.height() );
7045
QFont f( painter->font() );
7047
painter->setFont( f );
7050
QString txt( toolBoxOption->fontMetrics.elidedText( toolBoxOption->text, Qt::ElideRight, tr.width() ) );
7052
if( ih ) painter->drawPixmap( ir.left(), ( toolBoxOption->rect.height() - ih ) / 2, pm );
7054
int alignment( Qt::AlignLeft | Qt::AlignVCenter | Qt::TextShowMnemonic );
7055
drawItemText( painter, tr, alignment, toolBoxOption->palette, enabled, txt, QPalette::WindowText );
7060
//___________________________________________________________________________________
7061
bool Style::drawToolBoxTabShapeControl( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
7064
const QRect& r( option->rect );
7065
const QPalette& palette( option->palette );
7066
const State& flags( option->state );
7068
const bool enabled( flags&State_Enabled );
7069
const bool selected( flags&State_Selected );
7070
const bool mouseOver( enabled && !selected && ( flags&State_MouseOver ) );
7071
const bool reverseLayout( option->direction == Qt::RightToLeft );
7074
// cast to v2 and disable paint is tab is first
7075
const QStyleOptionToolBoxV2 *v2 = qstyleoption_cast<const QStyleOptionToolBoxV2 *>( option );
7076
if( v2 && v2->position == QStyleOptionToolBoxV2::Beginning && selected ) return true;
7079
the proper widget ( the toolbox tab ) is not passed as argument by Qt.
7080
What is passed is the toolbox directly. To implement animations properly,
7081
the painter->device() is used instead
7083
bool animated( false );
7084
qreal opacity( AnimationData::OpacityInvalid );
7087
// try retrieve button from painter device.
7088
if( QPaintDevice* device = painter->device() )
7090
animations().toolBoxEngine().updateState( device, mouseOver );
7091
animated = animations().toolBoxEngine().isAnimated( device );
7092
opacity = animations().toolBoxEngine().opacity( device );
7097
// save colors for shadow
7098
/* important: option returns a wrong color. We use the widget's palette when widget is set */
7099
const QColor color( widget ? widget->palette().color( widget->backgroundRole() ) : palette.color( QPalette::Window ) );
7100
const QColor dark( helper().calcDarkColor( color ) );
7101
QList<QColor> colors;
7102
colors.push_back( helper().calcLightColor( color ) );
7104
if( mouseOver || animated )
7107
QColor highlight = helper().viewHoverBrush().brush( palette ).color();
7111
colors.push_back( KColorUtils::mix( dark, highlight, opacity ) );
7112
colors.push_back( helper().alphaColor( highlight, 0.2*opacity ) );
7116
colors.push_back( highlight );
7117
colors.push_back( helper().alphaColor( highlight, 0.2 ) );
7121
} else colors.push_back( dark );
7126
const int y( r.height()*15/100 );
7130
path.moveTo( r.left()+52, r.top() );
7131
path.cubicTo( QPointF( r.left()+50-8, r.top() ), QPointF( r.left()+50-10, r.top()+y ), QPointF( r.left()+50-10, r.top()+y ) );
7132
path.lineTo( r.left()+18+9, r.bottom()-y );
7133
path.cubicTo( QPointF( r.left()+18+9, r.bottom()-y ), QPointF( r.left()+19+6, r.bottom()-1-0.3 ), QPointF( r.left()+19, r.bottom()-1-0.3 ) );
7134
painter->setClipRect( QRect( r.left()+21, r.top(), 28, r.height() ) );
7138
path.moveTo( r.right()-52, r.top() );
7139
path.cubicTo( QPointF( r.right()-50+8, r.top() ), QPointF( r.right()-50+10, r.top()+y ), QPointF( r.right()-50+10, r.top()+y ) );
7140
path.lineTo( r.right()-18-9, r.bottom()-y );
7141
path.cubicTo( QPointF( r.right()-18-9, r.bottom()-y ), QPointF( r.right()-19-6, r.bottom()-1-0.3 ), QPointF( r.right()-19, r.bottom()-1-0.3 ) );
7142
painter->setClipRect( QRect( r.right()-48, r.top(), 32, r.height() ) );
7148
painter->setRenderHint( QPainter::Antialiasing, true );
7149
painter->translate( 0,2 );
7150
foreach( const QColor& color, colors )
7152
painter->setPen( color );
7153
painter->drawPath( path );
7154
painter->translate( 0,-1 );
7159
painter->setRenderHint( QPainter::Antialiasing, false );
7160
painter->translate( 0,2 );
7161
foreach( const QColor& color, colors )
7163
painter->setPen( color );
7164
if( reverseLayout ) {
7165
painter->drawLine( r.left()+50-1, r.top(), r.right(), r.top() );
7166
painter->drawLine( r.left()+20, r.bottom()-2, r.left(), r.bottom()-2 );
7168
painter->drawLine( r.left(), r.top(), r.right()-50+1, r.top() );
7169
painter->drawLine( r.right()-20, r.bottom()-2, r.right(), r.bottom()-2 );
7171
painter->translate( 0,-1 );
7179
//___________________________________________________________________________________
7180
bool Style::drawToolButtonLabelControl( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
7183
// need to customize palettes to deal with autoraised buttons
7184
const State& flags( option->state );
7186
// normal processing if not autoRaised
7187
if( flags & State_AutoRaise )
7190
const QStyleOptionToolButton* toolButtonOpt( qstyleoption_cast<const QStyleOptionToolButton*>( option ) );
7191
if( !toolButtonOpt ) return true;
7193
QStyleOptionToolButton localOption( *toolButtonOpt );
7194
localOption.palette.setColor( QPalette::ButtonText, option->palette.color( QPalette::WindowText ) );
7196
QCommonStyle::drawControl( CE_ToolButtonLabel, &localOption, painter, widget );
7200
QCommonStyle::drawControl( CE_ToolButtonLabel, option, painter, widget );
7208
//______________________________________________________________
7209
bool Style::drawComboBoxComplexControl( const QStyleOptionComplex* option, QPainter* painter, const QWidget* widget ) const
7212
// cast option and check
7213
const QStyleOptionComboBox* cb( qstyleoption_cast<const QStyleOptionComboBox *>( option ) );
7214
if( !cb ) return true;
7216
const State& flags( option->state );
7217
const QRect& r( option->rect );
7218
const QPalette& palette( option->palette );
7219
const bool enabled( flags & State_Enabled );
7220
const bool mouseOver( enabled && ( flags & State_MouseOver ) );
7221
const bool hasFocus( flags & State_HasFocus );
7222
const bool& editable( cb->editable );
7223
const bool& hasFrame( cb->frame );
7226
if( cb->subControls & SC_ComboBoxFrame )
7231
StyleOptions opts = 0;
7232
if( mouseOver ) opts |= Hover;
7233
if( hasFocus ) opts |= Focus;
7234
if( ( flags & ( State_Sunken|State_On ) ) && !editable ) opts |= Sunken;
7236
const QColor inputColor( palette.color( QPalette::Base ) );
7237
const QRect editField( subControlRect( CC_ComboBox, cb, SC_ComboBoxEditField, widget ) );
7242
// editable combobox. Make it look like a LineEdit
7243
// focus takes precedence over hover
7244
animations().lineEditEngine().updateState( widget, AnimationFocus, hasFocus );
7245
animations().lineEditEngine().updateState( widget, AnimationHover, mouseOver && !hasFocus );
7247
const QRect fr( r.adjusted( 1,1,-1,-1 ) );
7251
painter->setRenderHint( QPainter::Antialiasing );
7252
painter->setPen( Qt::NoPen );
7253
painter->setBrush( inputColor );
7258
// adjust rect to match frameLess editors
7259
painter->fillRect( r, inputColor );
7264
helper().fillHole( *painter, r.adjusted( 0, -1, 0, 0 ) );
7267
HoleOptions options( 0 );
7268
if( hasFocus && enabled ) options |= HoleFocus;
7269
if( mouseOver && enabled ) options |= HoleHover;
7271
const QColor color( palette.color( QPalette::Window ) );
7272
if( enabled && animations().lineEditEngine().isAnimated( widget, AnimationFocus ) )
7275
helper().renderHole( painter, color, fr, options, animations().lineEditEngine().opacity( widget, AnimationFocus ), AnimationFocus, TileSet::Ring );
7277
} else if( enabled && animations().lineEditEngine().isAnimated( widget, AnimationHover ) ) {
7279
helper().renderHole( painter, color, fr, options, animations().lineEditEngine().opacity( widget, AnimationHover ), AnimationHover, TileSet::Ring );
7283
helper().renderHole( painter, color, fr, options );
7291
// non editable combobox. Make it look like a PushButton
7292
// hover takes precedence over focus
7293
animations().lineEditEngine().updateState( widget, AnimationHover, mouseOver );
7294
animations().lineEditEngine().updateState( widget, AnimationFocus, hasFocus && !mouseOver );
7296
// store animation state
7297
const bool hoverAnimated( animations().lineEditEngine().isAnimated( widget, AnimationHover ) );
7298
const bool focusAnimated( animations().lineEditEngine().isAnimated( widget, AnimationFocus ) );
7299
const qreal hoverOpacity( animations().lineEditEngine().opacity( widget, AnimationHover ) );
7300
const qreal focusOpacity( animations().lineEditEngine().opacity( widget, AnimationFocus ) );
7302
// blend button color to the background
7303
const QColor buttonColor( helper().backgroundColor( palette.color( QPalette::Button ), widget, r.center() ) );
7304
const QRect slabRect( r.adjusted( -1, 0, 1, 0 ) );
7309
QRect slitRect( r );
7310
if( !( opts & Sunken ) )
7313
if( enabled && hoverAnimated )
7316
QColor glow( helper().alphaColor( helper().viewFocusBrush().brush( QPalette::Active ).color(), hoverOpacity ) );
7317
helper().slitFocused( glow )->render( slitRect, painter );
7319
} else if( mouseOver ) {
7321
helper().slitFocused( helper().viewFocusBrush().brush( QPalette::Active ).color() )->render( slitRect, painter );
7327
slitRect.adjust( 0, 0, 0, -1 );
7329
HoleOptions options( HoleContrast );
7330
if( mouseOver && enabled ) options |= HoleHover;
7332
// flat pressed-down buttons do not get focus effect,
7333
// consistently with tool buttons
7334
if( enabled && hoverAnimated )
7337
helper().renderHole( painter, palette.color( QPalette::Window ), slitRect, options, hoverOpacity, AnimationHover, TileSet::Ring );
7341
helper().renderHole( painter, palette.color( QPalette::Window ), slitRect, options );
7349
if( enabled && hoverAnimated )
7352
renderButtonSlab( painter, slabRect, buttonColor, opts, hoverOpacity, AnimationHover, TileSet::Ring );
7354
} else if( enabled && focusAnimated ) {
7356
renderButtonSlab( painter, slabRect, buttonColor, opts, focusOpacity, AnimationFocus, TileSet::Ring );
7360
renderButtonSlab( painter, slabRect, buttonColor, opts );
7370
if( cb->subControls & SC_ComboBoxArrow )
7373
const QComboBox* comboBox = qobject_cast<const QComboBox*>( widget );
7374
const bool empty( comboBox && !comboBox->count() );
7378
bool drawContrast( true );
7383
if( enabled && empty ) color = palette.color( QPalette::Disabled, QPalette::Text );
7386
// check animation state
7387
const bool subControlHover( enabled && mouseOver && cb->activeSubControls&SC_ComboBoxArrow );
7388
animations().comboBoxEngine().updateState( widget, AnimationHover, subControlHover );
7390
const bool animated( enabled && animations().comboBoxEngine().isAnimated( widget, AnimationHover ) );
7391
const qreal opacity( animations().comboBoxEngine().opacity( widget, AnimationHover ) );
7396
QColor highlight = helper().viewHoverBrush().brush( palette ).color();
7397
color = KColorUtils::mix( palette.color( QPalette::Text ), highlight, opacity );
7399
} else if( subControlHover ) {
7401
color = helper().viewHoverBrush().brush( palette ).color();
7405
color = palette.color( QPalette::Text );
7411
background = palette.color( QPalette::Background );
7413
if( enabled ) drawContrast = false;
7418
const QPalette::ColorRole role( hasFrame ? QPalette::ButtonText : QPalette::WindowText );
7419
if( enabled && empty ) color = palette.color( QPalette::Disabled, role );
7420
else color = palette.color( role );
7423
background = palette.color( hasFrame ? QPalette::Button : QPalette::Window );
7428
QRect arrowRect = comboBoxSubControlRect( option, SC_ComboBoxArrow, widget );
7430
const QPolygonF a( genericArrow( ArrowDown, ArrowNormal ) );
7431
const qreal penThickness = 1.6;
7434
painter->translate( arrowRect.center() );
7435
painter->setRenderHint( QPainter::Antialiasing );
7440
const qreal offset( qMin( penThickness, qreal( 1.0 ) ) );
7441
painter->translate( 0,offset );
7442
painter->setPen( QPen( helper().calcLightColor( palette.color( QPalette::Window ) ), penThickness, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) );
7443
painter->drawPolyline( a );
7444
painter->translate( 0,-offset );
7448
painter->setPen( QPen( helper().decoColor( background, color ) , penThickness, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) );
7449
painter->drawPolyline( a );
7458
//______________________________________________________________
7459
bool Style::drawDialComplexControl( const QStyleOptionComplex* option, QPainter* painter, const QWidget* widget ) const
7462
const State& flags( option->state );
7463
const bool enabled = flags & State_Enabled;
7464
const bool mouseOver( enabled && ( flags & State_MouseOver ) );
7465
const bool hasFocus( enabled && ( flags & State_HasFocus ) );
7466
const bool sunken( flags & ( State_On|State_Sunken ) );
7468
StyleOptions opts = 0;
7469
if( sunken ) opts |= Sunken;
7470
if( hasFocus ) opts |= Focus;
7471
if( mouseOver ) opts |= Hover;
7473
// mouseOver has precedence over focus
7474
animations().widgetStateEngine().updateState( widget, AnimationHover, mouseOver );
7475
animations().widgetStateEngine().updateState( widget, AnimationFocus, hasFocus && !mouseOver );
7477
const QRect rect( option->rect );
7478
const QPalette &palette( option->palette );
7479
const QColor buttonColor( helper().backgroundColor( palette.color( QPalette::Button ), widget, rect.center() ) );
7481
if( enabled && animations().widgetStateEngine().isAnimated( widget, AnimationHover ) && !( opts & Sunken ) )
7484
qreal opacity( animations().widgetStateEngine().opacity( widget, AnimationHover ) );
7485
renderDialSlab( painter, rect, buttonColor, option, opts, opacity, AnimationHover );
7487
} else if( enabled && !mouseOver && animations().widgetStateEngine().isAnimated( widget, AnimationFocus ) && !( opts & Sunken ) ) {
7489
qreal opacity( animations().widgetStateEngine().opacity( widget, AnimationFocus ) );
7490
renderDialSlab( painter, rect, buttonColor, option, opts, opacity, AnimationFocus );
7494
renderDialSlab( painter, rect, buttonColor, option, opts );
7502
//______________________________________________________________
7503
bool Style::drawGroupBoxComplexControl( const QStyleOptionComplex* option, QPainter* painter, const QWidget* widget ) const
7505
const QStyleOptionGroupBox *groupBox = qstyleoption_cast<const QStyleOptionGroupBox *>( option );
7506
if( groupBox && groupBox->features & QStyleOptionFrameV2::Flat )
7509
// for flat groupboxes, the groupBox title is rendered bold
7511
TODO: talk to pinheiro. This is not an optimal design
7513
1/ keep the font unchanged
7514
2/ add an horizontal separator next to the title
7517
const QFont oldFont = painter->font();
7518
QFont font = oldFont;
7519
font.setBold( true );
7520
painter->setFont( font );
7521
QCommonStyle::drawComplexControl( CC_GroupBox, option, painter, widget );
7522
painter->setFont( oldFont );
7525
} else return false;
7528
//______________________________________________________________
7529
bool Style::drawQ3ListViewComplexControl( const QStyleOptionComplex* option, QPainter* painter, const QWidget* widget ) const
7532
const QStyleOptionQ3ListView* optListView( qstyleoption_cast<const QStyleOptionQ3ListView*>( option ) );
7533
if( !optListView ) return true;
7535
// this is copied from skulpture code
7536
// Copyright ( c ) 2007-2010 Christoph Feck <christoph@maxiom.de>
7537
if( optListView->subControls & QStyle::SC_Q3ListView )
7541
optListView->viewportPalette.brush( optListView->viewportBGRole ) );
7544
if( optListView->subControls & QStyle::SC_Q3ListViewBranch )
7547
QStyleOption opt = *static_cast<const QStyleOption*>( option );
7548
int y = optListView->rect.y();
7550
for ( int i = 1; i < optListView->items.size(); ++i )
7552
QStyleOptionQ3ListViewItem item = optListView->items.at( i );
7553
if( y + item.totalHeight > 0 && y < optListView->rect.height() )
7555
opt.state = QStyle::State_Item;
7556
if ( i + 1 < optListView->items.size() )
7557
{ opt.state |= QStyle::State_Sibling; }
7560
item.features & QStyleOptionQ3ListViewItem::Expandable
7561
|| ( item.childCount > 0 && item.height > 0 ) )
7562
{ opt.state |= QStyle::State_Children | ( item.state & QStyle::State_Open ); }
7564
opt.rect = QRect( optListView->rect.left(), y, optListView->rect.width(), item.height );
7565
drawIndicatorBranchPrimitive( &opt, painter, widget );
7567
if( ( opt.state & QStyle::State_Sibling ) && item.height < item.totalHeight )
7569
opt.state = QStyle::State_Sibling;
7571
optListView->rect.left(), y + item.height,
7572
optListView->rect.width(), item.totalHeight - item.height );
7573
drawIndicatorBranchPrimitive( &opt, painter, widget );
7577
y += item.totalHeight;
7585
//______________________________________________________________
7586
bool Style::drawSliderComplexControl( const QStyleOptionComplex* option, QPainter* painter, const QWidget* widget ) const
7588
const QStyleOptionSlider *slider( qstyleoption_cast<const QStyleOptionSlider *>( option ) );
7589
if( !slider ) return true;
7591
const QPalette& palette( option->palette );
7592
const State& flags( option->state );
7593
const bool enabled( flags & State_Enabled );
7594
const bool mouseOver( enabled && ( flags & State_MouseOver ) );
7595
const bool hasFocus( flags & State_HasFocus );
7597
if( slider->subControls & SC_SliderTickmarks ) { renderSliderTickmarks( painter, slider, widget ); }
7600
if( slider->subControls & SC_SliderGroove )
7602
const QRect groove = sliderSubControlRect( slider, SC_SliderGroove, widget );
7603
const Qt::Orientation orientation( groove.width() > groove.height() ? Qt::Horizontal : Qt::Vertical );
7604
if( groove.isValid() ) helper().scrollHole( palette.color( QPalette::Window ), orientation, true )->render( groove, painter, TileSet::Full );
7608
if ( slider->subControls & SC_SliderHandle )
7610
const QRect handle = sliderSubControlRect( slider, SC_SliderHandle, widget );
7611
const QRect r = centerRect( handle, 21, 21 );
7613
const bool handleActive( slider->activeSubControls & SC_SliderHandle );
7614
StyleOptions opts( 0 );
7615
if( hasFocus ) opts |= Focus;
7616
if( handleActive && mouseOver ) opts |= Hover;
7618
animations().sliderEngine().updateState( widget, enabled && handleActive );
7619
const qreal opacity( animations().sliderEngine().opacity( widget ) );
7621
const QColor color( helper().backgroundColor( palette.color( QPalette::Button ), widget, handle.center() ) );
7622
const QColor glow( slabShadowColor( color, opts, opacity, AnimationHover ) );
7624
const bool sunken( flags & (State_On|State_Sunken) );
7625
painter->drawPixmap( r.topLeft(), helper().sliderSlab( color, glow, sunken, 0.0 ) );
7632
//______________________________________________________________
7633
bool Style::drawSpinBoxComplexControl( const QStyleOptionComplex* option, QPainter* painter, const QWidget* widget ) const
7635
const QStyleOptionSpinBox *sb = qstyleoption_cast<const QStyleOptionSpinBox *>( option );
7636
if( !sb ) return true;
7638
const QRect& r( option->rect );
7639
const QPalette& palette( option->palette );
7641
const State& flags( option->state );
7642
const bool enabled( flags & State_Enabled );
7643
const bool mouseOver( enabled && ( flags & State_MouseOver ) );
7644
const bool hasFocus( flags & State_HasFocus );
7645
const QColor inputColor( palette.color( QPalette::Base ) );
7647
if( sb->subControls & SC_SpinBoxFrame )
7650
QRect fr( r.adjusted( 1,1,-1,-1 ) );
7652
painter->setRenderHint( QPainter::Antialiasing );
7653
painter->setPen( Qt::NoPen );
7654
painter->setBrush( inputColor );
7658
// frameless spinbox
7659
// frame is adjusted to have the same dimensions as a frameless editor
7660
painter->fillRect( r, inputColor );
7666
helper().fillHole( *painter, r.adjusted( 0, -1, 0, 0 ) );
7669
HoleOptions options( 0 );
7670
if( hasFocus && enabled ) options |= HoleFocus;
7671
if( mouseOver && enabled ) options |= HoleHover;
7673
QColor local( palette.color( QPalette::Window ) );
7674
animations().lineEditEngine().updateState( widget, AnimationHover, mouseOver );
7675
animations().lineEditEngine().updateState( widget, AnimationFocus, hasFocus );
7676
if( enabled && animations().lineEditEngine().isAnimated( widget, AnimationFocus ) )
7679
helper().renderHole( painter, local, fr, options, animations().lineEditEngine().opacity( widget, AnimationFocus ), AnimationFocus, TileSet::Ring );
7681
} else if( enabled && animations().lineEditEngine().isAnimated( widget, AnimationHover ) ) {
7683
helper().renderHole( painter, local, fr, options, animations().lineEditEngine().opacity( widget, AnimationHover ), AnimationHover, TileSet::Ring );
7687
helper().renderHole( painter, local, fr, options );
7694
if( sb->subControls & SC_SpinBoxUp ) renderSpinBoxArrow( painter, sb, widget, SC_SpinBoxUp );
7695
if( sb->subControls & SC_SpinBoxDown ) renderSpinBoxArrow( painter, sb, widget, SC_SpinBoxDown );
7701
//______________________________________________________________
7702
bool Style::drawTitleBarComplexControl( const QStyleOptionComplex* option, QPainter* painter, const QWidget* widget ) const
7704
const QStyleOptionTitleBar *tb( qstyleoption_cast<const QStyleOptionTitleBar *>( option ) );
7705
if( !tb ) return true;
7707
const State& flags( option->state );
7708
const bool enabled( flags & State_Enabled );
7709
const bool active( enabled && ( tb->titleBarState & Qt::WindowActive ) );
7713
QRect textRect = subControlRect( CC_TitleBar, tb, SC_TitleBarLabel, widget );
7715
// enable state transition
7716
animations().widgetEnabilityEngine().updateState( widget, AnimationEnable, active );
7718
// make sure palette has the correct color group
7719
QPalette palette( option->palette );
7721
if( animations().widgetEnabilityEngine().isAnimated( widget, AnimationEnable ) )
7722
{ palette = helper().mergePalettes( palette, animations().widgetEnabilityEngine().opacity( widget, AnimationEnable ) ); }
7724
palette.setCurrentColorGroup( active ? QPalette::Active: QPalette::Disabled );
7725
QCommonStyle::drawItemText( painter, textRect, Qt::AlignCenter, palette, active, tb->text, QPalette::WindowText );
7731
if( ( tb->subControls & SC_TitleBarSysMenu ) && ( tb->titleBarFlags & Qt::WindowSystemMenuHint ) && !tb->icon.isNull() )
7734
const QRect br = subControlRect( CC_TitleBar, tb, SC_TitleBarSysMenu, widget );
7735
tb->icon.paint( painter, br );
7739
if( ( tb->subControls & SC_TitleBarMinButton ) && ( tb->titleBarFlags & Qt::WindowMinimizeButtonHint ) )
7740
{ renderTitleBarButton( painter, tb, widget, SC_TitleBarMinButton ); }
7742
if( ( tb->subControls & SC_TitleBarMaxButton ) && ( tb->titleBarFlags & Qt::WindowMaximizeButtonHint ) )
7743
{ renderTitleBarButton( painter, tb, widget, SC_TitleBarMaxButton ); }
7745
if( ( tb->subControls & SC_TitleBarCloseButton ) )
7746
{ renderTitleBarButton( painter, tb, widget, SC_TitleBarCloseButton ); }
7748
if( ( tb->subControls & SC_TitleBarNormalButton ) &&
7749
( ( ( tb->titleBarFlags & Qt::WindowMinimizeButtonHint ) &&
7750
( tb->titleBarState & Qt::WindowMinimized ) ) ||
7751
( ( tb->titleBarFlags & Qt::WindowMaximizeButtonHint ) &&
7752
( tb->titleBarState & Qt::WindowMaximized ) ) ) )
7753
{ renderTitleBarButton( painter, tb, widget, SC_TitleBarNormalButton ); }
7755
if( tb->subControls & SC_TitleBarShadeButton )
7756
{ renderTitleBarButton( painter, tb, widget, SC_TitleBarShadeButton ); }
7758
if( tb->subControls & SC_TitleBarUnshadeButton )
7759
{ renderTitleBarButton( painter, tb, widget, SC_TitleBarUnshadeButton ); }
7761
if( ( tb->subControls & SC_TitleBarContextHelpButton ) && ( tb->titleBarFlags & Qt::WindowContextHelpButtonHint ) )
7762
{ renderTitleBarButton( painter, tb, widget, SC_TitleBarContextHelpButton ); }
7768
//______________________________________________________________
7769
bool Style::drawToolButtonComplexControl( const QStyleOptionComplex* option, QPainter* painter, const QWidget* widget ) const
7772
// check autoRaise state
7773
const State flags( option->state );
7774
const bool isInToolBar( widget && qobject_cast<QToolBar*>( widget->parent() ) );
7776
// get rect and palette
7777
const QRect& rect( option->rect );
7778
const QStyleOptionToolButton *tool( qstyleoption_cast<const QStyleOptionToolButton *>( option ) );
7779
if( !tool ) return true;
7781
const bool enabled( flags & State_Enabled );
7782
const bool mouseOver( enabled && ( flags & State_MouseOver ) );
7783
const bool hasFocus( enabled && ( flags&State_HasFocus ) );
7784
const bool sunken( flags & ( State_Sunken|State_On ) );
7789
animations().widgetStateEngine().updateState( widget, AnimationHover, mouseOver );
7793
// mouseOver has precedence over focus
7794
animations().widgetStateEngine().updateState( widget, AnimationHover, mouseOver );
7795
animations().widgetStateEngine().updateState( widget, AnimationFocus, hasFocus&&!mouseOver );
7799
// toolbar animation
7800
QWidget* parent( widget ? widget->parentWidget():0 );
7801
const bool toolBarAnimated( isInToolBar && animations().toolBarEngine().isAnimated( parent ) );
7802
const QRect animatedRect( animations().toolBarEngine().animatedRect( parent ) );
7803
const QRect currentRect( animations().toolBarEngine().currentRect( parent ) );
7804
const bool current( isInToolBar && currentRect.intersects( rect.translated( widget->mapToParent( QPoint( 0,0 ) ) ) ) );
7805
const bool toolBarTimerActive( isInToolBar && animations().toolBarEngine().isTimerActive( widget->parentWidget() ) );
7807
// normal toolbutton animation
7808
const bool hoverAnimated( animations().widgetStateEngine().isAnimated( widget, AnimationHover ) );
7809
const bool focusAnimated( animations().widgetStateEngine().isAnimated( widget, AnimationFocus ) );
7811
/* FIXME: this all logic is messy. The conditions to trigger the call to drawPrimitive can likely be simplified */
7813
// local copy of option
7814
QStyleOptionToolButton tOpt( *tool );
7815
tOpt.palette = option->palette;
7817
const QRect buttonRect( subControlRect( CC_ToolButton, tool, SC_ToolButton, widget ) );
7820
if( enabled && !( mouseOver || hasFocus || sunken ) )
7823
if( hoverAnimated || ( focusAnimated && !hasFocus ) || ( ( ( toolBarAnimated && animatedRect.isNull() )||toolBarTimerActive ) && current ) )
7825
tOpt.rect = buttonRect;
7827
drawPanelButtonToolPrimitive( &tOpt, painter, widget );
7833
// State_AutoRaise: only draw button when State_MouseOver
7834
State bflags = tool->state;
7835
if( bflags & State_AutoRaise && !( bflags & State_MouseOver ) )
7836
{ bflags &= ~State_Raised; }
7838
tOpt.state = bflags;
7840
if( tool->subControls & SC_ToolButton && ( bflags & ( State_Sunken | State_On | State_Raised ) ) && !drawn )
7842
tOpt.rect = buttonRect;
7843
drawPanelButtonToolPrimitive( &tOpt, painter, widget );
7846
if( tool->subControls & SC_ToolButtonMenu )
7849
tOpt.rect = subControlRect( CC_ToolButton, tool, SC_ToolButtonMenu, widget );
7851
drawIndicatorButtonDropDownPrimitive( &tOpt, painter, widget );
7854
} else if( tool->features & QStyleOptionToolButton::HasMenu ) {
7856
// This is requesting KDE3-style arrow indicator, per Qt 4.4 behavior. Qt 4.3 prefers to hide
7857
// the fact of the menu's existence. Whee! Since we don't know how to paint this right,
7858
// though, we have to have some metrics set for it to look nice.
7859
const int size( ToolButton_InlineMenuIndicatorSize );
7863
const int xOff( ToolButton_InlineMenuIndicatorXOff );
7864
const int yOff( ToolButton_InlineMenuIndicatorYOff );
7866
tOpt.rect = QRect( buttonRect.right() + xOff + 1, buttonRect.bottom() + yOff + 1, size, size );
7868
drawIndicatorButtonDropDownPrimitive( &tOpt, painter, widget );
7875
// CE_ToolButtonLabel expects a readjusted rect, for the button area proper
7876
QStyleOptionToolButton labelOpt = *tool;
7877
labelOpt.rect = buttonRect;
7878
drawToolButtonLabelControl( &labelOpt, painter, widget );
7884
//_____________________________________________________________________
7885
void Style::oxygenConfigurationChanged( void )
7888
// reset helper configuration
7889
helper().reloadConfig();
7891
// background pixmap
7892
helper().setBackgroundPixmap( StyleConfigData::backgroundPixmap() );
7895
StyleConfigData::self()->readConfig();
7897
// update caches size
7898
int cacheSize( StyleConfigData::cacheEnabled() ?
7899
StyleConfigData::maxCacheSize():0 );
7901
helper().setMaxCacheSize( cacheSize );
7903
// reinitialize engines
7904
animations().setupEngines();
7905
transitions().setupEngines();
7906
windowManager().initialize();
7907
shadowHelper().reloadConfig();
7910
widgetExplorer().setEnabled( StyleConfigData::widgetExplorerEnabled() );
7911
widgetExplorer().setDrawWidgetRects( StyleConfigData::drawWidgetRects() );
7913
// scrollbar button dimentions.
7914
/* it has to be reinitialized here because scrollbar width might have changed */
7915
_noButtonHeight = 0;
7916
_singleButtonHeight = qMax( StyleConfigData::scrollBarWidth() * 7 / 10, 14 );
7917
_doubleButtonHeight = 2*_singleButtonHeight;
7919
_showMnemonics = StyleConfigData::showMnemonics();
7921
// scrollbar buttons
7922
switch( StyleConfigData::scrollBarAddLineButtons() )
7924
case 0: _addLineButtons = NoButton; break;
7925
case 1: _addLineButtons = SingleButton; break;
7928
case 2: _addLineButtons = DoubleButton; break;
7931
switch( StyleConfigData::scrollBarSubLineButtons() )
7933
case 0: _subLineButtons = NoButton; break;
7934
case 1: _subLineButtons = SingleButton; break;
7937
case 2: _subLineButtons = DoubleButton; break;
7941
switch( StyleConfigData::tabStyle() )
7943
case StyleConfigData::TS_PLAIN:
7944
_tabBarTabShapeControl = &Style::drawTabBarTabShapeControl_Plain;
7948
case StyleConfigData::TS_SINGLE:
7949
_tabBarTabShapeControl = &Style::drawTabBarTabShapeControl_Single;
7954
if( StyleConfigData::viewDrawFocusIndicator() ) _frameFocusPrimitive = &Style::drawFrameFocusRectPrimitive;
7955
else _frameFocusPrimitive = &Style::emptyPrimitive;
7959
//_____________________________________________________________________
7960
void Style::globalPaletteChanged( void )
7962
helper().reloadConfig();
7963
helper().invalidateCaches();
7966
//____________________________________________________________________
7967
QIcon Style::standardIconImplementation(
7968
StandardPixmap standardIcon,
7969
const QStyleOption *option,
7970
const QWidget *widget ) const
7973
switch( standardIcon )
7976
// copied from kstyle
7977
case SP_DesktopIcon: return KIcon( "user-desktop" );
7978
case SP_TrashIcon: return KIcon( "user-trash" );
7979
case SP_ComputerIcon: return KIcon( "computer" );
7980
case SP_DriveFDIcon: return KIcon( "media-floppy" );
7981
case SP_DriveHDIcon: return KIcon( "drive-harddisk" );
7982
case SP_DriveCDIcon: return KIcon( "drive-optical" );
7983
case SP_DriveDVDIcon: return KIcon( "drive-optical" );
7984
case SP_DriveNetIcon: return KIcon( "folder-remote" );
7985
case SP_DirHomeIcon: return KIcon( "user-home" );
7986
case SP_DirOpenIcon: return KIcon( "document-open-folder" );
7987
case SP_DirClosedIcon: return KIcon( "folder" );
7988
case SP_DirIcon: return KIcon( "folder" );
7990
//TODO: generate ( !? ) folder with link emblem
7991
case SP_DirLinkIcon: return KIcon( "folder" );
7993
//TODO: look for a better icon
7994
case SP_FileIcon: return KIcon( "text-plain" );
7996
//TODO: generate ( !? ) file with link emblem
7997
case SP_FileLinkIcon: return KIcon( "text-plain" );
7999
//TODO: find correct icon
8000
case SP_FileDialogStart: return KIcon( "media-playback-start" );
8002
//TODO: find correct icon
8003
case SP_FileDialogEnd: return KIcon( "media-playback-stop" );
8005
case SP_FileDialogToParent: return KIcon( "go-up" );
8006
case SP_FileDialogNewFolder: return KIcon( "folder-new" );
8007
case SP_FileDialogDetailedView: return KIcon( "view-list-details" );
8008
case SP_FileDialogInfoView: return KIcon( "document-properties" );
8009
case SP_FileDialogContentsView: return KIcon( "view-list-icons" );
8010
case SP_FileDialogListView: return KIcon( "view-list-text" );
8011
case SP_FileDialogBack: return KIcon( "go-previous" );
8012
case SP_MessageBoxInformation: return KIcon( "dialog-information" );
8013
case SP_MessageBoxWarning: return KIcon( "dialog-warning" );
8014
case SP_MessageBoxCritical: return KIcon( "dialog-error" );
8015
case SP_MessageBoxQuestion: return KIcon( "dialog-information" );
8016
case SP_DialogOkButton: return KIcon( "dialog-ok" );
8017
case SP_DialogCancelButton: return KIcon( "dialog-cancel" );
8018
case SP_DialogHelpButton: return KIcon( "help-contents" );
8019
case SP_DialogOpenButton: return KIcon( "document-open" );
8020
case SP_DialogSaveButton: return KIcon( "document-save" );
8021
case SP_DialogCloseButton: return KIcon( "dialog-close" );
8022
case SP_DialogApplyButton: return KIcon( "dialog-ok-apply" );
8023
case SP_DialogResetButton: return KIcon( "document-revert" );
8024
case SP_DialogDiscardButton: return KIcon( "dialog-cancel" );
8025
case SP_DialogYesButton: return KIcon( "dialog-ok-apply" );
8026
case SP_DialogNoButton: return KIcon( "dialog-cancel" );
8027
case SP_ArrowUp: return KIcon( "go-up" );
8028
case SP_ArrowDown: return KIcon( "go-down" );
8029
case SP_ArrowLeft: return KIcon( "go-previous-view" );
8030
case SP_ArrowRight: return KIcon( "go-next-view" );
8031
case SP_ArrowBack: return KIcon( "go-previous" );
8032
case SP_ArrowForward: return KIcon( "go-next" );
8033
case SP_BrowserReload: return KIcon( "view-refresh" );
8034
case SP_BrowserStop: return KIcon( "process-stop" );
8035
case SP_MediaPlay: return KIcon( "media-playback-start" );
8036
case SP_MediaStop: return KIcon( "media-playback-stop" );
8037
case SP_MediaPause: return KIcon( "media-playback-pause" );
8038
case SP_MediaSkipForward: return KIcon( "media-skip-forward" );
8039
case SP_MediaSkipBackward: return KIcon( "media-skip-backward" );
8040
case SP_MediaSeekForward: return KIcon( "media-seek-forward" );
8041
case SP_MediaSeekBackward: return KIcon( "media-seek-backward" );
8042
case SP_MediaVolume: return KIcon( "audio-volume-medium" );
8043
case SP_MediaVolumeMuted: return KIcon( "audio-volume-muted" );
8049
// MDI windows buttons
8050
// get button color ( unfortunately option and widget might not be set )
8056
buttonColor = option->palette.window().color();
8057
iconColor = option->palette.windowText().color();
8059
} else if( widget ) {
8061
buttonColor = widget->palette().window().color();
8062
iconColor = widget->palette().windowText().color();
8066
// might not have a QApplication
8067
buttonColor = qApp->palette().window().color();
8068
iconColor = qApp->palette().windowText().color();
8072
// KCS is always safe
8073
buttonColor = KColorScheme( QPalette::Active, KColorScheme::Window, helper().config() ).background().color();
8074
iconColor = KColorScheme( QPalette::Active, KColorScheme::Window, helper().config() ).foreground().color();
8078
switch( standardIcon )
8081
case SP_TitleBarNormalButton:
8083
QPixmap realpm( pixelMetric( QStyle::PM_SmallIconSize,0,0 ), pixelMetric( QStyle::PM_SmallIconSize,0,0 ) );
8084
realpm.fill( Qt::transparent );
8085
QPixmap pm = helper().windecoButton( buttonColor, false, 15 );
8086
QPainter painter( &realpm );
8087
painter.drawPixmap( 1,1,pm );
8088
painter.setRenderHints( QPainter::Antialiasing );
8090
// should use the same icons as in the deco
8091
QPointF points[4] = {QPointF( 8.5, 6 ), QPointF( 11, 8.5 ), QPointF( 8.5, 11 ), QPointF( 6, 8.5 )};
8094
const qreal width( 1.1 );
8095
painter.translate( 0, 0.5 );
8096
painter.setBrush( Qt::NoBrush );
8097
painter.setPen( QPen( helper().calcLightColor( buttonColor ), width, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) );
8098
painter.drawPolygon( points, 4 );
8102
const qreal width( 1.1 );
8103
painter.translate( 0,-1 );
8104
painter.setBrush( Qt::NoBrush );
8105
painter.setPen( QPen( iconColor, width, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) );
8106
painter.drawPolygon( points, 4 );
8110
return QIcon( realpm );
8113
case SP_TitleBarShadeButton:
8115
QPixmap realpm( pixelMetric( QStyle::PM_SmallIconSize,0,0 ), pixelMetric( QStyle::PM_SmallIconSize,0,0 ) );
8116
realpm.fill( Qt::transparent );
8117
QPixmap pm = helper().windecoButton( buttonColor, false, 15 );
8118
QPainter painter( &realpm );
8119
painter.drawPixmap( 1,1,pm );
8120
painter.setRenderHints( QPainter::Antialiasing );
8124
painter.translate( 0, 0.5 );
8125
painter.setBrush( Qt::NoBrush );
8126
painter.setPen( QPen( helper().calcLightColor( buttonColor ), width, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) );
8127
painter.drawLine( QPointF( 6.5,6.5 ), QPointF( 8.75,8.75 ) );
8128
painter.drawLine( QPointF( 8.75,8.75 ), QPointF( 11.0,6.5 ) );
8129
painter.drawLine( QPointF( 6.5,11.0 ), QPointF( 11.0,11.0 ) );
8134
painter.translate( 0,-1 );
8135
painter.setBrush( Qt::NoBrush );
8136
painter.setPen( QPen( iconColor, width, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) );
8137
painter.drawLine( QPointF( 6.5,6.5 ), QPointF( 8.75,8.75 ) );
8138
painter.drawLine( QPointF( 8.75,8.75 ), QPointF( 11.0,6.5 ) );
8139
painter.drawLine( QPointF( 6.5,11.0 ), QPointF( 11.0,11.0 ) );
8144
return QIcon( realpm );
8147
case SP_TitleBarUnshadeButton:
8149
QPixmap realpm( pixelMetric( QStyle::PM_SmallIconSize,0,0 ), pixelMetric( QStyle::PM_SmallIconSize,0,0 ) );
8150
realpm.fill( Qt::transparent );
8151
QPixmap pm = helper().windecoButton( buttonColor, false, 15 );
8152
QPainter painter( &realpm );
8153
painter.drawPixmap( 1,1,pm );
8154
painter.setRenderHints( QPainter::Antialiasing );
8159
painter.translate( 0, 0.5 );
8160
painter.setBrush( Qt::NoBrush );
8161
painter.setPen( QPen( helper().calcLightColor( buttonColor ), width, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) );
8162
painter.drawLine( QPointF( 6.5,8.75 ), QPointF( 8.75,6.5 ) );
8163
painter.drawLine( QPointF( 8.75,6.5 ), QPointF( 11.0,8.75 ) );
8164
painter.drawLine( QPointF( 6.5,11.0 ), QPointF( 11.0,11.0 ) );
8169
painter.translate( 0,-1 );
8170
painter.setBrush( Qt::NoBrush );
8171
painter.setPen( QPen( iconColor, width, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) );
8172
painter.drawLine( QPointF( 6.5,8.75 ), QPointF( 8.75,6.5 ) );
8173
painter.drawLine( QPointF( 8.75,6.5 ), QPointF( 11.0,8.75 ) );
8174
painter.drawLine( QPointF( 6.5,11.0 ), QPointF( 11.0,11.0 ) );
8178
return QIcon( realpm );
8181
case SP_TitleBarCloseButton:
8182
case SP_DockWidgetCloseButton:
8184
QPixmap realpm( pixelMetric( QStyle::PM_SmallIconSize,0,0 ), pixelMetric( QStyle::PM_SmallIconSize,0,0 ) );
8185
realpm.fill( Qt::transparent );
8186
QPixmap pm = helper().windecoButton( buttonColor, false, 15 );
8187
QPainter painter( &realpm );
8188
painter.drawPixmap( 1,1,pm );
8189
painter.setRenderHints( QPainter::Antialiasing );
8190
painter.setBrush( Qt::NoBrush );
8194
painter.translate( 0, 0.5 );
8195
painter.setBrush( Qt::NoBrush );
8196
painter.setPen( QPen( helper().calcLightColor( buttonColor ), width, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) );
8197
painter.drawLine( QPointF( 6.5,6.5 ), QPointF( 11.0,11.0 ) );
8198
painter.drawLine( QPointF( 11.0,6.5 ), QPointF( 6.5,11.0 ) );
8203
painter.translate( 0,-1 );
8204
painter.setBrush( Qt::NoBrush );
8205
painter.setPen( QPen( iconColor, width, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) );
8206
painter.drawLine( QPointF( 6.5,6.5 ), QPointF( 11.0,11.0 ) );
8207
painter.drawLine( QPointF( 11.0,6.5 ), QPointF( 6.5,11.0 ) );
8212
return QIcon( realpm );
8215
case SP_ToolBarHorizontalExtensionButton:
8218
QPixmap realpm( pixelMetric( QStyle::PM_SmallIconSize,0,0 ), pixelMetric( QStyle::PM_SmallIconSize,0,0 ) );
8219
realpm.fill( Qt::transparent );
8220
QPainter painter( &realpm );
8221
painter.setRenderHints( QPainter::Antialiasing );
8222
painter.setBrush( Qt::NoBrush );
8224
painter.translate( qreal( realpm.width() )/2.0, qreal( realpm.height() )/2.0 );
8226
const bool reverseLayout( option && option->direction == Qt::RightToLeft );
8227
QPolygonF a = genericArrow( reverseLayout ? ArrowLeft:ArrowRight, ArrowTiny );
8230
painter.translate( 0, 0.5 );
8231
painter.setBrush( Qt::NoBrush );
8232
painter.setPen( QPen( helper().calcLightColor( buttonColor ), width, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) );
8233
painter.drawPolyline( a );
8238
painter.translate( 0,-1 );
8239
painter.setBrush( Qt::NoBrush );
8240
painter.setPen( QPen( iconColor, width, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) );
8241
painter.drawPolyline( a );
8244
return QIcon( realpm );
8247
case SP_ToolBarVerticalExtensionButton:
8249
QPixmap realpm( pixelMetric( QStyle::PM_SmallIconSize,0,0 ), pixelMetric( QStyle::PM_SmallIconSize,0,0 ) );
8250
realpm.fill( Qt::transparent );
8251
QPainter painter( &realpm );
8252
painter.setRenderHints( QPainter::Antialiasing );
8253
painter.setBrush( Qt::NoBrush );
8255
QPolygonF a = genericArrow( ArrowDown, ArrowTiny );
8258
painter.translate( 0, 0.5 );
8259
painter.setBrush( Qt::NoBrush );
8260
painter.setPen( QPen( helper().calcLightColor( buttonColor ), width, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) );
8261
painter.drawPolyline( a );
8266
painter.translate( 0,-1 );
8267
painter.setBrush( Qt::NoBrush );
8268
painter.setPen( QPen( iconColor, width, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) );
8269
painter.drawPolyline( a );
8272
return QIcon( realpm );
8276
return QCommonStyle::standardIconImplementation( standardIcon, option, widget );
8280
//_____________________________________________________________
8281
void Style::initializeKGlobalSettings( void )
8284
if( qApp && !qApp->inherits( "KApplication" ) )
8287
for Qt, non-KDE applications, needs to explicitely activate KGlobalSettings.
8288
On the other hand, it is done internally in kApplication constructor,
8289
so no need to duplicate here.
8291
KGlobalSettings::self()->activate( KGlobalSettings::ListenForChanges );
8294
// connect palette changes to local slot, to make sure caches are cleared
8295
connect( KGlobalSettings::self(), SIGNAL( kdisplayPaletteChanged( void ) ), this, SLOT( globalPaletteChanged( void ) ) );
8298
_kGlobalSettingsInitialized = true;
8302
//______________________________________________________________
8303
void Style::polishScrollArea( QAbstractScrollArea* scrollArea ) const
8306
if( !scrollArea ) return;
8308
// HACK: add exception for KPIM transactionItemView, which is an overlay widget
8309
// and must have filled background. This is a temporary workaround until a more
8310
// robust solution is found.
8311
if( scrollArea->inherits( "KPIM::TransactionItemView" ) )
8313
// also need to make the scrollarea background plain ( using autofill background )
8314
// so that optional vertical scrollbar background is not transparent either.
8315
// TODO: possibly add an event filter to use the "normal" window background
8316
// instead of something flat.
8317
scrollArea->setAutoFillBackground( true );
8321
// check frame style and background role
8322
if( !(scrollArea->frameShape() == QFrame::NoFrame || scrollArea->backgroundRole() == QPalette::Window ) )
8325
// get viewport and check background role
8326
QWidget* viewport( scrollArea->viewport() );
8327
if( !( viewport && viewport->backgroundRole() == QPalette::Window ) ) return;
8329
// change viewport autoFill background.
8330
// do the same for children if the background role is QPalette::Window
8331
viewport->setAutoFillBackground( false );
8332
QList<QWidget*> children( viewport->findChildren<QWidget*>() );
8333
foreach( QWidget* child, children )
8335
if( child->parent() == viewport && child->backgroundRole() == QPalette::Window )
8336
{ child->setAutoFillBackground( false ); }
8341
//_______________________________________________________________
8342
QRegion Style::tabBarClipRegion( const QTabBar* tabBar ) const
8344
// need to mask-out arrow buttons, if visible.
8345
QRegion mask( tabBar->rect() );
8346
foreach( const QObject* child, tabBar->children() )
8348
const QToolButton* toolButton( qobject_cast<const QToolButton*>( child ) );
8349
if( toolButton && toolButton->isVisible() ) mask -= toolButton->geometry();
8356
//_________________________________________________________________________________
8357
void Style::renderDialSlab( QPainter *painter, const QRect& r, const QColor &color, const QStyleOption *option, StyleOptions opts, qreal opacity, AnimationMode mode ) const
8361
const QStyleOptionSlider* sliderOption( qstyleoption_cast<const QStyleOptionSlider*>( option ) );
8362
if( !sliderOption ) return;
8364
// adjust rect to be square, and centered
8365
const int dimension( qMin( r.width(), r.height() ) );
8366
const QRect rect( centerRect( r, dimension, dimension ) );
8368
// calculate glow color
8369
const QColor glow( slabShadowColor( color, opts, opacity, mode ) );
8372
QPixmap pix( helper().dialSlab( color, glow, 0.0, dimension ) );
8373
const qreal baseOffset( 3.5 );
8375
const QColor light( helper().calcLightColor( color ) );
8376
const QColor shadow( helper().calcShadowColor( color ) );
8379
p.setPen( Qt::NoPen );
8380
p.setRenderHints( QPainter::Antialiasing );
8384
if( sliderOption->maximum == sliderOption->minimum ) angle = M_PI / 2;
8387
qreal fraction( qreal( sliderOption->sliderPosition - sliderOption->minimum )/qreal( sliderOption->maximum - sliderOption->minimum ) );
8388
if( !sliderOption->upsideDown ) fraction = 1.0 - fraction;
8390
if( sliderOption->dialWrapping ) angle = 1.5*M_PI - fraction*2*M_PI;
8391
else angle = ( M_PI*8 - fraction*10*M_PI )/6;
8394
QPointF center( pix.rect().center() );
8395
const int sliderWidth( dimension/6 );
8396
const qreal radius( 0.5*( dimension - 2*sliderWidth ) );
8397
center += QPointF( radius*cos( angle ), -radius*sin( angle ) );
8399
QRectF sliderRect( 0, 0, sliderWidth, sliderWidth );
8400
sliderRect.moveCenter( center );
8403
const qreal offset( 0.3 );
8404
QLinearGradient lg( 0, baseOffset, 0, baseOffset + 2*sliderRect.height() );
8405
p.setBrush( light );
8406
p.setPen( Qt::NoPen );
8407
p.drawEllipse( sliderRect.translated( 0, offset ) );
8410
p.setPen( Qt::NoPen );
8412
p.setCompositionMode( QPainter::CompositionMode_DestinationOut );
8413
p.setBrush( QBrush( Qt::black ) );
8414
p.drawEllipse( sliderRect );
8418
p.translate( sliderRect.topLeft() );
8419
helper().drawInverseShadow( p, shadow.darker( 200 ), 0.0, sliderRect.width(), 0.0 );
8422
if( glow.isValid() ) helper().drawInverseGlow( p, glow, 0.0, sliderRect.width(), sliderRect.width() );
8426
painter->drawPixmap( rect.topLeft(), pix );
8432
//____________________________________________________________________________________
8433
void Style::renderButtonSlab( QPainter *painter, QRect r, const QColor &color, StyleOptions options, qreal opacity,
8435
TileSet::Tiles tiles ) const
8437
if( ( r.width() <= 0 ) || ( r.height() <= 0 ) ) return;
8439
r.translate( 0,-1 );
8440
if( !painter->clipRegion().isEmpty() ) painter->setClipRegion( painter->clipRegion().translated( 0,-1 ) );
8443
if( !( options & NoFill ) ) helper().fillButtonSlab( *painter, r, color, options&Sunken );
8446
// for slabs, hover takes precedence over focus ( other way around for holes )
8447
// but in any case if the button is sunken we don't show focus nor hover
8449
if( options & Sunken )
8451
tile = helper().slabSunken( color );
8455
QColor glow = slabShadowColor( color, options, opacity, mode );
8456
tile = helper().slab( color, glow, 0.0 );
8461
{ tile->render( r, painter, tiles ); }
8465
//____________________________________________________________________________________
8466
void Style::renderSlab(
8467
QPainter *painter, QRect r,
8468
const QColor &color,
8469
StyleOptions options, qreal opacity,
8471
TileSet::Tiles tiles ) const
8475
if( !r.isValid() ) return;
8477
// this is needed for button vertical alignment
8478
r.translate( 0,-1 );
8479
if( !painter->clipRegion().isEmpty() ) painter->setClipRegion( painter->clipRegion().translated( 0,-1 ) );
8481
// additional adjustment for sunken frames
8482
if( options & Sunken ) r.adjust( -1,0,1,2 );
8485
if( !( options & NoFill ) )
8488
painter->setRenderHint( QPainter::Antialiasing );
8489
painter->setPen( Qt::NoPen );
8491
if( helper().calcShadowColor( color ).value() > color.value() && ( options & Sunken ) )
8494
QLinearGradient innerGradient( 0, r.top(), 0, r.bottom() + r.height() );
8495
innerGradient.setColorAt( 0.0, color );
8496
innerGradient.setColorAt( 1.0, helper().calcLightColor( color ) );
8497
painter->setBrush( innerGradient );
8501
QLinearGradient innerGradient( 0, r.top() - r.height(), 0, r.bottom() );
8502
innerGradient.setColorAt( 0.0, helper().calcLightColor( color ) );
8503
innerGradient.setColorAt( 1.0, color );
8504
painter->setBrush( innerGradient );
8508
helper().fillSlab( *painter, r );
8514
// for slabs, hover takes precedence over focus ( other way around for holes )
8515
// but in any case if the button is sunken we don't show focus nor hover
8517
if( ( options & Sunken ) && color.isValid() )
8519
tile = helper().slabSunken( color );
8523
// calculate proper glow color based on current settings and opacity
8524
const QColor glow( slabShadowColor( color, options, opacity, mode ) );
8525
if( color.isValid() || glow.isValid() ) tile = helper().slab( color, glow , 0.0 );
8531
if( tile ) tile->render( r, painter, tiles );
8535
//______________________________________________________________________________________________________________________________
8536
void Style::fillTabBackground( QPainter* painter, const QRect &r, const QColor &color, QTabBar::Shape shape, const QWidget* widget ) const
8540
QRect fillRect( r );
8543
case QTabBar::RoundedNorth:
8544
case QTabBar::TriangularNorth:
8545
fillRect.adjust( 4, 4, -4, -6 );
8548
case QTabBar::RoundedSouth:
8549
case QTabBar::TriangularSouth:
8550
fillRect.adjust( 4, 4, -4, -4 );
8553
case QTabBar::RoundedWest:
8554
case QTabBar::TriangularWest:
8555
fillRect.adjust( 4, 3, -5, -5 );
8558
case QTabBar::RoundedEast:
8559
case QTabBar::TriangularEast:
8560
fillRect.adjust( 5, 3, -4, -5 );
8567
if( widget ) helper().renderWindowBackground( painter, fillRect, widget, color );
8568
else painter->fillRect( fillRect, color );
8572
//______________________________________________________________________________________________________________________________
8573
void Style::fillTab( QPainter* painter, const QRect &r, const QColor &color, QTabBar::Shape shape, bool active ) const
8576
const QColor dark( helper().calcDarkColor( color ) );
8577
const QColor shadow( helper().calcShadowColor( color ) );
8578
const QColor light( helper().calcLightColor( color ) );
8579
const QRect fillRect( r.adjusted( 4, 3,-4,-5 ) );
8581
QLinearGradient highlight;
8584
case QTabBar::RoundedNorth:
8585
case QTabBar::TriangularNorth:
8586
highlight = QLinearGradient( fillRect.topLeft(), fillRect.bottomLeft() );
8589
case QTabBar::RoundedSouth:
8590
case QTabBar::TriangularSouth:
8591
highlight = QLinearGradient( fillRect.bottomLeft(), fillRect.topLeft() );
8594
case QTabBar::RoundedEast:
8595
case QTabBar::TriangularEast:
8596
highlight = QLinearGradient( fillRect.topRight(), fillRect.topLeft() );
8599
case QTabBar::RoundedWest:
8600
case QTabBar::TriangularWest:
8601
highlight = QLinearGradient( fillRect.topLeft(), fillRect.topRight() );
8610
highlight.setColorAt( 0.0, helper().alphaColor( light, 0.5 ) );
8611
highlight.setColorAt( 0.1, helper().alphaColor( light, 0.5 ) );
8612
highlight.setColorAt( 0.25, helper().alphaColor( light, 0.3 ) );
8613
highlight.setColorAt( 0.5, helper().alphaColor( light, 0.2 ) );
8614
highlight.setColorAt( 0.75, helper().alphaColor( light, 0.1 ) );
8615
highlight.setColorAt( 0.9, Qt::transparent );
8620
highlight.setColorAt( 0.0, helper().alphaColor( light, 0.1 ) );
8621
highlight.setColorAt( 0.4, helper().alphaColor( dark, 0.5 ) );
8622
highlight.setColorAt( 0.8, helper().alphaColor( dark, 0.4 ) );
8623
highlight.setColorAt( 0.9, Qt::transparent );
8627
painter->setRenderHints( QPainter::Antialiasing );
8628
painter->setPen( Qt::NoPen );
8630
painter->setBrush( highlight );
8631
painter->drawRoundedRect( fillRect, 2, 2 );
8635
//____________________________________________________________________________________________________
8636
void Style::renderSpinBoxArrow( QPainter* painter, const QStyleOptionSpinBox* option, const QWidget* widget, const SubControl& subControl ) const
8639
const QPalette& palette( option->palette );
8641
const State& flags( option->state );
8643
bool enabled( flags & State_Enabled );
8644
bool atLimit( false );
8648
if( const QSpinBox* spinbox = qobject_cast<const QSpinBox*>( widget ) )
8651
// cast to spinbox and check if at limit
8652
const int value( spinbox->value() );
8653
if( !spinbox->wrapping() && (( subControl == SC_SpinBoxUp && value == spinbox->maximum() ) ||
8654
( subControl == SC_SpinBoxDown && value == spinbox->minimum() ) ) )
8657
} else if( const QDoubleSpinBox* spinbox = qobject_cast<const QDoubleSpinBox*>( widget ) ) {
8659
// cast to spinbox and check if at limit
8660
const double value( spinbox->value() );
8661
if( !spinbox->wrapping() && (( subControl == SC_SpinBoxUp && value == spinbox->maximum() ) ||
8662
( subControl == SC_SpinBoxDown && value == spinbox->minimum() ) ) )
8669
enabled &= !atLimit;
8670
const bool mouseOver( enabled && ( flags & State_MouseOver ) );
8672
// check animation state
8673
const bool subControlHover( enabled && mouseOver && ( option->activeSubControls & subControl ) );
8674
animations().spinBoxEngine().updateState( widget, subControl, subControlHover );
8676
const bool animated( enabled && animations().spinBoxEngine().isAnimated( widget, subControl ) );
8677
const qreal opacity( animations().spinBoxEngine().opacity( widget, subControl ) );
8683
QColor highlight = helper().viewHoverBrush().brush( palette ).color();
8684
color = KColorUtils::mix( palette.color( QPalette::Text ), highlight, opacity );
8686
} else if( subControlHover ) {
8688
color = helper().viewHoverBrush().brush( palette ).color();
8690
} else if( atLimit ) {
8692
color = palette.color( QPalette::Disabled, QPalette::Text );
8696
color = palette.color( QPalette::Text );
8700
const qreal penThickness = 1.6;
8701
const QColor background = palette.color( QPalette::Background );
8703
const QPolygonF a( genericArrow( ( subControl == SC_SpinBoxUp ) ? ArrowUp:ArrowDown, ArrowNormal ) );
8704
const QRect arrowRect( subControlRect( CC_SpinBox, option, subControl, widget ) );
8707
painter->translate( arrowRect.center() );
8708
painter->setRenderHint( QPainter::Antialiasing );
8710
painter->setPen( QPen( helper().decoColor( background, color ) , penThickness, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) );
8711
painter->drawPolyline( a );
8718
//___________________________________________________________________________________
8719
void Style::renderSplitter( const QStyleOption* option, QPainter* painter, const QWidget* widget, bool horizontal ) const
8722
const QPalette& palette( option->palette );
8723
const QRect& r( option->rect );
8724
const State& flags( option->state );
8725
const bool enabled( flags & State_Enabled );
8726
const bool mouseOver( enabled && ( flags & ( State_MouseOver|State_Sunken ) ) );
8729
const Qt::Orientation orientation( horizontal ? Qt::Horizontal : Qt::Vertical );
8731
bool animated( false );
8732
qreal opacity( AnimationData::OpacityInvalid );
8736
if( qobject_cast<const QMainWindow*>( widget ) )
8739
animations().dockSeparatorEngine().updateRect( widget, r, orientation, mouseOver );
8740
animated = animations().dockSeparatorEngine().isAnimated( widget, r, orientation );
8741
opacity = animated ? animations().dockSeparatorEngine().opacity( widget, orientation ) : AnimationData::OpacityInvalid;
8743
} else if( QPaintDevice* device = painter->device() ) {
8746
try update QSplitterHandle using painter device, because Qt passes
8747
QSplitter as the widget to the QStyle primitive.
8749
animations().splitterEngine().updateState( device, mouseOver );
8750
animated = animations().splitterEngine().isAnimated( device );
8751
opacity = animations().splitterEngine().opacity( device );
8757
const QColor color = palette.color( QPalette::Background );
8761
const int h = r.height();
8763
if( animated || mouseOver )
8765
const QColor highlight = helper().alphaColor( helper().calcLightColor( color ),0.5*( animated ? opacity:1.0 ) );
8766
const qreal a( r.height() > 30 ? 10.0/r.height():0.1 );
8767
QLinearGradient lg( 0, r.top(), 0, r.bottom() );
8768
lg.setColorAt( 0, Qt::transparent );
8769
lg.setColorAt( a, highlight );
8770
lg.setColorAt( 1.0-a, highlight );
8771
lg.setColorAt( 1, Qt::transparent );
8772
painter->fillRect( r, lg );
8775
const int ngroups( qMax( 1,h / 250 ) );
8776
int center( ( h - ( ngroups-1 ) * 250 ) /2 + r.top() );
8777
for( int k = 0; k < ngroups; k++, center += 250 )
8779
helper().renderDot( painter, QPoint( r.left()+1, center-3 ), color );
8780
helper().renderDot( painter, QPoint( r.left()+1, center ), color );
8781
helper().renderDot( painter, QPoint( r.left()+1, center+3 ), color );
8786
const int w( r.width() );
8787
if( animated || mouseOver )
8789
const QColor highlight( helper().alphaColor( helper().calcLightColor( color ),0.5*( animated ? opacity:1.0 ) ) );
8790
const qreal a( r.width() > 30 ? 10.0/r.width():0.1 );
8791
QLinearGradient lg( r.left(), 0, r.right(), 0 );
8792
lg.setColorAt( 0, Qt::transparent );
8793
lg.setColorAt( a, highlight );
8794
lg.setColorAt( 1.0-a, highlight );
8795
lg.setColorAt( 1, Qt::transparent );
8796
painter->fillRect( r, lg );
8800
const int ngroups( qMax( 1, w / 250 ) );
8801
int center = ( w - ( ngroups-1 ) * 250 ) /2 + r.left();
8802
for( int k = 0; k < ngroups; k++, center += 250 )
8804
helper().renderDot( painter, QPoint( center-3, r.top()+1 ), color );
8805
helper().renderDot( painter, QPoint( center, r.top()+1 ), color );
8806
helper().renderDot( painter, QPoint( center+3, r.top()+1 ), color );
8813
//____________________________________________________________________________________________________
8814
void Style::renderTitleBarButton( QPainter* painter, const QStyleOptionTitleBar* option, const QWidget* widget, const SubControl& subControl ) const
8817
const QRect r = subControlRect( CC_TitleBar, option, subControl, widget );
8818
if( !r.isValid() ) return;
8820
QPalette palette = option->palette;
8823
painter->drawPixmap( r, helper().windecoButton( palette.window().color(), true, r.height() ) );
8824
painter->setRenderHints( QPainter::Antialiasing );
8825
painter->setBrush( Qt::NoBrush );
8827
const State& flags( option->state );
8828
const bool enabled( flags & State_Enabled );
8829
const bool active( enabled && ( option->titleBarState & Qt::WindowActive ) );
8831
// enable state transition
8832
animations().widgetEnabilityEngine().updateState( widget, AnimationEnable, active );
8833
if( animations().widgetEnabilityEngine().isAnimated( widget, AnimationEnable ) )
8834
{ palette = helper().mergePalettes( palette, animations().widgetEnabilityEngine().opacity( widget, AnimationEnable ) ); }
8836
const bool sunken( flags&State_Sunken );
8837
const bool mouseOver( ( !sunken ) && widget && r.translated( widget->mapToGlobal( QPoint( 0,0 ) ) ).contains( QCursor::pos() ) );
8839
animations().mdiWindowEngine().updateState( widget, subControl, enabled && mouseOver );
8840
const bool animated( enabled && animations().mdiWindowEngine().isAnimated( widget, subControl ) );
8841
const qreal opacity( animations().mdiWindowEngine().opacity( widget, subControl ) );
8846
const QColor contrast = helper().calcLightColor( option->palette.color( QPalette::Active, QPalette::Window ) );
8847
const qreal width( 1.1 );
8848
painter->translate( 0, 0.5 );
8849
painter->setPen( QPen( contrast, width, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) );
8850
renderTitleBarIcon( painter, QRectF( r ).adjusted( -2.5,-2.5,0,0 ), subControl );
8861
const QColor base( palette.color( active ? QPalette::Active : QPalette::Disabled, QPalette::WindowText ) );
8862
const QColor glow( subControl == SC_TitleBarCloseButton ?
8863
helper().viewNegativeTextBrush().brush( palette ).color():
8864
helper().viewHoverBrush().brush( palette ).color() );
8866
color = KColorUtils::mix( base, glow, opacity );
8868
} else if( mouseOver ) {
8870
color = ( subControl == SC_TitleBarCloseButton ) ?
8871
helper().viewNegativeTextBrush().brush( palette ).color():
8872
helper().viewHoverBrush().brush( palette ).color();
8876
color = palette.color( active ? QPalette::Active : QPalette::Disabled, QPalette::WindowText );
8880
// main icon painting
8881
const qreal width( 1.1 );
8882
painter->translate( 0,-1 );
8883
painter->setPen( QPen( color, width, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) );
8884
renderTitleBarIcon( painter, QRectF( r ).adjusted( -2.5,-2.5,0,0 ), subControl );
8892
//____________________________________________________________________________________
8893
void Style::renderTitleBarIcon( QPainter *painter, const QRectF &r, const SubControl& subControl ) const
8897
painter->translate( r.topLeft() );
8898
switch( subControl )
8900
case SC_TitleBarContextHelpButton:
8902
painter->translate( 1.5, 1.5 );
8903
painter->drawArc( 7,5,4,4,135*16, -180*16 );
8904
painter->drawArc( 9,8,4,4,135*16,45*16 );
8905
painter->drawPoint( 9,12 );
8908
case SC_TitleBarMinButton:
8910
painter->drawLine( QPointF( 7.5, 9.5 ), QPointF( 10.5,12.5 ) );
8911
painter->drawLine( QPointF( 10.5,12.5 ), QPointF( 13.5, 9.5 ) );
8914
case SC_TitleBarNormalButton:
8916
painter->translate( 1.5, 1.5 );
8917
QPoint points[4] = {QPoint( 9, 6 ), QPoint( 12, 9 ), QPoint( 9, 12 ), QPoint( 6, 9 )};
8918
painter->drawPolygon( points, 4 );
8921
case SC_TitleBarMaxButton:
8923
painter->drawLine( QPointF( 7.5,11.5 ), QPointF( 10.5, 8.5 ) );
8924
painter->drawLine( QPointF( 10.5, 8.5 ), QPointF( 13.5,11.5 ) );
8927
case SC_TitleBarCloseButton:
8929
painter->drawLine( QPointF( 7.5,7.5 ), QPointF( 13.5,13.5 ) );
8930
painter->drawLine( QPointF( 13.5,7.5 ), QPointF( 7.5,13.5 ) );
8933
case SC_TitleBarShadeButton:
8935
painter->drawLine( QPointF( 7.5, 13.5 ), QPointF( 13.5, 13.5 ) );
8936
painter->drawLine( QPointF( 7.5, 7.5 ), QPointF( 10.5,10.5 ) );
8937
painter->drawLine( QPointF( 10.5,10.5 ), QPointF( 13.5, 7.5 ) );
8940
case SC_TitleBarUnshadeButton:
8942
painter->drawLine( QPointF( 7.5,10.5 ), QPointF( 10.5, 7.5 ) );
8943
painter->drawLine( QPointF( 10.5, 7.5 ), QPointF( 13.5,10.5 ) );
8944
painter->drawLine( QPointF( 7.5,13.0 ), QPointF( 13.5,13.0 ) );
8953
//__________________________________________________________________________
8954
void Style::renderHeaderBackground( const QRect& r, const QPalette& palette, QPainter* painter, const QWidget* widget, bool horizontal, bool reverse ) const
8957
// use window background for the background
8958
if( widget ) helper().renderWindowBackground( painter, r, widget, palette );
8959
else painter->fillRect( r, palette.color( QPalette::Window ) );
8961
if( horizontal ) renderHeaderLines( r, palette, painter, TileSet::Bottom );
8962
else if( reverse ) renderHeaderLines( r, palette, painter, TileSet::Left );
8963
else renderHeaderLines( r, palette, painter, TileSet::Right );
8967
//__________________________________________________________________________
8968
void Style::renderHeaderLines( const QRect& r, const QPalette& palette, QPainter* painter, TileSet::Tiles tiles ) const
8971
// add horizontal lines
8972
const QColor color( palette.color( QPalette::Window ) );
8973
const QColor dark( helper().calcDarkColor( color ) );
8974
const QColor light( helper().calcLightColor( color ) );
8978
if( tiles & TileSet::Bottom )
8981
painter->setPen( dark );
8982
if( tiles & TileSet::Left ) painter->drawPoint( rect.bottomLeft() );
8983
else if( tiles& TileSet::Right ) painter->drawPoint( rect.bottomRight() );
8984
else painter->drawLine( rect.bottomLeft(), rect.bottomRight() );
8986
rect.adjust( 0,0,0,-1 );
8987
painter->setPen( light );
8988
if( tiles & TileSet::Left )
8990
painter->drawLine( rect.bottomLeft(), rect.bottomLeft()+QPoint( 1, 0 ) );
8991
painter->drawLine( rect.bottomLeft()+ QPoint( 1, 0 ), rect.bottomLeft()+QPoint( 1, 1 ) );
8993
} else if( tiles & TileSet::Right ) {
8995
painter->drawLine( rect.bottomRight(), rect.bottomRight() - QPoint( 1, 0 ) );
8996
painter->drawLine( rect.bottomRight() - QPoint( 1, 0 ), rect.bottomRight() - QPoint( 1, -1 ) );
9000
painter->drawLine( rect.bottomLeft(), rect.bottomRight() );
9002
} else if( tiles & TileSet::Left ) {
9004
painter->setPen( dark );
9005
painter->drawLine( rect.topLeft(), rect.bottomLeft() );
9007
rect.adjust( 1,0,0,0 );
9008
painter->setPen( light );
9009
painter->drawLine( rect.topLeft(), rect.bottomLeft() );
9011
} else if( tiles & TileSet::Right ) {
9013
painter->setPen( dark );
9014
painter->drawLine( rect.topRight(), rect.bottomRight() );
9016
rect.adjust( 0,0,-1,0 );
9017
painter->setPen( light );
9018
painter->drawLine( rect.topRight(), rect.bottomRight() );
9028
//__________________________________________________________________________
9029
void Style::renderMenuItemBackground( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
9031
const QRect& r( option->rect );
9032
const QPalette& palette( option->palette );
9033
const QRect animatedRect( animations().menuEngine().animatedRect( widget ) );
9034
if( !animatedRect.isNull() )
9037
if( animatedRect.intersects( r ) )
9039
const QColor color( helper().menuBackgroundColor( helper().calcMidColor( palette.color( QPalette::Window ) ), widget, animatedRect.center() ) );
9040
renderMenuItemRect( option, animatedRect, color, palette, painter );
9043
} else if( animations().menuEngine().isTimerActive( widget ) ) {
9045
const QRect previousRect( animations().menuEngine().currentRect( widget, Previous ) );
9046
if( previousRect.intersects( r ) )
9049
const QColor color( helper().menuBackgroundColor( helper().calcMidColor( palette.color( QPalette::Window ) ), widget, previousRect.center() ) );
9050
renderMenuItemRect( option, previousRect, color, palette, painter );
9053
} else if( animations().menuEngine().isAnimated( widget, Previous ) ) {
9055
QRect previousRect( animations().menuEngine().currentRect( widget, Previous ) );
9056
if( previousRect.intersects( r ) )
9058
const qreal opacity( animations().menuEngine().opacity( widget, Previous ) );
9059
const QColor color( helper().menuBackgroundColor( helper().calcMidColor( palette.color( QPalette::Window ) ), widget, previousRect.center() ) );
9060
renderMenuItemRect( option, previousRect, color, palette, painter, opacity );
9068
//__________________________________________________________________________
9069
void Style::renderMenuItemRect( const QStyleOption* opt, const QRect& r, const QColor& base, const QPalette& palette, QPainter* painter, qreal opacity ) const
9072
if( opacity == 0 ) return;
9074
// get relevant color
9075
// TODO: this is inconsistent with MenuBar color.
9076
// this should change to properly account for 'sunken' state
9077
QColor color( base );
9078
if( StyleConfigData::menuHighlightMode() == StyleConfigData::MM_STRONG )
9081
color = palette.color( QPalette::Highlight );
9083
} else if( StyleConfigData::menuHighlightMode() == StyleConfigData::MM_SUBTLE ) {
9085
color = KColorUtils::mix( color, KColorUtils::tint( color, palette.color( QPalette::Highlight ), 0.6 ) );
9089
// special painting for items with submenus
9090
const QStyleOptionMenuItem* menuItemOption = qstyleoption_cast<const QStyleOptionMenuItem*>( opt );
9091
if( menuItemOption && menuItemOption->menuItemType == QStyleOptionMenuItem::SubMenu )
9094
QPixmap pm( r.size() );
9095
pm.fill( Qt::transparent );
9097
QRect rr( QPoint( 0,0 ), r.size() );
9099
pp.setRenderHint( QPainter::Antialiasing );
9100
pp.setPen( Qt::NoPen );
9102
pp.setBrush( color );
9103
helper().fillHole( pp, rr );
9105
helper().holeFlat( color, 0.0 )->render( rr.adjusted( 1, 2, -2, -1 ), &pp );
9107
QRect maskr( visualRect( opt->direction, rr, QRect( rr.width()-40, 0, 40,rr.height() ) ) );
9108
QLinearGradient gradient(
9109
visualPos( opt->direction, maskr, QPoint( maskr.left(), 0 ) ),
9110
visualPos( opt->direction, maskr, QPoint( maskr.right()-4, 0 ) ) );
9111
gradient.setColorAt( 0.0, Qt::black );
9112
gradient.setColorAt( 1.0, Qt::transparent );
9113
pp.setBrush( gradient );
9114
pp.setCompositionMode( QPainter::CompositionMode_DestinationIn );
9115
pp.drawRect( maskr );
9117
if( opacity >= 0 && opacity < 1 )
9119
pp.setCompositionMode( QPainter::CompositionMode_DestinationIn );
9120
pp.fillRect( pm.rect(), helper().alphaColor( Qt::black, opacity ) );
9125
painter->drawPixmap( handleRTL( opt, r ), pm );
9129
if( opacity >= 0 && opacity < 1 )
9130
{ color.setAlphaF( opacity ); }
9132
helper().holeFlat( color, 0.0 )->render( r.adjusted( 1,2,-2,-1 ), painter, TileSet::Full );
9138
//________________________________________________________________________
9139
void Style::renderCheckBox(
9140
QPainter *painter, const QRect &rect, const QPalette &palette,
9141
StyleOptions options, CheckBoxState state,
9143
AnimationMode mode ) const
9146
const int s( qMin( rect.width(), rect.height() ) );
9147
const QRect r( centerRect( rect, s, s ) );
9149
if( !( options & NoFill ) )
9151
if( options & Sunken ) helper().holeFlat( palette.color( QPalette::Window ), 0.0, false )->render( r, painter, TileSet::Full );
9152
else renderSlab( painter, r, palette.color( QPalette::Button ), options, opacity, mode, TileSet::Ring );
9156
const qreal x( r.center().x() - 3.5 );
9157
const qreal y( r.center().y() - 2.5 );
9159
if( state != CheckOff )
9162
qreal penThickness( 2.0 );
9163
const QColor color( palette.color( ( options&Sunken ) ? QPalette::WindowText:QPalette::ButtonText ) );
9164
const QColor background( palette.color( ( options&Sunken ) ? QPalette::Window:QPalette::Button ) );
9165
QPen pen( helper().decoColor( background, color ), penThickness, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin );
9166
QPen contrastPen( helper().calcLightColor( background ), penThickness, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin );
9167
if( state == CheckTriState )
9169
QVector<qreal> dashes;
9170
if( StyleConfigData::checkBoxStyle() == StyleConfigData::CS_CHECK )
9173
dashes << 1.0 << 2.0;
9175
pen.setWidthF( penThickness );
9176
contrastPen.setWidthF( penThickness );
9180
dashes << 0.4 << 2.0;
9183
pen.setDashPattern( dashes );
9184
contrastPen.setDashPattern( dashes );
9188
if( !( options&Sunken ) ) painter->translate( 0, -1 );
9189
painter->setRenderHint( QPainter::Antialiasing );
9191
const qreal offset( qMin( penThickness, qreal( 1.0 ) ) );
9192
if( StyleConfigData::checkBoxStyle() == StyleConfigData::CS_CHECK )
9195
painter->setPen( contrastPen );
9196
painter->translate( 0, offset );
9197
painter->drawLine( QPointF( x+9, y ), QPointF( x+3,y+7 ) );
9198
painter->drawLine( QPointF( x, y+4 ), QPointF( x+3,y+7 ) );
9200
painter->setPen( pen );
9201
painter->translate( 0, -offset );
9202
painter->drawLine( QPointF( x+9, y ), QPointF( x+3,y+7 ) );
9203
painter->drawLine( QPointF( x, y+4 ), QPointF( x+3,y+7 ) );
9207
if( options&Sunken )
9210
painter->setPen( contrastPen );
9211
painter->translate( 0, offset );
9212
painter->drawLine( QPointF( x+8, y ), QPointF( x+1,y+7 ) );
9213
painter->drawLine( QPointF( x+8, y+7 ), QPointF( x+1,y ) );
9215
painter->setPen( pen );
9216
painter->translate( 0, -offset );
9217
painter->drawLine( QPointF( x+8, y ), QPointF( x+1,y+7 ) );
9218
painter->drawLine( QPointF( x+8, y+7 ), QPointF( x+1,y ) );
9222
painter->setPen( contrastPen );
9223
painter->translate( 0, offset );
9224
painter->drawLine( QPointF( x+8, y-1 ), QPointF( x,y+7 ) );
9225
painter->drawLine( QPointF( x+8, y+7 ), QPointF( x,y-1 ) );
9227
painter->setPen( pen );
9228
painter->translate( 0, -offset );
9229
painter->drawLine( QPointF( x+8, y-1 ), QPointF( x,y+7 ) );
9230
painter->drawLine( QPointF( x+8, y+7 ), QPointF( x,y-1 ) );
9241
//___________________________________________________________________
9242
void Style::renderRadioButton(
9243
QPainter* painter, const QRect& rect,
9244
const QPalette& palette,
9245
StyleOptions options,
9246
CheckBoxState state,
9248
AnimationMode mode ) const
9251
const int s( CheckBox_Size );
9252
const QRect r( centerRect( rect, s, s ) );
9253
const int x = r.x();
9254
const int y = r.y();
9256
const QColor color( palette.color( QPalette::Button ) );
9257
const QColor glow( slabShadowColor( color, options, opacity, mode ) );
9258
painter->drawPixmap( x, y, helper().roundSlab( color, glow, 0.0 ) );
9260
// draw the radio mark
9261
if( state == CheckOn )
9263
const qreal radius( 2.6 );
9264
const qreal dx( 0.5*r.width() - radius );
9265
const qreal dy( 0.5*r.height() - radius );
9268
painter->setRenderHints( QPainter::Antialiasing );
9269
painter->setPen( Qt::NoPen );
9271
const QColor background( palette.color( QPalette::Button ) );
9272
const QColor color( palette.color( QPalette::ButtonText ) );
9274
painter->setBrush( helper().calcLightColor( background ) );
9275
painter->translate( 0, radius/2 );
9276
painter->drawEllipse( QRectF( r ).adjusted( dx, dy, -dx, -dy ) );
9278
painter->setBrush( helper().decoColor( background, color ) );
9279
painter->translate( 0, -radius/2 );
9280
painter->drawEllipse( QRectF( r ).adjusted( dx, dy, -dx, -dy ) );
9288
//______________________________________________________________________________
9289
void Style::renderScrollBarHole(
9290
QPainter *painter, const QRect &r, const QColor &color,
9291
const Qt::Orientation& orientation, const TileSet::Tiles& tiles ) const
9294
if( !r.isValid() ) return;
9296
// one need to make smaller shadow
9297
// notably on the size when rect height is too high
9298
const bool smallShadow( orientation == Qt::Horizontal ? r.height() < 10 : r.width() < 10 );
9299
helper().scrollHole( color, orientation, smallShadow )->render( r, painter, tiles );
9303
//______________________________________________________________________________
9304
void Style::renderScrollBarHandle(
9305
QPainter* painter, const QRect& r, const QPalette& palette,
9306
const Qt::Orientation& orientation, const bool& hover, const qreal& opacity ) const
9309
if( !r.isValid() ) return;
9312
painter->setRenderHints( QPainter::Antialiasing );
9314
// draw the hole as background
9315
const bool horizontal( orientation == Qt::Horizontal );
9316
const QRect holeRect( horizontal ? r.adjusted( -4,0,4,0 ) : r.adjusted( 0,-3,0,4 ) );
9317
renderScrollBarHole( painter, holeRect, palette.color( QPalette::Window ), orientation, horizontal ? TileSet::Vertical : TileSet::Horizontal );
9319
// draw the slider itself
9320
QRectF rect( horizontal ? r.adjusted( 3, 2, -3, -3 ):r.adjusted( 3, 4, -3, -3 ) );
9322
if( !rect.isValid() )
9324
// e.g. not enough height
9329
const QColor color( palette.color( QPalette::Button ) );
9332
const qreal radius = 3.5;
9336
const QColor shadow( helper().alphaColor( helper().calcShadowColor( color ), 0.4 ) );
9337
const QColor hovered( helper().viewHoverBrush().brush( QPalette::Active ).color() );
9339
if( opacity >= 0 ) glow = KColorUtils::mix( shadow, hovered, opacity );
9340
else if( hover ) glow = hovered;
9343
helper().scrollHandle( color, glow )->
9344
render( rect.adjusted( -3, -3, 3, 3 ).toRect(),
9345
painter, TileSet::Full );
9348
const QColor mid( helper().calcMidColor( color ) );
9349
QLinearGradient lg( 0, rect.top(), 0, rect.bottom() );
9350
lg.setColorAt(0, color );
9351
lg.setColorAt(1, mid );
9352
painter->setPen( Qt::NoPen );
9353
painter->setBrush( lg );
9354
painter->drawRoundedRect( rect.adjusted( 1, 1, -1, -1), radius - 2, radius - 2 );
9357
const QColor light( helper().calcLightColor( color ) );
9359
QLinearGradient patternGradient( 0, 0, horizontal ? 30:0, horizontal? 0:30 );
9360
patternGradient.setSpread( QGradient::ReflectSpread );
9361
patternGradient.setColorAt( 0.0, Qt::transparent );
9362
patternGradient.setColorAt( 1.0, helper().alphaColor( light, 0.1 ) );
9364
QRectF bevelRect( rect );
9365
if( horizontal ) bevelRect.adjust( 0, 3, 0, -3 );
9366
else bevelRect.adjust( 3, 0, -3, 0 );
9368
if( bevelRect.isValid() )
9370
painter->setBrush( patternGradient );
9371
painter->drawRect( bevelRect );
9378
//______________________________________________________________________________
9379
void Style::renderScrollBarArrow(
9380
QPainter* painter, const QRect& r, const QColor& color, const QColor& background,
9381
ArrowOrientation orientation ) const
9384
const qreal penThickness = 1.6;
9385
QPolygonF a( genericArrow( orientation, ArrowNormal ) );
9387
const QColor contrast( helper().calcLightColor( background ) );
9388
const QColor base( helper().decoColor( background, color ) );
9391
painter->translate( r.center() );
9392
painter->setRenderHint( QPainter::Antialiasing );
9394
const qreal offset( qMin( penThickness, qreal( 1.0 ) ) );
9395
painter->translate( 0,offset );
9396
painter->setPen( QPen( contrast, penThickness, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) );
9397
painter->drawPolyline( a );
9398
painter->translate( 0,-offset );
9400
painter->setPen( QPen( base, penThickness, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) );
9401
painter->drawPolyline( a );
9408
//______________________________________________________________________________
9409
QColor Style::scrollBarArrowColor( const QStyleOption* option, const SubControl& control, const QWidget* widget ) const
9411
const QRect& r( option->rect );
9412
const QPalette& palette( option->palette );
9413
QColor color( palette.color( QPalette::WindowText ) );
9415
// check enabled state
9416
const bool enabled( option->state & State_Enabled );
9417
if( !enabled ) return color;
9419
if( const QAbstractSlider* slider = qobject_cast<const QAbstractSlider*>( widget ) )
9421
const int value( slider->value() );
9423
( control == SC_ScrollBarSubLine && value == slider->minimum() ) ||
9424
( control == SC_ScrollBarAddLine && value == slider->maximum() ) ) {
9426
// manually disable arrow, to indicate that scrollbar is at limit
9427
return palette.color( QPalette::Disabled, QPalette::WindowText );
9432
const bool hover( animations().scrollBarEngine().isHovered( widget, control ) );
9433
const bool animated( animations().scrollBarEngine().isAnimated( widget, control ) );
9434
const qreal opacity( animations().scrollBarEngine().opacity( widget, control ) );
9436
QPoint position( hover ? widget->mapFromGlobal( QCursor::pos() ) : QPoint( -1, -1 ) );
9437
if( hover && r.contains( position ) )
9439
// we need to update the arrow controlRect on fly because there is no
9440
// way to get it from the styles directly, outside of repaint events
9441
animations().scrollBarEngine().setSubControlRect( widget, control, r );
9445
if( r.intersects( animations().scrollBarEngine().subControlRect( widget, control ) ) )
9448
QColor highlight = helper().viewHoverBrush().brush( palette ).color();
9451
color = KColorUtils::mix( color, highlight, opacity );
9453
} else if( hover ) {
9465
//______________________________________________________________________________
9466
void Style::renderSliderTickmarks( QPainter* painter, const QStyleOptionSlider* option, const QWidget* widget ) const
9469
const int& ticks( option->tickPosition );
9470
const int available( pixelMetric( PM_SliderSpaceAvailable, option, widget ) );
9471
int interval = option->tickInterval;
9472
if( interval < 1 ) interval = option->pageStep;
9473
if( interval < 1 ) return;
9475
const QRect& r( option->rect );
9476
const QPalette& palette( option->palette );
9478
const int fudge( pixelMetric( PM_SliderLength, option, widget ) / 2 );
9479
int current( option->minimum );
9481
// Since there is no subrect for tickmarks do a translation here.
9483
painter->translate( r.x(), r.y() );
9485
if( option->orientation == Qt::Horizontal )
9487
QColor base( helper().backgroundColor( palette.color( QPalette::Window ), widget, r.center() ) );
9488
painter->setPen( helper().calcDarkColor( base ) );
9491
int tickSize( option->orientation == Qt::Horizontal ? r.height()/3:r.width()/3 );
9493
while( current <= option->maximum )
9496
const int position( sliderPositionFromValue( option->minimum, option->maximum, current, available ) + fudge );
9498
// calculate positions
9499
if( option->orientation == Qt::Horizontal )
9501
if( ticks == QSlider::TicksAbove ) painter->drawLine( position, 0, position, tickSize );
9502
else if( ticks == QSlider::TicksBelow ) painter->drawLine( position, r.height()-tickSize, position, r.height() );
9504
painter->drawLine( position, 0, position, tickSize );
9505
painter->drawLine( position, r.height()-tickSize, position, r.height() );
9510
QColor base( helper().backgroundColor( palette.color( QPalette::Window ), widget, QPoint( r.center().x(), position ) ) );
9511
painter->setPen( helper().calcDarkColor( base ) );
9513
if( ticks == QSlider::TicksAbove ) painter->drawLine( 0, position, tickSize, position );
9514
else if( ticks == QSlider::TicksBelow ) painter->drawLine( r.width()-tickSize, position, r.width(), position );
9516
painter->drawLine( 0, position, tickSize, position );
9517
painter->drawLine( r.width()-tickSize, position, r.width(), position );
9521
// go to next position
9522
current += interval;
9529
//____________________________________________________________________________________
9530
QColor Style::slabShadowColor( QColor color, StyleOptions options, qreal opacity, AnimationMode mode ) const
9534
if( mode == AnimationNone || opacity < 0 )
9537
if( options & Hover ) glow = helper().viewHoverBrush().brush( QPalette::Active ).color();
9538
else if( options & Focus ) glow = helper().viewFocusBrush().brush( QPalette::Active ).color();
9539
else if( ( options & SubtleShadow ) && color.isValid() ) glow = helper().alphaColor( helper().calcShadowColor( color ), 0.15 );
9542
} else if( mode == AnimationHover ) {
9544
// animated color, hover
9545
if( options & Focus ) glow = helper().viewFocusBrush().brush( QPalette::Active ).color();
9546
else if( ( options & SubtleShadow ) && color.isValid() ) glow = helper().alphaColor( helper().calcShadowColor( color ), 0.15 );
9548
if( glow.isValid() ) glow = KColorUtils::mix( glow, helper().viewHoverBrush().brush( QPalette::Active ).color(), opacity );
9549
else glow = helper().alphaColor( helper().viewHoverBrush().brush( QPalette::Active ).color(), opacity );
9551
} else if( mode == AnimationFocus ) {
9553
if( options & Hover ) glow = helper().viewHoverBrush().brush( QPalette::Active ).color();
9554
else if( ( options & SubtleShadow ) && color.isValid() ) glow = helper().alphaColor( helper().calcShadowColor( color ), 0.15 );
9556
if( glow.isValid() ) glow = KColorUtils::mix( glow, helper().viewFocusBrush().brush( QPalette::Active ).color(), opacity );
9557
else glow = helper().alphaColor( helper().viewFocusBrush().brush( QPalette::Active ).color(), opacity );
9564
//____________________________________________________________________________________
9565
QPolygonF Style::genericArrow( Style::ArrowOrientation orientation, Style::ArrowSize size ) const
9569
switch( orientation )
9573
if( size == ArrowTiny ) a << QPointF( -1.75, 1.125 ) << QPointF( 0.5, -1.125 ) << QPointF( 2.75, 1.125 );
9574
else if( size == ArrowSmall ) a << QPointF( -2,1.5 ) << QPointF( 0.5, -1.5 ) << QPointF( 3,1.5 );
9575
else a << QPointF( -3,2.5 ) << QPointF( 0.5, -1.5 ) << QPointF( 4,2.5 );
9581
if( size == ArrowTiny ) a << QPointF( -1.75, -1.125 ) << QPointF( 0.5, 1.125 ) << QPointF( 2.75, -1.125 );
9582
else if( size == ArrowSmall ) a << QPointF( -2,-1.5 ) << QPointF( 0.5, 1.5 ) << QPointF( 3,-1.5 );
9583
else a << QPointF( -3,-1.5 ) << QPointF( 0.5, 2.5 ) << QPointF( 4,-1.5 );
9589
if( size == ArrowTiny ) a << QPointF( 1.125, -1.75 ) << QPointF( -1.125, 0.5 ) << QPointF( 1.125, 2.75 );
9590
else if( size == ArrowSmall ) a << QPointF( 1.5,-2 ) << QPointF( -1.5, 0.5 ) << QPointF( 1.5,3 );
9591
else a << QPointF( 2.5,-3 ) << QPointF( -1.5, 0.5 ) << QPointF( 2.5,4 );
9597
if( size == ArrowTiny ) a << QPointF( -1.125, -1.75 ) << QPointF( 1.125, 0.5 ) << QPointF( -1.125, 2.75 );
9598
else if( size == ArrowSmall ) a << QPointF( -1.5,-2 ) << QPointF( 1.5, 0.5 ) << QPointF( -1.5,3 );
9599
else a << QPointF( -1.5,-3 ) << QPointF( 2.5, 0.5 ) << QPointF( -1.5,4 );