Logo Search packages:      
Sourcecode: kdbg version File versions

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

Reimplemented for key handling. If there are any items in the KTreeView, but there is no current item, the topmost item is made current. The key press event is first forwarded to the current item by calling KTreeViewItem::keyEvent.

Definition at line 1489 of file ktreeview.cpp.

References collapseSubTree(), currentItem(), expandSubTree(), KTreeViewItem::getParent(), KTreeViewItem::hasChild(), KTreeViewItem::isExpanded(), KTreeViewItem::isVisible(), itemAt(), itemRow(), scrollVisible(), selected(), and setCurrentItem().

{
    if (numRows() == 0)
      return;                       /* nothing to do */

    /* if there's no current item, make the top item current */
    if (currentItem() < 0)
      setCurrentItem(topCell());
    assert(currentItem() >= 0);           /* we need a current item */
    assert(itemAt(currentItem()) != 0);   /* we really need a current item */

    // give currentItem a chance to handle the event
    if (itemAt(currentItem())->keyEvent(e))
      return;                       /* handled */

    int pageSize, delta;
    KTreeViewItem* item;
    int key = e->key();
repeat:
    switch (key) {
    case Key_Up:
      // make previous item current, scroll up if necessary
      if (currentItem() > 0) {
          setCurrentItem(currentItem() - 1);
          scrollVisible(itemAt(currentItem()), false);
      }
      break;
    case Key_Down:
      // make next item current, scroll down if necessary
      if (currentItem() < numRows() - 1) {
          setCurrentItem(currentItem() + 1);
          if (currentItem() > lastRowVisible()) {
            // scrollVisible is not feasible here because
            // it scrolls the item to the top
            setTopCell(topCell() + currentItem() - lastRowVisible());
          } else if (currentItem() < topCell()) {
            setTopCell(currentItem());
          }
      }
      break;
    case Key_Next:
      // move highlight one page down and scroll down
      delta = currentItem() - topCell();
      pageSize = lastRowVisible() - topCell();
      setTopCell(QMIN(topCell() +  pageSize, numRows() - 1));
      setCurrentItem(QMIN(topCell() + delta, numRows() - 1));
      break;
    case Key_Prior:
      // move highlight one page up and scroll up
      delta = currentItem() - topCell();
      pageSize = lastRowVisible() - topCell();
      setTopCell(QMAX(topCell() - pageSize, 0));
      setCurrentItem(QMAX(topCell() + delta, 0));
      break;
    case Key_Plus:
    case Key_Right:
      // if current item has subtree and is collapsed, expand it
      item = itemAt(currentItem());
      if (item->isExpanded() && item->hasChild() && key == Key_Right) {
          // going right on an expanded item is like going down
          key = Key_Down;
          goto repeat;
      } else {
          expandSubTree(item, true);
          scrollVisible(item, true);
      }
      break;
    case Key_Minus:
    case Key_Left:
      // if current item has subtree and is expanded, collapse it
      item = itemAt(currentItem());
      if ((!item->isExpanded() || !item->hasChild()) && key == Key_Left) {
          // going left on a collapsed item goes to its parent
          item = item->getParent();
          if (item == treeRoot)
            break;                  /* we're already at the top */
          assert(item->isVisible());
          setCurrentItem(itemRow(item));
      } else {
          collapseSubTree(item, true);
      }
      scrollVisible(item, false);
      break;
    case Key_Return:
    case Key_Enter:
      // select the current item
      if (currentItem() >= 0)
          emit selected(currentItem());
      break;
    default:
      break;
    }
}


Generated by  Doxygen 1.6.0   Back to index