buttoneventlistener.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #include "gui/buttoneventlistener.h"
  2. #include "soundengine.h"
  3. #include <QPushButton>
  4. #include <QEvent>
  5. ButtonEventListener::ButtonEventListener(QObject *parent) : QObject(parent)
  6. {
  7. }
  8. bool ButtonEventListener::eventFilter(QObject * watched, QEvent * event) {
  9. QPushButton * button = qobject_cast<QPushButton*>(watched);
  10. if (!button) {
  11. return false;
  12. }
  13. if (event->type() == QEvent::Enter) {
  14. button->setStyleSheet("border-image: url(:/assets/common/buttons/" + button->objectName() + "_hover.png);");
  15. SoundEngine::getInstance().playAsync("qrc:/assets/common/buttons/button_hover.mp3");
  16. return false;
  17. }
  18. if (event->type() == QEvent::Leave){
  19. button->setStyleSheet("border-image: url(:/assets/common/buttons/" + button->objectName() + ".png);");
  20. SoundEngine::getInstance().playAsync("qrc:/assets/common/buttons/button_hover.mp3");
  21. return false;
  22. }
  23. if (event->type() == QEvent::MouseButtonPress) {
  24. SoundEngine::getInstance().playAsync("qrc:/assets/common/buttons/button_click.mp3");
  25. return false;
  26. }
  27. return false;
  28. }