mirror of
https://github.com/zhuzichu520/FluentUI.git
synced 2025-04-24 11:53:17 +08:00
update
This commit is contained in:
parent
f4112ee5dc
commit
61659b5e31
@ -1,10 +1,12 @@
|
|||||||
#include "FluFrameless.h"
|
#include "FluFramelessHelper.h"
|
||||||
|
|
||||||
#include <QGuiApplication>
|
#include <QGuiApplication>
|
||||||
#include <QOperatingSystemVersion>
|
#include <QOperatingSystemVersion>
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
#pragma comment(lib, "user32.lib")
|
#pragma comment (lib,"user32.lib")
|
||||||
|
#pragma comment (lib,"dwmapi.lib")
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
#include <dwmapi.h>
|
||||||
|
|
||||||
static inline QByteArray qtNativeEventType()
|
static inline QByteArray qtNativeEventType()
|
||||||
{
|
{
|
||||||
@ -28,6 +30,26 @@ static inline bool isCompositionEnabled(){
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void showShadow(HWND hwnd){
|
||||||
|
if(isCompositionEnabled()){
|
||||||
|
const MARGINS shadow = { 1, 1, 1, 1 };
|
||||||
|
typedef HRESULT (WINAPI* DwmExtendFrameIntoClientAreaPtr)(HWND hWnd, const MARGINS *pMarInset);
|
||||||
|
HMODULE module = LoadLibraryW(L"dwmapi.dll");
|
||||||
|
if (module)
|
||||||
|
{
|
||||||
|
DwmExtendFrameIntoClientAreaPtr dwm_extendframe_into_client_area_;
|
||||||
|
dwm_extendframe_into_client_area_= reinterpret_cast<DwmExtendFrameIntoClientAreaPtr>(GetProcAddress(module, "DwmExtendFrameIntoClientArea"));
|
||||||
|
if (dwm_extendframe_into_client_area_)
|
||||||
|
{
|
||||||
|
dwm_extendframe_into_client_area_(hwnd, &shadow);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
ULONG_PTR cNewStyle = GetClassLongPtr(hwnd, GCL_STYLE) | CS_DROPSHADOW;
|
||||||
|
SetClassLongPtr(hwnd, GCL_STYLE, cNewStyle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
FramelessEventFilter::FramelessEventFilter(QQuickWindow* window){
|
FramelessEventFilter::FramelessEventFilter(QQuickWindow* window){
|
||||||
@ -86,15 +108,15 @@ bool FramelessEventFilter::nativeEventFilter(const QByteArray &eventType, void *
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
FluFrameless::FluFrameless(QObject *parent)
|
FluFramelessHelper::FluFramelessHelper(QObject *parent)
|
||||||
: QObject{parent}
|
: QObject{parent}
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void FluFrameless::classBegin(){
|
void FluFramelessHelper::classBegin(){
|
||||||
}
|
}
|
||||||
|
|
||||||
void FluFrameless::updateCursor(int edges){
|
void FluFramelessHelper::updateCursor(int edges){
|
||||||
switch (edges) {
|
switch (edges) {
|
||||||
case 0:
|
case 0:
|
||||||
_window->setCursor(Qt::ArrowCursor);
|
_window->setCursor(Qt::ArrowCursor);
|
||||||
@ -118,7 +140,7 @@ void FluFrameless::updateCursor(int edges){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FluFrameless::eventFilter(QObject *obj, QEvent *ev){
|
bool FluFramelessHelper::eventFilter(QObject *obj, QEvent *ev){
|
||||||
if (!_window.isNull() && _window->flags() & Qt::FramelessWindowHint) {
|
if (!_window.isNull() && _window->flags() & Qt::FramelessWindowHint) {
|
||||||
|
|
||||||
static int edges = 0;
|
static int edges = 0;
|
||||||
@ -178,7 +200,7 @@ bool FluFrameless::eventFilter(QObject *obj, QEvent *ev){
|
|||||||
return QObject::eventFilter(obj, ev);
|
return QObject::eventFilter(obj, ev);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FluFrameless::componentComplete(){
|
void FluFramelessHelper::componentComplete(){
|
||||||
auto o = parent();
|
auto o = parent();
|
||||||
while (nullptr != o) {
|
while (nullptr != o) {
|
||||||
_window = (QQuickWindow*)o;
|
_window = (QQuickWindow*)o;
|
||||||
@ -190,11 +212,10 @@ void FluFrameless::componentComplete(){
|
|||||||
_nativeEvent =new FramelessEventFilter(_window);
|
_nativeEvent =new FramelessEventFilter(_window);
|
||||||
qApp->installNativeEventFilter(_nativeEvent);
|
qApp->installNativeEventFilter(_nativeEvent);
|
||||||
HWND hwnd = reinterpret_cast<HWND>(_window->winId());
|
HWND hwnd = reinterpret_cast<HWND>(_window->winId());
|
||||||
ULONG_PTR cNewStyle = GetClassLongPtr(hwnd, GCL_STYLE) | CS_DROPSHADOW;
|
|
||||||
SetClassLongPtr(hwnd, GCL_STYLE, cNewStyle);
|
|
||||||
DWORD style = GetWindowLongPtr(hwnd,GWL_STYLE);
|
DWORD style = GetWindowLongPtr(hwnd,GWL_STYLE);
|
||||||
SetWindowLongPtr(hwnd, GWL_STYLE, style | WS_THICKFRAME | WS_CAPTION &~ WS_SYSMENU);
|
SetWindowLongPtr(hwnd, GWL_STYLE, style | WS_THICKFRAME | WS_CAPTION &~ WS_SYSMENU);
|
||||||
SetWindowPos(hwnd,nullptr,0,0,0,0,SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOMOVE | SWP_NOSIZE |SWP_FRAMECHANGED);
|
SetWindowPos(hwnd,nullptr,0,0,0,0,SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOMOVE | SWP_NOSIZE |SWP_FRAMECHANGED);
|
||||||
|
showShadow(hwnd);
|
||||||
#endif
|
#endif
|
||||||
_stayTop = QQmlProperty(_window,"stayTop");
|
_stayTop = QQmlProperty(_window,"stayTop");
|
||||||
_stayTop.connectNotifySignal(this,SLOT(_onStayTopChange()));
|
_stayTop.connectNotifySignal(this,SLOT(_onStayTopChange()));
|
||||||
@ -204,12 +225,12 @@ void FluFrameless::componentComplete(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FluFrameless::_onScreenChanged(){
|
void FluFramelessHelper::_onScreenChanged(){
|
||||||
_window->update();
|
_window->update();
|
||||||
QGuiApplication::processEvents();
|
QGuiApplication::processEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FluFrameless::_onStayTopChange(){
|
void FluFramelessHelper::_onStayTopChange(){
|
||||||
bool isStayTop = _stayTop.read().toBool();
|
bool isStayTop = _stayTop.read().toBool();
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
HWND hwnd = reinterpret_cast<HWND>(_window->winId());
|
HWND hwnd = reinterpret_cast<HWND>(_window->winId());
|
||||||
@ -225,7 +246,7 @@ void FluFrameless::_onStayTopChange(){
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
FluFrameless::~FluFrameless(){
|
FluFramelessHelper::~FluFramelessHelper(){
|
||||||
if (!_window.isNull()) {
|
if (!_window.isNull()) {
|
||||||
_window->setFlags(Qt::Window);
|
_window->setFlags(Qt::Window);
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
@ -1,5 +1,5 @@
|
|||||||
#ifndef FLUFRAMELESS_H
|
#ifndef FLUFRAMELESSHELPER_H
|
||||||
#define FLUFRAMELESS_H
|
#define FLUFRAMELESSHELPER_H
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QQuickWindow>
|
#include <QQuickWindow>
|
||||||
@ -25,13 +25,13 @@ public:
|
|||||||
qint64 _current = 0;
|
qint64 _current = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class FluFrameless : public QObject, public QQmlParserStatus
|
class FluFramelessHelper : public QObject, public QQmlParserStatus
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
QML_NAMED_ELEMENT(FluFrameless)
|
QML_NAMED_ELEMENT(FluFramelessHelper)
|
||||||
public:
|
public:
|
||||||
explicit FluFrameless(QObject *parent = nullptr);
|
explicit FluFramelessHelper(QObject *parent = nullptr);
|
||||||
~FluFrameless();
|
~FluFramelessHelper();
|
||||||
void classBegin() override;
|
void classBegin() override;
|
||||||
void componentComplete() override;
|
void componentComplete() override;
|
||||||
protected:
|
protected:
|
||||||
@ -47,4 +47,4 @@ private:
|
|||||||
QQmlProperty _screen;
|
QQmlProperty _screen;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // FLUFRAMELESS_H
|
#endif // FLUFRAMELESSHELPER_H
|
@ -16,7 +16,7 @@
|
|||||||
#include "Screenshot.h"
|
#include "Screenshot.h"
|
||||||
#include "FluRectangle.h"
|
#include "FluRectangle.h"
|
||||||
#include "FluNetwork.h"
|
#include "FluNetwork.h"
|
||||||
#include "FluFrameless.h"
|
#include "FluFramelessHelper.h"
|
||||||
#include "QRCode.h"
|
#include "QRCode.h"
|
||||||
|
|
||||||
void FluentUI::registerTypes(QQmlEngine *engine){
|
void FluentUI::registerTypes(QQmlEngine *engine){
|
||||||
@ -41,7 +41,7 @@ void FluentUI::registerTypes(const char *uri){
|
|||||||
qmlRegisterType<FluRectangle>(uri,major,minor,"FluRectangle");
|
qmlRegisterType<FluRectangle>(uri,major,minor,"FluRectangle");
|
||||||
qmlRegisterType<NetworkCallable>(uri,major,minor,"FluNetworkCallable");
|
qmlRegisterType<NetworkCallable>(uri,major,minor,"FluNetworkCallable");
|
||||||
qmlRegisterType<NetworkParams>(uri,major,minor,"FluNetworkParams");
|
qmlRegisterType<NetworkParams>(uri,major,minor,"FluNetworkParams");
|
||||||
qmlRegisterType<FluFrameless>(uri,major,minor,"FluFrameless");
|
qmlRegisterType<FluFramelessHelper>(uri,major,minor,"FluFramelessHelper");
|
||||||
|
|
||||||
qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/ColorPicker/ColorPicker.qml"),uri,major,minor,"ColorPicker");
|
qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/ColorPicker/ColorPicker.qml"),uri,major,minor,"ColorPicker");
|
||||||
qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/ColorPicker/Content/Checkerboard.qml"),uri,major,minor,"Checkerboard");
|
qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/ColorPicker/Content/Checkerboard.qml"),uri,major,minor,"Checkerboard");
|
||||||
|
@ -92,7 +92,7 @@ Window {
|
|||||||
}
|
}
|
||||||
Component{
|
Component{
|
||||||
id:com_frameless
|
id:com_frameless
|
||||||
FluFrameless{}
|
FluFramelessHelper{}
|
||||||
}
|
}
|
||||||
Component{
|
Component{
|
||||||
id:com_background
|
id:com_background
|
||||||
|
@ -91,7 +91,7 @@ Window {
|
|||||||
}
|
}
|
||||||
Component{
|
Component{
|
||||||
id:com_frameless
|
id:com_frameless
|
||||||
FluFrameless{}
|
FluFramelessHelper{}
|
||||||
}
|
}
|
||||||
Component{
|
Component{
|
||||||
id:com_background
|
id:com_background
|
||||||
|
Loading…
x
Reference in New Issue
Block a user