Diffstat (limited to 'noncore/settings/aqpkg/inputdlg.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/aqpkg/inputdlg.cpp | 121 |
1 files changed, 121 insertions, 0 deletions
diff --git a/noncore/settings/aqpkg/inputdlg.cpp b/noncore/settings/aqpkg/inputdlg.cpp new file mode 100644 index 0000000..724a891 --- a/dev/null +++ b/noncore/settings/aqpkg/inputdlg.cpp | |||
@@ -0,0 +1,121 @@ | |||
1 | /*************************************************************************** | ||
2 | inputdlg.h - description | ||
3 | ------------------- | ||
4 | begin : Mon Aug 26 2002 | ||
5 | copyright : (C) 2002 by Andy Qua | ||
6 | email : andy.qua@blueyonder.co.uk | ||
7 | ***************************************************************************/ | ||
8 | |||
9 | /*************************************************************************** | ||
10 | * * | ||
11 | * This program is free software; you can redistribute it and/or modify * | ||
12 | * it under the terms of the GNU General Public License as published by * | ||
13 | * the Free Software Foundation; either version 2 of the License, or * | ||
14 | * (at your option) any later version. * | ||
15 | * * | ||
16 | ***************************************************************************/ | ||
17 | #include <qlayout.h> | ||
18 | #include <qlabel.h> | ||
19 | #include <qlineedit.h> | ||
20 | #include <qpushbutton.h> | ||
21 | #include <qspinbox.h> | ||
22 | #include <qcombobox.h> | ||
23 | #include <qwidgetstack.h> | ||
24 | #include <qvalidator.h> | ||
25 | #include <qapplication.h> | ||
26 | |||
27 | #include "inputdlg.h" | ||
28 | #include "global.h" | ||
29 | |||
30 | |||
31 | InputDialog :: InputDialog( const QString &label, QWidget* parent, const char* name, | ||
32 | bool modal ) | ||
33 | : QDialog( parent, name, modal ) | ||
34 | { | ||
35 | lineEdit = 0; | ||
36 | |||
37 | QVBoxLayout *vbox = new QVBoxLayout( this, 6, 6 ); | ||
38 | |||
39 | QLabel* l = new QLabel( label, this ); | ||
40 | vbox->addWidget( l ); | ||
41 | |||
42 | lineEdit = new QLineEdit( this ); | ||
43 | vbox->addWidget( lineEdit ); | ||
44 | |||
45 | QHBoxLayout *hbox = new QHBoxLayout( 6 ); | ||
46 | vbox->addLayout( hbox, AlignRight ); | ||
47 | |||
48 | ok = new QPushButton( tr( "&OK" ), this ); | ||
49 | ok->setDefault( TRUE ); | ||
50 | QPushButton *cancel = new QPushButton( tr( "&Cancel" ), this ); | ||
51 | |||
52 | QSize bs( ok->sizeHint() ); | ||
53 | if ( cancel->sizeHint().width() > bs.width() ) | ||
54 | bs.setWidth( cancel->sizeHint().width() ); | ||
55 | |||
56 | ok->setFixedSize( bs ); | ||
57 | cancel->setFixedSize( bs ); | ||
58 | |||
59 | hbox->addWidget( new QWidget( this ) ); | ||
60 | hbox->addWidget( ok ); | ||
61 | hbox->addWidget( cancel ); | ||
62 | |||
63 | connect( lineEdit, SIGNAL( returnPressed() ), | ||
64 | this, SLOT( tryAccept() ) ); | ||
65 | connect( lineEdit, SIGNAL( textChanged( const QString & ) ), | ||
66 | this, SLOT( textChanged( const QString & ) ) ); | ||
67 | |||
68 | connect( ok, SIGNAL( clicked() ), this, SLOT( accept() ) ); | ||
69 | connect( cancel, SIGNAL( clicked() ), this, SLOT( reject() ) ); | ||
70 | |||
71 | resize( QMAX( sizeHint().width(), 240 ), sizeHint().height() ); | ||
72 | } | ||
73 | |||
74 | /*! | ||
75 | Destructor. | ||
76 | */ | ||
77 | |||
78 | InputDialog::~InputDialog() | ||
79 | { | ||
80 | } | ||
81 | |||
82 | void InputDialog :: setText( const QString &text ) | ||
83 | { | ||
84 | lineEdit->setText( text ); | ||
85 | lineEdit->selectAll(); | ||
86 | } | ||
87 | |||
88 | QString InputDialog :: getText() | ||
89 | { | ||
90 | return lineEdit->text(); | ||
91 | } | ||
92 | |||
93 | QString InputDialog::getText( const QString &caption, const QString &label, | ||
94 | const QString &text, bool *ok, QWidget *parent, | ||
95 | const char *name ) | ||
96 | { | ||
97 | InputDialog *dlg = new InputDialog( label, parent, name, true ); | ||
98 | dlg->setCaption( caption ); | ||
99 | dlg->setText( text ); | ||
100 | |||
101 | QString result; | ||
102 | *ok = dlg->exec() == QDialog::Accepted; | ||
103 | if ( *ok ) | ||
104 | result = dlg->getText(); | ||
105 | |||
106 | delete dlg; | ||
107 | return result; | ||
108 | } | ||
109 | |||
110 | |||
111 | |||
112 | void InputDialog :: textChanged( const QString &s ) | ||
113 | { | ||
114 | ok->setEnabled( !s.isEmpty() ); | ||
115 | } | ||
116 | |||
117 | void InputDialog :: tryAccept() | ||
118 | { | ||
119 | if ( !lineEdit->text().isEmpty() ) | ||
120 | accept(); | ||
121 | } | ||