1 /*
2  * Cantata
3  *
4  * Copyright (c) 2011-2020 Craig Drummond <craig.p.drummond@gmail.com>
5  *
6  * ----
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; see the file COPYING.  If not, write to
20  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21  * Boston, MA 02110-1301, USA.
22  */
23 
24 #ifndef INPUT_DIALOG_H
25 #define INPUT_DIALOG_H
26 
27 #include <QLineEdit>
28 #include <QSpinBox>
29 #include <QWidget>
30 #include "dialog.h"
31 #include "combobox.h"
32 
33 class LineEdit;
34 
35 class InputDialog : public Dialog
36 {
37     Q_OBJECT
38 
39 public:
40     InputDialog(const QString &caption, const QString &label, const QString &value, const QStringList &options, QLineEdit::EchoMode echo, QWidget *parent);
41     InputDialog(const QString &caption, const QString &label, int value, int minValue, int maxValue, int step, QWidget *parent);
42 
43     static QString getText(const QString &caption, const QString &label, QLineEdit::EchoMode echoMode, const QString &value=QString(),
44                            const QStringList &options=QStringList(), bool *ok=nullptr, QWidget *parent=nullptr);
45 
46     static int getInteger(const QString &caption, const QString &label, int value=0, int minValue=INT_MIN, int maxValue=INT_MAX,
47                           int step=1, int base=10, bool *ok=nullptr, QWidget *parent=nullptr);
48 
49     static QString getText(const QString &caption, const QString &label, const QString &value=QString(),
50                            const QStringList &options=QStringList(), bool *ok=nullptr, QWidget *parent=nullptr) {
51         return getText(caption, label, QLineEdit::Normal, value, options, ok, parent);
52     }
53 
getText(const QString & caption,const QString & label,QLineEdit::EchoMode echoMode,const QString & value,bool * ok,QWidget * parent)54     static QString getText(const QString &caption, const QString &label, QLineEdit::EchoMode echoMode, const QString &value,
55                            bool *ok, QWidget *parent) {
56         return getText(caption, label, echoMode, value, QStringList(), ok, parent);
57     }
58 
getText(const QString & caption,const QString & label,const QString & value,bool * ok,QWidget * parent)59     static QString getText(const QString &caption, const QString &label, const QString &value, bool *ok, QWidget *parent) {
60         return getText(caption, label, QLineEdit::Normal, value, QStringList(), ok, parent);
61     }
62 
63     static QString getPassword(const QString &value=QString(), bool *ok=nullptr, QWidget *parent=nullptr) {
64         return getText(tr("Password"), tr("Please enter password:"), QLineEdit::Password, value, QStringList(), ok, parent);
65     }
66 
67     void addExtraWidget(QWidget *w);
spinBox()68     QSpinBox *spinBox() {
69         return spin;
70     }
lineEdit()71     QLineEdit *lineEdit() {
72         return edit ? (QLineEdit *)edit : combo ? combo->lineEdit() : nullptr;
73     }
comboBox()74     ComboBox *comboBox() {
75         return combo;
76     }
77 
78 private:
79     void init(int type, const QString &caption, const QString &labelText);
80 
81 private Q_SLOTS:
82     void enableOkButton();
83 
84 private:
85     QSpinBox *spin;
86     LineEdit *edit;
87     ComboBox *combo;
88     QWidget *extra;
89 };
90 
91 #endif // INPUT_DIALOG_H
92