Krita Source Code Documentation
Loading...
Searching...
No Matches
KisRootSurfaceInfoProxy.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2025 Dmitry Kazakov <dimula73@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
8
9#include <QTimer>
10
11#include <QEvent>
12#include <QWidget>
13#include <QWindow>
16
17
18namespace {
19class ChildChangedEventFilter : public QObject
20{
21 Q_OBJECT
22public:
23 ChildChangedEventFilter(QObject *watched, QObject *parent)
24 : QObject(parent)
25 , m_watched(watched)
26 {
27 }
28
29 bool eventFilter(QObject *watched, QEvent *event) override {
30 if (watched == m_watched &&
31 (event->type() == QEvent::ChildAdded || event->type() == QEvent::ChildRemoved)) {
37 QTimer::singleShot(0, this, &ChildChangedEventFilter::sigChildrenChanged);
38 }
39
40 return false;
41 }
42
43 QObject *m_watched {nullptr};
44
45Q_SIGNALS:
46 void sigChildrenChanged();
47};
48}
49
50KisRootSurfaceInfoProxy::KisRootSurfaceInfoProxy(QWidget *watched, QObject *parent)
51 : QObject(parent)
52 , m_watched(watched)
53{
57}
58
62
67
72
74{
75 return m_topLevelSurfaceManager ? m_topLevelSurfaceManager->colorManagementReport()
76 : QString("Top level surface color manager is not found!\n");
77}
78
80{
81 return m_topLevelSurfaceManager ? m_topLevelSurfaceManager->osPreferredColorSpaceReport()
82 : QString("Top level surface color manager is not found!\n");
83}
84
85bool KisRootSurfaceInfoProxy::eventFilter(QObject *watched, QEvent *event)
86{
87 if (event->type() == QEvent::ParentChange && m_watchedHierarchy.contains(watched)) {
89 }
90
91 if (event->type() == QEvent::PlatformSurface && watched == m_watchedHierarchy.last().data()) {
93 }
94
95 return false;
96}
97
99{
100 auto newHierarchy = getCurrentHierarchy(m_watched);
101 if (newHierarchy != m_watchedHierarchy) {
102 reconnectToHierarchy(newHierarchy);
103 QWidget *topLevel = static_cast<QWidget *>(newHierarchy.last().data());
104 if (topLevel != m_topLevelWidgetWithSurface) {
107 }
108 }
109}
110
112{
113 auto disconnectExistingManager = [this]() {
116 disconnect(m_surfaceManagerConnection);
117 }
118 };
119
121 disconnectExistingManager();
123 return;
124 }
125
126 QWindow *nativeWindow = m_topLevelWidgetWithSurface->windowHandle();
127
128 if (nativeWindow != m_topLevelNativeWindow) {
131 m_childChangedFilter->deleteLater();
132 m_childChangedFilter.clear();
133 }
134
135 m_topLevelNativeWindow = nativeWindow;
136
138 auto *filter = new ChildChangedEventFilter(m_topLevelNativeWindow, m_topLevelNativeWindow);
139 connect(filter,
140 &ChildChangedEventFilter::sigChildrenChanged,
141 this,
143 m_childChangedFilter = filter;
144 m_topLevelNativeWindow->installEventFilter(m_childChangedFilter);
145 }
146 }
147
148 if (nativeWindow) {
149 if (auto manager = nativeWindow->findChild<KisSRGBSurfaceColorSpaceManager *>()) {
150 if (manager != m_topLevelSurfaceManager) {
151 disconnectExistingManager();
152 m_topLevelSurfaceManager = manager;
155 this,
158 }
159 }
160 } else {
161 disconnectExistingManager();
163 }
164}
165
167{
169
171 newProfile = m_topLevelSurfaceManager->displayConfig().profile;
172 }
173
175
176 if (newProfile != m_rootSurfaceProfile) {
177 m_rootSurfaceProfile = newProfile;
179 }
180}
181
183{
185
186 while (wdg) {
187 result.append(wdg);
188 wdg = wdg->parentWidget();
189 }
190
191 return result;
192}
193
195{
196 Q_FOREACH (QPointer<QObject> widget, m_watchedHierarchy) {
197 KIS_SAFE_ASSERT_RECOVER(widget) continue;
198 widget->removeEventFilter(this);
199 }
200
201 m_watchedHierarchy.clear();
202
203 Q_FOREACH (QPointer<QObject> widget, newHierarchy) {
204 widget->installEventFilter(this);
205 }
206
207 m_watchedHierarchy = newHierarchy;
208}
209
210#include <KisRootSurfaceInfoProxy.moc>
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
static KisPlatformPluginInterfaceFactory * instance()
void reconnectToHierarchy(const QVector< QPointer< QObject > > newHierarchy)
QMetaObject::Connection m_surfaceManagerConnection
QPointer< QObject > m_childChangedFilter
QPointer< KisSRGBSurfaceColorSpaceManager > m_topLevelSurfaceManager
const KoColorProfile * m_rootSurfaceProfile
QPointer< QWidget > m_topLevelWidgetWithSurface
QVector< QPointer< QObject > > getCurrentHierarchy(QWidget *wdg)
bool eventFilter(QObject *watched, QEvent *event) override
KisRootSurfaceInfoProxy(QWidget *watched, QObject *parent=nullptr)
QPointer< QWindow > m_topLevelNativeWindow
const KoColorProfile * rootSurfaceProfile() const
void sigRootSurfaceProfileChanged(const KoColorProfile *profile) const
QVector< QPointer< QObject > > m_watchedHierarchy
#define KIS_SAFE_ASSERT_RECOVER(cond)
Definition kis_assert.h:126
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:128
ChildIterator< value_type, is_const > parent(const ChildIterator< value_type, is_const > &it)
Definition KisForest.h:327
void sigDisplayConfigChanged(const KisDisplayConfig &config)
static KoColorSpaceRegistry * instance()
const KoColorProfile * p709SRGBProfile() const