From 8d14068df71c1b9d8eb8910516fa602139cf6d94 Mon Sep 17 00:00:00 2001 From: Uwe Kindler Date: Sat, 2 Jan 2021 20:29:59 +0100 Subject: [PATCH] Fixed QMouseEvent::globalPos() warning --- demo/main.cpp | 2 ++ examples/centralwidget/mainwindow.cpp | 11 ----------- src/DockWidgetTab.cpp | 12 ++++++------ src/ads_globals.h | 14 ++++++++++++++ 4 files changed, 22 insertions(+), 17 deletions(-) diff --git a/demo/main.cpp b/demo/main.cpp index 48c725a..a948786 100644 --- a/demo/main.cpp +++ b/demo/main.cpp @@ -35,9 +35,11 @@ void myMessageOutput(QtMsgType type, const QMessageLogContext &context, const QS int main(int argc, char *argv[]) { +#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); #if QT_VERSION >= 0x050600 QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling); +#endif #endif std::shared_ptr b; QApplication a(argc, argv); diff --git a/examples/centralwidget/mainwindow.cpp b/examples/centralwidget/mainwindow.cpp index 7243a5c..eb964f4 100644 --- a/examples/centralwidget/mainwindow.cpp +++ b/examples/centralwidget/mainwindow.cpp @@ -26,17 +26,6 @@ using namespace ads; -/** - * Helper function to create an SVG icon - */ -static QIcon svgIcon(const QString& File) -{ - // This is a workaround, because in item views SVG icons are not - // properly scaled and look blurry or pixelate - QIcon SvgIcon(File); - SvgIcon.addPixmap(SvgIcon.pixmap(92)); - return SvgIcon; -} CMainWindow::CMainWindow(QWidget *parent) : QMainWindow(parent) diff --git a/src/DockWidgetTab.cpp b/src/DockWidgetTab.cpp index ca299fe..8bea5d2 100644 --- a/src/DockWidgetTab.cpp +++ b/src/DockWidgetTab.cpp @@ -259,7 +259,7 @@ void DockWidgetTabPrivate::createLayout() void DockWidgetTabPrivate::moveTab(QMouseEvent* ev) { ev->accept(); - QPoint Distance = ev->globalPos() - GlobalDragStartMousePosition; + QPoint Distance = internal::globalPositionOf(ev) - GlobalDragStartMousePosition; Distance.setY(0); auto TargetPos = Distance + TabDragStartPosition; TargetPos.rx() = qMax(TargetPos.x(), 0); @@ -351,7 +351,7 @@ void CDockWidgetTab::mousePressEvent(QMouseEvent* ev) if (ev->button() == Qt::LeftButton) { ev->accept(); - d->saveDragStartMousePosition(ev->globalPos()); + d->saveDragStartMousePosition(internal::globalPositionOf(ev)); d->DragState = DraggingMousePressed; emit clicked(); return; @@ -377,7 +377,7 @@ void CDockWidgetTab::mouseReleaseEvent(QMouseEvent* ev) // End of tab moving, emit signal if (d->DockArea) { - emit moved(ev->globalPos()); + emit moved(internal::globalPositionOf(ev)); } break; @@ -422,7 +422,7 @@ void CDockWidgetTab::mouseMoveEvent(QMouseEvent* ev) auto MappedPos = mapToParent(ev->pos()); bool MouseOutsideBar = (MappedPos.x() < 0) || (MappedPos.x() > parentWidget()->rect().right()); // Maybe a fixed drag distance is better here ? - int DragDistanceY = qAbs(d->GlobalDragStartMousePosition.y() - ev->globalPos().y()); + int DragDistanceY = qAbs(d->GlobalDragStartMousePosition.y() - internal::globalPositionOf(ev).y()); if (DragDistanceY >= CDockManager::startDragDistance() || MouseOutsideBar) { // If this is the last dock area in a dock container with only @@ -454,7 +454,7 @@ void CDockWidgetTab::mouseMoveEvent(QMouseEvent* ev) return; } else if (d->DockArea->openDockWidgetsCount() > 1 - && (ev->globalPos() - d->GlobalDragStartMousePosition).manhattanLength() >= QApplication::startDragDistance()) // Wait a few pixels before start moving + && (internal::globalPositionOf(ev) - d->GlobalDragStartMousePosition).manhattanLength() >= QApplication::startDragDistance()) // Wait a few pixels before start moving { // If we start dragging the tab, we save its inital position to // restore it later @@ -618,7 +618,7 @@ void CDockWidgetTab::mouseDoubleClickEvent(QMouseEvent *event) if ((!d->DockArea->dockContainer()->isFloating() || d->DockArea->dockWidgetsCount() > 1) && d->DockWidget->features().testFlag(CDockWidget::DockWidgetFloatable)) { - d->saveDragStartMousePosition(event->globalPos()); + d->saveDragStartMousePosition(internal::globalPositionOf(event)); d->startFloating(DraggingInactive); } diff --git a/src/ads_globals.h b/src/ads_globals.h index 2a22c0e..9705544 100644 --- a/src/ads_globals.h +++ b/src/ads_globals.h @@ -36,6 +36,7 @@ #include #include #include +#include #ifdef Q_OS_LINUX #include @@ -260,6 +261,19 @@ void setToolTip(QObjectPtr obj, const QString &tip) } +/** + * Helper function for access to mouse event global position in Qt5 and + */ +inline QPoint globalPositionOf(QMouseEvent* ev) +{ +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) + return ev->globalPosition().toPoint(); +#else + return ev->globalPos(); +#endif +} + + /** * Helper function to set the icon of a certain button. * Use this function to set the icons for the dock area and dock widget buttons.