diff --git a/crates/cxx-qt-lib/build.rs b/crates/cxx-qt-lib/build.rs index a647e2480..8b2bb2e77 100644 --- a/crates/cxx-qt-lib/build.rs +++ b/crates/cxx-qt-lib/build.rs @@ -237,7 +237,11 @@ fn main() { } if qt_qml_enabled() { - rust_bridges.extend(["qml/qqmlapplicationengine", "qml/qqmlengine"]); + rust_bridges.extend([ + "qml/qqmlapplicationengine", + "qml/qqmlengine", + "qml/qqmlimageproviderbase", + ]); } if qt_quickcontrols_enabled() { @@ -312,7 +316,11 @@ fn main() { } if qt_qml_enabled() { - cpp_files.extend(["qml/qqmlapplicationengine", "qml/qqmlengine"]); + cpp_files.extend([ + "qml/qqmlapplicationengine", + "qml/qqmlengine", + "qml/qqmlimageproviderbase", + ]); } if !emscripten_targeted { diff --git a/crates/cxx-qt-lib/include/qml/qqmlimageproviderbase.h b/crates/cxx-qt-lib/include/qml/qqmlimageproviderbase.h new file mode 100644 index 000000000..9d80b1bcb --- /dev/null +++ b/crates/cxx-qt-lib/include/qml/qqmlimageproviderbase.h @@ -0,0 +1,24 @@ +// clang-format off +// SPDX-FileCopyrightText: 2026 Klarälvdalens Datakonsult AB, a KDAB Group company +// clang-format on +// SPDX-FileContributor: Darshan Phaldesai +// +// SPDX-License-Identifier: MIT OR Apache-2.0 +#pragma once + +// The definitions file is auto-generated by the build script +#include + +#ifdef CXX_QT_QML_FEATURE + +#include + +namespace rust { +namespace cxxqtlib1 { + +using QQmlImageProviderBaseImageType = QQmlImageProviderBase::ImageType; + +} +} + +#endif diff --git a/crates/cxx-qt-lib/include/qqmlimageproviderbase.h b/crates/cxx-qt-lib/include/qqmlimageproviderbase.h new file mode 100644 index 000000000..53e06655f --- /dev/null +++ b/crates/cxx-qt-lib/include/qqmlimageproviderbase.h @@ -0,0 +1,9 @@ +// clang-format off +// SPDX-FileCopyrightText: 2026 Klarälvdalens Datakonsult AB, a KDAB Group company +// clang-format on +// SPDX-FileContributor: Darshan Phaldesai +// +// SPDX-License-Identifier: MIT OR Apache-2.0 +#pragma once + +#include "qml/qqmlimageproviderbase.h" diff --git a/crates/cxx-qt-lib/src/qml/mod.rs b/crates/cxx-qt-lib/src/qml/mod.rs index 589405e49..38bddb753 100644 --- a/crates/cxx-qt-lib/src/qml/mod.rs +++ b/crates/cxx-qt-lib/src/qml/mod.rs @@ -8,3 +8,7 @@ pub use qqmlapplicationengine::QQmlApplicationEngine; mod qqmlengine; pub use qqmlengine::QQmlEngine; + +mod qqmlimageproviderbase; +pub use qqmlimageproviderbase::QQmlImageProviderBase; +pub use qqmlimageproviderbase::QQmlImageProviderBaseImageType; diff --git a/crates/cxx-qt-lib/src/qml/qqmlapplicationengine.rs b/crates/cxx-qt-lib/src/qml/qqmlapplicationengine.rs index f9f6a0cbf..f06fdaaff 100644 --- a/crates/cxx-qt-lib/src/qml/qqmlapplicationengine.rs +++ b/crates/cxx-qt-lib/src/qml/qqmlapplicationengine.rs @@ -17,6 +17,9 @@ mod ffi { include!("cxx-qt-lib/qurl.h"); type QUrl = crate::QUrl; + include!("cxx-qt-lib/qqmlimageproviderbase.h"); + type QQmlImageProviderBase = crate::QQmlImageProviderBase; + /// Adds `path` as a directory where the engine searches for installed modules in a URL-based directory structure. #[rust_name = "add_import_path"] fn addImportPath(self: Pin<&mut QQmlApplicationEngine>, path: &QString); @@ -71,6 +74,17 @@ mod ffi { /// Sets `path` as string for storing offline user data. #[rust_name = "set_offline_storage_path"] fn setOfflineStoragePath(self: Pin<&mut QQmlApplicationEngine>, dir: &QString); + + #[rust_name = "add_image_provider"] + unsafe fn addImageProvider( + self: Pin<&mut QQmlApplicationEngine>, + provider_id: &QString, + provider: *mut QQmlImageProviderBase, + ); + + #[rust_name = "remove_image_provider"] + fn removeImageProvider(self: Pin<&mut QQmlApplicationEngine>, provider_id: &QString); + } unsafe extern "C++Qt" { diff --git a/crates/cxx-qt-lib/src/qml/qqmlimageproviderbase.cpp b/crates/cxx-qt-lib/src/qml/qqmlimageproviderbase.cpp new file mode 100644 index 000000000..3773d2b5b --- /dev/null +++ b/crates/cxx-qt-lib/src/qml/qqmlimageproviderbase.cpp @@ -0,0 +1,8 @@ +// clang-format off +// SPDX-FileCopyrightText: 2026 Klarälvdalens Datakonsult AB, a KDAB Group company +// clang-format on +// SPDX-FileContributor: Darshan Phaldesai +// +// SPDX-License-Identifier: MIT OR Apache-2.0 + +#include "cxx-qt-lib/qqmlimageproviderbase.h" diff --git a/crates/cxx-qt-lib/src/qml/qqmlimageproviderbase.rs b/crates/cxx-qt-lib/src/qml/qqmlimageproviderbase.rs new file mode 100644 index 000000000..9830e6f7f --- /dev/null +++ b/crates/cxx-qt-lib/src/qml/qqmlimageproviderbase.rs @@ -0,0 +1,34 @@ +// SPDX-FileCopyrightText: 2026 Klarälvdalens Datakonsult AB, a KDAB Group company +// SPDX-FileContributor: Darshan Phaldesai +// +// SPDX-License-Identifier: MIT OR Apache-2.0 + +#[cxx_qt::bridge] +mod ffi { + + #[repr(i32)] + #[namespace = "rust::cxxqtlib1"] + #[derive(Debug)] + enum QQmlImageProviderBaseImageType { + Invalid = 0, + Image, + Pixmap, + Texture, + ImageResponse, + } + + extern "C++Qt" { + include!("cxx-qt-lib/qqmlimageproviderbase.h"); + + #[qobject] + type QQmlImageProviderBase; + } + + #[namespace = "rust::cxxqtlib1"] + unsafe extern "C++" { + type QQmlImageProviderBaseImageType; + } +} + +pub use ffi::QQmlImageProviderBase; +pub use ffi::QQmlImageProviderBaseImageType;