Sine Striker
2023-12-04 2d08f989b16dad059d42c94e3a2cdccdbd3c379e
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include "abstractwindowcontext_p.h"
 
namespace QWK {
 
    AbstractWindowContext::~AbstractWindowContext() = default;
 
    void AbstractWindowContext::setupWindow(QWindow *window) {
        Q_ASSERT(window);
        if (!window) {
            return;
        }
        m_windowHandle = window;
    }
 
    bool AbstractWindowContext::setHitTestVisible(QObject *obj, bool visible) {
        Q_ASSERT(obj);
        if (!obj) {
            return false;
        }
 
        if (visible) {
            m_hitTestVisibleItems.insert(obj);
        } else {
            m_hitTestVisibleItems.remove(obj);
        }
        return true;
    }
 
    bool AbstractWindowContext::setHitTestVisible(const QRect &rect, bool visible) {
        Q_ASSERT(rect.isValid());
        if (!rect.isValid()) {
            return false;
        }
 
        if (visible) {
            m_hitTestVisibleRects.append(rect);
        } else {
            m_hitTestVisibleRects.removeAll(rect);
        }
        hitTestVisibleShapeDirty = true;
        return true;
    }
 
    bool AbstractWindowContext::setSystemButton(CoreWindowAgent::SystemButton button,
                                                QObject *obj) {
        Q_ASSERT(obj);
        Q_ASSERT(button != CoreWindowAgent::Unknown);
        if (!obj || (button == CoreWindowAgent::Unknown)) {
            return false;
        }
 
        if (m_systemButtons[button] == obj) {
            return false;
        }
        m_systemButtons[button] = obj;
        return true;
    }
 
    bool AbstractWindowContext::setTitleBar(QObject *item) {
        Q_ASSERT(item);
        if (!item) {
            return false;
        }
 
        if (m_titleBar == item) {
            return false;
        }
        m_titleBar = item;
        return true;
    }
 
    void AbstractWindowContext::showSystemMenu(const QPoint &pos) {
        // ?
    }
 
    QRegion AbstractWindowContext::hitTestShape() const {
        if (hitTestVisibleShapeDirty) {
            hitTestVisibleShape = {};
            for (const auto &rect : m_hitTestVisibleRects) {
                hitTestVisibleShape += rect;
            }
            hitTestVisibleShapeDirty = false;
        }
        return hitTestVisibleShape;
    }
 
    bool AbstractWindowContext::isInSystemButtons(const QPoint &pos,
                                                  CoreWindowAgent::SystemButton *button) const {
        *button = CoreWindowAgent::Unknown;
        for (int i = CoreWindowAgent::WindowIcon; i <= CoreWindowAgent::Close; ++i) {
            auto currentButton = m_systemButtons[i];
            if (!currentButton || !m_delegate->isVisible(currentButton) ||
                !m_delegate->isEnabled(currentButton)) {
                continue;
            }
            if (m_delegate->mapGeometryToScene(currentButton).contains(pos)) {
                *button = CoreWindowAgent::WindowIcon;
                return true;
            }
        }
        return false;
    }
 
}