17#include "moc_qgsscrollarea.cpp"
22#include <QAbstractItemView>
28 : QScrollArea( parent )
29 , mFilter( new ScrollAreaFilter( this, viewport() ) )
31 viewport()->installEventFilter( mFilter );
32 setMouseTracking(
true );
39 QScrollArea::wheelEvent( e );
44 if ( mVerticalOnly && widget() )
45 widget()->setFixedWidth( event->size().width() );
46 QScrollArea::resizeEvent( event );
51 mTimer.setSingleShot(
true );
57 return mTimer.isActive();
67 mVerticalOnly = verticalOnly;
69 setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
71 if ( mVerticalOnly && widget() )
72 widget()->setFixedWidth( size().width() );
77ScrollAreaFilter::ScrollAreaFilter(
QgsScrollArea *parent, QWidget *viewPort )
79 , mScrollAreaWidget( parent )
80 , mViewPort( viewPort )
82 QFontMetrics fm( parent->font() );
83 mMoveDistanceThreshold = fm.horizontalAdvance(
'X' );
86bool ScrollAreaFilter::eventFilter( QObject *obj, QEvent *event )
88 switch ( event->type() )
90 case QEvent::ChildAdded:
93 QChildEvent *ce =
static_cast<QChildEvent *
>( event );
94 addChild( ce->child() );
98 case QEvent::ChildRemoved:
100 QChildEvent *ce =
static_cast<QChildEvent *
>( event );
101 removeChild( ce->child() );
105 case QEvent::MouseMove:
107 if ( obj == mViewPort )
109 const QPoint mouseDelta = QCursor::pos() - mPreviousViewportCursorPos;
110 if ( mouseDelta.manhattanLength() > mMoveDistanceThreshold )
114 mScrollAreaWidget->resetHasScrolled();
116 mPreviousViewportCursorPos = QCursor::pos();
123 if ( obj == mViewPort )
126 mScrollAreaWidget->scrollOccurred();
130 if ( mScrollAreaWidget->hasScrolled() )
142 return QObject::eventFilter( obj, event );
145void ScrollAreaFilter::addChild( QObject *child )
147 if ( child && child->isWidgetType() )
149 if ( qobject_cast< QScrollArea * >( child ) || qobject_cast< QAbstractItemView * >( child ) )
152 child->installEventFilter(
this );
153 if ( QWidget *w = qobject_cast< QWidget * >( child ) )
154 w->setMouseTracking(
true );
157 const auto constChildren = child->children();
158 for ( QObject *
c : constChildren )
165void ScrollAreaFilter::removeChild( QObject *child )
167 if ( child && child->isWidgetType() )
169 if ( qobject_cast< QScrollArea * >( child ) || qobject_cast< QAbstractItemView * >( child ) )
172 child->removeEventFilter(
this );
175 const auto constChildren = child->children();
176 for ( QObject *
c : constChildren )
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c