wheel scrolling improved
This commit is contained in:
parent
acbb5d1c0b
commit
cec696a78b
|
@ -273,6 +273,25 @@ void QskListView::mouseReleaseEvent( QMouseEvent* event )
|
||||||
|
|
||||||
#ifndef QT_NO_WHEELEVENT
|
#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 QskListView::scrollOffset( const QWheelEvent* event ) const
|
||||||
{
|
{
|
||||||
QPointF offset;
|
QPointF offset;
|
||||||
|
@ -300,6 +319,7 @@ QPointF QskListView::scrollOffset( const QWheelEvent* event ) const
|
||||||
}
|
}
|
||||||
else if ( offset.y() != 0.0 )
|
else if ( offset.y() != 0.0 )
|
||||||
{
|
{
|
||||||
|
const qreal y0 = scrollPos().y();
|
||||||
const auto viewHeight = viewContentsRect().height();
|
const auto viewHeight = viewContentsRect().height();
|
||||||
const qreal rowHeight = this->rowHeight();
|
const qreal rowHeight = this->rowHeight();
|
||||||
|
|
||||||
|
@ -312,11 +332,15 @@ QPointF QskListView::scrollOffset( const QWheelEvent* event ) const
|
||||||
if ( event->modifiers() & ( Qt::ControlModifier | Qt::ShiftModifier ) )
|
if ( event->modifiers() & ( Qt::ControlModifier | Qt::ShiftModifier ) )
|
||||||
dy = qMax( dy, viewHeight );
|
dy = qMax( dy, viewHeight );
|
||||||
|
|
||||||
// we should align to row boundaries. TODO ...
|
dy *= offset.y(); // multiplied by the wheelsteps
|
||||||
offset.setY( offset.y() * dy );
|
|
||||||
|
// 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;
|
return offset;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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"
|
#include "moc_QskScrollArea.cpp"
|
||||||
|
|
|
@ -44,6 +44,10 @@ class QSK_EXPORT QskScrollArea : public QskScrollView
|
||||||
void updateLayout() override;
|
void updateLayout() override;
|
||||||
QSizeF layoutSizeHint( Qt::SizeHint, const QSizeF& ) const override;
|
QSizeF layoutSizeHint( Qt::SizeHint, const QSizeF& ) const override;
|
||||||
|
|
||||||
|
#ifndef QT_NO_WHEELEVENT
|
||||||
|
QPointF scrollOffset( const QWheelEvent* ) const override;
|
||||||
|
#endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void translateItem();
|
void translateItem();
|
||||||
void adjustItem();
|
void adjustItem();
|
||||||
|
|
Loading…
Reference in New Issue