From: Jukka K Date: Thu, 22 Apr 2010 13:43:08 +0000 (+0300) Subject: Custom button class added. X-Git-Tag: help~1 X-Git-Url: http://git.maemo.org/git/?p=speedfreak;a=commitdiff_plain;h=aa40ce55230787b7a57cc0588cd7e56d30a89dd2 Custom button class added. --- diff --git a/Client/custombutton.cpp b/Client/custombutton.cpp new file mode 100644 index 0000000..af023ad --- /dev/null +++ b/Client/custombutton.cpp @@ -0,0 +1,75 @@ +/* + * Custom button class for customized button. + * + * @author Jukka Kurttila + * @copyright (c) 2010 Speed Freak team + * @license http://opensource.org/licenses/gpl-license.php GNU Public License + */ + +#include "custombutton.h" + +#include +#include + +/** + *Constructor of this class. + */ +CustomButton::CustomButton(QWidget *parent, QIcon *icon) : QWidget(parent) +{ + bPressed = false; + if( icon ) + { + pict1 = new QPixmap(icon->pixmap(125,125,QIcon::Normal,QIcon::On)); + pict2 = new QPixmap(icon->pixmap(125,125,QIcon::Normal,QIcon::Off)); + } +} +/** + *Destructor of this class. + */ +CustomButton::~CustomButton() +{ + if(!pict1) + delete pict1; + if(!pict2) + delete pict2; +} + +void CustomButton::paintEvent(QPaintEvent *) +{ + QPainter painter(this); + + if(!bPressed) + painter.drawPixmap(0,0,*pict2); + else + painter.drawPixmap(0,0,*pict1); + + //Debug print + //painter.drawText(50,50,"y: "+QString::number(mY)); +} +void CustomButton::mousePressEvent(QMouseEvent* me) +{ + bPressed = true; + repaint(); +} +void CustomButton::mouseReleaseEvent(QMouseEvent* me) +{ + mX = me->x(); + mY = me->y(); + //Emit open dialog signal if mouse is still over button + if( mY < this->height() && mY > 0 && mX < this->width() && mX > 0 ) + emit OpenDialog(); + + bPressed = false; + repaint(); +} +void CustomButton::mouseMoveEvent(QMouseEvent* me) +{ + mX = me->x(); + mY = me->y(); + //Is mouse moved outside button? + if( mY > this->height() || mY < 0 || mX > this->width() || mX < 0 ) + bPressed = false; + else + bPressed = true; + repaint(); +} diff --git a/Client/custombutton.h b/Client/custombutton.h new file mode 100644 index 0000000..cad74ec --- /dev/null +++ b/Client/custombutton.h @@ -0,0 +1,39 @@ +/* + * Custom button class for customized button. + * + * @author Jukka Kurttila + * @copyright (c) 2010 Speed Freak team + * @license http://opensource.org/licenses/gpl-license.php GNU Public License + */ + +#ifndef CUSTOMBUTTON_H +#define CUSTOMBUTTON_H + +#include +#include +#include + +class CustomButton : public QWidget +{ + Q_OBJECT +public: + CustomButton(QWidget *parent = 0, QIcon* iconParam = 0); + ~CustomButton(); + +signals: + void OpenDialog(); + +protected: + void paintEvent(QPaintEvent *); + void mousePressEvent(QMouseEvent* me); + void mouseReleaseEvent(QMouseEvent* me); + void mouseMoveEvent(QMouseEvent* me); + +private: + QPixmap* pict1; + QPixmap* pict2; + bool bPressed; + int mX,mY; +}; + +#endif // CUSTOMBUTTON_H