~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to kstyles/oxygen/oxygenstyle.h

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef oxygenstyle_h
 
2
#define oxygenstyle_h
 
3
 
 
4
//////////////////////////////////////////////////////////////////////////////
 
5
// oxygenstyle.h
 
6
// Oxygen widget style for KDE 4
 
7
// -------------------
 
8
//
 
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>
 
14
//
 
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.
 
21
//
 
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>
 
34
//
 
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.
 
38
//
 
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.
 
43
//
 
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
//////////////////////////////////////////////////////////////////////////////
 
49
 
 
50
#include "oxygenanimationmodes.h"
 
51
#include "oxygenmetrics.h"
 
52
#include "oxygentileset.h"
 
53
 
 
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>
 
63
 
 
64
namespace Oxygen
 
65
{
 
66
 
 
67
    class Animations;
 
68
    class FrameShadowFactory;
 
69
    class MdiWindowShadowFactory;
 
70
    class ShadowHelper;
 
71
    class StyleHelper;
 
72
    class Transitions;
 
73
    class WindowManager;
 
74
    class WidgetExplorer;
 
75
 
 
76
    //! toplevel manager
 
77
    class TopLevelManager: public QObject
 
78
    {
 
79
        public:
 
80
 
 
81
        //! constructor
 
82
        TopLevelManager( QObject* parent, const StyleHelper& helper ):
 
83
            QObject( parent ),
 
84
            _helper( helper )
 
85
        {}
 
86
 
 
87
        //! event filter
 
88
        virtual bool eventFilter(QObject *, QEvent *);
 
89
 
 
90
        private:
 
91
 
 
92
        //! helper
 
93
        const StyleHelper& _helper;
 
94
 
 
95
    };
 
96
 
 
97
 
 
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
 
101
    {
 
102
        Q_OBJECT
 
103
 
 
104
        /* this tells kde applications that custom style elements are supported, using the kstyle mechanism */
 
105
        Q_CLASSINFO ("X-KDE-CustomElements", "true")
 
106
 
 
107
        public:
 
108
 
 
109
        //! constructor
 
110
        explicit Style( void );
 
111
 
 
112
        //! destructor
 
113
        virtual ~Style( void );
 
114
 
 
115
        //! widget polishing/unpolishing
 
116
        virtual void polish( QWidget* );
 
117
 
 
118
        //! widget polishing/unpolishing
 
119
        virtual void unpolish( QWidget* );
 
120
 
 
121
        //! needed to avoid warnings at compilation time
 
122
        using  QCommonStyle::polish;
 
123
        using  QCommonStyle::unpolish;
 
124
 
 
125
        //! pixel metrics
 
126
        virtual int pixelMetric(PixelMetric, const QStyleOption* = 0, const QWidget* = 0) const;
 
127
 
 
128
        //! style hints
 
129
        virtual int styleHint(StyleHint, const QStyleOption* = 0, const QWidget* = 0, QStyleHintReturn* = 0) const;
 
130
 
 
131
        //! returns rect corresponding to one widget's subelement
 
132
        virtual QRect subElementRect( SubElement subRect, const QStyleOption*, const QWidget* ) const;
 
133
 
 
134
        //! returns rect corresponding to one widget's subcontrol
 
135
        virtual QRect subControlRect( ComplexControl, const QStyleOptionComplex*, SubControl, const QWidget* ) const;
 
136
 
 
137
        //! returns size matching contents
 
138
        QSize sizeFromContents( ContentsType, const QStyleOption*, const QSize&, const QWidget* ) const;
 
139
 
 
140
        //! returns which subcontrol given QPoint corresponds to
 
141
        SubControl hitTestComplexControl( ComplexControl, const QStyleOptionComplex*, const QPoint&, const QWidget* ) const;
 
142
 
 
143
        //! primitives
 
144
        void drawPrimitive( PrimitiveElement, const QStyleOption*, QPainter*, const QWidget* ) const;
 
145
 
 
146
        //! controls
 
147
        void drawControl( ControlElement, const QStyleOption*, QPainter*, const QWidget* ) const;
 
148
 
 
149
        //! complex controls
 
150
        void drawComplexControl( ComplexControl, const QStyleOptionComplex*, QPainter*, const QWidget* ) const;
 
151
 
 
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;
 
156
 
 
157
        //! event filters
 
158
        virtual bool eventFilter(QObject *, QEvent *);
 
159
 
 
160
        //!@name specialized event filters
 
161
        /*!
 
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
 
165
        */
 
166
 
 
167
        //@{
 
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* );
 
177
 
 
178
        //! install event filter to object, in a unique way
 
179
        void addEventFilter( QObject* object )
 
180
        {
 
181
            object->removeEventFilter( this );
 
182
            object->installEventFilter( this );
 
183
        }
 
184
 
 
185
        //@}
 
186
 
 
187
        protected slots:
 
188
 
 
189
        //! update oxygen configuration
 
190
        void oxygenConfigurationChanged( void );
 
191
 
 
192
        //! needed to update style when configuration is changed
 
193
        void globalPaletteChanged( void );
 
194
 
 
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); }
 
200
 
 
201
        //! standard icons
 
202
        virtual QIcon standardIconImplementation(
 
203
            StandardPixmap standardIcon,
 
204
            const QStyleOption *option,
 
205
            const QWidget *widget) const;
 
206
 
 
207
        protected:
 
208
 
 
209
        //! initialize kGlobalSettings conections
 
210
        void initializeKGlobalSettings( void );
 
211
 
 
212
        //! helper
 
213
        StyleHelper& helper( void ) const
 
214
        { return *_helper; }
 
215
 
 
216
        //! shadow Helper
 
217
        ShadowHelper& shadowHelper( void ) const
 
218
        { return *_shadowHelper; }
 
219
 
 
220
        //!@name enumerations and convenience classes
 
221
        //@{
 
222
 
 
223
        //! arrow orientation
 
224
        enum ArrowOrientation
 
225
        {
 
226
            ArrowNone,
 
227
            ArrowUp,
 
228
            ArrowDown,
 
229
            ArrowLeft,
 
230
            ArrowRight
 
231
        };
 
232
 
 
233
 
 
234
        //! get polygon corresponding to generic arrow
 
235
        enum ArrowSize
 
236
        {
 
237
            ArrowNormal,
 
238
            ArrowSmall,
 
239
            ArrowTiny
 
240
        };
 
241
 
 
242
        //! internal option flags to pass arguments around
 
243
        enum StyleOption
 
244
        {
 
245
            Sunken = 0x1,
 
246
            Focus = 0x2,
 
247
            Hover = 0x4,
 
248
            Disabled = 0x8,
 
249
            NoFill = 0x10,
 
250
            SubtleShadow = 0x20
 
251
        };
 
252
 
 
253
        Q_DECLARE_FLAGS(StyleOptions, StyleOption)
 
254
 
 
255
        //! used to store slab characteristics
 
256
        class SlabRect
 
257
        {
 
258
            public:
 
259
 
 
260
            //! constructor
 
261
            SlabRect(void):
 
262
                _tiles( TileSet::Ring )
 
263
            {}
 
264
 
 
265
            //! constructor
 
266
            SlabRect( const QRect& r, const int& tiles ):
 
267
                _r( r ),
 
268
                _tiles( TileSet::Tiles( tiles ) )
 
269
            {}
 
270
 
 
271
            QRect _r;
 
272
            TileSet::Tiles _tiles;
 
273
 
 
274
        };
 
275
 
 
276
        //! list of slabs
 
277
        typedef QList<SlabRect> SlabRectList;
 
278
 
 
279
        /*!
 
280
        tabBar data class needed for
 
281
        the rendering of tabbars when
 
282
        one tab is being drawn
 
283
        */
 
284
        class TabBarData: public QObject
 
285
        {
 
286
 
 
287
            public:
 
288
 
 
289
            //! constructor
 
290
            TabBarData( Style* parent ):
 
291
                QObject( parent ),
 
292
                _style( parent ),
 
293
                _dirty( false )
 
294
            {}
 
295
 
 
296
            //! destructor
 
297
            virtual ~TabBarData( void )
 
298
            {}
 
299
 
 
300
            //! assign target tabBar
 
301
            void lock( const QWidget* widget )
 
302
            { _tabBar = widget; }
 
303
 
 
304
            //! true if tabbar is locked
 
305
            bool locks( const QWidget* widget ) const
 
306
            { return _tabBar && _tabBar.data() == widget; }
 
307
 
 
308
            //! set dirty
 
309
            void setDirty( const bool& value = true )
 
310
            { _dirty = value; }
 
311
 
 
312
            //! release
 
313
            void release( void )
 
314
            { _tabBar.clear(); }
 
315
 
 
316
            //! draw tabBarBase
 
317
            virtual void drawTabBarBaseControl( const QStyleOptionTab*, QPainter*, const QWidget* );
 
318
 
 
319
            private:
 
320
 
 
321
            //! pointer to parent style object
 
322
            QWeakPointer<const Style> _style;
 
323
 
 
324
            //! pointer to target tabBar
 
325
            QWeakPointer<const QWidget> _tabBar;
 
326
 
 
327
            //! if true, will paint on next TabBarTabShapeControlCall
 
328
            bool _dirty;
 
329
 
 
330
        };
 
331
 
 
332
        //@}
 
333
 
 
334
        //! animations
 
335
        Animations& animations( void ) const
 
336
        { return *_animations; }
 
337
 
 
338
        Transitions& transitions( void ) const
 
339
        { return *_transitions; }
 
340
 
 
341
        //! window manager
 
342
        WindowManager& windowManager( void ) const
 
343
        { return *_windowManager; }
 
344
 
 
345
        //! frame shadows
 
346
        FrameShadowFactory& frameShadowFactory( void ) const
 
347
        { return *_frameShadowFactory; }
 
348
 
 
349
        //! mdi window shadows
 
350
        MdiWindowShadowFactory& mdiWindowShadowFactory( void ) const
 
351
        { return *_mdiWindowShadowFactory; }
 
352
 
 
353
        //! widget explorer
 
354
        /*!
 
355
        this is used for debugging. Provides information about
 
356
        widgets, widgets' geometry, and ancestry tree
 
357
        */
 
358
        WidgetExplorer& widgetExplorer( void ) const
 
359
        { return *_widgetExplorer; }
 
360
 
 
361
        //! tabBar data
 
362
        TabBarData& tabBarData( void ) const
 
363
        { return *_tabBarData; }
 
364
 
 
365
        //!@name subelementRect specialized functions
 
366
        //@{
 
367
 
 
368
        //! default implementation. Does not change anything
 
369
        QRect defaultSubElementRect( const QStyleOption* option, const QWidget* ) const
 
370
        { return option->rect; }
 
371
 
 
372
        //! pushbutton contents
 
373
        QRect pushButtonContentsRect( const QStyleOption* option, const QWidget* ) const
 
374
        {
 
375
            return insideMargin( option->rect,
 
376
                PushButton_ContentsMargin,
 
377
                PushButton_ContentsMargin_Left,
 
378
                PushButton_ContentsMargin_Top,
 
379
                PushButton_ContentsMargin_Right,
 
380
                PushButton_ContentsMargin_Bottom );
 
381
        }
 
382
 
 
383
        //! toolbox tab
 
384
        QRect toolBoxTabContentsRect( const QStyleOption* option, const QWidget* ) const
 
385
        { return insideMargin( option->rect, 0, 5, 0, 5, 0 ); }
 
386
 
 
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 ) ); }
 
390
 
 
391
        //! progressbar contents
 
392
        QRect progressBarContentsRect( const QStyleOption* option, const QWidget* ) const;
 
393
 
 
394
        //! tabBar buttons
 
395
        QRect tabBarTabLeftButtonRect( const QStyleOption* option, const QWidget* widget ) const
 
396
        { return tabBarTabButtonRect( SE_TabBarTabLeftButton, option, widget ); }
 
397
 
 
398
        QRect tabBarTabRightButtonRect( const QStyleOption* option, const QWidget* widget ) const
 
399
        { return tabBarTabButtonRect( SE_TabBarTabRightButton, option, widget ); }
 
400
 
 
401
        QRect tabBarTabButtonRect( SubElement, const QStyleOption*, const QWidget* ) const;
 
402
 
 
403
        // tabbar tab text
 
404
        QRect tabBarTabTextRect( const QStyleOption* option, const QWidget* widget ) const
 
405
        { return QCommonStyle::subElementRect( SE_TabBarTabText, option, widget ).adjusted( 6, 0, -6, 0 ); }
 
406
 
 
407
        // tab widgets
 
408
        QRect tabWidgetTabContentsRect( const QStyleOption*, const QWidget* ) const;
 
409
        QRect tabWidgetTabPaneRect( const QStyleOption*, const QWidget* ) const;
 
410
 
 
411
        QRect tabWidgetLeftCornerRect( const QStyleOption* option, const QWidget* widget ) const;
 
412
        QRect tabWidgetRightCornerRect( const QStyleOption* option, const QWidget* widget ) const;
 
413
 
 
414
        //@}
 
415
 
 
416
        //!@name subcontrol Rect specialized functions
 
417
        //@{
 
418
 
 
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;
 
424
 
 
425
        //! this properly handles single/double or no scrollBar buttons
 
426
        QRect scrollBarInternalSubControlRect( const QStyleOptionComplex*, SubControl ) const;
 
427
 
 
428
        //@}
 
429
 
 
430
        //!@name sizeFromContents
 
431
        //@{
 
432
 
 
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;
 
436
 
 
437
        QSize menuBarSizeFromContents( const QStyleOption*, const QSize& size, const QWidget* ) const
 
438
        { return size; }
 
439
 
 
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 ); }
 
442
 
 
443
        QSize menuItemSizeFromContents( const QStyleOption*, const QSize&, const QWidget* ) const;
 
444
        QSize pushButtonSizeFromContents( const QStyleOption*, const QSize&, const QWidget* ) const;
 
445
 
 
446
        QSize tabWidgetSizeFromContents( const QStyleOption*, const QSize& size, const QWidget* ) const
 
447
        { return expandSize( size, TabWidget_ContentsMargin - 2 ); }
 
448
 
 
449
        QSize tabBarTabSizeFromContents( const QStyleOption*, const QSize& size, const QWidget* ) const;
 
450
        QSize toolButtonSizeFromContents( const QStyleOption*, const QSize&, const QWidget* ) const;
 
451
 
 
452
        //@}
 
453
 
 
454
        //!@name primitives specialized functions
 
455
        //@{
 
456
 
 
457
        bool emptyPrimitive( const QStyleOption*, QPainter*, const QWidget* ) const
 
458
        { return true; }
 
459
 
 
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;
 
467
 
 
468
        bool drawIndicatorArrowUpPrimitive( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
 
469
        { return drawIndicatorArrowPrimitive( ArrowUp, option, painter, widget ); }
 
470
 
 
471
        bool drawIndicatorArrowDownPrimitive( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
 
472
        { return drawIndicatorArrowPrimitive( ArrowDown, option, painter, widget ); }
 
473
 
 
474
        bool drawIndicatorArrowLeftPrimitive( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
 
475
        { return drawIndicatorArrowPrimitive( ArrowLeft, option, painter, widget ); }
 
476
 
 
477
        bool drawIndicatorArrowRightPrimitive( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
 
478
        { return drawIndicatorArrowPrimitive( ArrowRight, option, painter, widget ); }
 
479
 
 
480
        bool drawIndicatorArrowPrimitive( ArrowOrientation, const QStyleOption*, QPainter*, const QWidget* ) const;
 
481
 
 
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
 
485
        {
 
486
 
 
487
            renderSplitter( option, painter, widget, !(option->state & State_Horizontal ) );
 
488
            return true;
 
489
 
 
490
        }
 
491
 
 
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;
 
510
 
 
511
        bool drawWidgetPrimitive( const QStyleOption*, QPainter*, const QWidget* ) const;
 
512
 
 
513
        //@}
 
514
 
 
515
        //!@name controls specialized functions
 
516
        //@{
 
517
 
 
518
        bool emptyControl( const QStyleOption*, QPainter*, const QWidget* ) const
 
519
        { return true; }
 
520
 
 
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;
 
535
 
 
536
        //! scrollbar
 
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;
 
542
 
 
543
        virtual bool drawShapedFrameControl( const QStyleOption*, QPainter*, const QWidget* ) const;
 
544
 
 
545
        // size grip
 
546
        virtual bool drawSizeGripControl( const QStyleOption*, QPainter*, const QWidget* ) const
 
547
        {
 
548
            // size grips, whose usage is discouraged in KDE, are not rendered at all by oxygen
 
549
            return true;
 
550
        }
 
551
 
 
552
        // splitters
 
553
        virtual bool drawSplitterControl( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const
 
554
        {
 
555
            renderSplitter( option, painter, widget, option->state & State_Horizontal );
 
556
            return true;
 
557
        }
 
558
 
 
559
        virtual bool drawTabBarTabLabelControl( const QStyleOption*, QPainter*, const QWidget* ) const;
 
560
 
 
561
        //! tabbar tabs.
 
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;
 
569
 
 
570
        //!@}
 
571
 
 
572
        //!@name complex ontrols specialized functions
 
573
        //@{
 
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;
 
582
        //@}
 
583
 
 
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" ) ); }
 
587
 
 
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 ); }
 
591
 
 
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 ); }
 
595
 
 
596
        //! returns true for vertical tabs
 
597
        bool isVerticalTab( const QStyleOptionTab* option ) const
 
598
        { return isVerticalTab( option->shape ); }
 
599
 
 
600
        bool isVerticalTab( const QTabBar::Shape& shape ) const
 
601
        {
 
602
            return shape == QTabBar::RoundedEast
 
603
                || shape == QTabBar::RoundedWest
 
604
                || shape == QTabBar::TriangularEast
 
605
                || shape == QTabBar::TriangularWest;
 
606
 
 
607
        }
 
608
 
 
609
        //! returns true for reflected tabs
 
610
        bool isReflected( const QStyleOptionTab* option ) const
 
611
        { return isReflected( option->shape ); }
 
612
 
 
613
        bool isReflected( const QTabBar::Shape& shape ) const
 
614
        {
 
615
            return shape == QTabBar::RoundedEast
 
616
                || shape == QTabBar::RoundedSouth
 
617
                || shape == QTabBar::TriangularEast
 
618
                || shape == QTabBar::TriangularSouth;
 
619
 
 
620
        }
 
621
 
 
622
        //! right to left alignment handling
 
623
        QRect handleRTL(const QStyleOption* opt, const QRect& subRect) const
 
624
        { return visualRect(opt->direction, opt->rect, subRect); }
 
625
 
 
626
        //! right to left alignment handling
 
627
        QPoint handleRTL(const QStyleOption* opt, const QPoint& pos) const
 
628
        { return visualPos(opt->direction, opt->rect, pos); }
 
629
 
 
630
        QRect centerRect(const QRect &in, const QSize& s ) const
 
631
        { return centerRect( in, s.width(), s.height() ); }
 
632
 
 
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); }
 
635
 
 
636
        /*
 
637
        Checks whether the point is before the bound rect for
 
638
        bound of given orientation
 
639
        */
 
640
        inline bool preceeds( const QPoint&, const QRect&, const QStyleOption* ) const;
 
641
 
 
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;
 
644
 
 
645
        //! polish scrollarea
 
646
        void polishScrollArea( QAbstractScrollArea* ) const;
 
647
 
 
648
        //! tiles from tab orientation
 
649
        inline TileSet::Tiles tilesByShape( const QTabBar::Shape& shape) const;
 
650
 
 
651
        //! toolbar mask
 
652
        /*! this masks out toolbar expander buttons, when visible, from painting */
 
653
        QRegion tabBarClipRegion( const QTabBar* ) const;
 
654
 
 
655
        //! adjusted slabRect
 
656
        inline void adjustSlabRect( SlabRect& slab, const QRect&, bool documentMode, bool vertical ) const;
 
657
 
 
658
        //!@name internal rendering methods
 
659
        /*! here mostly to avoid code duplication */
 
660
        //@{
 
661
 
 
662
        //! qdial slab
 
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 ); }
 
665
 
 
666
        //! qdial slab
 
667
        void renderDialSlab( QPainter*, const QRect&, const QColor&, const QStyleOption*, StyleOptions, qreal, AnimationMode ) const;
 
668
 
 
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 ); }
 
672
 
 
673
        //! generic button slab
 
674
        void renderButtonSlab( QPainter*, QRect, const QColor&, StyleOptions, qreal, AnimationMode, TileSet::Tiles ) const;
 
675
 
 
676
        //! generic slab
 
677
        void renderSlab( QPainter* painter, const SlabRect& slab, const QColor& color, StyleOptions options = 0 ) const
 
678
        { renderSlab( painter, slab._r, color, options, slab._tiles ); }
 
679
 
 
680
        //! generic slab
 
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 ); }
 
683
 
 
684
        //! generic slab
 
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 ); }
 
687
 
 
688
        //! generic slab
 
689
        void renderSlab( QPainter*, QRect, const QColor&, StyleOptions, qreal, AnimationMode, TileSet::Tiles ) const;
 
690
 
 
691
        // render tab background
 
692
        void renderTabBackground( QPainter*, const QRect&, const QPalette&, const QTabBar::Shape, const QWidget* ) const;
 
693
 
 
694
        //! tab background
 
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;
 
697
 
 
698
        //! tab filling
 
699
        void fillTab( QPainter*, const QRect&, const QColor&, const QTabBar::Shape, bool active ) const;
 
700
 
 
701
        //! spinbox arrows
 
702
        void renderSpinBoxArrow( QPainter*, const QStyleOptionSpinBox*, const QWidget*, const SubControl& ) const;
 
703
 
 
704
        //! splitter
 
705
        void renderSplitter( const QStyleOption*, QPainter*, const QWidget*, bool ) const;
 
706
 
 
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;
 
710
 
 
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;
 
714
 
 
715
        //! menu item background
 
716
        void renderMenuItemBackground( const QStyleOption*, QPainter*, const QWidget* ) const;
 
717
 
 
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 ); }
 
720
 
 
721
        void renderMenuItemRect( const QStyleOption*, const QRect&, const QColor&, const QPalette&, QPainter* p, qreal opacity = -1 ) const;
 
722
 
 
723
        //! checkbox state (used for checkboxes _and_ radio buttons)
 
724
        enum CheckBoxState
 
725
        {
 
726
            CheckOn,
 
727
            CheckOff,
 
728
            CheckTriState
 
729
        };
 
730
 
 
731
        //! checkbox
 
732
        void renderCheckBox( QPainter*, const QRect&, const QPalette&, StyleOptions, CheckBoxState, qreal opacity = -1, AnimationMode mode = AnimationNone ) const;
 
733
 
 
734
        //! radio button
 
735
        void renderRadioButton( QPainter*, const QRect&, const QPalette&, StyleOptions, CheckBoxState, qreal opacity = -1, AnimationMode mode = AnimationNone ) const;
 
736
 
 
737
        //! scrollbar hole
 
738
        void renderScrollBarHole( QPainter*, const QRect&, const QColor&, const Qt::Orientation&, const TileSet::Tiles& = TileSet::Full ) const;
 
739
 
 
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 ); }
 
745
 
 
746
        //! scrollbar handle (animated)
 
747
        void renderScrollBarHandle( QPainter*, const QRect&, const QPalette&, const Qt::Orientation&, const bool&, const qreal& ) const;
 
748
 
 
749
        //! scrollbar arrow
 
750
        void renderScrollBarArrow( QPainter*, const QRect&, const QColor&, const QColor&, ArrowOrientation ) const;
 
751
 
 
752
        //! returns true if given scrollbar arrow is animated
 
753
        QColor scrollBarArrowColor( const QStyleOption*, const SubControl&, const QWidget* ) const;
 
754
 
 
755
        //! slider tickmarks
 
756
        void renderSliderTickmarks( QPainter*, const QStyleOptionSlider*, const QWidget* ) const;
 
757
 
 
758
        //@}
 
759
 
 
760
        //! slab glowing color
 
761
        QColor slabShadowColor( QColor, StyleOptions, qreal, AnimationMode ) const;
 
762
 
 
763
        //! returns point position for generic arrows
 
764
        QPolygonF genericArrow( ArrowOrientation, ArrowSize = ArrowNormal ) const;
 
765
 
 
766
        //! scrollbar buttons
 
767
        enum ScrollBarButtonType
 
768
        {
 
769
            NoButton,
 
770
            SingleButton,
 
771
            DoubleButton
 
772
        };
 
773
 
 
774
        //! returns height for scrollbar buttons depending of button types
 
775
        int scrollBarButtonHeight( const ScrollBarButtonType& type ) const
 
776
        {
 
777
            switch( type )
 
778
            {
 
779
                case NoButton: return _noButtonHeight;
 
780
                case SingleButton: return _singleButtonHeight;
 
781
                case DoubleButton: return _doubleButtonHeight;
 
782
                default: return 0;
 
783
            }
 
784
        }
 
785
 
 
786
        //!@name custom elemenents
 
787
        //@{
 
788
 
 
789
        //! generic element
 
790
        int newStyleElement( const QString &element, const char *check, int &counter )
 
791
        {
 
792
 
 
793
            if( !element.contains(check) ) return 0;
 
794
            int id = _styleElements.value(element, 0);
 
795
            if( !id )
 
796
            {
 
797
                ++counter;
 
798
                id = counter;
 
799
                _styleElements.insert(element, id);
 
800
            }
 
801
            return id;
 
802
        }
 
803
 
 
804
        //! style hint
 
805
        QStyle::StyleHint newStyleHint( const QString &element )
 
806
        { return (StyleHint) newStyleElement( element, "SH_", _hintCounter ); }
 
807
 
 
808
        //! control element
 
809
        QStyle::ControlElement newControlElement( const QString &element )
 
810
        { return (ControlElement)newStyleElement( element, "CE_", _controlCounter ); }
 
811
 
 
812
        //! subElement
 
813
        QStyle::SubElement newSubElement(const QString &element )
 
814
        { return (SubElement)newStyleElement( element, "SE_", _subElementCounter ); }
 
815
 
 
816
        //@}
 
817
 
 
818
        private:
 
819
 
 
820
        //! true if KGlobalSettings signals are initialized
 
821
        bool _kGlobalSettingsInitialized;
 
822
 
 
823
        //! scrollbar button types (for addLine and subLine )
 
824
        ScrollBarButtonType _addLineButtons;
 
825
        ScrollBarButtonType _subLineButtons;
 
826
 
 
827
        //! metrics for scrollbar buttons
 
828
        int _noButtonHeight;
 
829
        int _singleButtonHeight;
 
830
        int _doubleButtonHeight;
 
831
 
 
832
        //! true if keyboard accelerators must be drawn
 
833
        bool _showMnemonics;
 
834
 
 
835
        //! helper
 
836
        StyleHelper* _helper;
 
837
 
 
838
        //! shadow helper
 
839
        ShadowHelper* _shadowHelper;
 
840
 
 
841
        //! animations
 
842
        Animations* _animations;
 
843
 
 
844
        //! transitions
 
845
        Transitions* _transitions;
 
846
 
 
847
        //! window manager
 
848
        WindowManager* _windowManager;
 
849
 
 
850
        //! toplevel manager
 
851
        TopLevelManager* _topLevelManager;
 
852
 
 
853
        //! frame shadows
 
854
        FrameShadowFactory* _frameShadowFactory;
 
855
 
 
856
        //! mdi window shadows
 
857
        MdiWindowShadowFactory* _mdiWindowShadowFactory;
 
858
 
 
859
        //! widget explorer
 
860
        WidgetExplorer* _widgetExplorer;
 
861
 
 
862
        //! tabBar data
 
863
        TabBarData* _tabBarData;
 
864
 
 
865
        //! pointer to primitive specialized function
 
866
        typedef bool (Style::*StylePrimitive)( const QStyleOption*, QPainter*, const QWidget* ) const;
 
867
        StylePrimitive _frameFocusPrimitive;
 
868
 
 
869
        //! pointer to control specialized function
 
870
        typedef bool (Style::*StyleControl)( const QStyleOption*, QPainter*, const QWidget* ) const;
 
871
        StyleControl _tabBarTabShapeControl;
 
872
 
 
873
        //! pointer to control specialized function
 
874
        typedef bool (Style::*StyleComplexControl)( const QStyleOptionComplex*, QPainter*, const QWidget* ) const;
 
875
 
 
876
        //!@name custom elements
 
877
        //@{
 
878
 
 
879
        int _hintCounter;
 
880
        int _controlCounter;
 
881
        int _subElementCounter;
 
882
        QHash<QString, int> _styleElements;
 
883
 
 
884
        QStyle::ControlElement CE_CapacityBar;
 
885
 
 
886
        //@}
 
887
 
 
888
    };
 
889
 
 
890
    //_________________________________________________________________________
 
891
    bool Style::preceeds( const QPoint& point, const QRect& bound, const QStyleOption* option ) const
 
892
    {
 
893
        if( option->state&QStyle::State_Horizontal)
 
894
        {
 
895
 
 
896
            if( option->direction == Qt::LeftToRight) return point.x() < bound.right();
 
897
            else return point.x() > bound.x();
 
898
 
 
899
        } else return point.y() < bound.y();
 
900
 
 
901
    }
 
902
 
 
903
    //_________________________________________________________________________
 
904
    QStyle::SubControl Style::scrollBarHitTest( const QRect& rect, const QPoint& point, const QStyleOption* option ) const
 
905
    {
 
906
        if( option->state & QStyle::State_Horizontal)
 
907
        {
 
908
 
 
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;
 
912
    }
 
913
 
 
914
    //_____________________________________________________________
 
915
    TileSet::Tiles Style::tilesByShape( const QTabBar::Shape& shape ) const
 
916
    {
 
917
        switch( shape )
 
918
        {
 
919
 
 
920
            case QTabBar::RoundedNorth:
 
921
            case QTabBar::TriangularNorth:
 
922
            return TileSet::Top | TileSet::Left | TileSet::Right;
 
923
 
 
924
            case QTabBar::RoundedSouth:
 
925
            case QTabBar::TriangularSouth:
 
926
            return TileSet::Bottom | TileSet::Left | TileSet::Right;
 
927
 
 
928
            case QTabBar::RoundedEast:
 
929
            case QTabBar::TriangularEast:
 
930
            return TileSet::Right | TileSet::Top | TileSet::Bottom;
 
931
 
 
932
            case QTabBar::RoundedWest:
 
933
            case QTabBar::TriangularWest:
 
934
            return TileSet::Left | TileSet::Top | TileSet::Bottom;
 
935
 
 
936
            default:
 
937
            return TileSet::Ring;
 
938
 
 
939
        }
 
940
 
 
941
    }
 
942
 
 
943
    //___________________________________________________________________________________
 
944
    void Style::adjustSlabRect( SlabRect& slab, const QRect& tabWidgetRect, bool documentMode, bool vertical ) const
 
945
    {
 
946
 
 
947
        // no tabWidget found, do nothing
 
948
        if( documentMode || !tabWidgetRect.isValid() ) return;
 
949
        else if( vertical )
 
950
        {
 
951
 
 
952
            slab._r.setTop( qMax( slab._r.top(), tabWidgetRect.top() ) );
 
953
            slab._r.setBottom( qMin( slab._r.bottom(), tabWidgetRect.bottom() ) );
 
954
 
 
955
        } else {
 
956
 
 
957
            slab._r.setLeft( qMax( slab._r.left(), tabWidgetRect.left() ) );
 
958
            slab._r.setRight( qMin( slab._r.right(), tabWidgetRect.right() ) );
 
959
 
 
960
        }
 
961
 
 
962
        return;
 
963
    }
 
964
 
 
965
 
 
966
}
 
967
 
 
968
#endif