forked from github_mirror/framelesshelper
Minor improvements.
The ignore and draggable areas/objects are limited in the title bar area only. There's no need to judge them outside the title bar area. Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
parent
c4fe56345f
commit
ed6267461c
|
@ -1,7 +1,20 @@
|
|||
#include "framelesshelper.h"
|
||||
#include <QApplication>
|
||||
#include <QScreen>
|
||||
#include <QWidget>
|
||||
|
||||
static void moveWindowToDesktopCenter(QWidget *const widget) {
|
||||
if (widget) {
|
||||
const QRect sg = widget->screen()->geometry();
|
||||
const int sw = sg.width();
|
||||
const int sh = sg.height();
|
||||
const int ww = widget->width();
|
||||
const int wh = widget->height();
|
||||
widget->move(qRound(static_cast<qreal>(sw - ww) / 2.0),
|
||||
qRound(static_cast<qreal>(sh - wh) / 2.0));
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
// High DPI scaling is enabled by default from Qt 6
|
||||
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
|
||||
|
@ -27,6 +40,8 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
QWidget widget;
|
||||
helper.removeWindowFrame(&widget);
|
||||
widget.resize(800, 600);
|
||||
moveWindowToDesktopCenter(&widget);
|
||||
widget.show();
|
||||
|
||||
return QApplication::exec();
|
||||
|
|
|
@ -132,16 +132,19 @@ int main(int argc, char *argv[]) {
|
|||
mainLayout->addLayout(tbLayout);
|
||||
mainLayout->addStretch();
|
||||
widget.setLayout(mainLayout);
|
||||
WinNativeEventFilter::WINDOWDATA data_widget;
|
||||
data_widget.ignoreObjects << minimizeButton << maximizeButton
|
||||
<< closeButton;
|
||||
const auto hWnd_widget = reinterpret_cast<HWND>(widget.winId());
|
||||
WinNativeEventFilter::addFramelessWindow(hWnd_widget);
|
||||
const auto data_widget = WinNativeEventFilter::windowData(hWnd_widget);
|
||||
if (data_widget) {
|
||||
data_widget->ignoreObjects << minimizeButton << maximizeButton
|
||||
<< closeButton;
|
||||
}
|
||||
const int tbh_widget = WinNativeEventFilter::getSystemMetric(
|
||||
hWnd_widget, WinNativeEventFilter::SystemMetric::TitleBarHeight, false);
|
||||
updateQtFrame(widget.windowHandle(),
|
||||
(tbh_widget > 0 ? tbh_widget : m_defaultTitleBarHeight));
|
||||
widget.resize(800, 600);
|
||||
WinNativeEventFilter::addFramelessWindow(hWnd_widget, &data_widget, true);
|
||||
WinNativeEventFilter::moveWindowToDesktopCenter(hWnd_widget);
|
||||
widget.show();
|
||||
|
||||
#ifdef QT_QUICK_LIB
|
||||
|
@ -151,18 +154,17 @@ int main(int argc, char *argv[]) {
|
|||
const int tbh_qml_sys = WinNativeEventFilter::getSystemMetric(
|
||||
hWnd_qml, WinNativeEventFilter::SystemMetric::TitleBarHeight, false);
|
||||
const int tbh_qml = tbh_qml_sys > 0 ? tbh_qml_sys : m_defaultTitleBarHeight;
|
||||
updateQtFrame(&view, tbh_qml);
|
||||
view.rootContext()->setContextProperty(QString::fromUtf8("$TitleBarHeight"),
|
||||
tbh_qml);
|
||||
view.setSource(QUrl(QString::fromUtf8("qrc:///qml/main.qml")));
|
||||
QObject::connect(
|
||||
&view, &MyQuickView::windowSizeChanged, [hWnd_qml](const QSize &size) {
|
||||
const auto data = WinNativeEventFilter::windowData(hWnd_qml);
|
||||
if (data) {
|
||||
const auto data_qml = WinNativeEventFilter::windowData(hWnd_qml);
|
||||
if (data_qml) {
|
||||
const int tbh_qml = WinNativeEventFilter::getSystemMetric(
|
||||
hWnd_qml,
|
||||
WinNativeEventFilter::SystemMetric::TitleBarHeight, false);
|
||||
data->draggableAreas = {
|
||||
data_qml->draggableAreas = {
|
||||
{0, 0, (size.width() - (m_defaultButtonWidth * 3)),
|
||||
tbh_qml}};
|
||||
}
|
||||
|
@ -179,8 +181,10 @@ int main(int argc, char *argv[]) {
|
|||
SLOT(showNormal()));
|
||||
QObject::connect(rootObject, SIGNAL(closeButtonClicked()), &view,
|
||||
SLOT(close()));
|
||||
WinNativeEventFilter::addFramelessWindow(hWnd_qml);
|
||||
updateQtFrame(&view, tbh_qml);
|
||||
view.resize(800, 600);
|
||||
WinNativeEventFilter::addFramelessWindow(hWnd_qml, nullptr, true);
|
||||
WinNativeEventFilter::moveWindowToDesktopCenter(hWnd_qml);
|
||||
view.show();
|
||||
#endif
|
||||
|
||||
|
|
|
@ -1358,15 +1358,12 @@ bool WinNativeEventFilter::nativeEventFilter(const QByteArray &eventType,
|
|||
return HTCLIENT;
|
||||
}
|
||||
const bool isTop = (mouse.y <= bh) && isResizePermitted;
|
||||
const bool isBottom =
|
||||
(mouse.y >= (wh - bh)) && isResizePermitted;
|
||||
const bool isBottom = (mouse.y >= (wh - bh));
|
||||
// Make the border a little wider to let the user easy to resize
|
||||
// on corners.
|
||||
const int factor = (isTop || isBottom) ? 2 : 1;
|
||||
const bool isLeft =
|
||||
(mouse.x <= (bw * factor)) && isResizePermitted;
|
||||
const bool isRight =
|
||||
(mouse.x >= (ww - (bw * factor))) && isResizePermitted;
|
||||
const bool isLeft = (mouse.x <= (bw * factor));
|
||||
const bool isRight = (mouse.x >= (ww - (bw * factor)));
|
||||
const bool fixedSize = _data->windowData.fixedSize;
|
||||
const auto getBorderValue = [fixedSize](int value) -> int {
|
||||
// HTBORDER: non-resizeable window border.
|
||||
|
|
Loading…
Reference in New Issue