Skip to content

Commit

Permalink
feat(GraphicalEffects): add own port of GraphicalEffects & fix minor …
Browse files Browse the repository at this point in the history
…issues (#19)

* fix: Minor issue on radius and colour

* docs: add comment

* fix(build): Fix platform judgement

* fix(example): QML import PATH error

* feat(GraphicalEffects): add own port of GraphicalEffects

* chore: Update GraphicalEffects calls

* fix(GraphicalEffects): fix class name and qrc import path

* feat(example): add a rendering backend checker
  • Loading branch information
elysia-best authored Jan 23, 2025
1 parent 0f84941 commit f4f67b8
Show file tree
Hide file tree
Showing 98 changed files with 7,625 additions and 57 deletions.
2 changes: 1 addition & 1 deletion Compatible/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ set(TARGET_SOURCES

target_include_directories(${TARGET}CompatibleModule PRIVATE desktop)

if (MSVC)
if (CMAKE_HOST_SYSTEM_NAME MATCHES "Windows")
list(APPEND TARGET_SOURCES
platforms/windows/windowhelper.cpp platforms/windows/windowhelper.h
platforms/windows/blurhelper/windowblur.cpp platforms/windows/blurhelper/windowblur.h
Expand Down
2 changes: 1 addition & 1 deletion Compatible/Controls/AboutDialog.qml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import Qt5Compat.GraphicalEffects
import LingmoUI.GraphicalEffects
import LingmoUI.CompatibleModule as LingmoUI

LingmoUI.Window {
Expand Down
2 changes: 1 addition & 1 deletion Compatible/Controls/BusyIndicator.qml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import QtQuick
import QtQuick.Controls
import Qt5Compat.GraphicalEffects
import LingmoUI.GraphicalEffects
import LingmoUI.CompatibleModule as LingmoUI

Image {
Expand Down
2 changes: 1 addition & 1 deletion Compatible/Controls/RoundedRect.qml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import QtQuick 2.12
import QtQuick.Controls 2.12
import Qt5Compat.GraphicalEffects
import LingmoUI.GraphicalEffects

import LingmoUI.CompatibleModule as LingmoUI

Expand Down
2 changes: 1 addition & 1 deletion Compatible/Controls/Toast.qml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import QtQuick 2.15
import QtQuick.Controls
import QtQuick.Layouts
import Qt5Compat.GraphicalEffects
import LingmoUI.GraphicalEffects
import LingmoUI.CompatibleModule as LingmoUI

Popup {
Expand Down
2 changes: 1 addition & 1 deletion Compatible/Controls/Window.qml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import QtQuick.Window
import QtQuick.Controls
import QtQuick.Layouts
import QtQuick.Shapes
import Qt5Compat.GraphicalEffects
import LingmoUI.GraphicalEffects

import LingmoUI.CompatibleModule 3.0 as LingmoUI

Expand Down
2 changes: 1 addition & 1 deletion Compatible/lingmo-style/BorderButton.qml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import QtQuick 2.12
import QtQuick.Templates 2.12 as T
import Qt5Compat.GraphicalEffects
import LingmoUI.GraphicalEffects
import LingmoUI 3.0 as LingmoUI
import QtQuick.Controls.impl 2.12

Expand Down
2 changes: 1 addition & 1 deletion Compatible/lingmo-style/Button.qml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import QtQuick 2.12
import QtQuick.Templates 2.12 as T
import Qt5Compat.GraphicalEffects
import LingmoUI.GraphicalEffects
import LingmoUI.CompatibleModule 3.0 as LingmoUI
import QtQuick.Controls.impl 2.12

Expand Down
2 changes: 1 addition & 1 deletion Compatible/lingmo-style/ComboBox.qml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import QtQuick.Window 2.4
import QtQuick.Controls 2.4
import QtQuick.Controls.impl 2.4
import QtQuick.Templates 2.12 as T
import Qt5Compat.GraphicalEffects
import LingmoUI.GraphicalEffects
import LingmoUI.CompatibleModule 3.0 as LingmoUI

T.ComboBox {
Expand Down
2 changes: 1 addition & 1 deletion Compatible/lingmo-style/Dialog.qml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@


import QtQuick 2.6
import Qt5Compat.GraphicalEffects
import LingmoUI.GraphicalEffects
import QtQuick.Templates 2.3 as T
import LingmoUI.CompatibleModule 3.0 as LingmoUI

Expand Down
2 changes: 1 addition & 1 deletion Compatible/lingmo-style/Menu.qml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import QtQuick.Controls 2.12
import QtQuick.Templates 2.12 as T
import QtQuick.Window 2.12
import LingmoUI.CompatibleModule 3.0 as LingmoUI
import Qt5Compat.GraphicalEffects
import LingmoUI.GraphicalEffects

T.Menu
{
Expand Down
2 changes: 1 addition & 1 deletion Compatible/lingmo-style/ProgressBar.qml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

import QtQuick 2.12
import QtQuick.Templates 2.12 as T
import Qt5Compat.GraphicalEffects
import LingmoUI.GraphicalEffects
import LingmoUI.CompatibleModule 3.0 as LingmoUI
import QtQuick.Controls.impl 2.12

Expand Down
2 changes: 1 addition & 1 deletion Compatible/lingmo-style/Slider.qml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import QtQuick 2.6
import QtQuick.Templates 2.3 as T
import Qt5Compat.GraphicalEffects
import LingmoUI.GraphicalEffects
import LingmoUI.CompatibleModule 3.0 as LingmoUI

T.Slider {
Expand Down
2 changes: 1 addition & 1 deletion Compatible/lingmo-style/TabBar.qml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import QtQuick 2.9
import QtQuick.Templates 2.2 as T
import Qt5Compat.GraphicalEffects
import LingmoUI.GraphicalEffects
import LingmoUI.CompatibleModule 3.0 as LingmoUI

T.TabBar {
Expand Down
2 changes: 1 addition & 1 deletion Compatible/lingmo-style/ToolTip.qml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@


import QtQuick 2.6
import Qt5Compat.GraphicalEffects
import LingmoUI.GraphicalEffects
import QtQuick.Controls 2.3 as Controls
import QtQuick.Templates 2.3 as T
import LingmoUI.CompatibleModule 3.0 as LingmoUI
Expand Down
4 changes: 2 additions & 2 deletions LingmoStyle/Button.qml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ T.Button {

icon.width: 20
icon.height: 20
icon.color: Color.transparent(Universal.foreground, enabled ? 1.0 : 0.2)
icon.color: Color.transparent(control.textColor, enabled ? 1.0 : 0.2)

Accessible.role: Accessible.Button
Accessible.name: control.text
Expand Down Expand Up @@ -89,7 +89,7 @@ T.Button {
background: LingmoControlBackground {
implicitWidth: 30
implicitHeight: 30
radius: LingmoTheme.roundWindowRadius
radius: LingmoTheme.smallRadius
color: {
if (!enabled) {
return disableColor
Expand Down
4 changes: 2 additions & 2 deletions LingmoStyle/DelayButton.qml
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ T.DelayButton {
background: LingmoControlBackground {
implicitWidth: 30
implicitHeight: 30
radius: LingmoUnits.windowRadius
radius: LingmoUnits.smallRadius
border.color: LingmoTheme.dark ? Qt.rgba(
48 / 255, 48 / 255, 48 / 255,
1) : Qt.rgba(188 / 255, 188 / 255, 188 / 255, 1)
Expand All @@ -157,7 +157,7 @@ T.DelayButton {
}
LingmoClip {
anchors.fill: parent
radius: {return new Array(4).fill(LingmoUnits.windowRadius);}
radius: {return new Array(4).fill(LingmoUnits.smallRadius);}
Rectangle {
id: rect_back
width: parent.width * control.progress
Expand Down
1 change: 0 additions & 1 deletion LingmoStyle/Menu.qml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import QtQuick
import QtQuick.Templates as T
import QtQuick.Controls.Universal
import QtQuick.Window

T.Menu {
Expand Down
6 changes: 3 additions & 3 deletions LingmoStyle/ToolButton.qml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ T.ToolButton {

icon.width: 20
icon.height: 20
icon.color: Color.transparent(Universal.foreground, enabled ? 1.0 : 0.2)
icon.color: Color.transparent(control.textColor, enabled ? 1.0 : 0.2)

property bool useSystemFocusVisuals: true

Expand All @@ -86,8 +86,8 @@ T.ToolButton {
}

background: LingmoControlBackground {
implicitWidth: 68
implicitHeight: 48
implicitWidth: 30
implicitHeight: 30
radius: LingmoUnits.smallRadius
color: {
if (!enabled) {
Expand Down
77 changes: 53 additions & 24 deletions example/src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,43 +1,72 @@
#include <qlogging.h>
#include <qqmlcontext.h>
#include <qtenvironmentvariables.h>
#include <QApplication>
#include <QMessageBox>
#include <QObject>
#include <QQmlApplicationEngine>
#include <QQmlEngine>
#include <qlogging.h>
#include <QQuickWindow>
#include <qqmlcontext.h>
#include <qtenvironmentvariables.h>

class AboutQtController : public QObject {
Q_OBJECT
public:
AboutQtController(QObject* parent = nullptr) : QObject{parent} {}
signals:
void showAboutQt();
public slots:
void showAboutQtDialog() { QMessageBox::aboutQt(nullptr, "About Qt"); }
Q_OBJECT
public:
AboutQtController(QObject* parent = nullptr)
: QObject { parent }
{
}
signals:
void showAboutQt();
public slots:
void showAboutQtDialog() { QMessageBox::aboutQt(nullptr, "About Qt"); }
};

int main(int argc, char* argv[]) {
qDebug() << "LINGMOUI_TEMP_IMPORT_PATH: " << LINGMOUI_TEMP_IMPORT_PATH;
QString path =
QString(LINGMOUI_TEMP_IMPORT_PATH) + ":" + qgetenv("QML_IMPORT_PATH");
int main(int argc, char* argv[])
{
qDebug() << "LINGMOUI_TEMP_IMPORT_PATH: " << LINGMOUI_TEMP_IMPORT_PATH;

QApplication app(argc, argv);

QQmlApplicationEngine engine;

QApplication app(argc, argv);
engine.addImportPath(LINGMOUI_TEMP_IMPORT_PATH);

QQmlApplicationEngine engine;
// 创建 AboutQtController 对象
AboutQtController aboutQtController(&app);

engine.addImportPath(path);
// 将 aboutQtController 注册到 QML 上下文中
engine.rootContext()->setContextProperty("aboutQtController",
&aboutQtController);

// 创建 AboutQtController 对象
AboutQtController aboutQtController(&app);
engine.load(QUrl(QStringLiteral("qrc:/qml/main.qml")));

// 将 aboutQtController 注册到 QML 上下文中
engine.rootContext()->setContextProperty("aboutQtController",
&aboutQtController);
QString graphicsApiUsed = "";
switch(QQuickWindow::graphicsApi()) {
case QSGRendererInterface::Unknown:
graphicsApiUsed = "Unknown";
break;
case QSGRendererInterface::Software:
graphicsApiUsed = "Software Rendering";
break;
case QSGRendererInterface::OpenGL:
graphicsApiUsed = "OpenGL Rendering";
break;
case QSGRendererInterface::Vulkan:
graphicsApiUsed = "Vulkan Rendering";
break;
case QSGRendererInterface::Direct3D11:
graphicsApiUsed = "Direct3D11 Rendering";
break;
case QSGRendererInterface::Direct3D12:
graphicsApiUsed = "Direct3D11 Rendering";
break;
default:
graphicsApiUsed = "Unknown";
}

engine.load(QUrl(QStringLiteral("qrc:/qml/main.qml")));
qDebug() << "Using graphical API: " << graphicsApiUsed;

return app.exec();
return app.exec();
}

#include "main.moc"
23 changes: 15 additions & 8 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ qt_standard_project_setup()
# Create Qt6 library target
qt_add_library(${TARGET} SHARED)


target_include_directories(${TARGET} PRIVATE desktop)

target_link_libraries(${TARGET}
PUBLIC
Qt6::Core
Expand All @@ -32,7 +29,7 @@ set(qml_files "")
set(resource_files "")

#遍历所有Cpp文件
file(GLOB_RECURSE CPP_FILES *.cpp *.h)
file(GLOB CPP_FILES *.cpp *.h)
foreach (filepath ${CPP_FILES})
string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/" "" filename ${filepath})
list(APPEND sources_files ${filename})
Expand All @@ -58,10 +55,18 @@ foreach (filepath ${QML_PATHS})
endforeach (filepath)

#遍历所有资源文件
file(GLOB_RECURSE RES_PATHS *.png *.jpg *.svg *.ico *.ttf *.webp *.js *.qm)
foreach (filepath ${RES_PATHS})
string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/" "" filename ${filepath})
list(APPEND resource_files ${filename})
set(RES_SUFFIX "")
set(RES_PATHS "")
list(APPEND RES_SUFFIX *.png *.jpg *.svg *.ico *.ttf *.webp *.js *.qm *.qsb)
list(APPEND RES_PATHS Controls Font Image)
foreach (respath ${RES_PATHS})
foreach (filesuffix ${RES_SUFFIX})
file(GLOB_RECURSE RES_FOUND ${respath}/${filesuffix})
foreach (filepath ${RES_FOUND})
string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/" "" filename ${filepath})
list(APPEND resource_files ${filename})
endforeach()
endforeach ()
endforeach (filepath)

# Set Qt6 QMl Plugins
Expand All @@ -80,6 +85,8 @@ qt_add_qml_module(${TARGET}
set_target_properties(${TARGET}
PROPERTIES VERSION ${MODULE_VERSION} SOVERSION ${MODULE_VERSION_MAJOR})

add_subdirectory(GraphicalEffects)

install(DIRECTORY ${CMAKE_BINARY_DIR}/temp/${PROJECT_NAME} DESTINATION ${INSTALL_QMLDIR})
generate_export_header(${TARGET} BASE_NAME ${TARGET})

Expand Down
2 changes: 1 addition & 1 deletion src/Controls/LingmoAcrylic.qml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import QtQuick
import Qt5Compat.GraphicalEffects
import LingmoUI.GraphicalEffects
import LingmoUI

Item {
Expand Down
2 changes: 1 addition & 1 deletion src/Controls/LingmoClip.qml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import QtQuick
import QtQuick.Controls
import Qt5Compat.GraphicalEffects
import LingmoUI.GraphicalEffects
import LingmoUI


Expand Down
2 changes: 2 additions & 0 deletions src/Controls/LingmoWindow.qml
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ Window {
}
}
}
// Image in Window Background
// Can enable Blur effect here
Component {
id: com_background
Item {
Expand Down
Loading

0 comments on commit f4f67b8

Please sign in to comment.