summaryrefslogtreecommitdiffstats
path: root/pacman-c++/client.cpp
diff options
context:
space:
mode:
authormanuel <manuel@mausz.at>2011-04-14 02:37:31 +0200
committermanuel <manuel@mausz.at>2011-04-14 02:37:31 +0200
commitb18385a95f25e13c767244b494f31bd4fc238143 (patch)
treeaf389057a2d4a03565f70186d7c1d2e49b95828f /pacman-c++/client.cpp
parent3d20638fa8e295271ce38953ad1c657d9275bd99 (diff)
downloadfoop-b18385a95f25e13c767244b494f31bd4fc238143.tar.gz
foop-b18385a95f25e13c767244b494f31bd4fc238143.tar.bz2
foop-b18385a95f25e13c767244b494f31bd4fc238143.zip
encapsulate gapless audioplayer commit from yesterday into an own class (gaplessaudioplayer)
added two new menu entrys: toggle sound + toggle ambient sound (2. very useful!)
Diffstat (limited to 'pacman-c++/client.cpp')
-rw-r--r--pacman-c++/client.cpp93
1 files changed, 68 insertions, 25 deletions
diff --git a/pacman-c++/client.cpp b/pacman-c++/client.cpp
index 5cc9279..fc0fdfc 100644
--- a/pacman-c++/client.cpp
+++ b/pacman-c++/client.cpp
@@ -4,63 +4,106 @@
4#include "pacman.pb.h" 4#include "pacman.pb.h"
5 5
6Client::Client() 6Client::Client()
7 : m_ambientMuted(false)
7{ 8{
8 m_settings = new QSettings(qApp->organizationName(), qApp->applicationName(), this); 9 m_settings = new QSettings(qApp->organizationName(), qApp->applicationName(), this);
9 createMenu(); 10 createMenu();
10 m_mainWidget = new MainWidget(this); 11 m_mainWidget = new MainWidget(this);
12 m_mainWidget->setAmbientMuted(m_ambientMuted);
11 setCentralWidget(m_mainWidget); 13 setCentralWidget(m_mainWidget);
12} 14}
13 15
14void Client::createMenu() 16void Client::createMenu()
15{ 17{
16 QAction *quitAction = new QAction("E&xit", this);
17 connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
18
19 QMenu *fileMenu = menuBar()->addMenu("File"); 18 QMenu *fileMenu = menuBar()->addMenu("File");
20 fileMenu->addAction(quitAction);
21 19
20 bool sound = AudioManager::self()->isWorking();
21 bool muted = !sound || m_settings->value("muted", false).toBool();
22 AudioManager::self()->setMuted(muted);
23
24 /* toggle sound: corner icon */
22 ClickLabel *toggleSound = new ClickLabel("Toggle Sound", this); 25 ClickLabel *toggleSound = new ClickLabel("Toggle Sound", this);
23 toggleSound->setToolTip("Toggle Sound"); 26 toggleSound->setToolTip("Toggle Sound");
24 toggleSound->setFixedWidth(20); 27 toggleSound->setFixedWidth(20);
25 toggleSound->setFixedHeight(16); 28 toggleSound->setFixedHeight(16);
26 toggleSound->setAlignment(Qt::AlignBottom); 29 toggleSound->setAlignment(Qt::AlignBottom);
27 30 toggleSound->setPixmap(soundIcon(!muted));
28 bool sound = AudioManager::self()->isWorking();
29 bool muted = !sound || m_settings->value("muted", false).toBool();
30 AudioManager::self()->setMuted(muted);
31
32 QImage img(muted ? ":/soundoff" : ":/soundon");
33 img.setColor(1, menuBar()->palette().color(
34 muted ? QPalette::Disabled : QPalette::Active,
35 QPalette::ButtonText).rgba());
36 toggleSound->setPixmap(QPixmap::fromImage(img));
37
38 if (sound) 31 if (sound)
39 { 32 {
40 connect(toggleSound, SIGNAL(clicked()), this, SLOT(toggleSound())); 33 connect(toggleSound, SIGNAL(clicked()), this, SLOT(toggleSound()));
41 connect(AudioManager::self(), SIGNAL(mutedChanged(bool)), this, SLOT(mutedChanged(bool))); 34 connect(AudioManager::self(), SIGNAL(mutedChanged(bool)), this, SLOT(mutedChanged(bool)));
42 } 35 }
43
44 menuBar()->setCornerWidget(toggleSound); 36 menuBar()->setCornerWidget(toggleSound);
37
38 /* toggle sound: menu */
39 QAction *toggleSoundAction = new QAction("Sound", this);
40 toggleSoundAction->setToolTip("Toggle Sound");
41 toggleSoundAction->setCheckable(true);
42 toggleSoundAction->setChecked(!muted);
43 toggleSoundAction->setDisabled(!sound);
44 fileMenu->addAction(toggleSoundAction);
45 if (sound)
46 {
47 connect(toggleSoundAction, SIGNAL(triggered()), this, SLOT(toggleSound()));
48 connect(this, SIGNAL(setMuteActionsChecked(bool)), toggleSoundAction, SLOT(setChecked(bool)));
49 }
50
51 /* toggle ambient sound: menu */
52 m_ambientMuted = muted || m_settings->value("ambientMuted", false).toBool();
53 QAction *toggleAmbientAction = new QAction("Ambient Sound", this);
54 toggleAmbientAction->setToolTip("Toggle Ambient Sound");
55 toggleAmbientAction->setCheckable(true);
56 toggleAmbientAction->setChecked(!m_ambientMuted);
57 toggleAmbientAction->setDisabled(!sound);
58 fileMenu->addAction(toggleAmbientAction);
59 if (sound)
60 {
61 connect(toggleAmbientAction, SIGNAL(triggered(bool)), this, SLOT(enableAmbientSound(bool)));
62 connect(this, SIGNAL(setMuteActionsChecked(bool)), toggleAmbientAction, SLOT(setEnabled(bool)));
63 }
64
65 /* exit entry */
66 fileMenu->addSeparator();
67 QAction *quitAction = new QAction("E&xit", this);
68 connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
69 fileMenu->addAction(quitAction);
45} 70}
46 71
47void Client::toggleSound() const 72void Client::toggleSound()
48{ 73{
49 if (!AudioManager::self()->isWorking()) 74 if (!AudioManager::self()->isWorking())
50 return; 75 return;
51 AudioManager::self()->setMuted(!AudioManager::self()->isMuted()); 76 bool muted = !AudioManager::self()->isMuted();
77 AudioManager::self()->setMuted(muted);
78 /* mute ambient sound again if explicitly muted */
79 if (!muted && m_ambientMuted)
80 m_mainWidget->setAmbientMuted(true);
52} 81}
53 82
54void Client::mutedChanged(bool muted) const 83void Client::mutedChanged(bool muted)
55{ 84{
56 QImage img(muted ? ":/soundoff" : ":/soundon");
57 img.setColor(1, menuBar()->palette().color(
58 muted ? QPalette::Disabled : QPalette::Active,
59 QPalette::ButtonText).rgba());
60 ClickLabel *tmp = qobject_cast<ClickLabel *>(menuBar()->cornerWidget()); 85 ClickLabel *tmp = qobject_cast<ClickLabel *>(menuBar()->cornerWidget());
61 tmp->setPixmap(QPixmap::fromImage(img)); 86 tmp->setPixmap(soundIcon(!muted));
62
63 m_settings->setValue("muted", muted); 87 m_settings->setValue("muted", muted);
88 emit setMuteActionsChecked(!muted);
89}
90
91void Client::enableAmbientSound(bool enabled)
92{
93 if (!AudioManager::self()->isWorking())
94 return;
95 m_ambientMuted = !enabled;
96 m_mainWidget->setAmbientMuted(m_ambientMuted);
97 m_settings->setValue("ambientMuted", m_ambientMuted);
98}
99
100QPixmap Client::soundIcon(bool enabled) const
101{
102 QImage img(enabled ? ":/soundon" : ":/soundoff");
103 img.setColor(1, menuBar()->palette().color(
104 enabled ? QPalette::Active : QPalette::Disabled,
105 QPalette::ButtonText).rgba());
106 return QPixmap::fromImage(img);
64} 107}
65 108
66bool Constants::server = false; 109bool Constants::server = false;