update
parent
a772e18b93
commit
f1b52fc5ee
|
@ -9,6 +9,7 @@ FluWindow {
|
|||
id:rootwindow
|
||||
width: 800
|
||||
height: 600
|
||||
title: "FluentUI"
|
||||
|
||||
FluAppBar{
|
||||
id:appbar
|
||||
|
@ -43,10 +44,23 @@ FluWindow {
|
|||
|
||||
Rectangle{
|
||||
color: {
|
||||
if(nav_list.currentIndex === index){
|
||||
return "#EAEAEB"
|
||||
if(FluApp.isDark){
|
||||
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
|
||||
anchors{
|
||||
|
@ -70,9 +84,10 @@ FluWindow {
|
|||
}
|
||||
}
|
||||
|
||||
Text{
|
||||
FluText{
|
||||
text:model.text
|
||||
anchors.centerIn: parent
|
||||
fontStyle: FluText.Caption
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ FluWindow {
|
|||
|
||||
width: 500
|
||||
height: 500
|
||||
title:"设置"
|
||||
|
||||
FluAppBar{
|
||||
id:appbar
|
||||
|
|
|
@ -17,8 +17,7 @@ Item {
|
|||
FluButton{
|
||||
Layout.topMargin: 20
|
||||
onClicked: {
|
||||
FluApp.getWIdByWindow(Window.window)
|
||||
// FluApp.navigate("/Setting")
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
// qputenv("QSG_RENDER_LOOP","basic");
|
||||
qputenv("QSG_RENDER_LOOP","basic");
|
||||
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
||||
QGuiApplication app(argc, argv);
|
||||
QQmlApplicationEngine engine;
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include <QGuiApplication>
|
||||
#include <QQmlContext>
|
||||
#include <QQuickItem>
|
||||
#include <QTimer>
|
||||
#include "FramelessView.h"
|
||||
|
||||
|
||||
|
@ -30,26 +31,7 @@ void FluApp::setAppWindow(QWindow *window){
|
|||
}
|
||||
|
||||
void FluApp::run(){
|
||||
if(!routes().contains(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();
|
||||
navigate(initialRoute());
|
||||
}
|
||||
|
||||
void FluApp::navigate(const QString& route){
|
||||
|
@ -57,16 +39,27 @@ void FluApp::navigate(const QString& route){
|
|||
qErrnoWarning("没有找到当前路由");
|
||||
return;
|
||||
}
|
||||
|
||||
bool isAppWindow = route==initialRoute();
|
||||
FramelessView *view = new FramelessView();
|
||||
view->engine()->rootContext()->setContextProperty("FluApp",FluApp::getInstance());
|
||||
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()));
|
||||
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->show();
|
||||
}
|
||||
|
||||
void FluApp::getWIdByWindow(QWindow *window){
|
||||
qDebug()<< window->winId();
|
||||
window->winId();
|
||||
bool FluApp::equalsWindow(FramelessView *view,QWindow *window){
|
||||
return view->winId() == window->winId();
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include <QObject>
|
||||
#include <QWindow>
|
||||
#include <QJsonObject>
|
||||
#include "FramelessView.h"
|
||||
#include "stdafx.h"
|
||||
|
||||
class FluApp : public QObject
|
||||
|
@ -12,6 +13,7 @@ class FluApp : public QObject
|
|||
Q_PROPERTY_AUTO(QString,initialRoute);
|
||||
Q_PROPERTY_AUTO(bool,isDark);
|
||||
Q_PROPERTY_AUTO(QJsonObject,routes);
|
||||
|
||||
public:
|
||||
|
||||
static FluApp *getInstance();
|
||||
|
@ -24,7 +26,9 @@ public:
|
|||
|
||||
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:
|
||||
static FluApp* m_instance;
|
||||
|
|
|
@ -23,6 +23,7 @@ public:
|
|||
bool isFull() const;
|
||||
QQuickItem *titleItem() const;
|
||||
|
||||
static QMap<WId,FramelessView*> *windowCache;
|
||||
static QRect calcCenterGeo(const QRect &screenGeo, const QSize &normalSize);
|
||||
public slots:
|
||||
void setIsMax(bool isMax);
|
||||
|
|
|
@ -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_CAPTION: enables aero minimize animation/transition
|
||||
// WS_MAXIMIZEBOX, WS_MINIMIZEBOX: enable minimize/maximize
|
||||
|
||||
QMap<WId,FramelessView*>* FramelessView::windowCache = new QMap<WId,FramelessView*>;
|
||||
|
||||
|
||||
enum class Style : DWORD
|
||||
{
|
||||
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);
|
||||
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)
|
||||
{
|
||||
|
@ -181,6 +192,7 @@ FramelessView::~FramelessView()
|
|||
{
|
||||
::DestroyMenu(d->mMenuHandler);
|
||||
}
|
||||
FramelessView::windowCache->remove(this->winId());
|
||||
delete d;
|
||||
}
|
||||
|
||||
|
|
|
@ -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){
|
||||
window->setTitle(text);
|
||||
}
|
||||
|
||||
|
||||
void WindowHelper::initWindow(FramelessView* window){
|
||||
this->window = window;
|
||||
}
|
||||
|
|
|
@ -4,20 +4,21 @@
|
|||
#include <QObject>
|
||||
#include <QQuickWindow>
|
||||
#include <QQuickItem>
|
||||
#include <QWindow>
|
||||
#include "FramelessView.h"
|
||||
|
||||
class WindowHelper : public QObject, public QQmlParserStatus
|
||||
class WindowHelper : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit WindowHelper(QObject *parent = nullptr);
|
||||
void classBegin() override;
|
||||
void componentComplete() override;
|
||||
|
||||
Q_INVOKABLE void initWindow(FramelessView* window);
|
||||
Q_INVOKABLE void setTitle(const QString& text);
|
||||
private:
|
||||
|
||||
QQuickWindow* window;
|
||||
private:
|
||||
FramelessView* window;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -809,6 +809,10 @@ Module {
|
|||
prototype: "QObject"
|
||||
exports: ["FluentUI/WindowHelper 1.0"]
|
||||
exportMetaObjectRevisions: [0]
|
||||
Method {
|
||||
name: "initWindow"
|
||||
Parameter { name: "window"; type: "FramelessView"; isPointer: true }
|
||||
}
|
||||
Method {
|
||||
name: "setTitle"
|
||||
Parameter { name: "text"; type: "string" }
|
||||
|
@ -1044,5 +1048,6 @@ Module {
|
|||
defaultProperty: "data"
|
||||
Property { name: "isMax"; type: "bool" }
|
||||
Property { name: "title"; type: "string" }
|
||||
Property { name: "window"; type: "QVariant" }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,15 +14,31 @@ Switch {
|
|||
width: root.width
|
||||
height: root.height
|
||||
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.color: root.checked ? checkedColor : "#666666"
|
||||
|
||||
Rectangle {
|
||||
x: root.checked ? parent.width - width - 4 : 4
|
||||
width: root.checked ? parent.height - 8 : parent.height - 8
|
||||
height: width
|
||||
x: root.checked ? root.implicitWidth - width - 4 : 4
|
||||
width: root.height - 8
|
||||
height: root.height - 8
|
||||
radius: width / 2
|
||||
scale: switch_mouse.containsMouse ? 1.2 : 1.0
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
color: root.checked ? "#FFFFFF" : "#666666"
|
||||
// border.color: "#D5D5D5"
|
||||
|
|
|
@ -13,9 +13,21 @@ Rectangle {
|
|||
}
|
||||
property string title: "FluentUI"
|
||||
|
||||
Behavior on opacity{
|
||||
NumberAnimation{
|
||||
duration: 100
|
||||
}
|
||||
}
|
||||
|
||||
property var window : {
|
||||
if(Window.window == null)
|
||||
return null
|
||||
return Window.window
|
||||
}
|
||||
|
||||
onIsMaxChanged: {
|
||||
if(isMax){
|
||||
root.anchors.margins = 4
|
||||
root.anchors.margins = 8
|
||||
root.anchors.fill = parent
|
||||
}else{
|
||||
root.anchors.margins = 0
|
||||
|
@ -26,7 +38,17 @@ Rectangle {
|
|||
color : FluApp.isDark ? "#202020" : "#F3F3F3"
|
||||
|
||||
Component.onCompleted: {
|
||||
console.debug("onCompleted")
|
||||
}
|
||||
|
||||
Connections{
|
||||
target: FluApp
|
||||
function onWindowReady(view){
|
||||
if(FluApp.equalsWindow(view,window)){
|
||||
helper.initWindow(view);
|
||||
helper.setTitle(title);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
WindowHelper{
|
||||
|
|
Loading…
Reference in New Issue