main
朱子楚\zhuzi 2023-02-27 23:04:52 +08:00
parent a772e18b93
commit f1b52fc5ee
13 changed files with 116 additions and 58 deletions

View File

@ -9,6 +9,7 @@ FluWindow {
id:rootwindow id:rootwindow
width: 800 width: 800
height: 600 height: 600
title: "FluentUI"
FluAppBar{ FluAppBar{
id:appbar id:appbar
@ -43,10 +44,23 @@ FluWindow {
Rectangle{ Rectangle{
color: { color: {
if(nav_list.currentIndex === index){ if(FluApp.isDark){
return "#EAEAEB" if(item_mouse.containsMouse){
return "#292929"
}
if(nav_list.currentIndex === index){
return "#2D2D2D"
}
return "#00000000"
}else{
if(item_mouse.containsMouse){
return "#EDEDED"
}
if(nav_list.currentIndex === index){
return "#EAEAEA"
}
return "#00000000"
} }
return item_mouse.containsMouse? "#EAEAEA" : "#00000000"
} }
radius: 4 radius: 4
anchors{ anchors{
@ -70,9 +84,10 @@ FluWindow {
} }
} }
Text{ FluText{
text:model.text text:model.text
anchors.centerIn: parent anchors.centerIn: parent
fontStyle: FluText.Caption
} }
} }

View File

@ -5,6 +5,7 @@ FluWindow {
width: 500 width: 500
height: 500 height: 500
title:"设置"
FluAppBar{ FluAppBar{
id:appbar id:appbar

View File

@ -17,8 +17,7 @@ Item {
FluButton{ FluButton{
Layout.topMargin: 20 Layout.topMargin: 20
onClicked: { onClicked: {
FluApp.getWIdByWindow(Window.window)
// FluApp.navigate("/Setting")
} }
} }

View File

@ -7,7 +7,7 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
// qputenv("QSG_RENDER_LOOP","basic"); qputenv("QSG_RENDER_LOOP","basic");
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication app(argc, argv); QGuiApplication app(argc, argv);
QQmlApplicationEngine engine; QQmlApplicationEngine engine;

View File

@ -4,6 +4,7 @@
#include <QGuiApplication> #include <QGuiApplication>
#include <QQmlContext> #include <QQmlContext>
#include <QQuickItem> #include <QQuickItem>
#include <QTimer>
#include "FramelessView.h" #include "FramelessView.h"
@ -30,26 +31,7 @@ void FluApp::setAppWindow(QWindow *window){
} }
void FluApp::run(){ void FluApp::run(){
if(!routes().contains(initialRoute())){ navigate(initialRoute());
qErrnoWarning("没有找到当前路由");
return;
}
FramelessView *view = new FramelessView();
view->engine()->rootContext()->setContextProperty("FluApp",FluApp::getInstance());
view->setColor(QColor(255,0,0,1));
const QUrl url(routes().value(initialRoute()).toString());
QObject::connect(view, &QQuickView::statusChanged, view, [&](QQuickView::Status status) {
if (status == QQuickView::Status::Ready) {
qDebug()<<"-----------winId:"<<view->winId();
}
});
QObject::connect(view->engine(), &QQmlEngine::quit, qApp, &QCoreApplication::quit);
QObject::connect(qApp, &QGuiApplication::aboutToQuit, qApp, [&view](){view->setSource({});});
// view->setTitle("FluentUI");
view->setSource(url);
view->moveToScreenCenter();
view->show();
} }
void FluApp::navigate(const QString& route){ void FluApp::navigate(const QString& route){
@ -57,16 +39,27 @@ void FluApp::navigate(const QString& route){
qErrnoWarning("没有找到当前路由"); qErrnoWarning("没有找到当前路由");
return; return;
} }
bool isAppWindow = route==initialRoute();
FramelessView *view = new FramelessView(); FramelessView *view = new FramelessView();
view->engine()->rootContext()->setContextProperty("FluApp",FluApp::getInstance()); view->engine()->rootContext()->setContextProperty("FluApp",FluApp::getInstance());
view->setColor(isDark() ? QColor(0,0,0,1) : QColor(255, 255, 255, 1)); view->setColor(isDark() ? QColor(0,0,0,1) : QColor(255, 255, 255, 1));
QObject::connect(view, &QQuickView::statusChanged, view, [&](QQuickView::Status status) {
if (status == QQuickView::Status::Ready) {
Q_EMIT windowReady(view);
}
});
view->setSource((routes().value(route).toString())); view->setSource((routes().value(route).toString()));
view->closeDeleteLater(); if(isAppWindow){
QObject::connect(view->engine(), &QQmlEngine::quit, qApp, &QCoreApplication::quit);
QObject::connect(qApp, &QGuiApplication::aboutToQuit, qApp, [&view](){view->setSource({});});
}else{
view->closeDeleteLater();
}
view->moveToScreenCenter(); view->moveToScreenCenter();
view->show(); view->show();
} }
void FluApp::getWIdByWindow(QWindow *window){ bool FluApp::equalsWindow(FramelessView *view,QWindow *window){
qDebug()<< window->winId(); return view->winId() == window->winId();
window->winId();
} }

View File

@ -4,6 +4,7 @@
#include <QObject> #include <QObject>
#include <QWindow> #include <QWindow>
#include <QJsonObject> #include <QJsonObject>
#include "FramelessView.h"
#include "stdafx.h" #include "stdafx.h"
class FluApp : public QObject class FluApp : public QObject
@ -12,6 +13,7 @@ class FluApp : public QObject
Q_PROPERTY_AUTO(QString,initialRoute); Q_PROPERTY_AUTO(QString,initialRoute);
Q_PROPERTY_AUTO(bool,isDark); Q_PROPERTY_AUTO(bool,isDark);
Q_PROPERTY_AUTO(QJsonObject,routes); Q_PROPERTY_AUTO(QJsonObject,routes);
public: public:
static FluApp *getInstance(); static FluApp *getInstance();
@ -24,7 +26,9 @@ public:
Q_INVOKABLE void setAppWindow(QWindow *window); Q_INVOKABLE void setAppWindow(QWindow *window);
Q_INVOKABLE void getWIdByWindow(QWindow *window); Q_SIGNAL void windowReady(FramelessView *view);
Q_INVOKABLE bool equalsWindow(FramelessView *view,QWindow *window);
private: private:
static FluApp* m_instance; static FluApp* m_instance;

View File

@ -23,6 +23,7 @@ public:
bool isFull() const; bool isFull() const;
QQuickItem *titleItem() const; QQuickItem *titleItem() const;
static QMap<WId,FramelessView*> *windowCache;
static QRect calcCenterGeo(const QRect &screenGeo, const QSize &normalSize); static QRect calcCenterGeo(const QRect &screenGeo, const QSize &normalSize);
public slots: public slots:
void setIsMax(bool isMax); void setIsMax(bool isMax);

View File

@ -20,6 +20,10 @@
// WS_SYSMENU: enables the context menu with the move, close, maximize, minize... commands (shift + right-click on the task bar item) // WS_SYSMENU: enables the context menu with the move, close, maximize, minize... commands (shift + right-click on the task bar item)
// WS_CAPTION: enables aero minimize animation/transition // WS_CAPTION: enables aero minimize animation/transition
// WS_MAXIMIZEBOX, WS_MINIMIZEBOX: enable minimize/maximize // WS_MAXIMIZEBOX, WS_MINIMIZEBOX: enable minimize/maximize
QMap<WId,FramelessView*>* FramelessView::windowCache = new QMap<WId,FramelessView*>;
enum class Style : DWORD enum class Style : DWORD
{ {
windowed = WS_OVERLAPPEDWINDOW | WS_THICKFRAME | WS_CAPTION | WS_SYSMENU | WS_MAXIMIZEBOX | WS_MINIMIZEBOX, windowed = WS_OVERLAPPEDWINDOW | WS_THICKFRAME | WS_CAPTION | WS_SYSMENU | WS_MAXIMIZEBOX | WS_MINIMIZEBOX,
@ -149,6 +153,13 @@ FramelessView::FramelessView(QWindow* parent)
setIsMax(windowState() == Qt::WindowMaximized); setIsMax(windowState() == Qt::WindowMaximized);
setIsFull(windowState() == Qt::WindowFullScreen); setIsFull(windowState() == Qt::WindowFullScreen);
}); });
QObject::connect(this, &QQuickView::statusChanged, this, [&](QQuickView::Status status) {
if (status == QQuickView::Status::Ready) {
FramelessView::windowCache->insert(this->winId(),this);
}
});
} }
void FramelessView::showEvent(QShowEvent* e) void FramelessView::showEvent(QShowEvent* e)
{ {
@ -181,6 +192,7 @@ FramelessView::~FramelessView()
{ {
::DestroyMenu(d->mMenuHandler); ::DestroyMenu(d->mMenuHandler);
} }
FramelessView::windowCache->remove(this->winId());
delete d; delete d;
} }

View File

@ -6,22 +6,11 @@ WindowHelper::WindowHelper(QObject *parent)
} }
void WindowHelper::classBegin()
{
}
void WindowHelper::componentComplete()
{
auto rootItem = qobject_cast<QQuickItem*>(parent());
if (auto window = rootItem->window())
{
this->window = window;
this->window->setTitle("FluentUI");
qDebug()<<"--------->--------->";
}
}
void WindowHelper::setTitle(const QString& text){ void WindowHelper::setTitle(const QString& text){
window->setTitle(text); window->setTitle(text);
} }
void WindowHelper::initWindow(FramelessView* window){
this->window = window;
}

View File

@ -4,20 +4,21 @@
#include <QObject> #include <QObject>
#include <QQuickWindow> #include <QQuickWindow>
#include <QQuickItem> #include <QQuickItem>
#include <QWindow>
#include "FramelessView.h"
class WindowHelper : public QObject, public QQmlParserStatus class WindowHelper : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit WindowHelper(QObject *parent = nullptr); explicit WindowHelper(QObject *parent = nullptr);
void classBegin() override;
void componentComplete() override;
Q_INVOKABLE void initWindow(FramelessView* window);
Q_INVOKABLE void setTitle(const QString& text); Q_INVOKABLE void setTitle(const QString& text);
private:
QQuickWindow* window; private:
FramelessView* window;
}; };

View File

@ -809,6 +809,10 @@ Module {
prototype: "QObject" prototype: "QObject"
exports: ["FluentUI/WindowHelper 1.0"] exports: ["FluentUI/WindowHelper 1.0"]
exportMetaObjectRevisions: [0] exportMetaObjectRevisions: [0]
Method {
name: "initWindow"
Parameter { name: "window"; type: "FramelessView"; isPointer: true }
}
Method { Method {
name: "setTitle" name: "setTitle"
Parameter { name: "text"; type: "string" } Parameter { name: "text"; type: "string" }
@ -1044,5 +1048,6 @@ Module {
defaultProperty: "data" defaultProperty: "data"
Property { name: "isMax"; type: "bool" } Property { name: "isMax"; type: "bool" }
Property { name: "title"; type: "string" } Property { name: "title"; type: "string" }
Property { name: "window"; type: "QVariant" }
} }
} }

View File

@ -14,15 +14,31 @@ Switch {
width: root.width width: root.width
height: root.height height: root.height
radius: height / 2 radius: height / 2
color: root.checked ? checkedColor : "white" color: {
if(FluApp.isDark){
if(root.checked){
return checkedColor
}
if(switch_mouse.containsMouse){
return "#3E3E3C"
}
return "#323232"
}else{
if(switch_mouse.containsMouse){
return "#F4F4F4"
}
return root.checked ? checkedColor : "white"
}
}
border.width: 1 border.width: 1
border.color: root.checked ? checkedColor : "#666666" border.color: root.checked ? checkedColor : "#666666"
Rectangle { Rectangle {
x: root.checked ? parent.width - width - 4 : 4 x: root.checked ? root.implicitWidth - width - 4 : 4
width: root.checked ? parent.height - 8 : parent.height - 8 width: root.height - 8
height: width height: root.height - 8
radius: width / 2 radius: width / 2
scale: switch_mouse.containsMouse ? 1.2 : 1.0
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
color: root.checked ? "#FFFFFF" : "#666666" color: root.checked ? "#FFFFFF" : "#666666"
// border.color: "#D5D5D5" // border.color: "#D5D5D5"

View File

@ -13,9 +13,21 @@ Rectangle {
} }
property string title: "FluentUI" property string title: "FluentUI"
Behavior on opacity{
NumberAnimation{
duration: 100
}
}
property var window : {
if(Window.window == null)
return null
return Window.window
}
onIsMaxChanged: { onIsMaxChanged: {
if(isMax){ if(isMax){
root.anchors.margins = 4 root.anchors.margins = 8
root.anchors.fill = parent root.anchors.fill = parent
}else{ }else{
root.anchors.margins = 0 root.anchors.margins = 0
@ -26,7 +38,17 @@ Rectangle {
color : FluApp.isDark ? "#202020" : "#F3F3F3" color : FluApp.isDark ? "#202020" : "#F3F3F3"
Component.onCompleted: { Component.onCompleted: {
console.debug("onCompleted")
}
Connections{
target: FluApp
function onWindowReady(view){
if(FluApp.equalsWindow(view,window)){
helper.initWindow(view);
helper.setTitle(title);
}
}
} }
WindowHelper{ WindowHelper{