From 3fbcf1aa8f91a804af50fad4e2b122f698259c94 Mon Sep 17 00:00:00 2001 From: Sine Striker <trueful@163.com> Date: ćšć, 09 5æ 2024 23:45:28 +0800 Subject: [PATCH] Remove `isHostSizeFixed` in delegate --- src/core/contexts/qtwindowcontext.cpp | 39 ++++++++++++++++++++++----------------- 1 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/core/contexts/qtwindowcontext.cpp b/src/core/contexts/qtwindowcontext.cpp index 8a71c2b..644ce64 100644 --- a/src/core/contexts/qtwindowcontext.cpp +++ b/src/core/contexts/qtwindowcontext.cpp @@ -1,3 +1,7 @@ +// Copyright (C) 2023-2024 Stdware Collections (https://www.github.com/stdware) +// Copyright (C) 2021-2023 wangwenx190 (Yuhang Zhao) +// SPDX-License-Identifier: Apache-2.0 + #include "qtwindowcontext_p.h" #include <QtCore/QDebug> @@ -77,9 +81,9 @@ #endif } - class QtWindowEventFilter : public QObject { + class QtWindowEventFilter : public SharedEventFilter { public: - explicit QtWindowEventFilter(AbstractWindowContext *context, QObject *parent = nullptr); + explicit QtWindowEventFilter(AbstractWindowContext *context); ~QtWindowEventFilter() override; enum WindowStatus { @@ -91,7 +95,7 @@ }; protected: - bool eventFilter(QObject *object, QEvent *event) override; + bool sharedEventFilter(QObject *object, QEvent *event) override; private: AbstractWindowContext *m_context; @@ -99,15 +103,16 @@ WindowStatus m_windowStatus; }; - QtWindowEventFilter::QtWindowEventFilter(AbstractWindowContext *context, QObject *parent) - : QObject(parent), m_context(context), m_cursorShapeChanged(false), m_windowStatus(Idle) { - m_context->window()->installEventFilter(this); + QtWindowEventFilter::QtWindowEventFilter(AbstractWindowContext *context) + : m_context(context), m_cursorShapeChanged(false), m_windowStatus(Idle) { + m_context->installSharedEventFilter(this); } QtWindowEventFilter::~QtWindowEventFilter() = default; - bool QtWindowEventFilter::eventFilter(QObject *obj, QEvent *event) { + bool QtWindowEventFilter::sharedEventFilter(QObject *obj, QEvent *event) { Q_UNUSED(obj) + auto type = event->type(); if (type < QEvent::MouseButtonPress || type > QEvent::MouseMove) { return false; @@ -116,7 +121,7 @@ auto window = m_context->window(); auto delegate = m_context->delegate(); auto me = static_cast<const QMouseEvent *>(event); - bool fixedSize = delegate->isHostSizeFixed(host); + bool fixedSize = m_context->isHostSizeFixed(); QPoint scenePos = getMouseEventScenePos(me); QPoint globalPos = getMouseEventGlobalPos(me); @@ -235,6 +240,7 @@ } QtWindowContext::QtWindowContext() : AbstractWindowContext() { + qtWindowEventFilter = std::make_unique<QtWindowEventFilter>(this); } QtWindowContext::~QtWindowContext() = default; @@ -244,20 +250,19 @@ } void QtWindowContext::virtual_hook(int id, void *data) { - switch (id) { - case ShowSystemMenuHook: - return; - default: - break; - } AbstractWindowContext::virtual_hook(id, data); } - void QtWindowContext::winIdChanged(QWindow *oldWindow) { - Q_UNUSED(oldWindow) + void QtWindowContext::winIdChanged(WId winId, WId oldWinId) { + if (!m_windowHandle) { + m_delegate->setWindowFlags(m_host, m_delegate->getWindowFlags(m_host) & + ~Qt::FramelessWindowHint); + return; + } + + // Allocate new resources m_delegate->setWindowFlags(m_host, m_delegate->getWindowFlags(m_host) | Qt::FramelessWindowHint); - qtWindowEventFilter = std::make_unique<QtWindowEventFilter>(this); } } -- Gitblit v1.9.1