diff options
| author | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2023-10-10 15:39:33 +0200 |
|---|---|---|
| committer | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2023-10-10 20:47:18 +0200 |
| commit | 7a7d9dc216ecf0bf7200666b479fb08c0edec834 (patch) | |
| tree | 30957e51979a26f5baaf54e0c3f193d9689fe92c /src/widgets | |
| parent | 8cb79ee6711b3db3f138db6367752053f45efc17 (diff) | |
Replace QInputDialog with custom dialog for queriesquery-dialog
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.
Diffstat (limited to 'src/widgets')
| -rw-r--r-- | src/widgets/querydialog.cpp | 30 | ||||
| -rw-r--r-- | src/widgets/querydialog.hpp | 20 | ||||
| -rw-r--r-- | src/widgets/querydialog.ui | 77 |
3 files changed, 127 insertions, 0 deletions
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 <QDialog> +#include <QLineEdit> +#include <QString> + +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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>QueryDialog</class> + <widget class="QDialog" name="QueryDialog"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>480</width> + <height>240</height> + </rect> + </property> + <property name="windowTitle"> + <string>Dialog</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <widget class="QLabel" name="query"> + <property name="text"> + <string/> + </property> + </widget> + </item> + <item> + <widget class="QPlainTextEdit" name="text"/> + </item> + <item> + <widget class="QLineEdit" name="lineEdit"/> + </item> + <item> + <widget class="QDialogButtonBox" name="buttonBox"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="standardButtons"> + <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> + </property> + </widget> + </item> + </layout> + </widget> + <resources/> + <connections> + <connection> + <sender>buttonBox</sender> + <signal>accepted()</signal> + <receiver>QueryDialog</receiver> + <slot>accept()</slot> + <hints> + <hint type="sourcelabel"> + <x>248</x> + <y>254</y> + </hint> + <hint type="destinationlabel"> + <x>157</x> + <y>274</y> + </hint> + </hints> + </connection> + <connection> + <sender>buttonBox</sender> + <signal>rejected()</signal> + <receiver>QueryDialog</receiver> + <slot>reject()</slot> + <hints> + <hint type="sourcelabel"> + <x>316</x> + <y>260</y> + </hint> + <hint type="destinationlabel"> + <x>286</x> + <y>274</y> + </hint> + </hints> + </connection> + </connections> +</ui> |
