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(name, READY_COLOR);
36 setLabel(currentWord, BASE_COLOR, name+":");
41 void Player::setLabel(QString body, QString color, QString header)
43 QString text = QString("<font color=%1>").arg(color);
44 if (!header.isEmpty()) {
45 text += QString("<font size=-3>%1</font><br>").arg(Qt::escape(header));
47 text += Qt::escape(body);
48 theLabel->setText(text);
51 void Player::wordComplete(int points)
55 setLabel(currentWord, READY_COLOR, name+":");
58 QString Player::getCurrentWord() {
59 Q_ASSERT(state == Typing);
63 void Player::nextWord() {
64 Q_ASSERT(state == Waiting);
66 setLabel("<Eingabe erscheint hier>", BASE_COLOR, name+":");
70 void Player::showScore() {
71 Q_ASSERT(state == Waiting);
72 setLabel(QString ("Spieler %1 hat %2 Punkte.").arg(name).arg(score), READY_COLOR);