QtCanpool 3.3.0
载入中...
搜索中...
未找到
windowagentbase.cpp
浏览该文件的文档.
1
5#include "windowagentbase.h"
6#include "windowkit_p.h"
7#include "windowagentbase_p.h"
8#include "windowcontext_p.h"
9
10Q_LOGGING_CATEGORY(qWindowKitLog, "qwindowkit")
11
13
24 : q_ptr(nullptr)
25 , m_context(nullptr)
26{
27}
28
29WindowAgentBasePrivate::~WindowAgentBasePrivate() = default;
30
31void WindowAgentBasePrivate::init()
32{
33 // The context is created here rather than in setup(). Every accessor on
34 // WindowAgentBase and its subclasses goes through m_context, and asking a
35 // freshly constructed agent for its title bar is a perfectly reasonable
36 // thing to do - the answer is "none", not a null pointer dereference.
37 //
38 // createContext() is virtual, but it is not overridden anywhere and only
39 // depends on compile-time platform macros, so calling it this early is
40 // well defined.
41 m_context.reset(createContext());
42}
43
44WindowContext *WindowAgentBasePrivate::createContext() const
45{
46#if defined(Q_OS_WINDOWS) && defined(QX_WINDOW_NATIVE)
47 return new WindowContextWin();
48#elif defined(Q_OS_MAC) && defined(QX_WINDOW_NATIVE)
49 return new WindowContextCocoa();
50#else
51 return new WindowContextQt();
52#endif
53}
54
55void WindowAgentBasePrivate::setup(QObject *host, WindowItemDelegate *delegate)
56{
57 if (!m_context) {
58 m_context.reset(createContext());
59 }
60 m_context->setup(host, delegate);
61}
62
66WindowAgentBase::~WindowAgentBase() = default;
67
73QVariant WindowAgentBase::windowAttribute(const QString &key) const
74{
75 Q_D(const WindowAgentBase);
76 return d->m_context->windowAttribute(key);
77}
78
107bool WindowAgentBase::setWindowAttribute(const QString &key, const QVariant &attribute)
108{
109 Q_D(WindowAgentBase);
110 return d->m_context->setWindowAttribute(key, attribute);
111}
112
116void WindowAgentBase::showSystemMenu(const QPoint &pos)
117{
118 Q_D(WindowAgentBase);
119 d->m_context->showSystemMenu(pos);
120}
121
125void WindowAgentBase::centralize()
126{
127 Q_D(WindowAgentBase);
128 d->m_context->virtual_hook(WindowContext::CentralizeHook, nullptr);
129}
130
134void WindowAgentBase::raise()
135{
136 Q_D(WindowAgentBase);
137 d->m_context->virtual_hook(WindowContext::RaiseWindowHook, nullptr);
138}
139
143WindowAgentBase::WindowAgentBase(WindowAgentBasePrivate &d, QObject *parent)
144 : QObject(parent)
145 , d_ptr(&d)
146{
147 d.q_ptr = this;
148
149 d.init();
150}
151
WindowAgentBase is the base class of the specifiy window agent for QtWidgets and QtQuick.
#define QX_WINDOW_END_NAMESPACE
#define QX_WINDOW_BEGIN_NAMESPACE