| | |
| | | |
| | | namespace QWK { |
| | | |
| | | AbstractWindowContext::AbstractWindowContext(QWindow *window, WindowItemDelegate *delegate) |
| | | : m_windowHandle(window), m_delegate(delegate) { |
| | | AbstractWindowContext::AbstractWindowContext() |
| | | : m_host(nullptr), m_delegate(nullptr), m_windowHandle(nullptr) { |
| | | } |
| | | |
| | | AbstractWindowContext::~AbstractWindowContext() { |
| | | } |
| | | AbstractWindowContext::~AbstractWindowContext() = default; |
| | | |
| | | void AbstractWindowContext::setupWindow(QWindow *window) { |
| | | Q_ASSERT(window); |
| | | if (!window) { |
| | | return; |
| | | class EventFilterForwarder : public QObject { |
| | | public: |
| | | using EventProc = bool (*)(QEvent *, void *); |
| | | |
| | | EventFilterForwarder(EventProc proc, void *user, QObject *parent = nullptr) |
| | | : QObject(parent), proc(proc), user(user) { |
| | | } |
| | | m_windowHandle = window; |
| | | |
| | | bool eventFilter(QObject *obj, QEvent *event) override { |
| | | Q_UNUSED(obj) |
| | | return proc(event, user); |
| | | } |
| | | |
| | | protected: |
| | | EventProc proc; |
| | | void *user; |
| | | }; |
| | | |
| | | bool AbstractWindowContext::setup(QObject *host, WindowItemDelegate *delegate) { |
| | | if (!host || !delegate) { |
| | | return false; |
| | | } |
| | | |
| | | auto windowHandle = delegate->hostWindow(host); |
| | | if (!windowHandle) { |
| | | return false; |
| | | } |
| | | |
| | | m_host = host; |
| | | m_delegate.reset(delegate); |
| | | m_windowHandle = windowHandle; |
| | | |
| | | if (!setupHost()) { |
| | | m_host = nullptr; |
| | | m_delegate = nullptr; |
| | | m_windowHandle = nullptr; |
| | | return false; |
| | | } |
| | | |
| | | // Install specific event filter |
| | | host->installEventFilter(new EventFilterForwarder( |
| | | [](QEvent *event, void *user) { |
| | | return reinterpret_cast<AbstractWindowContext *>(user)->hostEventFilter(event); |
| | | }, |
| | | this, this)); |
| | | |
| | | return true; |
| | | } |
| | | |
| | | bool AbstractWindowContext::setHitTestVisible(QObject *obj, bool visible) { |
| | | bool AbstractWindowContext::setHitTestVisible(const QObject *obj, bool visible) { |
| | | Q_ASSERT(obj); |
| | | if (!obj) { |
| | | return false; |
| | |
| | | } |
| | | |
| | | bool AbstractWindowContext::setSystemButton(CoreWindowAgent::SystemButton button, |
| | | QObject *obj) { |
| | | const QObject *obj) { |
| | | Q_ASSERT(obj); |
| | | Q_ASSERT(button != CoreWindowAgent::Unknown); |
| | | if (!obj || (button == CoreWindowAgent::Unknown)) { |
| | |
| | | return true; |
| | | } |
| | | |
| | | bool AbstractWindowContext::setTitleBar(QObject *item) { |
| | | bool AbstractWindowContext::setTitleBar(const QObject *item) { |
| | | Q_ASSERT(item); |
| | | if (!item) { |
| | | return false; |
| | |
| | | continue; |
| | | } |
| | | if (m_delegate->mapGeometryToScene(currentButton).contains(pos)) { |
| | | *button = CoreWindowAgent::WindowIcon; |
| | | *button = static_cast<CoreWindowAgent::SystemButton>(i); |
| | | return true; |
| | | } |
| | | } |
| | |
| | | return false; |
| | | } |
| | | |
| | | if (!titleBarRect.contains(pos)) { |
| | | return false; |
| | | } |
| | | |
| | | for (int i = CoreWindowAgent::WindowIcon; i <= CoreWindowAgent::Close; ++i) { |
| | | auto currentButton = m_systemButtons[i]; |
| | | if (currentButton && m_delegate->isVisible(currentButton) && |
| | |
| | | } |
| | | } |
| | | |
| | | if (hitTestShape().contains(pos)) { |
| | | if (!m_hitTestVisibleRects.isEmpty() && hitTestShape().contains(pos)) { |
| | | return false; |
| | | } |
| | | |
| | | return true; |
| | | } |
| | | |
| | | bool AbstractWindowContext::hostEventFilter(QEvent *event) { |
| | | Q_UNUSED(event) |
| | | return false; |
| | | } |
| | | |
| | | } |