more stuff from the schönen künste
[multypo.git] / qt / player.cpp
index 40497881224caaea2026fc0549dd4d9e605eb02f..69e7651432a114a5b6309c11d399e525cfbc715f 100644 (file)
@@ -1,6 +1,7 @@
 #include "player.h"
 
 #include <QLayout>
+#include <QDebug>
 
 static QString colorToString(QColor col)
 {
@@ -9,15 +10,44 @@ static QString colorToString(QColor col)
                        .arg(col.blue(), 2, 16, QChar('0'));
 }
 
-Player::Player(QWidget* parent) {
+Player::Player(QWidget* parent) : score(0) {
        theLabel = new QLabel (parent);
        parent->layout()->addWidget(theLabel);
+       modifyable = true;
+       qDebug() << "Player created";
 }
 
-void Player::handleKey(QString str) {
+bool Player::hasName() {
+       return !name.isEmpty();
+}
+
+QString Player::getName() {
+       return name;
+}
+
+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;
+}
+
+bool Player::handleKey(QString str) {
+       if (!modifyable)
+               return false;
+       bool newChar = false;
        if (str.length() == 1) {
                currentLine += str;
-       } else if (name.isNull() && str == "Return") {
+               newChar = true;
+       } else if (!hasName() && str == "Return") {
                // set name
                name = currentLine;
                currentLine = "";
@@ -25,4 +55,5 @@ void Player::handleKey(QString str) {
                currentLine.chop(1);
        }
        theLabel->setText(currentLine);
+       return newChar;
 }