Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

namelineedit.cpp

Go to the documentation of this file.
00001 #include "namelineedit.h"
00002 
00003 /* OPIE */
00004 #include <opie2/odebug.h>
00005 
00006 #include <qpe/config.h>
00007 
00008 namespace ABOOK {
00009 NameLineEdit::NameLineEdit( QWidget* parent, const char* name )
00010     : QLineEdit( parent, name ), m_prevSpace( true ), m_disabled( false ) {
00011         configReader();
00012 }
00013 
00014 NameLineEdit::NameLineEdit( const QString& str, QWidget* par,
00015                             const char* name )
00016     : QLineEdit( str, par, name ),m_prevSpace( true ), m_disabled( false ) {
00017         configReader();
00018 }
00019 
00020 NameLineEdit::~NameLineEdit() {
00021 }
00022 
00023 void NameLineEdit::keyPressEvent( QKeyEvent* ev ) {
00024 
00025     // If disabled: Push everything to the mother class..
00026     if ( m_disabled ){
00027             QLineEdit::keyPressEvent( ev );
00028             return;
00029     }
00030 
00031     QString t = ev->text();
00032     int key = ev->key();
00033     int ascii = ev->ascii();
00034 
00035     // ### FIXME with composed events
00036     if ( !t.isEmpty() && ( !ev->ascii() || ev->ascii()>=32 ) &&
00037          key != Key_Delete && key != Key_Backspace &&
00038          key != Key_Return && key != Key_Enter ) {
00039         odebug << "str " << ev->text() << " " << m_prevSpace << oendl;
00040 
00041         if ( m_prevSpace ) {
00042             t = t.upper();
00043             m_prevSpace = false;
00044         }
00045         if ( key == Key_Space )
00046             m_prevSpace = true;
00047 
00048 
00049         QKeyEvent nEv(ev->type(), key, ascii, ev->state(),
00050                       t, ev->isAutoRepeat(), ev->count() );
00051         QLineEdit::keyPressEvent( &nEv );
00052         if ( !nEv.isAccepted() )
00053                 ev->ignore();
00054     }else {
00055         QLineEdit::keyPressEvent( ev );
00056         /* if key was a backspace lets see if we should
00057          * capitalize the next letter
00058          */
00059         if ( key == Key_Backspace ) {
00060             QString te = text();
00061             odebug << "Backspace: " << te << oendl;
00062             /* Capitalize first letter if a char is removed and:
00063              * 1. String is empty
00064              * 2. We are at the beginning of the line (pos 0)
00065              * 3. The char left from current cursor position is a space !
00066              */
00067             if ( te.isEmpty() || ( cursorPosition() == 0 ) || ( te[cursorPosition() - 1] == Key_Space ) )
00068                  m_prevSpace = true;
00069         }
00070     }
00071 }
00072 
00073 void NameLineEdit::configReader() {
00074         Config cfg("AddressBook");
00075         cfg.setGroup("Editor");
00076         m_disabled = cfg.readBoolEntry( "disableAutoCaps", false );
00077 }
00078 
00079 
00080 }

Generated on Sat Nov 5 16:15:47 2005 for OPIE by  doxygen 1.4.2