forked from github_mirror/framelesshelper
Minor tweaks
Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
parent
938756a757
commit
28144b1e74
|
@ -1,7 +1,11 @@
|
|||
#if(TARGET Qt${QT_VERSION_MAJOR}::Widgets)
|
||||
find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets)
|
||||
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets)
|
||||
|
||||
if(TARGET Qt${QT_VERSION_MAJOR}::Widgets)
|
||||
add_subdirectory(widget)
|
||||
add_subdirectory(mainwindow)
|
||||
#endif()
|
||||
endif()
|
||||
|
||||
if(TARGET Qt${QT_VERSION_MAJOR}::Quick)
|
||||
add_subdirectory(quick)
|
||||
endif()
|
||||
|
|
|
@ -5,7 +5,7 @@ DEFINES += \
|
|||
QT_NO_CAST_TO_ASCII \
|
||||
QT_NO_KEYWORDS \
|
||||
QT_DEPRECATED_WARNINGS \
|
||||
QT_DISABLE_DEPRECATED_BEFORE=0x060000
|
||||
QT_DISABLE_DEPRECATED_BEFORE=0x060100
|
||||
RESOURCES += $$PWD/images.qrc
|
||||
win32 {
|
||||
DEFINES += \
|
||||
|
|
|
@ -33,7 +33,7 @@ target_compile_definitions(MainWindow PRIVATE
|
|||
QT_NO_CAST_TO_ASCII
|
||||
QT_NO_KEYWORDS
|
||||
QT_DEPRECATED_WARNINGS
|
||||
QT_DISABLE_DEPRECATED_BEFORE=0x060000
|
||||
QT_DISABLE_DEPRECATED_BEFORE=0x060100
|
||||
)
|
||||
|
||||
if(MSVC)
|
||||
|
|
|
@ -56,7 +56,6 @@ MainWindow::MainWindow(QWidget *parent, Qt::WindowFlags flags) : QMainWindow(par
|
|||
titleBarWidget->maximizeButton->setChecked(isMaximized());
|
||||
titleBarWidget->maximizeButton->setToolTip(isMaximized() ? tr("Restore") : tr("Maximize"));
|
||||
});
|
||||
//connect(titleBarWidget->iconButton, &QPushButton::clicked, this, &MainWindow::displaySystemMenu);
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
|
@ -84,8 +83,8 @@ void MainWindow::showEvent(QShowEvent *event)
|
|||
FramelessWindowsManager::setHitTestVisibleInChrome(win, titleBarWidget->maximizeButton, true);
|
||||
FramelessWindowsManager::setHitTestVisibleInChrome(win, titleBarWidget->closeButton, true);
|
||||
FramelessWindowsManager::setHitTestVisibleInChrome(win, appMainWindow->menubar, true);
|
||||
inited = true;
|
||||
setContentsMargins(1, 1, 1, 1);
|
||||
inited = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -129,7 +128,7 @@ void MainWindow::paintEvent(QPaintEvent *event)
|
|||
{0, h, 0, 0}
|
||||
};
|
||||
painter.save();
|
||||
painter.setPen({Utilities::getNativeWindowFrameColor(), 1});
|
||||
painter.setPen({Utilities::getNativeWindowFrameColor(isActiveWindow()), 1});
|
||||
painter.drawLines(lines);
|
||||
painter.restore();
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ target_compile_definitions(Quick PRIVATE
|
|||
QT_NO_CAST_TO_ASCII
|
||||
QT_NO_KEYWORDS
|
||||
QT_DEPRECATED_WARNINGS
|
||||
QT_DISABLE_DEPRECATED_BEFORE=0x060000
|
||||
QT_DISABLE_DEPRECATED_BEFORE=0x060100
|
||||
)
|
||||
|
||||
if(MSVC)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (C) 2020 by wangwenx190 (Yuhang Zhao)
|
||||
* Copyright (C) 2021 by wangwenx190 (Yuhang Zhao)
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (C) 2020 by wangwenx190 (Yuhang Zhao)
|
||||
* Copyright (C) 2021 by wangwenx190 (Yuhang Zhao)
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (C) 2020 by wangwenx190 (Yuhang Zhao)
|
||||
* Copyright (C) 2021 by wangwenx190 (Yuhang Zhao)
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
|
|
|
@ -31,7 +31,7 @@ target_compile_definitions(Widget PRIVATE
|
|||
QT_NO_CAST_TO_ASCII
|
||||
QT_NO_KEYWORDS
|
||||
QT_DEPRECATED_WARNINGS
|
||||
QT_DISABLE_DEPRECATED_BEFORE=0x060000
|
||||
QT_DISABLE_DEPRECATED_BEFORE=0x060100
|
||||
)
|
||||
|
||||
if(MSVC)
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*/
|
||||
|
||||
#include "widget.h"
|
||||
#include <QtWidgets/qlayout.h>
|
||||
#include <QtWidgets/qboxlayout.h>
|
||||
#include <QtWidgets/qlabel.h>
|
||||
#include <QtCore/qdatetime.h>
|
||||
#include <QtWidgets/qpushbutton.h>
|
||||
|
@ -51,6 +51,7 @@ void Widget::showEvent(QShowEvent *event)
|
|||
FramelessWindowsManager::setHitTestVisibleInChrome(win, m_minimizeButton, true);
|
||||
FramelessWindowsManager::setHitTestVisibleInChrome(win, m_maximizeButton, true);
|
||||
FramelessWindowsManager::setHitTestVisibleInChrome(win, m_closeButton, true);
|
||||
setContentsMargins(1, 1, 1, 1);
|
||||
inited = true;
|
||||
}
|
||||
}
|
||||
|
@ -67,10 +68,10 @@ void Widget::changeEvent(QEvent *event)
|
|||
bool shouldUpdate = false;
|
||||
if (event->type() == QEvent::WindowStateChange) {
|
||||
if (isMaximized() || isFullScreen()) {
|
||||
layout()->setContentsMargins(0, 0, 0, 0);
|
||||
setContentsMargins(0, 0, 0, 0);
|
||||
m_maximizeButton->setIcon(QIcon{QStringLiteral(":/images/button_restore_black.svg")});
|
||||
} else if (!isMinimized()) {
|
||||
layout()->setContentsMargins(1, 1, 1, 1);
|
||||
setContentsMargins(1, 1, 1, 1);
|
||||
m_maximizeButton->setIcon(QIcon{QStringLiteral(":/images/button_maximize_black.svg")});
|
||||
}
|
||||
shouldUpdate = true;
|
||||
|
@ -101,7 +102,7 @@ void Widget::paintEvent(QPaintEvent *event)
|
|||
{0, h, 0, 0}
|
||||
};
|
||||
painter.save();
|
||||
painter.setPen({Utilities::getNativeWindowFrameColor(), 1});
|
||||
painter.setPen({Utilities::getNativeWindowFrameColor(isActiveWindow()), 1});
|
||||
painter.drawLines(lines);
|
||||
painter.restore();
|
||||
}
|
||||
|
@ -156,7 +157,7 @@ void Widget::setupUi()
|
|||
contentLayout->addWidget(m_label);
|
||||
contentLayout->addStretch();
|
||||
const auto mainLayout = new QVBoxLayout(this);
|
||||
mainLayout->setContentsMargins(1, 1, 1, 1);
|
||||
mainLayout->setContentsMargins(0, 0, 0, 0);
|
||||
mainLayout->setSpacing(0);
|
||||
mainLayout->addLayout(systemButtonLayout);
|
||||
mainLayout->addStretch();
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (C) 2020 by wangwenx190 (Yuhang Zhao)
|
||||
* Copyright (C) 2021 by wangwenx190 (Yuhang Zhao)
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
|
|
|
@ -386,10 +386,16 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me
|
|||
#if 0
|
||||
// Fix the flickering issue while resizing.
|
||||
// "clientRect->right += 1;" also works.
|
||||
// The only draw back of this small trick is it will affect
|
||||
// Qt's coordinate system. It makes the "canvas" of the window
|
||||
// larger than it should be. Be careful if you need to paint
|
||||
// something manually either through QPainter or Qt Quick.
|
||||
// This small technique is known to have two draw backs:
|
||||
// (1) Qt's coordinate system will be confused because the canvas size
|
||||
// doesn't match the client area size so you will get some warnings
|
||||
// from Qt and you should also be careful when you try to draw something
|
||||
// manually through QPainter or in Qt Quick, be aware of the coordinate
|
||||
// mismatch issue when you calculate position yourself.
|
||||
// (2) Qt's window system will take some wrong actions when the window
|
||||
// is being resized. For example, the window size will become 1px smaller
|
||||
// or bigger everytime when resize() is called because the client area size
|
||||
// is not correct. It confuses QPA's internal logic.
|
||||
clientRect->bottom += 1;
|
||||
#endif
|
||||
// If the window bounds change, we're going to relayout and repaint
|
||||
|
|
|
@ -79,19 +79,21 @@ using PROCESS_DPI_AWARENESS = enum _PROCESS_DPI_AWARENESS
|
|||
PROCESS_PER_MONITOR_DPI_AWARE = 2
|
||||
};
|
||||
|
||||
using ShouldAppsUseDarkModePtr = BOOL(WINAPI *)();
|
||||
using ShouldSystemUseDarkModePtr = BOOL(WINAPI *)();
|
||||
|
||||
using GetDpiForMonitorPtr = HRESULT(WINAPI *)(HMONITOR, MONITOR_DPI_TYPE, UINT *, UINT *);
|
||||
using GetProcessDpiAwarenessPtr = HRESULT(WINAPI *)(HANDLE, PROCESS_DPI_AWARENESS *);
|
||||
using GetSystemDpiForProcessPtr = UINT(WINAPI *)(HANDLE);
|
||||
using GetDpiForWindowPtr = UINT(WINAPI *)(HWND);
|
||||
using GetDpiForSystemPtr = UINT(WINAPI *)();
|
||||
using GetSystemMetricsForDpiPtr = int(WINAPI *)(int, UINT);
|
||||
using AdjustWindowRectExForDpiPtr = BOOL(WINAPI *)(LPRECT, DWORD, BOOL, DWORD, UINT);
|
||||
|
||||
using Win32Data = struct _FLH_UTILITIES_WIN32_DATA
|
||||
struct Win32Data
|
||||
{
|
||||
using ShouldAppsUseDarkModePtr = BOOL(WINAPI *)();
|
||||
using ShouldSystemUseDarkModePtr = BOOL(WINAPI *)();
|
||||
|
||||
using GetDpiForMonitorPtr = HRESULT(WINAPI *)(HMONITOR, MONITOR_DPI_TYPE, UINT *, UINT *);
|
||||
using GetProcessDpiAwarenessPtr = HRESULT(WINAPI *)(HANDLE, PROCESS_DPI_AWARENESS *);
|
||||
using GetSystemDpiForProcessPtr = UINT(WINAPI *)(HANDLE);
|
||||
using GetDpiForWindowPtr = UINT(WINAPI *)(HWND);
|
||||
using GetDpiForSystemPtr = UINT(WINAPI *)();
|
||||
using GetSystemMetricsForDpiPtr = int(WINAPI *)(int, UINT);
|
||||
using AdjustWindowRectExForDpiPtr = BOOL(WINAPI *)(LPRECT, DWORD, BOOL, DWORD, UINT);
|
||||
|
||||
|
||||
|
||||
ShouldAppsUseDarkModePtr ShouldAppsUseDarkModePFN = nullptr;
|
||||
ShouldSystemUseDarkModePtr ShouldSystemUseDarkModePFN = nullptr;
|
||||
|
||||
|
@ -103,7 +105,7 @@ using Win32Data = struct _FLH_UTILITIES_WIN32_DATA
|
|||
GetSystemMetricsForDpiPtr GetSystemMetricsForDpiPFN = nullptr;
|
||||
AdjustWindowRectExForDpiPtr AdjustWindowRectExForDpiPFN = nullptr;
|
||||
|
||||
_FLH_UTILITIES_WIN32_DATA()
|
||||
explicit Win32Data()
|
||||
{
|
||||
load();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue