4
//////////////////////////////////////////////////////////////////////////////
6
// Oxygen widget style for KDE 4
9
// Copyright (C) 2009-2010 Hugo Pereira Da Costa <hugo@oxygen-icons.org>
10
// Copyright (C) 2008 Long Huynh Huu <long.upcase@googlemail.com>
11
// Copyright (C) 2007-2008 Casper Boemann <cbr@boemann.dk>
12
// Copyright (C) 2007 Matthew Woehlke <mw_triad@users.sourceforge.net>
13
// Copyright (C) 2003-2005 Sandro Giessl <sandro@giessl.com>
15
// based on the KDE style "dotNET":
16
// Copyright (C) 2001-2002, Chris Lee <clee@kde.org>
17
// Carsten Pfeiffer <pfeiffer@kde.org>
18
// Karol Szwed <gallium@kde.org>
19
// Drawing routines completely reimplemented from KDE3 HighColor, which was
20
// originally based on some stuff from the KDE2 HighColor.
22
// based on drawing routines of the style "Keramik":
23
// Copyright (c) 2002 Malte Starostik <malte@kde.org>
24
// (c) 2002,2003 Maksim Orlovich <mo002j@mail.rochester.edu>
25
// based on the KDE3 HighColor Style
26
// Copyright (C) 2001-2002 Karol Szwed <gallium@kde.org>
27
// (C) 2001-2002 Fredrik Höglund <fredrik@kde.org>
28
// Drawing routines adapted from the KDE2 HCStyle,
29
// Copyright (C) 2000 Daniel M. Duley <mosfet@kde.org>
30
// (C) 2000 Dirk Mueller <mueller@kde.org>
31
// (C) 2001 Martijn Klingens <klingens@kde.org>
32
// Progressbar code based on KStyle,
33
// Copyright (C) 2001-2002 Karol Szwed <gallium@kde.org>
35
// This library is free software; you can redistribute it and/or
36
// modify it under the terms of the GNU Library General Public
37
// License version 2 as published by the Free Software Foundation.
39
// This library is distributed in the hope that it will be useful,
40
// but WITHOUT ANY WARRANTY; without even the implied warranty of
41
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
42
// Library General Public License for more details.
44
// You should have received a copy of the GNU Library General Public License
45
// along with this library; see the file COPYING.LIB. If not, write to
46
// the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
47
// Boston, MA 02110-1301, USA.
48
//////////////////////////////////////////////////////////////////////////////
50
#include "oxygenanimationmodes.h"
51
#include "oxygenmetrics.h"
52
#include "oxygentileset.h"
54
#include <QtCore/QMap>
55
#include <QtGui/QAbstractScrollArea>
56
#include <QtGui/QCommonStyle>
57
#include <QtGui/QDockWidget>
58
#include <QtGui/QMdiSubWindow>
59
#include <QtGui/QStyleOption>
60
#include <QtGui/QToolBar>
61
#include <QtGui/QToolBox>
62
#include <QtGui/QWidget>
68
class FrameShadowFactory;
69
class MdiWindowShadowFactory;
77
class TopLevelManager: public QObject
82
TopLevelManager( QObject* parent, const StyleHelper& helper ):
88
virtual bool eventFilter(QObject *, QEvent *);
93
const StyleHelper& _helper;
98
//! base class for oxygen style
99
/*! it is responsible to draw all the primitives to be displayed on screen, on request from Qt paint engine */
100
class Style: public QCommonStyle
104
/* this tells kde applications that custom style elements are supported, using the kstyle mechanism */
105
Q_CLASSINFO ("X-KDE-CustomElements", "true")
110
explicit Style( void );
113
virtual ~Style( void );
115
//! widget polishing/unpolishing
116
virtual void polish( QWidget* );
118
//! widget polishing/unpolishing
119
virtual void unpolish( QWidget* );
121
//! needed to avoid warnings at compilation time
122
using QCommonStyle::polish;
123
using QCommonStyle::unpolish;
126
virtual int pixelMetric(PixelMetric, const QStyleOption* = 0, const QWidget* = 0) const;
129
virtual int styleHint(StyleHint, const QStyleOption* = 0, const QWidget* = 0, QStyleHintReturn* = 0) const;
131
//! returns rect corresponding to one widget's subelement
132
virtual QRect subElementRect( SubElement subRect, const QStyleOption*, const QWidget* ) const;
134
//! returns rect corresponding to one widget's subcontrol
135
virtual QRect subControlRect( ComplexControl, const QStyleOptionComplex*, SubControl, const QWidget* ) const;
137
//! returns size matching contents
138
QSize sizeFromContents( ContentsType, const QStyleOption*, const QSize&, const QWidget* ) const;
140
//! returns which subcontrol given QPoint corresponds to
141
SubControl hitTestComplexControl( ComplexControl, const QStyleOptionComplex*, const QPoint&, const QWidget* ) const;
144
void drawPrimitive( PrimitiveElement, const QStyleOption*, QPainter*, const QWidget* ) const;
147
void drawControl( ControlElement, const QStyleOption*, QPainter*, const QWidget* ) const;
150
void drawComplexControl( ComplexControl, const QStyleOptionComplex*, QPainter*, const QWidget* ) const;
152
//! generic text rendering
153
virtual void drawItemText(
154
QPainter*, const QRect&, int alignment, const QPalette&, bool enabled,
155
const QString&, QPalette::ColorRole = QPalette::NoRole) const;
158
virtual bool eventFilter(QObject *, QEvent *);
160
//!@name specialized event filters
162
Note: one could use separate objects to install these event filters
163
This would have the advantage to avoid the big 'if' statement in the
164
Style::eventFilter method
168
bool eventFilterComboBoxContainer( QWidget*, QEvent* );
169
bool eventFilterDockWidget( QDockWidget*, QEvent* );
170
bool eventFilterGeometryTip( QWidget*, QEvent* );
171
bool eventFilterMdiSubWindow( QMdiSubWindow*, QEvent* );
172
bool eventFilterQ3ListView( QWidget*, QEvent* );
173
bool eventFilterScrollBar( QWidget*, QEvent* );
174
bool eventFilterTabBar( QWidget*, QEvent* );
175
bool eventFilterToolBar( QToolBar*, QEvent* );
176
bool eventFilterToolBox( QToolBox*, QEvent* );
178
//! install event filter to object, in a unique way
179
void addEventFilter( QObject* object )
181
object->removeEventFilter( this );
182
object->installEventFilter( this );
189
//! update oxygen configuration
190
void oxygenConfigurationChanged( void );
192
//! needed to update style when configuration is changed
193
void globalPaletteChanged( void );
195
//! copied from kstyle
196
int layoutSpacingImplementation(
197
QSizePolicy::ControlType, QSizePolicy::ControlType, Qt::Orientation,
198
const QStyleOption* option, const QWidget* widget ) const
199
{ return pixelMetric(PM_DefaultLayoutSpacing, option, widget); }
202
virtual QIcon standardIconImplementation(
203
StandardPixmap standardIcon,
204
const QStyleOption *option,
205
const QWidget *widget) const;
209
//! initialize kGlobalSettings conections
210
void initializeKGlobalSettings( void );
213
StyleHelper& helper( void ) const
217
ShadowHelper& shadowHelper( void ) const
218
{ return *_shadowHelper; }
220
//!@name enumerations and convenience classes
223
//! arrow orientation
224
enum ArrowOrientation
234
//! get polygon corresponding to generic arrow
242
//! internal option flags to pass arguments around
253
Q_DECLARE_FLAGS(StyleOptions, StyleOption)
255
//! used to store slab characteristics
262
_tiles( TileSet::Ring )
266
SlabRect( const QRect& r, const int& tiles ):
268
_tiles( TileSet::Tiles( tiles ) )
272
TileSet::Tiles _tiles;
277
typedef QList<SlabRect> SlabRectList;
280
tabBar data class needed for
281
the rendering of tabbars when
282
one tab is being drawn
284
class TabBarData: public QObject
290
TabBarData( Style* parent ):
297
virtual ~TabBarData( void )
300
//! assign target tabBar
301
void lock( const QWidget* widget )
302
{ _tabBar = widget; }
304
//! true if tabbar is locked
305
bool locks( const QWidget* widget ) const
306
{ return _tabBar && _tabBar.data() == widget; }
309
void setDirty( const bool& value = true )
317
virtual void drawTabBarBaseControl( const QStyleOptionTab*, QPainter*, const QWidget* );
321
//! pointer to parent style object
322
QWeakPointer<const Style> _style;
324
//! pointer to target tabBar
325
QWeakPointer<const QWidget> _tabBar;
327
//! if true, will paint on next TabBarTabShapeControlCall
335
Animations& animations( void ) const
336
{ return *_animations; }
338
Transitions& transitions( void ) const
339
{ return *_transitions; }
342
WindowManager& windowManager( void ) const
343
{ return *_windowManager; }
346
FrameShadowFactory& frameShadowFactory( void ) const
347
{ return *_frameShadowFactory; }
349
//! mdi window shadows
350
MdiWindowShadowFactory& mdiWindowShadowFactory( void ) const
351
{ return *_mdiWindowShadowFactory; }
355
this is used for debugging. Provides information about
356
widgets, widgets' geometry, and ancestry tree
358
WidgetExplorer& widgetExplorer( void ) const
359
{ return *_widgetExplorer; }
362
TabBarData& tabBarData( void ) const
363
{ return *_tabBarData; }
365
//!@name subelementRect specialized functions
368
//! default implementation. Does not change anything
369
QRect defaultSubElementRect( const QStyleOption* option, const QWidget* ) const
370
{ return option->rect; }
372
//! pushbutton contents
373
QRect pushButtonContentsRect( const QStyleOption* option, const QWidget* ) const
375
return insideMargin( option->rect,
376
PushButton_ContentsMargin,
377
PushButton_ContentsMargin_Left,
378
PushButton_ContentsMargin_Top,
379
PushButton_ContentsMargin_Right,
380
PushButton_ContentsMargin_Bottom );
384
QRect toolBoxTabContentsRect( const QStyleOption* option, const QWidget* ) const
385
{ return insideMargin( option->rect, 0, 5, 0, 5, 0 ); }
387
//! checkbox contents
388
QRect checkBoxContentsRect( const QStyleOption* option, const QWidget* ) const
389
{ return handleRTL( option, option->rect.adjusted( CheckBox_Size + CheckBox_BoxTextSpace, 0, 0, 0 ) ); }
391
//! progressbar contents
392
QRect progressBarContentsRect( const QStyleOption* option, const QWidget* ) const;
395
QRect tabBarTabLeftButtonRect( const QStyleOption* option, const QWidget* widget ) const
396
{ return tabBarTabButtonRect( SE_TabBarTabLeftButton, option, widget ); }
398
QRect tabBarTabRightButtonRect( const QStyleOption* option, const QWidget* widget ) const
399
{ return tabBarTabButtonRect( SE_TabBarTabRightButton, option, widget ); }
401
QRect tabBarTabButtonRect( SubElement, const QStyleOption*, const QWidget* ) const;
404
QRect tabBarTabTextRect( const QStyleOption* option, const QWidget* widget ) const
405
{ return QCommonStyle::subElementRect( SE_TabBarTabText, option, widget ).adjusted( 6, 0, -6, 0 ); }
408
QRect tabWidgetTabContentsRect( const QStyleOption*, const QWidget* ) const;
409
QRect tabWidgetTabPaneRect( const QStyleOption*, const QWidget* ) const;
411
QRect tabWidgetLeftCornerRect( const QStyleOption* option, const QWidget* widget ) const;
412
QRect tabWidgetRightCornerRect( const QStyleOption* option, const QWidget* widget ) const;
416
//!@name subcontrol Rect specialized functions
419
QRect groupBoxSubControlRect( const QStyleOptionComplex*, SubControl, const QWidget* ) const;
420
QRect comboBoxSubControlRect( const QStyleOptionComplex*, SubControl, const QWidget* ) const;
421
QRect scrollBarSubControlRect( const QStyleOptionComplex*, SubControl, const QWidget* ) const;
422
QRect sliderSubControlRect( const QStyleOptionComplex*, SubControl, const QWidget* ) const;
423
QRect spinBoxSubControlRect( const QStyleOptionComplex*, SubControl, const QWidget* ) const;
425
//! this properly handles single/double or no scrollBar buttons
426
QRect scrollBarInternalSubControlRect( const QStyleOptionComplex*, SubControl ) const;
430
//!@name sizeFromContents
433
QSize checkBoxSizeFromContents( const QStyleOption*, const QSize&, const QWidget* ) const;
434
QSize comboBoxSizeFromContents( const QStyleOption*, const QSize&, const QWidget* ) const;
435
QSize headerSectionSizeFromContents( const QStyleOption*, const QSize&, const QWidget* ) const;
437
QSize menuBarSizeFromContents( const QStyleOption*, const QSize& size, const QWidget* ) const
440
QSize menuBarItemSizeFromContents( const QStyleOption*, const QSize& size, const QWidget* ) const
441
{ return expandSize( size, MenuBarItem_Margin, MenuBarItem_Margin_Left, 0, MenuBarItem_Margin_Right, 0 ); }
443
QSize menuItemSizeFromContents( const QStyleOption*, const QSize&, const QWidget* ) const;
444
QSize pushButtonSizeFromContents( const QStyleOption*, const QSize&, const QWidget* ) const;
446
QSize tabWidgetSizeFromContents( const QStyleOption*, const QSize& size, const QWidget* ) const
447
{ return expandSize( size, TabWidget_ContentsMargin - 2 ); }
449
QSize tabBarTabSizeFromContents( const QStyleOption*, const QSize& size, const QWidget* ) const;
450
QSize toolButtonSizeFromContents( const QStyleOption*, const QSize&, const QWidget* ) const;
454
//!@name primitives specialized functions
457
bool emptyPrimitive( const QStyleOption*, QPainter*, const QWidget* ) const
460
bool drawFramePrimitive( const QStyleOption*, QPainter*, const QWidget* ) const;
461
bool drawFrameFocusRectPrimitive( const QStyleOption*, QPainter*, const QWidget* ) const;
462
bool drawFrameGroupBoxPrimitive( const QStyleOption*, QPainter*, const QWidget* ) const;
463
bool drawFrameMenuPrimitive( const QStyleOption*, QPainter*, const QWidget* ) const;
464
bool drawFrameTabBarBasePrimitive( const QStyleOption*, QPainter*, const QWidget* ) const;
465
bool drawFrameTabWidgetPrimitive( const QStyleOption*, QPainter*, const QWidget* ) const;
466
bool drawFrameWindowPrimitive( const QStyleOption*, QPainter*, const QWidget* ) const;
468
bool drawIndicatorArrowUpPrimitive( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
469
{ return drawIndicatorArrowPrimitive( ArrowUp, option, painter, widget ); }
471
bool drawIndicatorArrowDownPrimitive( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
472
{ return drawIndicatorArrowPrimitive( ArrowDown, option, painter, widget ); }
474
bool drawIndicatorArrowLeftPrimitive( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
475
{ return drawIndicatorArrowPrimitive( ArrowLeft, option, painter, widget ); }
477
bool drawIndicatorArrowRightPrimitive( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
478
{ return drawIndicatorArrowPrimitive( ArrowRight, option, painter, widget ); }
480
bool drawIndicatorArrowPrimitive( ArrowOrientation, const QStyleOption*, QPainter*, const QWidget* ) const;
482
//! dock widget separators
483
/*! it uses the same painting as QSplitter, but due to Qt, the horizontal/vertical convention is inverted */
484
bool drawIndicatorDockWidgetResizeHandlePrimitive( const QStyleOption* option, QPainter* painter, const QWidget* widget) const
487
renderSplitter( option, painter, widget, !(option->state & State_Horizontal ) );
492
bool drawIndicatorHeaderArrowPrimitive( const QStyleOption*, QPainter*, const QWidget* ) const;
493
bool drawPanelButtonCommandPrimitive( const QStyleOption*, QPainter*, const QWidget* ) const;
494
bool drawPanelMenuPrimitive( const QStyleOption*, QPainter*, const QWidget* ) const;
495
bool drawPanelButtonToolPrimitive( const QStyleOption*, QPainter*, const QWidget* ) const;
496
bool drawPanelScrollAreaCornerPrimitive( const QStyleOption*, QPainter*, const QWidget* ) const;
497
bool drawPanelTipLabelPrimitive( const QStyleOption*, QPainter*, const QWidget* ) const;
498
bool drawPanelItemViewItemPrimitive( const QStyleOption*, QPainter*, const QWidget* ) const;
499
bool drawPanelLineEditPrimitive( const QStyleOption*, QPainter*, const QWidget* ) const;
500
bool drawIndicatorMenuCheckMarkPrimitive( const QStyleOption*, QPainter*, const QWidget* ) const;
501
bool drawQ3CheckListIndicatorPrimitive( const QStyleOption*, QPainter*, const QWidget* ) const;
502
bool drawQ3CheckListExclusiveIndicatorPrimitive( const QStyleOption*, QPainter*, const QWidget* ) const;
503
bool drawIndicatorBranchPrimitive( const QStyleOption*, QPainter*, const QWidget* ) const;
504
bool drawIndicatorButtonDropDownPrimitive( const QStyleOption*, QPainter*, const QWidget* ) const;
505
bool drawIndicatorCheckBoxPrimitive( const QStyleOption*, QPainter*, const QWidget* ) const;
506
bool drawIndicatorRadioButtonPrimitive( const QStyleOption*, QPainter*, const QWidget* ) const;
507
bool drawIndicatorTabTearPrimitive( const QStyleOption*, QPainter*, const QWidget* ) const;
508
bool drawIndicatorToolBarHandlePrimitive( const QStyleOption*, QPainter*, const QWidget* ) const;
509
bool drawIndicatorToolBarSeparatorPrimitive( const QStyleOption*, QPainter*, const QWidget* ) const;
511
bool drawWidgetPrimitive( const QStyleOption*, QPainter*, const QWidget* ) const;
515
//!@name controls specialized functions
518
bool emptyControl( const QStyleOption*, QPainter*, const QWidget* ) const
521
virtual bool drawCapacityBarControl( const QStyleOption*, QPainter*, const QWidget* ) const;
522
virtual bool drawComboBoxLabelControl( const QStyleOption*, QPainter*, const QWidget* ) const;
523
virtual bool drawDockWidgetTitleControl( const QStyleOption*, QPainter*, const QWidget* ) const;
524
virtual bool drawHeaderEmptyAreaControl( const QStyleOption*, QPainter*, const QWidget* ) const;
525
virtual bool drawHeaderLabelControl( const QStyleOption*, QPainter*, const QWidget* ) const;
526
virtual bool drawHeaderSectionControl( const QStyleOption*, QPainter*, const QWidget* ) const;
527
virtual bool drawMenuBarItemControl( const QStyleOption*, QPainter*, const QWidget* ) const;
528
virtual bool drawMenuItemControl( const QStyleOption*, QPainter*, const QWidget* ) const;
529
virtual bool drawProgressBarControl( const QStyleOption*, QPainter*, const QWidget* ) const;
530
virtual bool drawProgressBarContentsControl( const QStyleOption*, QPainter*, const QWidget* ) const;
531
virtual bool drawProgressBarGrooveControl( const QStyleOption*, QPainter*, const QWidget* ) const;
532
virtual bool drawProgressBarLabelControl( const QStyleOption*, QPainter*, const QWidget* ) const;
533
virtual bool drawPushButtonLabelControl( const QStyleOption*, QPainter*, const QWidget* ) const;
534
virtual bool drawRubberBandControl( const QStyleOption*, QPainter*, const QWidget* ) const;
537
virtual bool drawScrollBarSliderControl( const QStyleOption*, QPainter*, const QWidget* ) const;
538
virtual bool drawScrollBarAddLineControl( const QStyleOption*, QPainter*, const QWidget* ) const;
539
virtual bool drawScrollBarSubLineControl( const QStyleOption*, QPainter*, const QWidget* ) const;
540
virtual bool drawScrollBarAddPageControl( const QStyleOption*, QPainter*, const QWidget* ) const;
541
virtual bool drawScrollBarSubPageControl( const QStyleOption*, QPainter*, const QWidget* ) const;
543
virtual bool drawShapedFrameControl( const QStyleOption*, QPainter*, const QWidget* ) const;
546
virtual bool drawSizeGripControl( const QStyleOption*, QPainter*, const QWidget* ) const
548
// size grips, whose usage is discouraged in KDE, are not rendered at all by oxygen
553
virtual bool drawSplitterControl( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
555
renderSplitter( option, painter, widget, option->state & State_Horizontal );
559
virtual bool drawTabBarTabLabelControl( const QStyleOption*, QPainter*, const QWidget* ) const;
562
/*! there are two methods (_Single and _Plain) implemented, to deal with tabbar appearance selected from options */
563
virtual bool drawTabBarTabShapeControl_Single( const QStyleOption*, QPainter*, const QWidget* ) const;
564
virtual bool drawTabBarTabShapeControl_Plain( const QStyleOption*, QPainter*, const QWidget* ) const;
565
virtual bool drawToolBarControl( const QStyleOption*, QPainter*, const QWidget* ) const;
566
virtual bool drawToolBoxTabLabelControl( const QStyleOption*, QPainter*, const QWidget* ) const;
567
virtual bool drawToolBoxTabShapeControl( const QStyleOption*, QPainter*, const QWidget* ) const;
568
virtual bool drawToolButtonLabelControl( const QStyleOption*, QPainter*, const QWidget* ) const;
572
//!@name complex ontrols specialized functions
574
bool drawComboBoxComplexControl( const QStyleOptionComplex*, QPainter*, const QWidget* ) const;
575
bool drawDialComplexControl( const QStyleOptionComplex*, QPainter*, const QWidget* ) const;
576
bool drawGroupBoxComplexControl( const QStyleOptionComplex*, QPainter*, const QWidget* ) const;
577
bool drawQ3ListViewComplexControl( const QStyleOptionComplex*, QPainter*, const QWidget* ) const;
578
bool drawSliderComplexControl( const QStyleOptionComplex*, QPainter*, const QWidget* ) const;
579
bool drawSpinBoxComplexControl( const QStyleOptionComplex*, QPainter*, const QWidget* ) const;
580
bool drawTitleBarComplexControl( const QStyleOptionComplex*, QPainter*, const QWidget* ) const;
581
bool drawToolButtonComplexControl( const QStyleOptionComplex*, QPainter*, const QWidget* ) const;
584
//! true if widget is child of KTextEdit
585
bool isKTextEditFrame( const QWidget* widget ) const
586
{ return ( widget && widget->parentWidget() && widget->parentWidget()->inherits( "KTextEditor::View" ) ); }
588
//! adjust rect based on provided margins
589
QRect insideMargin( const QRect& r, int main, int left = 0, int top = 0, int right = 0, int bottom = 0 ) const
590
{ return r.adjusted( main+left, main+top, -main-right, -main-bottom ); }
592
//! expand size based on margins
593
QSize expandSize( const QSize& size, int main, int left = 0, int top = 0, int right = 0, int bottom = 0 ) const
594
{ return size + QSize( 2*main+left+right, 2*main+top+bottom ); }
596
//! returns true for vertical tabs
597
bool isVerticalTab( const QStyleOptionTab* option ) const
598
{ return isVerticalTab( option->shape ); }
600
bool isVerticalTab( const QTabBar::Shape& shape ) const
602
return shape == QTabBar::RoundedEast
603
|| shape == QTabBar::RoundedWest
604
|| shape == QTabBar::TriangularEast
605
|| shape == QTabBar::TriangularWest;
609
//! returns true for reflected tabs
610
bool isReflected( const QStyleOptionTab* option ) const
611
{ return isReflected( option->shape ); }
613
bool isReflected( const QTabBar::Shape& shape ) const
615
return shape == QTabBar::RoundedEast
616
|| shape == QTabBar::RoundedSouth
617
|| shape == QTabBar::TriangularEast
618
|| shape == QTabBar::TriangularSouth;
622
//! right to left alignment handling
623
QRect handleRTL(const QStyleOption* opt, const QRect& subRect) const
624
{ return visualRect(opt->direction, opt->rect, subRect); }
626
//! right to left alignment handling
627
QPoint handleRTL(const QStyleOption* opt, const QPoint& pos) const
628
{ return visualPos(opt->direction, opt->rect, pos); }
630
QRect centerRect(const QRect &in, const QSize& s ) const
631
{ return centerRect( in, s.width(), s.height() ); }
633
QRect centerRect(const QRect &in, int w, int h) const
634
{ return QRect(in.x() + (in.width() - w)/2, in.y() + (in.height() - h)/2, w, h); }
637
Checks whether the point is before the bound rect for
638
bound of given orientation
640
inline bool preceeds( const QPoint&, const QRect&, const QStyleOption* ) const;
642
//! return which arrow button is hit by point for scrollbar double buttons
643
inline QStyle::SubControl scrollBarHitTest( const QRect&, const QPoint&, const QStyleOption* ) const;
645
//! polish scrollarea
646
void polishScrollArea( QAbstractScrollArea* ) const;
648
//! tiles from tab orientation
649
inline TileSet::Tiles tilesByShape( const QTabBar::Shape& shape) const;
652
/*! this masks out toolbar expander buttons, when visible, from painting */
653
QRegion tabBarClipRegion( const QTabBar* ) const;
655
//! adjusted slabRect
656
inline void adjustSlabRect( SlabRect& slab, const QRect&, bool documentMode, bool vertical ) const;
658
//!@name internal rendering methods
659
/*! here mostly to avoid code duplication */
663
void renderDialSlab( QPainter* p, const QRect& r, const QColor& c, const QStyleOption* option, StyleOptions opts = 0 ) const
664
{ renderDialSlab( p, r, c, option, opts, -1, AnimationNone ); }
667
void renderDialSlab( QPainter*, const QRect&, const QColor&, const QStyleOption*, StyleOptions, qreal, AnimationMode ) const;
669
//! generic button slab
670
void renderButtonSlab( QPainter* p, QRect r, const QColor& c, StyleOptions opts = 0, TileSet::Tiles tiles = TileSet::Ring) const
671
{ renderButtonSlab( p, r, c, opts, -1, AnimationNone, tiles ); }
673
//! generic button slab
674
void renderButtonSlab( QPainter*, QRect, const QColor&, StyleOptions, qreal, AnimationMode, TileSet::Tiles ) const;
677
void renderSlab( QPainter* painter, const SlabRect& slab, const QColor& color, StyleOptions options = 0 ) const
678
{ renderSlab( painter, slab._r, color, options, slab._tiles ); }
681
void renderSlab( QPainter* painter, QRect rect, const QColor& color, StyleOptions options = 0, TileSet::Tiles tiles = TileSet::Ring) const
682
{ renderSlab( painter, rect, color, options, -1, AnimationNone, tiles ); }
685
void renderSlab( QPainter* painter, const SlabRect& slab, const QColor& color, StyleOptions options, qreal opacity, AnimationMode mode ) const
686
{ renderSlab( painter, slab._r, color, options, opacity, mode, slab._tiles ); }
689
void renderSlab( QPainter*, QRect, const QColor&, StyleOptions, qreal, AnimationMode, TileSet::Tiles ) const;
691
// render tab background
692
void renderTabBackground( QPainter*, const QRect&, const QPalette&, const QTabBar::Shape, const QWidget* ) const;
695
/*! this paints window background behind tab when tab is being dragged */
696
void fillTabBackground( QPainter*, const QRect&, const QColor&, const QTabBar::Shape, const QWidget* ) const;
699
void fillTab( QPainter*, const QRect&, const QColor&, const QTabBar::Shape, bool active ) const;
702
void renderSpinBoxArrow( QPainter*, const QStyleOptionSpinBox*, const QWidget*, const SubControl& ) const;
705
void renderSplitter( const QStyleOption*, QPainter*, const QWidget*, bool ) const;
707
//! mdi subwindow titlebar button
708
void renderTitleBarButton( QPainter*, const QStyleOptionTitleBar*, const QWidget*, const SubControl& ) const;
709
void renderTitleBarIcon( QPainter*, const QRectF&, const SubControl& ) const;
711
//! header background
712
void renderHeaderBackground( const QRect&, const QPalette&, QPainter*, const QWidget*, bool horizontal, bool reverse ) const;
713
void renderHeaderLines( const QRect&, const QPalette&, QPainter*, TileSet::Tiles ) const;
715
//! menu item background
716
void renderMenuItemBackground( const QStyleOption*, QPainter*, const QWidget* ) const;
718
void renderMenuItemRect( const QStyleOption* opt, const QRect& rect, const QPalette& pal, QPainter* p, qreal opacity = -1 ) const
719
{ renderMenuItemRect( opt, rect, pal.color(QPalette::Window), p, opacity ); }
721
void renderMenuItemRect( const QStyleOption*, const QRect&, const QColor&, const QPalette&, QPainter* p, qreal opacity = -1 ) const;
723
//! checkbox state (used for checkboxes _and_ radio buttons)
732
void renderCheckBox( QPainter*, const QRect&, const QPalette&, StyleOptions, CheckBoxState, qreal opacity = -1, AnimationMode mode = AnimationNone ) const;
735
void renderRadioButton( QPainter*, const QRect&, const QPalette&, StyleOptions, CheckBoxState, qreal opacity = -1, AnimationMode mode = AnimationNone ) const;
738
void renderScrollBarHole( QPainter*, const QRect&, const QColor&, const Qt::Orientation&, const TileSet::Tiles& = TileSet::Full ) const;
740
//! scrollbar handle (non animated)
741
void renderScrollBarHandle(
742
QPainter* painter, const QRect& r, const QPalette& palette,
743
const Qt::Orientation& orientation, const bool& hover) const
744
{ renderScrollBarHandle( painter, r, palette, orientation, hover, -1 ); }
746
//! scrollbar handle (animated)
747
void renderScrollBarHandle( QPainter*, const QRect&, const QPalette&, const Qt::Orientation&, const bool&, const qreal& ) const;
750
void renderScrollBarArrow( QPainter*, const QRect&, const QColor&, const QColor&, ArrowOrientation ) const;
752
//! returns true if given scrollbar arrow is animated
753
QColor scrollBarArrowColor( const QStyleOption*, const SubControl&, const QWidget* ) const;
756
void renderSliderTickmarks( QPainter*, const QStyleOptionSlider*, const QWidget* ) const;
760
//! slab glowing color
761
QColor slabShadowColor( QColor, StyleOptions, qreal, AnimationMode ) const;
763
//! returns point position for generic arrows
764
QPolygonF genericArrow( ArrowOrientation, ArrowSize = ArrowNormal ) const;
766
//! scrollbar buttons
767
enum ScrollBarButtonType
774
//! returns height for scrollbar buttons depending of button types
775
int scrollBarButtonHeight( const ScrollBarButtonType& type ) const
779
case NoButton: return _noButtonHeight;
780
case SingleButton: return _singleButtonHeight;
781
case DoubleButton: return _doubleButtonHeight;
786
//!@name custom elemenents
790
int newStyleElement( const QString &element, const char *check, int &counter )
793
if( !element.contains(check) ) return 0;
794
int id = _styleElements.value(element, 0);
799
_styleElements.insert(element, id);
805
QStyle::StyleHint newStyleHint( const QString &element )
806
{ return (StyleHint) newStyleElement( element, "SH_", _hintCounter ); }
809
QStyle::ControlElement newControlElement( const QString &element )
810
{ return (ControlElement)newStyleElement( element, "CE_", _controlCounter ); }
813
QStyle::SubElement newSubElement(const QString &element )
814
{ return (SubElement)newStyleElement( element, "SE_", _subElementCounter ); }
820
//! true if KGlobalSettings signals are initialized
821
bool _kGlobalSettingsInitialized;
823
//! scrollbar button types (for addLine and subLine )
824
ScrollBarButtonType _addLineButtons;
825
ScrollBarButtonType _subLineButtons;
827
//! metrics for scrollbar buttons
829
int _singleButtonHeight;
830
int _doubleButtonHeight;
832
//! true if keyboard accelerators must be drawn
836
StyleHelper* _helper;
839
ShadowHelper* _shadowHelper;
842
Animations* _animations;
845
Transitions* _transitions;
848
WindowManager* _windowManager;
851
TopLevelManager* _topLevelManager;
854
FrameShadowFactory* _frameShadowFactory;
856
//! mdi window shadows
857
MdiWindowShadowFactory* _mdiWindowShadowFactory;
860
WidgetExplorer* _widgetExplorer;
863
TabBarData* _tabBarData;
865
//! pointer to primitive specialized function
866
typedef bool (Style::*StylePrimitive)( const QStyleOption*, QPainter*, const QWidget* ) const;
867
StylePrimitive _frameFocusPrimitive;
869
//! pointer to control specialized function
870
typedef bool (Style::*StyleControl)( const QStyleOption*, QPainter*, const QWidget* ) const;
871
StyleControl _tabBarTabShapeControl;
873
//! pointer to control specialized function
874
typedef bool (Style::*StyleComplexControl)( const QStyleOptionComplex*, QPainter*, const QWidget* ) const;
876
//!@name custom elements
881
int _subElementCounter;
882
QHash<QString, int> _styleElements;
884
QStyle::ControlElement CE_CapacityBar;
890
//_________________________________________________________________________
891
bool Style::preceeds( const QPoint& point, const QRect& bound, const QStyleOption* option ) const
893
if( option->state&QStyle::State_Horizontal)
896
if( option->direction == Qt::LeftToRight) return point.x() < bound.right();
897
else return point.x() > bound.x();
899
} else return point.y() < bound.y();
903
//_________________________________________________________________________
904
QStyle::SubControl Style::scrollBarHitTest( const QRect& rect, const QPoint& point, const QStyleOption* option ) const
906
if( option->state & QStyle::State_Horizontal)
909
if( option->direction == Qt::LeftToRight ) return point.x() < rect.center().x() ? QStyle::SC_ScrollBarSubLine : QStyle::SC_ScrollBarAddLine;
910
else return point.x() > rect.center().x() ? QStyle::SC_ScrollBarSubLine : QStyle::SC_ScrollBarAddLine;
911
} else return point.y() < rect.center().y() ? QStyle::SC_ScrollBarSubLine : QStyle::SC_ScrollBarAddLine;
914
//_____________________________________________________________
915
TileSet::Tiles Style::tilesByShape( const QTabBar::Shape& shape ) const
920
case QTabBar::RoundedNorth:
921
case QTabBar::TriangularNorth:
922
return TileSet::Top | TileSet::Left | TileSet::Right;
924
case QTabBar::RoundedSouth:
925
case QTabBar::TriangularSouth:
926
return TileSet::Bottom | TileSet::Left | TileSet::Right;
928
case QTabBar::RoundedEast:
929
case QTabBar::TriangularEast:
930
return TileSet::Right | TileSet::Top | TileSet::Bottom;
932
case QTabBar::RoundedWest:
933
case QTabBar::TriangularWest:
934
return TileSet::Left | TileSet::Top | TileSet::Bottom;
937
return TileSet::Ring;
943
//___________________________________________________________________________________
944
void Style::adjustSlabRect( SlabRect& slab, const QRect& tabWidgetRect, bool documentMode, bool vertical ) const
947
// no tabWidget found, do nothing
948
if( documentMode || !tabWidgetRect.isValid() ) return;
952
slab._r.setTop( qMax( slab._r.top(), tabWidgetRect.top() ) );
953
slab._r.setBottom( qMin( slab._r.bottom(), tabWidgetRect.bottom() ) );
957
slab._r.setLeft( qMax( slab._r.left(), tabWidgetRect.left() ) );
958
slab._r.setRight( qMin( slab._r.right(), tabWidgetRect.right() ) );