From dd99879ab004dd1d81b5942ad35d5ea6c1476c10 Mon Sep 17 00:00:00 2001 From: manuel Date: Thu, 7 Apr 2011 19:35:53 +0200 Subject: fixing app icon on windows add audio player --- pacman-c++/audioplayer.cpp | 55 ++++++++++++++++++++++++++++++++++++++++++++++ pacman-c++/audioplayer.h | 38 ++++++++++++++++++++++++++++++++ pacman-c++/client.cpp | 2 +- pacman-c++/mainwidget.cpp | 12 ++++------ pacman-c++/mainwidget.h | 1 + pacman-c++/pacman.pro | 6 +++-- pacman-c++/pacman.rc | 2 +- 7 files changed, 104 insertions(+), 12 deletions(-) create mode 100644 pacman-c++/audioplayer.cpp create mode 100644 pacman-c++/audioplayer.h (limited to 'pacman-c++') diff --git a/pacman-c++/audioplayer.cpp b/pacman-c++/audioplayer.cpp new file mode 100644 index 0000000..8620190 --- /dev/null +++ b/pacman-c++/audioplayer.cpp @@ -0,0 +1,55 @@ +#include "audioplayer.h" +#include +#include +#include +#include + +// the universe's only audio player +AudioPlayer *AudioPlayer::m_instance = 0; + +AudioPlayer::AudioPlayer() +{ + m_player = new Phonon::MediaObject(this); + + connect(m_player, SIGNAL(finished()), this, SLOT(finished_p())); + connect(m_player, SIGNAL(stateChanged(Phonon::State, Phonon::State)), this, SLOT(stateChanged_p(Phonon::State, Phonon::State))); + + m_output = new Phonon::AudioOutput(Phonon::MusicCategory, this); + Phonon::createPath(m_player, m_output); +} + +AudioPlayer *AudioPlayer::self() +{ + if (!m_instance) + m_instance = new AudioPlayer(); + return m_instance; +} + +void AudioPlayer::stop() +{ + m_player->stop(); +} + +void AudioPlayer::setMuted(bool mute) +{ + m_output->setMuted(mute); +} + +void AudioPlayer::playIntro() +{ + m_player->stop(); + m_player->setCurrentSource(new QFile(":/sound/intro")); + m_player->play(); +} + +void AudioPlayer::finished_p() +{ + qDebug() << "finished"; + emit finished(); +} + +void AudioPlayer::stateChanged_p(Phonon::State newstate, Phonon::State oldstate) +{ + qDebug() << "old=" << oldstate << "new=" << newstate; +} + diff --git a/pacman-c++/audioplayer.h b/pacman-c++/audioplayer.h new file mode 100644 index 0000000..3dc3cfd --- /dev/null +++ b/pacman-c++/audioplayer.h @@ -0,0 +1,38 @@ +#ifndef AUDIOPLAYER_H +#define AUDIOPLAYER_H + +#include +#include + +namespace Phonon +{ + class MediaObject; + class AudioOutput; +} + +class AudioPlayer + : public QObject +{ + Q_OBJECT + +public: + AudioPlayer(); + static AudioPlayer *self(); + void stop(); + void setMuted(bool mute = true); + void playIntro(); + +signals: + void finished(); + +private slots: + void finished_p(); + void stateChanged_p(Phonon::State newstate, Phonon::State oldstate); + +private: + Phonon::MediaObject *m_player; + Phonon::AudioOutput *m_output; + static AudioPlayer *m_instance; +}; + +#endif // AUDIOPLAYER_H diff --git a/pacman-c++/client.cpp b/pacman-c++/client.cpp index 47bbc4e..ebbcff2 100644 --- a/pacman-c++/client.cpp +++ b/pacman-c++/client.cpp @@ -15,7 +15,7 @@ Client::Client() int main(int argc, char ** argv) { QApplication app(argc, argv); - app.setApplicationName("pacman-client"); + app.setApplicationName("Pacman Client"); app.setWindowIcon(QIcon(":/appicon")); qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime())); diff --git a/pacman-c++/mainwidget.cpp b/pacman-c++/mainwidget.cpp index 96cf62f..537c5ad 100644 --- a/pacman-c++/mainwidget.cpp +++ b/pacman-c++/mainwidget.cpp @@ -4,9 +4,7 @@ #include "bonuspoint.h" #include "point.h" #include "constants.h" - -#include -#include +#include "audioplayer.h" // temporary Transmission::map_t createDummyMap() @@ -94,13 +92,11 @@ MainWidget::MainWidget() createGui(); updateMap(createDummyMap()); -#if 1 +#if 0 emit startGame(); #else - Phonon::MediaObject *player = Phonon::createPlayer(Phonon::MusicCategory, - Phonon::MediaSource(new QFile(":/sound/intro"))); - connect(player, SIGNAL(finished()), this, SLOT(startGame())); - player->play(); + AudioPlayer::self()->playIntro(); + connect(AudioPlayer::self(), SIGNAL(finished()), this, SLOT(startGame())); #endif } diff --git a/pacman-c++/mainwidget.h b/pacman-c++/mainwidget.h index f5703db..8d21649 100644 --- a/pacman-c++/mainwidget.h +++ b/pacman-c++/mainwidget.h @@ -5,6 +5,7 @@ #include "pixmapitem.h" #include #include +#include class Actor; diff --git a/pacman-c++/pacman.pro b/pacman-c++/pacman.pro index 3826852..f95625b 100644 --- a/pacman-c++/pacman.pro +++ b/pacman-c++/pacman.pro @@ -6,7 +6,8 @@ SOURCES += pixmapitem.cpp \ client.cpp \ bonuspoint.cpp \ mainwidget.cpp \ - point.cpp + point.cpp \ + audioplayer.cpp HEADERS += pixmapitem.h \ actor.h \ animationmanager.h \ @@ -15,7 +16,8 @@ HEADERS += pixmapitem.h \ bonuspoint.h \ mainwidget.h \ constants.h \ - point.h + point.h \ + audioplayer.h RESOURCES += pacman.qrc OBJECTS_DIR = .obj diff --git a/pacman-c++/pacman.rc b/pacman-c++/pacman.rc index 808718b..8c9f03b 100644 --- a/pacman-c++/pacman.rc +++ b/pacman-c++/pacman.rc @@ -1 +1 @@ -IDI_ICON1 ICON DISCARDABLE "pics/pacman.ico" +IDI_ICON1 ICON DISCARDABLE "pics/app.ico" -- cgit v1.2.3