diff options
author | Slávek Banko <[email protected]> | 2016-04-10 02:08:09 +0200 |
---|---|---|
committer | Slávek Banko <[email protected]> | 2016-04-10 02:08:09 +0200 |
commit | 0d02094e2b261de9aadac40f65a574e9fbee66e2 (patch) | |
tree | 60621cbe5c2907665040e91d9c9523ce7a05e4fa /src/tastybutton.cpp | |
download | tastymenu-0d02094e2b261de9aadac40f65a574e9fbee66e2.tar.gz tastymenu-0d02094e2b261de9aadac40f65a574e9fbee66e2.zip |
Initial import of tastymenu 1.0.8
Diffstat (limited to 'src/tastybutton.cpp')
-rw-r--r-- | src/tastybutton.cpp | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/src/tastybutton.cpp b/src/tastybutton.cpp new file mode 100644 index 0000000..9f89c05 --- /dev/null +++ b/src/tastybutton.cpp @@ -0,0 +1,116 @@ +/*************************************************************************** + * Copyright (C) 2006 by Marco Martin * + * [email protected] * + * * + * 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; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#include "tastybutton.h" + +#include <qimage.h> +#include <qpainter.h> +#include <qpalette.h> +#include <qcolor.h> +#include <kimageeffect.h> + +TastyButton::TastyButton(QWidget *parent) + : QToolButton(parent) +{ + iconEffect = new KIconEffect(); + iconEffect->init(); +} + + +TastyButton::~TastyButton() +{ +} + +void TastyButton::drawButton( QPainter * p ) +{ + //background image or pseudo transparency + if( parentWidget()->erasePixmap() ) + { + const QPixmap erasePix(size()); + QPainter buffPainter(&erasePix); + buffPainter.drawPixmap(QPoint(0, 0), *parentWidget()->erasePixmap(), geometry()); + buffPainter.end(); + + QImage eraseImg = erasePix.convertToImage(); + if( isDown() ) + { + KImageEffect::fade(eraseImg, 0.25, black); + p->drawPixmap(rect(), eraseImg ); + } + else if( uses3D() ) + { + KImageEffect::fade(eraseImg, 0.4, white); + p->drawPixmap(rect(), eraseImg ); + } + else + p->drawPixmap(rect(), erasePix ); + + //lightScore = 0 grey, >0 lighter <0 darker + int lightScore = 0; + //chacks the brightness of 10 pixels of the diagonal + //we won't be 100% sure if this reflects the global brightess of the image + //but it seems to work well + int x = 0; + int y = 0; + while( x < eraseImg.width() && y < eraseImg.height() && x < 10 ) + { + x=++y; + //deciding the text color to use + int h,s,v; + QColor(eraseImg.pixel(x,y)).getHsv( h, s, v ); + // is purely empirical :) + if( v > 140) lightScore++; + else lightScore--; + } + if( lightScore < 0 ) + setPaletteForegroundColor(white); + else + setPaletteForegroundColor(black); + } + //simple background color + else + { + if( isDown() ) + { + p->fillRect(rect(), colorGroup().background().dark(120)); + } + else if( uses3D() ) + { + p->fillRect(rect(), colorGroup().background().light(120)); + } + else + { + p->fillRect(rect(), colorGroup().background()); + } + } + + drawButtonLabel(p); +} + +void TastyButton::setIconSet( QIconSet is ) +{ + is.setPixmap(iconEffect->apply(is.pixmap(), + (int)KIcon::Panel, + (int)KIcon::ActiveState), + QIconSet::Automatic, + QIconSet::Active); + + QToolButton::setIconSet( is ); +} + |