simplify qpushbuttonwithsound and add a mouseover sound (I tried selecting the least annoying ones, maybe it'd be better to look for proper button sound effects)
authorkoda
Wed, 18 Jan 2012 01:07:07 +0100
changeset 6584 5bb48450b978
parent 6583 4218782d8ca0
child 6585 6225b838a630
simplify qpushbuttonwithsound and add a mouseover sound (I tried selecting the least annoying ones, maybe it'd be better to look for proper button sound effects)
QTfrontend/ui/mouseoverfilter.cpp
QTfrontend/ui/widget/qpushbuttonwithsound.cpp
--- a/QTfrontend/ui/mouseoverfilter.cpp	Tue Jan 17 23:42:30 2012 +0100
+++ b/QTfrontend/ui/mouseoverfilter.cpp	Wed Jan 18 01:07:07 2012 +0100
@@ -1,11 +1,18 @@
-#include "mouseoverfilter.h"
-#include "ui/page/AbstractPage.h"
-#include "ui_hwform.h"
 
 #include <QEvent>
 #include <QWidget>
 #include <QStackedLayout>
 #include <QLabel>
+#include <QLineEdit>
+#include <QCheckBox>
+
+#include "mouseoverfilter.h"
+#include "ui/page/AbstractPage.h"
+#include "ui_hwform.h"
+#include "hwform.h"
+#include "gameuiconfig.h"
+#include "HWDataManager.h"
+#include "SDLInteraction.h"
 
 MouseOverFilter::MouseOverFilter(QObject *parent) :
     QObject(parent)
@@ -25,6 +32,18 @@
         else if (widget->toolTip() != NULL)
             abstractpage->setButtonDescription(widget->toolTip());
 
+        // play a sound when mouse hovers certain ui elements
+        QPushButton * button = dynamic_cast<QPushButton*>(dist);
+        QLineEdit * textfield = dynamic_cast<QLineEdit*>(dist);
+        QCheckBox * checkbox = dynamic_cast<QCheckBox*>(dist);
+        QComboBox * droplist = dynamic_cast<QComboBox*>(dist);
+        QSlider * slider = dynamic_cast<QSlider*>(dist);
+        QTabWidget * tab = dynamic_cast<QTabWidget*>(dist);
+        if (HWForm::config->isFrontendSoundEnabled() && (button || textfield || checkbox || droplist || slider || tab)) {
+            HWDataManager & dataMgr = HWDataManager::instance();
+            SDLInteraction::instance().playSoundFile(dataMgr.findFileForRead("Sounds/steps.ogg"));
+        }
+
         return true;
     }
     else if (event->type() == QEvent::Leave)
--- a/QTfrontend/ui/widget/qpushbuttonwithsound.cpp	Tue Jan 17 23:42:30 2012 +0100
+++ b/QTfrontend/ui/widget/qpushbuttonwithsound.cpp	Wed Jan 18 01:07:07 2012 +0100
@@ -1,11 +1,11 @@
-#include "qpushbuttonwithsound.h"
 #include <QMessageBox>
-#include <HWDataManager.h>
 #include <QDir>
-#include <SDLInteraction.h>
-#include <hwform.h>
-#include <QSettings>
-#include <gameuiconfig.h>
+
+#include "qpushbuttonwithsound.h"
+#include "HWDataManager.h"
+#include "SDLInteraction.h"
+#include "hwform.h"
+#include "gameuiconfig.h"
 
 QPushButtonWithSound::QPushButtonWithSound(QWidget *parent) :
     QPushButton(parent),
@@ -21,14 +21,6 @@
 
     HWDataManager & dataMgr = HWDataManager::instance();
 
-    QString soundsDir = QString("Sounds/");
-
-    QStringList list = dataMgr.entryList(
-            soundsDir,
-            QDir::Files,
-            QStringList() <<
-                "shotgunreload.ogg"
-            );
-    if(!list.empty())
-        SDLInteraction::instance().playSoundFile(dataMgr.findFileForRead(soundsDir + "/" + list[0]));
+    if (this->isEnabled())
+        SDLInteraction::instance().playSoundFile(dataMgr.findFileForRead("Sounds/roperelease.ogg"));
 }