From 4c8c448a6de8b33e4a64271d6b2d0d25e00043ab Mon Sep 17 00:00:00 2001 From: manuel Date: Sat, 9 Apr 2011 16:01:36 +0200 Subject: store sound muted in local settings --- pacman-c++/client.cpp | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) (limited to 'pacman-c++/client.cpp') 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 @@ #include "client.h" +#include "clicklabel.h" +#include "audioplayer.h" Client::Client() { - m_mainWidget = new MainWidget(this, this); + m_settings = new QSettings(qApp->organizationName(), qApp->applicationName(), this); + createMenu(); + m_mainWidget = new MainWidget(this); setCentralWidget(m_mainWidget); } +void Client::createMenu() +{ + QAction *quitAction = new QAction("E&xit", this); + connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit())); + + QMenu *fileMenu = menuBar()->addMenu("File"); + fileMenu->addAction(quitAction); + + ClickLabel *toggleSound = new ClickLabel("Toggle Sound", this); + toggleSound->setFixedWidth(20); + toggleSound->setFixedHeight(16); + toggleSound->setAlignment(Qt::AlignBottom); + + bool sound = AudioPlayer::self()->isWorking(); + bool muted = sound && m_settings->value("muted", false).toBool(); + AudioPlayer::self()->setMuted(muted); + + QImage img(muted ? ":/soundoff" : ":/soundon"); + img.setColor(1, menuBar()->palette().color( + muted ? QPalette::Disabled : QPalette::Active, + dQPalette::ButtonText).rgba()); + toggleSound->setPixmap(QPixmap::fromImage(img)); + + if (sound) + { + connect(toggleSound, SIGNAL(clicked()), this, SLOT(toggleSound())); + connect(AudioPlayer::self(), SIGNAL(mutedChanged(bool)), this, SLOT(mutedChanged(bool))); + } + + menuBar()->setCornerWidget(toggleSound); +} + +void Client::toggleSound() const +{ + if (!AudioPlayer::self()->isWorking()) + return; + AudioPlayer::self()->setMuted(!AudioPlayer::self()->isMuted()); +} + +void Client::mutedChanged(bool muted) const +{ + QImage img(muted ? ":/soundoff" : ":/soundon"); + img.setColor(1, menuBar()->palette().color( + muted ? QPalette::Disabled : QPalette::Active, + QPalette::ButtonText).rgba()); + ClickLabel *tmp = qobject_cast(menuBar()->cornerWidget()); + tmp->setPixmap(QPixmap::fromImage(img)); + + m_settings->setValue("muted", muted); +} + int main(int argc, char ** argv) { QApplication app(argc, argv); + app.setOrganizationName("TU Wien FOOP"); app.setApplicationName("Pacman Client"); app.setWindowIcon(QIcon(":/appicon")); -- cgit v1.2.3