From b7a8b597b00eedde277836eb8530ba742edcad5d Mon Sep 17 00:00:00 2001 From: Treeki Date: Wed, 25 Dec 2013 09:00:59 +0100 Subject: commit initial bits --- client/mainwindow.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 client/mainwindow.cpp (limited to 'client/mainwindow.cpp') 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); +} -- cgit v1.2.3