~charon-developers/tuchulcha/supernodes

« back to all changes in this revision

Viewing changes to src/QTextInputDialog.cpp

  • Committer: Jens Malte Gottfried
  • Date: 2013-07-04 16:29:23 UTC
  • Revision ID: jmgottfried@web.de-20130704162923-htru5p4jlfp5jxkl
added input validation to add/rename node

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
*/
 
18
/** \file   QTextInputDialog.h
 
19
 *  \brief  Declaration of class QTextInputDialog
 
20
 *  \date   04.07.2013
 
21
 *  \author <a href="mailto:jmgottfried@web.de">Jens-Malte Gottfried</a>
 
22
 */
 
23
 
 
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
 
 
60
QString QTextInputDialog::getText(
 
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) {
 
87
                emit textValueSelected(textValue());
 
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
}
 
102
 
 
103
QString QTextInputDialog::textValue() const {
 
104
        return eText->text();
 
105
}
 
106
 
 
107
QString QTextInputDialog::labelText() const {
 
108
        return lText->text();
 
109
}
 
110
 
 
111
QLineEdit::EchoMode QTextInputDialog::textEchoMode() const {
 
112
        return eText->echoMode();
 
113
}
 
114
 
 
115
void QTextInputDialog::setValidator(const QValidator* val) {
 
116
        eText->setValidator(val);
 
117
}
 
118
 
 
119
const QValidator* QTextInputDialog::validator() const {
 
120
        return eText->validator();
 
121
}