summaryrefslogtreecommitdiffstats
path: root/pacman-c++/mainwidget.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'pacman-c++/mainwidget.cpp')
-rw-r--r--pacman-c++/mainwidget.cpp41
1 files changed, 23 insertions, 18 deletions
diff --git a/pacman-c++/mainwidget.cpp b/pacman-c++/mainwidget.cpp
index 6930b1a..a77daab 100644
--- a/pacman-c++/mainwidget.cpp
+++ b/pacman-c++/mainwidget.cpp
@@ -6,7 +6,7 @@
6#include "pacman.pb.h" 6#include "pacman.pb.h"
7 7
8MainWidget::MainWidget(QWidget *parent) 8MainWidget::MainWidget(QWidget *parent)
9 : QWidget(parent), m_currentKey(Transmission::none), m_running(false) 9 : QWidget(parent), m_currentKey(Transmission::none), m_running(false), m_maxplayers(0)
10{ 10{
11 /* create audio player */ 11 /* create audio player */
12 m_ambientPlayer = new GaplessAudioPlayer(Sound::Ambient, 100, this); 12 m_ambientPlayer = new GaplessAudioPlayer(Sound::Ambient, 100, this);
@@ -54,51 +54,55 @@ void MainWidget::createGui()
54 setFocusPolicy(Qt::StrongFocus); 54 setFocusPolicy(Qt::StrongFocus);
55 55
56 /* first one is always the own score */ 56 /* first one is always the own score */
57 QVBoxLayout *layout = new QVBoxLayout(this);
58 layout->setAlignment(Qt::AlignHCenter | Qt::AlignTop);
57 QHBoxLayout *scoreLayout = new QHBoxLayout(); 59 QHBoxLayout *scoreLayout = new QHBoxLayout();
58 for (unsigned int i = 0; Color::order[i] != Color::none ; ++i) 60 for (unsigned int i = 0; Color::order[i] != Color::none; ++i)
59 { 61 {
60 QGroupBox *scoreBox = new QGroupBox(QString("Spieler %1").arg(i + 1), this); 62 QGridLayout *playerLayout = new QGridLayout();
63 playerLayout->addWidget(new QLabel("Current:", this), 0, 0);
64 playerLayout->addWidget(new QLabel("Total:", this), 1, 0);
65 playerLayout->addWidget(new QLabel("0", this), 0, 1);
66 playerLayout->addWidget(new QLabel("0", this), 1, 1);
67
68 QGroupBox *scoreBox = new QGroupBox(QString("Player %1").arg(i + 1), this);
61 scoreBox->setObjectName(QString("actor%1").arg(i + 1)); 69 scoreBox->setObjectName(QString("actor%1").arg(i + 1));
62 scoreBox->setCheckable(true); 70 scoreBox->setCheckable(true);
63 connect(scoreBox, SIGNAL(clicked()), this, SLOT(playerScoreClicked())); 71 connect(scoreBox, SIGNAL(clicked()), this, SLOT(playerScoreClicked()));
64
65 QGridLayout *playerLayout = new QGridLayout();
66 scoreBox->setLayout(playerLayout); 72 scoreBox->setLayout(playerLayout);
67 73 scoreBox->setDisabled(i >= m_maxplayers);
68 playerLayout->addWidget(new QLabel("Rundenpunkte:", this), 0, 0); 74 m_playerScoreLayouts.append(playerLayout);
69 playerLayout->addWidget(new QLabel("Gesamtpunkte:", this), 1, 0);
70
71 playerLayout->addWidget(new QLabel("", this), 0, 1);
72 playerLayout->addWidget(new QLabel("", this), 1, 1);
73 75
74 if (Color::order[i] == m_scene->color()) 76 if (Color::order[i] == m_scene->color())
75 scoreLayout->insertWidget(0, scoreBox); 77 scoreLayout->insertWidget(0, scoreBox);
76 else 78 else
77 scoreLayout->addWidget(scoreBox); 79 scoreLayout->addWidget(scoreBox);
78 m_playerScoreLayouts.append(playerLayout);
79 } 80 }
80
81 QVBoxLayout *layout = new QVBoxLayout(this);
82 layout->addLayout(scoreLayout); 81 layout->addLayout(scoreLayout);
82 /* add some margin to scorebox hopefully won't resize the window */
83 //setMinimumWidth(scoreLayout->minimumSize().width() + 50);
83 84
84 QGraphicsView *window = new QGraphicsView(m_scene, this); 85 QGraphicsView *window = new QGraphicsView(m_scene, this);
85 window->setFrameStyle(0); 86 window->setFrameStyle(0);
86 window->setAlignment(Qt::AlignLeft | Qt::AlignTop);
87 window->setFixedSize(Constants::map_size_pixel.width, Constants::map_size_pixel.height); 87 window->setFixedSize(Constants::map_size_pixel.width, Constants::map_size_pixel.height);
88 window->setWindowFlags(window->windowFlags() & ~Qt::WindowMaximizeButtonHint); 88 window->setWindowFlags(window->windowFlags() & ~Qt::WindowMaximizeButtonHint);
89 window->setFocusPolicy(Qt::NoFocus); 89 window->setFocusPolicy(Qt::NoFocus);
90 layout->addWidget(window); 90 layout->addWidget(window, 0, Qt::AlignCenter);
91 91
92 QFile css(":/stylesheet"); 92 QFile css(":/stylesheet");
93 css.open(QFile::ReadOnly); 93 css.open(QFile::ReadOnly);
94 qApp->setStyleSheet(QLatin1String(css.readAll())); 94 qApp->setStyleSheet(QLatin1String(css.readAll()));
95 95
96 /* add dummy layout at the end which gets streched when resizing */
97 QHBoxLayout *spacer = new QHBoxLayout();
98 layout->addLayout(spacer, 10);
99
96 setLayout(layout); 100 setLayout(layout);
97} 101}
98 102
99void MainWidget::updateScore(const ProtoBuf::MapUpdate& packet) 103void MainWidget::updateScore(const ProtoBuf::MapUpdate& packet)
100{ 104{
101 for(unsigned i = 0; Color::order[i] != Color::none; ++i) 105 for(unsigned i = 0; i < m_maxplayers; ++i)
102 { 106 {
103 QGridLayout *score = m_playerScoreLayouts.at(i); 107 QGridLayout *score = m_playerScoreLayouts.at(i);
104 QLabel *turnPointsLbl = dynamic_cast<QLabel *>(score->itemAtPosition(0, 1)->widget()); 108 QLabel *turnPointsLbl = dynamic_cast<QLabel *>(score->itemAtPosition(0, 1)->widget());
@@ -233,10 +237,11 @@ Color::Color MainWidget::connectToServer()
233 { 237 {
234 /* receive color */ 238 /* receive color */
235 QSharedPointer<QByteArray> data = Util::receivePacket(m_socket); 239 QSharedPointer<QByteArray> data = Util::receivePacket(m_socket);
236 ProtoBuf::WhoAmI packet; 240 ProtoBuf::Init packet;
237 bool worked = packet.ParseFromArray(data->data(), data->size()); 241 bool worked = packet.ParseFromArray(data->data(), data->size());
238 Q_ASSERT(worked); 242 Q_ASSERT(worked);
239 Q_UNUSED(worked); 243 Q_UNUSED(worked);
244 m_maxplayers = packet.maxplayers();
240 return static_cast<Color::Color>(packet.color() & Transmission::color_mask); 245 return static_cast<Color::Color>(packet.color() & Transmission::color_mask);
241 } 246 }
242 } 247 }