?? qlistbox.cpp
字號:
handleItemChange( old, e->state() & ShiftButton, e->state() & ControlButton ); }#endif if ( !( e->state() & ShiftButton ) || !d->selectAnchor ) d->selectAnchor = d->current; break; case Key_Down: d->currInputString = QString::null; if ( currentItem() < (int)count() - 1 ) { setCurrentItem( currentItem() + 1 ); handleItemChange( old, e->state() & ShiftButton, e->state() & ControlButton ); }#ifdef QT_KEYPAD_MODE else { setCurrentItem( 0 ); handleItemChange( old, e->state() & ShiftButton, e->state() & ControlButton ); }#endif if ( !( e->state() & ShiftButton ) || !d->selectAnchor ) d->selectAnchor = d->current; break; case Key_Left: d->currInputString = QString::null; if ( currentColumn() > 0 ) { setCurrentItem( currentItem() - numRows() ); handleItemChange( old, e->state() & ShiftButton, e->state() & ControlButton ); } else if ( numColumns() > 1 && currentItem() > 0 ) { int row = currentRow(); setCurrentItem( currentRow() - 1 + ( numColumns() - 1 ) * numRows() ); if ( currentItem() == -1 ) setCurrentItem( row - 1 + ( numColumns() - 2 ) * numRows() ); handleItemChange( old, e->state() & ShiftButton, e->state() & ControlButton ); } else { QApplication::sendEvent( horizontalScrollBar(), e ); } if ( !( e->state() & ShiftButton ) || !d->selectAnchor ) d->selectAnchor = d->current; break; case Key_Right: d->currInputString = QString::null; if ( currentColumn() < numColumns()-1 ) { int row = currentRow(); int i = currentItem(); setCurrentItem( currentItem() + numRows() ); if ( currentItem() == -1 ) { if ( row < numRows() - 1 ) setCurrentItem( row + 1 ); else setCurrentItem( i ); } handleItemChange( old, e->state() & ShiftButton, e->state() & ControlButton ); } else if ( numColumns() > 1 && currentRow() < numRows() ) { if ( currentRow() + 1 < numRows() ) { setCurrentItem( currentRow() + 1 ); handleItemChange( old, e->state() & ShiftButton, e->state() & ControlButton ); } } else { QApplication::sendEvent( horizontalScrollBar(), e ); } if ( !( e->state() & ShiftButton ) || !d->selectAnchor ) d->selectAnchor = d->current; break; case Key_Next: { d->currInputString = QString::null; int i = 0; if ( numColumns() == 1 ) { i = currentItem() + numItemsVisible(); i = i > (int)count() - 1 ? (int)count() - 1 : i; setCurrentItem( i ); setBottomItem( i ); } else { // I'm not sure about this behavior... if ( currentRow() == numRows() - 1 ) i = currentItem() + numRows(); else i = currentItem() + numRows() - currentRow() - 1; i = i > (int)count() - 1 ? (int)count() - 1 : i; setCurrentItem( i ); } handleItemChange( old, e->state() & ShiftButton, e->state() & ControlButton ); if ( !( e->state() & ShiftButton ) || !d->selectAnchor ) d->selectAnchor = d->current; } break; case Key_Prior: { selectCurrent = TRUE; d->currInputString = QString::null; int i; if ( numColumns() == 1 ) { i = currentItem() - numItemsVisible(); i = i < 0 ? 0 : i; setCurrentItem( i ); setTopItem( i ); } else { // I'm not sure about this behavior... if ( currentRow() == 0 ) i = currentItem() - numRows(); else i = currentItem() - currentRow(); i = i < 0 ? 0 : i; setCurrentItem( i ); } handleItemChange( old, e->state() & ShiftButton, e->state() & ControlButton ); if ( !( e->state() & ShiftButton ) || !d->selectAnchor ) d->selectAnchor = d->current; } break;#ifdef QT_KEYPAD_MODE case Key_Select:#endif case Key_Space: selectCurrent = TRUE; d->currInputString = QString::null; toggleCurrentItem(); if ( !( e->state() & ShiftButton ) || !d->selectAnchor ) d->selectAnchor = d->current;#ifdef QT_KEYPAD_MODE if ( currentItem() >= 0 && selectionMode() != NoSelection ) { QString tmp = item( currentItem() )->text(); emit selected( currentItem()); emit selected( item( currentItem() ) ); if ( !tmp.isEmpty() ) emit selected( tmp ); emit returnPressed( item( currentItem() ) ); }#endif break; case Key_Return: case Key_Enter: selectCurrent = TRUE; d->currInputString = QString::null; if ( currentItem() >= 0 && selectionMode() != NoSelection ) { QString tmp = item( currentItem() )->text(); emit selected( currentItem()); emit selected( item( currentItem() ) ); if ( !tmp.isEmpty() ) emit selected( tmp ); emit returnPressed( item( currentItem() ) ); } if ( !( e->state() & ShiftButton ) || !d->selectAnchor ) d->selectAnchor = d->current; break; case Key_Home: { selectCurrent = TRUE; d->currInputString = QString::null; setCurrentItem( 0 ); handleItemChange( old, e->state() & ShiftButton, e->state() & ControlButton ); if ( !( e->state() & ShiftButton ) || !d->selectAnchor ) d->selectAnchor = d->current; } break; case Key_End: { selectCurrent = TRUE; d->currInputString = QString::null; int i = (int)count() - 1; setCurrentItem( i ); handleItemChange( old, e->state() & ShiftButton, e->state() & ControlButton ); if ( !( e->state() & ShiftButton ) || !d->selectAnchor ) d->selectAnchor = d->current; } break; default: { if ( !e->text().isEmpty() && e->text()[ 0 ].isPrint() ) { d->findItemByName( e->text() ); } else { d->currInputString = QString::null; if ( e->state() & ControlButton ) { switch ( e->key() ) { case Key_A: selectAll( TRUE ); break; } } else { e->ignore(); } } } } if ( selectCurrent && selectionMode() == Single && d->current && !d->current->s ) { updateItem( d->current ); setSelected( d->current, TRUE ); }}/*!\reimp*/void QListBox::focusInEvent( QFocusEvent *e ){ d->mousePressRow = -1; d->mousePressColumn = -1; if ( #ifdef QT_KEYPAD_MODE !qt_modalEditingEnabled &&#endif e->reason() != QFocusEvent::Mouse && !d->current && d->head ) { setCurrentItem(d->head); } else if ( d->current ) updateItem( currentItem() );}/*!\reimp*/void QListBox::focusOutEvent( QFocusEvent * ){ if ( d->current ) updateItem( currentItem() );}/*! Repaints the item at position \a index in the list.*/void QListBox::updateItem( int index ){ if ( index >= 0 ) updateItem( item( index ) );}/*! Repaints \a i.*/void QListBox::updateItem( QListBoxItem * i ){ if ( !i ) return; i->dirty = TRUE; d->updateTimer->start( 0, TRUE );}/*! Sets the list box to selection mode \a mode, which may be one of \c Single (the default), \c Extended, \c Multi or \c NoSelection. \sa selectionMode()*/void QListBox::setSelectionMode( SelectionMode mode ){ if ( d->selectionMode == mode ) return; d->selectionMode = mode; triggerUpdate( TRUE );}/*! Returns the selection mode of the list box. The initial mode is \c Single. \sa setSelectionMode()*/QListBox::SelectionMode QListBox::selectionMode() const{ return d->selectionMode;}/*! \obsolete Consider using selectionMode() instead of this method. Returns TRUE if the listbox is in multi-selection mode or extended selection mode, and FALSE if it is in single-selection mode or no-selection more. \sa selectionMode() setSelectionMode()*/bool QListBox::isMultiSelection() const{ return selectionMode() == Multi || selectionMode() == Extended;}/*! \obsolete Consider using setSelectionMode() instead of this method. Sets the list box to multi-selection mode if \a enable is TRUE, and to single-selection mode if \a enable is FALSE. We recommend using setSelectionMode() instead; that function also offers two other modes. \sa setSelectionMode() selectionMode()*/void QListBox::setMultiSelection( bool enable ){ setSelectionMode( enable ? Multi : Single );}/*! Toggles the selection status of currentItem() and repaints, if the listbox is a multi-selection listbox. \sa setMultiSelection()*/void QListBox::toggleCurrentItem(){ if ( selectionMode() == Single || selectionMode() == NoSelection || !d->current ) return; if ( d->current->s || d->current->isSelectable() ) { d->current->s = !d->current->s; emit selectionChanged(); } updateItem( d->current );}/*! Selects the item at position \a index if \a select is TRUE, or unselects it if \a select is FALSE, and repaints the item appropriately. If the listbox is a single-selection listbox and and \a select is TRUE, setCurrentItem() will be called. If the listbox is a single-selection listbox and and \a select is FALSE, clearSelection() will be called if \a index is the currently selected item. \sa setMultiSelection(), setCurrentItem(), clearSelection(), currentItem()*/void QListBox::setSelected( int index, bool select ){ setSelected( item( index ), select );}/*! Selects \a item if \a select is TRUE, or unselects it if \a select is FALSE, and repaints the item appropriately. If the listbox is a single-selection listbox and and \a select is TRUE, setCurrentItem() is called. If the listbox is a single-selection listbox and and \a select is FALSE, clearSelection() is called if \a item is the currently selected item. Note that for this function, no-selection means multi-selection. The user cannot select items in a no-selection list box, but the application programmer can. \sa setMultiSelection(), setCurrentItem(), clearSelection(), currentItem()*/void QListBox::setSelected( QListBoxItem * item, bool select ){ if ( !item || !item->isSelectable() || (bool)item->s == select || d->selectionMode == NoSelection ) return; bool emitHighlighted = FALSE; if ( selectionMode() == Single && d->current != item ) { QListBoxItem *o = d->current; if ( d->current && d->current->s ) d->current->s = FALSE; d->current = item; int ind = index( item ); d->currentColumn = ind / numRows(); d->currentRow = ind % numRows(); if ( o ) updateItem( o ); emitHighlighted = TRUE; } item->s = (uint)select; updateItem( item ); if ( d->selectionMode == Single && select ) emit selectionChanged( item ); emit selectionChanged(); if ( emitHighlighted ) { QString tmp; if ( d->current ) tmp = d->current->text(); int tmp2 = index( d->current ); emit highlighted( d->current ); if ( !tmp.isNull() ) emit highlighted( tmp ); emit highlighted( tmp2 ); emit currentChanged( d->current ); }}/*! Returns TRUE if item \a i is selected. Returns FALSE if it is not selected or if there is an error.*/bool QListBox::isSelected( int i ) const{ QListBoxItem * lbi = item( i ); if ( !lbi ) return FALSE; // should not happen return lbi->s;}/*! Returns TRUE if item \a i is selected. Returns FALSE if it is not selected or if there is an error.*/bool QListBox::isSelected( const QListBoxItem * i ) const{ if ( !i ) return FALSE; return i->s;}/*! Deselects all items, if possible. Note that a single-selection listbox will automatically select an item if it has keyboard focus.*/void QListBox::clearSelection(){ selectAll( FALSE );}/*! If \a select is TRUE, all items get selected, else all get unselected. This works only in the selection modes Multi and Extended. In Single and NoSelection mode the selection of the current item is just set to \a select.*/void QListBox::selectAll( bool select ){ if ( isMultiSelection() ) { bool b = signalsBlocked(); blockSignals( TRUE ); for ( int i = 0; i < (int)count(); i++ ) setSelected( i, select ); blockSignals( b ); emit selectionChanged(); } else if ( d->current ) { QListBoxItem * i = d->current; setSelected( i, select ); }}/*! Inverts the selection. Works only in Multi and Extended selection mode.*/void QListBox::invertSelection(){ if ( d->selectionMode == Single || d->selectionMode == NoSelection ) return; bool b = signalsBlocked(); blockSignals( TRUE ); for ( int i = 0; i < (int)count(); i++ ) setSelected( i, !item( i )->selected() ); blockSignals( b ); emit selectionChanged();}/*! \obsolete Not used anymore, available only for binary compatibility*/void QListBox::emitChangedSignal( bool ){}/*! \reimp */QSize QListBox::sizeHint() const{ if ( isVisibleTo(0) && d->sizeHint.isValid() ) return d->sizeHint; doLayout(); int i=0; while( i < 10 && i < (int)d->columnPos.size()-1 && d->columnPos[i] < 200 ) i++; int x; x = QMIN( 200, d->columnPos[i] ); x = QMAX( 40, x ); i = 0; while( i < 10 && i < (int)d->rowPos.size()-1 && d->
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -