You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
195 lines
5.6 KiB
195 lines
5.6 KiB
15 years ago
|
/* This file is part of the KDE libraries
|
||
|
Copyright (C) 1999 Preston Brown <pbrown@kde.org>
|
||
|
|
||
|
This library is free software; you can redistribute it and/or
|
||
|
modify it under the terms of the GNU Library General Public
|
||
|
License as published by the Free Software Foundation; either
|
||
|
version 2 of the License, or (at your option) any later version.
|
||
|
|
||
|
This library is distributed in the hope that it will be useful,
|
||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
Library General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU Library General Public License
|
||
|
along with this library; see the file COPYING.LIB. If not, write to
|
||
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
#include <config.h>
|
||
|
|
||
15 years ago
|
#include <tqvalidator.h>
|
||
|
#include <tqpushbutton.h>
|
||
|
#include <tqlineedit.h>
|
||
|
#include <tqlabel.h>
|
||
|
#include <tqlayout.h>
|
||
|
#undef Unsorted // Required for --enable-final (tqdir.h)
|
||
|
#include <tqfiledialog.h>
|
||
15 years ago
|
|
||
|
#include <kbuttonbox.h>
|
||
|
#include <klocale.h>
|
||
|
#include <kapplication.h>
|
||
|
#include <klineedit.h>
|
||
|
#include <kstdguiitem.h>
|
||
|
|
||
|
#include "klineeditdlg.h"
|
||
|
|
||
15 years ago
|
KLineEditDlg::KLineEditDlg( const TQString&_text, const TQString& _value,
|
||
|
TQWidget *parent )
|
||
|
: KDialogBase( Plain, TQString::null, Ok|Cancel|User1, Ok, parent, 0L, true,
|
||
15 years ago
|
true, KStdGuiItem::clear() )
|
||
|
{
|
||
15 years ago
|
TQVBoxLayout *topLayout = new TQVBoxLayout( plainPage(), 0, spacingHint() );
|
||
|
TQLabel *label = new TQLabel(_text, plainPage() );
|
||
15 years ago
|
topLayout->addWidget( label, 1 );
|
||
|
|
||
|
edit = new KLineEdit( plainPage(), 0L );
|
||
14 years ago
|
edit->setMinimumWidth(edit->tqsizeHint().width() * 3);
|
||
15 years ago
|
label->setBuddy(edit); // please "scheck" style
|
||
15 years ago
|
// connect( edit, TQT_SIGNAL(returnPressed()), TQT_SLOT(accept()) );
|
||
|
connect( edit, TQT_SIGNAL(textChanged(const TQString&)),
|
||
|
TQT_SLOT(slotTextChanged(const TQString&)) );
|
||
15 years ago
|
topLayout->addWidget( edit, 1 );
|
||
|
|
||
15 years ago
|
connect( this, TQT_SIGNAL(user1Clicked()), this, TQT_SLOT(slotClear()) );
|
||
15 years ago
|
edit->setText( _value );
|
||
|
if ( _value.isEmpty() )
|
||
|
{
|
||
|
enableButtonOK( false );
|
||
|
enableButton(KDialogBase::User1, false);
|
||
|
}
|
||
|
edit->setSelection(0, edit->text().length());
|
||
|
edit->setFocus();
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
#if 0
|
||
15 years ago
|
KLineEditDlg::KLineEditDlg( const TQString&_text, const TQString& _value,
|
||
|
TQWidget *parent, bool _file_mode )
|
||
|
: TQDialog( parent, 0L, true )
|
||
15 years ago
|
{
|
||
14 years ago
|
TQGridLayout *layout = new TQGridLayout(this, 4, 3, 10);
|
||
15 years ago
|
|
||
15 years ago
|
TQLabel *label = new TQLabel(_text, this);
|
||
14 years ago
|
layout->addWidget(label, 0, 0, AlignLeft);
|
||
15 years ago
|
|
||
|
edit = new KLineEdit( this, 0L );
|
||
14 years ago
|
edit->setMinimumWidth(edit->tqsizeHint().width() * 3);
|
||
15 years ago
|
connect( edit, TQT_SIGNAL(returnPressed()), TQT_SLOT(accept()) );
|
||
15 years ago
|
|
||
|
if ( _file_mode ) {
|
||
|
completion = new KURLCompletion();
|
||
|
edit->setCompletionObject( completion );
|
||
|
edit->setAutoDeleteCompletionObject( true );
|
||
|
} else
|
||
|
completion = 0L;
|
||
|
|
||
14 years ago
|
layout->addMultiCellWidget(edit, 1, 1, 0, _file_mode ? 1 : 2);
|
||
|
layout->setColStretch(1, 1);
|
||
15 years ago
|
|
||
|
if (_file_mode) {
|
||
15 years ago
|
TQPushButton *browse = new TQPushButton(i18n("&Browse..."), this);
|
||
14 years ago
|
layout->addWidget(browse, 1, 2, AlignCenter);
|
||
15 years ago
|
connect(browse, TQT_SIGNAL(clicked()),
|
||
|
TQT_SLOT(slotBrowse()));
|
||
15 years ago
|
}
|
||
|
|
||
15 years ago
|
TQFrame *hLine = new TQFrame(this);
|
||
|
hLine->setFrameStyle(TQFrame::Sunken|TQFrame::HLine);
|
||
14 years ago
|
layout->addMultiCellWidget(hLine, 2, 2, 0, 2);
|
||
15 years ago
|
|
||
|
KButtonBox *bBox = new KButtonBox(this);
|
||
14 years ago
|
layout->addMultiCellWidget(bBox, 3, 3, 0, 2);
|
||
15 years ago
|
|
||
15 years ago
|
TQPushButton *ok = bBox->addButton(KStdGuiItem::ok());
|
||
15 years ago
|
ok->setDefault(true);
|
||
15 years ago
|
connect( ok, TQT_SIGNAL(clicked()), TQT_SLOT(accept()));
|
||
15 years ago
|
|
||
|
bBox->addStretch(1);
|
||
|
|
||
15 years ago
|
TQPushButton *clear = bBox->addButton(KStdGuiItem::clear());
|
||
|
connect( clear, TQT_SIGNAL(clicked()), TQT_SLOT(slotClear()));
|
||
15 years ago
|
|
||
|
bBox->addStretch(1);
|
||
|
|
||
15 years ago
|
TQPushButton *cancel = bBox->addButton(KStdGuiItem::cancel());
|
||
|
connect( cancel, TQT_SIGNAL(clicked()), TQT_SLOT(reject()));
|
||
15 years ago
|
|
||
14 years ago
|
bBox->layout();
|
||
15 years ago
|
|
||
14 years ago
|
layout->activate();
|
||
15 years ago
|
|
||
|
edit->setText( _value );
|
||
|
edit->setSelection(0, edit->text().length());
|
||
|
edit->setFocus();
|
||
|
}
|
||
|
#endif
|
||
|
|
||
|
|
||
|
KLineEditDlg::~KLineEditDlg()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
void KLineEditDlg::slotClear()
|
||
|
{
|
||
15 years ago
|
edit->setText(TQString::null);
|
||
15 years ago
|
}
|
||
|
|
||
15 years ago
|
void KLineEditDlg::slotTextChanged(const TQString &text)
|
||
15 years ago
|
{
|
||
|
bool on;
|
||
|
if ( edit->validator() ) {
|
||
15 years ago
|
TQString str = edit->text();
|
||
15 years ago
|
int index = edit->cursorPosition();
|
||
|
on = ( edit->validator()->validate( str, index )
|
||
15 years ago
|
== TQValidator::Acceptable );
|
||
15 years ago
|
} else {
|
||
|
on = !text.isEmpty();
|
||
|
}
|
||
|
enableButtonOK( on );
|
||
|
enableButton(KDialogBase::User1, text.length());
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString KLineEditDlg::text() const
|
||
15 years ago
|
{
|
||
|
return edit->text();
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString KLineEditDlg::getText(const TQString &_text, const TQString& _value,
|
||
|
bool *ok, TQWidget *parent, TQValidator *_validator )
|
||
15 years ago
|
{
|
||
|
KLineEditDlg dlg(_text, _value, parent );
|
||
|
dlg.lineEdit()->setValidator( _validator );
|
||
|
dlg.slotTextChanged( _value ); // trigger validation
|
||
|
|
||
15 years ago
|
bool ok_ = dlg.exec() == TQDialog::Accepted;
|
||
15 years ago
|
if ( ok )
|
||
|
*ok = ok_;
|
||
|
if ( ok_ )
|
||
|
return dlg.text();
|
||
15 years ago
|
return TQString::null;
|
||
15 years ago
|
}
|
||
|
|
||
15 years ago
|
TQString KLineEditDlg::getText(const TQString &_caption, const TQString &_text,
|
||
|
const TQString& _value,
|
||
|
bool *ok, TQWidget *parent, TQValidator *_validator )
|
||
15 years ago
|
{
|
||
|
KLineEditDlg dlg( _text, _value, parent );
|
||
|
dlg.setCaption( _caption );
|
||
|
dlg.lineEdit()->setValidator( _validator );
|
||
|
dlg.slotTextChanged( _value ); // trigger validation
|
||
|
|
||
15 years ago
|
bool ok_ = dlg.exec() == TQDialog::Accepted;
|
||
15 years ago
|
if ( ok )
|
||
|
*ok = ok_;
|
||
|
if ( ok_ )
|
||
|
return dlg.text();
|
||
15 years ago
|
return TQString::null;
|
||
15 years ago
|
}
|
||
|
|
||
|
void KLineEditDlg::virtual_hook( int id, void* data )
|
||
|
{ KDialogBase::virtual_hook( id, data ); }
|
||
|
|
||
|
#include "klineeditdlg.moc"
|