krestrictedline.cpp Source File (kdeui Library)

| # kdeui Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Source Files

# krestrictedline.cpp

    00001 /*
    00002  *
    00003  * $Id: krestrictedline.cpp,v 1.11 2002/03/04 00:51:51 lunakl Exp $
    00004  *
    00005  * Implementation of KRestrictedLine
    00006  *
    00007  * Copyright (C) 1997 Michael Wiedmann, <mw@miwie.in-berlin.de>
    00008  *
    00009  * This library is free software; you can redistribute it and/or
    00010  * modify it under the terms of the GNU Library General Public
    00011  * License as published by the Free Software Foundation; either
    00012  * version 2 of the License, or (at your option) any later version.
    00013  *
    00014  * This library is distributed in the hope that it will be useful,
    00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00017  * Library General Public License for more details.
    00018  *
    00019  * You should have received a copy of the GNU Library General Public
    00020  * License along with this library; if not, write to the Free
    00021  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    00022  *
    00023  */
    00024
    00025 #include <qkeycode.h>
    00026
    00027 #include "krestrictedline.h"
    00028
    00029 KRestrictedLine::KRestrictedLine( QWidget *parent,
    00030                                   const char *name,
    00031                                   const QString& valid )
    00032   : KLineEdit( parent, name )
    00033 {
    00034     qsValidChars = valid;
    00035 }
    00036
    00037 KRestrictedLine::~KRestrictedLine()
    00038 {
    00039   ;
    00040 }
    00041
    00042
    00043 void KRestrictedLine::keyPressEvent( QKeyEvent *e )
    00044 {
    00045   // let QLineEdit process "special" keys and return/enter
    00046   // so that we still can use the default key binding
    00047   if (e->key() == Key_Enter || e->key() == Key_Return || e->key() == Key_Delete || e->ascii() < 32)
    00048     {
    00049       QLineEdit::keyPressEvent(e);
    00050       return;
    00051     }
    00052
    00053   // do we have a list of valid chars &&
    00054   // is the pressed key in the list of valid chars?
    00055   if (!qsValidChars.isEmpty() && !qsValidChars.contains(e->ascii()))
    00056     {
    00057       // invalid char, emit signal and return
    00058       emit (invalidChar(e->key()));
    00059       return;
    00060     }
    00061   else
    00062         // valid char: let QLineEdit process this key as usual
    00063         QLineEdit::keyPressEvent(e);
    00064
    00065   return;
    00066 }
    00067
    00068
    00069 void KRestrictedLine::setValidChars( const QString& valid)
    00070 {
    00071   qsValidChars = valid;
    00072 }
    00073
    00074 QString KRestrictedLine::validChars() const
    00075 {
    00076   return qsValidChars;
    00077 }
    00078
    00079 void KRestrictedLine::virtual_hook( int id, void* data )
    00080 { KLineEdit::virtual_hook( id, data ); }
    00081
    00082 #include "krestrictedline.moc"

This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 12:57:35 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001