From a5ca07bad8e278aa6576d35972141c1cbc7a065f Mon Sep 17 00:00:00 2001 From: Ayush Singh Date: Mon, 27 Dec 2021 19:58:13 +0530 Subject: [PATCH] Added klocalizedtranslator. --- src/klocalizedtranslator.rs | 28 ++++++++++++++++++++++++++++ src/lib.rs | 1 + 2 files changed, 29 insertions(+) create mode 100644 src/klocalizedtranslator.rs diff --git a/src/klocalizedtranslator.rs b/src/klocalizedtranslator.rs new file mode 100644 index 0000000..84a1562 --- /dev/null +++ b/src/klocalizedtranslator.rs @@ -0,0 +1,28 @@ +use cpp::{cpp, cpp_class}; + +#[cfg(feature = "qmetaobject")] +use qmetaobject::{QObject, QObjectPinned}; + +cpp! {{ + #include + + struct KLocalizedTranslatorHolder { + std::unique_ptr translator; + + KLocalizedTranslatorHolder(QObject *parent) : translator(new KLocalizedTranslator(parent)) {} + }; +}} + +cpp_class!( + pub unsafe struct KLocalizedTranslator as "KLocalizedTranslatorHolder" +); + +impl KLocalizedTranslator { + #[cfg(feature = "qmetaobject")] + pub fn new(obj: QObjectPinned) -> KLocalizedTranslator { + let obj_ptr = obj.get_or_create_cpp_object(); + cpp!(unsafe [obj_ptr as "QObject *"] -> KLocalizedTranslator as "KLocalizedTranslatorHolder" { + return KLocalizedTranslatorHolder(obj_ptr); + }) + } +} diff --git a/src/lib.rs b/src/lib.rs index bad8b79..107fc87 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -47,6 +47,7 @@ pub mod klocalizedcontext; pub mod klocalizedstring; +pub mod klocalizedtranslator; // pub mod kcountry; pub mod prelude {