19 #include <QMouseEvent>
21 #include <QAbstractItemView>
27 : QScrollArea( parent )
28 , mFilter( new ScrollAreaFilter( this, viewport() ) )
30 viewport()->installEventFilter( mFilter );
31 setMouseTracking(
true );
38 QScrollArea::wheelEvent( e );
43 if ( mVerticalOnly && widget() )
44 widget()->setFixedWidth( event->size().width() );
45 QScrollArea::resizeEvent( event );
50 mTimer.setSingleShot(
true );
56 return mTimer.isActive();
66 mVerticalOnly = verticalOnly;
68 setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
70 if ( mVerticalOnly && widget() )
71 widget()->setFixedWidth( size().width() );
76 ScrollAreaFilter::ScrollAreaFilter(
QgsScrollArea *parent, QWidget *viewPort )
78 , mScrollAreaWidget( parent )
79 , mViewPort( viewPort )
81 QFontMetrics fm( parent->font() );
82 mMoveDistanceThreshold = fm.horizontalAdvance(
'X' );
85 bool ScrollAreaFilter::eventFilter( QObject *obj, QEvent *event )
87 switch ( event->type() )
89 case QEvent::ChildAdded:
92 QChildEvent *ce =
static_cast<QChildEvent *
>( event );
93 addChild( ce->child() );
97 case QEvent::ChildRemoved:
99 QChildEvent *ce =
static_cast<QChildEvent *
>( event );
100 removeChild( ce->child() );
104 case QEvent::MouseMove:
106 if ( obj == mViewPort )
108 const QPoint mouseDelta = QCursor::pos() - mPreviousViewportCursorPos;
109 if ( mouseDelta.manhattanLength() > mMoveDistanceThreshold )
113 mScrollAreaWidget->resetHasScrolled();
115 mPreviousViewportCursorPos = QCursor::pos();
122 if ( obj == mViewPort )
125 mScrollAreaWidget->scrollOccurred();
129 if ( mScrollAreaWidget->hasScrolled() )
141 return QObject::eventFilter( obj, event );
144 void ScrollAreaFilter::addChild( QObject *child )
146 if ( child && child->isWidgetType() )
148 if ( qobject_cast< QScrollArea * >( child ) || qobject_cast< QAbstractItemView * >( child ) )
151 child->installEventFilter(
this );
152 if ( QWidget *w = qobject_cast< QWidget * >( child ) )
153 w->setMouseTracking(
true );
156 const auto constChildren = child->children();
157 for ( QObject *
c : constChildren )
164 void ScrollAreaFilter::removeChild( QObject *child )
166 if ( child && child->isWidgetType() )
168 if ( qobject_cast< QScrollArea * >( child ) || qobject_cast< QAbstractItemView * >( child ) )
171 child->removeEventFilter(
this );
174 const auto constChildren = child->children();
175 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