5 #include <QTextDocument>
7 Player::Player(QWidget* parent) : score(0), state(Naming) {
8 theLabel = new QLabel (parent);
9 theLabel->setTextFormat(Qt::RichText);
10 parent->layout()->addWidget(theLabel);
11 qDebug() << "Player created";
14 void Player::handleKey(QString str)
16 // edit "current line"
17 if (str.length() == 1) {
20 else if (str == "BackSpace") {
23 // see if this does anything useful
26 setLabel(currentWord, BASE_COLOR);
27 if (str == "Return") {
30 setLabel("<Bereit>", READY_COLOR);
36 setLabel(currentWord, BASE_COLOR);
41 void Player::setLabel(QString body, QString color)
43 QString text = QString("<font color=%1>").arg(color);
44 if (state >= Waiting) {
45 text += QString("<font size=-3>%1:</font><br>").arg(Qt::escape(name));
47 text += Qt::escape(body);
48 theLabel->setText(text);
51 void Player::wordComplete(int points)
55 setLabel(currentWord, READY_COLOR);
58 QString Player::getCurrentWord() {
59 Q_ASSERT(state == Typing);
63 void Player::nextWord() {
64 Q_ASSERT(state == Waiting);
66 setLabel("<Warte auf Eingabe>", BASE_COLOR);
70 void Player::showScore() {
71 Q_ASSERT(state == Waiting);
72 setLabel(QString ("%1 Punkte").arg(score), READY_COLOR);