diff options
| author | Peter Penz <[email protected]> | 2011-08-20 13:52:36 +0200 |
|---|---|---|
| committer | Peter Penz <[email protected]> | 2011-08-20 13:54:20 +0200 |
| commit | 074acd8009765f5e6ad5cb7f1887d50f4aea5a58 (patch) | |
| tree | d182a0fc286dfe214bd33bd5b04a1d6605958685 /src/kitemviews/kitemlistview.cpp | |
| parent | dbe2152912cc58f1d2bfba187175ec0e4b3e4761 (diff) | |
Fix possible endless recursion when using the rubberband
If the autoscrolling has been activated when using the rubberband,
it was possible that an endless recursion occured as the
autoscrolling triggered a change of the rubberband which triggered
a change of the autoscrolling etc.
Diffstat (limited to 'src/kitemviews/kitemlistview.cpp')
| -rw-r--r-- | src/kitemviews/kitemlistview.cpp | 37 |
1 files changed, 26 insertions, 11 deletions
diff --git a/src/kitemviews/kitemlistview.cpp b/src/kitemviews/kitemlistview.cpp index 3b6b4e2e9..f6cfed984 100644 --- a/src/kitemviews/kitemlistview.cpp +++ b/src/kitemviews/kitemlistview.cpp @@ -678,7 +678,9 @@ void KItemListView::slotCurrentChanged(int current, int previous) } } - emit scrollTo(newOffset); + if (newOffset != offset()) { + emit scrollTo(newOffset); + } } } @@ -749,7 +751,11 @@ void KItemListView::slotRubberBandStartPosChanged() void KItemListView::slotRubberBandEndPosChanged() { - triggerAutoScrolling(); + // The autoscrolling is triggered asynchronously otherwise it + // might be possible to have an endless recursion: The autoscrolling + // might adjust the position which might result in updating the + // rubberband end-position. + QTimer::singleShot(0, this, SLOT(triggerAutoScrolling())); update(); } @@ -766,6 +772,24 @@ void KItemListView::slotRubberBandActivationChanged(bool active) update(); } +void KItemListView::triggerAutoScrolling() +{ + int pos = 0; + int visibleSize = 0; + if (scrollOrientation() == Qt::Vertical) { + pos = m_mousePos.y(); + visibleSize = size().height(); + } else { + pos = m_mousePos.x(); + visibleSize = size().width(); + } + + const int inc = calculateAutoScrollingIncrement(pos, visibleSize); + if (inc != 0) { + emit scrollTo(offset() + inc); + } +} + void KItemListView::setController(KItemListController* controller) { if (m_controller != controller) { @@ -1172,15 +1196,6 @@ void KItemListView::updateWidgetProperties(KItemListWidget* widget, int index) widget->setData(m_model->data(index)); } -void KItemListView::triggerAutoScrolling() -{ - const int pos = (scrollOrientation() == Qt::Vertical) ? m_mousePos.y() : m_mousePos.x(); - const int inc = calculateAutoScrollingIncrement(pos, size().height()); - if (inc != 0) { - emit scrollTo(offset() + inc); - } -} - int KItemListView::calculateAutoScrollingIncrement(int pos, int size) { int inc = 0; |
