summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pacman-c++/client.cpp38
-rw-r--r--pacman-c++/client.h3
-rw-r--r--pacman-c++/mainwidget.cpp45
-rw-r--r--pacman-c++/mainwidget.h6
4 files changed, 47 insertions, 45 deletions
diff --git a/pacman-c++/client.cpp b/pacman-c++/client.cpp
index 7827591..2135636 100644
--- a/pacman-c++/client.cpp
+++ b/pacman-c++/client.cpp
@@ -1,47 +1,11 @@
1#include "client.h" 1#include "client.h"
2#include "audioplayer.h"
3#include "clicklabel.h"
4 2
5Client::Client() 3Client::Client()
6{ 4{
7 QAction *quitAction = new QAction("E&xit", this); 5 m_mainWidget = new MainWidget(this, this);
8 connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
9
10 QMenu *fileMenu = menuBar()->addMenu("File");
11 fileMenu->addAction(quitAction);
12
13 ClickLabel *toggleSound = new ClickLabel("Toggle Sound", this);
14 toggleSound->setFixedWidth(20);
15 toggleSound->setFixedHeight(16);
16 toggleSound->setAlignment(Qt::AlignBottom);
17 bool sound = AudioPlayer::self()->isWorking();
18 QImage img(sound ? ":/soundon" : ":/soundoff");
19 img.setColor(1, menuBar()->palette().color(sound ? QPalette::Active : QPalette::Disabled,
20 QPalette::ButtonText).rgba());
21 toggleSound->setPixmap(QPixmap::fromImage(img));
22 if (sound)
23 connect(toggleSound, SIGNAL(clicked()), this, SLOT(toggleSound()));
24
25 menuBar()->setCornerWidget(toggleSound);
26
27 m_mainWidget = new MainWidget();
28 setCentralWidget(m_mainWidget); 6 setCentralWidget(m_mainWidget);
29} 7}
30 8
31void Client::toggleSound() const
32{
33 if (!AudioPlayer::self()->isWorking())
34 return;
35
36 bool muted = AudioPlayer::self()->isMuted();
37 QImage img(muted ? ":/soundon" : ":/soundoff");
38 img.setColor(1, menuBar()->palette().color(muted ? QPalette::Active : QPalette::Disabled,
39 QPalette::ButtonText).rgba());
40 ClickLabel *tmp = qobject_cast<ClickLabel *>(menuBar()->cornerWidget());
41 tmp->setPixmap(QPixmap::fromImage(img));
42 AudioPlayer::self()->setMuted(!muted);
43}
44
45int main(int argc, char ** argv) 9int main(int argc, char ** argv)
46{ 10{
47 QApplication app(argc, argv); 11 QApplication app(argc, argv);
diff --git a/pacman-c++/client.h b/pacman-c++/client.h
index 56f3602..476b972 100644
--- a/pacman-c++/client.h
+++ b/pacman-c++/client.h
@@ -11,9 +11,6 @@ class Client
11public: 11public:
12 Client(); 12 Client();
13 13
14public slots:
15 void toggleSound() const;
16
17private: 14private:
18 MainWidget *m_mainWidget; 15 MainWidget *m_mainWidget;
19}; 16};
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}
diff --git a/pacman-c++/mainwidget.h b/pacman-c++/mainwidget.h
index 27e901f..650a472 100644
--- a/pacman-c++/mainwidget.h
+++ b/pacman-c++/mainwidget.h
@@ -7,7 +7,6 @@
7#include "pixmapitem.h" 7#include "pixmapitem.h"
8#include <QtGui> 8#include <QtGui>
9#include <QtCore> 9#include <QtCore>
10#include <phonon/MediaObject>
11 10
12class Actor; 11class Actor;
13 12
@@ -17,7 +16,7 @@ class MainWidget
17 Q_OBJECT 16 Q_OBJECT
18 17
19public: 18public:
20 MainWidget(QWidget *parent = 0); 19 MainWidget(QMainWindow *window = 0, QWidget *parent = 0);
21 20
22protected: 21protected:
23 // handling of current key 22 // handling of current key
@@ -28,6 +27,7 @@ protected:
28 27
29private: 28private:
30 void createGui(); 29 void createGui();
30 void createMenu();
31 void updateScore(); 31 void updateScore();
32 bool isRunning(); 32 bool isRunning();
33 33
@@ -35,8 +35,10 @@ private slots:
35 void startGame(); 35 void startGame();
36 void playerScoreClicked(); 36 void playerScoreClicked();
37 void tick(); 37 void tick();
38 void toggleSound() const;
38 39
39private: 40private:
41 QMainWindow *m_mainwindow;
40 42
41 // GUI elements needed in the progress of the game 43 // GUI elements needed in the progress of the game
42 QList<QGridLayout*> m_playerScoreLayouts; 44 QList<QGridLayout*> m_playerScoreLayouts;