DigraphMultiLineEdit.cpp

Go to the documentation of this file.
00001 #include "DigraphMultiLineEdit.h"
00002 
00003 DigraphMultiLineEdit::DigraphMultiLineEdit( QWidget* parent, const char* name = 0 )
00004     : QMultiLineEdit( parent, name ), digraphEnabled( false ) {
00005 }
00006 
00007 DigraphMultiLineEdit::~DigraphMultiLineEdit() {
00008 }
00009 
00010 void DigraphMultiLineEdit::keyPressEvent( QKeyEvent* event ) {
00011     //cout << "txt='" << event->text() << "' asc=" << event->ascii() << "; k=" << event->key() << " count=" << event->count() << endl;
00012     if( digraphEnabled ) {
00013         // We consider only printable keys.  Control keys are processed normally.
00014         // I'm not sure if this test covers all the cases though.
00015         if( event->count() > 0 ) {
00016             if( event->key() == Key_Backspace ) {
00017                 int line;
00018                 int col;
00019                 getCursorPosition( &line, &col );
00020                 if( line + col > 0 ) {
00021                     if( buffer.isNull() ) {
00022                         QString charToDelete( textLine( line ).mid( col - 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                         QMultiLineEdit::keyPressEvent( digraphEvent );
00038                         return;
00039                     }
00040                 }
00041             }
00042         }
00043     }
00044     QMultiLineEdit::keyPressEvent( event );
00045 }
00046 
00047 void DigraphMultiLineEdit::setDigraphEnabled( bool isEnabled ) {
00048     this->digraphEnabled = isEnabled;
00049 }
00050 
00051 bool DigraphMultiLineEdit::isDigraphEnabled() const {
00052     return( digraphEnabled );
00053 }

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