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 // SPDX-License-Identifier: LGPL-3.0-or-later
import QtQuick 2.12 import QtQuick 2.12
import Clipboard 0.1
FocusScope { FocusScope {
signal deselectAll() signal deselectAll()

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -37,11 +37,19 @@ int main(int argc, char *argv[]) {
objectContext->setContextProperty("debugMode", false); objectContext->setContextProperty("debugMode", false);
#endif #endif
// Add our custom non-visual `QObject `s as properties. // Register our custom non-visual QObject singletons,
// Their attributes and methods will be accessing like normal QML objects. // that will be importable anywhere in QML. Example:
/* objectContext->setContextProperty("CppUtils", new Utils()); */ // import Clipboard 0.1
objectContext->setContextProperty("Clipboard", new Clipboard()); // ...
// 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>( qmlRegisterSingletonType<Utils>(
"CppUtils", 0, 1, "CppUtils", "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, // Register our custom visual items that will be importable from QML, e.g.
// e.g. `import RadialBar 1.0` // import RadialBar 1.0
// ...
// RadialBar { ... }
qmlRegisterType<RadialBar>("RadialBar", 1, 0, "RadialBar"); qmlRegisterType<RadialBar>("RadialBar", 1, 0, "RadialBar");
// Create the QML root component by loading its file from the Qt Resource // Create the QML root component by loading its file from the Qt Resource