diff options
| author | manuel <manuel@mausz.at> | 2011-04-09 15:03:50 +0200 |
|---|---|---|
| committer | manuel <manuel@mausz.at> | 2011-04-09 15:03:50 +0200 |
| commit | 9f896b86b671b3a05314d2013a315d996b456f95 (patch) | |
| tree | 18bb310c96ea4a6f819494776a91a96a38fee2af /pacman-c++/client.cpp | |
| parent | 7e4bc8ece49543533c4e27f5d6bc867c1bada601 (diff) | |
| download | foop-9f896b86b671b3a05314d2013a315d996b456f95.tar.gz foop-9f896b86b671b3a05314d2013a315d996b456f95.tar.bz2 foop-9f896b86b671b3a05314d2013a315d996b456f95.zip | |
add toggle audio icon
Diffstat (limited to 'pacman-c++/client.cpp')
| -rw-r--r-- | pacman-c++/client.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/pacman-c++/client.cpp b/pacman-c++/client.cpp index e4978f7..7827591 100644 --- a/pacman-c++/client.cpp +++ b/pacman-c++/client.cpp | |||
| @@ -1,5 +1,6 @@ | |||
| 1 | #include "client.h" | 1 | #include "client.h" |
| 2 | #include "audioplayer.h" | 2 | #include "audioplayer.h" |
| 3 | #include "clicklabel.h" | ||
| 3 | 4 | ||
| 4 | Client::Client() | 5 | Client::Client() |
| 5 | { | 6 | { |
| @@ -9,10 +10,38 @@ Client::Client() | |||
| 9 | QMenu *fileMenu = menuBar()->addMenu("File"); | 10 | QMenu *fileMenu = menuBar()->addMenu("File"); |
| 10 | fileMenu->addAction(quitAction); | 11 | fileMenu->addAction(quitAction); |
| 11 | 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 | |||
| 12 | m_mainWidget = new MainWidget(); | 27 | m_mainWidget = new MainWidget(); |
| 13 | setCentralWidget(m_mainWidget); | 28 | setCentralWidget(m_mainWidget); |
| 14 | } | 29 | } |
| 15 | 30 | ||
| 31 | void 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 | |||
| 16 | int main(int argc, char ** argv) | 45 | int main(int argc, char ** argv) |
| 17 | { | 46 | { |
| 18 | QApplication app(argc, argv); | 47 | QApplication app(argc, argv); |
