From 9f896b86b671b3a05314d2013a315d996b456f95 Mon Sep 17 00:00:00 2001 From: manuel Date: Sat, 9 Apr 2011 15:03:50 +0200 Subject: add toggle audio icon --- pacman-c++/actor.cpp | 6 +++--- pacman-c++/audioplayer.cpp | 12 +++++++++++- pacman-c++/audioplayer.h | 5 +++-- pacman-c++/clicklabel.cpp | 12 ++++++++++++ pacman-c++/clicklabel.h | 21 +++++++++++++++++++++ pacman-c++/client.cpp | 29 +++++++++++++++++++++++++++++ pacman-c++/client.h | 3 +++ pacman-c++/pacman.pro | 6 ++++-- pacman-c++/pacman.qrc | 2 ++ pacman-c++/pics/soundoff.xpm | 15 +++++++++++++++ pacman-c++/pics/soundon.xpm | 15 +++++++++++++++ 11 files changed, 118 insertions(+), 8 deletions(-) create mode 100644 pacman-c++/clicklabel.cpp create mode 100644 pacman-c++/clicklabel.h create mode 100644 pacman-c++/pics/soundoff.xpm create mode 100644 pacman-c++/pics/soundon.xpm (limited to 'pacman-c++') diff --git a/pacman-c++/actor.cpp b/pacman-c++/actor.cpp index 445d63d..011fbeb 100644 --- a/pacman-c++/actor.cpp +++ b/pacman-c++/actor.cpp @@ -81,7 +81,7 @@ QSequentialAnimationGroup *Actor::setupEatingAnimation(Actor::Movement direction fadeout->setEndValue(false); QPropertyAnimation *move = new QPropertyAnimation(img, "pos", m_moving); - move->setDuration(Constants::tick); + move->setDuration(Constants::tick - 50); move->setEndValue(QPoint(0, 0)); } @@ -106,8 +106,8 @@ bool Actor::isLocal() void Actor::move(Actor::Movement direction) { //TODO: remove? - if (isMoving()) - return; + //if (isMoving()) + // return; /* stop current animation */ if (direction != m_direction) diff --git a/pacman-c++/audioplayer.cpp b/pacman-c++/audioplayer.cpp index 424d3cf..5507bb3 100644 --- a/pacman-c++/audioplayer.cpp +++ b/pacman-c++/audioplayer.cpp @@ -52,6 +52,11 @@ AudioPlayer *AudioPlayer::self() return m_instance; } +bool AudioPlayer::isWorking() const +{ + return m_working; +} + void AudioPlayer::stop() { m_player->stop(); @@ -62,6 +67,11 @@ void AudioPlayer::setMuted(bool mute) m_output->setMuted(mute); } +bool AudioPlayer::isMuted() const +{ + return m_output->isMuted(); +} + void AudioPlayer::play(AudioPlayer::Sound sound) { if (!m_working) @@ -86,7 +96,7 @@ void AudioPlayer::enqueue(AudioPlayer::Sound sound) m_player->enqueue(Phonon::MediaSource(m_sounds[sound])); } -void AudioPlayer::clearQueue() +void AudioPlayer::clearQueue() const { if (!m_working) return; diff --git a/pacman-c++/audioplayer.h b/pacman-c++/audioplayer.h index dd0c25a..567ccb1 100644 --- a/pacman-c++/audioplayer.h +++ b/pacman-c++/audioplayer.h @@ -28,13 +28,14 @@ public: public: AudioPlayer(); static AudioPlayer *self(); - bool isWorking(); + bool isWorking() const; void stop(); void setMuted(bool mute = true); + bool isMuted() const; void play(Sound sound); void clear(); void enqueue(Sound sound); - void clearQueue(); + void clearQueue() const; Phonon::State state(); signals: diff --git a/pacman-c++/clicklabel.cpp b/pacman-c++/clicklabel.cpp new file mode 100644 index 0000000..87b06b8 --- /dev/null +++ b/pacman-c++/clicklabel.cpp @@ -0,0 +1,12 @@ +#include "clicklabel.h" + +ClickLabel::ClickLabel(const QString &text, QWidget *parent, Qt::WindowFlags f) + : QLabel(text, parent, f) +{ +} + +void ClickLabel::mouseReleaseEvent(QMouseEvent * /* event */) +{ + emit clicked(); +} + diff --git a/pacman-c++/clicklabel.h b/pacman-c++/clicklabel.h new file mode 100644 index 0000000..494b1ee --- /dev/null +++ b/pacman-c++/clicklabel.h @@ -0,0 +1,21 @@ +#ifndef CLICKLABEL_H +#define CLICKLABEL_H + +#include + +class ClickLabel + : public QLabel +{ + Q_OBJECT + +public: + ClickLabel(const QString &text, QWidget *parent = 0, Qt::WindowFlags f = 0); + +signals: + void clicked(); + +protected: + void mouseReleaseEvent(QMouseEvent *event); +}; + +#endif // CLICKLABEL_H 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 @@ #include "client.h" #include "audioplayer.h" +#include "clicklabel.h" Client::Client() { @@ -9,10 +10,38 @@ Client::Client() 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(); + QImage img(sound ? ":/soundon" : ":/soundoff"); + img.setColor(1, menuBar()->palette().color(sound ? QPalette::Active : QPalette::Disabled, + QPalette::ButtonText).rgba()); + toggleSound->setPixmap(QPixmap::fromImage(img)); + if (sound) + connect(toggleSound, SIGNAL(clicked()), this, SLOT(toggleSound())); + + menuBar()->setCornerWidget(toggleSound); + m_mainWidget = new MainWidget(); setCentralWidget(m_mainWidget); } +void Client::toggleSound() const +{ + if (!AudioPlayer::self()->isWorking()) + return; + + bool muted = AudioPlayer::self()->isMuted(); + QImage img(muted ? ":/soundon" : ":/soundoff"); + img.setColor(1, menuBar()->palette().color(muted ? QPalette::Active : QPalette::Disabled, + QPalette::ButtonText).rgba()); + ClickLabel *tmp = qobject_cast(menuBar()->cornerWidget()); + tmp->setPixmap(QPixmap::fromImage(img)); + AudioPlayer::self()->setMuted(!muted); +} + int main(int argc, char ** argv) { QApplication app(argc, argv); diff --git a/pacman-c++/client.h b/pacman-c++/client.h index 476b972..56f3602 100644 --- a/pacman-c++/client.h +++ b/pacman-c++/client.h @@ -11,6 +11,9 @@ class Client public: Client(); +public slots: + void toggleSound() const; + private: MainWidget *m_mainWidget; }; diff --git a/pacman-c++/pacman.pro b/pacman-c++/pacman.pro index f95625b..f2baaed 100644 --- a/pacman-c++/pacman.pro +++ b/pacman-c++/pacman.pro @@ -7,7 +7,8 @@ SOURCES += pixmapitem.cpp \ bonuspoint.cpp \ mainwidget.cpp \ point.cpp \ - audioplayer.cpp + audioplayer.cpp \ + clicklabel.cpp HEADERS += pixmapitem.h \ actor.h \ animationmanager.h \ @@ -17,7 +18,8 @@ HEADERS += pixmapitem.h \ mainwidget.h \ constants.h \ point.h \ - audioplayer.h + audioplayer.h \ + clicklabel.h RESOURCES += pacman.qrc OBJECTS_DIR = .obj diff --git a/pacman-c++/pacman.qrc b/pacman-c++/pacman.qrc index b116a30..4fb542e 100644 --- a/pacman-c++/pacman.qrc +++ b/pacman-c++/pacman.qrc @@ -17,6 +17,8 @@ pics/actor2icon.png pics/actor3icon.png pics/actor4icon.png + pics/soundon.xpm + pics/soundoff.xpm sound/intro.ogg diff --git a/pacman-c++/pics/soundoff.xpm b/pacman-c++/pics/soundoff.xpm new file mode 100644 index 0000000..ba33f5f --- /dev/null +++ b/pacman-c++/pics/soundoff.xpm @@ -0,0 +1,15 @@ +/* XPM */ +static char * soundoff_xpm[] = { +"12 10 2 1", +" c None", +". c #000000", +" ", +" . ", +" .. . .", +".... . . ", +".... .. ", +".... .. ", +".... . . ", +" .. . .", +" . ", +" "}; diff --git a/pacman-c++/pics/soundon.xpm b/pacman-c++/pics/soundon.xpm new file mode 100644 index 0000000..e6ca41e --- /dev/null +++ b/pacman-c++/pics/soundon.xpm @@ -0,0 +1,15 @@ +/* XPM */ +static char * soundoff_xpm[] = { +"12 10 2 1", +" c None", +". c #000000", +" . ", +" . . ", +" .. . . ", +".... . . ", +".... . . ", +".... . . ", +".... . . ", +" .. . . ", +" . . ", +" . "}; -- cgit v1.2.3 From 827a9b10539af4a8c4cff70fa345254668d294c7 Mon Sep 17 00:00:00 2001 From: manuel Date: Sat, 9 Apr 2011 15:06:41 +0200 Subject: newlines everywhere --- pacman-c++/sceneholder.cpp | 2 +- pacman-c++/sceneholder.h | 2 +- pacman-c++/util.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'pacman-c++') diff --git a/pacman-c++/sceneholder.cpp b/pacman-c++/sceneholder.cpp index 83025d5..310c929 100644 --- a/pacman-c++/sceneholder.cpp +++ b/pacman-c++/sceneholder.cpp @@ -112,4 +112,4 @@ void SceneHolder::updateMap(const Transmission::map_t& map) QPoint SceneHolder::mapPositionToCoord(unsigned int x, unsigned int y) { return QPoint(x * Constants::field_size.width, y * Constants::field_size.height); -} \ No newline at end of file +} diff --git a/pacman-c++/sceneholder.h b/pacman-c++/sceneholder.h index d69e07e..4e96f7a 100644 --- a/pacman-c++/sceneholder.h +++ b/pacman-c++/sceneholder.h @@ -34,4 +34,4 @@ protected: }; -#endif // SCENEHOLDER_H \ No newline at end of file +#endif // SCENEHOLDER_H diff --git a/pacman-c++/util.h b/pacman-c++/util.h index 34ddd31..97666c4 100644 --- a/pacman-c++/util.h +++ b/pacman-c++/util.h @@ -5,4 +5,4 @@ // temporary Transmission::map_t createDummyMap(); -#endif // UTIL_H \ No newline at end of file +#endif // UTIL_H -- cgit v1.2.3