summaryrefslogtreecommitdiff
path: root/core
authorzecke <zecke>2004-05-01 17:21:57 (UTC)
committer zecke <zecke>2004-05-01 17:21:57 (UTC)
commit8dd2d693000c916346f0bb7d94cbc02b8456c65b (patch) (side-by-side diff)
tree4246b70152d010a8c0e3e7d5268e462f8630be82 /core
parentfd2bbf9a09aa7a13bd8a43db351b9153e5a4b7ab (diff)
downloadopie-8dd2d693000c916346f0bb7d94cbc02b8456c65b.zip
opie-8dd2d693000c916346f0bb7d94cbc02b8456c65b.tar.gz
opie-8dd2d693000c916346f0bb7d94cbc02b8456c65b.tar.bz2
A new LineEdit to assis entering names.
so holger hans peter freyther will get Holger Hans Peter Freyther on the fly but you can also change the letter later...
Diffstat (limited to 'core') (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
@@ -8,7 +8,8 @@ HEADERS = addressbook.h \
ofloatbar.h \
configdlg.h \
abconfig.h \
- abview.h
+ abview.h \
+ namelineedit.h
SOURCES = main.cpp \
addressbook.cpp \
contacteditor.cpp \
@@ -17,7 +18,8 @@ SOURCES = main.cpp \
picker.cpp \
configdlg.cpp \
abconfig.cpp \
- abview.cpp
+ abview.cpp \
+ namelineedit.cpp
INTERFACES = configdlg_base.ui
TARGET = addressbook
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
@@ -20,6 +20,7 @@
*/
#include "contacteditor.h"
+#include "namelineedit.h"
#include <opie2/odebug.h>
#include <opie2/opimcontact.h>
@@ -141,7 +142,7 @@ void ContactEditor::init() {
btnFullName = new QPushButton( tr( "Full Name..." ), container );
QWhatsThis::add( btnFullName, tr( "Press to enter last- middle and firstname" ) );
gl->addWidget( btnFullName, 0, 0 );
- txtFullName = new QLineEdit( container );
+ txtFullName = new ABOOK::NameLineEdit( container );
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\"" ) );
gl->addWidget( txtFullName, 0, 1 );
@@ -613,17 +614,17 @@ void ContactEditor::init() {
l = new QLabel( tr("First Name"), dlgName );
gl->addWidget( l, 0, 0 );
- txtFirstName = new QLineEdit( dlgName );
+ txtFirstName = new ABOOK::NameLineEdit( dlgName );
gl->addWidget( txtFirstName, 0, 1 );
l = new QLabel( tr("Middle Name"), dlgName );
gl->addWidget( l, 1, 0 );
- txtMiddleName = new QLineEdit( dlgName );
+ txtMiddleName = new ABOOK::NameLineEdit( dlgName );
gl->addWidget( txtMiddleName, 1, 1 );
l = new QLabel( tr("Last Name"), dlgName );
gl->addWidget( l, 2, 0 );
- txtLastName = new QLineEdit( dlgName );
+ txtLastName = new ABOOK::NameLineEdit( dlgName );
gl->addWidget( txtLastName, 2, 1 );
// l = new QLabel( tr("Suffix"), dlgName );
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 @@
+#include "namelineedit.h"
+
+namespace ABOOK {
+NameLineEdit::NameLineEdit( QWidget* parent, const char* name )
+ : QLineEdit( parent, name ), m_prevSpace( true ) {
+}
+
+NameLineEdit::NameLineEdit( const QString& str, QWidget* par,
+ const char* name )
+ : QLineEdit( str, par, name ),m_prevSpace( true ) {
+}
+
+NameLineEdit::~NameLineEdit() {
+}
+
+void NameLineEdit::keyPressEvent( QKeyEvent* ev ) {
+ QString t = ev->text();
+ int key = ev->key();
+ int ascii = ev->ascii();
+
+ // ### FIXME with composed events
+ if ( !t.isEmpty() && ( !ev->ascii() || ev->ascii()>=32 ) &&
+ key != Key_Delete && key != Key_Backspace &&
+ key != Key_Return && key != Key_Enter ) {
+ qWarning( "str " + ev->text() + " %d", m_prevSpace );
+
+ if ( m_prevSpace ) {
+ t = t.upper();
+ m_prevSpace = false;
+ }
+ if ( key == Key_Space )
+ m_prevSpace = true;
+
+
+ QKeyEvent nEv(ev->type(), key, ascii, ev->state(),
+ t, ev->isAutoRepeat(), ev->count() );
+ QLineEdit::keyPressEvent( &nEv );
+ if ( !nEv.isAccepted() )
+ ev->ignore();
+ }else {
+ QLineEdit::keyPressEvent( ev );
+ /* if key was a backspace lets see if we should
+ * capitalize the next letter
+ */
+ if ( key == Key_Backspace ) {
+ QString te = text();
+ /* if string is empty capitalize the first letter */
+ /* else see if we're at the end of the string */
+ if ( te.isEmpty() || cursorPosition() == te.length() )
+ m_prevSpace = true;
+ }
+ }
+}
+
+}
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 @@
+/*
+ * (C) 2004
+ * GPLv2 zecke@handhelds.org
+ *
+ */
+
+#ifndef ABOOK_NAME_LINE_EDIT
+#define ABOOK_NAME_LINE_EDIT
+
+#include <qlineedit.h>
+
+namespace ABOOK {
+ /**
+ * small class to ease the input of names to capitalize them
+ *
+ */
+ class NameLineEdit : public QLineEdit {
+ Q_OBJECT
+ public:
+ NameLineEdit( QWidget* parent, const char* name = 0 );
+ NameLineEdit( const QString& str, QWidget* par,
+ const char *name = 0);
+ ~NameLineEdit();
+
+ protected:
+ void keyPressEvent( QKeyEvent* ev );
+
+ private:
+ bool m_prevSpace : 1;
+ };
+}
+
+#endif