From 6d97b7f19824e36caee34219e02e7bbe7ec29fa1 Mon Sep 17 00:00:00 2001 From: Xavier Del Campo Romero Date: Tue, 10 Oct 2023 15:39:33 +0200 Subject: Replace QInputDialog with custom dialog for queries Recent commits allowed multi-line input while reusing the QInputDialog object already defined by Kristall. However, QInputDialog lacks a way to access its QPlainTextEdit directly, and therefore set the wrap mode. Since QInputDialog does no wrapping, it is inconvenient for writing a long text (think of social media sites such as BBS or Station). Therefore, a custom QDialog-derived class, namely QueryDialog, has been provided. --- src/widgets/querydialog.cpp | 30 ++++++++++++++++++ src/widgets/querydialog.hpp | 20 ++++++++++++ src/widgets/querydialog.ui | 77 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 127 insertions(+) create mode 100644 src/widgets/querydialog.cpp create mode 100644 src/widgets/querydialog.hpp create mode 100644 src/widgets/querydialog.ui (limited to 'src/widgets') diff --git a/src/widgets/querydialog.cpp b/src/widgets/querydialog.cpp new file mode 100644 index 0000000..467c4c2 --- /dev/null +++ b/src/widgets/querydialog.cpp @@ -0,0 +1,30 @@ +#include "widgets/querydialog.hpp" + +QueryDialog::QueryDialog(QWidget *parent) : + QDialog(parent), + mode(QLineEdit::Normal) +{ + ui.setupUi(this); + ui.lineEdit->setVisible(false); +} + +void QueryDialog::setLabelText(const QString &text) +{ + ui.query->setText(text); +} + +void QueryDialog::setTextEchoMode(QLineEdit::EchoMode mode) +{ + ui.text->setVisible(mode == QLineEdit::Normal); + ui.lineEdit->setVisible(mode != QLineEdit::Normal); + ui.lineEdit->setEchoMode(mode); + this->mode = mode; +} + +QString QueryDialog::textValue() +{ + if (mode == QLineEdit::Normal) + return ui.text->toPlainText(); + + return ui.lineEdit->text(); +} diff --git a/src/widgets/querydialog.hpp b/src/widgets/querydialog.hpp new file mode 100644 index 0000000..d3ea71a --- /dev/null +++ b/src/widgets/querydialog.hpp @@ -0,0 +1,20 @@ +#ifndef QUERYDIALOG_H +#define QUERYDIALOG_H + +#include "ui_querydialog.h" +#include +#include +#include + +class QueryDialog : public QDialog { +public: + QueryDialog(QWidget *parent); + void setLabelText(const QString &text); + void setTextEchoMode(QLineEdit::EchoMode mode); + QString textValue(); +private: + Ui_QueryDialog ui; + QLineEdit::EchoMode mode; +}; + +#endif diff --git a/src/widgets/querydialog.ui b/src/widgets/querydialog.ui new file mode 100644 index 0000000..001c29d --- /dev/null +++ b/src/widgets/querydialog.ui @@ -0,0 +1,77 @@ + + + QueryDialog + + + + 0 + 0 + 480 + 240 + + + + Dialog + + + + + + + + + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + QueryDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + QueryDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + -- cgit v1.2.3