-
Notifications
You must be signed in to change notification settings - Fork 0
/
global.cpp
47 lines (37 loc) · 956 Bytes
/
global.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "global.h"
#include <QSettings>
#include <QSoundEffect>
Global * Global::s_instance;
Global::Global(QObject *parent)
: QObject(parent)
{
Q_ASSERT(!s_instance);
s_instance = this;
}
VolumeAction *Global::volumeAction()
{
if (!m_volumeAction) {
QSettings s;
float volume = s.value("volume", 0.5).toFloat();
m_volumeAction = new VolumeAction(volume, this);
connect(m_volumeAction, SIGNAL(volumeChanged(float)), this, SLOT(volumeChanged(float)));
}
return m_volumeAction;
}
Global *Global::instance()
{
Q_ASSERT(s_instance);
return s_instance;
}
void Global::volumeChanged(float v)
{
QSettings s;
s.setValue("volume", v);
if (!m_soundEffect) {
m_soundEffect = new QSoundEffect(this);
m_soundEffect->setSource(QUrl("qrc:/assets/clock.wav"));
m_soundEffect->setLoopCount(1);
}
m_soundEffect->setVolume(v);
m_soundEffect->play();
}