diff options
| -rw-r--r-- | pacman-c++/audioplayer.cpp | 8 | ||||
| -rw-r--r-- | pacman-c++/audioplayer.h | 2 | ||||
| -rw-r--r-- | pacman-c++/client.cpp | 58 | ||||
| -rw-r--r-- | pacman-c++/client.h | 9 | ||||
| -rw-r--r-- | pacman-c++/mainwidget.cpp | 46 | ||||
| -rw-r--r-- | pacman-c++/mainwidget.h | 6 |
6 files changed, 79 insertions, 50 deletions
diff --git a/pacman-c++/audioplayer.cpp b/pacman-c++/audioplayer.cpp index 5170183..238e05d 100644 --- a/pacman-c++/audioplayer.cpp +++ b/pacman-c++/audioplayer.cpp | |||
| @@ -39,6 +39,8 @@ AudioPlayer::AudioPlayer() | |||
| 39 | connect(m_player, SIGNAL(aboutToFinish()), this, SLOT(aboutToFinish_p())); | 39 | connect(m_player, SIGNAL(aboutToFinish()), this, SLOT(aboutToFinish_p())); |
| 40 | 40 | ||
| 41 | m_output = new Phonon::AudioOutput(Phonon::MusicCategory, m_player); | 41 | m_output = new Phonon::AudioOutput(Phonon::MusicCategory, m_player); |
| 42 | connect(m_output, SIGNAL(mutedChanged(bool)), this, SLOT(mutedChanged_p(bool))); | ||
| 43 | |||
| 42 | Phonon::createPath(m_player, m_output); | 44 | Phonon::createPath(m_player, m_output); |
| 43 | 45 | ||
| 44 | preload(); | 46 | preload(); |
| @@ -169,3 +171,9 @@ void AudioPlayer::testFinished() | |||
| 169 | qDebug() << "There's no sound for you :("; | 171 | qDebug() << "There's no sound for you :("; |
| 170 | disconnect(m_player, SIGNAL(stateChanged(Phonon::State, Phonon::State)), this, SLOT(stateChanged_p(Phonon::State, Phonon::State))); | 172 | disconnect(m_player, SIGNAL(stateChanged(Phonon::State, Phonon::State)), this, SLOT(stateChanged_p(Phonon::State, Phonon::State))); |
| 171 | } | 173 | } |
| 174 | |||
| 175 | |||
| 176 | void AudioPlayer::mutedChanged_p(bool muted) | ||
| 177 | { | ||
| 178 | emit mutedChanged(muted); | ||
| 179 | } | ||
diff --git a/pacman-c++/audioplayer.h b/pacman-c++/audioplayer.h index 567ccb1..474b6ca 100644 --- a/pacman-c++/audioplayer.h +++ b/pacman-c++/audioplayer.h | |||
| @@ -41,6 +41,7 @@ public: | |||
| 41 | signals: | 41 | signals: |
| 42 | void finished(); | 42 | void finished(); |
| 43 | void aboutToFinish(); | 43 | void aboutToFinish(); |
| 44 | void mutedChanged(bool muted); | ||
| 44 | 45 | ||
| 45 | private: | 46 | private: |
| 46 | void test(); | 47 | void test(); |
| @@ -50,6 +51,7 @@ private slots: | |||
| 50 | void finished_p(); | 51 | void finished_p(); |
| 51 | void aboutToFinish_p(); | 52 | void aboutToFinish_p(); |
| 52 | void stateChanged_p(Phonon::State newstate, Phonon::State oldstate); | 53 | void stateChanged_p(Phonon::State newstate, Phonon::State oldstate); |
| 54 | void mutedChanged_p(bool muted); | ||
| 53 | void testFinished(); | 55 | void testFinished(); |
| 54 | 56 | ||
| 55 | private: | 57 | private: |
diff --git a/pacman-c++/client.cpp b/pacman-c++/client.cpp index 2135636..2142278 100644 --- a/pacman-c++/client.cpp +++ b/pacman-c++/client.cpp | |||
| @@ -1,14 +1,70 @@ | |||
| 1 | #include "client.h" | 1 | #include "client.h" |
| 2 | #include "clicklabel.h" | ||
| 3 | #include "audioplayer.h" | ||
| 2 | 4 | ||
| 3 | Client::Client() | 5 | Client::Client() |
| 4 | { | 6 | { |
| 5 | m_mainWidget = new MainWidget(this, this); | 7 | m_settings = new QSettings(qApp->organizationName(), qApp->applicationName(), this); |
| 8 | createMenu(); | ||
| 9 | m_mainWidget = new MainWidget(this); | ||
| 6 | setCentralWidget(m_mainWidget); | 10 | setCentralWidget(m_mainWidget); |
| 7 | } | 11 | } |
| 8 | 12 | ||
| 13 | void Client::createMenu() | ||
| 14 | { | ||
| 15 | QAction *quitAction = new QAction("E&xit", this); | ||
| 16 | connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit())); | ||
| 17 | |||
| 18 | QMenu *fileMenu = menuBar()->addMenu("File"); | ||
| 19 | fileMenu->addAction(quitAction); | ||
| 20 | |||
| 21 | ClickLabel *toggleSound = new ClickLabel("Toggle Sound", this); | ||
| 22 | toggleSound->setFixedWidth(20); | ||
| 23 | toggleSound->setFixedHeight(16); | ||
| 24 | toggleSound->setAlignment(Qt::AlignBottom); | ||
| 25 | |||
| 26 | bool sound = AudioPlayer::self()->isWorking(); | ||
| 27 | bool muted = sound && m_settings->value("muted", false).toBool(); | ||
| 28 | AudioPlayer::self()->setMuted(muted); | ||
| 29 | |||
| 30 | QImage img(muted ? ":/soundoff" : ":/soundon"); | ||
| 31 | img.setColor(1, menuBar()->palette().color( | ||
| 32 | muted ? QPalette::Disabled : QPalette::Active, | ||
| 33 | dQPalette::ButtonText).rgba()); | ||
| 34 | toggleSound->setPixmap(QPixmap::fromImage(img)); | ||
| 35 | |||
| 36 | if (sound) | ||
| 37 | { | ||
| 38 | connect(toggleSound, SIGNAL(clicked()), this, SLOT(toggleSound())); | ||
| 39 | connect(AudioPlayer::self(), SIGNAL(mutedChanged(bool)), this, SLOT(mutedChanged(bool))); | ||
| 40 | } | ||
| 41 | |||
| 42 | menuBar()->setCornerWidget(toggleSound); | ||
| 43 | } | ||
| 44 | |||
| 45 | void Client::toggleSound() const | ||
| 46 | { | ||
| 47 | if (!AudioPlayer::self()->isWorking()) | ||
| 48 | return; | ||
| 49 | AudioPlayer::self()->setMuted(!AudioPlayer::self()->isMuted()); | ||
| 50 | } | ||
| 51 | |||
| 52 | void Client::mutedChanged(bool muted) const | ||
| 53 | { | ||
| 54 | QImage img(muted ? ":/soundoff" : ":/soundon"); | ||
| 55 | img.setColor(1, menuBar()->palette().color( | ||
| 56 | muted ? QPalette::Disabled : QPalette::Active, | ||
| 57 | QPalette::ButtonText).rgba()); | ||
| 58 | ClickLabel *tmp = qobject_cast<ClickLabel *>(menuBar()->cornerWidget()); | ||
| 59 | tmp->setPixmap(QPixmap::fromImage(img)); | ||
| 60 | |||
| 61 | m_settings->setValue("muted", muted); | ||
| 62 | } | ||
| 63 | |||
| 9 | int main(int argc, char ** argv) | 64 | int main(int argc, char ** argv) |
| 10 | { | 65 | { |
| 11 | QApplication app(argc, argv); | 66 | QApplication app(argc, argv); |
| 67 | app.setOrganizationName("TU Wien FOOP"); | ||
| 12 | app.setApplicationName("Pacman Client"); | 68 | app.setApplicationName("Pacman Client"); |
| 13 | app.setWindowIcon(QIcon(":/appicon")); | 69 | app.setWindowIcon(QIcon(":/appicon")); |
| 14 | 70 | ||
diff --git a/pacman-c++/client.h b/pacman-c++/client.h index 476b972..2d507e2 100644 --- a/pacman-c++/client.h +++ b/pacman-c++/client.h | |||
| @@ -10,9 +10,18 @@ class Client | |||
| 10 | Q_OBJECT | 10 | Q_OBJECT |
| 11 | public: | 11 | public: |
| 12 | Client(); | 12 | Client(); |
| 13 | QSettings *settings(); | ||
| 14 | |||
| 15 | public slots: | ||
| 16 | void toggleSound() const; | ||
| 17 | void mutedChanged(bool) const; | ||
| 18 | |||
| 19 | private: | ||
| 20 | void createMenu(); | ||
| 13 | 21 | ||
| 14 | private: | 22 | private: |
| 15 | MainWidget *m_mainWidget; | 23 | MainWidget *m_mainWidget; |
| 24 | QSettings *m_settings; | ||
| 16 | }; | 25 | }; |
| 17 | 26 | ||
| 18 | #endif // CLIENT_H | 27 | #endif // CLIENT_H |
diff --git a/pacman-c++/mainwidget.cpp b/pacman-c++/mainwidget.cpp index 02ece0f..06a0b9c 100644 --- a/pacman-c++/mainwidget.cpp +++ b/pacman-c++/mainwidget.cpp | |||
| @@ -1,15 +1,12 @@ | |||
| 1 | #include "mainwidget.h" | 1 | #include "mainwidget.h" |
| 2 | #include "actor.h" | 2 | #include "actor.h" |
| 3 | #include "block.h" | 3 | #include "block.h" |
| 4 | #include "bonuspoint.h" | ||
| 5 | #include "point.h" | ||
| 6 | #include "constants.h" | 4 | #include "constants.h" |
| 7 | #include "audioplayer.h" | 5 | #include "audioplayer.h" |
| 8 | #include "clicklabel.h" | ||
| 9 | #include "util.h" | 6 | #include "util.h" |
| 10 | 7 | ||
| 11 | MainWidget::MainWidget(QMainWindow *window, QWidget *parent) | 8 | MainWidget::MainWidget(QWidget *parent) |
| 12 | : SceneHolder(parent), m_mainwindow(window), m_currentKey(0), m_running(false) | 9 | : SceneHolder(parent), m_currentKey(0), m_running(false) |
| 13 | { | 10 | { |
| 14 | createGui(); | 11 | createGui(); |
| 15 | updateMap(Util::createDummyMap()); | 12 | updateMap(Util::createDummyMap()); |
| @@ -26,7 +23,6 @@ MainWidget::MainWidget(QMainWindow *window, QWidget *parent) | |||
| 26 | 23 | ||
| 27 | void MainWidget::createGui() | 24 | void MainWidget::createGui() |
| 28 | { | 25 | { |
| 29 | createMenu(); | ||
| 30 | setFocusPolicy(Qt::StrongFocus); | 26 | setFocusPolicy(Qt::StrongFocus); |
| 31 | 27 | ||
| 32 | QVBoxLayout *layout = new QVBoxLayout(this); | 28 | QVBoxLayout *layout = new QVBoxLayout(this); |
| @@ -68,29 +64,6 @@ void MainWidget::createGui() | |||
| 68 | setLayout(layout); | 64 | setLayout(layout); |
| 69 | } | 65 | } |
| 70 | 66 | ||
| 71 | void 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 | |||
| 94 | void MainWidget::updateScore() | 67 | void MainWidget::updateScore() |
| 95 | { | 68 | { |
| 96 | QMapIterator<Color::Color, Actor*> i(m_actors); | 69 | QMapIterator<Color::Color, Actor*> i(m_actors); |
| @@ -213,18 +186,3 @@ void MainWidget::playerScoreClicked() | |||
| 213 | tmp->setChecked(true); | 186 | tmp->setChecked(true); |
| 214 | return; | 187 | return; |
| 215 | } | 188 | } |
| 216 | |||
| 217 | void 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 650a472..6adc876 100644 --- a/pacman-c++/mainwidget.h +++ b/pacman-c++/mainwidget.h | |||
| @@ -2,7 +2,6 @@ | |||
| 2 | #define MAINWIDGET_H | 2 | #define MAINWIDGET_H |
| 3 | 3 | ||
| 4 | #include "sceneholder.h" | 4 | #include "sceneholder.h" |
| 5 | |||
| 6 | #include "constants.h" | 5 | #include "constants.h" |
| 7 | #include "pixmapitem.h" | 6 | #include "pixmapitem.h" |
| 8 | #include <QtGui> | 7 | #include <QtGui> |
| @@ -16,7 +15,7 @@ class MainWidget | |||
| 16 | Q_OBJECT | 15 | Q_OBJECT |
| 17 | 16 | ||
| 18 | public: | 17 | public: |
| 19 | MainWidget(QMainWindow *window = 0, QWidget *parent = 0); | 18 | MainWidget(QWidget *parent = 0); |
| 20 | 19 | ||
| 21 | protected: | 20 | protected: |
| 22 | // handling of current key | 21 | // handling of current key |
| @@ -35,11 +34,8 @@ private slots: | |||
| 35 | void startGame(); | 34 | void startGame(); |
| 36 | void playerScoreClicked(); | 35 | void playerScoreClicked(); |
| 37 | void tick(); | 36 | void tick(); |
| 38 | void toggleSound() const; | ||
| 39 | 37 | ||
| 40 | private: | 38 | private: |
| 41 | QMainWindow *m_mainwindow; | ||
| 42 | |||
| 43 | // GUI elements needed in the progress of the game | 39 | // GUI elements needed in the progress of the game |
| 44 | QList<QGridLayout*> m_playerScoreLayouts; | 40 | QList<QGridLayout*> m_playerScoreLayouts; |
| 45 | 41 | ||
