summaryrefslogtreecommitdiffstats
path: root/pacman-c++/mainwidget.cpp
diff options
context:
space:
mode:
authormanuel <manuel@mausz.at>2011-04-09 15:28:00 +0200
committermanuel <manuel@mausz.at>2011-04-09 15:28:00 +0200
commitb0d6e4fcf33d21b24d2e9bbf7c5abf2065f0a4b3 (patch)
treefecad081d78a75463be914f2a67ae80c9bc9da7c /pacman-c++/mainwidget.cpp
parent13199a5212e210206b8d6b938f7c1683760cf226 (diff)
downloadfoop-b0d6e4fcf33d21b24d2e9bbf7c5abf2065f0a4b3.tar.gz
foop-b0d6e4fcf33d21b24d2e9bbf7c5abf2065f0a4b3.tar.bz2
foop-b0d6e4fcf33d21b24d2e9bbf7c5abf2065f0a4b3.zip
move sound toggle icon to mainwidget
Diffstat (limited to 'pacman-c++/mainwidget.cpp')
-rw-r--r--pacman-c++/mainwidget.cpp45
1 files changed, 42 insertions, 3 deletions
diff --git a/pacman-c++/mainwidget.cpp b/pacman-c++/mainwidget.cpp
index 79648c5..02ece0f 100644
--- a/pacman-c++/mainwidget.cpp
+++ b/pacman-c++/mainwidget.cpp
@@ -5,11 +5,11 @@
5#include "point.h" 5#include "point.h"
6#include "constants.h" 6#include "constants.h"
7#include "audioplayer.h" 7#include "audioplayer.h"
8 8#include "clicklabel.h"
9#include "util.h" 9#include "util.h"
10 10
11MainWidget::MainWidget(QWidget *parent) 11MainWidget::MainWidget(QMainWindow *window, QWidget *parent)
12 : SceneHolder(parent), m_currentKey(0), m_running(false) 12 : SceneHolder(parent), m_mainwindow(window), m_currentKey(0), m_running(false)
13{ 13{
14 createGui(); 14 createGui();
15 updateMap(Util::createDummyMap()); 15 updateMap(Util::createDummyMap());
@@ -26,6 +26,7 @@ MainWidget::MainWidget(QWidget *parent)
26 26
27void MainWidget::createGui() 27void MainWidget::createGui()
28{ 28{
29 createMenu();
29 setFocusPolicy(Qt::StrongFocus); 30 setFocusPolicy(Qt::StrongFocus);
30 31
31 QVBoxLayout *layout = new QVBoxLayout(this); 32 QVBoxLayout *layout = new QVBoxLayout(this);
@@ -67,6 +68,29 @@ void MainWidget::createGui()
67 setLayout(layout); 68 setLayout(layout);
68} 69}
69 70
71void MainWidget::createMenu()
72{
73 QAction *quitAction = new QAction("E&xit", this);
74 connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
75
76 QMenu *fileMenu = m_mainwindow->menuBar()->addMenu("File");
77 fileMenu->addAction(quitAction);
78
79 ClickLabel *toggleSound = new ClickLabel("Toggle Sound", this);
80 toggleSound->setFixedWidth(20);
81 toggleSound->setFixedHeight(16);
82 toggleSound->setAlignment(Qt::AlignBottom);
83 bool sound = AudioPlayer::self()->isWorking();
84 QImage img(sound ? ":/soundon" : ":/soundoff");
85 img.setColor(1, m_mainwindow->menuBar()->palette().color(sound ? QPalette::Active : QPalette::Disabled,
86 QPalette::ButtonText).rgba());
87 toggleSound->setPixmap(QPixmap::fromImage(img));
88 if (sound)
89 connect(toggleSound, SIGNAL(clicked()), this, SLOT(toggleSound()));
90
91 m_mainwindow->menuBar()->setCornerWidget(toggleSound);
92}
93
70void MainWidget::updateScore() 94void MainWidget::updateScore()
71{ 95{
72 QMapIterator<Color::Color, Actor*> i(m_actors); 96 QMapIterator<Color::Color, Actor*> i(m_actors);
@@ -189,3 +213,18 @@ void MainWidget::playerScoreClicked()
189 tmp->setChecked(true); 213 tmp->setChecked(true);
190 return; 214 return;
191} 215}
216
217void MainWidget::toggleSound() const
218{
219 if (!AudioPlayer::self()->isWorking())
220 return;
221
222 bool muted = AudioPlayer::self()->isMuted();
223 QImage img(muted ? ":/soundon" : ":/soundoff");
224 img.setColor(1, m_mainwindow->menuBar()->palette().color(
225 muted ? QPalette::Active : QPalette::Disabled,
226 QPalette::ButtonText).rgba());
227 ClickLabel *tmp = qobject_cast<ClickLabel *>(m_mainwindow->menuBar()->cornerWidget());
228 tmp->setPixmap(QPixmap::fromImage(img));
229 AudioPlayer::self()->setMuted(!muted);
230}