From 657caef31ea68d5f674acc0bc884c3a34d9a3063 Mon Sep 17 00:00:00 2001 From: deepin-ci-robot Date: Mon, 28 Jul 2025 05:27:04 +0000 Subject: [PATCH] sync: from linuxdeepin/qt5platform-plugins Synchronize source files from linuxdeepin/qt5platform-plugins. Source-pull-request: https://github.com/linuxdeepin/qt5platform-plugins/pull/297 --- src/ddesktopinputselectioncontrol.cpp | 23 +++++++++++++++++++++-- src/dnativesettings.h | 2 +- src/dplatformsettings.h | 3 ++- src/dselectedtexttooltip.cpp | 15 +++++++++++++++ src/dselectedtexttooltip.h | 3 +++ src/dxcbxsettings.cpp | 4 ++++ src/dxcbxsettings.h | 2 +- xcb/dframewindow.cpp | 18 ++++++++++++++++++ xcb/dhighdpi.cpp | 13 +++++++++---- xcb/dnotitlebarwindowhelper.cpp | 16 ++++++++++++++++ xcb/dplatformwindowhelper.cpp | 8 ++++++++ 11 files changed, 98 insertions(+), 9 deletions(-) diff --git a/src/ddesktopinputselectioncontrol.cpp b/src/ddesktopinputselectioncontrol.cpp index 8d25d9a..15dfb74 100644 --- a/src/ddesktopinputselectioncontrol.cpp +++ b/src/ddesktopinputselectioncontrol.cpp @@ -475,9 +475,15 @@ bool DDesktopInputSelectionControl::eventFilter(QObject *object, QEvent *event) break; QTouchEvent *touchEvent = static_cast(event); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + const auto& tpList = touchEvent->points(); + const auto& tp = tpList.first(); + QPointF touchPos = tp.lastPosition(); +#else QList tpList = touchEvent->touchPoints(); QTouchEvent::TouchPoint tp = tpList.first(); QPointF touchPos = tp.lastPos(); +#endif // 有效点击位置 QRectF effectiveRect = anchorRectangle(); @@ -511,7 +517,11 @@ bool DDesktopInputSelectionControl::eventFilter(QObject *object, QEvent *event) break; QMouseEvent *me = static_cast(event); - const QPoint mousePos = me->screenPos().toPoint(); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + QPoint mousePos = me->globalPosition().toPoint(); +#else + QPoint mousePos = me->screenPos().toPoint(); +#endif // calculate distances from mouse pos to each handle, // then choose to interact with the nearest handle @@ -556,7 +566,12 @@ bool DDesktopInputSelectionControl::eventFilter(QObject *object, QEvent *event) m_otherSelectionPoint = QPoint(otherRect.x() + otherRect.width() / 2, otherRect.bottom() + 4); } - QMouseEvent *mouseEvent = new QMouseEvent(me->type(), me->localPos(), me->windowPos(), me->screenPos(), + QMouseEvent *mouseEvent = new QMouseEvent(me->type(), +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + me->position(), me->scenePosition(), me->globalPosition(), +#else + me->localPos(), me->windowPos(), me->screenPos(), +#endif me->button(), me->buttons(), me->modifiers(), me->source()); m_eventQueue.append(mouseEvent); return true; @@ -570,7 +585,11 @@ bool DDesktopInputSelectionControl::eventFilter(QObject *object, QEvent *event) m_handleVisible = true; QMouseEvent *me = static_cast(event); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + QPoint mousePos = me->globalPosition().toPoint(); +#else QPoint mousePos = me->screenPos().toPoint(); +#endif if (m_handleState == HandleIsHeld) { QPoint delta = m_handleDragStartedPosition - mousePos; const int startDragDistance = QGuiApplication::styleHints()->startDragDistance(); diff --git a/src/dnativesettings.h b/src/dnativesettings.h index 39da171..6857252 100644 --- a/src/dnativesettings.h +++ b/src/dnativesettings.h @@ -17,7 +17,7 @@ DPP_BEGIN_NAMESPACE class DPlatformSettings; -class DNativeSettings : public QAbstractDynamicMetaObject +class Q_DECL_HIDDEN DNativeSettings : public QAbstractDynamicMetaObject { public: explicit DNativeSettings(QObject *base, DPlatformSettings *settings, bool global_settings); diff --git a/src/dplatformsettings.h b/src/dplatformsettings.h index d555e6b..e667c82 100644 --- a/src/dplatformsettings.h +++ b/src/dplatformsettings.h @@ -15,7 +15,7 @@ QT_END_NAMESPACE DPP_BEGIN_NAMESPACE -class DPlatformSettings +class Q_DECL_HIDDEN DPlatformSettings { public: virtual ~DPlatformSettings() {} @@ -41,6 +41,7 @@ class DPlatformSettings void handlePropertyChanged(const QByteArray &property, const QVariant &value); void handleNotify(const QByteArray &signal, qint32 data1, qint32 data2); +private: struct Q_DECL_HIDDEN Callback { PropertyChangeFunc func; diff --git a/src/dselectedtexttooltip.cpp b/src/dselectedtexttooltip.cpp index 3d29c85..223734d 100644 --- a/src/dselectedtexttooltip.cpp +++ b/src/dselectedtexttooltip.cpp @@ -36,7 +36,12 @@ DSelectedTextTooltip::DSelectedTextTooltip() m_textInfoVec.push_back({Paste, 0, qApp->translate("QLineEdit", "&Paste").split("(").at(0)}); updateColor(); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + // Qt6中使用事件处理替代fontChanged信号 + qApp->installEventFilter(this); +#else connect(qApp, &QGuiApplication::fontChanged, this, &DSelectedTextTooltip::onFontChanged); +#endif // 更新文本信息 onFontChanged(); @@ -46,6 +51,16 @@ DSelectedTextTooltip::~DSelectedTextTooltip() { } +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) +bool DSelectedTextTooltip::eventFilter(QObject *obj, QEvent *event) +{ + if (event->type() == QEvent::ApplicationFontChange) { + onFontChanged(); + } + return QRasterWindow::eventFilter(obj, event); +} +#endif + void DSelectedTextTooltip::onFontChanged() { QFontMetrics font_metrics(qApp->font()); diff --git a/src/dselectedtexttooltip.h b/src/dselectedtexttooltip.h index 182dccd..1dd1753 100644 --- a/src/dselectedtexttooltip.h +++ b/src/dselectedtexttooltip.h @@ -31,6 +31,9 @@ class DSelectedTextTooltip : public QRasterWindow protected: void paintEvent(QPaintEvent *pe) override; void mousePressEvent(QMouseEvent *event) override; +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + bool eventFilter(QObject *obj, QEvent *event) override; +#endif private slots: void onFontChanged(); diff --git a/src/dxcbxsettings.cpp b/src/dxcbxsettings.cpp index 4e42682..1b9611b 100644 --- a/src/dxcbxsettings.cpp +++ b/src/dxcbxsettings.cpp @@ -405,7 +405,11 @@ class Q_DECL_HIDDEN DXcbXSettingsPrivate const QByteArray &key = i.key(); quint16 key_size = key.size(); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + switch (value.value.typeId()) { +#else switch (value.value.type()) { +#endif case QMetaType::QColor: type = XSettingsTypeColor; break; diff --git a/src/dxcbxsettings.h b/src/dxcbxsettings.h index 6d54770..60bde14 100644 --- a/src/dxcbxsettings.h +++ b/src/dxcbxsettings.h @@ -21,7 +21,7 @@ DPP_BEGIN_NAMESPACE class DXcbXSettingsPrivate; -class DXcbXSettings : public DPlatformSettings +class Q_DECL_HIDDEN DXcbXSettings : public DPlatformSettings { Q_DECLARE_PRIVATE(DXcbXSettings) public: diff --git a/xcb/dframewindow.cpp b/xcb/dframewindow.cpp index 802e61d..881c328 100644 --- a/xcb/dframewindow.cpp +++ b/xcb/dframewindow.cpp @@ -515,23 +515,41 @@ void DFrameWindow::mouseMoveEvent(QMouseEvent *event) } set_edge: /// begin set cursor edge type +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + if (event->position().x() <= m_contentGeometry.x()) { +#else if (event->x() <= m_contentGeometry.x()) { +#endif if (isFixedWidth) goto skip_set_cursor; mouseCorner = Utility::LeftEdge; +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + } else if (event->position().x() < m_contentGeometry.right()) { +#else } else if (event->x() < m_contentGeometry.right()) { +#endif if (isFixedHeight) goto skip_set_cursor; +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + if (event->position().y() <= m_contentGeometry.y()) { + mouseCorner = Utility::TopEdge; + } else if (!isFixedWidth || event->position().y() >= m_contentGeometry.bottom()) { +#else if (event->y() <= m_contentGeometry.y()) { mouseCorner = Utility::TopEdge; } else if (!isFixedWidth || event->y() >= m_contentGeometry.bottom()) { +#endif mouseCorner = Utility::BottomEdge; } else { goto skip_set_cursor; } +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + } else if (!isFixedWidth && (!isFixedHeight || event->position().x() >= m_contentGeometry.right())) { +#else } else if (!isFixedWidth && (!isFixedHeight || event->x() >= m_contentGeometry.right())) { +#endif mouseCorner = Utility::RightEdge; } else { goto skip_set_cursor; diff --git a/xcb/dhighdpi.cpp b/xcb/dhighdpi.cpp index 3b89932..d4c4563 100644 --- a/xcb/dhighdpi.cpp +++ b/xcb/dhighdpi.cpp @@ -39,11 +39,13 @@ inline static void init() Q_CONSTRUCTOR_FUNCTION(init) void DHighDpi::init() { - if (QGuiApplication::testAttribute(Qt::AA_DisableHighDpiScaling) - // 可以禁用此行为 - || qEnvironmentVariableIsSet("D_DXCB_DISABLE_OVERRIDE_HIDPI") + if (qEnvironmentVariableIsSet("D_DXCB_DISABLE_OVERRIDE_HIDPI") // 无有效的xsettings时禁用 - || !DXcbXSettings::getOwner()) { + || !DXcbXSettings::getOwner() +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) + || QGuiApplication::testAttribute(Qt::AA_DisableHighDpiScaling) +#endif + ) { // init函数可能会被重复调用, 此处应该清理VtableHook if (active) { #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) @@ -67,10 +69,13 @@ void DHighDpi::init() qunsetenv("QT_USE_PHYSICAL_DPI"); } +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) + // Qt6中高DPI缩放总是启用的,无需设置AA_EnableHighDpiScaling if (!QGuiApplication::testAttribute(Qt::AA_EnableHighDpiScaling)) { QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QHighDpiScaling::initHighDpiScaling(); } +#endif #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) active = VtableHook::overrideVfptrFun(&QXcbScreen::pixelDensity, pixelDensity); diff --git a/xcb/dnotitlebarwindowhelper.cpp b/xcb/dnotitlebarwindowhelper.cpp index f1758cb..40cfb64 100644 --- a/xcb/dnotitlebarwindowhelper.cpp +++ b/xcb/dnotitlebarwindowhelper.cpp @@ -559,11 +559,19 @@ bool DNoTitlebarWindowHelper::windowEvent(QEvent *event) #endif } if (isTouchDown && event->type() == QEvent::MouseButtonPress) { +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + touchBeginPosition = static_cast(event)->globalPosition().toPoint(); +#else touchBeginPosition = static_cast(event)->globalPos(); +#endif } // add some redundancy to distinguish trigger between system menu and system move if (event->type() == QEvent::MouseMove) { +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + QPointF currentPos = static_cast(event)->globalPosition(); +#else QPointF currentPos = static_cast(event)->globalPos(); +#endif QPointF delta = touchBeginPosition - currentPos; if (delta.manhattanLength() < QGuiApplication::styleHints()->startDragDistance()) { return VtableHook::callOriginalFun(w, &QWindow::event, event); @@ -590,7 +598,11 @@ bool DNoTitlebarWindowHelper::windowEvent(QEvent *event) // keeping the moving state, we can just reset ti back to normal. if (event->type() == QEvent::MouseButtonPress) { self->m_windowMoving = false; +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + g_pressPoint[this] = dynamic_cast(event)->globalPosition().toPoint(); +#else g_pressPoint[this] = dynamic_cast(event)->globalPos(); +#endif } // ========== 修改:鼠标事件处理保持原有逻辑 ========== @@ -605,7 +617,11 @@ bool DNoTitlebarWindowHelper::windowEvent(QEvent *event) return ret; } +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + QPointF delta = me->globalPosition() - g_pressPoint[this]; +#else QPointF delta = me->globalPos() - g_pressPoint[this]; +#endif if (delta.manhattanLength() < QGuiApplication::styleHints()->startDragDistance()) { return ret; } diff --git a/xcb/dplatformwindowhelper.cpp b/xcb/dplatformwindowhelper.cpp index 307a3e4..d849891 100644 --- a/xcb/dplatformwindowhelper.cpp +++ b/xcb/dplatformwindowhelper.cpp @@ -559,7 +559,11 @@ bool DPlatformWindowHelper::windowRedirectContent(QWindow *window) const QVariant &value = window->property(redirectContent); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + if (value.typeId() == QMetaType::Bool) +#else if (value.type() == QVariant::Bool) +#endif return value.toBool(); return window->surfaceType() == QSurface::OpenGLSurface; @@ -612,7 +616,11 @@ bool DPlatformWindowHelper::eventFilter(QObject *watched, QEvent *event) case QEvent::MouseMove: { DQMouseEvent *e = static_cast(event); const QRectF rectF(m_windowValidGeometry); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + const QPointF posF(e->position() - m_frameWindow->contentOffsetHint()); +#else const QPointF posF(e->localPos() - m_frameWindow->contentOffsetHint()); +#endif // QRectF::contains中判断时加入了右下边界 if (!qFuzzyCompare(posF.x(), rectF.width())