| | |
| | | // 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> |
| | |
| | | #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 { |
| | |
| | | }; |
| | | |
| | | protected: |
| | | bool eventFilter(QObject *object, QEvent *event) override; |
| | | bool sharedEventFilter(QObject *object, QEvent *event) override; |
| | | |
| | | private: |
| | | AbstractWindowContext *m_context; |
| | |
| | | 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; |
| | |
| | | } |
| | | |
| | | QtWindowContext::QtWindowContext() : AbstractWindowContext() { |
| | | qtWindowEventFilter = std::make_unique<QtWindowEventFilter>(this); |
| | | } |
| | | |
| | | QtWindowContext::~QtWindowContext() = default; |
| | |
| | | AbstractWindowContext::virtual_hook(id, data); |
| | | } |
| | | |
| | | void QtWindowContext::winIdChanged(QWindow *oldWindow, bool isDestroyed) { |
| | | 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); |
| | | } |
| | | |
| | | } |