Yuhang Zhao
2023-12-06 8521bbf2f335984542f2071825d7383548862b7a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#ifndef ABSTRACTWINDOWCONTEXT_P_H
#define ABSTRACTWINDOWCONTEXT_P_H
 
#include <array>
#include <memory>
 
#include <QtCore/QSet>
#include <QtGui/QWindow>
#include <QtGui/QPolygon>
 
#include <QWKCore/corewindowagent.h>
#include <QWKCore/windowitemdelegate.h>
 
namespace QWK {
 
    class QWK_CORE_EXPORT AbstractWindowContext : public QObject {
        Q_OBJECT
    public:
        AbstractWindowContext(QObject *host, WindowItemDelegate *delegate);
        ~AbstractWindowContext() override;
 
    public:
        virtual bool setup() = 0;
 
        inline QObject *host() const;
        inline QWindow *window() const;
 
        inline bool isHitTestVisible(QObject *obj) const;
        bool setHitTestVisible(QObject *obj, bool visible);
        bool setHitTestVisible(const QRect &rect, bool visible);
 
        inline QObject *systemButton(CoreWindowAgent::SystemButton button) const;
        bool setSystemButton(CoreWindowAgent::SystemButton button, QObject *obj);
 
        inline QObject *titleBar() const;
        bool setTitleBar(QObject *obj);
 
        void showSystemMenu(const QPoint &pos);
 
        QRegion hitTestShape() const;
        bool isInSystemButtons(const QPoint &pos, CoreWindowAgent::SystemButton *button) const;
        bool isInTitleBarDraggableArea(const QPoint &pos) const;
 
    protected:
        QObject *m_host;
        std::unique_ptr<WindowItemDelegate> m_delegate;
        QWindow *m_windowHandle;
 
        QSet<QObject *> m_hitTestVisibleItems;
        QList<QRect> m_hitTestVisibleRects;
 
        QObject *m_titleBar{};
        std::array<QObject *, CoreWindowAgent::NumSystemButton> m_systemButtons{};
 
        // Cached shape
        mutable bool hitTestVisibleShapeDirty{};
        mutable QRegion hitTestVisibleShape;
    };
 
    inline QObject *AbstractWindowContext::host() const {
        return m_host;
    }
 
    inline QWindow *AbstractWindowContext::window() const {
        return m_windowHandle;
    }
 
    inline bool AbstractWindowContext::isHitTestVisible(QObject *obj) const {
        return m_hitTestVisibleItems.contains(obj);
    }
 
    inline QObject *
        AbstractWindowContext::systemButton(CoreWindowAgent::SystemButton button) const {
        return m_systemButtons[button];
    }
 
    inline QObject *AbstractWindowContext::titleBar() const {
        return m_titleBar;
    }
 
}
 
#endif // ABSTRACTWINDOWCONTEXT_P_H