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

#include <KisRootSurfaceTrackerBase.h>

+ Inheritance diagram for KisRootSurfaceTrackerBase:

Public Member Functions

 KisRootSurfaceTrackerBase (QWidget *watched, QObject *parent=nullptr)
 
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)
 
void tryReconnectToNativeWindow ()
 
void tryUpdateHierarchy ()
 

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.

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}
QVector< QPointer< QObject > > m_watchedHierarchy

References 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().

◆ reconnectToHierarchy()

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

Definition at line 156 of file KisRootSurfaceTrackerBase.cpp.

157{
158 Q_FOREACH (QPointer<QObject> widget, m_watchedHierarchy) {
159 KIS_SAFE_ASSERT_RECOVER(widget) continue;
160 widget->removeEventFilter(this);
161 }
162
163 m_watchedHierarchy.clear();
164
165 Q_FOREACH (QPointer<QObject> widget, newHierarchy) {
166 widget->installEventFilter(this);
167 }
168
169 m_watchedHierarchy = newHierarchy;
170}
#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 ( )
private

Definition at line 89 of file KisRootSurfaceTrackerBase.cpp.

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

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

Member Data Documentation

◆ m_childChangedFilter

QPointer<QObject> KisRootSurfaceTrackerBase::m_childChangedFilter
private

Definition at line 69 of file KisRootSurfaceTrackerBase.h.

◆ m_topLevelNativeWindow

QPointer<QWindow> KisRootSurfaceTrackerBase::m_topLevelNativeWindow
private

Definition at line 68 of file KisRootSurfaceTrackerBase.h.

◆ m_topLevelWidgetWithSurface

QPointer<QWidget> KisRootSurfaceTrackerBase::m_topLevelWidgetWithSurface
private

Definition at line 66 of file KisRootSurfaceTrackerBase.h.

◆ m_watched

QWidget* KisRootSurfaceTrackerBase::m_watched {nullptr}
private

Definition at line 63 of file KisRootSurfaceTrackerBase.h.

63{nullptr};

◆ m_watchedHierarchy

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

Definition at line 64 of file KisRootSurfaceTrackerBase.h.


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