Diffstat (limited to 'core/pim/addressbook/namelineedit.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | core/pim/addressbook/namelineedit.cpp | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/core/pim/addressbook/namelineedit.cpp b/core/pim/addressbook/namelineedit.cpp new file mode 100644 index 0000000..ba16e2c --- a/dev/null +++ b/core/pim/addressbook/namelineedit.cpp | |||
@@ -0,0 +1,55 @@ | |||
1 | #include "namelineedit.h" | ||
2 | |||
3 | namespace ABOOK { | ||
4 | NameLineEdit::NameLineEdit( QWidget* parent, const char* name ) | ||
5 | : QLineEdit( parent, name ), m_prevSpace( true ) { | ||
6 | } | ||
7 | |||
8 | NameLineEdit::NameLineEdit( const QString& str, QWidget* par, | ||
9 | const char* name ) | ||
10 | : QLineEdit( str, par, name ),m_prevSpace( true ) { | ||
11 | } | ||
12 | |||
13 | NameLineEdit::~NameLineEdit() { | ||
14 | } | ||
15 | |||
16 | void NameLineEdit::keyPressEvent( QKeyEvent* ev ) { | ||
17 | QString t = ev->text(); | ||
18 | int key = ev->key(); | ||
19 | int ascii = ev->ascii(); | ||
20 | |||
21 | // ### FIXME with composed events | ||
22 | if ( !t.isEmpty() && ( !ev->ascii() || ev->ascii()>=32 ) && | ||
23 | key != Key_Delete && key != Key_Backspace && | ||
24 | key != Key_Return && key != Key_Enter ) { | ||
25 | qWarning( "str " + ev->text() + " %d", m_prevSpace ); | ||
26 | |||
27 | if ( m_prevSpace ) { | ||
28 | t = t.upper(); | ||
29 | m_prevSpace = false; | ||
30 | } | ||
31 | if ( key == Key_Space ) | ||
32 | m_prevSpace = true; | ||
33 | |||
34 | |||
35 | QKeyEvent nEv(ev->type(), key, ascii, ev->state(), | ||
36 | t, ev->isAutoRepeat(), ev->count() ); | ||
37 | QLineEdit::keyPressEvent( &nEv ); | ||
38 | if ( !nEv.isAccepted() ) | ||
39 | ev->ignore(); | ||
40 | }else { | ||
41 | QLineEdit::keyPressEvent( ev ); | ||
42 | /* if key was a backspace lets see if we should | ||
43 | * capitalize the next letter | ||
44 | */ | ||
45 | if ( key == Key_Backspace ) { | ||
46 | QString te = text(); | ||
47 | /* if string is empty capitalize the first letter */ | ||
48 | /* else see if we're at the end of the string */ | ||
49 | if ( te.isEmpty() || cursorPosition() == te.length() ) | ||
50 | m_prevSpace = true; | ||
51 | } | ||
52 | } | ||
53 | } | ||
54 | |||
55 | } | ||