oksirc/ui.cpp

42 lines
No EOL
1.3 KiB
C++

#include "ui.h"
ui::ui(int argc, char **argv) {
app = new QApplication(argc, argv);
mainWindow = new QWidget();
mainWindow->resize(1280, 720);
mainWindow->setWindowTitle("oksirc - early Qt test");
mainLog = new QPlainTextEdit();
mainLog->setReadOnly(true);
textEntry = new QLineEdit();
QPushButton *sendButton = new QPushButton(QApplication::translate("send", "Send"));
QObject::connect(sendButton, &QPushButton::clicked, this, &ui::sendButtonClicked);
QObject::connect(textEntry, &QLineEdit::returnPressed, this, &ui::returnOnTextEntry);
QHBoxLayout *entryLineLayout = new QHBoxLayout();
entryLineLayout->addWidget(textEntry);
entryLineLayout->addWidget(sendButton);
QVBoxLayout *mainLogAndLineLayout = new QVBoxLayout();
mainLogAndLineLayout->addWidget(mainLog);
mainLogAndLineLayout->addLayout(entryLineLayout);
mainWindow->setLayout(mainLogAndLineLayout);
mainWindow->show();
textEntry->setFocus();
}
int ui::exec() {
return app->exec();
}
void ui::returnOnTextEntry() {
mainLog->appendPlainText("Return key pressed!");
mainLog->appendPlainText(textEntry->text());
textEntry->clear();
}
void ui::sendButtonClicked(bool checked) {
mainLog->appendPlainText("Send button clicked!");
mainLog->appendPlainText(textEntry->text());
textEntry->clear();
}