tuchulcha  0.10.1
Graphical Workflow Configuration Editor
QTextInputDialog.cpp
1 /* Copyright (C) 2013 Jens-Malte Gottfried
2 
3  This file is part of Tuchulcha.
4 
5  Tuchulcha is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  Tuchulcha is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with Tuchulcha. If not, see <http://www.gnu.org/licenses/>.
17 */
24 #include "QTextInputDialog.h"
25 #include <QVBoxLayout>
26 #include <QLabel>
27 #include <QDialogButtonBox>
28 
29 QTextInputDialog::QTextInputDialog(QWidget *pp, Qt::WindowFlags flags) :
30  QDialog(pp,flags)
31 {
32  QVBoxLayout *verticalLayout;
33  QDialogButtonBox *bBox;
34 
35  verticalLayout = new QVBoxLayout(this);
36  lText = new QLabel(this);
37  lText->setObjectName(QString::fromUtf8("lText"));
38  verticalLayout->addWidget(lText);
39 
40  eText = new QLineEdit(this);
41  eText->setObjectName(QString::fromUtf8("eText"));
42  verticalLayout->addWidget(eText);
43 
44  bBox = new QDialogButtonBox(this);
45  bBox->setObjectName(QString::fromUtf8("bBox"));
46  bBox->setOrientation(Qt::Horizontal);
47  bBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
48  verticalLayout->addWidget(bBox);
49 
50  connect(bBox, SIGNAL(accepted()), SLOT(accept()));
51  connect(bBox, SIGNAL(rejected()), SLOT(reject()));
52  connect(eText, SIGNAL(textChanged(QString)), SIGNAL(textValueChanged(QString)));
53 
54  QMetaObject::connectSlotsByName(this);
55 }
56 
57 QTextInputDialog::~QTextInputDialog() {
58 }
59 
61  QWidget *parent, const QString &title,
62  const QString &label, QLineEdit::EchoMode mode,
63  const QString &text, bool *ok, Qt::WindowFlags flags,
64  Qt::InputMethodHints inputMethodHints,
65  QValidator* val) {
66  QTextInputDialog dialog(parent, flags);
67  dialog.setWindowTitle(title);
68  dialog.setLabelText(label);
69  dialog.setTextValue(text);
70  dialog.setTextEchoMode(mode);
71  dialog.setInputMethodHints(inputMethodHints);
72  dialog.setValidator(val);
73 
74  int ret = dialog.exec();
75  if (ok)
76  *ok = !!ret;
77  if (ret) {
78  return dialog.textValue();
79  } else {
80  return QString();
81  }
82 }
83 
84 void QTextInputDialog::done (int res) {
85  QDialog::done(res);
86  if (res) {
88  }
89 }
90 
91 void QTextInputDialog::setTextEchoMode(QLineEdit::EchoMode mode) {
92  eText->setEchoMode(mode);
93 }
94 
95 void QTextInputDialog::setLabelText(const QString& text) {
96  lText->setText(text);
97 }
98 
99 void QTextInputDialog::setTextValue(const QString& value) {
100  eText->setText(value);
101  eText->selectAll();
102 }
103 
104 QString QTextInputDialog::textValue() const {
105  return eText->text();
106 }
107 
108 QString QTextInputDialog::labelText() const {
109  return lText->text();
110 }
111 
112 QLineEdit::EchoMode QTextInputDialog::textEchoMode() const {
113  return eText->echoMode();
114 }
115 
116 void QTextInputDialog::setValidator(const QValidator* val) {
117  eText->setValidator(val);
118 }
119 
120 const QValidator* QTextInputDialog::validator() const {
121  return eText->validator();
122 }
QLineEdit * eText
text line edit
QLabel * lText
text label
void setTextValue(const QString &)
set line edit text
QString textValue
text entered by the user
void textValueChanged(const QString &)
changed text
QLineEdit::EchoMode textEchoMode() const
text echo mode
QTextInputDialog(QWidget *parent=0, Qt::WindowFlags flags=0)
default constructor
void setLabelText(const QString &)
set label text
QString textValue() const
line edit text
void setValidator(const QValidator *)
set validator
const QValidator * validator() const
text validator
QString labelText() const
label text
dialog to query a string variable, similar to QInputDialog
void textValueSelected(const QString &)
text selected
virtual void done(int result)
dialog done
Declaration of class QTextInputDialog.
static QString getText(QWidget *parent, const QString &title, const QString &label, QLineEdit::EchoMode mode=QLineEdit::Normal, const QString &text=QString(), bool *ok=0, Qt::WindowFlags flags=0, Qt::InputMethodHints iHints=Qt::ImhNone, QValidator *val=0)
get text
void setTextEchoMode(QLineEdit::EchoMode)
set text echo mode