projects
/
multypo.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
show player name while typing
[multypo.git]
/
qt
/
player.cpp
diff --git
a/qt/player.cpp
b/qt/player.cpp
index 937bbab739dddb597f1bbf310a3187ac6a0c5a4a..c75bb4614ec71fb004c41e8dda348dddb55f3452 100644
(file)
--- a/
qt/player.cpp
+++ b/
qt/player.cpp
@@
-2,58
+2,72
@@
#include <QLayout>
#include <QDebug>
#include <QLayout>
#include <QDebug>
+#include <QTextDocument>
-static QString colorToString(QColor col)
-{
- return QString("#%1%2%3").arg(col.red(), 2, 16, QChar('0'))
- .arg(col.green(), 2, 16, QChar('0'))
- .arg(col.blue(), 2, 16, QChar('0'));
-}
-
-Player::Player(QWidget* parent) {
+Player::Player(QWidget* parent) : score(0), state(Naming) {
theLabel = new QLabel (parent);
theLabel = new QLabel (parent);
+ theLabel->setTextFormat(Qt::RichText);
parent->layout()->addWidget(theLabel);
parent->layout()->addWidget(theLabel);
- modifyable = true;
qDebug() << "Player created";
}
qDebug() << "Player created";
}
-bool Player::hasName() {
- return !name.isEmpty();
+void Player::handleKey(QString str)
+{
+ // edit "current line"
+ if (str.length() == 1) {
+ currentWord += str;
+ }
+ else if (str == "BackSpace") {
+ currentWord.chop(1);
+ }
+ // see if this does anything useful
+ switch (state) {
+ case Naming:
+ setLabel(currentWord, BASE_COLOR);
+ if (str == "Return") {
+ name = currentWord;
+ state = Waiting;
+ setLabel(name, READY_COLOR);
+ }
+ break;
+ case Waiting:
+ break;
+ case Typing:
+ setLabel(currentWord, BASE_COLOR, name+":");
+ break;
+ }
}
}
-QString Player::getName() {
- return name;
+void Player::setLabel(QString body, QString color, QString header)
+{
+ QString text = QString("<font color=%1>").arg(color);
+ if (!header.isEmpty()) {
+ text += QString("<font size=-3>%1</font><br>").arg(Qt::escape(header));
+ }
+ text += Qt::escape(body);
+ theLabel->setText(text);
}
}
-QString Player::getCurrentLine() {
- return currentLine;
+void Player::wordComplete(int points)
+{
+ score += points;
+ state = Waiting;
+ setLabel(currentWord, READY_COLOR, name+":");
}
}
-
void Player::setWaiting(QString labeltext
) {
-
theLabel->setText(labeltext
);
-
modifyable = false
;
+
QString Player::getCurrentWord(
) {
+
Q_ASSERT(state == Typing
);
+
return currentWord
;
}
}
-void Player::resetText() {
- currentLine.clear();
- theLabel->setText(currentLine);
- modifyable = true;
+void Player::nextWord() {
+ Q_ASSERT(state == Waiting);
+ currentWord = "";
+ setLabel("<Eingabe erscheint hier>", BASE_COLOR, name+":");
+ state = Typing;
}
}
-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;
- currentLine = "";
- } else if (str == "BackSpace") {
- currentLine.chop(1);
- }
- theLabel->setText(currentLine);
- return newChar;
+void Player::showScore() {
+ Q_ASSERT(state == Waiting);
+ setLabel(QString ("Spieler %1 hat %2 Punkte.").arg(name).arg(score), READY_COLOR);
}
}