commit
5ea3cb1054
|
@ -11,7 +11,7 @@ Window {
|
||||||
//初始化一个MediaPlayer,解决macos切换到T_MediaPalyer页面崩溃问题
|
//初始化一个MediaPlayer,解决macos切换到T_MediaPalyer页面崩溃问题
|
||||||
MediaPlayer{}
|
MediaPlayer{}
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
FluApp.init(app,properties)
|
FluApp.init(app)
|
||||||
FluTheme.frameless = ("windows" === Qt.platform.os)
|
FluTheme.frameless = ("windows" === Qt.platform.os)
|
||||||
FluTheme.dark = false
|
FluTheme.dark = false
|
||||||
FluApp.routes = {
|
FluApp.routes = {
|
||||||
|
|
|
@ -3,10 +3,12 @@ CONFIG += c++17
|
||||||
DEFINES += QT_DEPRECATED_WARNINGS QT_NO_WARNING_OUTPUT
|
DEFINES += QT_DEPRECATED_WARNINGS QT_NO_WARNING_OUTPUT
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
ChatController.h
|
ChatController.h \
|
||||||
|
AppInfo.h
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
ChatController.cpp \
|
ChatController.cpp \
|
||||||
|
AppInfo.cpp \
|
||||||
main.cpp
|
main.cpp
|
||||||
|
|
||||||
RESOURCES += qml.qrc
|
RESOURCES += qml.qrc
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
pragma Singleton
|
pragma Singleton
|
||||||
|
|
||||||
import QtQuick
|
import QtQuick
|
||||||
|
import QtQuick.Controls
|
||||||
import FluentUI
|
import FluentUI
|
||||||
|
|
||||||
QtObject {
|
QtObject {
|
||||||
|
|
||||||
property int displayMode : FluNavigationView.Auto
|
property int displayMode : FluNavigationView.Auto
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,14 +5,9 @@
|
||||||
#include <QQuickWindow>
|
#include <QQuickWindow>
|
||||||
#include <QQuickStyle>
|
#include <QQuickStyle>
|
||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
|
#include "AppInfo.h"
|
||||||
#include "ChatController.h"
|
#include "ChatController.h"
|
||||||
|
|
||||||
QMap<QString, QVariant> properties(){
|
|
||||||
QMap<QString, QVariant> map;
|
|
||||||
// map["installHelper"] = QVariant::fromValue(QVariant::fromValue(InstallHelper::getInstance()));
|
|
||||||
return map;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
QCoreApplication::setOrganizationName("ZhuZiChu");
|
QCoreApplication::setOrganizationName("ZhuZiChu");
|
||||||
|
@ -21,17 +16,8 @@ int main(int argc, char *argv[])
|
||||||
QQuickStyle::setStyle("Basic");
|
QQuickStyle::setStyle("Basic");
|
||||||
QGuiApplication app(argc, argv);
|
QGuiApplication app(argc, argv);
|
||||||
QQmlApplicationEngine engine;
|
QQmlApplicationEngine engine;
|
||||||
|
|
||||||
qmlRegisterType<ChatController>("Controller",1,0,"ChatController");
|
qmlRegisterType<ChatController>("Controller",1,0,"ChatController");
|
||||||
|
engine.rootContext()->setContextProperty("appInfo",new AppInfo());
|
||||||
QMapIterator<QString, QVariant> iterator(properties());
|
|
||||||
while (iterator.hasNext()) {
|
|
||||||
iterator.next();
|
|
||||||
QString key = iterator.key();
|
|
||||||
QVariant value = iterator.value();
|
|
||||||
engine.rootContext()->setContextProperty(key,value);
|
|
||||||
}
|
|
||||||
engine.rootContext()->setContextProperty("properties",properties());
|
|
||||||
const QUrl url(QStringLiteral("qrc:/App.qml"));
|
const QUrl url(QStringLiteral("qrc:/App.qml"));
|
||||||
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
|
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
|
||||||
&app, [url](QObject *obj, const QUrl &objUrl) {
|
&app, [url](QObject *obj, const QUrl &objUrl) {
|
||||||
|
|
|
@ -5,6 +5,8 @@ import FluentUI
|
||||||
|
|
||||||
FluWindow {
|
FluWindow {
|
||||||
|
|
||||||
|
id:window
|
||||||
|
|
||||||
width: 500
|
width: 500
|
||||||
height: 600
|
height: 600
|
||||||
minimumWidth: 500
|
minimumWidth: 500
|
||||||
|
@ -36,7 +38,7 @@ FluWindow {
|
||||||
fontStyle: FluText.Title
|
fontStyle: FluText.Title
|
||||||
}
|
}
|
||||||
FluText{
|
FluText{
|
||||||
text:"v1.2.4"
|
text:"v%1".arg(appInfo.version)
|
||||||
fontStyle: FluText.Body
|
fontStyle: FluText.Body
|
||||||
Layout.alignment: Qt.AlignBottom
|
Layout.alignment: Qt.AlignBottom
|
||||||
}
|
}
|
||||||
|
@ -67,7 +69,8 @@ FluWindow {
|
||||||
text:"https://github.com/zhuzichu520/FluentUI"
|
text:"https://github.com/zhuzichu520/FluentUI"
|
||||||
Layout.alignment: Qt.AlignBottom
|
Layout.alignment: Qt.AlignBottom
|
||||||
onClicked: {
|
onClicked: {
|
||||||
Qt.openUrlExternally(text_hublink.text)
|
console.debug(window.width)
|
||||||
|
// Qt.openUrlExternally(text_hublink.text)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,8 +12,6 @@ FluWindow {
|
||||||
minimumHeight: 400
|
minimumHeight: 400
|
||||||
maximumWidth: 400
|
maximumWidth: 400
|
||||||
maximumHeight: 400
|
maximumHeight: 400
|
||||||
modality:2
|
|
||||||
|
|
||||||
title:"登录"
|
title:"登录"
|
||||||
|
|
||||||
onInitArgument:
|
onInitArgument:
|
||||||
|
|
|
@ -7,8 +7,20 @@
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QUuid>
|
#include <QUuid>
|
||||||
#include <QClipboard>
|
#include <QClipboard>
|
||||||
|
#include "FluTheme.h"
|
||||||
#include "Def.h"
|
#include "Def.h"
|
||||||
|
|
||||||
|
#ifdef Q_OS_WIN
|
||||||
|
#include <dwmapi.h>
|
||||||
|
#include <Windows.h>
|
||||||
|
#include <windowsx.h>
|
||||||
|
static bool isCompositionEnabled()
|
||||||
|
{
|
||||||
|
BOOL composition_enabled = FALSE;
|
||||||
|
bool success = ::DwmIsCompositionEnabled(&composition_enabled) == S_OK;
|
||||||
|
return composition_enabled && success;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
FluApp* FluApp::m_instance = nullptr;
|
FluApp* FluApp::m_instance = nullptr;
|
||||||
|
|
||||||
|
@ -25,12 +37,16 @@ FluApp::FluApp(QObject *parent)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void FluApp::init(QWindow *window,QMap<QString, QVariant> properties){
|
void FluApp::init(QQuickWindow *window){
|
||||||
this->appWindow = window;
|
this->appWindow = window;
|
||||||
this->properties = properties;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FluApp::run(){
|
void FluApp::run(){
|
||||||
|
#ifdef Q_OS_WIN
|
||||||
|
if(!isCompositionEnabled()){
|
||||||
|
FluTheme::getInstance()->frameless(false);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
navigate(initialRoute());
|
navigate(initialRoute());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,38 +55,23 @@ void FluApp::navigate(const QString& route,const QJsonObject& argument,FluRegist
|
||||||
qErrnoWarning("没有找到当前路由");
|
qErrnoWarning("没有找到当前路由");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
bool isAppWindow = route == initialRoute();
|
QQmlEngine *engine = qmlEngine(appWindow);
|
||||||
FramelessView *view = new FramelessView();
|
QQmlComponent component(engine, routes().value(route).toString());
|
||||||
|
QVariantMap properties;
|
||||||
|
if(fluRegister){
|
||||||
|
properties.insert("pageRegister",QVariant::fromValue(fluRegister));
|
||||||
|
}
|
||||||
|
properties.insert("argument",argument);
|
||||||
|
QQuickWindow *view = qobject_cast<QQuickWindow*>(component.createWithInitialProperties(properties));
|
||||||
|
wnds.insert(view->winId(),view);
|
||||||
if(fluRegister){
|
if(fluRegister){
|
||||||
fluRegister->to(view);
|
fluRegister->to(view);
|
||||||
view->setProperty("pageRegister",QVariant::fromValue(fluRegister));
|
|
||||||
}
|
|
||||||
view->setProperty("argument",argument);
|
|
||||||
QMapIterator<QString, QVariant> iterator(properties);
|
|
||||||
while (iterator.hasNext()) {
|
|
||||||
iterator.next();
|
|
||||||
QString key = iterator.key();
|
|
||||||
QVariant value = iterator.value();
|
|
||||||
view->engine()->rootContext()->setContextProperty(key,value);
|
|
||||||
}
|
}
|
||||||
view->setColor(QColor(Qt::transparent));
|
view->setColor(QColor(Qt::transparent));
|
||||||
QObject::connect(view, &QQuickView::statusChanged, view, [&](QQuickView::Status status) {
|
if(view->maximumWidth()==view->minimumWidth()&&view->maximumHeight()==view->minimumHeight()){
|
||||||
if (status == QQuickView::Status::Ready) {
|
view->resize(view->minimumSize());
|
||||||
Q_EMIT windowReady(view);
|
}
|
||||||
view->moveToScreenCenter();
|
|
||||||
view->show();
|
view->show();
|
||||||
}
|
|
||||||
});
|
|
||||||
view->setSource((routes().value(route).toString()));
|
|
||||||
if(isAppWindow){
|
|
||||||
QObject::connect(view->engine(), &QQmlEngine::quit, qApp, &QCoreApplication::quit);
|
|
||||||
}else{
|
|
||||||
view->closeDeleteLater();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool FluApp::equalsWindow(FramelessView *view,QWindow *window){
|
|
||||||
return view->winId() == window->winId();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QJsonArray FluApp::awesomelist(const QString& keyword)
|
QJsonArray FluApp::awesomelist(const QString& keyword)
|
||||||
|
|
11
src/FluApp.h
11
src/FluApp.h
|
@ -8,7 +8,6 @@
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
#include <QQmlEngine>
|
#include <QQmlEngine>
|
||||||
#include "FluRegister.h"
|
#include "FluRegister.h"
|
||||||
#include "FramelessView.h"
|
|
||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
|
|
||||||
class FluApp : public QObject
|
class FluApp : public QObject
|
||||||
|
@ -27,11 +26,7 @@ public:
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
Q_INVOKABLE void init(QWindow *window,QMap<QString, QVariant> properties);
|
Q_INVOKABLE void init(QQuickWindow *window);
|
||||||
|
|
||||||
Q_SIGNAL void windowReady(FramelessView *view);
|
|
||||||
|
|
||||||
Q_INVOKABLE bool equalsWindow(FramelessView *view,QWindow *window);
|
|
||||||
|
|
||||||
Q_INVOKABLE QJsonArray awesomelist(const QString& keyword = "");
|
Q_INVOKABLE QJsonArray awesomelist(const QString& keyword = "");
|
||||||
|
|
||||||
|
@ -39,11 +34,11 @@ public:
|
||||||
|
|
||||||
Q_INVOKABLE QString uuid();
|
Q_INVOKABLE QString uuid();
|
||||||
|
|
||||||
|
public:
|
||||||
|
QMap<quint64, QQuickWindow*> wnds;
|
||||||
private:
|
private:
|
||||||
QMap<QString, QVariant> properties;
|
|
||||||
static FluApp* m_instance;
|
static FluApp* m_instance;
|
||||||
QWindow *appWindow;
|
QWindow *appWindow;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // FLUAPP_H
|
#endif // FLUAPP_H
|
||||||
|
|
|
@ -2,15 +2,15 @@
|
||||||
#define FLUREGISTER_H
|
#define FLUREGISTER_H
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <FramelessView.h>
|
#include <QQuickWindow>
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
|
|
||||||
class FluRegister : public QObject
|
class FluRegister : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY_AUTO(FramelessView*,from)
|
Q_PROPERTY_AUTO(QQuickWindow*,from)
|
||||||
Q_PROPERTY_AUTO(FramelessView*,to)
|
Q_PROPERTY_AUTO(QQuickWindow*,to)
|
||||||
Q_PROPERTY_AUTO(QString,path);
|
Q_PROPERTY_AUTO(QString,path);
|
||||||
public:
|
public:
|
||||||
explicit FluRegister(QObject *parent = nullptr);
|
explicit FluRegister(QObject *parent = nullptr);
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include <QGuiApplication>
|
#include <QGuiApplication>
|
||||||
#include <QQuickWindow>
|
#include <QQuickWindow>
|
||||||
#include "FluColors.h"
|
#include "FluColors.h"
|
||||||
|
#include "NativeEventFilter.h"
|
||||||
#include "FluTheme.h"
|
#include "FluTheme.h"
|
||||||
#include "WindowHelper.h"
|
#include "WindowHelper.h"
|
||||||
#include "FluApp.h"
|
#include "FluApp.h"
|
||||||
|
@ -95,6 +96,8 @@ void Fluent::registerTypes(const char *uri){
|
||||||
|
|
||||||
void Fluent::initializeEngine(QQmlEngine *engine, const char *uri)
|
void Fluent::initializeEngine(QQmlEngine *engine, const char *uri)
|
||||||
{
|
{
|
||||||
|
nativeEvent = new NativeEventFilter();
|
||||||
|
qApp->installNativeEventFilter(nativeEvent);
|
||||||
Q_UNUSED(engine)
|
Q_UNUSED(engine)
|
||||||
Q_UNUSED(uri)
|
Q_UNUSED(uri)
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
|
|
|
@ -3,17 +3,25 @@
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QQmlEngine>
|
#include <QQmlEngine>
|
||||||
|
#include "NativeEventFilter.h"
|
||||||
|
|
||||||
class Fluent: public QObject
|
class Fluent: public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
Q_INVOKABLE QString version() const;
|
Q_INVOKABLE QString version() const;
|
||||||
|
~Fluent(){
|
||||||
|
if (nativeEvent != Q_NULLPTR) {
|
||||||
|
delete nativeEvent;
|
||||||
|
nativeEvent = Q_NULLPTR;
|
||||||
|
}
|
||||||
|
}
|
||||||
void registerTypes(const char *uri);
|
void registerTypes(const char *uri);
|
||||||
void initializeEngine(QQmlEngine *engine, const char *uri);
|
void initializeEngine(QQmlEngine *engine, const char *uri);
|
||||||
static Fluent *getInstance();
|
static Fluent *getInstance();
|
||||||
private:
|
private:
|
||||||
static Fluent* m_instance;
|
static Fluent* m_instance;
|
||||||
|
NativeEventFilter *nativeEvent = Q_NULLPTR;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // FLUENT_H
|
#endif // FLUENT_H
|
||||||
|
|
|
@ -19,7 +19,7 @@ HEADERS += \
|
||||||
FluTheme.h \
|
FluTheme.h \
|
||||||
Fluent.h \
|
Fluent.h \
|
||||||
FluentUI.h \
|
FluentUI.h \
|
||||||
FramelessView.h \
|
NativeEventFilter.h \
|
||||||
WindowHelper.h \
|
WindowHelper.h \
|
||||||
qml_plugin.h \
|
qml_plugin.h \
|
||||||
stdafx.h
|
stdafx.h
|
||||||
|
@ -33,16 +33,12 @@ SOURCES += \
|
||||||
FluTheme.cpp \
|
FluTheme.cpp \
|
||||||
Fluent.cpp \
|
Fluent.cpp \
|
||||||
FluentUI.cpp \
|
FluentUI.cpp \
|
||||||
|
NativeEventFilter.cpp \
|
||||||
WindowHelper.cpp \
|
WindowHelper.cpp \
|
||||||
qml_plugin.cpp \
|
qml_plugin.cpp \
|
||||||
|
|
||||||
win32 {
|
win32 {
|
||||||
LIBS += -ldwmapi -luser32
|
LIBS += -ldwmapi -luser32
|
||||||
SOURCES += \
|
|
||||||
FramelessView_win.cpp
|
|
||||||
} else {
|
|
||||||
SOURCES += \
|
|
||||||
FramelessView_unix.cpp
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DEFINES += VERSION_IN=\\\"1.0.0\\\"
|
DEFINES += VERSION_IN=\\\"1.0.0\\\"
|
||||||
|
|
|
@ -1,56 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <QMouseEvent>
|
|
||||||
#include <QQuickView>
|
|
||||||
#include <QRegion>
|
|
||||||
|
|
||||||
class FramelessViewPrivate;
|
|
||||||
class FramelessView : public QQuickView
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
using Super = QQuickView;
|
|
||||||
Q_PROPERTY(bool isMax READ isMax NOTIFY isMaxChanged)
|
|
||||||
Q_PROPERTY(bool isFull READ isFull NOTIFY isFullChanged)
|
|
||||||
public:
|
|
||||||
explicit FramelessView(QWindow *parent = nullptr);
|
|
||||||
~FramelessView();
|
|
||||||
void moveToScreenCenter();
|
|
||||||
void closeDeleteLater();
|
|
||||||
bool isMax() const;
|
|
||||||
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);
|
|
||||||
void setIsFull(bool isFull);
|
|
||||||
void setTitleItem(QQuickItem* item);
|
|
||||||
|
|
||||||
signals:
|
|
||||||
void isMaxChanged(bool isMax);
|
|
||||||
void isFullChanged(bool isFull);
|
|
||||||
void mousePressed(int xPos, int yPos, int button);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
void showEvent(QShowEvent *e) override;
|
|
||||||
void resizeEvent(QResizeEvent *e) override;
|
|
||||||
bool event(QEvent *ev) override;
|
|
||||||
# if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
|
||||||
bool nativeEvent(const QByteArray &eventType, void *message, qintptr *result) override;
|
|
||||||
# else
|
|
||||||
bool nativeEvent(const QByteArray &eventType, void *message, long *result) override;
|
|
||||||
# endif
|
|
||||||
void mousePressEvent(QMouseEvent* event) override
|
|
||||||
{
|
|
||||||
# if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
|
||||||
emit mousePressed(event->position().x(), event->position().y(), event->button());
|
|
||||||
#else
|
|
||||||
emit mousePressed(event->x(), event->y(), event->button());
|
|
||||||
#endif
|
|
||||||
Super::mousePressEvent(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
FramelessViewPrivate *d;
|
|
||||||
};
|
|
|
@ -1,138 +0,0 @@
|
||||||
#include "FramelessView.h"
|
|
||||||
#include <QGuiApplication>
|
|
||||||
#include <QQuickItem>
|
|
||||||
#include <QScreen>
|
|
||||||
#include <QWindow>
|
|
||||||
#include <FluTheme.h>
|
|
||||||
|
|
||||||
class FramelessViewPrivate
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
bool m_isMax = false;
|
|
||||||
bool m_isFull = false;
|
|
||||||
bool m_deleteLater = false;
|
|
||||||
QQuickItem *m_titleItem = nullptr;
|
|
||||||
};
|
|
||||||
|
|
||||||
FramelessView::FramelessView(QWindow *parent) : Super(parent), d(new FramelessViewPrivate)
|
|
||||||
{
|
|
||||||
if(FluTheme::getInstance()->frameless()){
|
|
||||||
setFlags( Qt::Window | Qt::FramelessWindowHint | Qt::WindowTitleHint | Qt::WindowSystemMenuHint);
|
|
||||||
}
|
|
||||||
setResizeMode(SizeRootObjectToView);
|
|
||||||
setIsMax(windowState() == Qt::WindowMaximized);
|
|
||||||
setIsFull(windowState() == Qt::WindowFullScreen);
|
|
||||||
connect(this, &QWindow::windowStateChanged, this, [&](Qt::WindowState state) {
|
|
||||||
(void)state;
|
|
||||||
setIsMax(windowState() == Qt::WindowMaximized);
|
|
||||||
setIsFull(windowState() == Qt::WindowFullScreen);
|
|
||||||
});
|
|
||||||
connect(FluTheme::getInstance(),&FluTheme::framelessChanged,this,[=](){
|
|
||||||
setFlag(Qt::Window,false);
|
|
||||||
setFlag(Qt::Window,true);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
FramelessView::~FramelessView()
|
|
||||||
{
|
|
||||||
delete d;
|
|
||||||
}
|
|
||||||
|
|
||||||
void FramelessView::showEvent(QShowEvent *e)
|
|
||||||
{
|
|
||||||
Super::showEvent(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
QRect FramelessView::calcCenterGeo(const QRect &screenGeo, const QSize &normalSize)
|
|
||||||
{
|
|
||||||
int w = normalSize.width();
|
|
||||||
int h = normalSize.height();
|
|
||||||
int x = screenGeo.x() + (screenGeo.width() - w) / 2;
|
|
||||||
int y = screenGeo.y() + (screenGeo.height() - h) / 2;
|
|
||||||
if (screenGeo.width() < w) {
|
|
||||||
x = screenGeo.x();
|
|
||||||
w = screenGeo.width();
|
|
||||||
}
|
|
||||||
if (screenGeo.height() < h) {
|
|
||||||
y = screenGeo.y();
|
|
||||||
h = screenGeo.height();
|
|
||||||
}
|
|
||||||
return { x, y, w, h };
|
|
||||||
}
|
|
||||||
|
|
||||||
void FramelessView::moveToScreenCenter()
|
|
||||||
{
|
|
||||||
auto geo = calcCenterGeo(screen()->availableGeometry(), size());
|
|
||||||
if (minimumWidth() > geo.width() || minimumHeight() > geo.height()) {
|
|
||||||
setMinimumSize(geo.size());
|
|
||||||
}
|
|
||||||
setGeometry(geo);
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
|
|
||||||
void FramelessView::closeDeleteLater(){
|
|
||||||
d->m_deleteLater = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool FramelessView::isMax() const
|
|
||||||
{
|
|
||||||
return d->m_isMax;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool FramelessView::isFull() const
|
|
||||||
{
|
|
||||||
return d->m_isFull;
|
|
||||||
}
|
|
||||||
|
|
||||||
QQuickItem *FramelessView::titleItem() const
|
|
||||||
{
|
|
||||||
return d->m_titleItem;
|
|
||||||
}
|
|
||||||
|
|
||||||
void FramelessView::setIsMax(bool isMax)
|
|
||||||
{
|
|
||||||
if (d->m_isMax == isMax)
|
|
||||||
return;
|
|
||||||
|
|
||||||
d->m_isMax = isMax;
|
|
||||||
emit isMaxChanged(d->m_isMax);
|
|
||||||
}
|
|
||||||
|
|
||||||
void FramelessView::setIsFull(bool isFull)
|
|
||||||
{
|
|
||||||
if(d->m_isFull == isFull)
|
|
||||||
return;
|
|
||||||
|
|
||||||
d->m_isFull = isFull;
|
|
||||||
emit isFullChanged(d->m_isFull);
|
|
||||||
}
|
|
||||||
|
|
||||||
void FramelessView::setTitleItem(QQuickItem *item)
|
|
||||||
{
|
|
||||||
d->m_titleItem = item;
|
|
||||||
}
|
|
||||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
|
||||||
bool FramelessView::nativeEvent(const QByteArray &eventType, void *message, qintptr *result)
|
|
||||||
#else
|
|
||||||
bool FramelessView::nativeEvent(const QByteArray &eventType, void *message, long *result)
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
return Super::nativeEvent(eventType, message, result);
|
|
||||||
}
|
|
||||||
|
|
||||||
void FramelessView::resizeEvent(QResizeEvent *e)
|
|
||||||
{
|
|
||||||
Super::resizeEvent(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool FramelessView::event(QEvent *ev)
|
|
||||||
{
|
|
||||||
if (ev->type() == QEvent::Close) {
|
|
||||||
if(d->m_deleteLater){
|
|
||||||
deleteLater();
|
|
||||||
ev->setAccepted(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return QQuickWindow::event(ev);
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,268 +0,0 @@
|
||||||
#include "FramelessView.h"
|
|
||||||
#include <QGuiApplication>
|
|
||||||
#include <QQuickItem>
|
|
||||||
#include <QScreen>
|
|
||||||
#include <QWindow>
|
|
||||||
#include <FluTheme.h>
|
|
||||||
#include <QTimer>
|
|
||||||
|
|
||||||
#include <dwmapi.h>
|
|
||||||
#include <windowsx.h>
|
|
||||||
#pragma comment(lib, "Dwmapi.lib")
|
|
||||||
#pragma comment(lib, "User32.lib")
|
|
||||||
|
|
||||||
|
|
||||||
static bool isCompositionEnabled()
|
|
||||||
{
|
|
||||||
BOOL composition_enabled = FALSE;
|
|
||||||
bool success = ::DwmIsCompositionEnabled(&composition_enabled) == S_OK;
|
|
||||||
return composition_enabled && success;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool isMaxWin(QWindow* win)
|
|
||||||
{
|
|
||||||
return win->windowState() == Qt::WindowMaximized;
|
|
||||||
}
|
|
||||||
static bool isFullWin(QQuickView* win)
|
|
||||||
{
|
|
||||||
return win->windowState() == Qt::WindowFullScreen;
|
|
||||||
}
|
|
||||||
static bool isFixWin(QQuickView* win)
|
|
||||||
{
|
|
||||||
return win->minimumWidth() == win->maximumWidth() && win->minimumHeight() == win->maximumHeight();
|
|
||||||
}
|
|
||||||
static long hitTest(RECT winrect, long x, long y, int borderWidth)
|
|
||||||
{
|
|
||||||
if ((x >= winrect.left) && (x < winrect.left + borderWidth) && (y >= winrect.top) && (y < winrect.top + borderWidth))
|
|
||||||
{
|
|
||||||
return HTTOPLEFT;
|
|
||||||
}
|
|
||||||
else if (x < winrect.right && x >= winrect.right - borderWidth && y >= winrect.top && y < winrect.top + borderWidth)
|
|
||||||
{
|
|
||||||
return HTTOPRIGHT;
|
|
||||||
}
|
|
||||||
else if (x >= winrect.left && x < winrect.left + borderWidth && y < winrect.bottom && y >= winrect.bottom - borderWidth)
|
|
||||||
{
|
|
||||||
return HTBOTTOMLEFT;
|
|
||||||
}
|
|
||||||
else if (x < winrect.right && x >= winrect.right - borderWidth && y < winrect.bottom && y >= winrect.bottom - borderWidth)
|
|
||||||
{
|
|
||||||
return HTBOTTOMRIGHT;
|
|
||||||
}
|
|
||||||
else if (x >= winrect.left && x < winrect.left + borderWidth)
|
|
||||||
{
|
|
||||||
return HTLEFT;
|
|
||||||
}
|
|
||||||
else if (x < winrect.right && x >= winrect.right - borderWidth)
|
|
||||||
{
|
|
||||||
return HTRIGHT;
|
|
||||||
}
|
|
||||||
else if (y >= winrect.top && y < winrect.top + borderWidth)
|
|
||||||
{
|
|
||||||
return HTTOP;
|
|
||||||
}
|
|
||||||
else if (y < winrect.bottom && y >= winrect.bottom - borderWidth)
|
|
||||||
{
|
|
||||||
return HTBOTTOM;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class FramelessViewPrivate
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
bool m_isMax = false;
|
|
||||||
bool m_isFull = false;
|
|
||||||
bool m_deleteLater = false;
|
|
||||||
bool m_isFirst = true;
|
|
||||||
QQuickItem *m_titleItem = nullptr;
|
|
||||||
};
|
|
||||||
|
|
||||||
FramelessView::FramelessView(QWindow *parent) : Super(parent), d(new FramelessViewPrivate)
|
|
||||||
{
|
|
||||||
if(!isCompositionEnabled()){
|
|
||||||
FluTheme::getInstance()->frameless(false);
|
|
||||||
}
|
|
||||||
if(FluTheme::getInstance()->frameless()){
|
|
||||||
setFlag(Qt::FramelessWindowHint,true);
|
|
||||||
}
|
|
||||||
setResizeMode(SizeRootObjectToView);
|
|
||||||
setIsMax(windowState() == Qt::WindowMaximized);
|
|
||||||
setIsFull(windowState() == Qt::WindowFullScreen);
|
|
||||||
connect(this, &QWindow::windowStateChanged, this, [=](Qt::WindowState state) {
|
|
||||||
(void)state;
|
|
||||||
setIsMax(windowState() == Qt::WindowMaximized);
|
|
||||||
setIsFull(windowState() == Qt::WindowFullScreen);
|
|
||||||
});
|
|
||||||
connect(FluTheme::getInstance(),&FluTheme::framelessChanged,this,[=](){
|
|
||||||
setFlag(Qt::Window,false);
|
|
||||||
setFlag(Qt::Window,true);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
FramelessView::~FramelessView()
|
|
||||||
{
|
|
||||||
delete d;
|
|
||||||
}
|
|
||||||
|
|
||||||
void FramelessView::showEvent(QShowEvent *e)
|
|
||||||
{
|
|
||||||
static const MARGINS shadow_state[2] { { 0, 0, 0, 0 }, { 1, 1, 1, 1 } };
|
|
||||||
::DwmExtendFrameIntoClientArea((HWND)(winId()), &shadow_state[true]);
|
|
||||||
if(FluTheme::getInstance()->frameless()){
|
|
||||||
setFlag(Qt::FramelessWindowHint,false);
|
|
||||||
}
|
|
||||||
Super::showEvent(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
QRect FramelessView::calcCenterGeo(const QRect &screenGeo, const QSize &normalSize)
|
|
||||||
{
|
|
||||||
int w = normalSize.width();
|
|
||||||
int h = normalSize.height();
|
|
||||||
int x = screenGeo.x() + (screenGeo.width() - w) / 2;
|
|
||||||
int y = screenGeo.y() + (screenGeo.height() - h) / 2;
|
|
||||||
if (screenGeo.width() < w) {
|
|
||||||
x = screenGeo.x();
|
|
||||||
w = screenGeo.width();
|
|
||||||
}
|
|
||||||
if (screenGeo.height() < h) {
|
|
||||||
y = screenGeo.y();
|
|
||||||
h = screenGeo.height();
|
|
||||||
}
|
|
||||||
return { x, y, w, h };
|
|
||||||
}
|
|
||||||
|
|
||||||
void FramelessView::moveToScreenCenter()
|
|
||||||
{
|
|
||||||
auto geo = calcCenterGeo(screen()->availableGeometry(), size());
|
|
||||||
if (minimumWidth() > geo.width() || minimumHeight() > geo.height()) {
|
|
||||||
setMinimumSize(geo.size());
|
|
||||||
}
|
|
||||||
setGeometry(geo);
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
|
|
||||||
void FramelessView::closeDeleteLater(){
|
|
||||||
d->m_deleteLater = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool FramelessView::isMax() const
|
|
||||||
{
|
|
||||||
return d->m_isMax;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool FramelessView::isFull() const
|
|
||||||
{
|
|
||||||
return d->m_isFull;
|
|
||||||
}
|
|
||||||
|
|
||||||
QQuickItem *FramelessView::titleItem() const
|
|
||||||
{
|
|
||||||
return d->m_titleItem;
|
|
||||||
}
|
|
||||||
|
|
||||||
void FramelessView::setIsMax(bool isMax)
|
|
||||||
{
|
|
||||||
if (d->m_isMax == isMax)
|
|
||||||
return;
|
|
||||||
|
|
||||||
d->m_isMax = isMax;
|
|
||||||
emit isMaxChanged(d->m_isMax);
|
|
||||||
}
|
|
||||||
|
|
||||||
void FramelessView::setIsFull(bool isFull)
|
|
||||||
{
|
|
||||||
if(d->m_isFull == isFull)
|
|
||||||
return;
|
|
||||||
|
|
||||||
d->m_isFull = isFull;
|
|
||||||
emit isFullChanged(d->m_isFull);
|
|
||||||
}
|
|
||||||
|
|
||||||
int count = 1;
|
|
||||||
|
|
||||||
void FramelessView::setTitleItem(QQuickItem *item)
|
|
||||||
{
|
|
||||||
d->m_titleItem = item;
|
|
||||||
}
|
|
||||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
|
||||||
bool FramelessView::nativeEvent(const QByteArray &eventType, void *message, qintptr *result)
|
|
||||||
#else
|
|
||||||
bool FramelessView::nativeEvent(const QByteArray &eventType, void *message, long *result)
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
MSG* msg = static_cast<MSG*>(message);
|
|
||||||
if (!msg || !msg->hwnd)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (msg->message == WM_NCHITTEST && FluTheme::getInstance()->frameless())
|
|
||||||
{
|
|
||||||
RECT winrect;
|
|
||||||
GetWindowRect(HWND(winId()), &winrect);
|
|
||||||
long x = GET_X_LPARAM(msg->lParam);
|
|
||||||
long y = GET_Y_LPARAM(msg->lParam);
|
|
||||||
*result = 0;
|
|
||||||
if (!isMaxWin(this) && !isFullWin(this) && !isFixWin(this))
|
|
||||||
{
|
|
||||||
*result = hitTest(winrect, x, y, 4);
|
|
||||||
if (0 != *result)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}else if (msg->message == WM_NCCALCSIZE && FluTheme::getInstance()->frameless())
|
|
||||||
{
|
|
||||||
const auto mode = static_cast<BOOL>(msg->wParam);
|
|
||||||
const auto clientRect = mode ? &(reinterpret_cast<LPNCCALCSIZE_PARAMS>(msg->lParam)->rgrc[0]) : reinterpret_cast<LPRECT>(msg->lParam);
|
|
||||||
if (mode == TRUE)
|
|
||||||
{
|
|
||||||
*result = WVR_REDRAW;
|
|
||||||
if (!isMaxWin(this) && !isFullWin(this))
|
|
||||||
{
|
|
||||||
if (clientRect->top != 0)
|
|
||||||
{
|
|
||||||
clientRect->top -= 0.1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (clientRect->top != 0)
|
|
||||||
{
|
|
||||||
clientRect->top += 0.1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}else if (msg->message == WM_WINDOWPOSCHANGING)
|
|
||||||
{
|
|
||||||
WINDOWPOS* wp = reinterpret_cast<WINDOWPOS*>(msg->lParam);
|
|
||||||
if (wp != nullptr && (wp->flags & SWP_NOSIZE) == 0)
|
|
||||||
{
|
|
||||||
wp->flags |= SWP_NOCOPYBITS;
|
|
||||||
*result = 0;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Super::nativeEvent(eventType, message, result);
|
|
||||||
}
|
|
||||||
|
|
||||||
void FramelessView::resizeEvent(QResizeEvent *e)
|
|
||||||
{
|
|
||||||
Super::resizeEvent(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool FramelessView::event(QEvent *ev)
|
|
||||||
{
|
|
||||||
if (ev->type() == QEvent::Close) {
|
|
||||||
if(d->m_deleteLater){
|
|
||||||
deleteLater();
|
|
||||||
ev->setAccepted(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return QQuickWindow::event(ev);
|
|
||||||
}
|
|
||||||
|
|
|
@ -0,0 +1,81 @@
|
||||||
|
#include "NativeEventFilter.h"
|
||||||
|
#include "FluTheme.h"
|
||||||
|
#include "FluApp.h"
|
||||||
|
#ifdef Q_OS_WIN
|
||||||
|
#include <Windows.h>
|
||||||
|
#include <windowsx.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
bool NativeEventFilter::nativeEventFilter(const QByteArray &eventType, void *message, qintptr *result)
|
||||||
|
{
|
||||||
|
#ifdef Q_OS_WIN
|
||||||
|
if (eventType == "windows_generic_MSG" && FluTheme::getInstance()->frameless()) {
|
||||||
|
MSG* msg = static_cast<MSG *>(message);
|
||||||
|
if (msg == Q_NULLPTR)
|
||||||
|
return false;
|
||||||
|
switch(msg->message) {
|
||||||
|
case WM_COMMAND: {
|
||||||
|
SendMessage(msg->hwnd, WM_SYSCOMMAND, msg->wParam, msg->lParam);
|
||||||
|
*result = DefWindowProc(msg->hwnd, msg->message, msg->wParam, msg->lParam);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
case WM_NCCALCSIZE:{
|
||||||
|
NCCALCSIZE_PARAMS& params = *reinterpret_cast<NCCALCSIZE_PARAMS*>(msg->lParam);
|
||||||
|
if (params.rgrc[0].top != 0)
|
||||||
|
params.rgrc[0].top -= 1;
|
||||||
|
*result = WVR_REDRAW;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
case WM_NCHITTEST: {
|
||||||
|
auto view = FluApp::getInstance()->wnds[(WId)msg->hwnd];
|
||||||
|
bool isResize = !(view->maximumWidth()==view->minimumWidth()&&view->maximumHeight()==view->minimumHeight());
|
||||||
|
const LONG borderWidth = 8;
|
||||||
|
RECT winrect;
|
||||||
|
GetWindowRect(msg->hwnd, &winrect);
|
||||||
|
long x = GET_X_LPARAM(msg->lParam);
|
||||||
|
long y = GET_Y_LPARAM(msg->lParam);
|
||||||
|
if (x >= winrect.left && x < winrect.left + borderWidth &&
|
||||||
|
y < winrect.bottom && y >= winrect.bottom - borderWidth && isResize) {
|
||||||
|
*result = HTBOTTOMLEFT;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (x < winrect.right && x >= winrect.right - borderWidth &&
|
||||||
|
y < winrect.bottom && y >= winrect.bottom - borderWidth && isResize) {
|
||||||
|
*result = HTBOTTOMRIGHT;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (x >= winrect.left && x < winrect.left + borderWidth &&
|
||||||
|
y >= winrect.top && y < winrect.top + borderWidth && isResize) {
|
||||||
|
*result = HTTOPLEFT;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (x < winrect.right && x >= winrect.right - borderWidth &&
|
||||||
|
y >= winrect.top && y < winrect.top + borderWidth && isResize) {
|
||||||
|
*result = HTTOPRIGHT;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (x >= winrect.left && x < winrect.left + borderWidth && isResize) {
|
||||||
|
*result = HTLEFT;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (x < winrect.right && x >= winrect.right - borderWidth && isResize) {
|
||||||
|
*result = HTRIGHT;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (y < winrect.bottom && y >= winrect.bottom - borderWidth && isResize) {
|
||||||
|
*result = HTBOTTOM;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (y >= winrect.top && y < winrect.top + borderWidth && isResize) {
|
||||||
|
*result = HTTOP;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return false;
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
#ifndef NATIVEEVENTFILTER_H
|
||||||
|
#define NATIVEEVENTFILTER_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QAbstractNativeEventFilter>
|
||||||
|
|
||||||
|
class NativeEventFilter : public QAbstractNativeEventFilter
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
bool nativeEventFilter(const QByteArray &eventType, void *message, qintptr *result) override;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // NATIVEEVENTFILTER_H
|
|
@ -1,6 +1,19 @@
|
||||||
#include "WindowHelper.h"
|
#include "WindowHelper.h"
|
||||||
|
|
||||||
#include "FluRegister.h"
|
#include "FluRegister.h"
|
||||||
|
#include "FluApp.h"
|
||||||
|
#include "FluTheme.h"
|
||||||
|
|
||||||
|
#ifdef Q_OS_WIN
|
||||||
|
#include <dwmapi.h>
|
||||||
|
#include <Windows.h>
|
||||||
|
#include <windowsx.h>
|
||||||
|
enum class Style : DWORD
|
||||||
|
{
|
||||||
|
windowed = (WS_OVERLAPPEDWINDOW | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_THICKFRAME | WS_CLIPCHILDREN),
|
||||||
|
aero_borderless = (WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_THICKFRAME | WS_CLIPCHILDREN)
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
WindowHelper::WindowHelper(QObject *parent)
|
WindowHelper::WindowHelper(QObject *parent)
|
||||||
: QObject{parent}
|
: QObject{parent}
|
||||||
|
@ -8,51 +21,18 @@ WindowHelper::WindowHelper(QObject *parent)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WindowHelper::setTitle(const QString& text){
|
void WindowHelper::initWindow(QQuickWindow* window){
|
||||||
window->setTitle(text);
|
|
||||||
}
|
|
||||||
|
|
||||||
void WindowHelper::initWindow(FramelessView* window){
|
|
||||||
this->window = window;
|
this->window = window;
|
||||||
}
|
#ifdef Q_OS_WIN
|
||||||
|
if(FluTheme::getInstance()->frameless()){
|
||||||
QJsonObject WindowHelper::getArgument(){
|
HWND wnd = (HWND)window->winId();
|
||||||
return window->property("argument").toJsonObject();
|
SetWindowLongPtr(wnd, GWL_STYLE, static_cast<LONG>(Style::aero_borderless));
|
||||||
}
|
const MARGINS shadow_on = { 1, 1, 1, 1 };
|
||||||
|
DwmExtendFrameIntoClientArea(wnd, &shadow_on);
|
||||||
QVariant WindowHelper::getPageRegister(){
|
SetWindowPos(wnd, Q_NULLPTR, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE);
|
||||||
return window->property("pageRegister");
|
ShowWindow(wnd, SW_SHOW);
|
||||||
}
|
|
||||||
|
|
||||||
void WindowHelper::setMinimumWidth(int width){
|
|
||||||
this->window->setMinimumWidth(width);
|
|
||||||
}
|
|
||||||
void WindowHelper::setMaximumWidth(int width){
|
|
||||||
this->window->setMaximumWidth(width);
|
|
||||||
}
|
|
||||||
void WindowHelper::setMinimumHeight(int height){
|
|
||||||
this->window->setMinimumHeight(height);
|
|
||||||
}
|
|
||||||
void WindowHelper::setMaximumHeight(int height){
|
|
||||||
this->window->setMaximumHeight(height);
|
|
||||||
}
|
|
||||||
void WindowHelper::updateWindow(){
|
|
||||||
this->window->setFlag(Qt::Window,false);
|
|
||||||
this->window->setFlag(Qt::Window,true);
|
|
||||||
}
|
|
||||||
void WindowHelper::setOpacity(qreal opacity){
|
|
||||||
this->window->setOpacity(opacity);
|
|
||||||
}
|
|
||||||
void WindowHelper::setModality(int type){
|
|
||||||
if(type == 0){
|
|
||||||
this->window->setModality(Qt::NonModal);
|
|
||||||
}else if(type == 1){
|
|
||||||
this->window->setModality(Qt::WindowModal);
|
|
||||||
}else if(type == 2){
|
|
||||||
this->window->setModality(Qt::ApplicationModal);
|
|
||||||
}else{
|
|
||||||
this->window->setModality(Qt::NonModal);
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant WindowHelper::createRegister(const QString& path){
|
QVariant WindowHelper::createRegister(const QString& path){
|
||||||
|
@ -61,3 +41,10 @@ QVariant WindowHelper::createRegister(const QString& path){
|
||||||
p->path(path);
|
p->path(path);
|
||||||
return QVariant::fromValue(p);
|
return QVariant::fromValue(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WindowHelper::destoryWindow(){
|
||||||
|
if(this->window){
|
||||||
|
FluApp::getInstance()->wnds.remove(this->window->winId());
|
||||||
|
this->window->deleteLater();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
#include <QQuickItem>
|
#include <QQuickItem>
|
||||||
#include <QWindow>
|
#include <QWindow>
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
#include "FramelessView.h"
|
|
||||||
|
|
||||||
class WindowHelper : public QObject
|
class WindowHelper : public QObject
|
||||||
{
|
{
|
||||||
|
@ -15,22 +14,12 @@ class WindowHelper : public QObject
|
||||||
public:
|
public:
|
||||||
explicit WindowHelper(QObject *parent = nullptr);
|
explicit WindowHelper(QObject *parent = nullptr);
|
||||||
|
|
||||||
Q_INVOKABLE void initWindow(FramelessView* window);
|
Q_INVOKABLE void initWindow(QQuickWindow* window);
|
||||||
Q_INVOKABLE void setTitle(const QString& text);
|
Q_INVOKABLE void destoryWindow();
|
||||||
Q_INVOKABLE void setMinimumWidth(int width);
|
|
||||||
Q_INVOKABLE void setMaximumWidth(int width);
|
|
||||||
Q_INVOKABLE void setMinimumHeight(int height);
|
|
||||||
Q_INVOKABLE void setMaximumHeight(int height);
|
|
||||||
Q_INVOKABLE QJsonObject getArgument();
|
|
||||||
Q_INVOKABLE QVariant getPageRegister();
|
|
||||||
Q_INVOKABLE void updateWindow();
|
|
||||||
Q_INVOKABLE void setOpacity(qreal opacity);
|
|
||||||
Q_INVOKABLE void setModality(int type);
|
|
||||||
Q_INVOKABLE QVariant createRegister(const QString& path);
|
Q_INVOKABLE QVariant createRegister(const QString& path);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FramelessView* window;
|
QQuickWindow* window;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // WINDOWHELPER_H
|
#endif // WINDOWHELPER_H
|
||||||
|
|
|
@ -1,46 +1,23 @@
|
||||||
import QtQuick
|
import QtQuick
|
||||||
import QtQuick.Window
|
import QtQuick.Window
|
||||||
|
import QtQuick.Controls
|
||||||
import QtQuick.Layouts
|
import QtQuick.Layouts
|
||||||
import FluentUI
|
import FluentUI
|
||||||
|
|
||||||
Item {
|
ApplicationWindow {
|
||||||
|
|
||||||
property string title: "FluentUI"
|
id:window
|
||||||
property int minimumWidth
|
|
||||||
property int maximumWidth
|
|
||||||
property int minimumHeight
|
|
||||||
property int maximumHeight
|
|
||||||
property int modality:0
|
|
||||||
signal initArgument(var argument)
|
|
||||||
property var pageRegister
|
|
||||||
default property alias content: container.data
|
default property alias content: container.data
|
||||||
property var window : {
|
property var argument:({})
|
||||||
if(Window.window == null)
|
property var pageRegister
|
||||||
return null
|
signal initArgument(var argument)
|
||||||
return Window.window
|
background: Rectangle{
|
||||||
}
|
color: {
|
||||||
|
if(active){
|
||||||
property color color: {
|
|
||||||
if(window && window.active){
|
|
||||||
return FluTheme.dark ? Qt.rgba(32/255,32/255,32/255,1) : Qt.rgba(238/255,244/255,249/255,1)
|
return FluTheme.dark ? Qt.rgba(32/255,32/255,32/255,1) : Qt.rgba(238/255,244/255,249/255,1)
|
||||||
}
|
}
|
||||||
return FluTheme.dark ? Qt.rgba(32/255,32/255,32/255,1) : Qt.rgba(243/255,243/255,243/255,1)
|
return FluTheme.dark ? Qt.rgba(32/255,32/255,32/255,1) : Qt.rgba(243/255,243/255,243/255,1)
|
||||||
}
|
}
|
||||||
|
|
||||||
id:root
|
|
||||||
|
|
||||||
Behavior on opacity{
|
|
||||||
NumberAnimation{
|
|
||||||
duration: 100
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Rectangle{
|
|
||||||
id:container
|
|
||||||
color:root.color
|
|
||||||
anchors.fill: parent
|
|
||||||
anchors.margins: (window && (window.visibility === Window.Maximized) && FluTheme.frameless) ? 8/Screen.devicePixelRatio : 0
|
|
||||||
clip: true
|
|
||||||
Behavior on color{
|
Behavior on color{
|
||||||
ColorAnimation {
|
ColorAnimation {
|
||||||
duration: 300
|
duration: 300
|
||||||
|
@ -48,47 +25,31 @@ Item {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Rectangle{
|
Item{
|
||||||
border.width: 1
|
id:container
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
color: Qt.rgba(0,0,0,0,)
|
anchors.margins: window.visibility === Window.Maximized && FluTheme.frameless ? 8/Screen.devicePixelRatio : 0
|
||||||
border.color:FluTheme.dark ? Qt.rgba(45/255,45/255,45/255,1) : Qt.rgba(226/255,230/255,234/255,1)
|
clip: true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onClosing:
|
||||||
|
(event)=>{
|
||||||
|
//销毁窗口,释放资源
|
||||||
|
helper.destoryWindow()
|
||||||
|
}
|
||||||
|
|
||||||
Connections{
|
FluInfoBar{
|
||||||
target: FluApp
|
id:infoBar
|
||||||
function onWindowReady(view){
|
root: window
|
||||||
if(FluApp.equalsWindow(view,window)){
|
|
||||||
helper.initWindow(view)
|
|
||||||
initArgument(helper.getArgument())
|
|
||||||
pageRegister = helper.getPageRegister()
|
|
||||||
helper.setTitle(title)
|
|
||||||
if(minimumWidth){
|
|
||||||
helper.setMinimumWidth(minimumWidth)
|
|
||||||
}
|
|
||||||
if(maximumWidth){
|
|
||||||
helper.setMaximumWidth(maximumWidth)
|
|
||||||
}
|
|
||||||
if(minimumHeight){
|
|
||||||
helper.setMinimumHeight(minimumHeight)
|
|
||||||
}
|
|
||||||
if(maximumHeight){
|
|
||||||
helper.setMaximumHeight(maximumHeight)
|
|
||||||
}
|
|
||||||
helper.setModality(root.modality);
|
|
||||||
helper.updateWindow()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
WindowHelper{
|
WindowHelper{
|
||||||
id:helper
|
id:helper
|
||||||
}
|
}
|
||||||
|
|
||||||
FluInfoBar{
|
Component.onCompleted: {
|
||||||
id:infoBar
|
helper.initWindow(window)
|
||||||
root: root
|
initArgument(argument)
|
||||||
}
|
}
|
||||||
|
|
||||||
function showSuccess(text,duration,moremsg){
|
function showSuccess(text,duration,moremsg){
|
||||||
|
@ -107,10 +68,6 @@ Item {
|
||||||
infoBar.showError(text,duration,moremsg);
|
infoBar.showError(text,duration,moremsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
function close(){
|
|
||||||
window.close()
|
|
||||||
}
|
|
||||||
|
|
||||||
function registerForPageResult(path){
|
function registerForPageResult(path){
|
||||||
return helper.createRegister(path)
|
return helper.createRegister(path)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue