#include "client.h" #include "clicklabel.h" #include "audio.h" #include "pacman.pb.h" Client::Client() : m_ambientMuted(false) { m_settings = new QSettings(qApp->organizationName(), qApp->applicationName(), this); createMenu(); m_mainWidget = new MainWidget(this); m_mainWidget->setAmbientMuted(m_ambientMuted); setCentralWidget(m_mainWidget); } void Client::createMenu() { QMenu *fileMenu = menuBar()->addMenu("File"); bool sound = AudioManager::self()->isWorking(); bool muted = !sound || m_settings->value("muted", false).toBool(); AudioManager::self()->setMuted(muted); /* toggle sound: corner icon */ ClickLabel *toggleSound = new ClickLabel("Toggle Sound", this); toggleSound->setToolTip("Toggle Sound"); toggleSound->setFixedWidth(20); toggleSound->setFixedHeight(16); toggleSound->setAlignment(Qt::AlignBottom); toggleSound->setPixmap(soundIcon(!muted)); if (sound) { connect(toggleSound, SIGNAL(clicked()), this, SLOT(toggleSound())); connect(AudioManager::self(), SIGNAL(mutedChanged(bool)), this, SLOT(mutedChanged(bool))); } menuBar()->setCornerWidget(toggleSound); /* toggle sound: menu */ QAction *toggleSoundAction = new QAction("Sound", this); toggleSoundAction->setToolTip("Toggle Sound"); toggleSoundAction->setCheckable(true); toggleSoundAction->setChecked(!muted); toggleSoundAction->setDisabled(!sound); fileMenu->addAction(toggleSoundAction); if (sound) { connect(toggleSoundAction, SIGNAL(triggered()), this, SLOT(toggleSound())); connect(this, SIGNAL(setMuteActionsChecked(bool)), toggleSoundAction, SLOT(setChecked(bool))); } /* toggle ambient sound: menu */ m_ambientMuted = muted || m_settings->value("ambientMuted", false).toBool(); QAction *toggleAmbientAction = new QAction("Ambient Sound", this); toggleAmbientAction->setToolTip("Toggle Ambient Sound"); toggleAmbientAction->setCheckable(true); toggleAmbientAction->setChecked(!m_ambientMuted); toggleAmbientAction->setDisabled(!sound); fileMenu->addAction(toggleAmbientAction); if (sound) { connect(toggleAmbientAction, SIGNAL(triggered(bool)), this, SLOT(enableAmbientSound(bool))); connect(this, SIGNAL(setMuteActionsChecked(bool)), toggleAmbientAction, SLOT(setEnabled(bool))); } /* exit entry */ fileMenu->addSeparator(); QAction *quitAction = new QAction("E&xit", this); connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit())); fileMenu->addAction(quitAction); } void Client::toggleSound() { if (!AudioManager::self()->isWorking()) return; bool muted = !AudioManager::self()->isMuted(); AudioManager::self()->setMuted(muted); /* mute ambient sound again if explicitly muted */ if (!muted && m_ambientMuted) m_mainWidget->setAmbientMuted(true); } void Client::mutedChanged(bool muted) { ClickLabel *tmp = qobject_cast(menuBar()->cornerWidget()); tmp->setPixmap(soundIcon(!muted)); m_settings->setValue("muted", muted); emit setMuteActionsChecked(!muted); } void Client::enableAmbientSound(bool enabled) { if (!AudioManager::self()->isWorking()) return; m_ambientMuted = !enabled; m_mainWidget->setAmbientMuted(m_ambientMuted); m_settings->setValue("ambientMuted", m_ambientMuted); } QPixmap Client::soundIcon(bool enabled) const { QImage img(enabled ? ":/soundon" : ":/soundoff"); img.setColor(1, menuBar()->palette().color( enabled ? QPalette::Active : QPalette::Disabled, QPalette::ButtonText).rgba()); return QPixmap::fromImage(img); } bool Constants::server = false; int main(int argc, char ** argv) { /* Verify that the version of the library that we linked against is * compatible with the version of the headers we compiled against. */ GOOGLE_PROTOBUF_VERIFY_VERSION; QApplication app(argc, argv, true); app.setOrganizationName("TU Wien FOOP"); app.setApplicationName("Pacman Client"); app.setWindowIcon(QIcon(":/appicon")); qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime())); Client client; client.show(); client.setWindowTitle(app.applicationName()); int ret = app.exec(); /* Delete all global objects allocated by libprotobuf */ google::protobuf::ShutdownProtobufLibrary(); return ret; }