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

kdeui

  • kdeui
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 <klistbox.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  KListBox *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 KListBox( 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 KListBox( 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 KListBox *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"
470 
471 /* vim: set ai et sw=2 ts=2
472 */

kdeui

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

kdeui

Skip menu "kdeui"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for kdeui by doxygen 1.8.1.2
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |