26 #include <tqvalidator.h> 27 #include <tqwhatsthis.h> 29 #include <klineedit.h> 30 #include <knuminput.h> 31 #include <kcombobox.h> 32 #include <tdelistbox.h> 33 #include <ktextedit.h> 35 #include "kinputdialog.h" 37 class KInputDialogPrivate
40 KInputDialogPrivate();
51 KInputDialogPrivate::KInputDialogPrivate()
52 : m_label( 0L ), m_lineEdit( 0L ), m_intSpinBox( 0L ),
53 m_doubleSpinBox( 0L ), m_comboBox( 0L )
57 KInputDialog::KInputDialog(
const TQString &caption,
const TQString &label,
58 const TQString &value, TQWidget *parent,
const char *name,
59 TQValidator *validator,
const TQString &mask )
60 :
KDialogBase( parent, name, true, caption, Ok|Cancel|User1, Ok, true,
62 d( new KInputDialogPrivate() )
64 TQFrame *frame = makeMainWidget();
65 TQVBoxLayout *layout =
new TQVBoxLayout( frame, 0, spacingHint() );
67 d->m_label =
new TQLabel( label, frame );
68 layout->addWidget( d->m_label );
70 d->m_lineEdit =
new KLineEdit( value, frame );
71 layout->addWidget( d->m_lineEdit );
73 d->m_lineEdit->setFocus();
74 d->m_label->setBuddy( d->m_lineEdit );
79 d->m_lineEdit->setValidator( validator );
81 if ( !mask.isEmpty() )
82 d->m_lineEdit->setInputMask( mask );
84 connect( d->m_lineEdit, TQT_SIGNAL( textChanged(
const TQString & ) ),
85 TQT_SLOT( slotEditTextChanged(
const TQString & ) ) );
86 connect(
this, TQT_SIGNAL( user1Clicked() ), d->m_lineEdit, TQT_SLOT(
clear() ) );
88 slotEditTextChanged( value );
89 setMinimumWidth( 350 );
92 KInputDialog::KInputDialog(
const TQString &caption,
const TQString &label,
93 const TQString &value, TQWidget *parent,
const char *name )
94 :
KDialogBase( parent, name, true, caption, Ok|Cancel|User1, Ok, false,
96 d( new KInputDialogPrivate() )
98 TQFrame *frame = makeMainWidget();
99 TQVBoxLayout *layout =
new TQVBoxLayout( frame, 0, spacingHint() );
101 d->m_label =
new TQLabel( label, frame );
102 layout->addWidget( d->m_label );
105 d->m_textEdit->setTextFormat( PlainText );
106 d->m_textEdit->setText( value );
107 layout->addWidget( d->m_textEdit, 10 );
109 d->m_textEdit->setFocus();
110 d->m_label->setBuddy( d->m_textEdit );
112 connect(
this, TQT_SIGNAL( user1Clicked() ), d->m_textEdit, TQT_SLOT(
clear() ) );
114 setMinimumWidth( 400 );
117 KInputDialog::KInputDialog(
const TQString &caption,
const TQString &label,
118 int value,
int minValue,
int maxValue,
int step,
int base,
119 TQWidget *parent,
const char *name )
120 :
KDialogBase( parent, name, true, caption, Ok|Cancel, Ok, true ),
121 d( new KInputDialogPrivate() )
123 TQFrame *frame = makeMainWidget();
124 TQVBoxLayout *layout =
new TQVBoxLayout( frame, 0, spacingHint() );
126 d->m_label =
new TQLabel( label, frame );
127 layout->addWidget( d->m_label );
129 d->m_intSpinBox =
new KIntSpinBox( minValue, maxValue, step, value,
131 layout->addWidget( d->m_intSpinBox );
133 layout->addStretch();
135 d->m_intSpinBox->setFocus();
136 setMinimumWidth( 300 );
139 KInputDialog::KInputDialog(
const TQString &caption,
const TQString &label,
140 double value,
double minValue,
double maxValue,
double step,
int decimals,
141 TQWidget *parent,
const char *name )
142 :
KDialogBase( parent, name, true, caption, Ok|Cancel, Ok, true ),
143 d( new KInputDialogPrivate() )
145 TQFrame *frame = makeMainWidget();
146 TQVBoxLayout *layout =
new TQVBoxLayout( frame, 0, spacingHint() );
148 d->m_label =
new TQLabel( label, frame );
149 layout->addWidget( d->m_label );
151 d->m_doubleSpinBox =
new KDoubleSpinBox( minValue, maxValue, step, value,
153 layout->addWidget( d->m_doubleSpinBox );
155 layout->addStretch();
157 d->m_doubleSpinBox->setFocus();
158 setMinimumWidth( 300 );
161 KInputDialog::KInputDialog(
const TQString &caption,
const TQString &label,
162 const TQStringList &list,
int current,
bool editable, TQWidget *parent,
164 :
KDialogBase( parent, name, true, caption, Ok|Cancel|User1, Ok, true,
166 d( new KInputDialogPrivate() )
168 showButton( User1, editable );
170 TQFrame *frame = makeMainWidget();
171 TQVBoxLayout *layout =
new TQVBoxLayout( frame, 0, spacingHint() );
173 d->m_label =
new TQLabel( label, frame );
174 layout->addWidget( d->m_label );
178 d->m_comboBox =
new KComboBox( editable, frame );
179 d->m_comboBox->insertStringList( list );
180 d->m_comboBox->setCurrentItem( current );
181 layout->addWidget( d->m_comboBox );
183 connect( d->m_comboBox, TQT_SIGNAL( textChanged(
const TQString & ) ),
184 TQT_SLOT( slotUpdateButtons(
const TQString & ) ) );
185 connect(
this, TQT_SIGNAL( user1Clicked() ),
186 d->m_comboBox, TQT_SLOT( clearEdit() ) );
187 slotUpdateButtons( d->m_comboBox->currentText() );
188 d->m_comboBox->setFocus();
191 d->m_listBox->insertStringList( list );
192 d->m_listBox->setSelected( current,
true );
193 d->m_listBox->ensureCurrentVisible();
194 layout->addWidget( d->m_listBox, 10 );
195 connect( d->m_listBox, TQT_SIGNAL( doubleClicked( TQListBoxItem * ) ),
196 TQT_SLOT( slotOk() ) );
197 connect( d->m_listBox, TQT_SIGNAL(
returnPressed( TQListBoxItem * ) ),
198 TQT_SLOT( slotOk() ) );
200 d->m_listBox->setFocus();
203 layout->addStretch();
205 setMinimumWidth( 320 );
208 KInputDialog::KInputDialog(
const TQString &caption,
const TQString &label,
209 const TQStringList &list,
const TQStringList &select,
bool multiple,
210 TQWidget *parent,
const char *name )
211 :
KDialogBase( parent, name, true, caption, Ok|Cancel, Ok, true ),
212 d( new KInputDialogPrivate() )
214 TQFrame *frame = makeMainWidget();
215 TQVBoxLayout *layout =
new TQVBoxLayout( frame, 0, spacingHint() );
217 d->m_label =
new TQLabel( label, frame );
218 layout->addWidget( d->m_label );
221 d->m_listBox->insertStringList( list );
222 layout->addWidget( d->m_listBox );
228 d->m_listBox->setSelectionMode( TQListBox::Extended );
230 for ( TQStringList::ConstIterator it=select.begin(); it!=select.end(); ++it )
232 item = d->m_listBox->findItem( *it, CaseSensitive|ExactMatch );
234 d->m_listBox->setSelected( item,
true );
239 connect( d->m_listBox, TQT_SIGNAL( doubleClicked( TQListBoxItem * ) ),
240 TQT_SLOT( slotOk() ) );
241 connect( d->m_listBox, TQT_SIGNAL(
returnPressed( TQListBoxItem * ) ),
242 TQT_SLOT( slotOk() ) );
244 TQString text = select.first();
245 item = d->m_listBox->findItem( text, CaseSensitive|ExactMatch );
247 d->m_listBox->setSelected( item,
true );
250 d->m_listBox->ensureCurrentVisible();
251 d->m_listBox->setFocus();
253 layout->addStretch();
255 setMinimumWidth( 320 );
258 KInputDialog::~KInputDialog()
264 const TQString &value,
bool *ok, TQWidget *parent,
const char *name,
265 TQValidator *validator,
const TQString &mask )
267 return text( caption, label, value, ok, parent, name, validator, mask,
272 const TQString &label,
const TQString &value,
bool *ok, TQWidget *parent,
273 const char *name, TQValidator *validator,
const TQString &mask,
274 const TQString &whatsThis )
276 KInputDialog dlg( caption, label, value, parent, name, validator, mask );
278 if( !whatsThis.isEmpty() )
279 TQWhatsThis::add( dlg.lineEdit(), whatsThis );
281 bool _ok = ( dlg.exec() == Accepted );
288 result = dlg.lineEdit()->text();
292 result = result.stripWhiteSpace();
298 const TQString &label,
const TQString &value,
bool *ok,
299 TQWidget *parent,
const char *name )
301 KInputDialog dlg( caption, label, value, parent, name );
303 bool _ok = ( dlg.exec() == Accepted );
310 result = dlg.textEdit()->text();
316 int value,
int minValue,
int maxValue,
int step,
int base,
bool *ok,
317 TQWidget *parent,
const char *name )
320 maxValue, step, base, parent, name );
322 bool _ok = ( dlg.exec() == Accepted );
329 result = dlg.intSpinBox()->value();
335 int value,
int minValue,
int maxValue,
int step,
bool *ok,
336 TQWidget *parent,
const char *name )
338 return getInteger( caption, label, value, minValue, maxValue, step,
339 10, ok, parent, name );
343 double value,
double minValue,
double maxValue,
double step,
int decimals,
344 bool *ok, TQWidget *parent,
const char *name )
347 maxValue, step, decimals, parent, name );
349 bool _ok = ( dlg.exec() == Accepted );
356 result = dlg.doubleSpinBox()->
value();
362 double value,
double minValue,
double maxValue,
int decimals,
363 bool *ok, TQWidget *parent,
const char *name )
365 return getDouble( caption, label, value, minValue, maxValue, 0.1, decimals,
370 const TQStringList &list,
int current,
bool editable,
bool *ok,
371 TQWidget *parent,
const char *name )
374 editable, parent, name );
377 connect( dlg.listBox(), TQT_SIGNAL(doubleClicked ( TQListBoxItem *)), &dlg, TQT_SLOT( slotOk()));
379 bool _ok = ( dlg.exec() == Accepted );
387 result = dlg.comboBox()->currentText();
389 result = dlg.listBox()->currentText();
395 const TQString &label,
const TQStringList &list,
const TQStringList &select,
396 bool multiple,
bool *ok, TQWidget *parent,
const char *name )
399 multiple, parent, name );
401 bool _ok = ( dlg.exec() == Accepted );
409 for (
const TQListBoxItem* i = dlg.listBox()->firstItem(); i != 0; i = i->next() )
410 if ( i->isSelected() )
411 result.append( i->text() );
417 void KInputDialog::slotEditTextChanged(
const TQString &text )
420 if ( lineEdit()->validator() ) {
421 TQString str = lineEdit()->text();
422 int index = lineEdit()->cursorPosition();
423 on = ( lineEdit()->validator()->validate( str, index )
424 == TQValidator::Acceptable );
426 on = !text.stripWhiteSpace().isEmpty();
429 enableButton( Ok, on );
430 enableButton( User1, !text.isEmpty() );
433 void KInputDialog::slotUpdateButtons(
const TQString &text )
435 enableButton( Ok, !text.isEmpty() );
436 enableButton( User1, !text.isEmpty() );
439 KLineEdit *KInputDialog::lineEdit()
const 441 return d->m_lineEdit;
446 return d->m_intSpinBox;
451 return d->m_doubleSpinBox;
454 KComboBox *KInputDialog::comboBox()
const 456 return d->m_comboBox;
464 KTextEdit *KInputDialog::textEdit()
const 466 return d->m_textEdit;
469 #include "kinputdialog.moc"
KLineEdit(const TQString &string, TQWidget *parent, const char *name=0)
Constructs a KLineEdit object with a default text, a parent, and a name.
A spin box for fractional numbers.
void returnPressed(const TQString &)
Emitted when the user presses the return key.
A dialog base class with standard buttons and predefined layouts.
void clear()
Clear line edit and empty hiddenItems, returning elements to iconView.
An enhanced TQLineEdit widget for inputting text.
A TQSpinBox with support for arbitrary base numbers.
Provides a set of standardized KGuiItems.
A variant of TQListBox that honors KDE's system-wide settings.
A KDE'ified QTextEdit.