Bladeren bron

Prototype

nordsoft 3 jaren geleden
bovenliggende
commit
b58f70ac5e
5 gewijzigde bestanden met toevoegingen van 193 en 2 verwijderingen
  1. 3 0
      launcher/CMakeLists.txt
  2. 86 0
      launcher/lobby/lobby_moc.cpp
  3. 56 0
      launcher/lobby/lobby_moc.h
  4. 31 0
      launcher/lobby/lobby_moc.ui
  5. 17 2
      launcher/mainwindow_moc.ui

+ 3 - 0
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)

+ 86 - 0
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");
+}
+

+ 56 - 0
launcher/lobby/lobby_moc.h

@@ -0,0 +1,56 @@
+#ifndef LOBBY_MOC_H
+#define LOBBY_MOC_H
+
+#include <QWidget>
+#include <QTcpSocket>
+#include <QAbstractSocket>
+
+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

+ 31 - 0
launcher/lobby/lobby_moc.ui

@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>Lobby</class>
+ <widget class="QWidget" name="Lobby">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>652</width>
+    <height>329</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Form</string>
+  </property>
+  <layout class="QGridLayout" name="gridLayout">
+   <item row="0" column="0">
+    <widget class="QPlainTextEdit" name="chat">
+     <property name="readOnly">
+      <bool>true</bool>
+     </property>
+    </widget>
+   </item>
+   <item row="1" column="0">
+    <widget class="QLineEdit" name="lineEdit"/>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>

+ 17 - 2
launcher/mainwindow_moc.ui

@@ -111,13 +111,21 @@
          <normaloff>icons:menu-settings.png</normaloff>icons:menu-settings.png</iconset>
        </property>
       </item>
+      <item>
+       <property name="text">
+        <string>Lobby</string>
+       </property>
+       <property name="icon">
+        <iconset>
+         <normaloff>icons:menu-settings.png</normaloff>icons:menu-settings.png</iconset>
+		</property>
+      </item>
      </widget>
     </item>
     <item row="2" column="0">
      <widget class="QLabel" name="startGameTitle">
       <property name="font">
        <font>
-        <weight>75</weight>
         <bold>true</bold>
        </font>
       </property>
@@ -141,10 +149,11 @@
        </sizepolicy>
       </property>
       <property name="currentIndex">
-       <number>0</number>
+       <number>2</number>
       </property>
       <widget class="CModListView" name="stackedWidgetPage2"/>
       <widget class="CSettingsView" name="settingsView"/>
+      <widget class="Lobby" name="lobbyView"/>
      </widget>
     </item>
     <item row="1" column="0">
@@ -202,6 +211,12 @@
    <header>settingsView/csettingsview_moc.h</header>
    <container>1</container>
   </customwidget>
+  <customwidget>
+   <class>Lobby</class>
+   <extends>QWidget</extends>
+   <header>lobby/lobby_moc.h</header>
+   <container>1</container>
+  </customwidget>
  </customwidgets>
  <tabstops>
   <tabstop>tabSelectList</tabstop>