1234567891011121314151617181920212223242526272829303132333435363738 |
- #include "gui/buttoneventlistener.h"
- #include "soundengine.h"
- #include <QPushButton>
- #include <QEvent>
- ButtonEventListener::ButtonEventListener(QObject *parent) : QObject(parent)
- {
- }
- bool ButtonEventListener::eventFilter(QObject * watched, QEvent * event) {
- QPushButton * button = qobject_cast<QPushButton*>(watched);
- if (!button) {
- return false;
- }
- if (event->type() == QEvent::Enter) {
- button->setStyleSheet("border-image: url(:/assets/common/buttons/" + button->objectName() + "_hover.png);");
- SoundEngine::getInstance().playAsync("qrc:/assets/common/buttons/button_hover.mp3");
- return false;
- }
- if (event->type() == QEvent::Leave){
- button->setStyleSheet("border-image: url(:/assets/common/buttons/" + button->objectName() + ".png);");
- SoundEngine::getInstance().playAsync("qrc:/assets/common/buttons/button_hover.mp3");
- return false;
- }
- if (event->type() == QEvent::MouseButtonPress || event->type() == QEvent::MouseButtonDblClick) {
- SoundEngine::getInstance().playAsync("qrc:/assets/common/buttons/button_click.mp3");
- return false;
- }
- return false;
- }
|