// ---------------------------------------------------------------------- // ---------------------------------------------------------------------- void QmvTable::keyPressEvent( QKeyEvent *ke ) { #ifdef QMVTABLE_DEBUG int ktype = ke ? ke->key() : -9999; qDebug( "%-20.20s::keyPressEvent::%6d", "QmvTable", ktype ); #endif // finish and move to next cell if ( ke->key() == Key_Return || ke->key() == Key_Enter ) activateNextCell(); // Finish if ( ke->key() == Key_Escape ) { editCompleted(); ke->accept(); // finish here. } // navigation, in-place editing etc QTable::keyPressEvent ( ke ); }
// ---------------------------------------------------------------------- bool QmvTable::eventFilter( QObject *o, QEvent *e ) { #ifdef QMVTABLE_DEBUG const char *name = o ? o->name() : "NO_OBJECT"; const char *classname = o ? o->className() : "NO_CLASS"; int etype = e ? e->type() : -9999; // qDebug( "%-20.20s::eventFilter(%20.20s/%20.20s, %6d)", "QmvTable", name, classname, etype ); #endif // test disabing this eventfilter while tracing crash - Issue#324 // return QTable::eventFilter( o, e ); if ( !o || !e ) return true; if ( e->type() == QEvent::KeyPress ) { QKeyEvent *ke = (QKeyEvent *) e; // keyboard row select. if ( ke->key() == Key_Return || ke->key() == Key_Enter ) if ( ke->state() & AltButton ) { // the mouse point is a fake - TODO: decide what to make it. emit clicked( currentRow(), currentColumn(), 1, QPoint(0,0) ); return true; } else { activateNextCell(); return true; } } // focus out - do nothing // TODO: popup a reminder to do something if ( e->type() == QEvent::FocusOut ) return true; return QTable::eventFilter( o, e ); }
// My own version of the table's actions // In principle it does the same as QTable, but // deletes selected cells // closes application on ESCAPE bool MTable::eventFilter( QObject *o, QEvent *e ) { if ( !o || !e ) return QScrollView::eventFilter( o, e ); //QWidget *editorWidget = cellWidget( currentRow(), currentColumn() ); switch ( e->type() ) { case QEvent::KeyPress: if ( !isEditing() ) { QKeyEvent *ke = (QKeyEvent*)e; if ( ke->key() == Key_Escape ) { QApplication::sendEvent( parentWidget ( FALSE ) , e ); return TRUE; } if ( ke->key() == Key_Return || ke->key() == Key_Enter ) { if ( currentRow() >= numRows() - 1 ){ setUpdatesEnabled( false ); setNumRows( numRows() + 10 ); setUpdatesEnabled( true ); } activateNextCell(); ensureCellVisible ( currentRow(), currentColumn() ); return TRUE; } if ( ke->key() == Key_Delete ) { if (numSelections() > 0) { QTableSelection ts = selection( currentSelection() ); for ( int icol = ts.leftCol(); icol <= ts.rightCol(); icol++){ for ( int irow = ts.topRow(); irow <= ts.bottomRow(); irow++){ clearCell( irow, icol ); } } setCurrentCell ( ts.anchorRow(), ts.anchorCol() ); clearSelection ( TRUE ); } else { clearCell( currentRow(), currentColumn() ); } return TRUE; } if ( ke->key() == Key_C && ( ke->state() & ControlButton ) == ControlButton ) { QString cellText; itemCopy.clear(); if (numSelections() > 0) { QTableSelection ts; ts = selection( currentSelection() ); for ( int irow = ts.topRow(); irow <= ts.bottomRow(); irow++){ for ( int icol = ts.leftCol(); icol <= ts.rightCol(); icol++){ cellText = text( irow, icol ); if ( !cellText.isEmpty() ) itemCopy.push_back( cellText.latin1() ); else itemCopy.push_back( "" ); } } } else { cellText = text( currentRow(), currentColumn() ); if ( !cellText.isEmpty() ) itemCopy.push_back( cellText.latin1() ); else itemCopy.push_back( "" ); } return TRUE; } if ( ke->key() == Key_V && ( ke->state() & ControlButton ) == ControlButton ) { if ( numSelections() > 0 && itemCopy.size() > 0 ) { QTableSelection ts = selection( currentSelection() ); uint icount; for ( int irow = ts.topRow(); irow <= ts.bottomRow(); irow++){ for ( int icol = ts.leftCol(); icol <= ts.rightCol(); icol++){ //icount = (icol - ts.leftCol())*(ts.bottomRow() - ts.topRow()+1) + irow-ts.topRow(); icount = (irow - ts.topRow())*(ts.rightCol() - ts.leftCol()+1) + icol-ts.leftCol(); if ( icount < itemCopy.size() ) setText( irow, icol, (itemCopy[icount]).c_str() ); } } } else { if ( itemCopy.size() > 0 ) // there was not selection, copy first item only setText( currentRow(), currentColumn(), (itemCopy[0]).c_str() ); } return TRUE; } if ( ke->key() == Key_X && ( ke->state() & ControlButton ) == ControlButton ) { QString cellText; if (numSelections() > 0) { itemCopy.clear(); QTableSelection ts; ts = selection( currentSelection() ); for ( int irow = ts.topRow(); irow <= ts.bottomRow(); irow++){ for ( int icol = ts.leftCol(); icol <= ts.rightCol(); icol++){ cellText = text( irow, icol ); if ( !cellText.isEmpty() ) itemCopy.push_back( cellText.latin1() ); else itemCopy.push_back( "" ); clearCell( irow, icol ); } } setCurrentCell ( ts.anchorRow(), ts.anchorCol() ); clearSelection ( TRUE ); } else { cellText = text( currentRow(), currentColumn() ); if ( !cellText.isEmpty() ) itemCopy.push_back( cellText.latin1() ); else itemCopy.push_back( "" ); clearCell( currentRow(), currentColumn() ); } return TRUE; } if ( currentColumn() == 0 && ctype == ComboBox && ke->key() != Key_Left && ke->key() != Key_Right && ke->key() != Key_Up && ke->key() != Key_Down && ke->key() != Key_Control && ke->key() != Key_Alt && ke->key() != Key_Shift ) { //QApplication::beep (); keyPressEvent( (QKeyEvent*)e ); return true; } } else{ QKeyEvent *ke = (QKeyEvent*)e; if ( ke->key() == Key_Return || ke->key() == Key_Enter ) { stopEditing(); if ( currentRow() >= numRows() - 1 ){ setUpdatesEnabled( false ); setNumRows( numRows() + 10 ); setUpdatesEnabled( true ); } //else {stopEditing();} activateNextCell(); return true; } } break; default: break; } return QTable::eventFilter( o, e ) ; }