diff options
| author | manuel <manuel@mausz.at> | 2011-04-09 16:01:36 +0200 |
|---|---|---|
| committer | manuel <manuel@mausz.at> | 2011-04-09 16:01:36 +0200 |
| commit | 4c8c448a6de8b33e4a64271d6b2d0d25e00043ab (patch) | |
| tree | cdaffdc2f43e50cbc12f6f6ead9493c7f7058c23 /pacman-c++/client.cpp | |
| parent | 64a02ded2453082fe13e8a8b408933e8fada131c (diff) | |
| download | foop-4c8c448a6de8b33e4a64271d6b2d0d25e00043ab.tar.gz foop-4c8c448a6de8b33e4a64271d6b2d0d25e00043ab.tar.bz2 foop-4c8c448a6de8b33e4a64271d6b2d0d25e00043ab.zip | |
store sound muted in local settings
Diffstat (limited to 'pacman-c++/client.cpp')
| -rw-r--r-- | pacman-c++/client.cpp | 58 |
1 files changed, 57 insertions, 1 deletions
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 | ||
