This commit is contained in:
zhuzihcu
2023-03-03 18:19:48 +08:00
parent 5ee8729353
commit 891270e6d1
32 changed files with 462 additions and 221 deletions

View File

@ -22,8 +22,7 @@ FluApp *FluApp::getInstance()
FluApp::FluApp(QObject *parent)
: QObject{parent}
{
isDark(true);
isFps(true);
isDark(false);
}
void FluApp::setAppWindow(QWindow *window){
@ -39,7 +38,7 @@ void FluApp::navigate(const QString& route){
qErrnoWarning("没有找到当前路由");
return;
}
bool isAppWindow = route==initialRoute();
bool isAppWindow = route == initialRoute();
FramelessView *view = new FramelessView();
view->setColor(QColor(Qt::transparent));
QObject::connect(view, &QQuickView::statusChanged, view, [&](QQuickView::Status status) {

View File

@ -4,7 +4,9 @@
#include <QObject>
#include <QWindow>
#include <QJsonArray>
#include <QQmlContext>
#include <QJsonObject>
#include <QQmlEngine>
#include "FramelessView.h"
#include "stdafx.h"
@ -13,7 +15,6 @@ class FluApp : public QObject
Q_OBJECT
Q_PROPERTY_AUTO(QString,initialRoute);
Q_PROPERTY_AUTO(bool,isDark);
Q_PROPERTY_AUTO(bool,isFps);
Q_PROPERTY_AUTO(QJsonObject,routes);
public:
@ -36,10 +37,20 @@ public:
Q_INVOKABLE void clipText(const QString& text);
Q_INVOKABLE void setContextProperty(const QString &name, QObject *data){
if(engine){
engine->rootContext()->setContextProperty(name,data);
}
}
void setEngine(QQmlEngine *engine){
this->engine = engine;
}
private:
static FluApp* m_instance;
QQmlEngine *engine;
QWindow *appWindow;
};

View File

@ -32,10 +32,9 @@ void Fluent::registerTypes(const char *uri){
qmlRegisterType(QUrl("qrc:/com.zhuzichu/controls/FluMenu.qml"),uri,major,minor,"FluMenu");
qmlRegisterType(QUrl("qrc:/com.zhuzichu/controls/FluMenuItem.qml"),uri,major,minor,"FluMenuItem");
qmlRegisterType(QUrl("qrc:/com.zhuzichu/controls/FluScrollBar.qml"),uri,major,minor,"FluScrollBar");
qmlRegisterType(QUrl("qrc:/com.zhuzichu/controls/FluTextButton.qml"),uri,major,minor,"FluTextButton");
qmlRegisterType(QUrl("qrc:/com.zhuzichu/controls/FluMultiLineTextBox.qml"),uri,major,minor,"FluMultiLineTextBox");
qmlRegisterType(QUrl("qrc:/com.zhuzichu/controls/FluDropShadow.qml"),uri,major,minor,"FluDropShadow");
qmlRegisterType(QUrl("qrc:/com.zhuzichu/controls/FluTooltip.qml"),uri,major,minor,"FluTooltip");
qmlRegisterType(QUrl("qrc:/com.zhuzichu/controls/FluDivider.qml"),uri,major,minor,"FluDivider");
qmlRegisterType(QUrl("qrc:/com.zhuzichu/controls/FluIcon.qml"),uri,major,minor,"FluIcon");
@ -72,5 +71,7 @@ void Fluent::initializeEngine(QQmlEngine *engine, const char *uri)
font.setFamily("Microsoft YaHei");
QGuiApplication::setFont(font);
QFontDatabase::addApplicationFont(":/com.zhuzichu/res/font/fontawesome-webfont.ttf");
engine->rootContext()->setContextProperty("FluApp",FluApp::getInstance());
FluApp* app = FluApp::getInstance();
app->setEngine(engine);
engine->rootContext()->setContextProperty("FluApp",app);
}

View File

@ -2,14 +2,10 @@
#include "Fluent.h"
void FluentUI::create(QQmlEngine *engine)
{
engine->addImportPath("/");
Fluent::getInstance()->initializeEngine(engine,URI_STR);
Fluent::getInstance()->registerTypes(URI_STR);
}
QString FluentUI::version()
{
return Fluent::getInstance()->version();
void FluentUI::registerTypes(const char *uri){
Fluent::getInstance()->registerTypes(uri);
}
void FluentUI::initializeEngine(QQmlEngine *engine, const char *uri){
Fluent::getInstance()->initializeEngine(engine,uri);
}

View File

@ -7,8 +7,8 @@ class FluentUI
{
public:
static void create(QQmlEngine* engine);
static QString version();
static void registerTypes(const char *uri) ;
static void initializeEngine(QQmlEngine *engine, const char *uri);
};
#endif // FLUENTUI_H

View File

@ -5,24 +5,11 @@ TARGET = FluentUI
TARGET = $$qtLibraryTarget($$TARGET)
uri = FluentUI
##########################################
CONFIG += sharedlib # staticlib or sharedlib
#** 多次切换编译构建模式,建议先清理缓存项目右键->清理
#*[staticlib] 构建静态库.a
#需要修改example.pro请打开后按说明操作
#*[sharedlib] 构建动态库 .dll .so .dylib
#会自动安装到Qt qmlplugin目录中
#无需其它配置即可运行demo以及其它项目中使用
#发布目标平台前必须每个平台都要构建一次
##########################################
RESOURCES += \
res.qrc
# Input
HEADERS += \
Def.h \
FluApp.h \
@ -33,7 +20,6 @@ HEADERS += \
qml_plugin.h \
stdafx.h
SOURCES += \
Def.cpp \
FluApp.cpp \
@ -50,7 +36,6 @@ win32 {
FramelessView_unix.cpp
}
DEFINES += VERSION_IN=\\\"1.0.0\\\"
DEFINES += URI_STR=\\\"$$uri\\\"

View File

@ -15,6 +15,9 @@ Rectangle{
property string title: "标题"
property bool showDark: false
property bool showFps: false
property bool resizable: {
if(Window.window == null){
return false
@ -63,12 +66,13 @@ Rectangle{
Layout.alignment: Qt.AlignVCenter
Layout.rightMargin: 12
Layout.topMargin: 5
visible: FluApp.isFps
visible: showFps
}
RowLayout{
Layout.alignment: Qt.AlignVCenter
spacing: 5
visible: showDark
FluText{
text:"夜间模式"
fontStyle: FluText.Body
@ -112,7 +116,6 @@ Rectangle{
icon : FluentIcons.FA_close
Layout.alignment: Qt.AlignVCenter
text:"关闭"
iconSize: 15
onClicked: {
Window.window.close()
}

View File

@ -1,8 +0,0 @@
import QtQuick 2.15
import QtGraphicalEffects 1.15
DropShadow {
radius: 5
samples: 4
color: FluApp.isDark ? "#80FFFFFF" : "#40000000"
}

View File

@ -6,13 +6,14 @@ Popup {
id: popup
default property alias content: container.children
background: FluRectangle {
background: Rectangle {
implicitWidth: 140
implicitHeight: container.height
color:FluApp.isDark ? Qt.rgba(45/255,45/255,45/255,1) : Qt.rgba(237/255,237/255,237/255,1)
radius: [5,5,5,5]
layer.effect: FluDropShadow{}
layer.enabled: true
radius: 5
FluShadow{
radius: 5
}
Column{
spacing: 5
topPadding: 5

View File

@ -8,6 +8,7 @@ Item{
property color color : "#FFFFFF"
property color borderColor:"red"
property int borderWidth: 1
property bool shadow: true
default property alias contentItem: container.children
Rectangle{
@ -18,6 +19,17 @@ Item{
color:root.color
}
FluShadow{
anchors.fill: container
radius: root.radius[0]
visible: {
if(root.radius[0] === root.radius[1] && root.radius[0] === root.radius[2] && root.radius[0] === root.radius[3] && root.shadow){
return true
}
return false
}
}
Canvas {
id: canvas
anchors.fill: parent

View File

@ -0,0 +1,65 @@
import QtQuick 2.15
Item {
id:root
anchors.fill: parent
anchors.margins: -4
property color color: FluApp.isDark ? "#FFFFFF" : "#000000"
property var radius: 4
Rectangle{
width: root.width
height: root.height
anchors.centerIn: parent
color: "#00000000"
opacity: 0.02
border.width: 1
radius: root.radius
border.color: root.color
}
Rectangle{
width: root.width - 2
height: root.height - 2
anchors.centerIn: parent
color: "#00000000"
opacity: 0.04
border.width: 1
radius: root.radius
border.color: root.color
}
Rectangle{
width: root.width - 4
height: root.height - 4
anchors.centerIn: parent
color: "#00000000"
opacity: 0.06
border.width: 1
radius: root.radius
border.color: root.color
}
Rectangle{
width: root.width - 6
height: root.height - 6
anchors.centerIn: parent
color: "#00000000"
opacity: 0.08
border.width: 1
radius: root.radius
border.color: root.color
}
Rectangle{
width: root.width - 8
height: root.height - 8
anchors.centerIn: parent
opacity: 0.1
radius: root.radius
color: "#00000000"
border.width: 1
border.color: root.color
}
}

View File

@ -40,11 +40,12 @@ Item{
id:dot
width: dotSize
height: dotSize
FluShadow{
radius: 15
}
radius: 15
anchors.verticalCenter: parent.verticalCenter
layer.enabled: true
color:FluApp.isDark ? Qt.rgba(69/255,69/255,69/255,1) :Qt.rgba(1,1,1,1)
layer.effect: FluDropShadow {}
Rectangle{
width: dotSize/2
height: dotSize/2

View File

@ -0,0 +1,22 @@
import QtQuick 2.15
import FluentUI 1.0
FluText {
id:root
color: {
if(FluApp.isDark){
return mouse_area.containsMouse?Qt.rgba(73/255,148/255,206/255,1):Qt.rgba(76/255,160/255,224/255,1)
}
return mouse_area.containsMouse?Qt.rgba(24/255,116/255,186/255,1):Qt.rgba(0/255,102/255,180/255,1)
}
signal clicked
MouseArea{
id:mouse_area
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onClicked: {
root.clicked()
}
}
}

View File

@ -18,7 +18,6 @@ ToolTip {
anchors.fill: parent
color: FluApp.isDark ? Qt.rgba(50/255,49/255,48/255,1) : Qt.rgba(1,1,1,1)
radius: 5
layer.enabled: true
layer.effect: FluDropShadow {}
FluShadow{}
}
}

View File

@ -32,25 +32,22 @@ Item {
FluWindowResize{}
Behavior on opacity{
NumberAnimation{
duration: 100
}
}
FluShadow{
anchors.fill: container
}
Rectangle{
id:container
color:root.color
anchors.fill: parent
anchors.margins: borderless
layer.enabled: true
layer.effect: DropShadow {
radius: 5
samples: 5
horizontalOffset: 0
verticalOffset: 0
color: "#40000000"
}
}
Component.onCompleted: {

View File

@ -31,68 +31,50 @@ MouseArea {
return;
}
var rc = Qt.rect(0, 0, 0, 0);
let e = 0;
//top-left
rc = Qt.rect(0, 0, border, border);
if (ptInRect(rc, mouse.x, mouse.y)) {
if (ptInRect(0,0,border,border, mouse.x, mouse.y)) {
e = Qt.TopEdge | Qt.LeftEdge;
window.startSystemResize(e);
return;
}
//top
rc = Qt.rect(border, 0, window.width-border*2, border);
if (ptInRect(rc, mouse.x, mouse.y)) {
if (ptInRect(border,0,window.width-border*2,border, mouse.x, mouse.y)) {
e = Qt.TopEdge;
window.startSystemResize(e);
return;
}
//top-right
rc = Qt.rect(window.width-border, 0, border, border);
if (ptInRect(rc, mouse.x, mouse.y)) {
if (ptInRect(window.width-border,0,border,border, mouse.x, mouse.y)) {
e = Qt.TopEdge | Qt.RightEdge;
window.startSystemResize(e);
return;
}
//right
rc = Qt.rect(window.width-border, border, border, window.height-border*2);
if (ptInRect(rc, mouse.x, mouse.y)) {
if (ptInRect(window.width-border,border,border,window.height-border*2, mouse.x, mouse.y)) {
e = Qt.RightEdge;
window.startSystemResize(e);
return;
}
//bottom-right
rc = Qt.rect(window.width-border, window.height-border, border, border);
if (ptInRect(rc, mouse.x, mouse.y)) {
if (ptInRect(window.width-border,window.height-border,border,border, mouse.x, mouse.y)) {
e = Qt.BottomEdge | Qt.RightEdge;
window.startSystemResize(e);
return;
}
//bottom
rc = Qt.rect(border, window.height-border, window.width-border*2, border);
if (ptInRect(rc, mouse.x, mouse.y)) {
if (ptInRect(border,window.height-border,window.width-border*2,border, mouse.x, mouse.y)) {
e = Qt.BottomEdge;
window.startSystemResize(e);
return;
}
//bottom_left
rc = Qt.rect(0, window.height-border,border, border);
if (ptInRect(rc, mouse.x, mouse.y)) {
if (ptInRect(0,window.height-border,border,border, mouse.x, mouse.y)) {
e = Qt.BottomEdge | Qt.LeftEdge;
window.startSystemResize(e);
return;
}
//left
rc = Qt.rect(0, border,border, window.height-border*2);
if (ptInRect(rc, mouse.x, mouse.y)) {
if (ptInRect(0,border,border , window.height-border*2, mouse.x, mouse.y)) {
e = Qt.LeftEdge;
window.startSystemResize(e);
return;
@ -105,66 +87,46 @@ MouseArea {
cursorShape = Qt.ArrowCursor;
return;
}
var rc = Qt.rect(0, 0, 0, 0);
//top-left
rc = Qt.rect(0, 0, border, border);
if (ptInRect(rc, mouse.x, mouse.y)) {
if (ptInRect(0,0,border,border, mouse.x, mouse.y)) {
cursorShape = Qt.SizeFDiagCursor;
return;
}
//top
rc = Qt.rect(border, 0, window.width-border*2, border);
if (ptInRect(rc, mouse.x, mouse.y)) {
if (ptInRect(border,0,window.width-border*2,border, mouse.x, mouse.y)) {
cursorShape = Qt.SizeVerCursor;
return;
}
//top-right
rc = Qt.rect(window.width-border, 0, border, border);
if (ptInRect(rc, mouse.x, mouse.y)) {
if (ptInRect(window.width-border,0,border,border, mouse.x, mouse.y)) {
cursorShape = Qt.SizeBDiagCursor;
return;
}
//right
rc = Qt.rect(window.width-border, border, border, window.height-border*2);
if (ptInRect(rc, mouse.x, mouse.y)) {
if (ptInRect(window.width-border,border,border,window.height-border*2, mouse.x, mouse.y)) {
cursorShape = Qt.SizeHorCursor;
return;
}
//bottom-right
rc = Qt.rect(window.width-border, window.height-border, border, border);
if (ptInRect(rc, mouse.x, mouse.y)) {
if (ptInRect(window.width-border,window.height-border,border,border, mouse.x, mouse.y)) {
cursorShape = Qt.SizeFDiagCursor;
return;
}
//bottom
rc = Qt.rect(border, window.height-border, window.width-border*2, border);
if (ptInRect(rc, mouse.x, mouse.y)) {
if (ptInRect(border,window.height-border,window.width-border*2,border, mouse.x, mouse.y)) {
cursorShape = Qt.SizeVerCursor;
return;
}
//bottom_left
rc = Qt.rect(0, window.height-border,border, border);
if (ptInRect(rc, mouse.x, mouse.y)) {
if (ptInRect(0,window.height-border,border,border, mouse.x, mouse.y)) {
cursorShape = Qt.SizeBDiagCursor;
return;
}
//left
rc = Qt.rect(0, border,border, window.height-border*2);
if (ptInRect(rc, mouse.x, mouse.y)) {
if (ptInRect(0,border,border, window.height-border*2, mouse.x, mouse.y)) {
cursorShape = Qt.SizeHorCursor;
return;
}
//default
cursorShape = Qt.ArrowCursor;
}
@ -172,13 +134,12 @@ MouseArea {
cursorShape = Qt.ArrowCursor;
}
function ptInRect(rc, x, y)
function ptInRect(rcx,rcy,rcwidth,rcheight, x, y)
{
if ((rc.x <= x && x <= (rc.x + rc.width)) &&
(rc.y <= y && y <= (rc.y + rc.height))) {
if ((rcx <= x && x <= (rcx + rcwidth)) &&
(rcy <= y && y <= (rcy + rcheight))) {
return true;
}
return false;
}

View File

@ -1,14 +1,12 @@
#include "qml_plugin.h"
#include "Fluent.h"
void FluentUIQmlPlugin::registerTypes(const char *uri)
{
Fluent::getInstance()->registerTypes(uri);
FluentUI::registerTypes(uri);
}
void FluentUIQmlPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
{
Fluent::getInstance()->initializeEngine(engine,uri);
FluentUI::initializeEngine(engine,uri);
}

View File

@ -1,6 +1,7 @@
#pragma once
#include <QQmlExtensionPlugin>
#include <FluentUI.h>
class FluentUIQmlPlugin : public QQmlExtensionPlugin
{

View File

@ -23,7 +23,6 @@
<file>controls/FluIcon.qml</file>
<file>controls/FluDivider.qml</file>
<file>controls/FluTooltip.qml</file>
<file>controls/FluDropShadow.qml</file>
<file>controls/TFpsMonitor.qml</file>
<file>controls/FluTextBoxBackground.qml</file>
<file>controls/FluMultiLineTextBox.qml</file>
@ -31,5 +30,7 @@
<file>controls/FluScrollBar.qml</file>
<file>controls/FluMenu.qml</file>
<file>controls/FluMenuItem.qml</file>
<file>controls/FluShadow.qml</file>
<file>controls/FluTextButton.qml</file>
</qresource>
</RCC>