1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
#include "client.h"
#include "clicklabel.h"
#include "audioplayer.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 = AudioPlayer::self()->isWorking();
bool muted = !(sound && m_settings->value("muted", false).toBool());
AudioPlayer::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(AudioPlayer::self(), SIGNAL(mutedChanged(bool)), this, SLOT(mutedChanged(bool)));
}
menuBar()->setCornerWidget(toggleSound);
}
void Client::toggleSound() const
{
if (!AudioPlayer::self()->isWorking())
return;
AudioPlayer::self()->setMuted(!AudioPlayer::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<ClickLabel *>(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();
}
|