diff --git a/src/ui/HiddenEvents.h b/src/ui/HiddenEvents.h
index bb68e0fa..4f0d23b4 100644
--- a/src/ui/HiddenEvents.h
+++ b/src/ui/HiddenEvents.h
@@ -5,6 +5,7 @@
#pragma once
#include <QObject>
+#include <QQmlEngine>
#include <QString>
#include <QVariantList>
@@ -13,6 +14,7 @@
class HiddenEvents : public QObject
{
Q_OBJECT
+ QML_ELEMENT
Q_PROPERTY(QString roomid READ roomid WRITE setRoomid NOTIFY roomidChanged REQUIRED)
Q_PROPERTY(QVariantList hiddenEvents READ hiddenEvents NOTIFY hiddenEventsChanged)
public:
diff --git a/src/ui/MxcAnimatedImage.h b/src/ui/MxcAnimatedImage.h
index bc53e711..c9f89764 100644
--- a/src/ui/MxcAnimatedImage.h
+++ b/src/ui/MxcAnimatedImage.h
@@ -15,6 +15,7 @@
class MxcAnimatedImage : public QQuickItem
{
Q_OBJECT
+ QML_ELEMENT
Q_PROPERTY(TimelineModel *roomm READ room WRITE setRoom NOTIFY roomChanged REQUIRED)
Q_PROPERTY(QString eventId READ eventId WRITE setEventId NOTIFY eventIdChanged)
Q_PROPERTY(bool animatable READ animatable NOTIFY animatableChanged)
diff --git a/src/ui/MxcMediaProxy.h b/src/ui/MxcMediaProxy.h
index 5c2eac33..d245dcae 100644
--- a/src/ui/MxcMediaProxy.h
+++ b/src/ui/MxcMediaProxy.h
@@ -8,6 +8,7 @@
#include <QMediaPlayer>
#include <QObject>
#include <QPointer>
+#include <QQuickItem>
#include <QString>
#include <QUrl>
#include <QVideoSink>
@@ -21,6 +22,8 @@ class TimelineModel;
class MxcMediaProxy : public QMediaPlayer
{
Q_OBJECT
+ QML_NAMED_ELEMENT(MxcMedia)
+
Q_PROPERTY(TimelineModel *roomm READ room WRITE setRoom NOTIFY roomChanged REQUIRED)
Q_PROPERTY(QString eventId READ eventId WRITE setEventId NOTIFY eventIdChanged)
Q_PROPERTY(bool loaded READ loaded NOTIFY loadedChanged)
diff --git a/src/ui/NhekoCursorShape.h b/src/ui/NhekoCursorShape.h
index 84d56fad..123852f9 100644
--- a/src/ui/NhekoCursorShape.h
+++ b/src/ui/NhekoCursorShape.h
@@ -12,7 +12,7 @@
class NhekoCursorShape : public QQuickItem
{
Q_OBJECT
-
+ QML_ELEMENT
Q_PROPERTY(
Qt::CursorShape cursorShape READ cursorShape WRITE setCursorShape NOTIFY cursorShapeChanged)
diff --git a/src/ui/NhekoDropArea.h b/src/ui/NhekoDropArea.h
index 91116844..46a02da5 100644
--- a/src/ui/NhekoDropArea.h
+++ b/src/ui/NhekoDropArea.h
@@ -7,6 +7,7 @@
class NhekoDropArea : public QQuickItem
{
Q_OBJECT
+ QML_ELEMENT
Q_PROPERTY(QString roomid READ roomid WRITE setRoomid NOTIFY roomidChanged)
public:
NhekoDropArea(QQuickItem *parent = nullptr);
diff --git a/src/ui/NhekoEventObserver.cpp b/src/ui/NhekoEventObserver.cpp
deleted file mode 100644
index 713a0733..00000000
--- a/src/ui/NhekoEventObserver.cpp
+++ /dev/null
@@ -1,60 +0,0 @@
-// SPDX-FileCopyrightText: Nheko Contributors
-//
-// SPDX-License-Identifier: GPL-3.0-or-later
-
-#include "NhekoEventObserver.h"
-
-#include <QMouseEvent>
-
-#include "Logging.h"
-
-NhekoEventObserver::NhekoEventObserver(QQuickItem *parent)
- : QQuickItem(parent)
-{
- setFiltersChildMouseEvents(true);
-}
-
-bool
-NhekoEventObserver::childMouseEventFilter(QQuickItem * /*item*/, QEvent *event)
-{
- // nhlog::ui()->debug("Touched {}", item->metaObject()->className());
-
- auto setTouched = [this](bool touched) {
- if (touched != this->wasTouched_) {
- this->wasTouched_ = touched;
- emit wasTouchedChanged();
- }
- };
-
- // see
- // https://code.qt.io/cgit/qt/qtdeclarative.git/tree/src/quicktemplates2/qquickscrollview.cpp?id=7f29e89c26ae2babc358b1c4e6f965af6ec759f4#n471
- switch (event->type()) {
- case QEvent::TouchBegin:
- case QEvent::TouchEnd:
- setTouched(true);
- break;
-
- case QEvent::MouseButtonPress:
- if (static_cast<QMouseEvent *>(event)->source() == Qt::MouseEventNotSynthesized) {
- setTouched(false);
- }
- break;
-
- case QEvent::MouseMove:
- case QEvent::MouseButtonRelease:
- if (static_cast<QMouseEvent *>(event)->source() == Qt::MouseEventNotSynthesized)
- setTouched(false);
- break;
-
- case QEvent::HoverEnter:
- case QEvent::HoverMove:
- case QEvent::Wheel:
- setTouched(false);
- break;
-
- default:
- break;
- }
-
- return false;
-}
diff --git a/src/ui/NhekoEventObserver.h b/src/ui/NhekoEventObserver.h
deleted file mode 100644
index 63739d4a..00000000
--- a/src/ui/NhekoEventObserver.h
+++ /dev/null
@@ -1,27 +0,0 @@
-// SPDX-FileCopyrightText: Nheko Contributors
-//
-// SPDX-License-Identifier: GPL-3.0-or-later
-
-#pragma once
-
-#include <QQuickItem>
-
-class NhekoEventObserver : public QQuickItem
-{
- Q_OBJECT
-
- Q_PROPERTY(bool wasTouched READ wasTouched NOTIFY wasTouchedChanged)
-
-public:
- explicit NhekoEventObserver(QQuickItem *parent = 0);
-
- bool childMouseEventFilter(QQuickItem *item, QEvent *event) override;
-
-private:
- bool wasTouched() { return wasTouched_; }
-
- bool wasTouched_ = false;
-
-signals:
- void wasTouchedChanged();
-};
diff --git a/src/ui/NhekoGlobalObject.h b/src/ui/NhekoGlobalObject.h
index b7a7a637..91210c54 100644
--- a/src/ui/NhekoGlobalObject.h
+++ b/src/ui/NhekoGlobalObject.h
@@ -7,6 +7,7 @@
#include <QFontDatabase>
#include <QObject>
#include <QPalette>
+#include <QQmlEngine>
#include <QWindow>
#include "AliasEditModel.h"
@@ -19,6 +20,9 @@ class Nheko final : public QObject
{
Q_OBJECT
+ QML_ELEMENT
+ QML_SINGLETON
+
Q_PROPERTY(QPalette colors READ colors NOTIFY colorsChanged)
Q_PROPERTY(QPalette inactiveColors READ inactiveColors NOTIFY colorsChanged)
Q_PROPERTY(Theme theme READ theme NOTIFY colorsChanged)
diff --git a/src/ui/RoomSummary.h b/src/ui/RoomSummary.h
index c02ea5d5..8225f0ae 100644
--- a/src/ui/RoomSummary.h
+++ b/src/ui/RoomSummary.h
@@ -7,6 +7,7 @@
#include <optional>
#include <QObject>
+#include <QQmlEngine>
#include <mtx/responses/public_rooms.hpp>
@@ -25,6 +26,9 @@ class RoomSummary final : public QObject
{
Q_OBJECT
+ QML_ELEMENT
+ QML_UNCREATABLE("Please use joinRoom to create a room summary.")
+
Q_PROPERTY(QString reason READ reason WRITE setReason NOTIFY reasonChanged)
Q_PROPERTY(QString roomid READ roomid NOTIFY loaded)
diff --git a/src/ui/UIA.h b/src/ui/UIA.h
index 7d23d88e..414cb804 100644
--- a/src/ui/UIA.h
+++ b/src/ui/UIA.h
@@ -5,6 +5,7 @@
#pragma once
#include <QObject>
+#include <QQmlEngine>
#include <mtxclient/http/client.hpp>
@@ -12,10 +13,31 @@ class UIA final : public QObject
{
Q_OBJECT
+ QML_ELEMENT
+ QML_SINGLETON
+
Q_PROPERTY(QString title READ title NOTIFY titleChanged)
public:
static UIA *instance();
+ static UIA *create(QQmlEngine *qmlEngine, QJSEngine *)
+ {
+ // The instance has to exist before it is used. We cannot replace it.
+ Q_ASSERT(instance());
+
+ // The engine has to have the same thread affinity as the singleton.
+ Q_ASSERT(qmlEngine->thread() == instance()->thread());
+
+ // There can only be one engine accessing the singleton.
+ static QJSEngine *s_engine = nullptr;
+ if (s_engine)
+ Q_ASSERT(qmlEngine == s_engine);
+ else
+ s_engine = qmlEngine;
+
+ QJSEngine::setObjectOwnership(instance(), QJSEngine::CppOwnership);
+ return instance();
+ }
UIA(QObject *parent = nullptr)
: QObject(parent)
diff --git a/src/ui/UserProfile.h b/src/ui/UserProfile.h
index a880f320..d8e06aa1 100644
--- a/src/ui/UserProfile.h
+++ b/src/ui/UserProfile.h
@@ -6,6 +6,7 @@
#include <QAbstractListModel>
#include <QObject>
+#include <QQmlEngine>
#include <QString>
#include <QVector>
#include <mtx/responses.hpp>
@@ -16,6 +17,7 @@
namespace verification {
Q_NAMESPACE
+QML_NAMED_ELEMENT(VerificationStatus)
enum Status
{
|