Turn Clipboard into a singleton

This commit is contained in:
miruka 2019-12-27 09:06:42 -04:00
parent f34d2a1c6d
commit a1256cf20a
8 changed files with 24 additions and 7 deletions

View File

@ -1,6 +1,7 @@
// SPDX-License-Identifier: LGPL-3.0-or-later
import QtQuick 2.12
import Clipboard 0.1
FocusScope {
signal deselectAll()

View File

@ -2,6 +2,7 @@
import QtQuick 2.12
import QtQuick.Controls 2.12
import Clipboard 0.1
import "Base"
Item {

View File

@ -2,6 +2,7 @@
import QtQuick 2.12
import QtQuick.Layouts 1.12
import Clipboard 0.1
import "../Base"
HTileDelegate {

View File

@ -2,6 +2,7 @@
import QtQuick 2.12
import QtQuick.Layouts 1.12
import Clipboard 0.1
import "../Base"
HTileDelegate {

View File

@ -2,6 +2,7 @@
import QtQuick 2.12
import QtQuick.Layouts 1.12
import Clipboard 0.1
import "../../Base"
import "../../Dialogs"

View File

@ -1,6 +1,7 @@
// SPDX-License-Identifier: LGPL-3.0-or-later
import QtQuick 2.12
import Clipboard 0.1
import "../../../Base"
HTileDelegate {

View File

@ -2,6 +2,7 @@
import QtQuick 2.12
import QtQuick.Layouts 1.12
import Clipboard 0.1
import "../../../Base"
HColumnLayout {

View File

@ -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>(
"Clipboard", 0, 1, "Clipboard",
[](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject * {
Q_UNUSED(engine)
Q_UNUSED(scriptEngine)
return new Clipboard();
}
);
qmlRegisterSingletonType<Utils>(
"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>("RadialBar", 1, 0, "RadialBar");
// Create the QML root component by loading its file from the Qt Resource