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

kdeui

  • kdeui
klineeditdlg.cpp
1 /* This file is part of the KDE libraries
2  Copyright (C) 1999 Preston Brown <pbrown@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 #include <config.h>
20 
21 #include <tqvalidator.h>
22 #include <tqpushbutton.h>
23 #include <tqlineedit.h>
24 #include <tqlabel.h>
25 #include <tqlayout.h>
26 #undef Unsorted // Required for --enable-final (tqdir.h)
27 #include <tqfiledialog.h>
28 
29 #include <kbuttonbox.h>
30 #include <klocale.h>
31 #include <kapplication.h>
32 #include <klineedit.h>
33 #include <kstdguiitem.h>
34 
35 #include "klineeditdlg.h"
36 
37 KLineEditDlg::KLineEditDlg( const TQString&_text, const TQString& _value,
38  TQWidget *parent )
39  : KDialogBase( Plain, TQString::null, Ok|Cancel|User1, Ok, parent, 0L, true,
40  true, KStdGuiItem::clear() )
41 {
42  TQVBoxLayout *topLayout = new TQVBoxLayout( plainPage(), 0, spacingHint() );
43  TQLabel *label = new TQLabel(_text, plainPage() );
44  topLayout->addWidget( label, 1 );
45 
46  edit = new KLineEdit( plainPage(), 0L );
47  edit->setMinimumWidth(edit->sizeHint().width() * 3);
48  label->setBuddy(edit); // please "scheck" style
49  // connect( edit, TQT_SIGNAL(returnPressed()), TQT_SLOT(accept()) );
50  connect( edit, TQT_SIGNAL(textChanged(const TQString&)),
51  TQT_SLOT(slotTextChanged(const TQString&)) );
52  topLayout->addWidget( edit, 1 );
53 
54  connect( this, TQT_SIGNAL(user1Clicked()), this, TQT_SLOT(slotClear()) );
55  edit->setText( _value );
56  if ( _value.isEmpty() )
57  {
58  enableButtonOK( false );
59  enableButton(KDialogBase::User1, false);
60  }
61  edit->setSelection(0, edit->text().length());
62  edit->setFocus();
63 }
64 
65 
66 
67 #if 0
68 KLineEditDlg::KLineEditDlg( const TQString&_text, const TQString& _value,
69  TQWidget *parent, bool _file_mode )
70  : TQDialog( parent, 0L, true )
71 {
72  TQGridLayout *layout = new TQGridLayout(this, 4, 3, 10);
73 
74  TQLabel *label = new TQLabel(_text, this);
75  layout->addWidget(label, 0, 0, AlignLeft);
76 
77  edit = new KLineEdit( this, 0L );
78  edit->setMinimumWidth(edit->sizeHint().width() * 3);
79  connect( edit, TQT_SIGNAL(returnPressed()), TQT_SLOT(accept()) );
80 
81  if ( _file_mode ) {
82  completion = new KURLCompletion();
83  edit->setCompletionObject( completion );
84  edit->setAutoDeleteCompletionObject( true );
85  } else
86  completion = 0L;
87 
88  layout->addMultiCellWidget(edit, 1, 1, 0, _file_mode ? 1 : 2);
89  layout->setColStretch(1, 1);
90 
91  if (_file_mode) {
92  TQPushButton *browse = new TQPushButton(i18n("&Browse..."), this);
93  layout->addWidget(browse, 1, 2, AlignCenter);
94  connect(browse, TQT_SIGNAL(clicked()),
95  TQT_SLOT(slotBrowse()));
96  }
97 
98  TQFrame *hLine = new TQFrame(this);
99  hLine->setFrameStyle(TQFrame::Sunken|TQFrame::HLine);
100  layout->addMultiCellWidget(hLine, 2, 2, 0, 2);
101 
102  KButtonBox *bBox = new KButtonBox(this);
103  layout->addMultiCellWidget(bBox, 3, 3, 0, 2);
104 
105  TQPushButton *ok = bBox->addButton(KStdGuiItem::ok());
106  ok->setDefault(true);
107  connect( ok, TQT_SIGNAL(clicked()), TQT_SLOT(accept()));
108 
109  bBox->addStretch(1);
110 
111  TQPushButton *clear = bBox->addButton(KStdGuiItem::clear());
112  connect( clear, TQT_SIGNAL(clicked()), TQT_SLOT(slotClear()));
113 
114  bBox->addStretch(1);
115 
116  TQPushButton *cancel = bBox->addButton(KStdGuiItem::cancel());
117  connect( cancel, TQT_SIGNAL(clicked()), TQT_SLOT(reject()));
118 
119  bBox->layout();
120 
121  layout->activate();
122 
123  edit->setText( _value );
124  edit->setSelection(0, edit->text().length());
125  edit->setFocus();
126 }
127 #endif
128 
129 
130 KLineEditDlg::~KLineEditDlg()
131 {
132 }
133 
134 void KLineEditDlg::slotClear()
135 {
136  edit->setText(TQString::null);
137 }
138 
139 void KLineEditDlg::slotTextChanged(const TQString &text)
140 {
141  bool on;
142  if ( edit->validator() ) {
143  TQString str = edit->text();
144  int index = edit->cursorPosition();
145  on = ( edit->validator()->validate( str, index )
146  == TQValidator::Acceptable );
147  } else {
148  on = !text.isEmpty();
149  }
150  enableButtonOK( on );
151  enableButton(KDialogBase::User1, text.length());
152 }
153 
154 TQString KLineEditDlg::text() const
155 {
156  return edit->text();
157 }
158 
159 TQString KLineEditDlg::getText(const TQString &_text, const TQString& _value,
160  bool *ok, TQWidget *parent, TQValidator *_validator )
161 {
162  KLineEditDlg dlg(_text, _value, parent );
163  dlg.lineEdit()->setValidator( _validator );
164  dlg.slotTextChanged( _value ); // trigger validation
165 
166  bool ok_ = dlg.exec() == TQDialog::Accepted;
167  if ( ok )
168  *ok = ok_;
169  if ( ok_ )
170  return dlg.text();
171  return TQString::null;
172 }
173 
174 TQString KLineEditDlg::getText(const TQString &_caption, const TQString &_text,
175  const TQString& _value,
176  bool *ok, TQWidget *parent, TQValidator *_validator )
177 {
178  KLineEditDlg dlg( _text, _value, parent );
179  dlg.setCaption( _caption );
180  dlg.lineEdit()->setValidator( _validator );
181  dlg.slotTextChanged( _value ); // trigger validation
182 
183  bool ok_ = dlg.exec() == TQDialog::Accepted;
184  if ( ok )
185  *ok = ok_;
186  if ( ok_ )
187  return dlg.text();
188  return TQString::null;
189 }
190 
191 void KLineEditDlg::virtual_hook( int id, void* data )
192 { KDialogBase::virtual_hook( id, data ); }
193 
194 #include "klineeditdlg.moc"

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.3.1
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |