KDEUI
krestrictedline.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "krestrictedline.h"
00025
00026 #include <QtCore/QCOORD>
00027 #include <QtGui/QKeyEvent>
00028
00029 class KRestrictedLinePrivate
00030 {
00031 public:
00033 QString qsValidChars;
00034 };
00035
00036 KRestrictedLine::KRestrictedLine( QWidget *parent )
00037 : KLineEdit( parent )
00038 , d( new KRestrictedLinePrivate )
00039 {
00040 }
00041
00042 KRestrictedLine::~KRestrictedLine()
00043 {
00044 delete d;
00045 }
00046
00047
00048 void KRestrictedLine::keyPressEvent( QKeyEvent *e )
00049 {
00050
00051
00052 if (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return || e->key() == Qt::Key_Delete
00053 || e->key() == Qt::Key_Backspace || (e->modifiers() & (Qt::ControlModifier | Qt::AltModifier
00054 | Qt::MetaModifier | Qt::GroupSwitchModifier)))
00055 {
00056 KLineEdit::keyPressEvent(e);
00057 return;
00058 }
00059
00060
00061
00062 if (!d->qsValidChars.isEmpty() && !d->qsValidChars.contains(e->text()))
00063 {
00064
00065 emit (invalidChar(e->key()));
00066 return;
00067 }
00068 else
00069
00070 KLineEdit::keyPressEvent(e);
00071
00072 return;
00073 }
00074
00075
00076 void KRestrictedLine::setValidChars( const QString& valid)
00077 {
00078 d->qsValidChars = valid;
00079 }
00080
00081 QString KRestrictedLine::validChars() const
00082 {
00083 return d->qsValidChars;
00084 }
00085
00086 #include "krestrictedline.moc"