Yuhang Zhao
2023-12-06 075a1fd1d67c6e347ab40f460819067b947f92f6
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
#include "corewindowagent.h"
#include "corewindowagent_p.h"
 
#include "qwkcoreglobal_p.h"
 
#ifdef Q_OS_WINDOWS
#  include "win32windowcontext_p.h"
#else
#  include "qtwindowcontext_p.h"
#endif
 
Q_LOGGING_CATEGORY(qWindowKitLog, "qwindowkit")
 
namespace QWK {
 
    CoreWindowAgentPrivate::CoreWindowAgentPrivate() : q_ptr(nullptr), context(nullptr) {
    }
 
    CoreWindowAgentPrivate::~CoreWindowAgentPrivate() {
        if (context) {
            delete context;
            context = nullptr;
        }
    }
 
    void CoreWindowAgentPrivate::init() {
    }
 
    bool CoreWindowAgentPrivate::setup(const QObject *host, const WindowItemDelegate *delegate) {
        auto ctx =
#ifdef Q_OS_WINDOWS
            new Win32WindowContext(host, delegate)
#else
            new QtWindowContext(host, window, delegate)
#endif
            ;
        if (!ctx->setup()) {
            delete ctx;
            ctx = nullptr;
            return false;
        }
        context = ctx;
        return true;
    }
 
    CoreWindowAgent::~CoreWindowAgent() = default;
 
    void CoreWindowAgent::showSystemMenu(const QPoint &pos) {
        Q_D(CoreWindowAgent);
        d->context->showSystemMenu(pos);
    }
 
    void CoreWindowAgent::startSystemMove(const QPoint &pos) {
        Q_D(CoreWindowAgent);
        auto win = d->context->window();
        if (!win) {
            return;
        }
 
        Q_UNUSED(pos)
        win->startSystemMove();
    }
 
    void CoreWindowAgent::startSystemResize(Qt::Edges edges, const QPoint &pos) {
        Q_D(CoreWindowAgent);
        auto win = d->context->window();
        if (!win) {
            return;
        }
 
        Q_UNUSED(pos)
        win->startSystemResize(edges);
    }
 
    void CoreWindowAgent::centralize() {
    }
 
    void CoreWindowAgent::raise() {
    }
 
    CoreWindowAgent::CoreWindowAgent(CoreWindowAgentPrivate &d, QObject *parent)
        : QObject(parent), d_ptr(&d) {
        d.q_ptr = this;
 
        d.init();
    }
 
}