X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/c91c770ef1a60e7966048ece0ebfe861c8b288d1..abb6807645598e8117e98bbf232cd9cd90fe019a:/src/dolphinviewautoscroller.cpp diff --git a/src/dolphinviewautoscroller.cpp b/src/dolphinviewautoscroller.cpp index 767a5b458..cfd3543a5 100644 --- a/src/dolphinviewautoscroller.cpp +++ b/src/dolphinviewautoscroller.cpp @@ -26,17 +26,20 @@ #include #include #include +#include DolphinViewAutoScroller::DolphinViewAutoScroller(QAbstractItemView* parent) : QObject(parent), m_rubberBandSelection(false), + m_keyPressed(false), m_horizontalScrollInc(0), m_verticalScrollInc(0), m_itemView(parent), - m_timer() + m_timer(0) { m_itemView->setAutoScroll(false); m_itemView->viewport()->installEventFilter(this); + m_itemView->installEventFilter(this); m_timer = new QTimer(this); m_timer->setSingleShot(false); @@ -48,6 +51,23 @@ DolphinViewAutoScroller::~DolphinViewAutoScroller() { } +bool DolphinViewAutoScroller::isActive() const +{ + return m_timer->isActive(); +} + +void DolphinViewAutoScroller::handleCurrentIndexChange(const QModelIndex& current, + const QModelIndex& previous) +{ + // When the autoscroller is inactive and a key has been pressed, it must be + // assured that the current item stays visible. The check whether the previous + // item is valid is important because of #197951. The keypress check is done + // because of #199833. + if (current.isValid() && (previous.isValid() || m_keyPressed) && !isActive()) { + m_itemView->scrollTo(current); + } +} + bool DolphinViewAutoScroller::eventFilter(QObject* watched, QEvent* event) { if (watched == m_itemView->viewport()) { @@ -81,6 +101,19 @@ bool DolphinViewAutoScroller::eventFilter(QObject* watched, QEvent* event) stopAutoScroll(); break; + default: + break; + } + } else if (watched == m_itemView) { + switch (event->type()) { + case QEvent::KeyPress: + m_keyPressed = true; + break; + + case QEvent::KeyRelease: + m_keyPressed = false; + break; + default: break; } @@ -155,18 +188,18 @@ int DolphinViewAutoScroller::calculateScrollIncrement(int cursorPos, int rangeSi { int inc = 0; - const int minSpeed = 2; - const int maxSpeed = 32; - const int speedLimiter = 8; - const int autoScrollBorder = 32; + const int minSpeed = 4; + const int maxSpeed = 768; + const int speedLimiter = 48; + const int autoScrollBorder = 64; if (cursorPos < autoScrollBorder) { - inc = -minSpeed + (cursorPos - autoScrollBorder) / speedLimiter; + inc = -minSpeed + qAbs(cursorPos - autoScrollBorder) * (cursorPos - autoScrollBorder) / speedLimiter; if (inc < -maxSpeed) { inc = -maxSpeed; } } else if (cursorPos > rangeSize - autoScrollBorder) { - inc = minSpeed + (cursorPos - rangeSize + autoScrollBorder) / speedLimiter; + inc = minSpeed + qAbs(cursorPos - rangeSize + autoScrollBorder) * (cursorPos - rangeSize + autoScrollBorder) / speedLimiter; if (inc > maxSpeed) { inc = maxSpeed; }