DigraphLineEdit.cpp

Go to the documentation of this file.
00001 #include "DigraphLineEdit.h"
00002 
00003 DigraphLineEdit::DigraphLineEdit( QWidget* parent, const char* name = 0 )
00004     : QLineEdit( parent, name ), digraphEnabled( false ) {
00005 }
00006 
00007 DigraphLineEdit::DigraphLineEdit( const QString& content, QWidget* parent, const char* name = 0 )
00008     : QLineEdit( content, parent, name ), digraphEnabled( false ) {
00009 }
00010 
00011 DigraphLineEdit::~DigraphLineEdit() {
00012 }
00013 
00014 void DigraphLineEdit::keyPressEvent( QKeyEvent* event ) {
00015     if( digraphEnabled ) {
00016         // We consider only printable keys.  Control keys are processed normally.
00017         // I'm not sure if this test covers all the cases though.
00018         if( event->count() > 0 ) {
00019             if( event->key() == Key_Backspace ) {
00020                 if( cursorPosition() > 0 ) {
00021                     if( buffer.isNull() ) {
00022                         QString charToDelete( text().mid( cursorPosition() - 1, 1 ) );
00023                         buffer = charToDelete;
00024                     }
00025                     else 
00026                         buffer = QString::null;
00027                 }
00028             }
00029             else {
00030                 if( !buffer.isNull() ) {
00031                     buffer += event->text();
00032                     const QString newChar( Util::getDigraph( buffer ) );
00033                     if( newChar == QString::null )
00034                         buffer = QString::null;
00035                     else {
00036                         QKeyEvent* digraphEvent = new QKeyEvent( QEvent::KeyPress, 0, 0, 0, newChar, event->isAutoRepeat(), 0 );
00037                         QLineEdit::keyPressEvent( digraphEvent );
00038                         return;
00039                     }
00040                 }
00041             }
00042         }
00043     }
00044     QLineEdit::keyPressEvent( event );
00045 }
00046 
00047 void DigraphLineEdit::setDigraphEnabled( bool isEnabled ) {
00048     this->digraphEnabled = isEnabled;
00049 }
00050 
00051 bool DigraphLineEdit::isDigraphEnabled() const {
00052     return( digraphEnabled );
00053 }

Generated on Sun Mar 1 17:30:47 2009 for toMOTko by  doxygen 1.5.6