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/mainwindow.cpp | |
download | bounce_qt-b7a8b597b00eedde277836eb8530ba742edcad5d.tar.gz bounce_qt-b7a8b597b00eedde277836eb8530ba742edcad5d.zip |
Diffstat (limited to 'client/mainwindow.cpp')
-rw-r--r-- | client/mainwindow.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
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); +} |