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.
82 lines
2.1 KiB
82 lines
2.1 KiB
15 years ago
|
/*
|
||
|
*
|
||
|
*
|
||
|
* Implementation of KRestrictedLine
|
||
|
*
|
||
|
* Copyright (C) 1997 Michael Wiedmann, <mw@miwie.in-berlin.de>
|
||
|
*
|
||
|
* 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; if not, write to the Free
|
||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||
|
*
|
||
|
*/
|
||
|
|
||
15 years ago
|
#include <tqkeycode.h>
|
||
15 years ago
|
|
||
|
#include "krestrictedline.h"
|
||
|
|
||
15 years ago
|
KRestrictedLine::KRestrictedLine( TQWidget *parent,
|
||
15 years ago
|
const char *name,
|
||
15 years ago
|
const TQString& valid )
|
||
15 years ago
|
: KLineEdit( parent, name )
|
||
|
{
|
||
|
qsValidChars = valid;
|
||
|
}
|
||
|
|
||
|
KRestrictedLine::~KRestrictedLine()
|
||
|
{
|
||
|
;
|
||
|
}
|
||
|
|
||
|
|
||
15 years ago
|
void KRestrictedLine::keyPressEvent( TQKeyEvent *e )
|
||
15 years ago
|
{
|
||
15 years ago
|
// let TQLineEdit process "special" keys and return/enter
|
||
15 years ago
|
// so that we still can use the default key binding
|
||
|
if (e->key() == Key_Enter || e->key() == Key_Return || e->key() == Key_Delete || e->ascii() < 32)
|
||
|
{
|
||
15 years ago
|
TQLineEdit::keyPressEvent(e);
|
||
15 years ago
|
return;
|
||
|
}
|
||
|
|
||
|
// do we have a list of valid chars &&
|
||
|
// is the pressed key in the list of valid chars?
|
||
14 years ago
|
if (!qsValidChars.isEmpty() && !qsValidChars.contains(e->ascii()))
|
||
15 years ago
|
{
|
||
|
// invalid char, emit signal and return
|
||
|
emit (invalidChar(e->key()));
|
||
|
return;
|
||
|
}
|
||
|
else
|
||
15 years ago
|
// valid char: let TQLineEdit process this key as usual
|
||
|
TQLineEdit::keyPressEvent(e);
|
||
15 years ago
|
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
|
||
15 years ago
|
void KRestrictedLine::setValidChars( const TQString& valid)
|
||
15 years ago
|
{
|
||
|
qsValidChars = valid;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString KRestrictedLine::validChars() const
|
||
15 years ago
|
{
|
||
|
return qsValidChars;
|
||
|
}
|
||
|
|
||
|
void KRestrictedLine::virtual_hook( int id, void* data )
|
||
|
{ KLineEdit::virtual_hook( id, data ); }
|
||
|
|
||
|
#include "krestrictedline.moc"
|