Route and Results buttons updated.
[speedfreak] / Client / custombutton.cpp
1 /*
2  * Custom button class for customized button.
3  *
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
7  */
8
9 #include "custombutton.h"
10
11 #include <QPainter>
12 #include <QIcon>
13
14 /**
15   *Constructor of this class.
16   */
17 CustomButton::CustomButton(QWidget *parent, QIcon *icon) : QWidget(parent)
18 {
19     bPressed = false;
20     if( icon )
21     {
22         pict1 = new QPixmap(icon->pixmap(125,125,QIcon::Normal,QIcon::On));
23         pict2 = new QPixmap(icon->pixmap(125,125,QIcon::Normal,QIcon::Off));
24     }
25 }
26 /**
27   *Destructor of this class.
28   */
29 CustomButton::~CustomButton()
30 {
31     if(!pict1)
32         delete pict1;
33     if(!pict2)
34         delete pict2;
35 }
36
37 void CustomButton::paintEvent(QPaintEvent *)
38 {
39     QPainter painter(this);
40
41     if(!bPressed)
42         painter.drawPixmap(0,0,*pict2);
43     else
44         painter.drawPixmap(0,0,*pict1);
45
46     //Debug print
47     //painter.drawText(50,50,"y: "+QString::number(mY));
48 }
49 void CustomButton::mousePressEvent(QMouseEvent* me)
50 {
51     bPressed = true;
52     repaint();
53 }
54 void CustomButton::mouseReleaseEvent(QMouseEvent* me)
55 {
56     mX = me->x();
57     mY = me->y();
58     //Emit open dialog signal if mouse is still over button
59     if( mY < this->height() && mY > 0 && mX < this->width() && mX > 0 )
60         emit OpenDialog();
61
62     bPressed = false;
63     repaint();
64 }
65 void CustomButton::mouseMoveEvent(QMouseEvent* me)
66 {
67     mX = me->x();
68     mY = me->y();
69     //Is mouse moved outside button?
70     if( mY > this->height() || mY < 0 || mX > this->width() || mX < 0 )
71         bPressed = false;
72     else
73         bPressed = true;
74     repaint();
75 }