implemented scrollbar hole and handle cache

added brushes
added ksharedconfig
wilder-pre-rebase
Hugo Pereira Da Costa 12 years ago
parent bbc4717d7a
commit ae1016bcbe
  1. 91
      kstyle/breezehelper.cpp
  2. 143
      kstyle/breezehelper.h

@ -22,7 +22,98 @@
#include "breezehelper.h"
#include "breezemetrics.h"
#include <QPainter>
namespace Breeze
{
//____________________________________________________________________
Helper::Helper( KSharedConfig::Ptr config ):
_config( config )
{}
//____________________________________________________________________
KSharedConfigPtr Helper::config() const
{ return _config; }
//____________________________________________________________________
void Helper::loadConfig()
{
_viewFocusBrush = KStatefulBrush( KColorScheme::View, KColorScheme::FocusColor, _config );
_viewHoverBrush = KStatefulBrush( KColorScheme::View, KColorScheme::HoverColor, _config );
_viewNegativeTextBrush = KStatefulBrush( KColorScheme::View, KColorScheme::NegativeText, _config );
}
//______________________________________________________________________________
void Helper::invalidateCaches( void )
{
_scrollBarHandleCache.clear();
}
//____________________________________________________________________
void Helper::setMaxCacheSize( int value )
{
_scrollBarHandleCache.setMaxCost( value );
}
//____________________________________________________________________
QColor Helper::alphaColor( QColor color, qreal alpha )
{
if( alpha >= 0 && alpha < 1.0 )
{ color.setAlphaF( alpha*color.alphaF() ); }
return color;
}
//________________________________________________________________________________________________________
TileSet *Helper::scrollBarHandle( const QColor& color, const QColor& glow)
{
const quint64 key( ( colorKey(color) << 32 ) | colorKey(glow) );
TileSet *tileSet = _scrollBarHandleCache.object( key );
if ( !tileSet )
{
QPixmap pm( Metrics::ScrollBar_SliderWidth, Metrics::ScrollBar_SliderWidth );
pm.fill( Qt::transparent );
QPainter p( &pm );
p.setRenderHints( QPainter::Antialiasing );
// content
if( color.isValid() )
{
p.setPen( Qt::NoPen );
p.setBrush( color );
// p.drawEllipse( QRectF( 0.5, 0.5, Metrics::ScrollBar_SliderWidth-1, Metrics::ScrollBar_SliderWidth-1 ) );
p.drawEllipse( QRectF( 0, 0, Metrics::ScrollBar_SliderWidth, Metrics::ScrollBar_SliderWidth ) );
}
// border
if( glow.isValid() )
{
p.setPen( QPen( glow, 2 ) );
p.setBrush( Qt::NoBrush );
p.drawEllipse( QRectF( 1, 1, Metrics::ScrollBar_SliderWidth-2, Metrics::ScrollBar_SliderWidth-2 ) );
}
p.end();
// create tileset and return
tileSet = new TileSet( pm, Metrics::ScrollBar_SliderWidth/2, Metrics::ScrollBar_SliderWidth/2, 1, 1 );
_scrollBarHandleCache.insert( key, tileSet );
}
return tileSet;
}
//________________________________________________________________________________________________________
TileSet *Helper::scrollBarHole( const QColor& color )
{
// in the current implementation, holes and handles are rendered with the same code
return scrollBarHandle( color, QColor() );
}
}

@ -23,6 +23,12 @@
* Boston, MA 02110-1301, USA.
*/
#include "breezetileset.h"
#include <KSharedConfig>
#include <KColorScheme>
#include <QCache>
#include <QScopedPointer>
#if HAVE_X11
@ -32,35 +38,146 @@
namespace Breeze
{
template<typename T> class BaseCache: public QCache<quint64, T>
{
public:
//! constructor
BaseCache( int maxCost ):
QCache<quint64, T>( maxCost ),
_enabled( true )
{}
//! constructor
explicit BaseCache( void ):
_enabled( true )
{}
//! destructor
~BaseCache( void )
{}
//! enable
void setEnabled( bool value )
{ _enabled = value; }
//! enable state
bool enabled( void ) const
{ return _enabled; }
//! access
T* object( const quint64& key )
{ return _enabled ? QCache<quint64, T>::object( key ) : 0; }
//! max cost
void setMaxCost( int cost )
{
if( cost <= 0 ) {
QCache<quint64, T>::clear();
QCache<quint64, T>::setMaxCost( 1 );
setEnabled( false );
} else {
setEnabled( true );
QCache<quint64, T>::setMaxCost( cost );
}
}
private:
//! enable flag
bool _enabled;
};
//! breeze style helper class.
/*! contains utility functions used at multiple places in both breeze style and breeze window decoration */
class Helper
{
public:
//! scoped pointer convenience typedef
template <typename T> using ScopedPointer = QScopedPointer<T, QScopedPointerPodDeleter>;
//! constructor
explicit Helper()
{}
explicit Helper( KSharedConfig::Ptr );
//! destructor
virtual ~Helper()
{}
template <typename T> class ScopedPointer: public QScopedPointer<T, QScopedPointerPodDeleter>
{
public:
//! load configuration
virtual void loadConfig();
//! constructor
ScopedPointer( T* t ):
QScopedPointer<T, QScopedPointerPodDeleter>( t )
{}
//! pointer to shared config
KSharedConfigPtr config() const;
//! destructor
virtual ~ScopedPointer( void )
{}
//! reset all caches
virtual void invalidateCaches();
//! update maximum cache size
virtual void setMaxCacheSize( int );
//! add alpha channel multiplier to color
static QColor alphaColor( QColor color, qreal alpha );
//!@name brushes
//@{
//! focus brush
const KStatefulBrush& viewFocusBrush( void ) const
{ return _viewFocusBrush; }
//! hover brush
const KStatefulBrush& viewHoverBrush( void ) const
{ return _viewHoverBrush; }
//! negative text brush ( used for close button hover )
const KStatefulBrush& viewNegativeTextBrush( void ) const
{ return _viewNegativeTextBrush; }
//@}
//!@name tilesets
//@{
//! scrollbar hole
TileSet *scrollBarHole( const QColor& );
//! scrollbar handle
TileSet *scrollBarHandle( const QColor&, const QColor& );
//@}
protected:
//! return color key for a given color, properly accounting for invalid colors
quint64 colorKey( const QColor& color ) const
{ return color.isValid() ? color.rgba():0; }
private:
//! configuration
KSharedConfigPtr _config;
//!@name brushes
//@{
KStatefulBrush _viewFocusBrush;
KStatefulBrush _viewHoverBrush;
KStatefulBrush _viewNegativeTextBrush;
//@}
//!@name tileset caches
//@{
};
typedef BaseCache<TileSet> TileSetCache;
TileSetCache _scrollBarHandleCache;
//@}
};
}

Loading…
Cancel
Save