show player name while typing
[multypo.git] / qt / multypo.cpp
index d58d247728286c90c3225df9dd2f0e72d83536f6..fff1da762ff487233d996cf39f28c70df1df1a17 100644 (file)
@@ -5,6 +5,7 @@
 #include <QVBoxLayout>
 #include <QLabel>
 #include <QMap>
+#include <QTextDocument>
 
 #include <X11/Xlib.h>
 #include <X11/extensions/XInput2.h>
@@ -16,12 +17,13 @@ MultypoWindow::MultypoWindow(QWidget *parent) :
        xiInited(false)
 {
        /* Prepare colors */
-       setStyleSheet("background-color: black; color: green; font-size: 45pt");
+       setStyleSheet("background-color: black; font-size: 45pt");
 
        /* Prepare conents */
        setLayout(new QVBoxLayout(this));
-
-       mainLabel = new QLabel("Namen eingeben, dann Return", this);
+       mainLabel = new QLabel(this);
+    mainLabel->setTextFormat(Qt::RichText);
+    setLabel("Namen eingeben, dann Return", BASE_COLOR);
        layout()->addWidget(mainLabel);
 
        /* Fullscreen, no cursor */
@@ -35,12 +37,17 @@ MultypoWindow::~MultypoWindow()
 {
 }
 
+void MultypoWindow::setLabel(QString text, QString color)
+{
+    mainLabel->setText(QString("<font color=%1>%2</span>").arg(color).arg(Qt::escape(text)));
+}
+
 void MultypoWindow::nextWord() {
        QByteArray tmp = words.readLine().trimmed();
        currentWord = QString::fromUtf8(tmp);
-       qDebug() << "New word" << currentWord;
+       qDebug() << "New word:" << currentWord;
        if (currentWord.isEmpty()) { // game over
-               mainLabel->setText("GAME OVER");
+               setLabel("GAME OVER", READY_COLOR);
                for (QMap<int, Player*>::Iterator it = players.begin(); it != players.end(); ++it) {
                        it.value()->showScore();
                }
@@ -49,7 +56,7 @@ void MultypoWindow::nextWord() {
                for (QMap<int, Player*>::Iterator it = players.begin(); it != players.end(); ++it) {
             it.value()->nextWord();
         }
-               mainLabel->setText(currentWord);
+               setLabel(currentWord, BASE_COLOR);
         state = Playing;
        }
 }
@@ -90,14 +97,12 @@ void MultypoWindow::handleKeyPress(int device, QString string)
     
     if (state == Naming) {
         // someone's still naming (or nobody's there yet)
-        qDebug() << "checking for game started";
         if (!players.empty() && allPlayersWaiting()) {
+            qDebug() << "Game starting";
             nextWord();
         }
     }
     else if (state == Playing) { // all players are waiting or typing
-               qDebug() << "current player line" << player->getCurrentWord();
-               qDebug() << "current word" << currentWord;
                if (player->getState() == Player::Typing && player->getCurrentWord() == currentWord) {
             int points = typingPlayers()+1;
             player->wordComplete(points);