diff options
author | Treeki <treeki@gmail.com> | 2013-12-25 09:00:59 +0100 |
---|---|---|
committer | Treeki <treeki@gmail.com> | 2013-12-25 09:00:59 +0100 |
commit | b7a8b597b00eedde277836eb8530ba742edcad5d (patch) | |
tree | 1b959fa0eec02ff4e22e168aa4379b2b64575ce3 /client | |
download | bounce_qt-b7a8b597b00eedde277836eb8530ba742edcad5d.tar.gz bounce_qt-b7a8b597b00eedde277836eb8530ba742edcad5d.zip |
Diffstat (limited to '')
-rw-r--r-- | client/bounce_client.pro | 28 | ||||
-rw-r--r-- | client/main.cpp | 11 | ||||
-rw-r--r-- | client/mainwindow.cpp | 44 | ||||
-rw-r--r-- | client/mainwindow.h | 29 | ||||
-rw-r--r-- | client/mainwindow.ui | 34 |
5 files changed, 146 insertions, 0 deletions
diff --git a/client/bounce_client.pro b/client/bounce_client.pro new file mode 100644 index 0000000..bfb6faf --- /dev/null +++ b/client/bounce_client.pro @@ -0,0 +1,28 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2013-12-16T07:46:22 +# +#------------------------------------------------- + +QT += core gui network + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +TARGET = bounce_client +TEMPLATE = app + + +SOURCES += main.cpp\ + mainwindow.cpp \ + ../server/socket.cpp \ + ../server/packetwriter.cpp \ + ../server/packetreader.cpp \ + ../server/client.cpp + +HEADERS += mainwindow.h \ + ../server/socket.h \ + ../server/packetwriter.h \ + ../server/packetreader.h \ + ../server/client.h + +FORMS += mainwindow.ui diff --git a/client/main.cpp b/client/main.cpp new file mode 100644 index 0000000..a080bdd --- /dev/null +++ b/client/main.cpp @@ -0,0 +1,11 @@ +#include "mainwindow.h" +#include <QApplication> + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + MainWindow w; + w.show(); + + return a.exec(); +} diff --git a/client/mainwindow.cpp b/client/mainwindow.cpp new file mode 100644 index 0000000..1dfee5e --- /dev/null +++ b/client/mainwindow.cpp @@ -0,0 +1,44 @@ +#include "mainwindow.h" +#include "ui_mainwindow.h" +#include "../server/client.h" + +MainWindow::MainWindow(QWidget *parent) : + QMainWindow(parent), + ui(new Ui::MainWindow) +{ + ui->setupUi(this); + + connect(ui->lineEdit, SIGNAL(returnPressed()), this, SLOT(handleLineEntered())); + + m_client = new Client(this); + connect(m_client, SIGNAL(consoleOutput(QString)), this, SLOT(handleConsoleOutput(QString))); + + m_client->connectToHost("localhost", 6744); +} + +MainWindow::~MainWindow() +{ + delete ui; +} + + + +void MainWindow::handleLineEntered() { + QString line = ui->lineEdit->text(); + ui->lineEdit->clear(); + + m_client->consoleInput(line); +} + +void MainWindow::handleConsoleOutput(const QString &str) { + QTextCursor cursor = ui->textEdit->textCursor(); + bool isAtEnd = cursor.atEnd(); + + cursor.movePosition(QTextCursor::End); + cursor.clearSelection(); + cursor.insertText(str); + cursor.insertText("\n"); + + if (isAtEnd) + ui->textEdit->setTextCursor(cursor); +} diff --git a/client/mainwindow.h b/client/mainwindow.h new file mode 100644 index 0000000..9cd58cf --- /dev/null +++ b/client/mainwindow.h @@ -0,0 +1,29 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include <QMainWindow> +class Client; + +namespace Ui { +class MainWindow; +} + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + explicit MainWindow(QWidget *parent = 0); + ~MainWindow(); + +private: + Ui::MainWindow *ui; + + Client *m_client; + +private slots: + void handleLineEntered(); + void handleConsoleOutput(const QString &str); +}; + +#endif // MAINWINDOW_H diff --git a/client/mainwindow.ui b/client/mainwindow.ui new file mode 100644 index 0000000..437f0ca --- /dev/null +++ b/client/mainwindow.ui @@ -0,0 +1,34 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>MainWindow</class> + <widget class="QMainWindow" name="MainWindow"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>508</width> + <height>364</height> + </rect> + </property> + <property name="windowTitle"> + <string>MainWindow</string> + </property> + <widget class="QWidget" name="centralWidget"> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <widget class="QTextEdit" name="textEdit"> + <property name="readOnly"> + <bool>true</bool> + </property> + </widget> + </item> + <item> + <widget class="QLineEdit" name="lineEdit"/> + </item> + </layout> + </widget> + </widget> + <layoutdefault spacing="6" margin="11"/> + <resources/> + <connections/> +</ui> |