Krita Source Code Documentation
Loading...
Searching...
No Matches
KisRootSurfaceTrackerBase Class Referenceabstract

#include <KisRootSurfaceTrackerBase.h>

+ Inheritance diagram for KisRootSurfaceTrackerBase:

Public Types

enum  UpdateHierarchyFlag { None = 0x0 , AllowDeadParents = 0x1 }
 

Public Member Functions

 KisRootSurfaceTrackerBase (QWidget *watched, QObject *parent=nullptr)
 
 Q_DECLARE_FLAGS (UpdateHierarchyFlags, UpdateHierarchyFlag)
 
QWidget * trackedWidget () const
 
 ~KisRootSurfaceTrackerBase ()
 

Protected Member Functions

virtual void connectToNativeWindow (QWindow *nativeWindow)=0
 
virtual void disconnectFromNativeWindow ()=0
 
void initialize ()
 

Private Member Functions

bool eventFilter (QObject *watched, QEvent *event) override
 
QVector< QPointer< QObject > > getCurrentHierarchy (QWidget *wdg)
 
void reconnectToHierarchy (const QVector< QPointer< QObject > > newHierarchy, bool allowDeadParents)
 
void tryReconnectToNativeWindow ()
 
void tryUpdateHierarchy (UpdateHierarchyFlags flags=None)
 

Private Attributes

QPointer< QObject > m_childChangedFilter
 
QPointer< QWindow > m_topLevelNativeWindow
 
QPointer< QWidget > m_topLevelWidgetWithSurface
 
QWidget * m_watched {nullptr}
 
QVector< QPointer< QObject > > m_watchedHierarchy
 

Detailed Description

KisRootSurfaceProxyBase is a special proxy object for toplevel native window attached to the current QWidget

When created, the proxy does the following:

1) Finds the top-level widget that watched belongs to. (is watched changed its parent in the meantime, e.g. during construction, then the proxy will handle that as well)

2) Finds the QWindow that this toplevel widget is painted on (if platform window is not created yet, subscribes to QPlatformSurfaceEvent to attach when platform window is finally created)

3) When found, calls implementation of connectToNativeWindow() that would connect to the actual native window

Definition at line 37 of file KisRootSurfaceTrackerBase.h.

Member Enumeration Documentation

◆ UpdateHierarchyFlag

Enumerator
None 
AllowDeadParents 

Definition at line 41 of file KisRootSurfaceTrackerBase.h.

Constructor & Destructor Documentation

◆ KisRootSurfaceTrackerBase()

KisRootSurfaceTrackerBase::KisRootSurfaceTrackerBase ( QWidget * watched,
QObject * parent = nullptr )

Definition at line 50 of file KisRootSurfaceTrackerBase.cpp.

51 : QObject(parent)
52 , m_watched(watched)
53{
54}

◆ ~KisRootSurfaceTrackerBase()

KisRootSurfaceTrackerBase::~KisRootSurfaceTrackerBase ( )

Definition at line 56 of file KisRootSurfaceTrackerBase.cpp.

57{
58}

Member Function Documentation

◆ connectToNativeWindow()

virtual void KisRootSurfaceTrackerBase::connectToNativeWindow ( QWindow * nativeWindow)
protectedpure virtual

◆ disconnectFromNativeWindow()

virtual void KisRootSurfaceTrackerBase::disconnectFromNativeWindow ( )
protectedpure virtual

◆ eventFilter()

bool KisRootSurfaceTrackerBase::eventFilter ( QObject * watched,
QEvent * event )
overrideprivate

Definition at line 70 of file KisRootSurfaceTrackerBase.cpp.

71{
72 if (event->type() == QEvent::ParentChange && m_watchedHierarchy.contains(watched)) {
74 }
75
76 if (event->type() == QEvent::PlatformSurface) {
77 if (watched == m_watchedHierarchy.last().data()) {
79 } else {
80 // some widget in the middle of the hierarchy just received
81 // a native window. Let's promote that to toplevel now!
83 }
84 }
85
86 return false;
87}
void tryUpdateHierarchy(UpdateHierarchyFlags flags=None)
QVector< QPointer< QObject > > m_watchedHierarchy

References AllowDeadParents, m_watchedHierarchy, tryReconnectToNativeWindow(), and tryUpdateHierarchy().

◆ getCurrentHierarchy()

QVector< QPointer< QObject > > KisRootSurfaceTrackerBase::getCurrentHierarchy ( QWidget * wdg)
private

Definition at line 138 of file KisRootSurfaceTrackerBase.cpp.

139{
141
142 while (wdg) {
143 result.append(wdg);
144
145 // break on the first native window
146 if (wdg->windowHandle()) {
147 break;
148 } else {
149 wdg = wdg->parentWidget();
150 }
151 }
152
153 return result;
154}

◆ initialize()

void KisRootSurfaceTrackerBase::initialize ( )
protected

Definition at line 65 of file KisRootSurfaceTrackerBase.cpp.

66{
68}

References tryUpdateHierarchy().

◆ Q_DECLARE_FLAGS()

KisRootSurfaceTrackerBase::Q_DECLARE_FLAGS ( UpdateHierarchyFlags ,
UpdateHierarchyFlag  )

◆ reconnectToHierarchy()

void KisRootSurfaceTrackerBase::reconnectToHierarchy ( const QVector< QPointer< QObject > > newHierarchy,
bool allowDeadParents )
private

When a parent of a widget is changed, some of its early parents may already be dead when we receive a ParentChange event.

Definition at line 156 of file KisRootSurfaceTrackerBase.cpp.

157{
158 Q_FOREACH (QPointer<QObject> widget, m_watchedHierarchy) {
164 if (allowDeadParents && !widget) continue;
165
166 KIS_SAFE_ASSERT_RECOVER(widget) continue;
167 widget->removeEventFilter(this);
168 }
169
170 m_watchedHierarchy.clear();
171
172 Q_FOREACH (QPointer<QObject> widget, newHierarchy) {
173 widget->installEventFilter(this);
174 }
175
176 m_watchedHierarchy = newHierarchy;
177}
#define KIS_SAFE_ASSERT_RECOVER(cond)
Definition kis_assert.h:126

References KIS_SAFE_ASSERT_RECOVER, and m_watchedHierarchy.

◆ trackedWidget()

QWidget * KisRootSurfaceTrackerBase::trackedWidget ( ) const

Definition at line 60 of file KisRootSurfaceTrackerBase.cpp.

61{
62 return m_watched;
63}

References m_watched.

◆ tryReconnectToNativeWindow()

void KisRootSurfaceTrackerBase::tryReconnectToNativeWindow ( )
private

Definition at line 102 of file KisRootSurfaceTrackerBase.cpp.

103{
106 return;
107 }
108
109 QWindow *nativeWindow = m_topLevelWidgetWithSurface->windowHandle();
110
111 if (nativeWindow != m_topLevelNativeWindow) {
114 m_childChangedFilter->deleteLater();
115 m_childChangedFilter.clear();
116 }
117
118 m_topLevelNativeWindow = nativeWindow;
119
121 auto *filter = new ChildChangedEventFilter(m_topLevelNativeWindow, m_topLevelNativeWindow);
122 connect(filter,
123 &ChildChangedEventFilter::sigChildrenChanged,
124 this,
126 m_childChangedFilter = filter;
127 m_topLevelNativeWindow->installEventFilter(m_childChangedFilter);
128 }
129 }
130
131 if (nativeWindow) {
132 connectToNativeWindow(nativeWindow);
133 } else {
135 }
136}
QPointer< QWindow > m_topLevelNativeWindow
virtual void disconnectFromNativeWindow()=0
virtual void connectToNativeWindow(QWindow *nativeWindow)=0
QPointer< QWidget > m_topLevelWidgetWithSurface

References connectToNativeWindow(), disconnectFromNativeWindow(), m_childChangedFilter, m_topLevelNativeWindow, m_topLevelWidgetWithSurface, and tryReconnectToNativeWindow().

◆ tryUpdateHierarchy()

void KisRootSurfaceTrackerBase::tryUpdateHierarchy ( UpdateHierarchyFlags flags = None)
private

Definition at line 89 of file KisRootSurfaceTrackerBase.cpp.

90{
91 auto newHierarchy = getCurrentHierarchy(m_watched);
92 if (newHierarchy != m_watchedHierarchy) {
93 reconnectToHierarchy(newHierarchy, flags.testFlag(AllowDeadParents));
94 QWidget *topLevel = static_cast<QWidget *>(newHierarchy.last().data());
95 if (topLevel != m_topLevelWidgetWithSurface) {
98 }
99 }
100}
void reconnectToHierarchy(const QVector< QPointer< QObject > > newHierarchy, bool allowDeadParents)
QVector< QPointer< QObject > > getCurrentHierarchy(QWidget *wdg)

References AllowDeadParents, getCurrentHierarchy(), m_topLevelWidgetWithSurface, m_watched, m_watchedHierarchy, reconnectToHierarchy(), and tryReconnectToNativeWindow().

Member Data Documentation

◆ m_childChangedFilter

QPointer<QObject> KisRootSurfaceTrackerBase::m_childChangedFilter
private

Definition at line 76 of file KisRootSurfaceTrackerBase.h.

◆ m_topLevelNativeWindow

QPointer<QWindow> KisRootSurfaceTrackerBase::m_topLevelNativeWindow
private

Definition at line 75 of file KisRootSurfaceTrackerBase.h.

◆ m_topLevelWidgetWithSurface

QPointer<QWidget> KisRootSurfaceTrackerBase::m_topLevelWidgetWithSurface
private

Definition at line 73 of file KisRootSurfaceTrackerBase.h.

◆ m_watched

QWidget* KisRootSurfaceTrackerBase::m_watched {nullptr}
private

Definition at line 70 of file KisRootSurfaceTrackerBase.h.

70{nullptr};

◆ m_watchedHierarchy

QVector<QPointer<QObject> > KisRootSurfaceTrackerBase::m_watchedHierarchy
private

Definition at line 71 of file KisRootSurfaceTrackerBase.h.


The documentation for this class was generated from the following files: