author | zecke <zecke> | 2004-05-01 17:21:57 (UTC) |
---|---|---|
committer | zecke <zecke> | 2004-05-01 17:21:57 (UTC) |
commit | 8dd2d693000c916346f0bb7d94cbc02b8456c65b (patch) (side-by-side diff) | |
tree | 4246b70152d010a8c0e3e7d5268e462f8630be82 | |
parent | fd2bbf9a09aa7a13bd8a43db351b9153e5a4b7ab (diff) | |
download | opie-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...
-rw-r--r-- | core/pim/addressbook/addressbook.pro | 6 | ||||
-rw-r--r-- | core/pim/addressbook/contacteditor.cpp | 9 | ||||
-rw-r--r-- | core/pim/addressbook/namelineedit.cpp | 55 | ||||
-rw-r--r-- | core/pim/addressbook/namelineedit.h | 33 |
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 @@ -1,28 +1,30 @@ #CONFIG = qt warn_on quick-app CONFIG = qt warn_on quick-app HEADERS = addressbook.h \ contacteditor.h \ ablabel.h \ abtable.h \ picker.h \ ofloatbar.h \ configdlg.h \ abconfig.h \ - abview.h + abview.h \ + namelineedit.h SOURCES = main.cpp \ addressbook.cpp \ contacteditor.cpp \ ablabel.cpp \ abtable.cpp \ picker.cpp \ configdlg.cpp \ abconfig.cpp \ - abview.cpp + abview.cpp \ + namelineedit.cpp INTERFACES = configdlg_base.ui TARGET = addressbook INCLUDEPATH += $(OPIEDIR)/include DEPENDPATH += $(OPIEDIR)/include LIBS += -lqpe -lopiecore2 -lopieui2 -lopiepim2 include ( $(OPIEDIR)/include.pro ) 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 @@ -1,70 +1,71 @@ /* * Copyright (c) 2002 Michael R. Crawford <mike@tuxnami.org> * Copyright (C) 2002 by Stefan Eilers (eilers.stefan@epost.de) * * This file is an add-on for the OPIE Palmtop Environment * * This file may be distributed and/or modified under the terms of the * GNU General Public License version 2 as published by the Free Software * Foundation and appearing in the file LICENSE.GPL included in the pacakaging * of this file. * * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * * * This is a rewrite of the abeditor.h file, modified to provide a more * intuitive interface to TrollTech's original Address Book editor. This * is made to operate exactly in interface with the exception of name. * */ #include "contacteditor.h" +#include "namelineedit.h" #include <opie2/odebug.h> #include <opie2/opimcontact.h> #include <qpe/categoryselect.h> #include <qpe/qpeapplication.h> #include <qpe/qpedialog.h> #include <qpe/resource.h> #include <qlabel.h> #include <qtabwidget.h> #include <qlayout.h> #include <qlineedit.h> #include <qmultilineedit.h> #include <qtoolbutton.h> #include <qlistbox.h> #include <qmessagebox.h> #include <qwhatsthis.h> #include <assert.h> static inline bool containsAlphaNum( const QString &str ); static inline bool constainsWhiteSpace( const QString &str ); // helper functions, convert our comma delimited list to proper // file format... void parseEmailFrom( const QString &txt, QString &strDefaultEmail, QString &strAll ); // helper convert from file format to comma delimited... void parseEmailTo( const QString &strDefaultEmail, const QString &strOtherEmail, QString &strBack ); ContactEditor::ContactEditor( const Opie::OPimContact &entry, QWidget *parent, const char *name, WFlags ) : QDialog( parent, name, TRUE, WStyle_ContextHelp ), defaultEmailChooserPosition( -1 ), m_personalView ( false ), cmbDefaultEmail( 0 ), initializing ( false ) { initializing = true; init(); setEntry( entry ); @@ -96,97 +97,97 @@ void ContactEditor::init() { // Ok, we have to remove elements from the list of dynamic entries // which are now stored in special (not dynamic) widgets.. // Otherwise we will get problems with field assignments! (se) slDynamicEntries.remove("Anniversary"); slDynamicEntries.remove("Birthday"); slDynamicEntries.remove("Gender"); // The same with translated fields.. But I will // use the translation map to avoid mismatches.. QMap<int, QString> translMap = Opie::OPimContactFields::idToTrFields(); trlDynamicEntries.remove( translMap[Qtopia::Anniversary] ); trlDynamicEntries.remove( translMap[Qtopia::Birthday] ); trlDynamicEntries.remove( translMap[Qtopia::Gender] ); // Last Check to be sure.. assert( slDynamicEntries.count() == trlDynamicEntries.count() ); assert( slChooserNames.count() == trlChooserNames.count() ); for (i = 0; i < slChooserNames.count(); i++) slChooserValues.append(""); QVBoxLayout *vb = new QVBoxLayout( this ); tabMain = new QTabWidget( this ); vb->addWidget( tabMain ); QWidget *tabViewport = new QWidget ( tabMain ); vb = new QVBoxLayout( tabViewport ); svGeneral = new QScrollView( tabViewport ); vb->addWidget( svGeneral, 0, 0 ); svGeneral->setResizePolicy( QScrollView::AutoOneFit ); // svGeneral->setHScrollBarMode( QScrollView::AlwaysOff ); // svGeneral->setVScrollBarMode( QScrollView::AlwaysOff ); svGeneral->setFrameStyle( QFrame::NoFrame ); QWidget *container = new QWidget( svGeneral->viewport() ); svGeneral->addChild( container ); QGridLayout *gl = new QGridLayout( container, 1, 1, 2, 4 ); gl->setResizeMode( QLayout::FreeResize ); 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 ); QLabel *l = new QLabel( tr( "Job Title" ), container ); QWhatsThis::add( l, tr( "The jobtitle.." ) ); gl->addWidget( l, 1, 0 ); txtJobTitle = new QLineEdit( container ); QWhatsThis::add( txtJobTitle, tr( "The jobtitle.." ) ); gl->addWidget( txtJobTitle, 1, 1 ); l = new QLabel( tr("Suffix"), container ); QWhatsThis::add( l, tr( "Something like \"jr.\".." ) ); gl->addWidget( l, 2, 0 ); txtSuffix = new QLineEdit( container ); QWhatsThis::add( txtSuffix, tr( "Something like \"jr.\".." ) ); gl->addWidget( txtSuffix, 2, 1 ); l = new QLabel( tr( "Organization" ), container ); QWhatsThis::add( l, tr( "The working place of the contact" ) ); gl->addWidget( l, 3, 0 ); txtOrganization = new QLineEdit( container ); QWhatsThis::add( txtOrganization, tr( "The working place of the contact" ) ); gl->addWidget( txtOrganization, 3, 1 ); // Chooser 1 cmbChooserField1 = new QComboBox( FALSE, container ); QWhatsThis::add( cmbChooserField1, tr( "Press to select attribute to change" ) ); cmbChooserField1->setMaximumWidth( 90 ); gl->addWidget( cmbChooserField1, 4, 0 ); // Textfield for chooser 1. // Now use Widgetstack to contain the textfield and the default-email combo ! m_widgetStack1 = new QWidgetStack( container ); txtChooserField1 = new QLineEdit( m_widgetStack1 ); m_widgetStack1 -> addWidget( txtChooserField1, TextField ); gl->addWidget( m_widgetStack1, 4, 1 ); m_widgetStack1 -> raiseWidget( TextField ); // Chooser 2 cmbChooserField2 = new QComboBox( FALSE, container ); QWhatsThis::add( cmbChooserField2, tr( "Press to select attribute to change" ) ); cmbChooserField2->setMaximumWidth( 90 ); gl->addWidget( cmbChooserField2, 5, 0 ); // Textfield for chooser 2 // Now use WidgetStack to contain the textfield and the default-email combo! m_widgetStack2 = new QWidgetStack( container ); txtChooserField2 = new QLineEdit( m_widgetStack2 ); m_widgetStack2 -> addWidget( txtChooserField2, TextField ); gl->addWidget( m_widgetStack2, 5, 1 ); @@ -568,107 +569,107 @@ void ContactEditor::init() { ++counter; // Gender l = new QLabel( tr("Gender"), container ); gl->addWidget( l, counter, 0 ); cmbGender = new QComboBox( container ); cmbGender->insertItem( "", 0 ); cmbGender->insertItem( tr("Male"), 1); cmbGender->insertItem( tr("Female"), 2); gl->addWidget( cmbGender, counter, 1 ); ++counter; // Create Labels and lineedit fields for every dynamic entry QStringList::ConstIterator it = slDynamicEntries.begin(); QMap<QString, int> mapStrToID = Opie::OPimContactFields::untrFieldsToId(); QMap<int, QString> mapIdToStr = Opie::OPimContactFields::idToTrFields(); for (i = counter; it != slDynamicEntries.end(); i++, ++it ) { if (((*it) == "Anniversary") || ((*it) == "Birthday")|| ((*it) == "Gender")) continue; l = new QLabel( mapIdToStr[mapStrToID[*it]], container ); listName.append( l ); gl->addWidget( l, i, 0 ); QLineEdit *e = new QLineEdit( container ); listValue.append( e ); gl->addWidget( e, i, 1); } // Fill labels with names.. // loadFields(); tabMain->insertTab( tabViewport, tr( "Details" ) ); dlgNote = new QDialog( this, "Note Dialog", TRUE ); dlgNote->setCaption( tr("Enter Note") ); QVBoxLayout *vbNote = new QVBoxLayout( dlgNote ); txtNote = new QMultiLineEdit( dlgNote ); vbNote->addWidget( txtNote ); connect( btnNote, SIGNAL(clicked()), this, SLOT(slotNote()) ); dlgName = new QDialog( this, "Name Dialog", TRUE ); dlgName->setCaption( tr("Edit Name") ); gl = new QGridLayout( dlgName, 5, 2, 2, 3 ); 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 ); // gl->addWidget( l, 3, 0 ); // txtSuffix = new QLineEdit( dlgName ); // gl->addWidget( txtSuffix, 3, 1 ); space = new QSpacerItem(1,1, QSizePolicy::Maximum, QSizePolicy::MinimumExpanding ); gl->addItem( space, 4, 0 ); cmbChooserField1->insertStringList( trlChooserNames ); cmbChooserField2->insertStringList( trlChooserNames ); cmbChooserField3->insertStringList( trlChooserNames ); cmbChooserField4->insertStringList( trlChooserNames ); cmbChooserField1->setCurrentItem( 0 ); cmbChooserField2->setCurrentItem( 1 ); cmbChooserField3->setCurrentItem( 2 ); connect( btnFullName, SIGNAL(clicked()), this, SLOT(slotName()) ); connect( txtFullName, SIGNAL(textChanged(const QString&)), this, SLOT(slotFullNameChange(const QString&)) ); connect( txtSuffix, SIGNAL(textChanged(const QString&)), this, SLOT(slotSuffixChange(const QString&)) ); connect( txtOrganization, SIGNAL(textChanged(const QString&)), this, SLOT(slotOrganizationChange(const QString&)) ); connect( txtChooserField1, SIGNAL(textChanged(const QString&)), this, SLOT(slotChooser1Change(const QString&)) ); connect( txtChooserField2, SIGNAL(textChanged(const QString&)), this, SLOT(slotChooser2Change(const QString&)) ); connect( txtChooserField3, SIGNAL(textChanged(const QString&)), this, SLOT(slotChooser3Change(const QString&)) ); connect( txtChooserField4, SIGNAL(textChanged(const QString&)), this, SLOT(slotChooser4Change(const QString&)) ); connect( txtAddress, SIGNAL(textChanged(const QString&)), this, SLOT(slotAddressChange(const QString&)) ); connect( txtCity, SIGNAL(textChanged(const QString&)), this, SLOT(slotCityChange(const QString&)) ); connect( txtState, SIGNAL(textChanged(const QString&)), this, SLOT(slotStateChange(const QString&)) ); connect( txtZip, SIGNAL(textChanged(const QString&)), this, SLOT(slotZipChange(const QString&)) ); connect( cmbCountry, SIGNAL(textChanged(const QString&)), this, SLOT(slotCountryChange(const QString&)) ); connect( cmbCountry, SIGNAL(activated(const QString&)), this, SLOT(slotCountryChange(const QString&)) ); 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 |