main
zhuzihcu 2023-04-27 17:29:39 +08:00
parent afeb6daea5
commit a70ddf7087
22 changed files with 280 additions and 56 deletions

View File

@ -36,7 +36,7 @@ FluExpander{
topMargin: 5 topMargin: 5
} }
onClicked:{ onClicked:{
FluApp.clipText(content.text) FluTools.clipText(content.text)
showSuccess("复制成功") showSuccess("复制成功")
} }
} }

View File

@ -55,7 +55,7 @@ FluContentPage {
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter
onClicked: { onClicked: {
var text ="FluentIcons."+modelData.name; var text ="FluentIcons."+modelData.name;
FluApp.clipText(text) FluTools.clipText(text)
showSuccess("您复制了 "+text) showSuccess("您复制了 "+text)
} }
} }

View File

@ -7,6 +7,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
# #
add_definitions(-DVERSION=1,2,9,0) add_definitions(-DVERSION=1,2,9,0)
#
if(CMAKE_BUILD_TYPE STREQUAL "Debug") if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin/debug) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin/debug)
else() else()
@ -15,29 +16,34 @@ endif()
find_package(Qt6 REQUIRED COMPONENTS Core Quick Qml) find_package(Qt6 REQUIRED COMPONENTS Core Quick Qml)
#Cpp
file(GLOB_RECURSE CPP_FILES *.cpp *.h) file(GLOB_RECURSE CPP_FILES *.cpp *.h)
foreach(filepath ${CPP_FILES}) foreach(filepath ${CPP_FILES})
string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/" "" filename ${filepath}) string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/" "" filename ${filepath})
list(APPEND sources_files ${filename}) list(APPEND sources_files ${filename})
endforeach(filepath) endforeach(filepath)
#qml
file(GLOB_RECURSE QML_PATHS *.qml) file(GLOB_RECURSE QML_PATHS *.qml)
foreach(filepath ${QML_PATHS}) foreach(filepath ${QML_PATHS})
string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/" "" filename ${filepath}) string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/" "" filename ${filepath})
list(APPEND qml_files ${filename}) list(APPEND qml_files ${filename})
endforeach(filepath) endforeach(filepath)
#
file(GLOB_RECURSE RES_PATHS *.png *.jpg *.svg *.ico *.ttf *.webp) file(GLOB_RECURSE RES_PATHS *.png *.jpg *.svg *.ico *.ttf *.webp)
foreach(filepath ${RES_PATHS}) foreach(filepath ${RES_PATHS})
string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/" "" filename ${filepath}) string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/" "" filename ${filepath})
list(APPEND resource_files ${filename}) list(APPEND resource_files ${filename})
endforeach(filepath) endforeach(filepath)
#
foreach(filepath IN LISTS qml_files resource_files) foreach(filepath IN LISTS qml_files resource_files)
string(REPLACE "imports/FluentUI/" "" filename ${filepath}) string(REPLACE "imports/FluentUI/" "" filename ${filepath})
set_source_files_properties(${filepath} PROPERTIES QT_RESOURCE_ALIAS ${filename}) set_source_files_properties(${filepath} PROPERTIES QT_RESOURCE_ALIAS ${filename})
endforeach() endforeach()
#qml
qt_add_qml_module(fluentui qt_add_qml_module(fluentui
OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/FluentUI OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/FluentUI
VERSION 1.0 VERSION 1.0
@ -47,17 +53,20 @@ qt_add_qml_module(fluentui
RESOURCES ${resource_files} RESOURCES ${resource_files}
) )
#
set_target_properties(fluentui PROPERTIES set_target_properties(fluentui PROPERTIES
WIN32_EXECUTABLE TRUE WIN32_EXECUTABLE TRUE
MACOSX_BUNDLE TRUE MACOSX_BUNDLE TRUE
) )
#
target_link_libraries(fluentui PUBLIC target_link_libraries(fluentui PUBLIC
Qt::Core Qt::Core
Qt::Quick Qt::Quick
Qt::Qml Qt::Qml
) )
# win32 mingw
if(WIN32) if(WIN32)
target_link_libraries(fluentui PRIVATE dwmapi user32) target_link_libraries(fluentui PRIVATE dwmapi user32)
endif() endif()

View File

@ -8,9 +8,7 @@
#include <QUuid> #include <QUuid>
#include <QFontDatabase> #include <QFontDatabase>
#include <QClipboard> #include <QClipboard>
#include "FluTheme.h"
#include "Def.h" #include "Def.h"
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
#pragma comment(lib, "Dwmapi.lib") #pragma comment(lib, "Dwmapi.lib")
#pragma comment(lib, "User32.lib") #pragma comment(lib, "User32.lib")
@ -26,18 +24,12 @@ static bool isCompositionEnabled()
#endif #endif
FluApp* FluApp::fluApp = nullptr; FluApp* FluApp::fluApp = nullptr;
FluTheme* FluApp::fluTheme = nullptr;
FluColors* FluApp::flutColors = nullptr;
void FluApp::setFluApp(FluApp* val){ FluTheme* FluApp::fluTheme = nullptr;
FluApp::fluApp = val;
} FluColors* FluApp::fluColors = nullptr;
void FluApp::setFluTheme(FluTheme* val){
FluApp::fluTheme = val; FluTools* FluApp::fluTools = nullptr;
}
void FluApp::setFluColors(FluColors* val){
FluApp::flutColors = val;
}
FluApp::FluApp(QObject *parent) FluApp::FluApp(QObject *parent)
: QObject{parent} : QObject{parent}
@ -45,6 +37,29 @@ FluApp::FluApp(QObject *parent)
QFontDatabase::addApplicationFont(":/FluentUI/Font/Segoe_Fluent_Icons.ttf"); QFontDatabase::addApplicationFont(":/FluentUI/Font/Segoe_Fluent_Icons.ttf");
} }
FluApp::~FluApp(){
if (nativeEvent != Q_NULLPTR) {
delete nativeEvent;
nativeEvent = Q_NULLPTR;
}
}
void FluApp::setFluApp(FluApp* val){
FluApp::fluApp = val;
}
void FluApp::setFluTheme(FluTheme* val){
FluApp::fluTheme = val;
}
void FluApp::setFluColors(FluColors* val){
FluApp::fluColors = val;
}
void FluApp::setFluTools(FluTools* val){
FluApp::fluTools = val;
}
void FluApp::init(QQuickWindow *window){ void FluApp::init(QQuickWindow *window){
this->appWindow = window; this->appWindow = window;
QQmlEngine *engine = qmlEngine(appWindow); QQmlEngine *engine = qmlEngine(appWindow);
@ -133,14 +148,6 @@ QJsonArray FluApp::awesomelist(const QString& keyword)
return arr; return arr;
} }
void FluApp::clipText(const QString& text){
QGuiApplication::clipboard()->setText(text);
}
QString FluApp::uuid(){
return QUuid::createUuid().toString();
}
void FluApp::closeApp(){ void FluApp::closeApp(){
qApp->exit(0); qApp->exit(0);
} }

View File

@ -9,44 +9,125 @@
#include <QJsonObject> #include <QJsonObject>
#include <QQmlEngine> #include <QQmlEngine>
#include "FluTheme.h" #include "FluTheme.h"
#include "FluTools.h"
#include "FluColors.h" #include "FluColors.h"
#include "NativeEventFilter.h" #include "NativeEventFilter.h"
#include "FluRegister.h" #include "FluRegister.h"
#include "stdafx.h" #include "stdafx.h"
/**
* @brief The FluApp class
*/
class FluApp : public QObject class FluApp : public QObject
{ {
Q_OBJECT Q_OBJECT
/**
* @brief initialRoute
*/
Q_PROPERTY_AUTO(QString,initialRoute); Q_PROPERTY_AUTO(QString,initialRoute);
/**
* @brief routes
*/
Q_PROPERTY_AUTO(QJsonObject,routes); Q_PROPERTY_AUTO(QJsonObject,routes);
QML_NAMED_ELEMENT(FluApp) QML_NAMED_ELEMENT(FluApp)
QML_SINGLETON QML_SINGLETON
public: public:
static FluApp *getInstance();
explicit FluApp(QObject *parent = nullptr); explicit FluApp(QObject *parent = nullptr);
~FluApp(){ ~FluApp();
if (nativeEvent != Q_NULLPTR) {
delete nativeEvent; /**
nativeEvent = Q_NULLPTR; * @brief run
} */
}
Q_INVOKABLE void run(); Q_INVOKABLE void run();
/**
* @brief navigate
* @param route
* @param argument
* @param fluRegister
*/
Q_INVOKABLE void navigate(const QString& route,const QJsonObject& argument = {},FluRegister* fluRegister = nullptr); Q_INVOKABLE void navigate(const QString& route,const QJsonObject& argument = {},FluRegister* fluRegister = nullptr);
/**
* @brief init
* @param window
*/
Q_INVOKABLE void init(QQuickWindow *window); Q_INVOKABLE void init(QQuickWindow *window);
/**
* @brief awesomelist
* @param keyword
* @return
*/
Q_INVOKABLE QJsonArray awesomelist(const QString& keyword = ""); Q_INVOKABLE QJsonArray awesomelist(const QString& keyword = "");
Q_INVOKABLE void clipText(const QString& text);
Q_INVOKABLE QString uuid(); /**
* @brief closeApp
*/
Q_INVOKABLE void closeApp(); Q_INVOKABLE void closeApp();
/**
* @brief setFluApp FluSingleton.qmlQMLFluApp
* @param val
*/
Q_INVOKABLE void setFluApp(FluApp* val); Q_INVOKABLE void setFluApp(FluApp* val);
/**
* @brief setFluTheme FluSingleton.qmlQMLFluTheme
* @param val
*/
Q_INVOKABLE void setFluTheme(FluTheme* val); Q_INVOKABLE void setFluTheme(FluTheme* val);
/**
* @brief setFluColors FluSingleton.qmlQMLFluColors
* @param val
*/
Q_INVOKABLE void setFluColors(FluColors* val); Q_INVOKABLE void setFluColors(FluColors* val);
/**
* @brief setFluColors FluSingleton.qmlQMLFluTools
* @param val
*/
Q_INVOKABLE void setFluTools(FluTools* val);
public: public:
/**
* @brief wnds
*/
QMap<quint64, QQuickWindow*> wnds; QMap<quint64, QQuickWindow*> wnds;
/**
* @brief fluApp
*/
static FluApp* fluApp; static FluApp* fluApp;
/**
* @brief fluTheme
*/
static FluTheme* fluTheme; static FluTheme* fluTheme;
static FluColors* flutColors;
/**
* @brief fluColors
*/
static FluColors* fluColors;
/**
* @brief fluTools
*/
static FluTools* fluTools;
private: private:
/**
* @brief nativeEvent
*/
NativeEventFilter *nativeEvent = Q_NULLPTR; NativeEventFilter *nativeEvent = Q_NULLPTR;
/**
* @brief appWindow
*/
QWindow *appWindow; QWindow *appWindow;
}; };

View File

@ -4,9 +4,11 @@
#include <QObject> #include <QObject>
#include "stdafx.h" #include "stdafx.h"
/**
* @brief The FluColorSet class
*/
class FluColorSet : public QObject class FluColorSet : public QObject
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY_AUTO(QString,darkest) Q_PROPERTY_AUTO(QString,darkest)
Q_PROPERTY_AUTO(QString,darker) Q_PROPERTY_AUTO(QString,darker)

View File

@ -6,6 +6,9 @@
#include "FluColorSet.h" #include "FluColorSet.h"
#include "stdafx.h" #include "stdafx.h"
/**
* @brief The FluColors class
*/
class FluColors : public QObject class FluColors : public QObject
{ {
Q_OBJECT Q_OBJECT
@ -33,7 +36,6 @@ class FluColors : public QObject
Q_PROPERTY_AUTO(QString,Grey200); Q_PROPERTY_AUTO(QString,Grey200);
Q_PROPERTY_AUTO(QString,Grey210); Q_PROPERTY_AUTO(QString,Grey210);
Q_PROPERTY_AUTO(QString,Grey220); Q_PROPERTY_AUTO(QString,Grey220);
Q_PROPERTY_AUTO(FluColorSet*,Yellow); Q_PROPERTY_AUTO(FluColorSet*,Yellow);
Q_PROPERTY_AUTO(FluColorSet*,Orange); Q_PROPERTY_AUTO(FluColorSet*,Orange);
Q_PROPERTY_AUTO(FluColorSet*,Red); Q_PROPERTY_AUTO(FluColorSet*,Red);

View File

@ -6,6 +6,9 @@
#include <QJsonObject> #include <QJsonObject>
#include "stdafx.h" #include "stdafx.h"
/**
* @brief The FluRegister class
*/
class FluRegister : public QObject class FluRegister : public QObject
{ {
Q_OBJECT Q_OBJECT
@ -15,8 +18,22 @@ class FluRegister : public QObject
public: public:
explicit FluRegister(QObject *parent = nullptr); explicit FluRegister(QObject *parent = nullptr);
/**
* @brief launch
* @param argument
*/
Q_INVOKABLE void launch(const QJsonObject& argument = {}); Q_INVOKABLE void launch(const QJsonObject& argument = {});
/**
* @brief onResult
* @param data
*/
Q_INVOKABLE void onResult(const QJsonObject& data = {}); Q_INVOKABLE void onResult(const QJsonObject& data = {});
/**
* @brief result
* @param data
*/
Q_SIGNAL void result(const QJsonObject& data); Q_SIGNAL void result(const QJsonObject& data);
}; };

View File

@ -11,7 +11,7 @@ FluTheme::FluTheme(QObject *parent)
connect(this,&FluTheme::darkModeChanged,this,[=]{ connect(this,&FluTheme::darkModeChanged,this,[=]{
Q_EMIT darkChanged(); Q_EMIT darkChanged();
}); });
primaryColor(FluApp::flutColors->Blue()); primaryColor(FluApp::fluColors->Blue());
textSize(13); textSize(13);
nativeText(false); nativeText(false);
frameless(true); frameless(true);

View File

@ -6,15 +6,42 @@
#include "FluColorSet.h" #include "FluColorSet.h"
#include "stdafx.h" #include "stdafx.h"
/**
* @brief The FluTheme class
*/
class FluTheme : public QObject class FluTheme : public QObject
{ {
Q_OBJECT Q_OBJECT
/**
* @brief dark darkMode
*/
Q_PROPERTY(bool dark READ dark NOTIFY darkChanged) Q_PROPERTY(bool dark READ dark NOTIFY darkChanged)
/**
* @brief primaryColor
*/
Q_PROPERTY_AUTO(FluColorSet*,primaryColor) Q_PROPERTY_AUTO(FluColorSet*,primaryColor)
/**
* @brief frameless windows
*/
Q_PROPERTY_AUTO(bool,frameless); Q_PROPERTY_AUTO(bool,frameless);
/**
* @brief darkMode System=0Light=1Dark=2
*/
Q_PROPERTY_AUTO(int,darkMode); Q_PROPERTY_AUTO(int,darkMode);
/**
* @brief nativeText
*/
Q_PROPERTY_AUTO(bool,nativeText); Q_PROPERTY_AUTO(bool,nativeText);
/**
* @brief textSize
*/
Q_PROPERTY_AUTO(int,textSize); Q_PROPERTY_AUTO(int,textSize);
QML_NAMED_ELEMENT(FluTheme) QML_NAMED_ELEMENT(FluTheme)
QML_SINGLETON QML_SINGLETON
public: public:

18
src/FluTools.cpp Normal file
View File

@ -0,0 +1,18 @@
#include "FluTools.h"
#include <QGuiApplication>
#include <QClipboard>
#include <QUuid>
FluTools::FluTools(QObject *parent)
: QObject{parent}
{
}
void FluTools::clipText(const QString& text){
QGuiApplication::clipboard()->setText(text);
}
QString FluTools::uuid(){
return QUuid::createUuid().toString();
}

34
src/FluTools.h Normal file
View File

@ -0,0 +1,34 @@
#ifndef FLUTOOLS_H
#define FLUTOOLS_H
#include <QObject>
#include <QtQml/qqml.h>
/**
* @brief The FluTools class
*/
class FluTools : public QObject
{
Q_OBJECT
QML_NAMED_ELEMENT(FluTools)
QML_SINGLETON
public:
explicit FluTools(QObject *parent = nullptr);
/**
* @brief clipText
* @param text
*/
Q_INVOKABLE void clipText(const QString& text);
/**
* @brief uuid uuid
* @return
*/
Q_INVOKABLE QString uuid();
};
#endif // FLUTOOLS_H

View File

@ -4,6 +4,9 @@
#include <QObject> #include <QObject>
#include <QAbstractNativeEventFilter> #include <QAbstractNativeEventFilter>
/**
* @brief The NativeEventFilter class
*/
class NativeEventFilter : public QAbstractNativeEventFilter class NativeEventFilter : public QAbstractNativeEventFilter
{ {

View File

@ -28,7 +28,6 @@ void WindowHelper::initWindow(QQuickWindow* window){
} }
void WindowHelper::firstUpdate(){ void WindowHelper::firstUpdate(){
if(isFisrt){
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
if(FluApp::fluTheme->frameless()){ if(FluApp::fluTheme->frameless()){
HWND wnd = (HWND)window->winId(); HWND wnd = (HWND)window->winId();
@ -40,9 +39,6 @@ void WindowHelper::firstUpdate(){
window->setFlag(Qt::FramelessWindowHint,false); window->setFlag(Qt::FramelessWindowHint,false);
} }
#endif #endif
isFisrt = false;
}
} }
QVariant WindowHelper::createRegister(QQuickWindow* window,const QString& path){ QVariant WindowHelper::createRegister(QQuickWindow* window,const QString& path){

View File

@ -8,6 +8,9 @@
#include <QWindow> #include <QWindow>
#include <QJsonObject> #include <QJsonObject>
/**
* @brief The WindowHelper class
*/
class WindowHelper : public QObject class WindowHelper : public QObject
{ {
Q_OBJECT Q_OBJECT
@ -15,14 +18,32 @@ class WindowHelper : public QObject
public: public:
explicit WindowHelper(QObject *parent = nullptr); explicit WindowHelper(QObject *parent = nullptr);
/**
* @brief initWindow FluWindow
* @param window
*/
Q_INVOKABLE void initWindow(QQuickWindow* window); Q_INVOKABLE void initWindow(QQuickWindow* window);
/**
* @brief destoryWindow QMLWindow close
*/
Q_INVOKABLE void destoryWindow(); Q_INVOKABLE void destoryWindow();
/**
* @brief createRegister FluRegsiterFluWindowregisterForWindowResult
* @param window
* @param path
* @return
*/
Q_INVOKABLE QVariant createRegister(QQuickWindow* window,const QString& path); Q_INVOKABLE QVariant createRegister(QQuickWindow* window,const QString& path);
/**
* @brief firstUpdate
*/
Q_INVOKABLE void firstUpdate(); Q_INVOKABLE void firstUpdate();
private: private:
QQuickWindow* window; QQuickWindow* window;
bool isFisrt=true;
}; };
#endif // WINDOWHELPER_H #endif // WINDOWHELPER_H

View File

@ -3,7 +3,7 @@ import QtQuick.Controls
import FluentUI import FluentUI
QtObject { QtObject {
readonly property string key : FluApp.uuid() readonly property string key : FluTools.uuid()
readonly property int flag : 0 readonly property int flag : 0
property string title property string title
property int order : 0 property int order : 0

View File

@ -3,7 +3,7 @@ import QtQuick.Controls
import FluentUI import FluentUI
QtObject { QtObject {
readonly property string key : FluApp.uuid() readonly property string key : FluTools.uuid()
property var parent property var parent
property int idx property int idx
} }

View File

@ -3,7 +3,7 @@ import QtQuick.Controls
import FluentUI import FluentUI
FluObject { FluObject {
readonly property string key : FluApp.uuid() readonly property string key : FluTools.uuid()
property string title property string title
property var icon property var icon
property Component cusIcon property Component cusIcon

View File

@ -3,7 +3,7 @@ import QtQuick.Controls
import FluentUI import FluentUI
QtObject { QtObject {
readonly property string key : FluApp.uuid() readonly property string key : FluTools.uuid()
property string title property string title
property var parent property var parent
property int idx property int idx

View File

@ -3,7 +3,7 @@ import QtQuick.Controls
import FluentUI import FluentUI
QtObject { QtObject {
readonly property string key : FluApp.uuid() readonly property string key : FluTools.uuid()
property var parent property var parent
property int idx property int idx
} }

View File

@ -10,6 +10,7 @@ QtObject {
FluApp.setFluApp(FluApp) FluApp.setFluApp(FluApp)
FluApp.setFluColors(FluColors) FluApp.setFluColors(FluColors)
FluApp.setFluTheme(FluTheme) FluApp.setFluTheme(FluTheme)
FluApp.setFluTools(FluTools)
} }
} }

View File

@ -28,6 +28,11 @@ ApplicationWindow {
} }
signal initArgument(var argument) signal initArgument(var argument)
QtObject{
id:d
property bool firstFlag: true
}
id:window id:window
background: Rectangle{ background: Rectangle{
color: { color: {
@ -51,8 +56,9 @@ ApplicationWindow {
} }
onActiveChanged: { onActiveChanged: {
if(active){ if(d.firstFlag){
helper.firstUpdate() helper.firstUpdate()
d.firstFlag = false
} }
} }