1
#ifndef oxygen_style_helper_h
2
#define oxygen_style_helper_h
5
* Copyright 2010 Hugo Pereira Da Costa <hugo@oxygen-icons.org>
6
* Copyright 2008 Long Huynh Huu <long.upcase@googlemail.com>
7
* Copyright 2007 Matthew Woehlke <mw_triad@users.sourceforge.net>
8
* Copyright 2007 Casper Boemann <cbr@boemann.dk>
10
* This library is free software; you can redistribute it and/or
11
* modify it under the terms of the GNU Library General Public
12
* License version 2 as published by the Free Software Foundation.
14
* This library is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
* Library General Public License for more details.
19
* You should have received a copy of the GNU Library General Public License
20
* along with this library; see the file COPYING.LIB. If not, write to
21
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22
* Boston, MA 02110-1301, USA.
25
#include "oxygenhelper.h"
26
#include "oxygenanimationmodes.h"
28
#include <KWindowSystem>
32
#include <QtGui/QX11Info>
36
/*! contains utility functions used at multiple places in oxygen style */
48
Q_DECLARE_FLAGS(HoleOptions, HoleOption)
50
class StyleHelper : public Helper
55
explicit StyleHelper( const QByteArray &componentName );
58
virtual ~StyleHelper() {}
60
//! dynamically allocated debug area
61
int debugArea( void ) const
62
{ return _debugArea; }
65
virtual void invalidateCaches();
67
//! update maximum cache size
68
virtual void setMaxCacheSize( int );
70
//! render window background using a given color as a reference
72
For the widget style, both the gradient and the background pixmap are rendered in the same method.
73
All the actual rendering is performed by the base class
75
using Helper::renderWindowBackground;
76
virtual void renderWindowBackground( QPainter* p, const QRect& clipRect, const QWidget* widget, const QColor& color, int y_shift=-23, int gradientHeight = 64 )
78
Helper::renderWindowBackground( p, clipRect, widget, widget->window(), color, y_shift, gradientHeight );
79
Helper::renderBackgroundPixmap( p, clipRect, widget, widget->window(), y_shift, gradientHeight );
82
// render menu background
83
void renderMenuBackground( QPainter* p, const QRect& clipRect, const QWidget* widget, const QPalette& pal )
84
{ renderMenuBackground( p, clipRect, widget, pal.color( widget->window()->backgroundRole() ) ); }
86
// render menu background
87
void renderMenuBackground( QPainter*, const QRect&, const QWidget*, const QColor& );
89
//! returns menu background color matching position in a given menu widget
90
virtual const QColor& menuBackgroundColor( const QColor& color, const QWidget* w, const QPoint& point )
92
if( !( w && w->window() ) || checkAutoFillBackground( w ) ) return color;
93
else return menuBackgroundColor( color, w->window()->height(), w->mapTo( w->window(), point ).y() );
96
//! returns menu background color matching position in a menu widget of given height
97
virtual const QColor& menuBackgroundColor( const QColor& color, int height, int y )
98
{ return backgroundColor( color, qMin( qreal( 1.0 ), qreal( y )/qMin( 200, 3*height/4 ) ) ); }
101
inline const QColor& calcMidColor( const QColor& color );
103
//! merge active and inactive palettes based on ratio, for smooth enable state change transition
104
QPalette mergePalettes( const QPalette&, qreal ratio ) const;
106
//! overloaded window decoration buttons for MDI windows
107
virtual QPixmap windecoButton( const QColor& color, bool pressed, int size = 21 );
109
//! round corners( used for Menus, combobox drop-down, detached toolbars and dockwidgets
110
TileSet *roundCorner( const QColor&, int size = 5 );
112
//! groupbox background
113
TileSet *slope( const QColor&, qreal shade, int size = 7 );
119
QPixmap progressBarIndicator( const QPalette&, const QRect& );
122
QPixmap dialSlab( const QColor& color, qreal shade, int size = 7 )
123
{ return dialSlab( color, QColor(), shade, size ); }
126
QPixmap dialSlab( const QColor&, const QColor&, qreal shade, int size = 7 );
129
QPixmap roundSlab( const QColor& color, qreal shade, int size = 7 )
130
{ return roundSlab( color, QColor(), shade, size ); }
133
QPixmap roundSlab( const QColor&, const QColor& glow, qreal shade, int size = 7 );
136
QPixmap sliderSlab( const QColor&, const QColor& glow, bool sunken, qreal shade, int size = 7 );
143
void fillHole( QPainter&, const QRect&, int size = 7 ) const;
146
void renderHole( QPainter *p, const QColor& color, const QRect &r,
147
HoleOptions options = 0,
148
TileSet::Tiles tiles = TileSet::Ring )
149
{ renderHole( p, color, r, options, -1, Oxygen::AnimationNone, tiles ); }
151
//! generic hole (with animated glow)
153
QPainter*, const QColor&, const QRect &r,
155
qreal opacity, Oxygen::AnimationMode animationMode,
156
TileSet::Tiles = TileSet::Ring );
158
TileSet *holeFlat( const QColor&, qreal shade, bool fill = true, int size = 7 );
161
TileSet *scrollHole( const QColor&, Qt::Orientation orientation, bool smallShadow = false );
164
TileSet *scrollHandle( const QColor&, const QColor&, int size = 7 );
169
TileSet *groove( const QColor&, int size = 7 );
171
//! focus rect for flat toolbuttons
172
TileSet *slitFocused( const QColor& );
175
TileSet *dockFrame( const QColor&, const QColor& );
178
TileSet *selection( const QColor&, int height, bool custom );
181
/*! this method must be public because it is used directly by OxygenStyle to draw dials */
182
void drawInverseGlow( QPainter&, const QColor&, int pad, int size, int rsize ) const;
184
//!@name utility functions
186
//! returns true if compositing is active
187
bool compositingActive( void ) const
188
{ return KWindowSystem::compositingActive(); }
190
//! returns true if a given widget supports alpha channel
191
inline bool hasAlphaChannel( const QWidget* ) const;
193
//! returns true if given widget will get a decoration
194
bool hasDecoration( const QWidget* ) const;
204
TileSet *hole( const QColor& color, int size = 7, HoleOptions options = 0 )
205
{ return hole( color, QColor(), size, options ); }
208
TileSet *hole( const QColor&, const QColor& glow, int size = 7, HoleOptions = 0 );
213
void drawRoundSlab( QPainter&, const QColor&, qreal );
216
void drawSliderSlab( QPainter&, const QColor&, bool sunken, qreal );
220
//! dynamically allocated debug area
223
Cache<QPixmap> _dialSlabCache;
224
Cache<QPixmap> _roundSlabCache;
225
Cache<QPixmap> _sliderSlabCache;
226
Cache<TileSet> _holeCache;
227
Cache<TileSet> _scrollHandleCache;
230
ColorCache _midColorCache;
232
//! progressbar cache
233
PixmapCache _progressBarCache;
235
typedef BaseCache<TileSet> TileSetCache;
236
TileSetCache _cornerCache;
237
TileSetCache _holeFlatCache;
238
TileSetCache _slopeCache;
239
TileSetCache _grooveCache;
240
TileSetCache _slitCache;
241
TileSetCache _dockFrameCache;
242
TileSetCache _scrollHoleCache;
243
TileSetCache _selectionCache;
247
//____________________________________________________________________
248
const QColor& StyleHelper::calcMidColor( const QColor& color )
250
const quint64 key( color.rgba() );
251
QColor* out( _midColorCache.object( key ) );
254
out = new QColor( KColorScheme::shade( color, KColorScheme::MidShade, _contrast - 1.0 ) );
255
_midColorCache.insert( key, out );
261
//____________________________________________________________________
262
bool StyleHelper::hasAlphaChannel( const QWidget* widget ) const
265
if( compositingActive() )
268
if( widget ) return widget->x11Info().depth() == 32;
269
else return QX11Info().appDepth() == 32;
274
return compositingActive();