wheel scrolling improved

This commit is contained in:
Uwe Rathmann 2022-01-17 09:46:27 +01:00
parent acbb5d1c0b
commit cec696a78b
3 changed files with 41 additions and 3 deletions

View File

@ -273,6 +273,25 @@ void QskListView::mouseReleaseEvent( QMouseEvent* event )
#ifndef QT_NO_WHEELEVENT
static qreal qskAlignedToRows( const qreal y0, qreal dy,
qreal rowHeight, qreal viewHeight )
{
qreal y = y0 - dy;
if ( dy > 0 )
{
y = qFloor( y / rowHeight ) * rowHeight;
}
else
{
y += viewHeight;
y = qCeil( y / rowHeight ) * rowHeight;
y -= viewHeight;
}
return y;
}
QPointF QskListView::scrollOffset( const QWheelEvent* event ) const
{
QPointF offset;
@ -300,6 +319,7 @@ QPointF QskListView::scrollOffset( const QWheelEvent* event ) const
}
else if ( offset.y() != 0.0 )
{
const qreal y0 = scrollPos().y();
const auto viewHeight = viewContentsRect().height();
const qreal rowHeight = this->rowHeight();
@ -312,11 +332,15 @@ QPointF QskListView::scrollOffset( const QWheelEvent* event ) const
if ( event->modifiers() & ( Qt::ControlModifier | Qt::ShiftModifier ) )
dy = qMax( dy, viewHeight );
// we should align to row boundaries. TODO ...
offset.setY( offset.y() * dy );
dy *= offset.y(); // multiplied by the wheelsteps
// aligning rows that enter the view
dy = qskAlignedToRows( y0, dy, rowHeight, viewHeight );
offset.setY( y0 - dy );
}
// using the animated scrollTo instead ?
// TODO using the animated scrollTo instead ?
return offset;
}

View File

@ -644,4 +644,14 @@ void QskScrollArea::translateItem()
}
}
#ifndef QT_NO_WHEELEVENT
QPointF QskScrollArea::scrollOffset( const QWheelEvent* event ) const
{
// TODO: what to do here ???
return Inherited::scrollOffset( event );
}
#endif
#include "moc_QskScrollArea.cpp"

View File

@ -44,6 +44,10 @@ class QSK_EXPORT QskScrollArea : public QskScrollView
void updateLayout() override;
QSizeF layoutSizeHint( Qt::SizeHint, const QSizeF& ) const override;
#ifndef QT_NO_WHEELEVENT
QPointF scrollOffset( const QWheelEvent* ) const override;
#endif
private:
void translateItem();
void adjustItem();