• 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 #ifdef USE_QT4
21 #undef Status
22 #endif // USE_QT4
23 
24 #include <tqlayout.h>
25 #include <tqlabel.h>
26 #include <tqvalidator.h>
27 #include <tqwhatsthis.h>
28 
29 #include <klineedit.h>
30 #include <knuminput.h>
31 #include <kcombobox.h>
32 #include <tdelistbox.h>
33 #include <ktextedit.h>
34 
35 #include "kinputdialog.h"
36 
37 class KInputDialogPrivate
38 {
39  public:
40  KInputDialogPrivate();
41 
42  TQLabel *m_label;
43  KLineEdit *m_lineEdit;
44  KIntSpinBox *m_intSpinBox;
45  KDoubleSpinBox *m_doubleSpinBox;
46  KComboBox *m_comboBox;
47  TDEListBox *m_listBox;
48  KTextEdit *m_textEdit;
49 };
50 
51 KInputDialogPrivate::KInputDialogPrivate()
52  : m_label( 0L ), m_lineEdit( 0L ), m_intSpinBox( 0L ),
53  m_doubleSpinBox( 0L ), m_comboBox( 0L )
54 {
55 }
56 
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,
61  KStdGuiItem::clear() ),
62  d( new KInputDialogPrivate() )
63 {
64  TQFrame *frame = makeMainWidget();
65  TQVBoxLayout *layout = new TQVBoxLayout( frame, 0, spacingHint() );
66 
67  d->m_label = new TQLabel( label, frame );
68  layout->addWidget( d->m_label );
69 
70  d->m_lineEdit = new KLineEdit( value, frame );
71  layout->addWidget( d->m_lineEdit );
72 
73  d->m_lineEdit->setFocus();
74  d->m_label->setBuddy( d->m_lineEdit );
75 
76  layout->addStretch();
77 
78  if ( validator )
79  d->m_lineEdit->setValidator( validator );
80 
81  if ( !mask.isEmpty() )
82  d->m_lineEdit->setInputMask( mask );
83 
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() ) );
87 
88  slotEditTextChanged( value );
89  setMinimumWidth( 350 );
90 }
91 
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,
95  KStdGuiItem::clear() ),
96  d( new KInputDialogPrivate() )
97 {
98  TQFrame *frame = makeMainWidget();
99  TQVBoxLayout *layout = new TQVBoxLayout( frame, 0, spacingHint() );
100 
101  d->m_label = new TQLabel( label, frame );
102  layout->addWidget( d->m_label );
103 
104  d->m_textEdit = new KTextEdit( frame );
105  d->m_textEdit->setTextFormat( PlainText );
106  d->m_textEdit->setText( value );
107  layout->addWidget( d->m_textEdit, 10 );
108 
109  d->m_textEdit->setFocus();
110  d->m_label->setBuddy( d->m_textEdit );
111 
112  connect( this, TQT_SIGNAL( user1Clicked() ), d->m_textEdit, TQT_SLOT( clear() ) );
113 
114  setMinimumWidth( 400 );
115 }
116 
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() )
122 {
123  TQFrame *frame = makeMainWidget();
124  TQVBoxLayout *layout = new TQVBoxLayout( frame, 0, spacingHint() );
125 
126  d->m_label = new TQLabel( label, frame );
127  layout->addWidget( d->m_label );
128 
129  d->m_intSpinBox = new KIntSpinBox( minValue, maxValue, step, value,
130  base, frame );
131  layout->addWidget( d->m_intSpinBox );
132 
133  layout->addStretch();
134 
135  d->m_intSpinBox->setFocus();
136  setMinimumWidth( 300 );
137 }
138 
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() )
144 {
145  TQFrame *frame = makeMainWidget();
146  TQVBoxLayout *layout = new TQVBoxLayout( frame, 0, spacingHint() );
147 
148  d->m_label = new TQLabel( label, frame );
149  layout->addWidget( d->m_label );
150 
151  d->m_doubleSpinBox = new KDoubleSpinBox( minValue, maxValue, step, value,
152  decimals, frame );
153  layout->addWidget( d->m_doubleSpinBox );
154 
155  layout->addStretch();
156 
157  d->m_doubleSpinBox->setFocus();
158  setMinimumWidth( 300 );
159 }
160 
161 KInputDialog::KInputDialog( const TQString &caption, const TQString &label,
162  const TQStringList &list, int current, bool editable, TQWidget *parent,
163  const char *name )
164  : KDialogBase( parent, name, true, caption, Ok|Cancel|User1, Ok, true,
165  KStdGuiItem::clear() ),
166  d( new KInputDialogPrivate() )
167 {
168  showButton( User1, editable );
169 
170  TQFrame *frame = makeMainWidget();
171  TQVBoxLayout *layout = new TQVBoxLayout( frame, 0, spacingHint() );
172 
173  d->m_label = new TQLabel( label, frame );
174  layout->addWidget( d->m_label );
175 
176  if ( editable )
177  {
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 );
182 
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();
189  } else {
190  d->m_listBox = new TDEListBox( frame );
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() ) );
199 
200  d->m_listBox->setFocus();
201  }
202 
203  layout->addStretch();
204 
205  setMinimumWidth( 320 );
206 }
207 
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() )
213 {
214  TQFrame *frame = makeMainWidget();
215  TQVBoxLayout *layout = new TQVBoxLayout( frame, 0, spacingHint() );
216 
217  d->m_label = new TQLabel( label, frame );
218  layout->addWidget( d->m_label );
219 
220  d->m_listBox = new TDEListBox( frame );
221  d->m_listBox->insertStringList( list );
222  layout->addWidget( d->m_listBox );
223 
224  TQListBoxItem *item;
225 
226  if ( multiple )
227  {
228  d->m_listBox->setSelectionMode( TQListBox::Extended );
229 
230  for ( TQStringList::ConstIterator it=select.begin(); it!=select.end(); ++it )
231  {
232  item = d->m_listBox->findItem( *it, CaseSensitive|ExactMatch );
233  if ( item )
234  d->m_listBox->setSelected( item, true );
235  }
236  }
237  else
238  {
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() ) );
243 
244  TQString text = select.first();
245  item = d->m_listBox->findItem( text, CaseSensitive|ExactMatch );
246  if ( item )
247  d->m_listBox->setSelected( item, true );
248  }
249 
250  d->m_listBox->ensureCurrentVisible();
251  d->m_listBox->setFocus();
252 
253  layout->addStretch();
254 
255  setMinimumWidth( 320 );
256 }
257 
258 KInputDialog::~KInputDialog()
259 {
260  delete d;
261 }
262 
263 TQString KInputDialog::getText( const TQString &caption, const TQString &label,
264  const TQString &value, bool *ok, TQWidget *parent, const char *name,
265  TQValidator *validator, const TQString &mask )
266 {
267  return text( caption, label, value, ok, parent, name, validator, mask,
268  TQString::null );
269 }
270 
271 TQString KInputDialog::text( const TQString &caption,
272  const TQString &label, const TQString &value, bool *ok, TQWidget *parent,
273  const char *name, TQValidator *validator, const TQString &mask,
274  const TQString &whatsThis )
275 {
276  KInputDialog dlg( caption, label, value, parent, name, validator, mask );
277 
278  if( !whatsThis.isEmpty() )
279  TQWhatsThis::add( dlg.lineEdit(), whatsThis );
280 
281  bool _ok = ( dlg.exec() == Accepted );
282 
283  if ( ok )
284  *ok = _ok;
285 
286  TQString result;
287  if ( _ok )
288  result = dlg.lineEdit()->text();
289 
290  // A validator may explicitly allow leading and trailing whitespace
291  if ( !validator )
292  result = result.stripWhiteSpace();
293 
294  return result;
295 }
296 
297 TQString KInputDialog::getMultiLineText( const TQString &caption,
298  const TQString &label, const TQString &value, bool *ok,
299  TQWidget *parent, const char *name )
300 {
301  KInputDialog dlg( caption, label, value, parent, name );
302 
303  bool _ok = ( dlg.exec() == Accepted );
304 
305  if ( ok )
306  *ok = _ok;
307 
308  TQString result;
309  if ( _ok )
310  result = dlg.textEdit()->text();
311 
312  return result;
313 }
314 
315 int KInputDialog::getInteger( const TQString &caption, const TQString &label,
316  int value, int minValue, int maxValue, int step, int base, bool *ok,
317  TQWidget *parent, const char *name )
318 {
319  KInputDialog dlg( caption, label, value, minValue,
320  maxValue, step, base, parent, name );
321 
322  bool _ok = ( dlg.exec() == Accepted );
323 
324  if ( ok )
325  *ok = _ok;
326 
327  int result=0;
328  if ( _ok )
329  result = dlg.intSpinBox()->value();
330 
331  return result;
332 }
333 
334 int KInputDialog::getInteger( const TQString &caption, const TQString &label,
335  int value, int minValue, int maxValue, int step, bool *ok,
336  TQWidget *parent, const char *name )
337 {
338  return getInteger( caption, label, value, minValue, maxValue, step,
339  10, ok, parent, name );
340 }
341 
342 double KInputDialog::getDouble( const TQString &caption, const TQString &label,
343  double value, double minValue, double maxValue, double step, int decimals,
344  bool *ok, TQWidget *parent, const char *name )
345 {
346  KInputDialog dlg( caption, label, value, minValue,
347  maxValue, step, decimals, parent, name );
348 
349  bool _ok = ( dlg.exec() == Accepted );
350 
351  if ( ok )
352  *ok = _ok;
353 
354  double result=0;
355  if ( _ok )
356  result = dlg.doubleSpinBox()->value();
357 
358  return result;
359 }
360 
361 double KInputDialog::getDouble( const TQString &caption, const TQString &label,
362  double value, double minValue, double maxValue, int decimals,
363  bool *ok, TQWidget *parent, const char *name )
364 {
365  return getDouble( caption, label, value, minValue, maxValue, 0.1, decimals,
366  ok, parent, name );
367 }
368 
369 TQString KInputDialog::getItem( const TQString &caption, const TQString &label,
370  const TQStringList &list, int current, bool editable, bool *ok,
371  TQWidget *parent, const char *name )
372 {
373  KInputDialog dlg( caption, label, list, current,
374  editable, parent, name );
375  if ( !editable)
376  {
377  connect( dlg.listBox(), TQT_SIGNAL(doubleClicked ( TQListBoxItem *)), &dlg, TQT_SLOT( slotOk()));
378  }
379  bool _ok = ( dlg.exec() == Accepted );
380 
381  if ( ok )
382  *ok = _ok;
383 
384  TQString result;
385  if ( _ok )
386  if ( editable )
387  result = dlg.comboBox()->currentText();
388  else
389  result = dlg.listBox()->currentText();
390 
391  return result;
392 }
393 
394 TQStringList KInputDialog::getItemList( const TQString &caption,
395  const TQString &label, const TQStringList &list, const TQStringList &select,
396  bool multiple, bool *ok, TQWidget *parent, const char *name )
397 {
398  KInputDialog dlg( caption, label, list, select,
399  multiple, parent, name );
400 
401  bool _ok = ( dlg.exec() == Accepted );
402 
403  if ( ok )
404  *ok = _ok;
405 
406  TQStringList result;
407  if ( _ok )
408  {
409  for (const TQListBoxItem* i = dlg.listBox()->firstItem(); i != 0; i = i->next() )
410  if ( i->isSelected() )
411  result.append( i->text() );
412  }
413 
414  return result;
415 }
416 
417 void KInputDialog::slotEditTextChanged( const TQString &text )
418 {
419  bool on;
420  if ( lineEdit()->validator() ) {
421  TQString str = lineEdit()->text();
422  int index = lineEdit()->cursorPosition();
423  on = ( lineEdit()->validator()->validate( str, index )
424  == TQValidator::Acceptable );
425  } else {
426  on = !text.stripWhiteSpace().isEmpty();
427  }
428 
429  enableButton( Ok, on );
430  enableButton( User1, !text.isEmpty() );
431 }
432 
433 void KInputDialog::slotUpdateButtons( const TQString &text )
434 {
435  enableButton( Ok, !text.isEmpty() );
436  enableButton( User1, !text.isEmpty() );
437 }
438 
439 KLineEdit *KInputDialog::lineEdit() const
440 {
441  return d->m_lineEdit;
442 }
443 
444 KIntSpinBox *KInputDialog::intSpinBox() const
445 {
446  return d->m_intSpinBox;
447 }
448 
449 KDoubleSpinBox *KInputDialog::doubleSpinBox() const
450 {
451  return d->m_doubleSpinBox;
452 }
453 
454 KComboBox *KInputDialog::comboBox() const
455 {
456  return d->m_comboBox;
457 }
458 
459 TDEListBox *KInputDialog::listBox() const
460 {
461  return d->m_listBox;
462 }
463 
464 KTextEdit *KInputDialog::textEdit() const
465 {
466  return d->m_textEdit;
467 }
468 
469 #include "kinputdialog.moc"
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:369
KDialogBase::slotOk
virtual void slotOk()
Activated when the Ok button has been clicked.
Definition: kdialogbase.cpp:1164
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:271
KLineEdit::KLineEdit
KLineEdit(const TQString &string, TQWidget *parent, const char *name=0)
Constructs a KLineEdit object with a default text, a parent, and a name.
Definition: klineedit.cpp:106
KDialogBase::Ok
Show Ok button.
Definition: kdialogbase.h:201
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
KDoubleSpinBox
A spin box for fractional numbers.
Definition: knuminput.h:838
KDialogBase::enableButton
void enableButton(ButtonCode id, bool state)
Enable or disable (gray out) a general action button.
Definition: kdialogbase.cpp:838
KLineEdit::returnPressed
void returnPressed(const TQString &)
Emitted when the user presses the return key.
KDialogBase
A dialog base class with standard buttons and predefined layouts.
Definition: kdialogbase.h:191
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:297
KDialogBase::User1
Show User defined button 1.
Definition: kdialogbase.h:206
KDoubleSpinBox::value
double value() const
Definition: knuminput.cpp:1102
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:263
TDEIconViewSearchLine::clear
void clear()
Clear line edit and empty hiddenItems, returning elements to iconView.
Definition: kiconviewsearchline.cpp:123
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:315
KLineEdit
An enhanced TQLineEdit widget for inputting text.
Definition: klineedit.h:145
KIntSpinBox
A TQSpinBox with support for arbitrary base numbers.
Definition: knuminput.h:707
CaseSensitive
KComboBox
An enhanced combo box.
Definition: kcombobox.h:151
KInputDialog
The KInputDialog class provides a simple dialog to get a single value from the user.
Definition: kinputdialog.h:48
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:342
KStdGuiItem
Provides a set of standardized KGuiItems.
Definition: kstdguiitem.h:37
TDEListBox
A variant of TQListBox that honors KDE's system-wide settings.
Definition: tdelistbox.h:40
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:394
KTextEdit
A KDE'ified QTextEdit.
Definition: ktextedit.h:43

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
  •     tdecore
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  • tdeioslave
  •   http
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeui by doxygen 1.8.8
This website is maintained by Timothy Pearson.