keep cached pixmaps in the handler so not every decoration needs to create its own pixmaps...
svn path=/trunk/kdebase/kwin/; revision=397041icc-effect-5.14.5
parent
45d3cfaa36
commit
64e8b52430
|
@ -20,7 +20,11 @@
|
|||
Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <qpainter.h>
|
||||
|
||||
#include <kconfig.h>
|
||||
#include <kpixmap.h>
|
||||
#include <kpixmapeffect.h>
|
||||
|
||||
#include "misc.h"
|
||||
#include "plastik.h"
|
||||
|
@ -30,8 +34,6 @@
|
|||
namespace KWinPlastik
|
||||
{
|
||||
|
||||
// static bool pixmaps_created = false;
|
||||
|
||||
bool PlastikHandler::m_initialized = false;
|
||||
bool PlastikHandler::m_animateButtons = true;
|
||||
bool PlastikHandler::m_titleShadow = true;
|
||||
|
@ -47,12 +49,18 @@ Qt::AlignmentFlags PlastikHandler::m_titleAlign = Qt::AlignHCenter;
|
|||
|
||||
PlastikHandler::PlastikHandler()
|
||||
{
|
||||
memset(m_pixmaps, 0, sizeof(QPixmap *) * NumPixmaps); // set elements to 0
|
||||
|
||||
reset(0);
|
||||
}
|
||||
|
||||
PlastikHandler::~PlastikHandler()
|
||||
{
|
||||
m_initialized = false;
|
||||
|
||||
for (int n=0; n<NumPixmaps; n++) {
|
||||
if (m_pixmaps[n]) delete m_pixmaps[n];
|
||||
}
|
||||
}
|
||||
|
||||
bool PlastikHandler::reset(unsigned long changed)
|
||||
|
@ -92,6 +100,14 @@ bool PlastikHandler::reset(unsigned long changed)
|
|||
// read in the configuration
|
||||
readConfig();
|
||||
|
||||
// pixmaps probably need to be updated, so delete the cache.
|
||||
for (int n=0; n<NumPixmaps; n++) {
|
||||
if (m_pixmaps[n]) {
|
||||
delete m_pixmaps[n];
|
||||
m_pixmaps[n] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
m_initialized = true;
|
||||
|
||||
// Do we need to "hit the wooden hammer" ?
|
||||
|
@ -200,6 +216,77 @@ QColor PlastikHandler::getColor(KWinPlastik::ColorType type, const bool active)
|
|||
}
|
||||
}
|
||||
|
||||
const QPixmap &PlastikHandler::pixmap(Pixmaps type) {
|
||||
|
||||
if (m_pixmaps[type])
|
||||
return *m_pixmaps[type];
|
||||
|
||||
switch (type) {
|
||||
case aTitleBarTileTop:
|
||||
case iTitleBarTileTop:
|
||||
case atTitleBarTileTop:
|
||||
case itTitleBarTileTop:
|
||||
{
|
||||
int h = 4-2; // TODO: don't hardcode the height...
|
||||
|
||||
bool active = false;
|
||||
if (type == aTitleBarTileTop || type == atTitleBarTileTop) {
|
||||
active = true;
|
||||
}
|
||||
|
||||
KPixmap tempPixmap;
|
||||
tempPixmap.resize(1, h);
|
||||
KPixmapEffect::gradient(tempPixmap,
|
||||
getColor(TitleGradientToTop, active),
|
||||
getColor(TitleGradientFrom, active),
|
||||
KPixmapEffect::VerticalGradient);
|
||||
QPixmap *pixmap = new QPixmap(1, h);
|
||||
QPainter painter(pixmap);
|
||||
painter.drawPixmap(0, 0, tempPixmap);
|
||||
painter.end();
|
||||
|
||||
m_pixmaps[type] = pixmap;
|
||||
return *pixmap;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case aTitleBarTile:
|
||||
case iTitleBarTile:
|
||||
case atTitleBarTile:
|
||||
case itTitleBarTile:
|
||||
{
|
||||
bool active = false;
|
||||
if (type == aTitleBarTile || type == atTitleBarTile) {
|
||||
active = true;
|
||||
}
|
||||
bool toolWindow = false;
|
||||
if (type == atTitleBarTile || type == itTitleBarTile) {
|
||||
toolWindow = true;
|
||||
}
|
||||
|
||||
int h = toolWindow ? m_titleHeightTool : m_titleHeight;
|
||||
|
||||
KPixmap tempPixmap;
|
||||
tempPixmap.resize(5, h);
|
||||
KPixmapEffect::gradient(tempPixmap,
|
||||
PlastikHandler::getColor(TitleGradientFrom, active),
|
||||
PlastikHandler::getColor(TitleGradientTo, active),
|
||||
KPixmapEffect::VerticalGradient);
|
||||
QPixmap *pixmap = new QPixmap(5, h);
|
||||
QPainter painter(pixmap);
|
||||
painter.drawPixmap(0, 0, tempPixmap);
|
||||
painter.end();
|
||||
|
||||
m_pixmaps[type] = pixmap;
|
||||
return *pixmap;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
QValueList< PlastikHandler::BorderSize >
|
||||
PlastikHandler::borderSizes() const
|
||||
{
|
||||
|
@ -209,19 +296,24 @@ PlastikHandler::borderSizes() const
|
|||
BorderVeryHuge << BorderOversized;
|
||||
}
|
||||
|
||||
// make the handler accessible to other classes...
|
||||
static PlastikHandler *handler = 0;
|
||||
PlastikHandler* Handler()
|
||||
{
|
||||
return handler;
|
||||
}
|
||||
|
||||
} // KWinPlastik
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Plugin Stuff //
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static KWinPlastik::PlastikHandler *handler = 0;
|
||||
|
||||
extern "C"
|
||||
{
|
||||
KDE_EXPORT KDecorationFactory *create_factory()
|
||||
{
|
||||
handler = new KWinPlastik::PlastikHandler();
|
||||
return handler;
|
||||
KWinPlastik::handler = new KWinPlastik::PlastikHandler();
|
||||
return KWinPlastik::handler;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,16 +20,17 @@
|
|||
Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef KNIFTY_H
|
||||
#define KNIFTY_H
|
||||
#ifndef PLASTIK_H
|
||||
#define PLASTIK_H
|
||||
|
||||
#include <qintcache.h>
|
||||
#include <qfont.h>
|
||||
|
||||
#include <kdecoration.h>
|
||||
#include <kdecorationfactory.h>
|
||||
|
||||
namespace KWinPlastik {
|
||||
|
||||
#include <qfont.h>
|
||||
|
||||
enum ColorType {
|
||||
WindowContour=0,
|
||||
TitleGradientFrom,
|
||||
|
@ -43,6 +44,18 @@ enum ColorType {
|
|||
TitleFont
|
||||
};
|
||||
|
||||
enum Pixmaps {
|
||||
aTitleBarTileTop, // normal windows
|
||||
iTitleBarTileTop,
|
||||
aTitleBarTile,
|
||||
iTitleBarTile,
|
||||
atTitleBarTileTop, // tool windows
|
||||
itTitleBarTileTop,
|
||||
atTitleBarTile,
|
||||
itTitleBarTile,
|
||||
NumPixmaps
|
||||
};
|
||||
|
||||
class PlastikHandler: public QObject, public KDecorationFactory
|
||||
{
|
||||
Q_OBJECT
|
||||
|
@ -56,6 +69,8 @@ public:
|
|||
|
||||
static bool initialized() { return m_initialized; }
|
||||
|
||||
const QPixmap &pixmap(Pixmaps pixmap);
|
||||
|
||||
static int titleHeight() { return m_titleHeight; }
|
||||
static int titleHeightTool() { return m_titleHeightTool; }
|
||||
static QFont titleFont() { return m_titleFont; }
|
||||
|
@ -84,8 +99,13 @@ private:
|
|||
static Qt::AlignmentFlags m_titleAlign;
|
||||
|
||||
static bool m_initialized;
|
||||
|
||||
// pixmap cache
|
||||
QPixmap *m_pixmaps[NumPixmaps];
|
||||
};
|
||||
|
||||
PlastikHandler* Handler();
|
||||
|
||||
} // KWinPlastik
|
||||
|
||||
#endif // KNIFT_H
|
||||
#endif // PLASTIK_H
|
||||
|
|
|
@ -43,19 +43,20 @@
|
|||
namespace KWinPlastik
|
||||
{
|
||||
|
||||
#define TITLEBARTILETOP (isToolWindow()? (isActive()?atTitleBarTileTop : itTitleBarTileTop) \
|
||||
: (isActive()?aTitleBarTileTop : iTitleBarTileTop))
|
||||
#define TITLEBARTILE (isToolWindow()? (isActive()?KWinPlastik::atTitleBarTile : KWinPlastik::itTitleBarTile) \
|
||||
: (isActive()?KWinPlastik::aTitleBarTile : KWinPlastik::iTitleBarTile))
|
||||
|
||||
PlastikClient::PlastikClient(KDecorationBridge* bridge, KDecorationFactory* factory)
|
||||
: KCommonDecoration (bridge, factory),
|
||||
aCaptionBuffer(0), iCaptionBuffer(0),
|
||||
aTitleBarTile(0), iTitleBarTile(0), aTitleBarTopTile(0), iTitleBarTopTile(0),
|
||||
pixmaps_created(false),
|
||||
captionBufferDirty(true),
|
||||
s_titleFont(QFont() )
|
||||
{ }
|
||||
|
||||
PlastikClient::~PlastikClient()
|
||||
{
|
||||
delete_pixmaps();
|
||||
|
||||
delete aCaptionBuffer;
|
||||
delete iCaptionBuffer;
|
||||
}
|
||||
|
@ -200,7 +201,7 @@ void PlastikClient::init()
|
|||
PlastikHandler::titleFontTool()
|
||||
: PlastikHandler::titleFont();
|
||||
|
||||
create_pixmaps();
|
||||
// create_pixmaps();
|
||||
|
||||
aCaptionBuffer = new QPixmap();
|
||||
iCaptionBuffer = new QPixmap();
|
||||
|
@ -249,6 +250,8 @@ void PlastikClient::paintEvent(QPaintEvent *e)
|
|||
{
|
||||
QRegion region = e->region();
|
||||
|
||||
PlastikHandler *handler = Handler();
|
||||
|
||||
if (oldCaption != caption() )
|
||||
captionBufferDirty = true;
|
||||
if (captionBufferDirty)
|
||||
|
@ -355,7 +358,7 @@ void PlastikClient::paintEvent(QPaintEvent *e)
|
|||
|
||||
tempRect.setRect(r_x+2, r_y+2, r_w-2*2, titleEdgeTop-2 );
|
||||
if (tempRect.isValid() && region.contains(tempRect) ) {
|
||||
painter.drawTiledPixmap(tempRect, active ? *aTitleBarTopTile : *iTitleBarTopTile);
|
||||
painter.drawTiledPixmap(tempRect, handler->pixmap(TITLEBARTILETOP) );
|
||||
}
|
||||
|
||||
// outside the region normally masked by doShape
|
||||
|
@ -402,14 +405,14 @@ void PlastikClient::paintEvent(QPaintEvent *e)
|
|||
tempRect.setRect(r_x+titleMarginLeft, m_captionRect.top(),
|
||||
m_captionRect.left() - (r_x+titleMarginLeft), m_captionRect.height() );
|
||||
if (tempRect.isValid() && region.contains(tempRect) ) {
|
||||
painter.drawTiledPixmap(tempRect, active ? *aTitleBarTile : *iTitleBarTile);
|
||||
painter.drawTiledPixmap(tempRect, handler->pixmap(TITLEBARTILE) );
|
||||
}
|
||||
|
||||
// right to the title
|
||||
tempRect.setRect(m_captionRect.right()+1, m_captionRect.top(),
|
||||
(r_x2-titleMarginRight) - m_captionRect.right(), m_captionRect.height() );
|
||||
if (tempRect.isValid() && region.contains(tempRect) ) {
|
||||
painter.drawTiledPixmap(tempRect, active ? *aTitleBarTile : *iTitleBarTile);
|
||||
painter.drawTiledPixmap(tempRect, handler->pixmap(TITLEBARTILE) );
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -579,8 +582,6 @@ void PlastikClient::reset( unsigned long changed )
|
|||
if (changed & SettingColors)
|
||||
{
|
||||
// repaint the whole thing
|
||||
delete_pixmaps();
|
||||
create_pixmaps();
|
||||
captionBufferDirty = true;
|
||||
widget()->update();
|
||||
updateButtons();
|
||||
|
@ -593,8 +594,6 @@ void PlastikClient::reset( unsigned long changed )
|
|||
updateLayout();
|
||||
|
||||
// then repaint
|
||||
delete_pixmaps();
|
||||
create_pixmaps();
|
||||
captionBufferDirty = true;
|
||||
widget()->update();
|
||||
}
|
||||
|
@ -602,79 +601,10 @@ void PlastikClient::reset( unsigned long changed )
|
|||
KCommonDecoration::reset(changed);
|
||||
}
|
||||
|
||||
void PlastikClient::create_pixmaps()
|
||||
const QPixmap &PlastikClient::getTitleBarTile(bool active) const
|
||||
{
|
||||
if(pixmaps_created)
|
||||
return;
|
||||
|
||||
KPixmap tempPixmap;
|
||||
QPainter painter;
|
||||
|
||||
const int tet = layoutMetric(LM_TitleEdgeTop, false);
|
||||
const int th = layoutMetric(LM_TitleHeight, false);
|
||||
|
||||
// aTitleBarTopTile
|
||||
tempPixmap.resize(1, tet-1-1 );
|
||||
KPixmapEffect::gradient(tempPixmap,
|
||||
PlastikHandler::getColor(TitleGradientToTop, true),
|
||||
PlastikHandler::getColor(TitleGradientFrom, true),
|
||||
KPixmapEffect::VerticalGradient);
|
||||
aTitleBarTopTile = new QPixmap(1, tet-1-1 );
|
||||
painter.begin(aTitleBarTopTile);
|
||||
painter.drawPixmap(0, 0, tempPixmap);
|
||||
painter.end();
|
||||
|
||||
// aTitleBarTile
|
||||
tempPixmap.resize(1, th );
|
||||
KPixmapEffect::gradient(tempPixmap,
|
||||
PlastikHandler::getColor(TitleGradientFrom, true),
|
||||
PlastikHandler::getColor(TitleGradientTo, true),
|
||||
KPixmapEffect::VerticalGradient);
|
||||
aTitleBarTile = new QPixmap(1, th );
|
||||
painter.begin(aTitleBarTile);
|
||||
painter.drawPixmap(0, 0, tempPixmap);
|
||||
painter.end();
|
||||
|
||||
// iTitleBarTopTile
|
||||
tempPixmap.resize(1, tet-1-1 );
|
||||
KPixmapEffect::gradient(tempPixmap,
|
||||
PlastikHandler::getColor(TitleGradientToTop, false),
|
||||
PlastikHandler::getColor(TitleGradientFrom, false),
|
||||
KPixmapEffect::VerticalGradient);
|
||||
iTitleBarTopTile = new QPixmap(1, tet-1-1 );
|
||||
painter.begin(iTitleBarTopTile);
|
||||
painter.drawPixmap(0, 0, tempPixmap);
|
||||
painter.end();
|
||||
|
||||
// iTitleBarTile
|
||||
tempPixmap.resize(1, th );
|
||||
KPixmapEffect::gradient(tempPixmap,
|
||||
PlastikHandler::getColor(TitleGradientFrom, false),
|
||||
PlastikHandler::getColor(TitleGradientTo, false),
|
||||
KPixmapEffect::VerticalGradient);
|
||||
iTitleBarTile = new QPixmap(1, th );
|
||||
painter.begin(iTitleBarTile);
|
||||
painter.drawPixmap(0, 0, tempPixmap);
|
||||
painter.end();
|
||||
|
||||
pixmaps_created = true;
|
||||
}
|
||||
|
||||
void PlastikClient::delete_pixmaps()
|
||||
{
|
||||
delete aTitleBarTopTile;
|
||||
aTitleBarTopTile = 0;
|
||||
|
||||
delete iTitleBarTopTile;
|
||||
iTitleBarTopTile = 0;
|
||||
|
||||
delete aTitleBarTile;
|
||||
aTitleBarTile = 0;
|
||||
|
||||
delete iTitleBarTile;
|
||||
iTitleBarTile = 0;
|
||||
|
||||
pixmaps_created = false;
|
||||
return Handler()->pixmap(isToolWindow() ?
|
||||
(active? atTitleBarTile : itTitleBarTile) : (active? aTitleBarTile : iTitleBarTile) );
|
||||
}
|
||||
|
||||
void PlastikClient::update_captionBuffer()
|
||||
|
@ -714,7 +644,8 @@ void PlastikClient::update_captionBuffer()
|
|||
// active
|
||||
aCaptionBuffer->resize(captionWidth+4, th ); // 4 px shadow
|
||||
painter.begin(aCaptionBuffer);
|
||||
painter.drawTiledPixmap(aCaptionBuffer->rect(), *aTitleBarTile);
|
||||
painter.drawTiledPixmap(aCaptionBuffer->rect(),
|
||||
Handler()->pixmap(isToolWindow()?KWinPlastik::atTitleBarTile:KWinPlastik::aTitleBarTile) );
|
||||
if(PlastikHandler::titleShadow())
|
||||
{
|
||||
QColor shadowColor;
|
||||
|
@ -734,7 +665,8 @@ void PlastikClient::update_captionBuffer()
|
|||
// inactive
|
||||
iCaptionBuffer->resize(captionWidth+4, th );
|
||||
painter.begin(iCaptionBuffer);
|
||||
painter.drawTiledPixmap(iCaptionBuffer->rect(), *iTitleBarTile);
|
||||
painter.drawTiledPixmap(iCaptionBuffer->rect(),
|
||||
Handler()->pixmap(isToolWindow()?KWinPlastik::itTitleBarTile:KWinPlastik::iTitleBarTile) );
|
||||
if(PlastikHandler::titleShadow())
|
||||
{
|
||||
painter.drawImage(1, 1, shadow);
|
||||
|
|
|
@ -51,10 +51,7 @@ public:
|
|||
virtual void paintEvent(QPaintEvent *e);
|
||||
virtual void updateCaption();
|
||||
|
||||
QPixmap getTitleBarTile(bool active) const
|
||||
{
|
||||
return active ? *aTitleBarTile : *iTitleBarTile;
|
||||
}
|
||||
const QPixmap &getTitleBarTile(bool active) const;
|
||||
|
||||
private:
|
||||
QRect captionRect() const;
|
||||
|
@ -62,11 +59,6 @@ private:
|
|||
QPixmap *aCaptionBuffer, *iCaptionBuffer;
|
||||
void update_captionBuffer();
|
||||
|
||||
QPixmap *aTitleBarTile, *iTitleBarTile, *aTitleBarTopTile, *iTitleBarTopTile;
|
||||
bool pixmaps_created;
|
||||
void create_pixmaps();
|
||||
void delete_pixmaps();
|
||||
|
||||
QRect m_captionRect;
|
||||
QString oldCaption;
|
||||
bool captionBufferDirty;
|
||||
|
|
Loading…
Reference in New Issue