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

void QTreeView::scrollContentsBy ( int  dx,
int  dy 
) [protected, virtual, inherited]

Scrolls the contents of the tree view by (dx, dy).

Reimplemented from QAbstractScrollArea.

Definition at line 1272 of file qtreeview.cpp.

References QAbstractScrollArea::horizontalScrollBar(), QWidget::isRightToLeft(), QWidget::repaint(), QAbstractSlider::value, QAbstractScrollArea::verticalScrollBar(), and QAbstractItemView::verticalStepsPerItem().

{
    Q_D(QTreeView);

    dx = isRightToLeft() ? -dx : dx;

    if (dx)
        d->header->setOffset(horizontalScrollBar()->value());

    if (d->viewItems.isEmpty())
        return;

    // guestimate the number of items in the viewport
    int viewCount = d->viewport->height() / d->itemHeight;
    int maxDeltaY = verticalStepsPerItem() * qMin(d->viewItems.count(), viewCount);

    // no need to do a lot of work if we are going to redraw the whole thing anyway
    if (qAbs(dy) > qAbs(maxDeltaY) && d->editors.isEmpty()) {
        verticalScrollBar()->repaint();
        d->viewport->update();
        return;
    }

    if (dy) {
        int steps = verticalStepsPerItem();
        int currentScrollbarValue = verticalScrollBar()->value();
        int previousScrollbarValue = currentScrollbarValue + dy; // -(-dy)
        int currentViewIndex = currentScrollbarValue / steps; // the first visible item
        int previousViewIndex = previousScrollbarValue / steps;

        const QVector<QTreeViewItem> viewItems = d->viewItems;

        int currentY = d->topItemDelta(currentScrollbarValue, d->height(currentViewIndex));
        int previousY = currentY;
        if ((previousViewIndex >= 0) && (previousViewIndex < d->viewItems.size()))
            previousY = d->topItemDelta(previousScrollbarValue, d->height(previousViewIndex));

        dy = currentY - previousY;
        if (previousViewIndex < currentViewIndex) { // scrolling down
            for (int i = previousViewIndex; i < currentViewIndex; ++i)
                dy -= d->height(i);
        } else if (previousViewIndex > currentViewIndex) { // scrolling up
            for (int i = previousViewIndex - 1; i >= currentViewIndex; --i)
                dy += d->height(i);
        }
    }

    d->scrollContentsBy(dx, dy);
}


Generated by  Doxygen 1.6.0   Back to index