X-Git-Url: https://git.ralfj.de/multypo.git/blobdiff_plain/5b3ad773cf2d6f2ead71996f496611561929b657..e8b07da1c5251e412f80fdeb94fb327b641fc956:/qt/multypo.cpp diff --git a/qt/multypo.cpp b/qt/multypo.cpp index e7a1886..e6befe2 100644 --- a/qt/multypo.cpp +++ b/qt/multypo.cpp @@ -4,18 +4,12 @@ #include #include #include +#include #include #include #include -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')); -} - MultypoWindow::MultypoWindow(QWidget *parent) : QWidget(parent), xiInited(false) @@ -32,26 +26,55 @@ MultypoWindow::MultypoWindow(QWidget *parent) : /* Fullscreen, no cursor */ setWindowState(Qt::WindowFullScreen); setCursor(QCursor(Qt::BlankCursor)); + + words.open(stdin,QIODevice::ReadOnly); } MultypoWindow::~MultypoWindow() { } +void MultypoWindow::resetPlayerText() { + for (QMap::Iterator it = players.begin(); it != players.end(); ++it) { + it.value()->resetText(); + } +} + +void MultypoWindow::nextWord() { + QByteArray tmp = words.readLine(); + QString word = QString::fromUtf8(tmp); + mainLabel->setText(word); +} + void MultypoWindow::handleKeyPress(int device, QString string) { qDebug() << "Device" << device << "String" << string; - if (string == "Escape") + if (string == "Escape") { close(); + return; + } if (!players.contains(device)) { - QLabel *label = new QLabel(this); - layout()->addWidget(label); - players[device] = label; + players[device] = new Player(this); + } + players[device]->handleKey(string); + + if (gameStarted) { // ingame + + } else { // name entering phase + bool allHaveNames = true; + for (QMap::Iterator it = players.begin(); it != players.end(); ++it) { + if (! it.value()->hasName()) { + allHaveNames = false; + break; + } + } + if (!players.empty() && allHaveNames) { + gameStarted = true; + nextWord(); + } } - QColor textColor = QColor(Qt::blue); - players[device]->setText(players[device]->text() + ""+string+""); } bool MultypoWindow::handleX11Event(XEvent *event) @@ -66,7 +89,7 @@ bool MultypoWindow::handleX11Event(XEvent *event) } /* Which version of XI2? We support 2.0 */ - int major = 2, minor = 0; + int major = 2, minor = 1; if (XIQueryVersion(dpy, &major, &minor) == BadRequest) { qCritical() << "XI2 not available. Server supports" << major << "." << minor; @@ -90,7 +113,7 @@ bool MultypoWindow::handleX11Event(XEvent *event) for (int i = 0; i < ndevices; ++i) { if (devices[i].use != XIMasterKeyboard) continue; qDebug() << "Found master keyboard with ID" << devices[i].deviceid; - XISetFocus(dpy, devices[i].deviceid, winId(), CurrentTime); + //XISetFocus(dpy, devices[i].deviceid, winId(), CurrentTime); } XIFreeDeviceInfo(devices); @@ -100,7 +123,13 @@ bool MultypoWindow::handleX11Event(XEvent *event) } else if (xiInited && event->type == GenericEvent && event->xcookie.type == GenericEvent && event->xcookie.extension == xiOpcode - && event->xcookie.evtype == XI_KeyPress && XGetEventData(dpy, &event->xcookie)) { + && event->xcookie.evtype == XI_KeyPress) { + + if (XGetEventData(dpy, &event->xcookie) != True) { + qCritical() << "Error getting event data"; + // FIXME return true; + } + /* Handle XI event */ XIDeviceEvent *d_ev = (XIDeviceEvent*) event->xcookie.data; KeyCode keycode = d_ev->detail;