2003-08-29 22:49:03 +00:00
|
|
|
/* Plastik KWin window decoration
|
|
|
|
Copyright (C) 2003 Sandro Giessl <ceebx@users.sourceforge.net>
|
|
|
|
|
|
|
|
based on the window decoration "Web":
|
|
|
|
Copyright (C) 2001 Rik Hemsley (rikkus) <rik@kde.org>
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; see the file COPYING. If not, write to
|
|
|
|
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2003-09-17 18:43:17 +00:00
|
|
|
// #include <kwin/options.h>
|
2003-08-29 22:49:03 +00:00
|
|
|
|
|
|
|
#include <qbitmap.h>
|
2003-09-17 18:43:17 +00:00
|
|
|
#include <qcursor.h>
|
2003-08-29 22:49:03 +00:00
|
|
|
#include <qimage.h>
|
|
|
|
#include <qpainter.h>
|
|
|
|
#include <qpixmap.h>
|
|
|
|
#include <kpixmap.h>
|
|
|
|
#include <kpixmapeffect.h>
|
2003-09-17 18:43:17 +00:00
|
|
|
#include <qtooltip.h>
|
|
|
|
#include <qtimer.h>
|
2003-08-29 22:49:03 +00:00
|
|
|
|
|
|
|
#include "plastikbutton.h"
|
|
|
|
#include "plastikbutton.moc"
|
|
|
|
#include "plastikclient.h"
|
|
|
|
#include "misc.h"
|
|
|
|
#include "shadow.h"
|
|
|
|
|
2003-09-17 18:43:17 +00:00
|
|
|
namespace KWinPlastik
|
|
|
|
{
|
2003-08-29 22:49:03 +00:00
|
|
|
|
|
|
|
static const uint TIMERINTERVAL = 50; // msec
|
|
|
|
static const uint ANIMATIONSTEPS = 4;
|
|
|
|
|
2005-03-11 20:14:04 +00:00
|
|
|
PlastikButton::PlastikButton(ButtonType type, PlastikClient *parent, const char *name)
|
|
|
|
: KCommonDecorationButton(type, parent, name),
|
2003-08-29 22:49:03 +00:00
|
|
|
m_client(parent),
|
2005-03-15 14:07:37 +00:00
|
|
|
m_pixmapType(BtnClose),
|
2004-05-14 22:50:53 +00:00
|
|
|
hover(false)
|
2003-08-29 22:49:03 +00:00
|
|
|
{
|
|
|
|
setBackgroundMode(NoBackground);
|
|
|
|
|
2005-03-14 09:39:09 +00:00
|
|
|
// no need to reset here as the button will be resetted on first resize.
|
2003-08-29 22:49:03 +00:00
|
|
|
|
|
|
|
animTmr = new QTimer(this);
|
|
|
|
connect(animTmr, SIGNAL(timeout() ), this, SLOT(animate() ) );
|
|
|
|
animProgress = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
PlastikButton::~PlastikButton()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2005-03-14 09:39:09 +00:00
|
|
|
void PlastikButton::reset(unsigned long changed)
|
2003-08-29 22:49:03 +00:00
|
|
|
{
|
2005-03-14 09:39:09 +00:00
|
|
|
if (changed&DecorationReset || changed&ManualReset || changed&SizeChange || changed&StateChange) {
|
|
|
|
switch (type() ) {
|
|
|
|
case CloseButton:
|
2005-03-15 14:07:37 +00:00
|
|
|
m_pixmapType = BtnClose;
|
2005-03-14 09:39:09 +00:00
|
|
|
break;
|
|
|
|
case HelpButton:
|
2005-03-15 14:07:37 +00:00
|
|
|
m_pixmapType = BtnHelp;
|
2005-03-14 09:39:09 +00:00
|
|
|
break;
|
|
|
|
case MinButton:
|
2005-03-15 14:07:37 +00:00
|
|
|
m_pixmapType = BtnMin;
|
2005-03-14 09:39:09 +00:00
|
|
|
break;
|
|
|
|
case MaxButton:
|
|
|
|
if (isOn()) {
|
2005-03-15 14:07:37 +00:00
|
|
|
m_pixmapType = BtnMaxRestore;
|
2005-03-14 09:39:09 +00:00
|
|
|
} else {
|
2005-03-15 14:07:37 +00:00
|
|
|
m_pixmapType = BtnMax;
|
2005-03-14 09:39:09 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case OnAllDesktopsButton:
|
|
|
|
if (isOn()) {
|
2005-03-15 14:07:37 +00:00
|
|
|
m_pixmapType = BtnNotOnAllDesktops;
|
2005-03-14 09:39:09 +00:00
|
|
|
} else {
|
2005-03-15 14:07:37 +00:00
|
|
|
m_pixmapType = BtnOnAllDesktops;
|
2005-03-14 09:39:09 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ShadeButton:
|
|
|
|
if (isOn()) {
|
2005-03-15 14:07:37 +00:00
|
|
|
m_pixmapType = BtnShadeRestore;
|
2005-03-14 09:39:09 +00:00
|
|
|
} else {
|
2005-03-15 14:07:37 +00:00
|
|
|
m_pixmapType = BtnShade;
|
2005-03-14 09:39:09 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case AboveButton:
|
|
|
|
if (isOn()) {
|
2005-03-15 14:07:37 +00:00
|
|
|
m_pixmapType = BtnNotAbove;
|
2005-03-14 09:39:09 +00:00
|
|
|
} else {
|
2005-03-15 14:07:37 +00:00
|
|
|
m_pixmapType = BtnAbove;
|
2005-03-14 09:39:09 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case BelowButton:
|
|
|
|
if (isOn()) {
|
2005-03-15 14:07:37 +00:00
|
|
|
m_pixmapType = BtnNotBelow;
|
2005-03-14 09:39:09 +00:00
|
|
|
} else {
|
2005-03-15 14:07:37 +00:00
|
|
|
m_pixmapType = BtnBelow;
|
2005-03-14 09:39:09 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2005-03-15 14:07:37 +00:00
|
|
|
m_pixmapType = NumButtonPixmaps; // invalid...
|
2005-03-14 09:39:09 +00:00
|
|
|
break;
|
|
|
|
}
|
2003-08-29 22:49:03 +00:00
|
|
|
|
2005-03-14 09:39:09 +00:00
|
|
|
this->update();
|
|
|
|
}
|
2003-08-29 22:49:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PlastikButton::animate()
|
|
|
|
{
|
|
|
|
animTmr->stop();
|
|
|
|
|
|
|
|
if(hover) {
|
|
|
|
if(animProgress < ANIMATIONSTEPS) {
|
2005-03-12 20:13:51 +00:00
|
|
|
if (Handler()->animateButtons() ) {
|
2003-08-29 22:49:03 +00:00
|
|
|
animProgress++;
|
|
|
|
} else {
|
|
|
|
animProgress = ANIMATIONSTEPS;
|
|
|
|
}
|
|
|
|
animTmr->start(TIMERINTERVAL, true); // single-shot
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if(animProgress > 0) {
|
2005-03-12 20:13:51 +00:00
|
|
|
if (Handler()->animateButtons() ) {
|
2003-08-29 22:49:03 +00:00
|
|
|
animProgress--;
|
|
|
|
} else {
|
|
|
|
animProgress = 0;
|
|
|
|
}
|
|
|
|
animTmr->start(TIMERINTERVAL, true); // single-shot
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
repaint(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlastikButton::enterEvent(QEvent *e)
|
|
|
|
{
|
2003-09-17 18:43:17 +00:00
|
|
|
QButton::enterEvent(e);
|
|
|
|
|
2003-08-29 22:49:03 +00:00
|
|
|
hover = true;
|
|
|
|
animate();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlastikButton::leaveEvent(QEvent *e)
|
|
|
|
{
|
2003-09-17 18:43:17 +00:00
|
|
|
QButton::leaveEvent(e);
|
|
|
|
|
2003-08-29 22:49:03 +00:00
|
|
|
hover = false;
|
|
|
|
animate();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlastikButton::drawButton(QPainter *painter)
|
|
|
|
{
|
|
|
|
QRect r(0,0,width(),height());
|
|
|
|
|
|
|
|
bool active = m_client->isActive();
|
|
|
|
QPixmap backgroundTile = m_client->getTitleBarTile(active);
|
|
|
|
KPixmap tempKPixmap;
|
|
|
|
|
|
|
|
QColor highlightColor;
|
2005-03-11 20:14:04 +00:00
|
|
|
if(type() == CloseButton) {
|
2003-08-29 22:49:03 +00:00
|
|
|
highlightColor = QColor(255,64,0);
|
|
|
|
} else {
|
|
|
|
highlightColor = Qt::white;
|
|
|
|
}
|
|
|
|
|
2005-03-12 20:13:51 +00:00
|
|
|
QColor contourTop = alphaBlendColors(Handler()->getColor(TitleGradientFrom, active),
|
2003-08-29 22:49:03 +00:00
|
|
|
Qt::black, 220);
|
2005-03-12 20:13:51 +00:00
|
|
|
QColor contourBottom = alphaBlendColors(Handler()->getColor(TitleGradientTo, active),
|
2003-08-29 22:49:03 +00:00
|
|
|
Qt::black, 220);
|
2005-03-12 20:13:51 +00:00
|
|
|
QColor sourfaceTop = alphaBlendColors(Handler()->getColor(TitleGradientFrom, active),
|
2003-08-29 22:49:03 +00:00
|
|
|
Qt::white, 220);
|
2005-03-12 20:13:51 +00:00
|
|
|
QColor sourfaceBottom = alphaBlendColors(Handler()->getColor(TitleGradientTo, active),
|
2003-08-29 22:49:03 +00:00
|
|
|
Qt::white, 220);
|
|
|
|
|
|
|
|
int highlightAlpha = static_cast<int>(255-((60/static_cast<double>(ANIMATIONSTEPS))*
|
|
|
|
static_cast<double>(animProgress) ) );
|
|
|
|
contourTop = alphaBlendColors(contourTop, highlightColor, highlightAlpha );
|
|
|
|
contourBottom = alphaBlendColors(contourBottom, highlightColor, highlightAlpha);
|
|
|
|
sourfaceTop = alphaBlendColors(sourfaceTop, highlightColor, highlightAlpha);
|
|
|
|
sourfaceBottom = alphaBlendColors(sourfaceBottom, highlightColor, highlightAlpha);
|
|
|
|
|
|
|
|
if (isDown() ) {
|
|
|
|
contourTop = alphaBlendColors(contourTop, Qt::black, 200);
|
|
|
|
contourBottom = alphaBlendColors(contourBottom, Qt::black, 200);
|
|
|
|
sourfaceTop = alphaBlendColors(sourfaceTop, Qt::black, 200);
|
|
|
|
sourfaceBottom = alphaBlendColors(sourfaceBottom, Qt::black, 200);
|
|
|
|
}
|
|
|
|
|
|
|
|
QPixmap buffer;
|
|
|
|
buffer.resize(width(), height());
|
|
|
|
QPainter bP(&buffer);
|
|
|
|
|
|
|
|
// fill with the titlebar background
|
|
|
|
bP.drawTiledPixmap(0, 0, width(), width(), backgroundTile);
|
|
|
|
|
2005-03-11 20:14:04 +00:00
|
|
|
if (type() != MenuButton || hover || animProgress != 0) {
|
2003-08-29 22:49:03 +00:00
|
|
|
// contour
|
|
|
|
bP.setPen(contourTop);
|
|
|
|
bP.drawLine(r.x()+2, r.y(), r.right()-2, r.y() );
|
|
|
|
bP.drawPoint(r.x()+1, r.y()+1);
|
|
|
|
bP.drawPoint(r.right()-1, r.y()+1);
|
|
|
|
bP.setPen(contourBottom);
|
|
|
|
bP.drawLine(r.x()+2, r.bottom(), r.right()-2, r.bottom() );
|
|
|
|
bP.drawPoint(r.x()+1, r.bottom()-1);
|
|
|
|
bP.drawPoint(r.right()-1, r.bottom()-1);
|
|
|
|
// sides of the contour
|
|
|
|
tempKPixmap.resize(1, r.height()-2*2);
|
|
|
|
KPixmapEffect::gradient(tempKPixmap,
|
|
|
|
contourTop,
|
|
|
|
contourBottom,
|
|
|
|
KPixmapEffect::VerticalGradient);
|
|
|
|
bP.drawPixmap(r.x(), r.y()+2, tempKPixmap);
|
|
|
|
bP.drawPixmap(r.right(), r.y()+2, tempKPixmap);
|
|
|
|
// sort of anti-alias for the contour
|
2005-03-12 20:13:51 +00:00
|
|
|
bP.setPen(alphaBlendColors(Handler()->getColor(TitleGradientFrom, active),
|
2003-08-29 22:49:03 +00:00
|
|
|
contourTop, 150) );
|
|
|
|
bP.drawPoint(r.x()+1, r.y());
|
|
|
|
bP.drawPoint(r.right()-1, r.y());
|
|
|
|
bP.drawPoint(r.x(), r.y()+1);
|
|
|
|
bP.drawPoint(r.right(), r.y()+1);
|
2005-03-12 20:13:51 +00:00
|
|
|
bP.setPen(alphaBlendColors(Handler()->getColor(TitleGradientTo, active),
|
2003-08-29 22:49:03 +00:00
|
|
|
contourBottom, 150) );
|
|
|
|
bP.drawPoint(r.x()+1, r.bottom());
|
|
|
|
bP.drawPoint(r.right()-1, r.bottom());
|
|
|
|
bP.drawPoint(r.x(), r.bottom()-1);
|
|
|
|
bP.drawPoint(r.right(), r.bottom()-1);
|
|
|
|
// sourface
|
|
|
|
// fill top and bottom
|
|
|
|
bP.setPen(sourfaceTop);
|
|
|
|
bP.drawLine(r.x()+2, r.y()+1, r.right()-2, r.y()+1 );
|
|
|
|
bP.setPen(sourfaceBottom);
|
|
|
|
bP.drawLine(r.x()+2, r.bottom()-1, r.right()-2, r.bottom()-1 );
|
|
|
|
// fill the rest! :)
|
|
|
|
tempKPixmap.resize(1, r.height()-2*2);
|
|
|
|
KPixmapEffect::gradient(tempKPixmap,
|
|
|
|
sourfaceTop,
|
|
|
|
sourfaceBottom,
|
|
|
|
KPixmapEffect::VerticalGradient);
|
|
|
|
bP.drawTiledPixmap(r.x()+1, r.y()+2, r.width()-2, r.height()-4, tempKPixmap);
|
|
|
|
}
|
|
|
|
|
2005-03-11 20:14:04 +00:00
|
|
|
if (type() == MenuButton)
|
2003-08-29 22:49:03 +00:00
|
|
|
{
|
2003-09-17 18:43:17 +00:00
|
|
|
QPixmap menuIcon(m_client->icon().pixmap( QIconSet::Small, QIconSet::Normal));
|
2003-08-29 22:49:03 +00:00
|
|
|
if (width() < menuIcon.width() || height() < menuIcon.height() ) {
|
2003-09-17 18:43:17 +00:00
|
|
|
menuIcon.convertFromImage( menuIcon.convertToImage().smoothScale(width(), height()));
|
2003-08-29 22:49:03 +00:00
|
|
|
}
|
|
|
|
bP.drawPixmap((width()-menuIcon.width())/2, (height()-menuIcon.height())/2, menuIcon);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int dX,dY;
|
2005-03-15 14:07:37 +00:00
|
|
|
const QPixmap &icon = Handler()->buttonPixmap(m_pixmapType, size(), isDown(), active, decoration()->isToolWindow() );
|
|
|
|
dX = r.x()+(r.width()-icon.width())/2;
|
|
|
|
dY = r.y()+(r.height()-icon.height())/2;
|
2003-08-29 22:49:03 +00:00
|
|
|
if (isDown() ) {
|
|
|
|
dY++;
|
|
|
|
}
|
2005-03-15 14:07:37 +00:00
|
|
|
bP.drawPixmap(dX, dY, icon);
|
2003-08-29 22:49:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bP.end();
|
|
|
|
painter->drawPixmap(0, 0, buffer);
|
|
|
|
}
|
2003-09-17 18:43:17 +00:00
|
|
|
|
|
|
|
} // KWinPlastik
|