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

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

For internal use only.

Scroll the view contents by dx and dy.

Reimplemented from QAbstractScrollArea.

Definition at line 636 of file qlistview.cpp.

References QAbstractScrollArea::horizontalScrollBar(), QAbstractItemView::horizontalScrollMode, QWidget::isRightToLeft(), QAbstractItemView::state(), QAbstractScrollArea::verticalScrollBar(), and QAbstractItemView::verticalScrollMode.

{
    Q_D(QListView);

    dx = isRightToLeft() ? -dx : dx;

    // ### reorder this logic
    if (d->movement == Static) {
        const bool vertical = verticalScrollMode() == QAbstractItemView::ScrollPerItem;
        const bool horizontal = horizontalScrollMode() == QAbstractItemView::ScrollPerItem;
        if (d->wrap) {
            if (d->segmentPositions.isEmpty())
                return;
            const int max = d->segmentPositions.count() - 1;
            if (horizontal && d->flow == TopToBottom && dx != 0) {
                int currentValue = qBound(0, horizontalScrollBar()->value(), max);
                int previousValue = qBound(0, currentValue + dx, max);
                int currentCoordinate = d->segmentPositions.at(currentValue);
                int previousCoordinate = d->segmentPositions.at(previousValue);
                dx = previousCoordinate - currentCoordinate;
            } else if (vertical && d->flow == LeftToRight && dy != 0) {
                int currentValue = qBound(0, verticalScrollBar()->value(), max);
                int previousValue = qBound(0, currentValue + dy, max);
                int currentCoordinate = d->segmentPositions.at(currentValue);
                int previousCoordinate = d->segmentPositions.at(previousValue);
                dy = previousCoordinate - currentCoordinate;
            }
        } else {
            if (d->flowPositions.isEmpty())
                return;
            const int max = d->flowPositions.count() - 1;
            if (vertical && d->flow == TopToBottom && dy != 0) {
                int currentValue = qBound(0, verticalScrollBar()->value(), max);
                int previousValue = qBound(0, currentValue + dy, max);
                int currentCoordinate = d->flowPositions.at(currentValue);
                int previousCoordinate = d->flowPositions.at(previousValue);
                dy = previousCoordinate - currentCoordinate;
            } else if (horizontal && d->flow == LeftToRight && dx != 0) {
                int currentValue = qBound(0, horizontalScrollBar()->value(), max);
                int previousValue = qBound(0, currentValue + dx, max);
                int currentCoordinate = d->flowPositions.at(currentValue);
                int previousCoordinate = d->flowPositions.at(previousValue);
                dx = previousCoordinate - currentCoordinate;
            }
        }
    }

    if (state() == DragSelectingState) {
        if (dx > 0) // right
            d->elasticBand.moveRight(d->elasticBand.right() + dx);
        else if (dx < 0) // left
            d->elasticBand.moveLeft(d->elasticBand.left() - dx);
        if (dy > 0) // down
            d->elasticBand.moveBottom(d->elasticBand.bottom() + dy);
        else if (dy < 0) // up
            d->elasticBand.moveTop(d->elasticBand.top() - dy);
    }

    d->scrollContentsBy(dx, dy);

    // update the dragged items
    if (!d->draggedItems.isEmpty())
        d->setDirtyRegion(d->draggedItemsRect().translated(dx, dy));
}


Generated by  Doxygen 1.6.0   Back to index