fix score
[multypo.git] / qt / player.cpp
index 485382300e993e7913e1b3508d2ca5f6295f9b31..036d547d4482405524cbb37f53e7020eba2cb6b7 100644 (file)
@@ -2,9 +2,11 @@
 
 #include <QLayout>
 #include <QDebug>
 
 #include <QLayout>
 #include <QDebug>
+#include <QTextDocument>
 
 Player::Player(QWidget* parent) : score(0), state(Naming) {
        theLabel = new QLabel (parent);
 
 Player::Player(QWidget* parent) : score(0), state(Naming) {
        theLabel = new QLabel (parent);
+    theLabel->setTextFormat(Qt::RichText);
        parent->layout()->addWidget(theLabel);
        qDebug() << "Player created";
 }
        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:
     // see if this does anything useful
     switch (state) {
         case Naming:
-            theLabel->setText(currentWord);
+            setLabel(currentWord, BASE_COLOR);
             if (str == "Return") {
                 name = currentWord;
                 state = Waiting;
             if (str == "Return") {
                 name = currentWord;
                 state = Waiting;
-                theLabel->setText("<READY>");
+                setLabel("<Bereit>", READY_COLOR);
             }
             break;
         case Waiting:
             break;
         case Typing:
             }
             break;
         case Waiting:
             break;
         case Typing:
-            theLabel->setText(currentWord);
+            setLabel(currentWord, BASE_COLOR);
             break;
     }
 }
 
             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;
 void Player::wordComplete(int points)
 {
     score += points;
     state = Waiting;
-    theLabel->setText("<COMPLETE>");
+    setLabel(currentWord, READY_COLOR);
 }
 
 QString Player::getCurrentWord() {
 }
 
 QString Player::getCurrentWord() {
@@ -49,12 +61,13 @@ QString Player::getCurrentWord() {
 }
 
 void Player::nextWord() {
 }
 
 void Player::nextWord() {
+    Q_ASSERT(state == Waiting);
        currentWord = "";
        currentWord = "";
-    theLabel->setText(currentWord);
+    setLabel("<Warte auf Eingabe>", BASE_COLOR);
        state = Typing;
 }
 
 void Player::showScore() {
     Q_ASSERT(state == Waiting);
        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);
 }
 }