summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/addressbook/addressbook.pro6
-rw-r--r--core/pim/addressbook/contacteditor.cpp9
-rw-r--r--core/pim/addressbook/namelineedit.cpp55
-rw-r--r--core/pim/addressbook/namelineedit.h33
4 files changed, 97 insertions, 6 deletions
diff --git a/core/pim/addressbook/addressbook.pro b/core/pim/addressbook/addressbook.pro
index b27e4b8..bcfdb62 100644
--- a/core/pim/addressbook/addressbook.pro
+++ b/core/pim/addressbook/addressbook.pro
@@ -10,3 +10,4 @@ HEADERS = addressbook.h \
10 abconfig.h \ 10 abconfig.h \
11 abview.h 11 abview.h \
12 namelineedit.h
12 SOURCES= main.cpp \ 13 SOURCES= main.cpp \
@@ -19,3 +20,4 @@ SOURCES = main.cpp \
19 abconfig.cpp \ 20 abconfig.cpp \
20 abview.cpp 21 abview.cpp \
22 namelineedit.cpp
21 23
diff --git a/core/pim/addressbook/contacteditor.cpp b/core/pim/addressbook/contacteditor.cpp
index 72c8bd3..9c13017 100644
--- a/core/pim/addressbook/contacteditor.cpp
+++ b/core/pim/addressbook/contacteditor.cpp
@@ -22,2 +22,3 @@
22#include "contacteditor.h" 22#include "contacteditor.h"
23#include "namelineedit.h"
23 24
@@ -143,3 +144,3 @@ void ContactEditor::init() {
143 gl->addWidget( btnFullName, 0, 0 ); 144 gl->addWidget( btnFullName, 0, 0 );
144 txtFullName = new QLineEdit( container ); 145 txtFullName = new ABOOK::NameLineEdit( container );
145 QWhatsThis::add( txtFullName, tr( "Enter fullname directly ! If you have a lastname with multiple words ( for instance \"de la Guerra\"), please write <lastname>,<firstnames> like this: \"de la Guerra, Carlos Pedro\"" ) ); 146 QWhatsThis::add( txtFullName, tr( "Enter fullname directly ! If you have a lastname with multiple words ( for instance \"de la Guerra\"), please write <lastname>,<firstnames> like this: \"de la Guerra, Carlos Pedro\"" ) );
@@ -615,3 +616,3 @@ void ContactEditor::init() {
615 gl->addWidget( l, 0, 0 ); 616 gl->addWidget( l, 0, 0 );
616 txtFirstName = new QLineEdit( dlgName ); 617 txtFirstName = new ABOOK::NameLineEdit( dlgName );
617 gl->addWidget( txtFirstName, 0, 1 ); 618 gl->addWidget( txtFirstName, 0, 1 );
@@ -620,3 +621,3 @@ void ContactEditor::init() {
620 gl->addWidget( l, 1, 0 ); 621 gl->addWidget( l, 1, 0 );
621 txtMiddleName = new QLineEdit( dlgName ); 622 txtMiddleName = new ABOOK::NameLineEdit( dlgName );
622 gl->addWidget( txtMiddleName, 1, 1 ); 623 gl->addWidget( txtMiddleName, 1, 1 );
@@ -625,3 +626,3 @@ void ContactEditor::init() {
625 gl->addWidget( l, 2, 0 ); 626 gl->addWidget( l, 2, 0 );
626 txtLastName = new QLineEdit( dlgName ); 627 txtLastName = new ABOOK::NameLineEdit( dlgName );
627 gl->addWidget( txtLastName, 2, 1 ); 628 gl->addWidget( txtLastName, 2, 1 );
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
3namespace ABOOK {
4NameLineEdit::NameLineEdit( QWidget* parent, const char* name )
5 : QLineEdit( parent, name ), m_prevSpace( true ) {
6}
7
8NameLineEdit::NameLineEdit( const QString& str, QWidget* par,
9 const char* name )
10 : QLineEdit( str, par, name ),m_prevSpace( true ) {
11}
12
13NameLineEdit::~NameLineEdit() {
14}
15
16void 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}
diff --git a/core/pim/addressbook/namelineedit.h b/core/pim/addressbook/namelineedit.h
new file mode 100644
index 0000000..c719579
--- a/dev/null
+++ b/core/pim/addressbook/namelineedit.h
@@ -0,0 +1,33 @@
1/*
2 * (C) 2004
3 * GPLv2 zecke@handhelds.org
4 *
5 */
6
7#ifndef ABOOK_NAME_LINE_EDIT
8#define ABOOK_NAME_LINE_EDIT
9
10#include <qlineedit.h>
11
12namespace ABOOK {
13 /**
14 * small class to ease the input of names to capitalize them
15 *
16 */
17 class NameLineEdit : public QLineEdit {
18 Q_OBJECT
19 public:
20 NameLineEdit( QWidget* parent, const char* name = 0 );
21 NameLineEdit( const QString& str, QWidget* par,
22 const char *name = 0);
23 ~NameLineEdit();
24
25 protected:
26 void keyPressEvent( QKeyEvent* ev );
27
28 private:
29 bool m_prevSpace : 1;
30 };
31}
32
33#endif