1/*
2 * Definition of KRestrictedLine
3 *
4 * Copyright (C) 1997 Michael Wiedmann, <mw@miwie.in-berlin.de>
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the Free
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 *
20 */
21
22#ifndef KRESTRICTEDLINE_H
23#define KRESTRICTEDLINE_H
24
25#include <klineedit.h>
26
27class KRestrictedLinePrivate;
28/**
29 * @short A line editor for restricted character sets.
30 *
31 * The KRestrictedLine widget is a variant of QLineEdit which
32 * accepts only a restricted set of characters as input.
33 * All other characters will be discarded and the signal invalidChar()
34 * will be emitted for each of them.
35 *
36 * Valid characters can be passed as a QString to the constructor
37 * or set afterwards via setValidChars().
38 * The default key bindings of QLineEdit are still in effect.
39 *
40 * This is almost like setting a QRegExpValidator on a KLineEdit;
41 * the difference is that with KRestrictedLine it can all be done in Qt designer.
42 *
43 * \image html krestrictedline.png "KDE Restricted Line Edit allowing all characters but 'o'"
44 *
45 * @author Michael Wiedmann <mw@miwie.in-berlin.de>
46 */
47class KDEUI_EXPORT KRestrictedLine : public KLineEdit
48{
49 Q_OBJECT
50 Q_PROPERTY( QString validChars READ validChars WRITE setValidChars )
51
52public:
53
54 /**
55 * Constructor
56 * @param parent pointer to the parent widget
57 */
58 explicit KRestrictedLine( QWidget* parent = 0);
59
60 /**
61 * Destructs the restricted line editor.
62 */
63 ~KRestrictedLine();
64
65 /**
66 * All characters in the string valid are treated as
67 * acceptable characters.
68 */
69 void setValidChars(const QString& valid);
70 /**
71 * @return the string of acceptable characters.
72 */
73 QString validChars() const;
74
75Q_SIGNALS:
76
77 /**
78 * Emitted when an invalid character was typed.
79 */
80 void invalidChar(int);
81
82protected:
83 void keyPressEvent( QKeyEvent *e );
84 void inputMethodEvent(QInputMethodEvent *e);
85
86private:
87 KRestrictedLinePrivate * const d;
88};
89
90#endif // KRESTRICTEDLINE_H
91