Skip to content
This repository has been archived by the owner on Dec 14, 2021. It is now read-only.

Commit

Permalink
build: Add compatibility layer for Qt versions (#1118)
Browse files Browse the repository at this point in the history
  • Loading branch information
fsimonis authored Dec 7, 2020
1 parent 5cae072 commit f70e9ec
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/lib_gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ add_files(
qt/project_wizard/QtProjectWizardWindow.cpp
qt/project_wizard/QtProjectWizardWindow.h

qt/utility/compatibilityQt.cpp
qt/utility/compatibilityQt.h
qt/utility/QtContextMenu.cpp
qt/utility/QtContextMenu.h
qt/utility/QtDeviceScaledPixmap.cpp
Expand Down
3 changes: 2 additions & 1 deletion src/lib_gui/qt/element/code/QtCodeArea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "utility.h"
#include "utilityApp.h"
#include "utilityString.h"
#include "compatibilityQt.h"

MouseWheelOverScrollbarFilter::MouseWheelOverScrollbarFilter() {}

Expand All @@ -40,7 +41,7 @@ bool MouseWheelOverScrollbarFilter::eventFilter(QObject* obj, QEvent* event)
if (event->type() == QEvent::Wheel && scrollbar)
{
QRect scrollbarArea(scrollbar->pos(), scrollbar->size());
QPoint globalMousePos = dynamic_cast<QWheelEvent*>(event)->globalPos();
QPoint globalMousePos = utility::compatibility::QWheelEvent_globalPos(*dynamic_cast<QWheelEvent*>(event));
QPoint localMousePos = scrollbar->mapFromGlobal(globalMousePos);

// instead of "scrollbar->underMouse()" we need this check implemented here because
Expand Down
18 changes: 18 additions & 0 deletions src/lib_gui/qt/utility/compatibilityQt.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include "compatibilityQt.h"

#include <QtGlobal>

namespace utility
{
namespace compatibility
{
QPoint QWheelEvent_globalPos(const QWheelEvent& event)
{
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
return event.globalPosition().toPoint();
#else
return event.globalPos();
#endif
}
} // namespace compatibility
} // namespace utility
17 changes: 17 additions & 0 deletions src/lib_gui/qt/utility/compatibilityQt.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#ifndef COMPATIBILITY_QT_H
#define COMPATIBILITY_QT_H

#include <QWheelEvent>

namespace utility
{
namespace compatibility
{
// Extracts the global position from a QWheelEvent.
// This compatibility wrapper bridges Qt 5.12 and Qt 5.14
QPoint QWheelEvent_globalPos(const QWheelEvent& event);

} // namespace compatibility
} // namespace utility

#endif // COMPATIBILITY_QT_H

0 comments on commit f70e9ec

Please sign in to comment.