ralfs Fixes
[multypo.git] / qt / player.cpp
index 871ecb9d474182fd1ad50ddd6790fff4a4d71d42..937bbab739dddb597f1bbf310a3187ac6a0c5a4a 100644 (file)
@@ -1,6 +1,7 @@
 #include "player.h"
 
 #include <QLayout>
+#include <QDebug>
 
 static QString colorToString(QColor col)
 {
@@ -12,11 +13,12 @@ static QString colorToString(QColor col)
 Player::Player(QWidget* parent) {
        theLabel = new QLabel (parent);
        parent->layout()->addWidget(theLabel);
+       modifyable = true;
+       qDebug() << "Player created";
 }
 
-
 bool Player::hasName() {
-       return !name.isNull();
+       return !name.isEmpty();
 }
 
 QString Player::getName() {
@@ -27,14 +29,24 @@ QString Player::getCurrentLine() {
        return currentLine;
 }
 
+void Player::setWaiting(QString labeltext) {
+       theLabel->setText(labeltext);
+       modifyable = false;
+}
+
 void Player::resetText() {
        currentLine.clear();
        theLabel->setText(currentLine);
+       modifyable = true;
 }
 
-void Player::handleKey(QString str) {
+bool Player::handleKey(QString str) {
+       if (!modifyable)
+               return false;
+       bool newChar = false;
        if (str.length() == 1) {
                currentLine += str;
+               newChar = true;
        } else if (!hasName() && str == "Return") {
                // set name
                name = currentLine;
@@ -43,4 +55,5 @@ void Player::handleKey(QString str) {
                currentLine.chop(1);
        }
        theLabel->setText(currentLine);
+       return newChar;
 }