Initial Commit.

This commit is contained in:
Ayush Singh 2021-11-01 15:01:02 +05:30
commit 2c6be797a3
5 changed files with 128 additions and 0 deletions

27
src/lib.rs Normal file
View file

@ -0,0 +1,27 @@
use cpp::{cpp, cpp_class};
use qmetaobject::prelude::*;
use qmetaobject::QObjectPinned;
cpp! {{
#include <KLocalizedContext>
#include <QtCore/QObject>
#include <QtQml/QQmlEngine>
#include <QtQuick/QtQuick>
struct KLocalizedContextHolder {
std::unique_ptr<KLocalizedContext> klocalized;
KLocalizedContextHolder(QObject *parent) : klocalized(new KLocalizedContext(parent)) {}
};
}}
cpp_class!(pub unsafe struct KLocalizedContext as "KLocalizedContextHolder");
impl KLocalizedContext {
pub fn init_from_engine(engine: &QmlEngine) {
let engine_ptr = engine.cpp_ptr();
cpp!(unsafe [engine_ptr as "QQmlEngine*"] {
engine_ptr->rootContext()->setContextObject(new KLocalizedContext(engine_ptr));
});
}
}