22 #include <tqvalidator.h>
23 #include <tqwhatsthis.h>
25 #include <klineedit.h>
26 #include <knuminput.h>
27 #include <kcombobox.h>
28 #include <tdelistbox.h>
29 #include <ktextedit.h>
31 #include "kinputdialog.h"
33 class KInputDialogPrivate
36 KInputDialogPrivate();
47 KInputDialogPrivate::KInputDialogPrivate()
48 : m_label( 0L ), m_lineEdit( 0L ), m_intSpinBox( 0L ),
49 m_doubleSpinBox( 0L ), m_comboBox( 0L )
53 KInputDialog::KInputDialog(
const TQString &caption,
const TQString &label,
54 const TQString &value, TQWidget *parent,
const char *name,
55 TQValidator *validator,
const TQString &mask )
58 d( new KInputDialogPrivate() )
60 TQFrame *frame = makeMainWidget();
61 TQVBoxLayout *layout =
new TQVBoxLayout( frame, 0, spacingHint() );
63 d->m_label =
new TQLabel( label, frame );
64 layout->addWidget( d->m_label );
66 d->m_lineEdit =
new KLineEdit( value, frame );
67 layout->addWidget( d->m_lineEdit );
69 d->m_lineEdit->setFocus();
70 d->m_label->setBuddy( d->m_lineEdit );
75 d->m_lineEdit->setValidator( validator );
77 if ( !mask.isEmpty() )
78 d->m_lineEdit->setInputMask( mask );
80 connect( d->m_lineEdit, TQ_SIGNAL( textChanged(
const TQString & ) ),
81 TQ_SLOT( slotEditTextChanged(
const TQString & ) ) );
82 connect(
this, TQ_SIGNAL( user1Clicked() ), d->m_lineEdit, TQ_SLOT(
clear() ) );
84 slotEditTextChanged( value );
85 setMinimumWidth( 350 );
88 KInputDialog::KInputDialog(
const TQString &caption,
const TQString &label,
89 const TQString &value, TQWidget *parent,
const char *name )
92 d( new KInputDialogPrivate() )
94 TQFrame *frame = makeMainWidget();
95 TQVBoxLayout *layout =
new TQVBoxLayout( frame, 0, spacingHint() );
97 d->m_label =
new TQLabel( label, frame );
98 layout->addWidget( d->m_label );
101 d->m_textEdit->setTextFormat( PlainText );
102 d->m_textEdit->setText( value );
103 layout->addWidget( d->m_textEdit, 10 );
105 d->m_textEdit->setFocus();
106 d->m_label->setBuddy( d->m_textEdit );
108 connect(
this, TQ_SIGNAL( user1Clicked() ), d->m_textEdit, TQ_SLOT(
clear() ) );
110 setMinimumWidth( 400 );
113 KInputDialog::KInputDialog(
const TQString &caption,
const TQString &label,
114 int value,
int minValue,
int maxValue,
int step,
int base,
115 TQWidget *parent,
const char *name )
117 d( new KInputDialogPrivate() )
119 TQFrame *frame = makeMainWidget();
120 TQVBoxLayout *layout =
new TQVBoxLayout( frame, 0, spacingHint() );
122 d->m_label =
new TQLabel( label, frame );
123 layout->addWidget( d->m_label );
125 d->m_intSpinBox =
new KIntSpinBox( minValue, maxValue, step, value,
127 layout->addWidget( d->m_intSpinBox );
129 layout->addStretch();
131 d->m_intSpinBox->setFocus();
132 setMinimumWidth( 300 );
135 KInputDialog::KInputDialog(
const TQString &caption,
const TQString &label,
136 double value,
double minValue,
double maxValue,
double step,
int decimals,
137 TQWidget *parent,
const char *name )
139 d( new KInputDialogPrivate() )
141 TQFrame *frame = makeMainWidget();
142 TQVBoxLayout *layout =
new TQVBoxLayout( frame, 0, spacingHint() );
144 d->m_label =
new TQLabel( label, frame );
145 layout->addWidget( d->m_label );
147 d->m_doubleSpinBox =
new KDoubleSpinBox( minValue, maxValue, step, value,
149 layout->addWidget( d->m_doubleSpinBox );
151 layout->addStretch();
153 d->m_doubleSpinBox->setFocus();
154 setMinimumWidth( 300 );
157 KInputDialog::KInputDialog(
const TQString &caption,
const TQString &label,
158 const TQStringList &list,
int current,
bool editable, TQWidget *parent,
162 d( new KInputDialogPrivate() )
164 showButton( User1, editable );
166 TQFrame *frame = makeMainWidget();
167 TQVBoxLayout *layout =
new TQVBoxLayout( frame, 0, spacingHint() );
169 d->m_label =
new TQLabel( label, frame );
170 layout->addWidget( d->m_label );
174 d->m_comboBox =
new KComboBox( editable, frame );
175 d->m_comboBox->insertStringList( list );
176 d->m_comboBox->setCurrentItem( current );
177 layout->addWidget( d->m_comboBox );
179 connect( d->m_comboBox, TQ_SIGNAL( textChanged(
const TQString & ) ),
180 TQ_SLOT( slotUpdateButtons(
const TQString & ) ) );
181 connect(
this, TQ_SIGNAL( user1Clicked() ),
182 d->m_comboBox, TQ_SLOT( clearEdit() ) );
183 slotUpdateButtons( d->m_comboBox->currentText() );
184 d->m_comboBox->setFocus();
187 d->m_listBox->insertStringList( list );
188 d->m_listBox->setSelected( current,
true );
189 d->m_listBox->ensureCurrentVisible();
190 layout->addWidget( d->m_listBox, 10 );
191 connect( d->m_listBox, TQ_SIGNAL( doubleClicked( TQListBoxItem * ) ),
192 TQ_SLOT( slotOk() ) );
193 connect( d->m_listBox, TQ_SIGNAL( returnPressed( TQListBoxItem * ) ),
194 TQ_SLOT( slotOk() ) );
196 d->m_listBox->setFocus();
199 layout->addStretch();
201 setMinimumWidth( 320 );
204 KInputDialog::KInputDialog(
const TQString &caption,
const TQString &label,
205 const TQStringList &list,
const TQStringList &select,
bool multiple,
206 TQWidget *parent,
const char *name )
208 d( new KInputDialogPrivate() )
210 TQFrame *frame = makeMainWidget();
211 TQVBoxLayout *layout =
new TQVBoxLayout( frame, 0, spacingHint() );
213 d->m_label =
new TQLabel( label, frame );
214 layout->addWidget( d->m_label );
217 d->m_listBox->insertStringList( list );
218 layout->addWidget( d->m_listBox );
224 d->m_listBox->setSelectionMode( TQListBox::Extended );
226 for ( TQStringList::ConstIterator it=select.begin(); it!=select.end(); ++it )
228 item = d->m_listBox->findItem( *it, CaseSensitive|ExactMatch );
230 d->m_listBox->setSelected( item,
true );
235 connect( d->m_listBox, TQ_SIGNAL( doubleClicked( TQListBoxItem * ) ),
236 TQ_SLOT( slotOk() ) );
237 connect( d->m_listBox, TQ_SIGNAL( returnPressed( TQListBoxItem * ) ),
238 TQ_SLOT( slotOk() ) );
240 TQString text = select.first();
241 item = d->m_listBox->findItem( text, CaseSensitive|ExactMatch );
243 d->m_listBox->setSelected( item,
true );
246 d->m_listBox->ensureCurrentVisible();
247 d->m_listBox->setFocus();
249 layout->addStretch();
251 setMinimumWidth( 320 );
254 KInputDialog::~KInputDialog()
260 const TQString &value,
bool *ok, TQWidget *parent,
const char *name,
261 TQValidator *validator,
const TQString &mask )
263 return text( caption, label, value, ok, parent, name, validator, mask,
268 const TQString &label,
const TQString &value,
bool *ok, TQWidget *parent,
269 const char *name, TQValidator *validator,
const TQString &mask,
270 const TQString &whatsThis )
272 KInputDialog dlg( caption, label, value, parent, name, validator, mask );
274 if( !whatsThis.isEmpty() )
275 TQWhatsThis::add( dlg.lineEdit(), whatsThis );
277 bool _ok = ( dlg.exec() == Accepted );
284 result = dlg.lineEdit()->text();
288 result = result.stripWhiteSpace();
294 const TQString &label,
const TQString &value,
bool *ok,
295 TQWidget *parent,
const char *name )
297 KInputDialog dlg( caption, label, value, parent, name );
299 bool _ok = ( dlg.exec() == Accepted );
306 result = dlg.textEdit()->text();
312 int value,
int minValue,
int maxValue,
int step,
int base,
bool *ok,
313 TQWidget *parent,
const char *name )
316 maxValue, step, base, parent, name );
318 bool _ok = ( dlg.exec() == Accepted );
325 result = dlg.intSpinBox()->value();
331 int value,
int minValue,
int maxValue,
int step,
bool *ok,
332 TQWidget *parent,
const char *name )
334 return getInteger( caption, label, value, minValue, maxValue, step,
335 10, ok, parent, name );
339 double value,
double minValue,
double maxValue,
double step,
int decimals,
340 bool *ok, TQWidget *parent,
const char *name )
343 maxValue, step, decimals, parent, name );
345 bool _ok = ( dlg.exec() == Accepted );
352 result = dlg.doubleSpinBox()->
value();
358 double value,
double minValue,
double maxValue,
int decimals,
359 bool *ok, TQWidget *parent,
const char *name )
361 return getDouble( caption, label, value, minValue, maxValue, 0.1, decimals,
366 const TQStringList &list,
int current,
bool editable,
bool *ok,
367 TQWidget *parent,
const char *name )
370 editable, parent, name );
373 connect( dlg.listBox(), TQ_SIGNAL(doubleClicked ( TQListBoxItem *)), &dlg, TQ_SLOT(
slotOk()));
375 bool _ok = ( dlg.exec() == Accepted );
383 result = dlg.comboBox()->currentText();
385 result = dlg.listBox()->currentText();
391 const TQString &label,
const TQStringList &list,
const TQStringList &select,
392 bool multiple,
bool *ok, TQWidget *parent,
const char *name )
395 multiple, parent, name );
397 bool _ok = ( dlg.exec() == Accepted );
405 for (
const TQListBoxItem* i = dlg.listBox()->firstItem(); i != 0; i = i->next() )
406 if ( i->isSelected() )
407 result.append( i->text() );
413 void KInputDialog::slotEditTextChanged(
const TQString &text )
416 if ( lineEdit()->validator() ) {
417 TQString str = lineEdit()->text();
418 int index = lineEdit()->cursorPosition();
419 on = ( lineEdit()->validator()->validate( str, index )
420 == TQValidator::Acceptable );
422 on = !
text.stripWhiteSpace().isEmpty();
429 void KInputDialog::slotUpdateButtons(
const TQString &text )
435 KLineEdit *KInputDialog::lineEdit()
const
437 return d->m_lineEdit;
442 return d->m_intSpinBox;
447 return d->m_doubleSpinBox;
450 KComboBox *KInputDialog::comboBox()
const
452 return d->m_comboBox;
460 KTextEdit *KInputDialog::textEdit()
const
462 return d->m_textEdit;
465 #include "kinputdialog.moc"
A dialog base class with standard buttons and predefined layouts.
void enableButton(ButtonCode id, bool state)
Enable or disable (gray out) a general action button.
@ User1
Show User defined button 1.
virtual void slotOk()
Activated when the Ok button has been clicked.
A spin box for fractional numbers.
A TQSpinBox with support for arbitrary base numbers.
An enhanced TQLineEdit widget for inputting text.
Provides a set of standardized KGuiItems.
A variant of TQListBox that honors KDE's system-wide settings.
TDEAction * clear(const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name)
Clear the content of the focus widget.
TQString name(StdAccel id)