-
Notifications
You must be signed in to change notification settings - Fork 364
/
mywindowattached.cpp
97 lines (82 loc) · 3.03 KB
/
mywindowattached.cpp
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
#include "mywindowattached.h"
#include "mywindow.h"
#include <qquickwindow.h>
#include <qquickitem.h>
MyQuickWindowAttached::MyQuickWindowAttached(QObject* attachee)
: QObject(attachee)
, m_window(nullptr)
{
m_attachee = qobject_cast<QQuickItem*>(attachee);
if (m_attachee && m_attachee->window()) // It might not be in a window yet
windowChange(m_attachee->window());
if (m_attachee)
connect(m_attachee, &QQuickItem::windowChanged, this, &MyQuickWindowAttached::windowChange);
}
QWindow::Visibility MyQuickWindowAttached::visibility() const
{
return (m_window ? m_window->visibility() : QWindow::Hidden);
}
bool MyQuickWindowAttached::isActive() const
{
return (m_window ? m_window->isActive() : false);
}
QQuickItem *MyQuickWindowAttached::activeFocusItem() const
{
return (m_window ? m_window->activeFocusItem() : nullptr);
}
QQuickItem *MyQuickWindowAttached::contentItem() const
{
return (m_window ? m_window->contentItem() : nullptr);
}
int MyQuickWindowAttached::width() const
{
return (m_window ? m_window->width() : 0);
}
int MyQuickWindowAttached::height() const
{
return (m_window ? m_window->height() : 0);
}
qreal MyQuickWindowAttached::dpiRatio() const
{
return (m_window ? m_window->dpiRatio() : 1.0);
}
MyQuickWindow *MyQuickWindowAttached::window() const
{
return m_window;
}
void MyQuickWindowAttached::windowChange(QQuickWindow *win)
{
MyQuickWindow *window = qobject_cast<MyQuickWindow*>(win);
if (window != m_window) {
MyQuickWindow* oldWindow = m_window;
m_window = window;
if (oldWindow)
oldWindow->disconnect(this);
emit windowChanged();
if (!oldWindow || !window || window->visibility() != oldWindow->visibility())
emit visibilityChanged();
if (!oldWindow || !window || window->isActive() != oldWindow->isActive())
emit activeChanged();
if (!oldWindow || !window || window->activeFocusItem() != oldWindow->activeFocusItem())
emit activeFocusItemChanged();
emit contentItemChanged();
if (!oldWindow || !window || window->width() != oldWindow->width())
emit widthChanged();
if (!oldWindow || !window || window->height() != oldWindow->height())
emit heightChanged();
if (!window)
return;
connect(window, &QQuickWindow::visibilityChanged,
this, &MyQuickWindowAttached::visibilityChanged);
connect(window, &QQuickWindow::activeChanged,
this, &MyQuickWindowAttached::activeChanged);
connect(window, &QQuickWindow::activeFocusItemChanged,
this, &MyQuickWindowAttached::activeFocusItemChanged);
connect(window, &QQuickWindow::widthChanged,
this, &MyQuickWindowAttached::widthChanged);
connect(window, &QQuickWindow::heightChanged,
this, &MyQuickWindowAttached::heightChanged);
connect(window, &MyQuickWindow::dpiRatioChanged,
this, &MyQuickWindowAttached::dpiRatioChanged);
}
}