Logo Search packages:      
Sourcecode: qt4-x11 version File versions

void Q3ComboBox::keyPressEvent ( QKeyEvent e  )  [protected, virtual]

Reimplemented from QWidget.

Definition at line 1437 of file q3combobox.cpp.

References activated(), completionIndex(), currentItem, currentText, QEvent::ignore(), QString::isEmpty(), QKeyEvent::key(), QString::left(), QString::length(), popup(), QKeyEvent::text(), and text().

Referenced by eventFilter().

{
    bool handleEventHere = d->usingListBox() || !d->poppedUp;

    int c = currentItem();
    if ( ( e->key() == Qt::Key_F4 && e->state() == 0 ) ||
       ( e->key() == Qt::Key_Down && (e->state() & Qt::AltModifier) ) ||
       ( !d->ed && e->key() == Qt::Key_Space ) ) {
      if ( count() ) {
          if ( !d->usingListBox() )
            d->popup()->setActiveItem( this->d->current );
          popup();
      }
      return;
    } else if ( handleEventHere && e->key() == Qt::Key_Up ) {
      if ( c > 0 )
          setCurrentItem( c-1 );
    } else if ( handleEventHere && e->key() == Qt::Key_Down ) {
      if ( ++c < count() )
          setCurrentItem( c );
    } else if ( handleEventHere && e->key() == Qt::Key_Home && ( !d->ed || !d->ed->hasFocus() ) ) {
      setCurrentItem( 0 );
    } else if ( handleEventHere && e->key() == Qt::Key_End && ( !d->ed || !d->ed->hasFocus() ) ) {
      setCurrentItem( count()-1 );
    } else if ( !d->ed && e->ascii() >= 32 && !e->text().isEmpty() ) {
      if ( !d->completionTimer->isActive() ) {
          d->completeAt = 0;
          c = completionIndex( e->text(), ++c );
          if ( c >= 0 ) {
            setCurrentItem( c );
            d->completeAt = e->text().length();
          }
      } else {
          d->completionTimer->stop();
          QString ct = currentText().left( d->completeAt ) + e->text();
          c = completionIndex( ct, c );
          if ( c < 0 && d->completeAt > 0 ) {
            c = completionIndex( e->text(), 0 );
            ct = e->text();
          }
          d->completeAt = 0;
          if ( c >= 0 ) {
            setCurrentItem( c );
            d->completeAt = ct.length();
          }
      }
      d->completionTimer->start( 400, true );
    } else {
      e->ignore();
      return;
    }

    c = currentItem();
    if ( count() && !text( c ).isNull() )
      emit activated( text( c ) );
    emit activated( c );
}


Generated by  Doxygen 1.6.0   Back to index