QAbstractItemView - prepare fix for auto scroll on sectionmove
There are no semantic changes in this patch. We just avoid many calls to horizontalScrollBar() and verticalScrollBar() by storing the result of them in local variables, that are used instead. This is just a prepare for auto-scroll when a user is moving a section. Change-Id: I4b3d3ecbf3a29992e6f578d4b0442d7f494125e4 Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
This commit is contained in:
parent
02c110e989
commit
c6754c2720
@ -3746,30 +3746,33 @@ void QAbstractItemView::doAutoScroll()
|
||||
{
|
||||
// find how much we should scroll with
|
||||
Q_D(QAbstractItemView);
|
||||
int verticalStep = verticalScrollBar()->pageStep();
|
||||
int horizontalStep = horizontalScrollBar()->pageStep();
|
||||
QScrollBar *verticalScroll = verticalScrollBar();
|
||||
QScrollBar *horizontalScroll = horizontalScrollBar();
|
||||
|
||||
int verticalStep = verticalScroll->pageStep();
|
||||
int horizontalStep = horizontalScroll->pageStep();
|
||||
if (d->autoScrollCount < qMax(verticalStep, horizontalStep))
|
||||
++d->autoScrollCount;
|
||||
|
||||
int margin = d->autoScrollMargin;
|
||||
int verticalValue = verticalScrollBar()->value();
|
||||
int horizontalValue = horizontalScrollBar()->value();
|
||||
int verticalValue = verticalScroll->value();
|
||||
int horizontalValue = horizontalScroll->value();
|
||||
|
||||
QPoint pos = d->viewport->mapFromGlobal(QCursor::pos());
|
||||
QRect area = static_cast<QAbstractItemView*>(d->viewport)->d_func()->clipRect(); // access QWidget private by bending C++ rules
|
||||
|
||||
// do the scrolling if we are in the scroll margins
|
||||
if (pos.y() - area.top() < margin)
|
||||
verticalScrollBar()->setValue(verticalValue - d->autoScrollCount);
|
||||
verticalScroll->setValue(verticalValue - d->autoScrollCount);
|
||||
else if (area.bottom() - pos.y() < margin)
|
||||
verticalScrollBar()->setValue(verticalValue + d->autoScrollCount);
|
||||
verticalScroll->setValue(verticalValue + d->autoScrollCount);
|
||||
if (pos.x() - area.left() < margin)
|
||||
horizontalScrollBar()->setValue(horizontalValue - d->autoScrollCount);
|
||||
horizontalScroll->setValue(horizontalValue - d->autoScrollCount);
|
||||
else if (area.right() - pos.x() < margin)
|
||||
horizontalScrollBar()->setValue(horizontalValue + d->autoScrollCount);
|
||||
horizontalScroll->setValue(horizontalValue + d->autoScrollCount);
|
||||
// if nothing changed, stop scrolling
|
||||
bool verticalUnchanged = (verticalValue == verticalScrollBar()->value());
|
||||
bool horizontalUnchanged = (horizontalValue == horizontalScrollBar()->value());
|
||||
bool verticalUnchanged = (verticalValue == verticalScroll->value());
|
||||
bool horizontalUnchanged = (horizontalValue == horizontalScroll->value());
|
||||
if (verticalUnchanged && horizontalUnchanged) {
|
||||
stopAutoScroll();
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user