summaryrefslogtreecommitdiff
path: root/noncore/apps/checkbook/qrestrictedcombo.cpp
Unidiff
Diffstat (limited to 'noncore/apps/checkbook/qrestrictedcombo.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/checkbook/qrestrictedcombo.cpp78
1 files changed, 78 insertions, 0 deletions
diff --git a/noncore/apps/checkbook/qrestrictedcombo.cpp b/noncore/apps/checkbook/qrestrictedcombo.cpp
new file mode 100644
index 0000000..e1533f6
--- a/dev/null
+++ b/noncore/apps/checkbook/qrestrictedcombo.cpp
@@ -0,0 +1,78 @@
1/*
2 *
3 * $Id$
4 *
5 * Implementation of QRestrictedCombo
6 *
7 * Copyright (C) 1997 Michael Wiedmann, <mw@miwie.in-berlin.de>
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Library General Public License for more details.
18 *
19 * You should have received a copy of the GNU Library General Public
20 * License along with this library; if not, write to the Free
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 *
23 */
24
25#include <qkeycode.h>
26
27#include "qrestrictedcombo.h"
28
29QRestrictedCombo::QRestrictedCombo( QWidget *parent,
30 const char *name,
31 const QString& valid )
32 : QComboBox( parent, name )
33{
34 qsValidChars = valid;
35}
36
37QRestrictedCombo::~QRestrictedCombo()
38{
39 ;
40}
41
42
43void QRestrictedCombo::keyPressEvent( QKeyEvent *e )
44{
45 // let QLineEdit process "special" keys and return/enter
46 // so that we still can use the default key binding
47 if (e->key() == Key_Enter || e->key() == Key_Return || e->key() == Key_Delete || e->ascii() < 32)
48 {
49 QComboBox::keyPressEvent(e);
50 return;
51 }
52
53 // do we have a list of valid chars &&
54 // is the pressed key in the list of valid chars?
55 if (!qsValidChars.isEmpty() && !qsValidChars.contains(e->ascii()))
56 {
57 // invalid char, emit signal and return
58 emit (invalidChar(e->key()));
59 return;
60 }
61 else
62 // valid char: let QLineEdit process this key as usual
63 QComboBox::keyPressEvent(e);
64
65 return;
66}
67
68
69void QRestrictedCombo::setValidChars( const QString& valid)
70{
71 qsValidChars = valid;
72}
73
74QString QRestrictedCombo::validChars() const
75{
76 return qsValidChars;
77}
78