Logo Search packages:      
Sourcecode: kdbg version File versions

void KTreeView::scrollVisible ( KTreeViewItem item,
bool  children 
)

The specified item is scrolled into view. If the specified item is already visible, nothing happens, unless children is true, in which case the display is scrolled such that the item and as many of its child items as possible are visible.

Parameters:
item specifies the item to make visible
children specifies whether children should be made visible

Definition at line 1028 of file ktreeview.cpp.

References countItem(), forEveryVisibleItem(), KTreeViewItem::isExpanded(), and itemRow().

Referenced by keyPressEvent(), and mousePressEvent().

{
    if (item == 0)
      return;
    int row = itemRow(item);
    if (row < 0)
      return;                       /* do nothing if invisible */

    if (children && item->isExpanded()) {
      // we are concerned about children
      if (!rowIsVisible(row)) {
          // just move to the top
          setTopCell(row);
      } else {
          // this is the complicated part
          // count the visible children (including grandchildren)
          int numVisible = 0;
          forEveryVisibleItem(countItem, &numVisible, item);
          // if the last child is visible, do nothing
          if (rowIsVisible(row + numVisible))
            return;
          /*
           * Basically, item will become the top cell; but if there are
           * more visible rows in the widget than we have children, then
           * we don't move that far.
           */
          int remain = lastRowVisible()-topCell()-numVisible;
          if (remain <= 0) {
            setTopCell(row);
          } else {
            setTopCell(QMAX(0,row-remain));
          }
      }
    } else {
      // we are not concerned about children
      if (rowIsVisible(row))
          return;
      // just move the item to the top
      setTopCell(row);
    }
}


Generated by  Doxygen 1.6.0   Back to index