-rw-r--r-- | core/pim/addressbook/namelineedit.cpp | 37 | ||||
-rw-r--r-- | core/pim/addressbook/namelineedit.h | 3 |
2 files changed, 32 insertions, 8 deletions
diff --git a/core/pim/addressbook/namelineedit.cpp b/core/pim/addressbook/namelineedit.cpp index 81b959b..5c6c0b9 100644 --- a/core/pim/addressbook/namelineedit.cpp +++ b/core/pim/addressbook/namelineedit.cpp | |||
@@ -1,35 +1,45 @@ | |||
1 | #include "namelineedit.h" | 1 | #include "namelineedit.h" |
2 | 2 | ||
3 | /* OPIE */ | 3 | /* OPIE */ |
4 | #include <opie2/odebug.h> | 4 | #include <opie2/odebug.h> |
5 | 5 | ||
6 | #include <qpe/config.h> | ||
6 | 7 | ||
7 | namespace ABOOK { | 8 | namespace ABOOK { |
8 | NameLineEdit::NameLineEdit( QWidget* parent, const char* name ) | 9 | NameLineEdit::NameLineEdit( QWidget* parent, const char* name ) |
9 | : QLineEdit( parent, name ), m_prevSpace( true ) { | 10 | : QLineEdit( parent, name ), m_prevSpace( true ), m_disabled( false ) { |
11 | configReader(); | ||
10 | } | 12 | } |
11 | 13 | ||
12 | NameLineEdit::NameLineEdit( const QString& str, QWidget* par, | 14 | NameLineEdit::NameLineEdit( const QString& str, QWidget* par, |
13 | const char* name ) | 15 | const char* name ) |
14 | : QLineEdit( str, par, name ),m_prevSpace( true ) { | 16 | : QLineEdit( str, par, name ),m_prevSpace( true ), m_disabled( false ) { |
17 | configReader(); | ||
15 | } | 18 | } |
16 | 19 | ||
17 | NameLineEdit::~NameLineEdit() { | 20 | NameLineEdit::~NameLineEdit() { |
18 | } | 21 | } |
19 | 22 | ||
20 | void NameLineEdit::keyPressEvent( QKeyEvent* ev ) { | 23 | void NameLineEdit::keyPressEvent( QKeyEvent* ev ) { |
24 | |||
25 | // If disabled: Push everything to the mother class.. | ||
26 | if ( m_disabled ){ | ||
27 | QLineEdit::keyPressEvent( ev ); | ||
28 | return; | ||
29 | } | ||
30 | |||
21 | QString t = ev->text(); | 31 | QString t = ev->text(); |
22 | int key = ev->key(); | 32 | int key = ev->key(); |
23 | int ascii = ev->ascii(); | 33 | int ascii = ev->ascii(); |
24 | 34 | ||
25 | // ### FIXME with composed events | 35 | // ### FIXME with composed events |
26 | if ( !t.isEmpty() && ( !ev->ascii() || ev->ascii()>=32 ) && | 36 | if ( !t.isEmpty() && ( !ev->ascii() || ev->ascii()>=32 ) && |
27 | key != Key_Delete && key != Key_Backspace && | 37 | key != Key_Delete && key != Key_Backspace && |
28 | key != Key_Return && key != Key_Enter ) { | 38 | key != Key_Return && key != Key_Enter ) { |
29 | owarn << "str " << ev->text() << " " << m_prevSpace << oendl; | 39 | odebug << "str " << ev->text() << " " << m_prevSpace << oendl; |
30 | 40 | ||
31 | if ( m_prevSpace ) { | 41 | if ( m_prevSpace ) { |
32 | t = t.upper(); | 42 | t = t.upper(); |
33 | m_prevSpace = false; | 43 | m_prevSpace = false; |
34 | } | 44 | } |
35 | if ( key == Key_Space ) | 45 | if ( key == Key_Space ) |
@@ -37,23 +47,34 @@ void NameLineEdit::keyPressEvent( QKeyEvent* ev ) { | |||
37 | 47 | ||
38 | 48 | ||
39 | QKeyEvent nEv(ev->type(), key, ascii, ev->state(), | 49 | QKeyEvent nEv(ev->type(), key, ascii, ev->state(), |
40 | t, ev->isAutoRepeat(), ev->count() ); | 50 | t, ev->isAutoRepeat(), ev->count() ); |
41 | QLineEdit::keyPressEvent( &nEv ); | 51 | QLineEdit::keyPressEvent( &nEv ); |
42 | if ( !nEv.isAccepted() ) | 52 | if ( !nEv.isAccepted() ) |
43 | ev->ignore(); | 53 | ev->ignore(); |
44 | }else { | 54 | }else { |
45 | QLineEdit::keyPressEvent( ev ); | 55 | QLineEdit::keyPressEvent( ev ); |
46 | /* if key was a backspace lets see if we should | 56 | /* if key was a backspace lets see if we should |
47 | * capitalize the next letter | 57 | * capitalize the next letter |
48 | */ | 58 | */ |
49 | if ( key == Key_Backspace ) { | 59 | if ( key == Key_Backspace ) { |
50 | QString te = text(); | 60 | QString te = text(); |
51 | /* if string is empty capitalize the first letter */ | 61 | odebug << "Backspace: " << te << oendl; |
52 | /* else see if we're at the end of the string */ | 62 | /* Capitalize first letter if a char is removed and: |
53 | if ( te.isEmpty() || cursorPosition() == te.length() ) | 63 | * 1. String is empty |
54 | m_prevSpace = true; | 64 | * 2. We are at the beginning of the line (pos 0) |
65 | * 3. The char left from current cursor position is a space ! | ||
66 | */ | ||
67 | if ( te.isEmpty() || ( cursorPosition() == 0 ) || ( te[cursorPosition() - 1] == Key_Space ) ) | ||
68 | m_prevSpace = true; | ||
55 | } | 69 | } |
56 | } | 70 | } |
57 | } | 71 | } |
58 | 72 | ||
73 | void NameLineEdit::configReader() { | ||
74 | Config cfg("AddressBook"); | ||
75 | cfg.setGroup("Editor"); | ||
76 | m_disabled = cfg.readBoolEntry( "disableAutoCaps", false ); | ||
77 | } | ||
78 | |||
79 | |||
59 | } | 80 | } |
diff --git a/core/pim/addressbook/namelineedit.h b/core/pim/addressbook/namelineedit.h index c719579..7f0eda8 100644 --- a/core/pim/addressbook/namelineedit.h +++ b/core/pim/addressbook/namelineedit.h | |||
@@ -23,11 +23,14 @@ namespace ABOOK { | |||
23 | ~NameLineEdit(); | 23 | ~NameLineEdit(); |
24 | 24 | ||
25 | protected: | 25 | protected: |
26 | void keyPressEvent( QKeyEvent* ev ); | 26 | void keyPressEvent( QKeyEvent* ev ); |
27 | 27 | ||
28 | private: | 28 | private: |
29 | void configReader(); | ||
30 | |||
29 | bool m_prevSpace : 1; | 31 | bool m_prevSpace : 1; |
32 | bool m_disabled : 1; | ||
30 | }; | 33 | }; |
31 | } | 34 | } |
32 | 35 | ||
33 | #endif | 36 | #endif |