no need to create as well the inactive as the active caption buffer. now only create them when needed...
svn path=/trunk/kdebase/kwin/; revision=397838
This commit is contained in:
parent
5cb8a385e9
commit
87b57d4e7f
2 changed files with 72 additions and 81 deletions
|
@ -45,15 +45,14 @@ namespace KWinPlastik
|
||||||
|
|
||||||
PlastikClient::PlastikClient(KDecorationBridge* bridge, KDecorationFactory* factory)
|
PlastikClient::PlastikClient(KDecorationBridge* bridge, KDecorationFactory* factory)
|
||||||
: KCommonDecoration (bridge, factory),
|
: KCommonDecoration (bridge, factory),
|
||||||
aCaptionBuffer(0), iCaptionBuffer(0),
|
|
||||||
captionBufferDirty(true),
|
|
||||||
s_titleFont(QFont() )
|
s_titleFont(QFont() )
|
||||||
{ }
|
{
|
||||||
|
memset(m_captionPixmaps, 0, sizeof(QPixmap*)*2);
|
||||||
|
}
|
||||||
|
|
||||||
PlastikClient::~PlastikClient()
|
PlastikClient::~PlastikClient()
|
||||||
{
|
{
|
||||||
delete aCaptionBuffer;
|
clearCaptionPixmaps();
|
||||||
delete iCaptionBuffer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString PlastikClient::visibleName() const
|
QString PlastikClient::visibleName() const
|
||||||
|
@ -194,11 +193,7 @@ void PlastikClient::init()
|
||||||
{
|
{
|
||||||
s_titleFont = isToolWindow() ? Handler()->titleFontTool() : Handler()->titleFont();
|
s_titleFont = isToolWindow() ? Handler()->titleFontTool() : Handler()->titleFont();
|
||||||
|
|
||||||
// create_pixmaps();
|
clearCaptionPixmaps();
|
||||||
|
|
||||||
aCaptionBuffer = new QPixmap();
|
|
||||||
iCaptionBuffer = new QPixmap();
|
|
||||||
captionBufferDirty = true;
|
|
||||||
|
|
||||||
KCommonDecoration::init();
|
KCommonDecoration::init();
|
||||||
}
|
}
|
||||||
|
@ -246,9 +241,7 @@ void PlastikClient::paintEvent(QPaintEvent *e)
|
||||||
PlastikHandler *handler = Handler();
|
PlastikHandler *handler = Handler();
|
||||||
|
|
||||||
if (oldCaption != caption() )
|
if (oldCaption != caption() )
|
||||||
captionBufferDirty = true;
|
clearCaptionPixmaps();
|
||||||
if (captionBufferDirty)
|
|
||||||
update_captionBuffer();
|
|
||||||
|
|
||||||
bool active = isActive();
|
bool active = isActive();
|
||||||
bool toolWindow = isToolWindow();
|
bool toolWindow = isToolWindow();
|
||||||
|
@ -386,13 +379,14 @@ void PlastikClient::paintEvent(QPaintEvent *e)
|
||||||
}
|
}
|
||||||
|
|
||||||
// titleSpacer
|
// titleSpacer
|
||||||
QPixmap *titleBfrPtr = active ? aCaptionBuffer : iCaptionBuffer;
|
const QPixmap &caption = captionPixmap();
|
||||||
if(Rtitle.width() > 0 && titleBfrPtr != 0)
|
// QPixmap *titleBfrPtr = active ? aCaptionBuffer : iCaptionBuffer;
|
||||||
|
if(Rtitle.width() > 0)
|
||||||
{
|
{
|
||||||
m_captionRect = captionRect(); // also update m_captionRect!
|
m_captionRect = captionRect(); // also update m_captionRect!
|
||||||
if (m_captionRect.isValid() && region.contains(m_captionRect) )
|
if (m_captionRect.isValid() && region.contains(m_captionRect) )
|
||||||
{
|
{
|
||||||
painter.drawTiledPixmap(m_captionRect, *titleBfrPtr);
|
painter.drawTiledPixmap(m_captionRect, caption);
|
||||||
}
|
}
|
||||||
|
|
||||||
// left to the title
|
// left to the title
|
||||||
|
@ -410,7 +404,7 @@ void PlastikClient::paintEvent(QPaintEvent *e)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
titleBfrPtr = 0;
|
// titleBfrPtr = 0;
|
||||||
|
|
||||||
// decoSpacer
|
// decoSpacer
|
||||||
if(titleEdgeBottom > 0)
|
if(titleEdgeBottom > 0)
|
||||||
|
@ -513,8 +507,7 @@ void PlastikClient::paintEvent(QPaintEvent *e)
|
||||||
|
|
||||||
QRect PlastikClient::captionRect() const
|
QRect PlastikClient::captionRect() const
|
||||||
{
|
{
|
||||||
QPixmap *titleBfrPtr = isActive() ? aCaptionBuffer : iCaptionBuffer;
|
const QPixmap &caption = captionPixmap();
|
||||||
if (titleBfrPtr) {
|
|
||||||
QRect r = widget()->rect();
|
QRect r = widget()->rect();
|
||||||
|
|
||||||
const int titleHeight = layoutMetric(LM_TitleHeight);
|
const int titleHeight = layoutMetric(LM_TitleHeight);
|
||||||
|
@ -532,36 +525,31 @@ QRect PlastikClient::captionRect() const
|
||||||
Qt::AlignmentFlags a = Handler()->titleAlign();
|
Qt::AlignmentFlags a = Handler()->titleAlign();
|
||||||
|
|
||||||
int tX, tW; // position/width of the title buffer
|
int tX, tW; // position/width of the title buffer
|
||||||
if (titleBfrPtr->width() > titleWidth) {
|
if (caption.width() > titleWidth) {
|
||||||
tW = titleWidth;
|
tW = titleWidth;
|
||||||
} else {
|
} else {
|
||||||
tW = titleBfrPtr->width();
|
tW = caption.width();
|
||||||
}
|
}
|
||||||
if (a == Qt::AlignLeft || (titleBfrPtr->width() > titleWidth) ) {
|
if (a == Qt::AlignLeft || (caption.width() > titleWidth) ) {
|
||||||
// Align left
|
// Align left
|
||||||
tX = titleLeft;
|
tX = titleLeft;
|
||||||
} else if (a == Qt::AlignHCenter) {
|
} else if (a == Qt::AlignHCenter) {
|
||||||
// Align center
|
// Align center
|
||||||
tX = titleLeft+(titleWidth- titleBfrPtr->width() )/2;
|
tX = titleLeft+(titleWidth- caption.width() )/2;
|
||||||
} else {
|
} else {
|
||||||
// Align right
|
// Align right
|
||||||
tX = titleLeft+titleWidth-titleBfrPtr->width();
|
tX = titleLeft+titleWidth-caption.width();
|
||||||
}
|
}
|
||||||
|
|
||||||
return QRect(tX, r.top()+titleEdgeTop, tW, titleHeight);
|
return QRect(tX, r.top()+titleEdgeTop, tW, titleHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
return QRect();
|
|
||||||
}
|
|
||||||
|
|
||||||
void PlastikClient::updateCaption()
|
void PlastikClient::updateCaption()
|
||||||
{
|
{
|
||||||
QRect oldCaptionRect = m_captionRect;
|
QRect oldCaptionRect = m_captionRect;
|
||||||
|
|
||||||
if (oldCaption != caption() )
|
if (oldCaption != caption() )
|
||||||
captionBufferDirty = true;
|
clearCaptionPixmaps();
|
||||||
if (captionBufferDirty)
|
|
||||||
update_captionBuffer();
|
|
||||||
|
|
||||||
m_captionRect = PlastikClient::captionRect();
|
m_captionRect = PlastikClient::captionRect();
|
||||||
|
|
||||||
|
@ -576,7 +564,7 @@ void PlastikClient::reset( unsigned long changed )
|
||||||
if (changed & SettingColors)
|
if (changed & SettingColors)
|
||||||
{
|
{
|
||||||
// repaint the whole thing
|
// repaint the whole thing
|
||||||
captionBufferDirty = true;
|
clearCaptionPixmaps();
|
||||||
widget()->update();
|
widget()->update();
|
||||||
updateButtons();
|
updateButtons();
|
||||||
} else if (changed & SettingFont) {
|
} else if (changed & SettingFont) {
|
||||||
|
@ -586,7 +574,7 @@ void PlastikClient::reset( unsigned long changed )
|
||||||
updateLayout();
|
updateLayout();
|
||||||
|
|
||||||
// then repaint
|
// then repaint
|
||||||
captionBufferDirty = true;
|
clearCaptionPixmaps();
|
||||||
widget()->update();
|
widget()->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -598,9 +586,15 @@ const QPixmap &PlastikClient::getTitleBarTile(bool active) const
|
||||||
return Handler()->pixmap(TitleBarTile, active, isToolWindow() );
|
return Handler()->pixmap(TitleBarTile, active, isToolWindow() );
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlastikClient::update_captionBuffer()
|
const QPixmap &PlastikClient::captionPixmap() const
|
||||||
{
|
{
|
||||||
oldCaption = caption();
|
bool active = isActive();
|
||||||
|
|
||||||
|
if (m_captionPixmaps[active]) {
|
||||||
|
return *m_captionPixmaps[active];
|
||||||
|
}
|
||||||
|
|
||||||
|
// not found, create new pixmap...
|
||||||
|
|
||||||
const uint maxCaptionLength = 300; // truncate captions longer than this!
|
const uint maxCaptionLength = 300; // truncate captions longer than this!
|
||||||
QString c(caption() );
|
QString c(caption() );
|
||||||
|
@ -632,15 +626,15 @@ void PlastikClient::update_captionBuffer()
|
||||||
QImage shadow;
|
QImage shadow;
|
||||||
ShadowEngine se;
|
ShadowEngine se;
|
||||||
|
|
||||||
// active
|
QPixmap *captionPixmap = new QPixmap(captionWidth+4, th);
|
||||||
aCaptionBuffer->resize(captionWidth+4, th ); // 4 px shadow
|
|
||||||
painter.begin(aCaptionBuffer);
|
painter.begin(captionPixmap);
|
||||||
painter.drawTiledPixmap(aCaptionBuffer->rect(),
|
painter.drawTiledPixmap(captionPixmap->rect(),
|
||||||
Handler()->pixmap(TitleBarTile, true, isToolWindow()) );
|
Handler()->pixmap(TitleBarTile, active, isToolWindow()) );
|
||||||
if(Handler()->titleShadow())
|
if(Handler()->titleShadow())
|
||||||
{
|
{
|
||||||
QColor shadowColor;
|
QColor shadowColor;
|
||||||
if (qGray(Handler()->getColor(TitleFont,true).rgb()) < 100)
|
if (qGray(Handler()->getColor(TitleFont,active).rgb()) < 100)
|
||||||
shadowColor = QColor(255, 255, 255);
|
shadowColor = QColor(255, 255, 255);
|
||||||
else
|
else
|
||||||
shadowColor = QColor(0,0,0);
|
shadowColor = QColor(0,0,0);
|
||||||
|
@ -648,26 +642,22 @@ void PlastikClient::update_captionBuffer()
|
||||||
painter.drawImage(1, 1, shadow);
|
painter.drawImage(1, 1, shadow);
|
||||||
}
|
}
|
||||||
painter.setFont(s_titleFont);
|
painter.setFont(s_titleFont);
|
||||||
painter.setPen(Handler()->getColor(TitleFont,true));
|
painter.setPen(Handler()->getColor(TitleFont,active) );
|
||||||
painter.drawText(aCaptionBuffer->rect(), AlignCenter, c );
|
painter.drawText(captionPixmap->rect(), AlignCenter, c );
|
||||||
painter.end();
|
painter.end();
|
||||||
|
|
||||||
|
m_captionPixmaps[active] = captionPixmap;
|
||||||
// inactive
|
return *captionPixmap;
|
||||||
iCaptionBuffer->resize(captionWidth+4, th );
|
|
||||||
painter.begin(iCaptionBuffer);
|
|
||||||
painter.drawTiledPixmap(iCaptionBuffer->rect(),
|
|
||||||
Handler()->pixmap(TitleBarTile, false, isToolWindow()) );
|
|
||||||
if(Handler()->titleShadow())
|
|
||||||
{
|
|
||||||
painter.drawImage(1, 1, shadow);
|
|
||||||
}
|
}
|
||||||
painter.setFont(s_titleFont);
|
|
||||||
painter.setPen(Handler()->getColor(TitleFont,false));
|
|
||||||
painter.drawText(iCaptionBuffer->rect(), AlignCenter, c );
|
|
||||||
painter.end();
|
|
||||||
|
|
||||||
captionBufferDirty = false;
|
void PlastikClient::clearCaptionPixmaps()
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 2; ++i) {
|
||||||
|
delete m_captionPixmaps[i];
|
||||||
|
m_captionPixmaps[i] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
oldCaption = caption();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // KWinPlastik
|
} // KWinPlastik
|
||||||
|
|
|
@ -56,12 +56,13 @@ public:
|
||||||
private:
|
private:
|
||||||
QRect captionRect() const;
|
QRect captionRect() const;
|
||||||
|
|
||||||
QPixmap *aCaptionBuffer, *iCaptionBuffer;
|
const QPixmap &captionPixmap() const;
|
||||||
void update_captionBuffer();
|
void clearCaptionPixmaps();
|
||||||
|
|
||||||
|
mutable QPixmap *m_captionPixmaps[2];
|
||||||
|
|
||||||
QRect m_captionRect;
|
QRect m_captionRect;
|
||||||
QString oldCaption;
|
QString oldCaption;
|
||||||
bool captionBufferDirty;
|
|
||||||
|
|
||||||
// settings...
|
// settings...
|
||||||
QFont s_titleFont;
|
QFont s_titleFont;
|
||||||
|
|
Loading…
Reference in a new issue