X-Git-Url: https://git.ralfj.de/multypo.git/blobdiff_plain/318e322c3cd72e6a7f692c6f7c7770c0e15720c8..HEAD:/qt/player.cpp diff --git a/qt/player.cpp b/qt/player.cpp index 4853823..036d547 100644 --- a/qt/player.cpp +++ b/qt/player.cpp @@ -2,9 +2,11 @@ #include #include +#include Player::Player(QWidget* parent) : score(0), state(Naming) { theLabel = new QLabel (parent); + theLabel->setTextFormat(Qt::RichText); parent->layout()->addWidget(theLabel); qDebug() << "Player created"; } @@ -21,26 +23,36 @@ void Player::handleKey(QString str) // 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(""); + setLabel("", 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("").arg(color); + if (state >= Waiting) { + text += QString("%1:
").arg(Qt::escape(name)); + } + text += Qt::escape(body); + theLabel->setText(text); +} + void Player::wordComplete(int points) { score += points; state = Waiting; - theLabel->setText(""); + setLabel(currentWord, READY_COLOR); } QString Player::getCurrentWord() { @@ -49,12 +61,13 @@ QString Player::getCurrentWord() { } void Player::nextWord() { + Q_ASSERT(state == Waiting); currentWord = ""; - theLabel->setText(currentWord); + setLabel("", 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); }