Skip to content

Commit f963da1

Browse files
committed
Add object helper
1 parent 0339e9e commit f963da1

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

src/core/qwkglobal_p.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
// version without notice, or may even be removed.
1111
//
1212

13+
#include <QtCore/QObject>
1314
#include <QtCore/QLoggingCategory>
1415
#include <QtGui/QMouseEvent>
1516

@@ -42,22 +43,32 @@ QWK_CORE_EXPORT Q_DECLARE_LOGGING_CATEGORY(qWindowKitLog)
4243

4344
namespace QWK {
4445

46+
namespace Private {
47+
48+
class ObjectHelper : public QObject {
49+
public:
50+
static inline bool sendEvent(QObject *obj, QEvent *event) {
51+
return static_cast<ObjectHelper *>(obj)->event(event);
52+
}
53+
};
54+
55+
}
56+
4557
inline QPoint getMouseEventScenePos(const QMouseEvent *event) {
4658
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
4759
return event->scenePosition().toPoint();
4860
#else
4961
return event->windowPos().toPoint();
5062
#endif
5163
}
52-
64+
5365
inline QPoint getMouseEventGlobalPos(const QMouseEvent *event) {
5466
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
5567
return event->globalPosition().toPoint();
5668
#else
5769
return event->screenPos().toPoint();
5870
#endif
5971
}
60-
6172
}
6273

6374
#endif // QWKGLOBAL_P_H

src/quick/quickwindowagent.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ namespace QWK {
3131
Q_INVOKABLE void setHitTestVisible(const QQuickItem *item, bool visible = true);
3232

3333
#ifdef Q_OS_MAC
34-
QQuickItem *systemButtonArea() const;
35-
void setSystemButtonArea(QQuickItem *item);
34+
Q_INVOKABLE QQuickItem *systemButtonArea() const;
35+
Q_INVOKABLE void setSystemButtonArea(QQuickItem *item);
3636
#endif
3737

3838
Q_SIGNALS:

src/widgets/widgetwindowagent_win.cpp

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <QtGui/QPainter>
66

77
#include <QWKCore/qwindowkit_windows.h>
8+
#include <QWKCore/private/qwkglobal_p.h>
89

910
namespace QWK {
1011

@@ -68,14 +69,8 @@ namespace QWK {
6869
}
6970

7071
inline void resumeWidgetEventAndDraw(QWidget *w, QEvent *event) {
71-
// Friend class helping to call `event`
72-
class HackedWidget : public QWidget {
73-
public:
74-
friend class QWK::WidgetBorderHandler;
75-
};
76-
7772
// Let the widget paint first
78-
static_cast<HackedWidget *>(w)->event(event);
73+
Private::ObjectHelper::sendEvent(w, event);
7974

8075
// Due to the timer or user action, Qt will repaint some regions spontaneously,
8176
// even if there is no WM_PAINT message, we must wait for it to finish painting
@@ -84,14 +79,8 @@ namespace QWK {
8479
}
8580

8681
inline void resumeWindowEventAndDraw(QWindow *window, QEvent *event) {
87-
// Friend class helping to call `event`
88-
class HackedWindow : public QWindow {
89-
public:
90-
friend class QWK::WidgetBorderHandler;
91-
};
92-
9382
// Let Qt paint first
94-
static_cast<HackedWindow *>(window)->event(event);
83+
Private::ObjectHelper::sendEvent(window, event);
9584

9685
// Upon receiving the WM_PAINT message, Qt will repaint the entire view, and we
9786
// must wait for it to finish painting before drawing this top border area.

0 commit comments

Comments
 (0)