From 174690f0e357dedbd2a136d4a17858d23daf9026 Mon Sep 17 00:00:00 2001 From: CommanderRedYT Date: Tue, 1 Feb 2022 13:41:17 +0100 Subject: [PATCH] Changed lineEdit to combobox (to add history) --- mainwindow.cpp | 10 ++++++---- mainwindow.h | 1 + mainwindow.ui | 18 +++++++++++++++++- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/mainwindow.cpp b/mainwindow.cpp index 3ff1b0c..14758bc 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -24,7 +24,7 @@ MainWindow::MainWindow(QWidget *parent) : connect(m_ui->lineEditUrl, &QLineEdit::returnPressed, this, &MainWindow::connectClicked); connect(m_ui->pushButtonConnect, &QAbstractButton::clicked, this, &MainWindow::connectClicked); - connect(m_ui->lineEditSend, &QLineEdit::returnPressed, this, &MainWindow::sendClicked); + connect(m_ui->comboBoxSend->lineEdit(), &QLineEdit::returnPressed, this, &MainWindow::sendClicked); connect(m_ui->pushButtonSend, &QAbstractButton::clicked, this, &MainWindow::sendClicked); connect(m_ui->saveSlot, &QComboBox::currentIndexChanged, this, &MainWindow::loadSelectedUrl); @@ -47,6 +47,8 @@ MainWindow::MainWindow(QWidget *parent) : loadSettings(); stateChanged(m_webSocket.state()); + + qApp->installEventFilter(this); } MainWindow::~MainWindow() = default; @@ -73,9 +75,9 @@ void MainWindow::sendClicked() return; } - const auto msg = m_ui->lineEditSend->text(); + const auto msg = m_ui->comboBoxSend->currentText(); m_webSocket.sendTextMessage(msg); - m_ui->lineEditSend->clear(); + m_ui->comboBoxSend->setCurrentIndex(m_ui->comboBoxSend->count()); m_ui->plainTextEdit->appendHtml(QStringLiteral("%0 %2: %3
") .arg(QTime::currentTime().toString()) @@ -145,7 +147,7 @@ void MainWindow::stateChanged(QAbstractSocket::SocketState state) m_ui->pushButtonSave->setEnabled(state == QAbstractSocket::UnconnectedState); m_ui->pushButtonConnect->setText(state == QAbstractSocket::UnconnectedState ? tr("Connect") : tr("Disconnect")); m_ui->labelStatus->setText(qtEnumToString(state)); - m_ui->lineEditSend->setEnabled(state == QAbstractSocket::ConnectedState); + m_ui->comboBoxSend->setEnabled(state == QAbstractSocket::ConnectedState); m_ui->pushButtonSend->setEnabled(state == QAbstractSocket::ConnectedState); } diff --git a/mainwindow.h b/mainwindow.h index 02ac848..9a5202b 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -34,6 +34,7 @@ private slots: void loadSelectedUrl(); void setAutoReconnect(bool state); + private: const std::unique_ptr m_ui; QWebSocket m_webSocket; diff --git a/mainwindow.ui b/mainwindow.ui index 4e5b5b8..0c5df4d 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -10,6 +10,12 @@ 709 + + + 0 + 0 + + WebSocket Tester @@ -82,7 +88,17 @@ - + + + + 630 + 0 + + + + true + +