Cover Grid: Improve scroll wheel based scrolling.

On windows and linux a single "tick" of the wheel now scrolls by about
half a row. On OS X, scrolling is pixel based, so as you scroll faster,
more content is scrolled.
This commit is contained in:
Kovid Goyal 2014-11-06 12:36:58 +05:30
parent 264312d2b7
commit c05bb2ee69

View File

@ -6,7 +6,7 @@ from __future__ import (unicode_literals, division, absolute_import,
__license__ = 'GPL v3'
__copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
import itertools, operator, os
import itertools, operator, os, math
from types import MethodType
from threading import Event, Thread
from Queue import LifoQueue
@ -981,4 +981,19 @@ class GridView(QListView):
return QItemSelectionModel.ClearAndSelect | QItemSelectionModel.Rows
return super(GridView, self).selectionCommand(index, event)
def wheelEvent(self, ev):
if ev.phase() != Qt.ScrollUpdate:
return
number_of_pixels = ev.pixelDelta()
number_of_degrees = ev.angleDelta() / 8
b = self.verticalScrollBar()
if number_of_pixels.isNull():
dy = number_of_degrees.y() / 15.0
# Scroll by approximately half a row
dy = int(math.ceil((dy) * b.singleStep() / 2.0))
else:
dy = number_of_pixels.y()
if abs(dy) > 0:
b.setValue(b.value() - dy)
# }}}