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 {