From b58f70ac5e1d8433bb3f8c987077cb2452293a56 Mon Sep 17 00:00:00 2001 From: nordsoft Date: Fri, 21 Oct 2022 05:53:30 +0400 Subject: [PATCH] Prototype --- launcher/CMakeLists.txt | 3 ++ launcher/lobby/lobby_moc.cpp | 86 ++++++++++++++++++++++++++++++++++++ launcher/lobby/lobby_moc.h | 56 +++++++++++++++++++++++ launcher/lobby/lobby_moc.ui | 31 +++++++++++++ launcher/mainwindow_moc.ui | 19 +++++++- 5 files changed, 193 insertions(+), 2 deletions(-) create mode 100644 launcher/lobby/lobby_moc.cpp create mode 100644 launcher/lobby/lobby_moc.h create mode 100644 launcher/lobby/lobby_moc.ui diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt index 695d1524a..8747485df 100644 --- a/launcher/CMakeLists.txt +++ b/launcher/CMakeLists.txt @@ -33,6 +33,7 @@ set(launcher_SRCS launcherdirs.cpp jsonutils.cpp updatedialog_moc.cpp + lobby/lobby_moc.cpp ) set(launcher_HEADERS @@ -43,6 +44,7 @@ set(launcher_HEADERS launcherdirs.h jsonutils.h updatedialog_moc.h + lobby/lobby_moc.h main.h ) @@ -52,6 +54,7 @@ set(launcher_FORMS settingsView/csettingsview_moc.ui mainwindow_moc.ui updatedialog_moc.ui + lobby/lobby_moc.ui ) if(APPLE_IOS) diff --git a/launcher/lobby/lobby_moc.cpp b/launcher/lobby/lobby_moc.cpp new file mode 100644 index 000000000..7fe9c709f --- /dev/null +++ b/launcher/lobby/lobby_moc.cpp @@ -0,0 +1,86 @@ +#include "lobby_moc.h" +#include "ui_lobby_moc.h" + +SocketTest::SocketTest(QObject *parent) : + QObject(parent) +{ + socket = new QTcpSocket(this); + connect(socket, SIGNAL(connected()), this, SLOT(connected())); + connect(socket, SIGNAL(disconnected()), this, SLOT(disconnected())); + connect(socket, SIGNAL(readyRead()), this, SLOT(readyRead())); + connect(socket, SIGNAL(bytesWritten(qint64)), this, SLOT(bytesWritten(qint64))); +} + +void SocketTest::Test() +{ + qDebug() << "Connecting,.."; + emit text("Connecting to 127.0.0.1:5002..."); + + socket->connectToHost("127.0.0.1", 5002); + + if(!socket->waitForDisconnected(1000) && !isConnected) + { + emit text("Error: " + socket->errorString()); + } + +} + +void SocketTest::send(const QString & msg) +{ + socket->write(qPrintable(msg)); +} + +void SocketTest::connected() +{ + isConnected = true; + emit text("Connected!"); +} + +void SocketTest::disconnected() +{ + isConnected = false; + emit text("Disconnected!"); +} + +void SocketTest::bytesWritten(qint64 bytes) +{ + qDebug() << "We wrote: " << bytes; +} + +void SocketTest::readyRead() +{ + qDebug() << "Reading..."; + emit text(socket->readAll()); +} + + + +Lobby::Lobby(QWidget *parent) : + QWidget(parent), + ui(new Ui::Lobby) +{ + ui->setupUi(this); + + connect(&mTest, SIGNAL(text(QString)), this, SLOT(text(QString))); + + mTest.Test(); +} + +Lobby::~Lobby() +{ + delete ui; +} + +void Lobby::on_lineEdit_returnPressed() +{ + mTest.send(ui->lineEdit->text()); + ui->lineEdit->clear(); +} + +void Lobby::text(QString txt) +{ + QTextCursor curs(ui->chat->document()); + curs.movePosition(QTextCursor::End); + curs.insertText(txt + "\n"); +} + diff --git a/launcher/lobby/lobby_moc.h b/launcher/lobby/lobby_moc.h new file mode 100644 index 000000000..0b24741d7 --- /dev/null +++ b/launcher/lobby/lobby_moc.h @@ -0,0 +1,56 @@ +#ifndef LOBBY_MOC_H +#define LOBBY_MOC_H + +#include +#include +#include + +class SocketTest : public QObject +{ + Q_OBJECT +public: + explicit SocketTest(QObject *parent = 0); + void Test(); + + void send(const QString &); + +signals: + + void text(QString); + +public slots: + + void connected(); + void disconnected(); + void bytesWritten(qint64 bytes); + void readyRead(); + +private: + QTcpSocket *socket; + bool isConnected = false; + +}; + +namespace Ui { +class Lobby; +} + +class Lobby : public QWidget +{ + Q_OBJECT + +public: + explicit Lobby(QWidget *parent = nullptr); + ~Lobby(); + +private slots: + void on_lineEdit_returnPressed(); + + void text(QString); + +private: + Ui::Lobby *ui; + SocketTest mTest; +}; + +#endif // LOBBY_MOC_H diff --git a/launcher/lobby/lobby_moc.ui b/launcher/lobby/lobby_moc.ui new file mode 100644 index 000000000..a09b437c0 --- /dev/null +++ b/launcher/lobby/lobby_moc.ui @@ -0,0 +1,31 @@ + + + Lobby + + + + 0 + 0 + 652 + 329 + + + + Form + + + + + + true + + + + + + + + + + + diff --git a/launcher/mainwindow_moc.ui b/launcher/mainwindow_moc.ui index 95ba70e52..76f770ee8 100644 --- a/launcher/mainwindow_moc.ui +++ b/launcher/mainwindow_moc.ui @@ -111,13 +111,21 @@ icons:menu-settings.pngicons:menu-settings.png + + + Lobby + + + + icons:menu-settings.pngicons:menu-settings.png + + - 75 true @@ -141,10 +149,11 @@ - 0 + 2 + @@ -202,6 +211,12 @@
settingsView/csettingsview_moc.h
1 + + Lobby + QWidget +
lobby/lobby_moc.h
+ 1 +
tabSelectList