diff --git a/src/AutoHideSideBar.cpp b/src/AutoHideSideBar.cpp index 7dea2fe3..7e32b46b 100644 --- a/src/AutoHideSideBar.cpp +++ b/src/AutoHideSideBar.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include "DockContainerWidget.h" #include "DockWidgetTab.h" @@ -300,6 +301,13 @@ bool CAutoHideSideBar::eventFilter(QObject *watched, QEvent *event) } break; +#if QT_CONFIG(wheelevent) + case QEvent::Wheel: + // the button received the event so pass to the scroll area + wheelEvent(static_cast(event)); + break; +#endif + default: break; } @@ -433,6 +441,41 @@ QSize CAutoHideSideBar::sizeHint() const } +//=========================================================================== +#if QT_CONFIG(wheelevent) +void CAutoHideSideBar::wheelEvent(QWheelEvent* e) +{ + QPoint AngleDelta = e->angleDelta(); + + // completely ignore the effects if the alt key is being held + // if alt is held on a vertical scroll area, cancel the applied horizontal scroll by forcing a vertical scroll + // if alt is held on a horizontal scroll area, cancel the applied vertical scroll by forcing a horizontal scroll + if (!d->isHorizontal() && (e->modifiers() & Qt::KeyboardModifier::AltModifier) || + d->isHorizontal() && (~e->modifiers() & Qt::KeyboardModifier::AltModifier)) + { + AngleDelta = e->angleDelta().transposed(); + } + + QWheelEvent WheelEvent { + e->position(), + e->globalPosition(), + e->pixelDelta(), + AngleDelta, + e->buttons(), + e->modifiers(), + e->phase(), + e->inverted(), + e->source() +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) + ,e->pointingDevice() +#endif + }; + + Super::wheelEvent(&WheelEvent); +} +#endif + + //=========================================================================== int CAutoHideSideBar::spacing() const { diff --git a/src/AutoHideSideBar.h b/src/AutoHideSideBar.h index 35056825..f10aa20d 100644 --- a/src/AutoHideSideBar.h +++ b/src/AutoHideSideBar.h @@ -185,6 +185,16 @@ class ADS_EXPORT CAutoHideSideBar : public QScrollArea */ virtual QSize sizeHint() const override; +#if QT_CONFIG(wheelevent) + /** + * This function handles scroll wheel events and will ignore the + * alt key modifier if applied by the user to make sure vertical + * auto-hide side bars will always scroll vertically and that + * horizontal ones will always scroll horizontally. + */ + virtual void wheelEvent(QWheelEvent* e) override; +#endif + /** * Getter for spacing property - returns the spacing of the tabs */