FluentUI/src/FluFramelessHelper.cpp

491 lines
17 KiB
C++
Raw Normal View History

2023-12-19 20:02:15 +08:00
#include "FluFramelessHelper.h"
2023-12-11 23:47:03 +08:00
#include <QGuiApplication>
2024-01-02 16:56:28 +08:00
#include <QScreen>
2024-02-26 15:50:42 +08:00
#include <QQuickItem>
2023-12-29 11:13:10 +08:00
#include "FluTools.h"
2024-01-08 17:43:46 +08:00
2023-12-13 21:28:21 +08:00
#ifdef Q_OS_WIN
2023-12-19 20:02:15 +08:00
#pragma comment (lib,"user32.lib")
#pragma comment (lib,"dwmapi.lib")
2023-12-13 21:28:21 +08:00
#include <windows.h>
2024-01-02 16:56:28 +08:00
#include <windowsx.h>
2023-12-19 20:02:15 +08:00
#include <dwmapi.h>
2023-12-19 18:01:49 +08:00
2023-12-13 21:28:21 +08:00
static inline QByteArray qtNativeEventType()
{
static const auto result = "windows_generic_MSG";
return result;
}
2023-12-22 01:30:25 +08:00
2023-12-18 21:29:38 +08:00
static inline bool isCompositionEnabled(){
typedef HRESULT (WINAPI* DwmIsCompositionEnabledPtr)(BOOL *pfEnabled);
HMODULE module = LoadLibraryW(L"dwmapi.dll");
if (module)
{
BOOL composition_enabled = false;
DwmIsCompositionEnabledPtr dwm_is_composition_enabled;
dwm_is_composition_enabled= reinterpret_cast<DwmIsCompositionEnabledPtr>(GetProcAddress(module, "DwmIsCompositionEnabled"));
if (dwm_is_composition_enabled)
{
dwm_is_composition_enabled(&composition_enabled);
}
return composition_enabled;
}
2024-01-08 17:03:24 +08:00
return false;
2023-12-18 21:29:38 +08:00
}
2023-12-18 21:32:56 +08:00
#endif
2023-12-18 21:29:38 +08:00
2023-12-22 01:30:25 +08:00
FramelessEventFilter::FramelessEventFilter(FluFramelessHelper* helper){
_helper = helper;
_current = _helper->window->winId();
2023-12-13 21:28:21 +08:00
}
bool FramelessEventFilter::nativeEventFilter(const QByteArray &eventType, void *message, QT_NATIVE_EVENT_RESULT_TYPE *result){
#ifdef Q_OS_WIN
2023-12-22 01:30:25 +08:00
if ((eventType != qtNativeEventType()) || !message || _helper.isNull() || _helper->window.isNull()) {
2023-12-13 21:28:21 +08:00
return false;
}
const auto msg = static_cast<const MSG *>(message);
2023-12-18 21:29:38 +08:00
const HWND hwnd = msg->hwnd;
2024-01-02 16:56:28 +08:00
if (!hwnd || !msg) {
2023-12-13 21:28:21 +08:00
return false;
}
2023-12-18 21:29:38 +08:00
const qint64 wid = reinterpret_cast<qint64>(hwnd);
2023-12-13 21:28:21 +08:00
if(wid != _current){
return false;
}
const UINT uMsg = msg->message;
2023-12-28 21:30:27 +08:00
const WPARAM wParam = msg->wParam;
const LPARAM lParam = msg->lParam;
2024-01-08 10:43:25 +08:00
static QPoint offsetXY;
2023-12-28 21:30:27 +08:00
if(uMsg == WM_WINDOWPOSCHANGING){
WINDOWPOS* wp = reinterpret_cast<WINDOWPOS*>(lParam);
if (wp != nullptr && (wp->flags & SWP_NOSIZE) == 0)
{
wp->flags |= SWP_NOCOPYBITS;
2024-01-08 10:43:25 +08:00
*result = DefWindowProcW(hwnd, uMsg, wParam, lParam);
2023-12-28 21:30:27 +08:00
return true;
}
return false;
}else if(uMsg == WM_NCCALCSIZE){
2023-12-29 17:38:04 +08:00
const auto clientRect = ((wParam == FALSE) ? reinterpret_cast<LPRECT>(lParam) : &(reinterpret_cast<LPNCCALCSIZE_PARAMS>(lParam))->rgrc[0]);
const LONG originalTop = clientRect->top;
const LONG originalLeft = clientRect->left;
2024-01-08 14:07:38 +08:00
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
const LONG originalRight = clientRect->right;
const LONG originalBottom = clientRect->bottom;
#endif
2023-12-29 17:38:04 +08:00
const LRESULT hitTestResult = ::DefWindowProcW(hwnd, WM_NCCALCSIZE, wParam, lParam);
if ((hitTestResult != HTERROR) && (hitTestResult != HTNOWHERE)) {
*result = hitTestResult;
return true;
}
2024-01-08 14:07:38 +08:00
int offsetSize = 0;
2024-01-08 16:40:19 +08:00
bool isMaximum = IsZoomed(hwnd);
2024-01-08 10:43:25 +08:00
offsetXY = QPoint(abs(clientRect->left - originalLeft),abs(clientRect->top - originalTop));
2024-02-26 15:50:42 +08:00
if(isMaximum || _helper->fullScreen()){
2024-01-08 17:03:24 +08:00
_helper->setOriginalPos(QPoint(originalLeft,originalTop));
offsetSize = 0;
2024-01-08 14:07:38 +08:00
}else{
2024-01-08 17:03:24 +08:00
_helper->setOriginalPos({});
offsetSize = 1;
}
if(!isCompositionEnabled()){
2024-01-08 14:07:38 +08:00
offsetSize = 0;
2023-12-29 17:38:04 +08:00
}
2024-01-08 14:07:38 +08:00
clientRect->top = originalTop+offsetSize;
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
2024-01-08 16:40:19 +08:00
if(!isMaximum){
clientRect->bottom = originalBottom-offsetSize;
clientRect->left = originalLeft+offsetSize;
clientRect->right = originalRight-offsetSize;
}
2024-01-08 14:07:38 +08:00
#endif
2023-12-15 11:25:54 +08:00
*result = WVR_REDRAW;
return true;
2023-12-29 23:09:46 +08:00
}if(uMsg == WM_NCHITTEST){
2023-12-29 11:13:10 +08:00
if(FluTools::getInstance()->isWindows11OrGreater() && _helper->hoverMaxBtn() && _helper->resizeable()){
2023-12-22 02:09:47 +08:00
if (*result == HTNOWHERE) {
*result = HTZOOM;
}
2023-12-22 01:30:25 +08:00
return true;
}
2024-02-26 15:50:42 +08:00
*result = 0;
2024-02-27 16:27:48 +08:00
POINT nativeGlobalPos{GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)};
POINT nativeLocalPos = nativeGlobalPos;
::ScreenToClient(hwnd, &nativeLocalPos);
RECT clientRect{0, 0, 0, 0};
::GetClientRect(hwnd, &clientRect);
auto clientWidth = clientRect.right-clientRect.left;
auto clientHeight = clientRect.bottom-clientRect.top;
2024-02-26 15:50:42 +08:00
int margins = _helper->getMargins();
2024-02-27 16:27:48 +08:00
bool left = nativeLocalPos.x < margins;
bool right = nativeLocalPos.x > clientWidth - margins;
bool top = nativeLocalPos.y < margins;
bool bottom = nativeLocalPos.y > clientHeight - margins;
2024-02-26 15:50:42 +08:00
*result = 0;
if (_helper->resizeable() && !_helper->fullScreen() && !_helper->maximized()) {
if (left && top) {
*result = HTTOPLEFT;
} else if (left && bottom) {
*result = HTBOTTOMLEFT;
} else if (right && top) {
*result = HTTOPRIGHT;
} else if (right && bottom) {
*result = HTBOTTOMRIGHT;
} else if (left) {
*result = HTLEFT;
} else if (right) {
*result = HTRIGHT;
} else if (top) {
*result = HTTOP;
} else if (bottom) {
*result = HTBOTTOM;
}
}
if (0 != *result) {
return true;
}
QVariant appBar = _helper->getAppBar();
2024-02-27 16:27:48 +08:00
if(!appBar.isNull()&& _helper->hoverAppBar()){
*result = HTCAPTION;
return true;
2024-02-26 15:50:42 +08:00
}
2024-01-05 18:18:08 +08:00
*result = HTCLIENT;
return true;
2023-12-22 01:30:25 +08:00
}else if(uMsg == WM_NCLBUTTONDBLCLK || uMsg == WM_NCLBUTTONDOWN){
2023-12-29 11:13:10 +08:00
if(FluTools::getInstance()->isWindows11OrGreater() && _helper->hoverMaxBtn() && _helper->resizeable()){
2023-12-22 01:30:25 +08:00
QMouseEvent event = QMouseEvent(QEvent::MouseButtonPress, QPoint(), QPoint(), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
QGuiApplication::sendEvent(_helper->maximizeButton(),&event);
return true;
}
return false;
}else if(uMsg == WM_NCLBUTTONUP || uMsg == WM_NCRBUTTONUP){
2023-12-29 11:13:10 +08:00
if(FluTools::getInstance()->isWindows11OrGreater() && _helper->hoverMaxBtn() && _helper->resizeable()){
2023-12-22 01:30:25 +08:00
QMouseEvent event = QMouseEvent(QEvent::MouseButtonRelease, QPoint(), QPoint(), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
QGuiApplication::sendEvent(_helper->maximizeButton(),&event);
}
return false;
2024-01-08 17:43:46 +08:00
}else if(uMsg == WM_NCPAINT){
2024-01-02 22:33:47 +08:00
*result = FALSE;
2024-01-02 14:53:53 +08:00
return true;
2024-01-02 16:56:28 +08:00
}else if(uMsg == WM_NCACTIVATE){
2024-01-02 14:53:53 +08:00
*result = DefWindowProcW(hwnd, WM_NCACTIVATE, wParam, -1);
2024-01-02 13:04:28 +08:00
return true;
2024-01-08 10:43:25 +08:00
}else if(uMsg == WM_GETMINMAXINFO){
2024-02-27 15:38:45 +08:00
#if QT_VERSION < QT_VERSION_CHECK(6,2,4)
2024-01-08 10:43:25 +08:00
MINMAXINFO* minmaxInfo = reinterpret_cast<MINMAXINFO *>(lParam);
auto pixelRatio = _helper->window->devicePixelRatio();
auto geometry = _helper->window->screen()->availableGeometry();
minmaxInfo->ptMaxSize.x = geometry.width()*pixelRatio + offsetXY.x()*2;
minmaxInfo->ptMaxSize.y = geometry.height()*pixelRatio + offsetXY.y()*2;
#endif
return false;
2024-02-26 15:50:42 +08:00
}else if(uMsg == WM_NCRBUTTONDOWN){
if (wParam == HTCAPTION) {
2024-02-27 22:09:39 +08:00
_helper->showSystemMenu(QCursor::pos());
}
}else if(uMsg == WM_KEYDOWN || uMsg == WM_SYSKEYDOWN){
const bool altPressed = ((wParam == VK_MENU) || (::GetKeyState(VK_MENU) < 0));
const bool spacePressed = ((wParam == VK_SPACE) || (::GetKeyState(VK_SPACE) < 0));
if (altPressed && spacePressed) {
auto pos = _helper->window->position();
_helper->showSystemMenu(QPoint(pos.x(),pos.y()+_helper->getAppBarHeight()));
2024-02-26 15:50:42 +08:00
}
2023-12-13 21:28:21 +08:00
}
return false;
#endif
return false;
}
2023-12-19 20:02:15 +08:00
FluFramelessHelper::FluFramelessHelper(QObject *parent)
2023-12-11 23:47:03 +08:00
: QObject{parent}
{
2023-12-22 01:30:25 +08:00
2023-12-11 23:47:03 +08:00
}
2023-12-19 20:02:15 +08:00
void FluFramelessHelper::classBegin(){
2023-12-11 23:47:03 +08:00
}
2023-12-22 01:30:25 +08:00
void FluFramelessHelper::_updateCursor(int edges){
2023-12-11 23:47:03 +08:00
switch (edges) {
case 0:
2023-12-22 01:30:25 +08:00
window->setCursor(Qt::ArrowCursor);
2023-12-11 23:47:03 +08:00
break;
case Qt::LeftEdge:
case Qt::RightEdge:
2023-12-22 01:30:25 +08:00
window->setCursor(Qt::SizeHorCursor);
2023-12-11 23:47:03 +08:00
break;
case Qt::TopEdge:
case Qt::BottomEdge:
2023-12-22 01:30:25 +08:00
window->setCursor(Qt::SizeVerCursor);
2023-12-11 23:47:03 +08:00
break;
case Qt::LeftEdge | Qt::TopEdge:
case Qt::RightEdge | Qt::BottomEdge:
2023-12-22 01:30:25 +08:00
window->setCursor(Qt::SizeFDiagCursor);
2023-12-11 23:47:03 +08:00
break;
case Qt::RightEdge | Qt::TopEdge:
case Qt::LeftEdge | Qt::BottomEdge:
2023-12-22 01:30:25 +08:00
window->setCursor(Qt::SizeBDiagCursor);
2023-12-11 23:47:03 +08:00
break;
}
}
2023-12-19 20:02:15 +08:00
bool FluFramelessHelper::eventFilter(QObject *obj, QEvent *ev){
2023-12-28 20:47:36 +08:00
if (!window.isNull() && window->flags()) {
2023-12-11 23:47:03 +08:00
switch (ev->type()) {
case QEvent::MouseButtonPress:
2024-01-08 17:43:46 +08:00
if(_edges!=0){
2023-12-22 01:30:25 +08:00
QMouseEvent *event = static_cast<QMouseEvent*>(ev);
if(event->button() == Qt::LeftButton){
2024-01-08 17:43:46 +08:00
_updateCursor(_edges);
window->startSystemResize(Qt::Edges(_edges));
2023-12-22 01:30:25 +08:00
}
2023-12-13 16:20:09 +08:00
}
2023-12-11 23:47:03 +08:00
break;
case QEvent::MouseButtonRelease:
2024-01-08 17:43:46 +08:00
_edges = 0;
2023-12-11 23:47:03 +08:00
break;
case QEvent::MouseMove: {
2024-02-26 15:50:42 +08:00
if(maximized() || fullScreen()){
2023-12-13 16:20:09 +08:00
break;
}
2023-12-22 01:30:25 +08:00
if(!resizeable()){
2023-12-13 16:20:09 +08:00
break;
}
2023-12-11 23:47:03 +08:00
QMouseEvent *event = static_cast<QMouseEvent*>(ev);
QPoint p =
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
event->pos();
#else
event->position().toPoint();
#endif
2024-02-26 15:50:42 +08:00
if(p.x() >= _margins && p.x() <= (window->width() - _margins) && p.y() >= _margins && p.y() <= (window->height() - _margins)){
2024-01-08 17:43:46 +08:00
if(_edges != 0){
_edges = 0;
_updateCursor(_edges);
2023-12-13 23:43:01 +08:00
}
break;
}
2024-01-08 17:43:46 +08:00
_edges = 0;
2024-02-26 15:50:42 +08:00
if ( p.x() < _margins ) {
2024-01-08 17:43:46 +08:00
_edges |= Qt::LeftEdge;
2023-12-11 23:47:03 +08:00
}
2024-02-26 15:50:42 +08:00
if ( p.x() > (window->width() - _margins) ) {
2024-01-08 17:43:46 +08:00
_edges |= Qt::RightEdge;
2023-12-11 23:47:03 +08:00
}
2024-02-26 15:50:42 +08:00
if ( p.y() < _margins ) {
2024-01-08 17:43:46 +08:00
_edges |= Qt::TopEdge;
2023-12-11 23:47:03 +08:00
}
2024-02-26 15:50:42 +08:00
if ( p.y() > (window->height() - _margins) ) {
2024-01-08 17:43:46 +08:00
_edges |= Qt::BottomEdge;
2023-12-11 23:47:03 +08:00
}
2024-01-08 17:43:46 +08:00
_updateCursor(_edges);
2023-12-11 23:47:03 +08:00
break;
}
default:
break;
}
}
return QObject::eventFilter(obj, ev);
}
2023-12-19 20:02:15 +08:00
void FluFramelessHelper::componentComplete(){
2023-12-11 23:47:03 +08:00
auto o = parent();
2024-01-24 15:41:10 +08:00
do {
window = qobject_cast<QQuickWindow *>(o);
if (window) {
break;
}
2023-12-11 23:47:03 +08:00
o = o->parent();
2024-01-24 15:41:10 +08:00
} while (nullptr != o);
2023-12-22 01:30:25 +08:00
if(!window.isNull()){
2023-12-29 23:09:46 +08:00
_stayTop = QQmlProperty(window,"stayTop");
_screen = QQmlProperty(window,"screen");
_fixSize = QQmlProperty(window,"fixSize");
_originalPos = QQmlProperty(window,"_originalPos");
2024-01-01 20:01:46 +08:00
_realHeight = QQmlProperty(window,"_realHeight");
_realWidth = QQmlProperty(window,"_realWidth");
_appBarHeight = QQmlProperty(window,"_appBarHeight");
2024-02-26 15:50:42 +08:00
_appBar = window->property("appBar");
2023-12-13 21:28:21 +08:00
#ifdef Q_OS_WIN
2024-02-26 15:50:42 +08:00
if(!_appBar.isNull()){
_appBar.value<QObject*>()->setProperty("systemMoveEnable",false);
}
2024-02-27 22:09:39 +08:00
window->setFlags((window->flags()) | Qt::CustomizeWindowHint | Qt::WindowMinimizeButtonHint | Qt::WindowCloseButtonHint);
2024-01-02 22:33:47 +08:00
_nativeEvent =new FramelessEventFilter(this);
qApp->installNativeEventFilter(_nativeEvent);
HWND hwnd = reinterpret_cast<HWND>(window->winId());
DWORD style = ::GetWindowLong(hwnd, GWL_STYLE);
if(resizeable()){
2024-01-03 21:21:33 +08:00
SetWindowLongPtr(hwnd, GWL_STYLE, style | WS_MAXIMIZEBOX | WS_THICKFRAME);
2023-12-28 12:42:22 +08:00
}else{
2024-01-03 21:21:33 +08:00
SetWindowLongPtr(hwnd, GWL_STYLE, style | WS_THICKFRAME);
2023-12-28 12:42:22 +08:00
}
2024-02-19 17:32:12 +08:00
LONG exstyle = ::GetWindowLong(hwnd, GWL_EXSTYLE);
exstyle = exstyle | WS_EX_LAYERED;
SetWindowLongPtr(hwnd, GWL_EXSTYLE, exstyle);
SetLayeredWindowAttributes(hwnd, RGB(251, 255, 242), 0, LWA_COLORKEY);
2024-02-24 22:26:54 +08:00
connect(window,&QQuickWindow::activeChanged,this,[this,hwnd]{
if(this->window->isActive()){
LONG exstyle = ::GetWindowLong(hwnd, GWL_EXSTYLE);
if(exstyle & WS_EX_LAYERED){
exstyle = exstyle &~ WS_EX_LAYERED;
SetWindowLongPtr(hwnd, GWL_EXSTYLE, exstyle);
2024-02-26 18:28:35 +08:00
SetWindowPos(hwnd,nullptr,0,0,0,0,SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED);
2024-02-24 22:26:54 +08:00
}
}
});
2023-12-28 12:42:22 +08:00
#else
window->setFlags((window->flags() & (~Qt::WindowMinMaxButtonsHint) & (~Qt::Dialog)) | Qt::FramelessWindowHint | Qt::Window);
2024-02-26 15:50:42 +08:00
window->installEventFilter(this);
2023-12-13 21:28:21 +08:00
#endif
2024-01-01 20:01:46 +08:00
int w = _realWidth.read().toInt();
int h = _realHeight.read().toInt()+_appBarHeight.read().toInt();
2024-02-27 22:09:39 +08:00
if(resizeable()){
window->setFlag(Qt::WindowMaximizeButtonHint);
}else{
2024-01-01 20:01:46 +08:00
window->setMaximumSize(QSize(w,h));
window->setMinimumSize(QSize(w,h));
}
window->setWidth(w);
window->setHeight(h);
2023-12-19 20:28:14 +08:00
_onStayTopChange();
2023-12-19 18:01:49 +08:00
_stayTop.connectNotifySignal(this,SLOT(_onStayTopChange()));
_screen.connectNotifySignal(this,SLOT(_onScreenChanged()));
2024-01-02 16:56:28 +08:00
Q_EMIT loadCompleted();
2023-12-11 23:47:03 +08:00
}
}
2023-12-19 20:02:15 +08:00
void FluFramelessHelper::_onScreenChanged(){
2023-12-20 18:01:09 +08:00
#ifdef Q_OS_WIN
2023-12-22 01:30:25 +08:00
HWND hwnd = reinterpret_cast<HWND>(window->winId());
2023-12-21 10:44:46 +08:00
SetWindowPos(hwnd,0,0,0,0,0,SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED | SWP_NOOWNERZORDER);
RedrawWindow(hwnd, NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
2023-12-20 18:01:09 +08:00
#endif
2023-12-19 18:01:49 +08:00
}
2024-02-27 22:09:39 +08:00
void FluFramelessHelper::showSystemMenu(QPoint point){
2023-12-22 01:30:25 +08:00
#ifdef Q_OS_WIN
HWND hwnd = reinterpret_cast<HWND>(window->winId());
DWORD style = GetWindowLongPtr(hwnd,GWL_STYLE);
2024-01-02 16:56:28 +08:00
SetWindowLongPtr(hwnd, GWL_STYLE, style | WS_SYSMENU);
2023-12-22 01:30:25 +08:00
const HMENU hMenu = ::GetSystemMenu(hwnd, FALSE);
2024-02-26 15:50:42 +08:00
if(maximized() || fullScreen()){
EnableMenuItem(hMenu,SC_MOVE,MFS_DISABLED);
2023-12-22 01:30:25 +08:00
EnableMenuItem(hMenu,SC_RESTORE,MFS_ENABLED);
}else{
2024-02-26 15:50:42 +08:00
EnableMenuItem(hMenu,SC_MOVE,MFS_ENABLED);
2023-12-22 01:30:25 +08:00
EnableMenuItem(hMenu,SC_RESTORE,MFS_DISABLED);
}
2024-02-26 15:50:42 +08:00
if(resizeable() && !maximized() && !fullScreen()){
EnableMenuItem(hMenu,SC_SIZE,MFS_ENABLED);
2023-12-22 01:30:25 +08:00
EnableMenuItem(hMenu,SC_MAXIMIZE,MFS_ENABLED);
}else{
2024-02-26 15:50:42 +08:00
EnableMenuItem(hMenu,SC_SIZE,MFS_DISABLED);
2023-12-22 01:30:25 +08:00
EnableMenuItem(hMenu,SC_MAXIMIZE,MFS_DISABLED);
}
2023-12-22 12:39:04 +08:00
const int result = TrackPopupMenu(hMenu, (TPM_RETURNCMD | (QGuiApplication::isRightToLeft() ? TPM_RIGHTALIGN : TPM_LEFTALIGN)), point.x()*window->devicePixelRatio(), point.y()*window->devicePixelRatio(), 0, hwnd, nullptr);
2023-12-22 01:30:25 +08:00
if (result != FALSE) {
PostMessageW(hwnd, WM_SYSCOMMAND, result, 0);
}
2024-01-02 16:56:28 +08:00
SetWindowLongPtr(hwnd, GWL_STYLE, style &~ WS_SYSMENU);
2023-12-22 01:30:25 +08:00
#endif
}
2023-12-19 20:02:15 +08:00
void FluFramelessHelper::_onStayTopChange(){
2023-12-19 18:01:49 +08:00
bool isStayTop = _stayTop.read().toBool();
2023-12-18 22:24:24 +08:00
#ifdef Q_OS_WIN
2023-12-22 01:30:25 +08:00
HWND hwnd = reinterpret_cast<HWND>(window->winId());
2023-12-19 18:01:49 +08:00
if(isStayTop){
SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
}else{
SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
}
#else
2023-12-22 01:30:25 +08:00
window->setFlag(Qt::WindowStaysOnTopHint,isStayTop);
2023-12-18 22:24:24 +08:00
#endif
}
2023-12-19 20:02:15 +08:00
FluFramelessHelper::~FluFramelessHelper(){
2023-12-22 01:30:25 +08:00
if (!window.isNull()) {
window->setFlags(Qt::Window);
2023-12-13 21:28:21 +08:00
#ifdef Q_OS_WIN
2024-01-02 22:33:47 +08:00
qApp->removeNativeEventFilter(_nativeEvent);
delete _nativeEvent;
2023-12-13 21:28:21 +08:00
#endif
2023-12-22 01:30:25 +08:00
window->removeEventFilter(this);
}
}
bool FluFramelessHelper::hoverMaxBtn(){
2024-02-26 15:50:42 +08:00
if(_appBar.isNull()){
2023-12-22 01:30:25 +08:00
return false;
2023-12-11 23:47:03 +08:00
}
2023-12-22 01:30:25 +08:00
QVariant var;
2024-02-26 15:50:42 +08:00
QMetaObject::invokeMethod(_appBar.value<QObject*>(), "_maximizeButtonHover",Q_RETURN_ARG(QVariant, var));
2023-12-22 01:30:25 +08:00
if(var.isNull()){
return false;
}
return var.toBool();
}
2024-02-26 15:50:42 +08:00
bool FluFramelessHelper::hoverAppBar(){
if(_appBar.isNull()){
return false;
}
QVariant var;
QMetaObject::invokeMethod(_appBar.value<QObject*>(), "_appBarHover",Q_RETURN_ARG(QVariant, var));
if(var.isNull()){
return false;
}
return var.toBool();
}
QVariant FluFramelessHelper::getAppBar(){
return _appBar;
}
2024-02-27 22:09:39 +08:00
int FluFramelessHelper::getAppBarHeight(){
if(_appBar.isNull()){
return 0;
}
QVariant var = _appBar.value<QObject*>()->property("height");
if(var.isNull()){
return 0;
}
return var.toInt();
}
2023-12-22 01:30:25 +08:00
QObject* FluFramelessHelper::maximizeButton(){
2024-02-26 15:50:42 +08:00
if(_appBar.isNull()){
2023-12-22 01:30:25 +08:00
return nullptr;
}
2024-02-26 15:50:42 +08:00
QVariant var = _appBar.value<QObject*>()->property("buttonMaximize");
2023-12-22 01:30:25 +08:00
if(var.isNull()){
return nullptr;
}
return var.value<QObject*>();
}
2023-12-29 17:38:04 +08:00
void FluFramelessHelper::setOriginalPos(QVariant pos){
_originalPos.write(pos);
}
2023-12-22 01:30:25 +08:00
bool FluFramelessHelper::resizeable(){
2024-01-02 18:27:59 +08:00
return !_fixSize.read().toBool();
2023-12-22 01:30:25 +08:00
}
2024-02-26 15:50:42 +08:00
bool FluFramelessHelper::maximized(){
2023-12-22 01:30:25 +08:00
return window->visibility() == QWindow::Maximized;
}
2024-02-26 15:50:42 +08:00
bool FluFramelessHelper::fullScreen(){
2023-12-22 01:30:25 +08:00
return window->visibility() == QWindow::FullScreen;
2023-12-11 23:47:03 +08:00
}
2024-02-26 15:50:42 +08:00
int FluFramelessHelper::getMargins(){
return _margins;
}