summaryrefslogtreecommitdiffstats
path: root/pacman-c++/client.cpp
blob: 782759181ea125fe186a91b89a78460245a617cf (plain)
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
#include "client.h"
#include "audioplayer.h"
#include "clicklabel.h"

Client::Client()
{
  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->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<ClickLabel *>(menuBar()->cornerWidget());
  tmp->setPixmap(QPixmap::fromImage(img));
  AudioPlayer::self()->setMuted(!muted);
}

int main(int argc, char ** argv)
{
  QApplication app(argc, argv);
  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();
}