build: Add compatibility layer for Qt versions (#1118)

This commit is contained in:
Frédéric Simonis
2020-12-07 15:34:14 +01:00
committed by GitHub
parent 5cae072a02
commit f70e9ecbc4
4 changed files with 39 additions and 1 deletions
+2
View File
@@ -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
+2 -1
View File
@@ -31,6 +31,7 @@
#include "utility.h"
#include "utilityApp.h"
#include "utilityString.h"
#include "compatibilityQt.h"
MouseWheelOverScrollbarFilter::MouseWheelOverScrollbarFilter() {}
@@ -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
@@ -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
View File
@@ -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