2 * Custom button class for customized button.
4 * @author Jukka Kurttila <jktla@suomi24.fi>
5 * @copyright (c) 2010 Speed Freak team
6 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
9 #include "custombutton.h"
15 *Constructor of this class.
17 CustomButton::CustomButton(QWidget *parent, QIcon *icon) : QWidget(parent)
20 //Get size of the icon
21 QList<QSize> list = icon->availableSizes(QIcon::Normal,QIcon::On);
23 //If icon is empty, do not create pixmaps and leave
26 QSize size = list.first();
29 pict1 = new QPixmap(icon->pixmap(size.width(),size.height(),QIcon::Normal,QIcon::On));
30 pict2 = new QPixmap(icon->pixmap(size.width(),size.height(),QIcon::Normal,QIcon::Off));
34 *Destructor of this class.
36 CustomButton::~CustomButton()
44 void CustomButton::paintEvent(QPaintEvent *)
46 QPainter painter(this);
49 painter.drawPixmap(0,0,*pict2);
51 painter.drawPixmap(0,0,*pict1);
54 //painter.drawText(50,50,"y: "+QString::number(mY));
56 void CustomButton::mousePressEvent(QMouseEvent* me)
61 void CustomButton::mouseReleaseEvent(QMouseEvent* me)
65 //Emit open dialog signal if mouse is still over button
66 if( mY < this->height() && mY > 0 && mX < this->width() && mX > 0 )
72 void CustomButton::mouseMoveEvent(QMouseEvent* me)
76 //Is mouse moved outside button?
77 if( mY > this->height() || mY < 0 || mX > this->width() || mX < 0 )