#include <QLayout>
#include <QDebug>
+#include <QTextDocument>
Player::Player(QWidget* parent) : score(0), state(Naming) {
theLabel = new QLabel (parent);
+ theLabel->setTextFormat(Qt::RichText);
parent->layout()->addWidget(theLabel);
qDebug() << "Player created";
}
// see if this does anything useful
switch (state) {
case Naming:
- theLabel->setText(currentWord);
+ setLabel(currentWord, BASE_COLOR);
if (str == "Return") {
name = currentWord;
state = Waiting;
- theLabel->setText("<READY>");
+ setLabel("<Bereit>", READY_COLOR);
}
break;
case Waiting:
break;
case Typing:
- theLabel->setText(currentWord);
+ setLabel(currentWord, BASE_COLOR);
break;
}
}
+void Player::setLabel(QString body, QString color)
+{
+ QString text = QString("<font color=%1>").arg(color);
+ if (state >= Waiting) {
+ text += QString("<font size=-3>%1:</font><br>").arg(Qt::escape(name));
+ }
+ text += Qt::escape(body);
+ theLabel->setText(text);
+}
+
void Player::wordComplete(int points)
{
score += points;
state = Waiting;
- theLabel->setText("<COMPLETE>");
+ setLabel(currentWord, READY_COLOR);
}
QString Player::getCurrentWord() {
}
void Player::nextWord() {
+ Q_ASSERT(state == Waiting);
currentWord = "";
- theLabel->setText(currentWord);
+ setLabel("<Warte auf Eingabe>", BASE_COLOR);
state = Typing;
}
void Player::showScore() {
Q_ASSERT(state == Waiting);
- theLabel->setText(QString ("Spieler %1 hat %2 Punkte.").arg(name).arg(score));
+ setLabel(QString ("%1 Punkte").arg(score), READY_COLOR);
}