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
}
onClicked:{
FluApp.clipText(content.text)
FluTools.clipText(content.text)
showSuccess("复制成功")
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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