Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Compatible): Fix ImageProvider Registration #14

Merged
merged 3 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Compatible/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ set(TARGET_SOURCES
qqmlsortfilterproxymodel.cpp

desktop/menupopupwindow.cpp

lingmoui.cpp
)

target_include_directories(${TARGET}CompatibleModule PRIVATE desktop)
Expand Down Expand Up @@ -114,6 +116,7 @@ qt_add_qml_module(${TARGET}CompatibleModule
QML_FILES ${qml_files}
RESOURCES ${resource_files}
RESOURCE_PREFIX "/lingmoui/kit/compatible_module"
NO_GENERATE_PLUGIN_SOURCE
)

set_target_properties(${TARGET}CompatibleModule
Expand Down
2 changes: 1 addition & 1 deletion Compatible/iconthemeprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class IconThemeProvider : public QQuickImageProvider {
public:
IconThemeProvider();

QPixmap requestPixmap(const QString& id, QSize* realSize, const QSize& requestedSize);
QPixmap requestPixmap(const QString& id, QSize* realSize, const QSize& requestedSize) override;
};

#endif // ICONTHEMEPROVIDER_H
75 changes: 75 additions & 0 deletions Compatible/lingmoui.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#include "lingmoui.h"

#include "blurhelper/windowblur.h"
#include "iconthemeprovider.h"
#include "newiconitem.h"
#include "qqmlsortfilterproxymodel.h"
#include "shadowhelper/windowshadow.h"
#include "thememanager.h"
#include "wheelhandler.h"
#include "windowhelper.h"

#include "desktop/menupopupwindow.h"

#include <QDebug>
#include <QFontDatabase>
#include <QQmlEngine>
#include <QQuickStyle>

QUrl componentUrl(const QString& fileName)
{
return QUrl(QStringLiteral("qrc:/lingmoui/kit/compatible_module/LingmoUI/CompatibleModule/Controls/") + fileName);
}

void LingmoUI::initializeEngine(QQmlEngine* engine, const char* uri)
{
Q_ASSERT(QLatin1String(uri) == QLatin1String("LingmoUI.CompatibleModule"));

int fontId = QFontDatabase::addApplicationFont(":/lingmoui/kit/compatible_module/LingmoUI/CompatibleModule/images/fonticons/FluentSystemIcons-Regular.ttf");
QStringList fontFamilies;
fontFamilies << QFontDatabase::applicationFontFamilies(fontId);

// Set base URL to the plugin URL
engine->setBaseUrl(baseUrl());

engine->addImageProvider(QStringLiteral("icontheme"), new IconThemeProvider());
}

void LingmoUI::registerTypes(const char* uri)
{
Q_ASSERT(QLatin1String(uri) == QLatin1String("LingmoUI.CompatibleModule"));

qmlRegisterSingletonType<ThemeManager>("LingmoUI.CompatibleModule.Core", 3, 0, "ThemeManager", [](QQmlEngine* engine, QJSEngine* scriptEngine) -> QObject* {
Q_UNUSED(engine)
Q_UNUSED(scriptEngine)
return new ThemeManager;
});

qmlRegisterType<WindowShadow>(uri, 3, 0, "WindowShadow");
qmlRegisterType<WindowBlur>(uri, 3, 0, "WindowBlur");
qmlRegisterType<WindowHelper>(uri, 3, 0, "WindowHelper");
qmlRegisterType<NewIconItem>(uri, 3, 0, "IconItem");
qmlRegisterType<MenuPopupWindow>(uri, 3, 0, "MenuPopupWindow");
qmlRegisterType<WheelHandler>(uri, 3, 0, "WheelHandler");
qmlRegisterType<QQmlSortFilterProxyModel>(uri, 3, 0, "SortFilterProxyModel");

qmlRegisterSingletonType(componentUrl(QStringLiteral("Theme.qml")), uri, 3, 0, "Theme");
qmlRegisterSingletonType(componentUrl(QStringLiteral("Units.qml")), uri, 3, 0, "Units");

qmlRegisterType(componentUrl(QStringLiteral("AboutDialog.qml")), uri, 3, 0, "AboutDialog");
qmlRegisterType(componentUrl(QStringLiteral("ActionTextField.qml")), uri, 3, 0, "ActionTextField");
qmlRegisterType(componentUrl(QStringLiteral("BusyIndicator.qml")), uri, 3, 0, "BusyIndicator");
qmlRegisterType(componentUrl(QStringLiteral("Icon.qml")), uri, 3, 0, "Icon");
qmlRegisterType(componentUrl(QStringLiteral("PopupTips.qml")), uri, 3, 0, "PopupTips");
qmlRegisterType(componentUrl(QStringLiteral("RoundedRect.qml")), uri, 3, 0, "RoundedRect");
qmlRegisterType(componentUrl(QStringLiteral("TabBar.qml")), uri, 3, 0, "TabBar");
qmlRegisterType(componentUrl(QStringLiteral("TabButton.qml")), uri, 3, 0, "TabButton");
qmlRegisterType(componentUrl(QStringLiteral("TabCloseButton.qml")), uri, 3, 0, "TabCloseButton");
qmlRegisterType(componentUrl(QStringLiteral("TabView.qml")), uri, 3, 0, "TabView");
qmlRegisterType(componentUrl(QStringLiteral("Toast.qml")), uri, 3, 0, "Toast");
qmlRegisterType(componentUrl(QStringLiteral("Window.qml")), uri, 3, 0, "Window");
qmlRegisterType(componentUrl(QStringLiteral("RoundImageButton.qml")), uri, 3, 0, "RoundImageButton");
qmlRegisterType(componentUrl(QStringLiteral("DesktopMenu.qml")), uri, 3, 0, "DesktopMenu");

qmlProtectModule(uri, 1);
}
18 changes: 18 additions & 0 deletions Compatible/lingmoui.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* SPDX-FileCopyrightText: 2024 Elysia <[email protected]>
*
* SPDX-License-Identifier: GPL-3.0
*/
#pragma once

#include <QtQml/QQmlExtensionPlugin>
#include <qobject.h>

class LingmoUI : public QQmlExtensionPlugin {
Q_OBJECT
Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid)

public:
void initializeEngine(QQmlEngine *engine, const char *uri) override;
void registerTypes(const char *uri) override;
};
Loading