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

tdeui

  • tdeui
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 <tdelocale.h>
31 #include <tdeapplication.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"
KLineEditDlg::text
TQString text() const
Definition: klineeditdlg.cpp:154
KLineEditDlg::slotClear
void slotClear()
Clears the edit widget.
Definition: klineeditdlg.cpp:134
KButtonBox::addButton
TQPushButton * addButton(const TQString &text, bool noexpand=false)
Add a new TQPushButton.
Definition: kbuttonbox.cpp:98
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
KDialogBase::enableButtonOK
void enableButtonOK(bool state)
Enable or disable (gray out) the OK button.
Definition: kdialogbase.cpp:848
KLineEditDlg::KLineEditDlg
KLineEditDlg(const TQString &_text, const TQString &_value, TQWidget *parent) KDE_DEPRECATED
Create a dialog that asks for a single line of text.
Definition: klineeditdlg.cpp:37
KDialogBase::enableButton
void enableButton(ButtonCode id, bool state)
Enable or disable (gray out) a general action button.
Definition: kdialogbase.cpp:838
KDialogBase::cancel
void cancel()
Force closing the dialog, setting its result code to the one Esc would set.
Definition: kdialogbase.cpp:1632
KDialogBase
A dialog base class with standard buttons and predefined layouts.
Definition: kdialogbase.h:191
KButtonBox
Container widget for buttons.
Definition: kbuttonbox.h:42
KLineEditDlg::edit
KLineEdit * edit
The line edit widget.
Definition: klineeditdlg.h:119
KButtonBox::layout
void layout()
This function must be called once after all buttons have been inserted.
Definition: kbuttonbox.cpp:163
KLineEditDlg::getText
static TQString getText(const TQString &text, const TQString &value, bool *ok, TQWidget *parent, TQValidator *validator=0) KDE_DEPRECATED
Static convenience function to get a textual input from the user.
Definition: klineeditdlg.cpp:159
KDialogBase::User1
Show User defined button 1.
Definition: kdialogbase.h:206
tdelocale.h
KDialog::spacingHint
static int spacingHint()
Return the number of pixels you shall use between widgets inside a dialog according to the KDE standa...
Definition: kdialog.cpp:110
KLineEditDlg::slotTextChanged
void slotTextChanged(const TQString &)
Enables and disables the OK button depending on the state returned by the lineedit's TQValidator...
Definition: klineeditdlg.cpp:139
TDECompletionBase::setAutoDeleteCompletionObject
void setAutoDeleteCompletionObject(bool autoDelete)
KLineEditDlg::lineEdit
KLineEdit * lineEdit() const
Definition: klineeditdlg.h:71
KDialogBase::plainPage
TQFrame * plainPage()
Retrieve the empty page when the predefined layout is used in Plain mode.
Definition: kdialogbase.cpp:420
KDialogBase::user1Clicked
void user1Clicked()
The User1 button was pressed.
KLineEdit
An enhanced TQLineEdit widget for inputting text.
Definition: klineedit.h:145
KLineEditDlg
Definition: klineeditdlg.h:40
KLineEdit::setCompletionObject
virtual void setCompletionObject(TDECompletion *, bool hsig=true)
Reimplemented for internal reasons, the API is not affected.
Definition: klineedit.cpp:1272
KDialog::setCaption
virtual void setCaption(const TQString &caption)
Make a KDE compliant caption.
Definition: kdialog.cpp:122
KStdGuiItem
Provides a set of standardized KGuiItems.
Definition: kstdguiitem.h:37
KButtonBox::addStretch
void addStretch(int scale=1)
Add a stretch to the buttonbox.
Definition: kbuttonbox.cpp:154
TDEStdAccel::completion
const TDEShortcut & completion()
KLineEdit::setText
virtual void setText(const TQString &)
Re-implemented to enable text squeezing.
Definition: klineedit.cpp:310

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.