#include "client.h" #include "clicklabel.h" #include "audio.h" #include "pacman.pb.h" Client::Client() { m_settings = new QSettings(qApp->organizationName(), qApp->applicationName(), this); createMenu(); m_mainWidget = new MainWidget(this); setCentralWidget(m_mainWidget); } void Client::createMenu() { QAction *quitAction = new QAction("E&xit", this); connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit())); QMenu *fileMenu = menuBar()->addMenu("File"); fileMenu->addAction(quitAction); ClickLabel *toggleSound = new ClickLabel("Toggle Sound", this); toggleSound->setToolTip("Toggle Sound"); toggleSound->setFixedWidth(20); toggleSound->setFixedHeight(16); toggleSound->setAlignment(Qt::AlignBottom); bool sound = AudioManager::self()->isWorking(); bool muted = !(sound && m_settings->value("muted", false).toBool()); AudioManager::self()->setMuted(muted); QImage img(muted ? ":/soundoff" : ":/soundon"); img.setColor(1, menuBar()->palette().color( muted ? QPalette::Disabled : QPalette::Active, QPalette::ButtonText).rgba()); toggleSound->setPixmap(QPixmap::fromImage(img)); if (sound) { connect(toggleSound, SIGNAL(clicked()), this, SLOT(toggleSound())); connect(AudioManager::self(), SIGNAL(mutedChanged(bool)), this, SLOT(mutedChanged(bool))); } menuBar()->setCornerWidget(toggleSound); } void Client::toggleSound() const { if (!AudioManager::self()->isWorking()) return; AudioManager::self()->setMuted(!AudioManager::self()->isMuted()); } void Client::mutedChanged(bool muted) const { QImage img(muted ? ":/soundoff" : ":/soundon"); img.setColor(1, menuBar()->palette().color( muted ? QPalette::Disabled : QPalette::Active, QPalette::ButtonText).rgba()); ClickLabel *tmp = qobject_cast(menuBar()->cornerWidget()); tmp->setPixmap(QPixmap::fromImage(img)); m_settings->setValue("muted", muted); } int main(int argc, char ** argv) { GOOGLE_PROTOBUF_VERIFY_VERSION; QApplication app(argc, argv); 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()); return app.exec(); }