21 #include "kinputdialog_p.h"
23 #include <QtGui/QDoubleValidator>
24 #include <QtGui/QLabel>
25 #include <QtGui/QLayout>
40 m_label(0), m_lineEdit(0), m_intSpinBox(0),
41 m_doubleSpinBox(0), m_comboBox(0), m_listBox(0)
49 QVBoxLayout *layout =
new QVBoxLayout(frame);
52 m_label =
new QLabel(label, frame);
53 m_label->setWordWrap(
true);
54 layout->addWidget(m_label);
57 m_lineEdit->setClearButtonShown(
true);
58 layout->addWidget(m_lineEdit);
60 m_lineEdit->setFocus();
61 m_label->setBuddy(m_lineEdit);
66 m_lineEdit->setValidator(validator);
69 m_lineEdit->setInputMask(mask);
71 connect(m_lineEdit, SIGNAL(textChanged(
QString)),
72 SLOT(slotEditTextChanged(
QString)));
75 slotEditTextChanged(value);
79 KInputDialogHelper::KInputDialogHelper(
const QString &caption,
const QString &label,
82 m_label(0), m_lineEdit(0), m_intSpinBox(0),
83 m_doubleSpinBox(0), m_comboBox(0)
91 QVBoxLayout *layout =
new QVBoxLayout(frame);
94 m_label =
new QLabel(label, frame);
95 m_label->setWordWrap(
true);
96 layout->addWidget(m_label);
99 m_textEdit->insertPlainText(value);
100 layout->addWidget(m_textEdit, 10);
102 m_textEdit->setFocus();
103 m_label->setBuddy(m_textEdit);
105 connect(
this, SIGNAL(user1Clicked()), m_textEdit, SLOT(
clear()));
106 connect(
this, SIGNAL(user1Clicked()), m_textEdit, SLOT(setFocus()));
107 setMainWidget(frame);
108 setMinimumWidth(400);
111 KInputDialogHelper::KInputDialogHelper(
const QString &caption,
const QString &label,
112 int value,
int minValue,
int maxValue,
int step,
int base,
115 m_label(0), m_lineEdit(0), m_intSpinBox(0),
116 m_doubleSpinBox(0), m_comboBox(0), m_listBox(0)
123 QVBoxLayout *layout =
new QVBoxLayout(frame);
125 m_label =
new QLabel(label, frame);
126 m_label->setWordWrap(
true);
127 layout->addWidget(m_label);
129 m_intSpinBox =
new KIntSpinBox(minValue, maxValue, step, value, frame, base);
130 layout->addWidget(m_intSpinBox);
132 layout->addStretch();
133 layout->setMargin(0);
135 m_intSpinBox->setFocus();
136 setMainWidget(frame);
137 setMinimumWidth(300);
140 KInputDialogHelper::KInputDialogHelper(
const QString &caption,
const QString &label,
141 double value,
double minValue,
double maxValue,
double step,
int decimals,
144 m_label(0), m_lineEdit(0), m_intSpinBox(0),
145 m_doubleSpinBox(0), m_comboBox(0), m_listBox(0)
152 QVBoxLayout *layout =
new QVBoxLayout(frame);
154 m_label =
new QLabel(label, frame);
155 m_label->setWordWrap(
true);
156 layout->addWidget(m_label);
158 m_doubleSpinBox =
new QDoubleSpinBox(frame);
159 m_doubleSpinBox->setRange(minValue, maxValue);
160 m_doubleSpinBox->setSingleStep(step);
161 m_doubleSpinBox->setValue(value);
162 m_doubleSpinBox->setDecimals(decimals);
164 layout->addWidget(m_doubleSpinBox);
166 layout->addStretch();
167 layout->setMargin(0);
169 m_doubleSpinBox->setFocus();
170 setMainWidget(frame);
171 setMinimumWidth(300);
174 KInputDialogHelper::KInputDialogHelper(
const QString &caption,
const QString &label,
177 m_label(0), m_lineEdit(0), m_intSpinBox(0),
178 m_doubleSpinBox(0), m_comboBox(0), m_listBox(0)
182 setDefaultButton(
Ok);
186 QVBoxLayout *layout =
new QVBoxLayout(frame);
188 m_label =
new QLabel(label, frame);
189 m_label->setWordWrap(
true);
190 layout->addWidget(m_label);
193 m_comboBox =
new KComboBox(editable, frame);
195 m_lineEdit->setClearButtonShown(
true);
196 m_comboBox->setLineEdit(m_lineEdit);
197 m_comboBox->insertItems(0, list);
198 m_comboBox->setCurrentIndex(current);
199 layout->addWidget(m_comboBox);
201 connect(m_comboBox, SIGNAL(editTextChanged(
QString)),
202 SLOT(slotUpdateButtons(
QString)));
203 slotUpdateButtons(m_comboBox->currentText());
204 m_comboBox->setFocus();
207 m_listBox->addItems(list);
208 m_listBox->setCurrentRow(current);
209 layout->addWidget(m_listBox, 10);
210 connect(m_listBox, SIGNAL(executed(QListWidgetItem*)),
212 m_listBox->setFocus();
215 layout->addStretch();
216 layout->setMargin(0);
217 setMainWidget(frame);
218 setMinimumWidth(320);
221 KInputDialogHelper::KInputDialogHelper(
const QString &caption,
const QString &label,
225 m_label(0), m_lineEdit(0), m_intSpinBox(0),
226 m_doubleSpinBox(0), m_comboBox(0), m_listBox(0)
233 QVBoxLayout *layout =
new QVBoxLayout(frame);
235 m_label =
new QLabel(label, frame);
236 m_label->setWordWrap(
true);
237 layout->addWidget(m_label);
240 m_listBox->addItems(list);
241 layout->addWidget(m_listBox);
244 m_listBox->setSelectionMode(QAbstractItemView::ExtendedSelection);
246 for (QStringList::ConstIterator it = select.begin(); it != select.end(); ++it) {
248 if (!matches.isEmpty())
249 m_listBox->setCurrentItem(matches.first());
252 connect(m_listBox, SIGNAL(executed(QListWidgetItem*)), SLOT(accept()));
254 if (!select.isEmpty()) {
258 if (!matches.isEmpty())
259 m_listBox->setCurrentItem(matches.first());
263 m_listBox->setFocus();
265 layout->addStretch();
266 layout->setMargin(0);
267 setMainWidget(frame);
268 setMinimumWidth(320);
271 KInputDialogHelper::~KInputDialogHelper()
275 void KInputDialogHelper::slotEditTextChanged(
const QString &text )
279 if (m_lineEdit->validator()) {
280 QString str = m_lineEdit->text();
281 int index = m_lineEdit->cursorPosition();
282 on = (m_lineEdit->validator()->validate(str, index) == QValidator::Acceptable);
284 on = !text.trimmed().isEmpty();
287 enableButton(
Ok, on);
290 void KInputDialogHelper::slotUpdateButtons(
const QString &text )
292 enableButton(
Ok, !text.isEmpty());
295 KLineEdit *KInputDialogHelper::lineEdit()
const
300 KIntSpinBox *KInputDialogHelper::intSpinBox()
const
305 QDoubleSpinBox *KInputDialogHelper::doubleSpinBox()
const
307 return m_doubleSpinBox;
310 KComboBox *KInputDialogHelper::comboBox()
const
320 KTextEdit *KInputDialogHelper::textEdit()
const
328 namespace KInputDialog {
335 KInputDialogHelper dlg(caption, label, value, parent, validator, mask);
337 if (!whatsThis.isEmpty())
338 dlg.lineEdit()->setWhatsThis(whatsThis);
340 if (!completionList.isEmpty()) {
341 KCompletion *comp=dlg.lineEdit()->completionObject();
342 for (QStringList::const_iterator it = completionList.constBegin(); it != completionList.constEnd(); ++it)
346 bool _ok = (dlg.exec() == KDialog::Accepted);
353 result = dlg.lineEdit()->text();
357 result = result.trimmed();
366 KInputDialogHelper dlg(caption, label, value, parent);
367 dlg.textEdit()->setAcceptRichText(
false);
368 bool _ok = (dlg.exec() == KDialog::Accepted);
375 result = dlg.textEdit()->toPlainText();
381 int value,
int minValue,
int maxValue,
int step,
int base,
bool *
ok,
384 KInputDialogHelper dlg(caption, label, value, minValue, maxValue, step, base, parent);
386 bool _ok = (dlg.exec() == KDialog::Accepted);
393 result = dlg.intSpinBox()->value();
399 int value,
int minValue,
int maxValue,
int step,
bool *
ok,
402 return getInteger(caption, label, value, minValue, maxValue, step, 10, ok, parent);
406 double value,
double minValue,
double maxValue,
double step,
int decimals,
409 KInputDialogHelper dlg(caption, label, value, minValue, maxValue, step, decimals, parent);
411 bool _ok = (dlg.exec() == KDialog::Accepted);
418 result = dlg.doubleSpinBox()->value();
424 double value,
double minValue,
double maxValue,
int decimals,
427 return getDouble(caption, label, value, minValue, maxValue, 0.1, decimals, ok, parent);
431 const QStringList &list,
int current,
bool editable,
bool *
ok,
434 KInputDialogHelper dlg(caption, label, list, current, editable, parent);
437 dlg.connect(dlg.listBox(), SIGNAL(executed(QListWidgetItem*)), &dlg, SLOT(accept()));
439 bool _ok = (dlg.exec() == KDialog::Accepted);
447 result = dlg.comboBox()->currentText();
448 else if( dlg.listBox()->currentItem())
449 result = dlg.listBox()->currentItem()->text();
457 bool multiple,
bool *
ok,
QWidget *parent )
459 KInputDialogHelper dlg(caption, label, list, select, multiple, parent);
461 bool _ok = (dlg.exec() == KDialog::Accepted);
468 for (
int i=0 ; i < dlg.listBox()->count() ; i++) {
470 QListWidgetItem* item = dlg.listBox()->item(i);
472 if (item->isSelected())
473 result.append(item->text());
482 #include "kinputdialog_p.moc"
QString label(StandardShortcut id)
Returns a localized label for user-visible display.
void clear()
Removes all entries from the cache.
A dialog base class with standard buttons and predefined layouts.
KGuiItem clear()
Returns the 'Clear' gui item.
A generic class for completing QStrings.
KGuiItem ok()
Returns the 'Ok' gui item.
An enhanced QLineEdit widget for inputting text.
A QSpinBox with support for arbitrary base numbers.
QString whatsThis(StandardShortcut)
What's This button.
void addItem(const QString &item)
Adds an item to the list of available completions.