From a1256cf20a0832bbc9ca86f1cc50f7553626ad88 Mon Sep 17 00:00:00 2001 From: miruka Date: Fri, 27 Dec 2019 09:06:42 -0400 Subject: [PATCH] Turn Clipboard into a singleton --- src/gui/Base/HSelectableLabelContainer.qml | 1 + src/gui/GlobalShortcuts.qml | 1 + src/gui/MainPane/AccountDelegate.qml | 1 + src/gui/MainPane/RoomDelegate.qml | 1 + src/gui/Pages/Chat/Composer.qml | 1 + .../Pages/Chat/RoomPane/MemberDelegate.qml | 1 + src/gui/Pages/Chat/Timeline/EventDelegate.qml | 1 + src/main.cpp | 24 +++++++++++++------ 8 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/gui/Base/HSelectableLabelContainer.qml b/src/gui/Base/HSelectableLabelContainer.qml index 3f45bd3c..82e481d9 100644 --- a/src/gui/Base/HSelectableLabelContainer.qml +++ b/src/gui/Base/HSelectableLabelContainer.qml @@ -1,6 +1,7 @@ // SPDX-License-Identifier: LGPL-3.0-or-later import QtQuick 2.12 +import Clipboard 0.1 FocusScope { signal deselectAll() diff --git a/src/gui/GlobalShortcuts.qml b/src/gui/GlobalShortcuts.qml index 02960126..ca7e525c 100644 --- a/src/gui/GlobalShortcuts.qml +++ b/src/gui/GlobalShortcuts.qml @@ -2,6 +2,7 @@ import QtQuick 2.12 import QtQuick.Controls 2.12 +import Clipboard 0.1 import "Base" Item { diff --git a/src/gui/MainPane/AccountDelegate.qml b/src/gui/MainPane/AccountDelegate.qml index afe8a43b..409135e5 100644 --- a/src/gui/MainPane/AccountDelegate.qml +++ b/src/gui/MainPane/AccountDelegate.qml @@ -2,6 +2,7 @@ import QtQuick 2.12 import QtQuick.Layouts 1.12 +import Clipboard 0.1 import "../Base" HTileDelegate { diff --git a/src/gui/MainPane/RoomDelegate.qml b/src/gui/MainPane/RoomDelegate.qml index 0fa9d659..3899485c 100644 --- a/src/gui/MainPane/RoomDelegate.qml +++ b/src/gui/MainPane/RoomDelegate.qml @@ -2,6 +2,7 @@ import QtQuick 2.12 import QtQuick.Layouts 1.12 +import Clipboard 0.1 import "../Base" HTileDelegate { diff --git a/src/gui/Pages/Chat/Composer.qml b/src/gui/Pages/Chat/Composer.qml index 761694a7..b2979a78 100644 --- a/src/gui/Pages/Chat/Composer.qml +++ b/src/gui/Pages/Chat/Composer.qml @@ -2,6 +2,7 @@ import QtQuick 2.12 import QtQuick.Layouts 1.12 +import Clipboard 0.1 import "../../Base" import "../../Dialogs" diff --git a/src/gui/Pages/Chat/RoomPane/MemberDelegate.qml b/src/gui/Pages/Chat/RoomPane/MemberDelegate.qml index 405e3122..6b9d93fd 100644 --- a/src/gui/Pages/Chat/RoomPane/MemberDelegate.qml +++ b/src/gui/Pages/Chat/RoomPane/MemberDelegate.qml @@ -1,6 +1,7 @@ // SPDX-License-Identifier: LGPL-3.0-or-later import QtQuick 2.12 +import Clipboard 0.1 import "../../../Base" HTileDelegate { diff --git a/src/gui/Pages/Chat/Timeline/EventDelegate.qml b/src/gui/Pages/Chat/Timeline/EventDelegate.qml index 833c2501..dba68ec4 100644 --- a/src/gui/Pages/Chat/Timeline/EventDelegate.qml +++ b/src/gui/Pages/Chat/Timeline/EventDelegate.qml @@ -2,6 +2,7 @@ import QtQuick 2.12 import QtQuick.Layouts 1.12 +import Clipboard 0.1 import "../../../Base" HColumnLayout { diff --git a/src/main.cpp b/src/main.cpp index 66ca27f5..12004440 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -37,11 +37,19 @@ int main(int argc, char *argv[]) { objectContext->setContextProperty("debugMode", false); #endif - // Add our custom non-visual `QObject `s as properties. - // Their attributes and methods will be accessing like normal QML objects. - /* objectContext->setContextProperty("CppUtils", new Utils()); */ - objectContext->setContextProperty("Clipboard", new Clipboard()); - + // Register our custom non-visual QObject singletons, + // that will be importable anywhere in QML. Example: + // import Clipboard 0.1 + // ... + // Component.onCompleted: print(Clipboard.text) + qmlRegisterSingletonType( + "Clipboard", 0, 1, "Clipboard", + [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject * { + Q_UNUSED(engine) + Q_UNUSED(scriptEngine) + return new Clipboard(); + } + ); qmlRegisterSingletonType( "CppUtils", 0, 1, "CppUtils", @@ -52,8 +60,10 @@ int main(int argc, char *argv[]) { } ); - // Register our custom visual items that will be importable from QML, - // e.g. `import RadialBar 1.0` + // Register our custom visual items that will be importable from QML, e.g. + // import RadialBar 1.0 + // ... + // RadialBar { ... } qmlRegisterType("RadialBar", 1, 0, "RadialBar"); // Create the QML root component by loading its file from the Qt Resource