• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeui
 

tdeui

  • tdeui
kinputdialog.cpp
1/*
2 Copyright (C) 2003 Nadeem Hasan <nhasan@kde.org>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
18*/
19
20#include <tqlayout.h>
21#include <tqlabel.h>
22#include <tqvalidator.h>
23#include <tqwhatsthis.h>
24
25#include <klineedit.h>
26#include <knuminput.h>
27#include <kcombobox.h>
28#include <tdelistbox.h>
29#include <ktextedit.h>
30
31#include "kinputdialog.h"
32
33class KInputDialogPrivate
34{
35 public:
36 KInputDialogPrivate();
37
38 TQLabel *m_label;
39 KLineEdit *m_lineEdit;
40 KIntSpinBox *m_intSpinBox;
41 KDoubleSpinBox *m_doubleSpinBox;
42 KComboBox *m_comboBox;
43 TDEListBox *m_listBox;
44 KTextEdit *m_textEdit;
45};
46
47KInputDialogPrivate::KInputDialogPrivate()
48 : m_label( 0L ), m_lineEdit( 0L ), m_intSpinBox( 0L ),
49 m_doubleSpinBox( 0L ), m_comboBox( 0L )
50{
51}
52
53KInputDialog::KInputDialog( const TQString &caption, const TQString &label,
54 const TQString &value, TQWidget *parent, const char *name,
55 TQValidator *validator, const TQString &mask )
56 : KDialogBase( parent, name, true, caption, Ok|Cancel|User1, Ok, true,
57 KStdGuiItem::clear() ),
58 d( new KInputDialogPrivate() )
59{
60 TQFrame *frame = makeMainWidget();
61 TQVBoxLayout *layout = new TQVBoxLayout( frame, 0, spacingHint() );
62
63 d->m_label = new TQLabel( label, frame );
64 layout->addWidget( d->m_label );
65
66 d->m_lineEdit = new KLineEdit( value, frame );
67 layout->addWidget( d->m_lineEdit );
68
69 d->m_lineEdit->setFocus();
70 d->m_label->setBuddy( d->m_lineEdit );
71
72 layout->addStretch();
73
74 if ( validator )
75 d->m_lineEdit->setValidator( validator );
76
77 if ( !mask.isEmpty() )
78 d->m_lineEdit->setInputMask( mask );
79
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() ) );
83
84 slotEditTextChanged( value );
85 setMinimumWidth( 350 );
86}
87
88KInputDialog::KInputDialog( const TQString &caption, const TQString &label,
89 const TQString &value, TQWidget *parent, const char *name )
90 : KDialogBase( parent, name, true, caption, Ok|Cancel|User1, Ok, false,
91 KStdGuiItem::clear() ),
92 d( new KInputDialogPrivate() )
93{
94 TQFrame *frame = makeMainWidget();
95 TQVBoxLayout *layout = new TQVBoxLayout( frame, 0, spacingHint() );
96
97 d->m_label = new TQLabel( label, frame );
98 layout->addWidget( d->m_label );
99
100 d->m_textEdit = new KTextEdit( frame );
101 d->m_textEdit->setTextFormat( PlainText );
102 d->m_textEdit->setText( value );
103 layout->addWidget( d->m_textEdit, 10 );
104
105 d->m_textEdit->setFocus();
106 d->m_label->setBuddy( d->m_textEdit );
107
108 connect( this, TQ_SIGNAL( user1Clicked() ), d->m_textEdit, TQ_SLOT( clear() ) );
109
110 setMinimumWidth( 400 );
111}
112
113KInputDialog::KInputDialog( const TQString &caption, const TQString &label,
114 int value, int minValue, int maxValue, int step, int base,
115 TQWidget *parent, const char *name )
116 : KDialogBase( parent, name, true, caption, Ok|Cancel, Ok, true ),
117 d( new KInputDialogPrivate() )
118{
119 TQFrame *frame = makeMainWidget();
120 TQVBoxLayout *layout = new TQVBoxLayout( frame, 0, spacingHint() );
121
122 d->m_label = new TQLabel( label, frame );
123 layout->addWidget( d->m_label );
124
125 d->m_intSpinBox = new KIntSpinBox( minValue, maxValue, step, value,
126 base, frame );
127 layout->addWidget( d->m_intSpinBox );
128
129 layout->addStretch();
130
131 d->m_intSpinBox->setFocus();
132 setMinimumWidth( 300 );
133}
134
135KInputDialog::KInputDialog( const TQString &caption, const TQString &label,
136 double value, double minValue, double maxValue, double step, int decimals,
137 TQWidget *parent, const char *name )
138 : KDialogBase( parent, name, true, caption, Ok|Cancel, Ok, true ),
139 d( new KInputDialogPrivate() )
140{
141 TQFrame *frame = makeMainWidget();
142 TQVBoxLayout *layout = new TQVBoxLayout( frame, 0, spacingHint() );
143
144 d->m_label = new TQLabel( label, frame );
145 layout->addWidget( d->m_label );
146
147 d->m_doubleSpinBox = new KDoubleSpinBox( minValue, maxValue, step, value,
148 decimals, frame );
149 layout->addWidget( d->m_doubleSpinBox );
150
151 layout->addStretch();
152
153 d->m_doubleSpinBox->setFocus();
154 setMinimumWidth( 300 );
155}
156
157KInputDialog::KInputDialog( const TQString &caption, const TQString &label,
158 const TQStringList &list, int current, bool editable, TQWidget *parent,
159 const char *name )
160 : KDialogBase( parent, name, true, caption, Ok|Cancel|User1, Ok, true,
161 KStdGuiItem::clear() ),
162 d( new KInputDialogPrivate() )
163{
164 showButton( User1, editable );
165
166 TQFrame *frame = makeMainWidget();
167 TQVBoxLayout *layout = new TQVBoxLayout( frame, 0, spacingHint() );
168
169 d->m_label = new TQLabel( label, frame );
170 layout->addWidget( d->m_label );
171
172 if ( editable )
173 {
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 );
178
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();
185 } else {
186 d->m_listBox = new TDEListBox( frame );
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() ) );
195
196 d->m_listBox->setFocus();
197 }
198
199 layout->addStretch();
200
201 setMinimumWidth( 320 );
202}
203
204KInputDialog::KInputDialog( const TQString &caption, const TQString &label,
205 const TQStringList &list, const TQStringList &select, bool multiple,
206 TQWidget *parent, const char *name )
207 : KDialogBase( parent, name, true, caption, Ok|Cancel, Ok, true ),
208 d( new KInputDialogPrivate() )
209{
210 TQFrame *frame = makeMainWidget();
211 TQVBoxLayout *layout = new TQVBoxLayout( frame, 0, spacingHint() );
212
213 d->m_label = new TQLabel( label, frame );
214 layout->addWidget( d->m_label );
215
216 d->m_listBox = new TDEListBox( frame );
217 d->m_listBox->insertStringList( list );
218 layout->addWidget( d->m_listBox );
219
220 TQListBoxItem *item;
221
222 if ( multiple )
223 {
224 d->m_listBox->setSelectionMode( TQListBox::Extended );
225
226 for ( TQStringList::ConstIterator it=select.begin(); it!=select.end(); ++it )
227 {
228 item = d->m_listBox->findItem( *it, CaseSensitive|ExactMatch );
229 if ( item )
230 d->m_listBox->setSelected( item, true );
231 }
232 }
233 else
234 {
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() ) );
239
240 TQString text = select.first();
241 item = d->m_listBox->findItem( text, CaseSensitive|ExactMatch );
242 if ( item )
243 d->m_listBox->setSelected( item, true );
244 }
245
246 d->m_listBox->ensureCurrentVisible();
247 d->m_listBox->setFocus();
248
249 layout->addStretch();
250
251 setMinimumWidth( 320 );
252}
253
254KInputDialog::~KInputDialog()
255{
256 delete d;
257}
258
259TQString KInputDialog::getText( const TQString &caption, const TQString &label,
260 const TQString &value, bool *ok, TQWidget *parent, const char *name,
261 TQValidator *validator, const TQString &mask )
262{
263 return text( caption, label, value, ok, parent, name, validator, mask,
264 TQString::null );
265}
266
267TQString KInputDialog::text( const TQString &caption,
268 const TQString &label, const TQString &value, bool *ok, TQWidget *parent,
269 const char *name, TQValidator *validator, const TQString &mask,
270 const TQString &whatsThis )
271{
272 KInputDialog dlg( caption, label, value, parent, name, validator, mask );
273
274 if( !whatsThis.isEmpty() )
275 TQWhatsThis::add( dlg.lineEdit(), whatsThis );
276
277 bool _ok = ( dlg.exec() == Accepted );
278
279 if ( ok )
280 *ok = _ok;
281
282 TQString result;
283 if ( _ok )
284 result = dlg.lineEdit()->text();
285
286 // A validator may explicitly allow leading and trailing whitespace
287 if ( !validator )
288 result = result.stripWhiteSpace();
289
290 return result;
291}
292
293TQString KInputDialog::getMultiLineText( const TQString &caption,
294 const TQString &label, const TQString &value, bool *ok,
295 TQWidget *parent, const char *name )
296{
297 KInputDialog dlg( caption, label, value, parent, name );
298
299 bool _ok = ( dlg.exec() == Accepted );
300
301 if ( ok )
302 *ok = _ok;
303
304 TQString result;
305 if ( _ok )
306 result = dlg.textEdit()->text();
307
308 return result;
309}
310
311int KInputDialog::getInteger( const TQString &caption, const TQString &label,
312 int value, int minValue, int maxValue, int step, int base, bool *ok,
313 TQWidget *parent, const char *name )
314{
315 KInputDialog dlg( caption, label, value, minValue,
316 maxValue, step, base, parent, name );
317
318 bool _ok = ( dlg.exec() == Accepted );
319
320 if ( ok )
321 *ok = _ok;
322
323 int result=0;
324 if ( _ok )
325 result = dlg.intSpinBox()->value();
326
327 return result;
328}
329
330int KInputDialog::getInteger( const TQString &caption, const TQString &label,
331 int value, int minValue, int maxValue, int step, bool *ok,
332 TQWidget *parent, const char *name )
333{
334 return getInteger( caption, label, value, minValue, maxValue, step,
335 10, ok, parent, name );
336}
337
338double KInputDialog::getDouble( const TQString &caption, const TQString &label,
339 double value, double minValue, double maxValue, double step, int decimals,
340 bool *ok, TQWidget *parent, const char *name )
341{
342 KInputDialog dlg( caption, label, value, minValue,
343 maxValue, step, decimals, parent, name );
344
345 bool _ok = ( dlg.exec() == Accepted );
346
347 if ( ok )
348 *ok = _ok;
349
350 double result=0;
351 if ( _ok )
352 result = dlg.doubleSpinBox()->value();
353
354 return result;
355}
356
357double KInputDialog::getDouble( const TQString &caption, const TQString &label,
358 double value, double minValue, double maxValue, int decimals,
359 bool *ok, TQWidget *parent, const char *name )
360{
361 return getDouble( caption, label, value, minValue, maxValue, 0.1, decimals,
362 ok, parent, name );
363}
364
365TQString KInputDialog::getItem( const TQString &caption, const TQString &label,
366 const TQStringList &list, int current, bool editable, bool *ok,
367 TQWidget *parent, const char *name )
368{
369 KInputDialog dlg( caption, label, list, current,
370 editable, parent, name );
371 if ( !editable)
372 {
373 connect( dlg.listBox(), TQ_SIGNAL(doubleClicked ( TQListBoxItem *)), &dlg, TQ_SLOT( slotOk()));
374 }
375 bool _ok = ( dlg.exec() == Accepted );
376
377 if ( ok )
378 *ok = _ok;
379
380 TQString result;
381 if ( _ok )
382 if ( editable )
383 result = dlg.comboBox()->currentText();
384 else
385 result = dlg.listBox()->currentText();
386
387 return result;
388}
389
390TQStringList KInputDialog::getItemList( const TQString &caption,
391 const TQString &label, const TQStringList &list, const TQStringList &select,
392 bool multiple, bool *ok, TQWidget *parent, const char *name )
393{
394 KInputDialog dlg( caption, label, list, select,
395 multiple, parent, name );
396
397 bool _ok = ( dlg.exec() == Accepted );
398
399 if ( ok )
400 *ok = _ok;
401
402 TQStringList result;
403 if ( _ok )
404 {
405 for (const TQListBoxItem* i = dlg.listBox()->firstItem(); i != 0; i = i->next() )
406 if ( i->isSelected() )
407 result.append( i->text() );
408 }
409
410 return result;
411}
412
413void KInputDialog::slotEditTextChanged( const TQString &text )
414{
415 bool on;
416 if ( lineEdit()->validator() ) {
417 TQString str = lineEdit()->text();
418 int index = lineEdit()->cursorPosition();
419 on = ( lineEdit()->validator()->validate( str, index )
420 == TQValidator::Acceptable );
421 } else {
422 on = !text.stripWhiteSpace().isEmpty();
423 }
424
425 enableButton( Ok, on );
426 enableButton( User1, !text.isEmpty() );
427}
428
429void KInputDialog::slotUpdateButtons( const TQString &text )
430{
431 enableButton( Ok, !text.isEmpty() );
432 enableButton( User1, !text.isEmpty() );
433}
434
435KLineEdit *KInputDialog::lineEdit() const
436{
437 return d->m_lineEdit;
438}
439
440KIntSpinBox *KInputDialog::intSpinBox() const
441{
442 return d->m_intSpinBox;
443}
444
445KDoubleSpinBox *KInputDialog::doubleSpinBox() const
446{
447 return d->m_doubleSpinBox;
448}
449
450KComboBox *KInputDialog::comboBox() const
451{
452 return d->m_comboBox;
453}
454
455TDEListBox *KInputDialog::listBox() const
456{
457 return d->m_listBox;
458}
459
460KTextEdit *KInputDialog::textEdit() const
461{
462 return d->m_textEdit;
463}
464
465#include "kinputdialog.moc"
KComboBox
An enhanced combo box.
Definition: kcombobox.h:152
KDialogBase
A dialog base class with standard buttons and predefined layouts.
Definition: kdialogbase.h:192
KDialogBase::enableButton
void enableButton(ButtonCode id, bool state)
Enable or disable (gray out) a general action button.
Definition: kdialogbase.cpp:838
KDialogBase::User1
@ User1
Show User defined button 1.
Definition: kdialogbase.h:206
KDialogBase::Ok
@ Ok
Show Ok button.
Definition: kdialogbase.h:201
KDialogBase::slotOk
virtual void slotOk()
Activated when the Ok button has been clicked.
Definition: kdialogbase.cpp:1164
KDoubleSpinBox
A spin box for fractional numbers.
Definition: knuminput.h:838
KDoubleSpinBox::value
double value() const
Definition: knuminput.cpp:1102
KInputDialog
The KInputDialog class provides a simple dialog to get a single value from the user.
Definition: kinputdialog.h:47
KInputDialog::getDouble
static double getDouble(const TQString &caption, const TQString &label, double value=0, double minValue=-2147483647, double maxValue=2147483647, double step=0.1, int decimals=1, bool *ok=0, TQWidget *parent=0, const char *name=0)
Static convenience function to get a floating point number from the user.
Definition: kinputdialog.cpp:338
KInputDialog::getInteger
static int getInteger(const TQString &caption, const TQString &label, int value=0, int minValue=-2147483647, int maxValue=2147483647, int step=1, int base=10, bool *ok=0, TQWidget *parent=0, const char *name=0)
Static convenience function to get an integer from the user.
Definition: kinputdialog.cpp:311
KInputDialog::getItemList
static TQStringList getItemList(const TQString &caption, const TQString &label, const TQStringList &list=TQStringList(), const TQStringList &select=TQStringList(), bool multiple=false, bool *ok=0, TQWidget *parent=0, const char *name=0)
Static convenience function to let the user select one or more items from a listbox.
Definition: kinputdialog.cpp:390
KInputDialog::getItem
static TQString getItem(const TQString &caption, const TQString &label, const TQStringList &list, int current=0, bool editable=false, bool *ok=0, TQWidget *parent=0, const char *name=0)
Static convenience function to let the user select an item from a list.
Definition: kinputdialog.cpp:365
KInputDialog::text
static TQString text(const TQString &caption, const TQString &label, const TQString &value=TQString::null, bool *ok=0, TQWidget *parent=0, const char *name=0, TQValidator *validator=0, const TQString &mask=TQString::null, const TQString &whatsThis=TQString::null)
Same as getText except it provides an extra parameter to specify a TQWhatsThis text for the input wid...
Definition: kinputdialog.cpp:267
KInputDialog::getMultiLineText
static TQString getMultiLineText(const TQString &caption, const TQString &label, const TQString &value=TQString::null, bool *ok=0, TQWidget *parent=0, const char *name=0)
Static convenience function to get a multiline string from the user.
Definition: kinputdialog.cpp:293
KInputDialog::getText
static TQString getText(const TQString &caption, const TQString &label, const TQString &value=TQString::null, bool *ok=0, TQWidget *parent=0, const char *name=0, TQValidator *validator=0, const TQString &mask=TQString::null)
Static convenience function to get a string from the user.
Definition: kinputdialog.cpp:259
KIntSpinBox
A TQSpinBox with support for arbitrary base numbers.
Definition: knuminput.h:708
KLineEdit
An enhanced TQLineEdit widget for inputting text.
Definition: klineedit.h:146
KStdGuiItem
Provides a set of standardized KGuiItems.
Definition: kstdguiitem.h:38
KTextEdit
A KDE'ified QTextEdit.
Definition: ktextedit.h:44
TDEListBox
A variant of TQListBox that honors KDE's system-wide settings.
Definition: tdelistbox.h:41
KStdAction::clear
TDEAction * clear(const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name)
Clear the content of the focus widget.
Definition: kstdaction.cpp:176
TDEStdAccel::name
TQString name(StdAccel id)

tdeui

Skip menu "tdeui"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdeui

Skip menu "tdeui"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeui by doxygen 1.9.4
This website is maintained by Timothy Pearson.