diff options
Diffstat (limited to 'pacman-c++/mainwidget.cpp')
| -rw-r--r-- | pacman-c++/mainwidget.cpp | 46 |
1 files changed, 2 insertions, 44 deletions
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 | } | ||
