1
/* smplayer, GUI front-end for mplayer.
2
Copyright (C) 2006-2012 Ricardo Villalba <rvm@users.sourceforge.net>
3
umplayer, Copyright (C) 2010 Ori Rejwan
5
This program is free software; you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published by
7
the Free Software Foundation; either version 2 of the License, or
8
(at your option) any later version.
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
15
You should have received a copy of the GNU General Public License
16
along with this program; if not, write to the Free Software
17
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
#include <QPaintEvent>
26
MyButton::MyButton(QWidget *parent) :
27
QAbstractButton(parent), mouseHover(false), state(false), action(0)
33
void MyButton::paintEvent(QPaintEvent *e)
36
if(isEnabled() && ( isDown() || isChecked()))
38
pix = icon.pixmap(MyIcon::MouseDown, state ? MyIcon::On : MyIcon::Off);
40
else if(isEnabled() && mouseHover)
42
pix = icon.pixmap(MyIcon::MouseOver, state ? MyIcon::On : MyIcon::Off);
46
pix = icon.pixmap(MyIcon::Normal, state ? MyIcon::On : MyIcon::Off);
50
pix = icon.pixmap(MyIcon::Disabled, state ? MyIcon::On : MyIcon::Off);
54
p.drawPixmap(0,0,pix);
58
void MyButton::enterEvent(QEvent *)
64
void MyButton::leaveEvent(QEvent *)
70
void MyButton::setAction(MyAction *pAction)
75
setEnabled(action->isEnabled());
76
action->installEventFilter(this);
77
connect(this, SIGNAL(clicked()), action, SLOT(trigger()));
78
if( action->isCheckable())
81
connect(action, SIGNAL(toggled(bool)), this, SLOT(toggleImage()));
86
bool MyButton::eventFilter(QObject *watched, QEvent *event)
90
if(event->type() == QEvent::ActionChanged)
92
setEnabled(action->isEnabled());
98
void MyButton::toggleImage()
100
if(isCheckable()) setChecked(action->isChecked());
101
else setState(action->isChecked());
105
#include "moc_mybutton.cpp"