wheelEvent handling improved
This commit is contained in:
parent
d4f140f20e
commit
379a6f6ccc
@ -207,7 +207,7 @@ void QskBoundedInput::wheelEvent( QWheelEvent* event )
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto offset = qskWheelSteps( event ) * m_stepSize;
|
auto offset = qskWheelIncrement( event ) * m_stepSize;
|
||||||
if ( event->modifiers() & ( Qt::ControlModifier | Qt::ShiftModifier ) )
|
if ( event->modifiers() & ( Qt::ControlModifier | Qt::ShiftModifier ) )
|
||||||
offset *= m_pageSize;
|
offset *= m_pageSize;
|
||||||
|
|
||||||
|
@ -87,52 +87,31 @@ QPointF qskWheelPosition( const QWheelEvent* event )
|
|||||||
|
|
||||||
#ifndef QT_NO_WHEELEVENT
|
#ifndef QT_NO_WHEELEVENT
|
||||||
|
|
||||||
qreal qskWheelSteps( const QWheelEvent* event, int orientation )
|
qreal qskWheelSteps( const QWheelEvent* event )
|
||||||
{
|
{
|
||||||
qreal delta = 0.0;
|
const auto angleDelta = event->angleDelta();
|
||||||
|
|
||||||
// what about event->pixelDelta()
|
|
||||||
auto aDelta = event->angleDelta();
|
|
||||||
|
|
||||||
#if QT_VERSION >= QT_VERSION_CHECK( 5, 7, 0 )
|
|
||||||
if ( event->inverted() )
|
|
||||||
aDelta.setY( -aDelta.y() );
|
|
||||||
#endif
|
|
||||||
|
|
||||||
switch( orientation )
|
|
||||||
{
|
|
||||||
case Qt::Horizontal:
|
|
||||||
delta = aDelta.x();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case Qt::Vertical:
|
|
||||||
delta = aDelta.y();
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
delta = aDelta.y() ? aDelta.y() : aDelta.x();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
const qreal delta = angleDelta.y() ? angleDelta.y() : angleDelta.x();
|
||||||
return delta / QWheelEvent::DefaultDeltasPerStep;
|
return delta / QWheelEvent::DefaultDeltasPerStep;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qreal qskWheelIncrement( const QWheelEvent* event )
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
Some controls ( f.e a spin box ) are interpreting the wheel to
|
||||||
|
in/decrease a value. For those the physical direction is not relevant
|
||||||
|
and we might have to invert the y delta.
|
||||||
|
*/
|
||||||
|
|
||||||
|
auto angleDelta = event->angleDelta();
|
||||||
|
|
||||||
|
#if QT_VERSION >= QT_VERSION_CHECK( 5, 7, 0 )
|
||||||
|
if ( event->inverted() )
|
||||||
|
angleDelta.setY( -angleDelta.y() );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef QT_NO_WHEELEVENT
|
const qreal delta = angleDelta.y() ? angleDelta.y() : angleDelta.x();
|
||||||
|
return delta / QWheelEvent::DefaultDeltasPerStep;
|
||||||
QPointF qskScrollIncrement( const QWheelEvent* event )
|
|
||||||
{
|
|
||||||
QPointF increment = event->pixelDelta();
|
|
||||||
|
|
||||||
if ( increment.isNull() )
|
|
||||||
{
|
|
||||||
increment = event->angleDelta() / QWheelEvent::DefaultDeltasPerStep;
|
|
||||||
|
|
||||||
constexpr qreal stepSize = 20.0; // how to find this value ???
|
|
||||||
increment *= stepSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
return increment;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -143,10 +143,8 @@ QSK_EXPORT QPointF qskHoverPosition( const QHoverEvent* );
|
|||||||
#ifndef QT_NO_WHEELEVENT
|
#ifndef QT_NO_WHEELEVENT
|
||||||
|
|
||||||
QSK_EXPORT QPointF qskWheelPosition( const QWheelEvent* );
|
QSK_EXPORT QPointF qskWheelPosition( const QWheelEvent* );
|
||||||
QSK_EXPORT qreal qskWheelSteps(
|
QSK_EXPORT qreal qskWheelSteps( const QWheelEvent* );
|
||||||
const QWheelEvent*, int orientation = 0 );
|
QSK_EXPORT qreal qskWheelIncrement( const QWheelEvent* );
|
||||||
|
|
||||||
QSK_EXPORT QPointF qskScrollIncrement( const QWheelEvent* );
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -402,11 +402,21 @@ void QskScrollBox::gestureEvent( QskGestureEvent* event )
|
|||||||
|
|
||||||
QPointF QskScrollBox::scrollOffset( const QWheelEvent* event ) const
|
QPointF QskScrollBox::scrollOffset( const QWheelEvent* event ) const
|
||||||
{
|
{
|
||||||
|
QPointF offset;
|
||||||
|
|
||||||
const auto pos = qskWheelPosition( event );
|
const auto pos = qskWheelPosition( event );
|
||||||
if ( viewContentsRect().contains( pos ) )
|
if ( viewContentsRect().contains( pos ) )
|
||||||
return qskScrollIncrement( event );
|
{
|
||||||
|
offset = event->pixelDelta();
|
||||||
|
|
||||||
return QPointF();
|
if ( offset.isNull() )
|
||||||
|
{
|
||||||
|
offset = event->angleDelta() / QWheelEvent::DefaultDeltasPerStep;
|
||||||
|
offset *= 20.0; // how to find such a value ???
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QskScrollBox::wheelEvent( QWheelEvent* event )
|
void QskScrollBox::wheelEvent( QWheelEvent* event )
|
||||||
|
@ -8,6 +8,9 @@
|
|||||||
#include "QskBoxBorderMetrics.h"
|
#include "QskBoxBorderMetrics.h"
|
||||||
#include "QskEvent.h"
|
#include "QskEvent.h"
|
||||||
|
|
||||||
|
#include <qguiapplication.h>
|
||||||
|
#include <qstylehints.h>
|
||||||
|
|
||||||
QSK_SUBCONTROL( QskScrollView, Panel )
|
QSK_SUBCONTROL( QskScrollView, Panel )
|
||||||
QSK_SUBCONTROL( QskScrollView, Viewport )
|
QSK_SUBCONTROL( QskScrollView, Viewport )
|
||||||
QSK_SUBCONTROL( QskScrollView, HorizontalScrollBar )
|
QSK_SUBCONTROL( QskScrollView, HorizontalScrollBar )
|
||||||
@ -18,6 +21,15 @@ QSK_SUBCONTROL( QskScrollView, VerticalScrollHandle )
|
|||||||
QSK_SYSTEM_STATE( QskScrollView, VerticalHandlePressed, QskAspect::FirstSystemState << 1 )
|
QSK_SYSTEM_STATE( QskScrollView, VerticalHandlePressed, QskAspect::FirstSystemState << 1 )
|
||||||
QSK_SYSTEM_STATE( QskScrollView, HorizontalHandlePressed, QskAspect::FirstSystemState << 2 )
|
QSK_SYSTEM_STATE( QskScrollView, HorizontalHandlePressed, QskAspect::FirstSystemState << 2 )
|
||||||
|
|
||||||
|
static int qskScrollLines()
|
||||||
|
{
|
||||||
|
#if QT_VERSION >= QT_VERSION_CHECK( 5, 9, 0 )
|
||||||
|
return QGuiApplication::styleHints()->wheelScrollLines();
|
||||||
|
#else
|
||||||
|
return 3;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
class QskScrollView::PrivateData
|
class QskScrollView::PrivateData
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -217,24 +229,13 @@ QPointF QskScrollView::scrollOffset( const QWheelEvent* event ) const
|
|||||||
|
|
||||||
if ( subControlRect( VerticalScrollBar ).contains( pos ) )
|
if ( subControlRect( VerticalScrollBar ).contains( pos ) )
|
||||||
{
|
{
|
||||||
const auto increment = qskScrollIncrement( event );
|
const auto steps = qskWheelSteps( event );
|
||||||
offset.setY( increment.y() );
|
offset.setY( steps * qskScrollLines() );
|
||||||
}
|
}
|
||||||
else if ( subControlRect( HorizontalScrollBar ).contains( pos ) )
|
else if ( subControlRect( HorizontalScrollBar ).contains( pos ) )
|
||||||
{
|
{
|
||||||
const auto increment = qskScrollIncrement( event );
|
const auto steps = qskWheelSteps( event );
|
||||||
|
offset.setX( steps * qskScrollLines() );
|
||||||
qreal dx = increment.x();
|
|
||||||
if ( dx == 0 )
|
|
||||||
{
|
|
||||||
dx = increment.y();
|
|
||||||
|
|
||||||
#if QT_VERSION >= QT_VERSION_CHECK( 5, 7, 0 )
|
|
||||||
if ( event->inverted() )
|
|
||||||
dx = -dx;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
offset.setX( dx );
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user