diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..c0a13474 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "framelesshelper"] + path = framelesshelper + url = https://github.com/zhuzichu520/framelesshelper.git \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index a4d0ecc3..3a9d2221 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,3 +4,4 @@ project(FluentUI VERSION 0.1 LANGUAGES CXX) add_subdirectory(src) add_subdirectory(example) +add_subdirectory(framelesshelper) diff --git a/example/src/main.cpp b/example/src/main.cpp index 40dce665..03da1616 100644 --- a/example/src/main.cpp +++ b/example/src/main.cpp @@ -12,17 +12,13 @@ int main(int argc, char *argv[]) { //将样式设置为Basic,不然会导致组件显示异常 - FluentUI::init(); - qputenv("QT_QUICK_CONTROLS_STYLE","Basic"); - //6.4及以下监听系统深色模式变化 -#ifdef Q_OS_WIN - qputenv("QT_QPA_PLATFORM","windows:darkmode=2"); -#endif + FluentUI::preInit(); QGuiApplication::setOrganizationName("ZhuZiChu"); QGuiApplication::setOrganizationDomain("https://zhuzichu520.github.io"); QGuiApplication::setApplicationName("FluentUI"); // QQuickWindow::setGraphicsApi(QSGRendererInterface::Software); QGuiApplication app(argc, argv); + FluentUI::postInit(); AppInfo* appInfo = new AppInfo(); IPC ipc(0); QString activeWindowEvent = "activeWindow"; @@ -47,7 +43,7 @@ int main(int argc, char *argv[]) }); context->setContextProperty("appInfo",appInfo); const QUrl url(QStringLiteral("qrc:/example/qml/App.qml")); -// const QUrl url(QStringLiteral("qrc:/example/qml/TestWindow.qml")); + // const QUrl url(QStringLiteral("qrc:/example/qml/TestWindow.qml")); QObject::connect(&engine, &QQmlApplicationEngine::objectCreated, &app, [url](QObject *obj, const QUrl &objUrl) { if (!obj && url == objUrl) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a7f8efe8..674787db 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -66,6 +66,8 @@ target_link_libraries(fluentuiplugin PUBLIC Qt::Core Qt::Quick Qt::Qml + FramelessHelper::Core + FramelessHelper::Quick ) #链接库 win32库 不然mingw会编译错误 diff --git a/src/FluApp.cpp b/src/FluApp.cpp index 0a129f41..c585af1d 100644 --- a/src/FluApp.cpp +++ b/src/FluApp.cpp @@ -78,7 +78,6 @@ void FluApp::navigate(const QString& route,const QJsonObject& argument,FluRegist fluRegister->to(view); } view->setColor(QColor(Qt::transparent)); - view->show(); } QJsonArray FluApp::awesomelist(const QString& keyword) diff --git a/src/FluentUI.cpp b/src/FluentUI.cpp index cf7bfc71..ef6e2023 100644 --- a/src/FluentUI.cpp +++ b/src/FluentUI.cpp @@ -1,5 +1,21 @@ #include "FluentUI.h" +#include +#include -void FluentUI::init(){ +FRAMELESSHELPER_USE_NAMESPACE; + +void FluentUI::preInit(){ qDebug()<<"FluentUI init"; + FramelessHelper::Quick::initialize(); + qputenv("QT_QUICK_CONTROLS_STYLE","Basic"); + //6.4及以下监听系统深色模式变化 +#ifdef Q_OS_WIN + qputenv("QT_QPA_PLATFORM","windows:darkmode=2"); +#endif +} + +void FluentUI::postInit(){ + FramelessHelper::Core::setApplicationOSThemeAware(); + FramelessConfig::instance()->set(Global::Option::EnableBlurBehindWindow); + FramelessConfig::instance()->set(Global::Option::DisableLazyInitializationForMicaMaterial); } diff --git a/src/FluentUI.h b/src/FluentUI.h index cba1e73f..14d337a4 100644 --- a/src/FluentUI.h +++ b/src/FluentUI.h @@ -8,8 +8,8 @@ class Q_DECL_EXPORT FluentUI { public: - static void init(); - + static void preInit(); + static void postInit(); }; #endif // FLUENTUI_H diff --git a/src/imports/FluentUI/Controls/FluWindow.qml b/src/imports/FluentUI/Controls/FluWindow.qml index fb7f18a6..0d358d66 100644 --- a/src/imports/FluentUI/Controls/FluWindow.qml +++ b/src/imports/FluentUI/Controls/FluWindow.qml @@ -3,8 +3,9 @@ import QtQuick.Window import QtQuick.Controls import QtQuick.Layouts import FluentUI +import org.wangwenx190.FramelessHelper -Window { +FramelessWindow { enum LaunchMode { Standard, SingleTask, @@ -32,7 +33,7 @@ Window { } signal initArgument(var argument) id:window - color:Qt.rgba(0,0,0,0) + color:"transparent" onClosing:(event)=>closeFunc(event) Component.onCompleted: { helper.initWindow(window) @@ -47,9 +48,26 @@ Window { } } } + StandardTitleBar { + id: title_bar + z:999 + anchors { + top: parent.top + topMargin: window.visibility === Window.Windowed ? 1 : 0 + left: parent.left + right: parent.right + } + // windowIcon: "qrc:///images/microsoft.svg" + windowIconVisible: false + } Item{ id:container - anchors.fill: parent + anchors{ + top: title_bar.bottom + left: parent.left + right: parent.right + bottom: parent.bottom + } clip: true } FluInfoBar{ @@ -59,17 +77,27 @@ Window { WindowHelper{ id:helper } + FramelessHelper.onReady: { + FramelessHelper.titleBarItem = title_bar + FramelessHelper.moveWindowToDesktopCenter() + if (Qt.platform.os !== "macos") { + FramelessHelper.setSystemButton(title_bar.minimizeButton, FramelessHelperConstants.Minimize); + FramelessHelper.setSystemButton(title_bar.maximizeButton, FramelessHelperConstants.Maximize); + FramelessHelper.setSystemButton(title_bar.closeButton, FramelessHelperConstants.Close); + } + window.visible = true + } function showSuccess(text,duration,moremsg){ - infoBar.showSuccess(text,duration,moremsg); + infoBar.showSuccess(text,duration,moremsg) } function showInfo(text,duration,moremsg){ - infoBar.showInfo(text,duration,moremsg); + infoBar.showInfo(text,duration,moremsg) } function showWarning(text,duration,moremsg){ - infoBar.showWarning(text,duration,moremsg); + infoBar.showWarning(text,duration,moremsg) } function showError(text,duration,moremsg){ - infoBar.showError(text,duration,moremsg); + infoBar.showError(text,duration,moremsg) } function registerForWindowResult(path){ return helper.createRegister(window,path)