Minor tweaks

Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
Yuhang Zhao 2021-06-09 13:27:11 +08:00
parent 938756a757
commit 28144b1e74
13 changed files with 48 additions and 36 deletions

View File

@ -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(widget)
add_subdirectory(mainwindow) add_subdirectory(mainwindow)
#endif() endif()
if(TARGET Qt${QT_VERSION_MAJOR}::Quick) if(TARGET Qt${QT_VERSION_MAJOR}::Quick)
add_subdirectory(quick) add_subdirectory(quick)
endif() endif()

View File

@ -5,7 +5,7 @@ DEFINES += \
QT_NO_CAST_TO_ASCII \ QT_NO_CAST_TO_ASCII \
QT_NO_KEYWORDS \ QT_NO_KEYWORDS \
QT_DEPRECATED_WARNINGS \ QT_DEPRECATED_WARNINGS \
QT_DISABLE_DEPRECATED_BEFORE=0x060000 QT_DISABLE_DEPRECATED_BEFORE=0x060100
RESOURCES += $$PWD/images.qrc RESOURCES += $$PWD/images.qrc
win32 { win32 {
DEFINES += \ DEFINES += \

View File

@ -33,7 +33,7 @@ target_compile_definitions(MainWindow PRIVATE
QT_NO_CAST_TO_ASCII QT_NO_CAST_TO_ASCII
QT_NO_KEYWORDS QT_NO_KEYWORDS
QT_DEPRECATED_WARNINGS QT_DEPRECATED_WARNINGS
QT_DISABLE_DEPRECATED_BEFORE=0x060000 QT_DISABLE_DEPRECATED_BEFORE=0x060100
) )
if(MSVC) if(MSVC)

View File

@ -56,7 +56,6 @@ MainWindow::MainWindow(QWidget *parent, Qt::WindowFlags flags) : QMainWindow(par
titleBarWidget->maximizeButton->setChecked(isMaximized()); titleBarWidget->maximizeButton->setChecked(isMaximized());
titleBarWidget->maximizeButton->setToolTip(isMaximized() ? tr("Restore") : tr("Maximize")); titleBarWidget->maximizeButton->setToolTip(isMaximized() ? tr("Restore") : tr("Maximize"));
}); });
//connect(titleBarWidget->iconButton, &QPushButton::clicked, this, &MainWindow::displaySystemMenu);
} }
MainWindow::~MainWindow() MainWindow::~MainWindow()
@ -84,8 +83,8 @@ void MainWindow::showEvent(QShowEvent *event)
FramelessWindowsManager::setHitTestVisibleInChrome(win, titleBarWidget->maximizeButton, true); FramelessWindowsManager::setHitTestVisibleInChrome(win, titleBarWidget->maximizeButton, true);
FramelessWindowsManager::setHitTestVisibleInChrome(win, titleBarWidget->closeButton, true); FramelessWindowsManager::setHitTestVisibleInChrome(win, titleBarWidget->closeButton, true);
FramelessWindowsManager::setHitTestVisibleInChrome(win, appMainWindow->menubar, true); FramelessWindowsManager::setHitTestVisibleInChrome(win, appMainWindow->menubar, true);
inited = true;
setContentsMargins(1, 1, 1, 1); setContentsMargins(1, 1, 1, 1);
inited = true;
} }
} }
} }
@ -129,7 +128,7 @@ void MainWindow::paintEvent(QPaintEvent *event)
{0, h, 0, 0} {0, h, 0, 0}
}; };
painter.save(); painter.save();
painter.setPen({Utilities::getNativeWindowFrameColor(), 1}); painter.setPen({Utilities::getNativeWindowFrameColor(isActiveWindow()), 1});
painter.drawLines(lines); painter.drawLines(lines);
painter.restore(); painter.restore();
} }

View File

@ -31,7 +31,7 @@ target_compile_definitions(Quick PRIVATE
QT_NO_CAST_TO_ASCII QT_NO_CAST_TO_ASCII
QT_NO_KEYWORDS QT_NO_KEYWORDS
QT_DEPRECATED_WARNINGS QT_DEPRECATED_WARNINGS
QT_DISABLE_DEPRECATED_BEFORE=0x060000 QT_DISABLE_DEPRECATED_BEFORE=0x060100
) )
if(MSVC) if(MSVC)

View File

@ -1,7 +1,7 @@
/* /*
* MIT License * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal

View File

@ -1,7 +1,7 @@
/* /*
* MIT License * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal

View File

@ -1,7 +1,7 @@
/* /*
* MIT License * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal

View File

@ -31,7 +31,7 @@ target_compile_definitions(Widget PRIVATE
QT_NO_CAST_TO_ASCII QT_NO_CAST_TO_ASCII
QT_NO_KEYWORDS QT_NO_KEYWORDS
QT_DEPRECATED_WARNINGS QT_DEPRECATED_WARNINGS
QT_DISABLE_DEPRECATED_BEFORE=0x060000 QT_DISABLE_DEPRECATED_BEFORE=0x060100
) )
if(MSVC) if(MSVC)

View File

@ -23,7 +23,7 @@
*/ */
#include "widget.h" #include "widget.h"
#include <QtWidgets/qlayout.h> #include <QtWidgets/qboxlayout.h>
#include <QtWidgets/qlabel.h> #include <QtWidgets/qlabel.h>
#include <QtCore/qdatetime.h> #include <QtCore/qdatetime.h>
#include <QtWidgets/qpushbutton.h> #include <QtWidgets/qpushbutton.h>
@ -51,6 +51,7 @@ void Widget::showEvent(QShowEvent *event)
FramelessWindowsManager::setHitTestVisibleInChrome(win, m_minimizeButton, true); FramelessWindowsManager::setHitTestVisibleInChrome(win, m_minimizeButton, true);
FramelessWindowsManager::setHitTestVisibleInChrome(win, m_maximizeButton, true); FramelessWindowsManager::setHitTestVisibleInChrome(win, m_maximizeButton, true);
FramelessWindowsManager::setHitTestVisibleInChrome(win, m_closeButton, true); FramelessWindowsManager::setHitTestVisibleInChrome(win, m_closeButton, true);
setContentsMargins(1, 1, 1, 1);
inited = true; inited = true;
} }
} }
@ -67,10 +68,10 @@ void Widget::changeEvent(QEvent *event)
bool shouldUpdate = false; bool shouldUpdate = false;
if (event->type() == QEvent::WindowStateChange) { if (event->type() == QEvent::WindowStateChange) {
if (isMaximized() || isFullScreen()) { if (isMaximized() || isFullScreen()) {
layout()->setContentsMargins(0, 0, 0, 0); setContentsMargins(0, 0, 0, 0);
m_maximizeButton->setIcon(QIcon{QStringLiteral(":/images/button_restore_black.svg")}); m_maximizeButton->setIcon(QIcon{QStringLiteral(":/images/button_restore_black.svg")});
} else if (!isMinimized()) { } else if (!isMinimized()) {
layout()->setContentsMargins(1, 1, 1, 1); setContentsMargins(1, 1, 1, 1);
m_maximizeButton->setIcon(QIcon{QStringLiteral(":/images/button_maximize_black.svg")}); m_maximizeButton->setIcon(QIcon{QStringLiteral(":/images/button_maximize_black.svg")});
} }
shouldUpdate = true; shouldUpdate = true;
@ -101,7 +102,7 @@ void Widget::paintEvent(QPaintEvent *event)
{0, h, 0, 0} {0, h, 0, 0}
}; };
painter.save(); painter.save();
painter.setPen({Utilities::getNativeWindowFrameColor(), 1}); painter.setPen({Utilities::getNativeWindowFrameColor(isActiveWindow()), 1});
painter.drawLines(lines); painter.drawLines(lines);
painter.restore(); painter.restore();
} }
@ -156,7 +157,7 @@ void Widget::setupUi()
contentLayout->addWidget(m_label); contentLayout->addWidget(m_label);
contentLayout->addStretch(); contentLayout->addStretch();
const auto mainLayout = new QVBoxLayout(this); const auto mainLayout = new QVBoxLayout(this);
mainLayout->setContentsMargins(1, 1, 1, 1); mainLayout->setContentsMargins(0, 0, 0, 0);
mainLayout->setSpacing(0); mainLayout->setSpacing(0);
mainLayout->addLayout(systemButtonLayout); mainLayout->addLayout(systemButtonLayout);
mainLayout->addStretch(); mainLayout->addStretch();

View File

@ -1,7 +1,7 @@
/* /*
* MIT License * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal

View File

@ -386,10 +386,16 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me
#if 0 #if 0
// Fix the flickering issue while resizing. // Fix the flickering issue while resizing.
// "clientRect->right += 1;" also works. // "clientRect->right += 1;" also works.
// The only draw back of this small trick is it will affect // This small technique is known to have two draw backs:
// Qt's coordinate system. It makes the "canvas" of the window // (1) Qt's coordinate system will be confused because the canvas size
// larger than it should be. Be careful if you need to paint // doesn't match the client area size so you will get some warnings
// something manually either through QPainter or Qt Quick. // 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; clientRect->bottom += 1;
#endif #endif
// If the window bounds change, we're going to relayout and repaint // If the window bounds change, we're going to relayout and repaint

View File

@ -79,19 +79,21 @@ using PROCESS_DPI_AWARENESS = enum _PROCESS_DPI_AWARENESS
PROCESS_PER_MONITOR_DPI_AWARE = 2 PROCESS_PER_MONITOR_DPI_AWARE = 2
}; };
using ShouldAppsUseDarkModePtr = BOOL(WINAPI *)(); struct Win32Data
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
{ {
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; ShouldAppsUseDarkModePtr ShouldAppsUseDarkModePFN = nullptr;
ShouldSystemUseDarkModePtr ShouldSystemUseDarkModePFN = nullptr; ShouldSystemUseDarkModePtr ShouldSystemUseDarkModePFN = nullptr;
@ -103,7 +105,7 @@ using Win32Data = struct _FLH_UTILITIES_WIN32_DATA
GetSystemMetricsForDpiPtr GetSystemMetricsForDpiPFN = nullptr; GetSystemMetricsForDpiPtr GetSystemMetricsForDpiPFN = nullptr;
AdjustWindowRectExForDpiPtr AdjustWindowRectExForDpiPFN = nullptr; AdjustWindowRectExForDpiPtr AdjustWindowRectExForDpiPFN = nullptr;
_FLH_UTILITIES_WIN32_DATA() explicit Win32Data()
{ {
load(); load();
} }