1
0
mirror of https://github.com/jaredtao/TaoQuick.git synced 2025-01-31 21:22:58 +08:00

update 3rdparty

This commit is contained in:
jared 2021-12-04 11:00:16 +08:00
parent 8def3be687
commit 33ff76120e
6 changed files with 124 additions and 60 deletions

View File

@ -5,10 +5,11 @@
#include <QScreen> #include <QScreen>
#include <QWindow> #include <QWindow>
#include <windows.h>
#include <WinUser.h> #include <WinUser.h>
#include <dwmapi.h> #include <dwmapi.h>
#include <objidl.h> // Fixes error C2504: 'IUnknown' : base class undefined #include <objidl.h> // Fixes error C2504: 'IUnknown' : base class undefined
#include <windows.h>
#include <windowsx.h> #include <windowsx.h>
#pragma comment(lib, "Dwmapi.lib") // Adds missing library, fixes error LNK2019: unresolved #pragma comment(lib, "Dwmapi.lib") // Adds missing library, fixes error LNK2019: unresolved
#pragma comment(lib, "User32.lib") #pragma comment(lib, "User32.lib")
@ -18,7 +19,8 @@
// WS_SYSMENU: enables the context menu with the move, close, maximize, minize... commands (shift + right-click on the task bar item) // WS_SYSMENU: enables the context menu with the move, close, maximize, minize... commands (shift + right-click on the task bar item)
// WS_CAPTION: enables aero minimize animation/transition // WS_CAPTION: enables aero minimize animation/transition
// WS_MAXIMIZEBOX, WS_MINIMIZEBOX: enable minimize/maximize // WS_MAXIMIZEBOX, WS_MINIMIZEBOX: enable minimize/maximize
enum class Style : DWORD { enum class Style : DWORD
{
windowed = WS_OVERLAPPEDWINDOW | WS_THICKFRAME | WS_CAPTION | WS_SYSMENU | WS_MAXIMIZEBOX | WS_MINIMIZEBOX, windowed = WS_OVERLAPPEDWINDOW | WS_THICKFRAME | WS_CAPTION | WS_SYSMENU | WS_MAXIMIZEBOX | WS_MINIMIZEBOX,
aero_borderless = WS_POPUP | WS_THICKFRAME | WS_CAPTION | WS_SYSMENU | WS_MAXIMIZEBOX | WS_MINIMIZEBOX, aero_borderless = WS_POPUP | WS_THICKFRAME | WS_CAPTION | WS_SYSMENU | WS_MAXIMIZEBOX | WS_MINIMIZEBOX,
basic_borderless = WS_POPUP | WS_THICKFRAME | WS_SYSMENU | WS_MAXIMIZEBOX | WS_MINIMIZEBOX basic_borderless = WS_POPUP | WS_THICKFRAME | WS_SYSMENU | WS_MAXIMIZEBOX | WS_MINIMIZEBOX
@ -35,7 +37,8 @@ static Style selectBorderLessStyle()
} }
static void setShadow(HWND handle, bool enabled) static void setShadow(HWND handle, bool enabled)
{ {
if (isCompositionEnabled()) { if (isCompositionEnabled())
{
static const MARGINS shadow_state[2] { { 0, 0, 0, 0 }, { 1, 1, 1, 1 } }; static const MARGINS shadow_state[2] { { 0, 0, 0, 0 }, { 1, 1, 1, 1 } };
::DwmExtendFrameIntoClientArea(handle, &shadow_state[enabled]); ::DwmExtendFrameIntoClientArea(handle, &shadow_state[enabled]);
} }
@ -43,23 +46,40 @@ static void setShadow(HWND handle, bool enabled)
static long hitTest(RECT winrect, long x, long y, int borderWidth) static long hitTest(RECT winrect, long x, long y, int borderWidth)
{ {
// 鼠标区域位于窗体边框,进行缩放 // 鼠标区域位于窗体边框,进行缩放
if ((x >= winrect.left) && (x < winrect.left + borderWidth) && (y >= winrect.top) && (y < winrect.top + borderWidth)) { if ((x >= winrect.left) && (x < winrect.left + borderWidth) && (y >= winrect.top) && (y < winrect.top + borderWidth))
{
return HTTOPLEFT; return HTTOPLEFT;
} else if (x < winrect.right && x >= winrect.right - borderWidth && y >= winrect.top && y < winrect.top + borderWidth) { }
else if (x < winrect.right && x >= winrect.right - borderWidth && y >= winrect.top && y < winrect.top + borderWidth)
{
return HTTOPRIGHT; return HTTOPRIGHT;
} else if (x >= winrect.left && x < winrect.left + borderWidth && y < winrect.bottom && y >= winrect.bottom - borderWidth) { }
else if (x >= winrect.left && x < winrect.left + borderWidth && y < winrect.bottom && y >= winrect.bottom - borderWidth)
{
return HTBOTTOMLEFT; return HTBOTTOMLEFT;
} else if (x < winrect.right && x >= winrect.right - borderWidth && y < winrect.bottom && y >= winrect.bottom - borderWidth) { }
else if (x < winrect.right && x >= winrect.right - borderWidth && y < winrect.bottom && y >= winrect.bottom - borderWidth)
{
return HTBOTTOMRIGHT; return HTBOTTOMRIGHT;
} else if (x >= winrect.left && x < winrect.left + borderWidth) { }
else if (x >= winrect.left && x < winrect.left + borderWidth)
{
return HTLEFT; return HTLEFT;
} else if (x < winrect.right && x >= winrect.right - borderWidth) { }
else if (x < winrect.right && x >= winrect.right - borderWidth)
{
return HTRIGHT; return HTRIGHT;
} else if (y >= winrect.top && y < winrect.top + borderWidth) { }
else if (y >= winrect.top && y < winrect.top + borderWidth)
{
return HTTOP; return HTTOP;
} else if (y < winrect.bottom && y >= winrect.bottom - borderWidth) { }
else if (y < winrect.bottom && y >= winrect.bottom - borderWidth)
{
return HTBOTTOM; return HTBOTTOM;
} else { }
else
{
return 0; return 0;
} }
} }
@ -73,7 +93,6 @@ static bool isFullWin(QQuickView *win)
return win->windowState() == Qt::WindowFullScreen; return win->windowState() == Qt::WindowFullScreen;
} }
class TaoFrameLessViewPrivate class TaoFrameLessViewPrivate
{ {
public: public:
@ -87,7 +106,8 @@ public:
{ {
auto newStyle = enabled ? selectBorderLessStyle() : Style::windowed; auto newStyle = enabled ? selectBorderLessStyle() : Style::windowed;
auto oldStyle = static_cast<Style>(::GetWindowLongPtrW(handle, GWL_STYLE)); auto oldStyle = static_cast<Style>(::GetWindowLongPtrW(handle, GWL_STYLE));
if (oldStyle != newStyle) { if (oldStyle != newStyle)
{
borderless = enabled; borderless = enabled;
::SetWindowLongPtrW(handle, GWL_STYLE, static_cast<LONG>(newStyle)); ::SetWindowLongPtrW(handle, GWL_STYLE, static_cast<LONG>(newStyle));
@ -101,13 +121,16 @@ public:
} }
void setBorderLessShadow(HWND handle, bool enabled) void setBorderLessShadow(HWND handle, bool enabled)
{ {
if (borderless) { if (borderless)
{
borderless_shadow = enabled; borderless_shadow = enabled;
setShadow(handle, enabled); setShadow(handle, enabled);
} }
} }
}; };
TaoFrameLessView::TaoFrameLessView(QWindow *parent) : QQuickView(parent), d(new TaoFrameLessViewPrivate) TaoFrameLessView::TaoFrameLessView(QWindow* parent)
: QQuickView(parent)
, d(new TaoFrameLessViewPrivate)
{ {
setFlags(Qt::CustomizeWindowHint | Qt::Window | Qt::FramelessWindowHint | Qt::WindowMinMaxButtonsHint | Qt::WindowTitleHint | Qt::WindowSystemMenuHint); setFlags(Qt::CustomizeWindowHint | Qt::Window | Qt::FramelessWindowHint | Qt::WindowMinMaxButtonsHint | Qt::WindowTitleHint | Qt::WindowSystemMenuHint);
setResizeMode(SizeRootObjectToView); setResizeMode(SizeRootObjectToView);
@ -141,11 +164,13 @@ QRect TaoFrameLessView::calcCenterGeo(const QRect &screenGeo, const QSize &norma
int h = normalSize.height(); int h = normalSize.height();
int x = screenGeo.x() + (screenGeo.width() - w) / 2; int x = screenGeo.x() + (screenGeo.width() - w) / 2;
int y = screenGeo.y() + (screenGeo.height() - h) / 2; int y = screenGeo.y() + (screenGeo.height() - h) / 2;
if (screenGeo.width() < w) { if (screenGeo.width() < w)
{
x = screenGeo.x(); x = screenGeo.x();
w = screenGeo.width(); w = screenGeo.width();
} }
if (screenGeo.height() < h) { if (screenGeo.height() < h)
{
y = screenGeo.y(); y = screenGeo.y();
h = screenGeo.height(); h = screenGeo.height();
} }
@ -155,7 +180,8 @@ QRect TaoFrameLessView::calcCenterGeo(const QRect &screenGeo, const QSize &norma
void TaoFrameLessView::moveToScreenCenter() void TaoFrameLessView::moveToScreenCenter()
{ {
auto geo = calcCenterGeo(screen()->availableGeometry(), size()); auto geo = calcCenterGeo(screen()->availableGeometry(), size());
if (minimumWidth() > geo.width() || minimumHeight() > geo.height()) { if (minimumWidth() > geo.width() || minimumHeight() > geo.height())
{
setMinimumSize(geo.size()); setMinimumSize(geo.size());
} }
setGeometry(geo); setGeometry(geo);
@ -173,13 +199,10 @@ void TaoFrameLessView::setIsMax(bool isMax)
void TaoFrameLessView::resizeEvent(QResizeEvent* e) void TaoFrameLessView::resizeEvent(QResizeEvent* e)
{ {
// SetWindowRgn(HWND(winId()), //SetWindowRgn(HWND(winId()), CreateRoundRectRgn(0, 0, width(), height(), 4, 4), true);
// CreateRoundRectRgn(0, 0, width(), height(), 4, 4),
// true);
Super::resizeEvent(e); Super::resizeEvent(e);
} }
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
bool TaoFrameLessView::nativeEvent(const QByteArray& eventType, void* message, qintptr* result) bool TaoFrameLessView::nativeEvent(const QByteArray& eventType, void* message, qintptr* result)
#else #else
@ -188,7 +211,8 @@ bool TaoFrameLessView::nativeEvent(const QByteArray &eventType, void *message, l
{ {
const long border_width = 4; const long border_width = 4;
if (!result) { if (!result)
{
//防御式编程 //防御式编程
//一般不会发生这种情况win7一些极端情况会传空指针进来。解决方案是升级驱动、切换到basic主题。 //一般不会发生这种情况win7一些极端情况会传空指针进来。解决方案是升级驱动、切换到basic主题。
return false; return false;
@ -201,22 +225,30 @@ bool TaoFrameLessView::nativeEvent(const QByteArray &eventType, void *message, l
const auto msg = static_cast<LPMSG>(message); const auto msg = static_cast<LPMSG>(message);
#endif #endif
if (!msg || !msg->hwnd) { if (!msg || !msg->hwnd)
{
return false; return false;
} }
switch (msg->message) { switch (msg->message)
{
case WM_NCCALCSIZE: { case WM_NCCALCSIZE: {
const auto mode = static_cast<BOOL>(msg->wParam); const auto mode = static_cast<BOOL>(msg->wParam);
const auto clientRect = mode ? &(reinterpret_cast<LPNCCALCSIZE_PARAMS>(msg->lParam)->rgrc[0]) : reinterpret_cast<LPRECT>(msg->lParam); const auto clientRect = mode ? &(reinterpret_cast<LPNCCALCSIZE_PARAMS>(msg->lParam)->rgrc[0]) : reinterpret_cast<LPRECT>(msg->lParam);
if (mode == TRUE && d->borderless) { if (mode == TRUE && d->borderless)
{
*result = WVR_REDRAW; *result = WVR_REDRAW;
//规避 拖动border进行resize时界面闪烁 //规避 拖动border进行resize时界面闪烁
if (!isMaxWin(this) && !isFullWin(this)) { if (!isMaxWin(this) && !isFullWin(this))
if (clientRect->top != 0) { {
if (clientRect->top != 0)
{
clientRect->top -= 0.1; clientRect->top -= 0.1;
} }
} else { }
if (clientRect->top != 0) { else
{
if (clientRect->top != 0)
{
clientRect->top += 0.1; clientRect->top += 0.1;
} }
} }
@ -225,7 +257,8 @@ bool TaoFrameLessView::nativeEvent(const QByteArray &eventType, void *message, l
break; break;
} }
case WM_NCACTIVATE: { case WM_NCACTIVATE: {
if (!isCompositionEnabled()) { if (!isCompositionEnabled())
{
// Prevents window frame reappearing on window activation // Prevents window frame reappearing on window activation
// in "basic" theme, where no aero shadow is present. // in "basic" theme, where no aero shadow is present.
*result = 1; *result = 1;
@ -234,7 +267,8 @@ bool TaoFrameLessView::nativeEvent(const QByteArray &eventType, void *message, l
break; break;
} }
case WM_NCHITTEST: { case WM_NCHITTEST: {
if (d->borderless) { if (d->borderless)
{
RECT winrect; RECT winrect;
GetWindowRect(HWND(winId()), &winrect); GetWindowRect(HWND(winId()), &winrect);
@ -242,20 +276,24 @@ bool TaoFrameLessView::nativeEvent(const QByteArray &eventType, void *message, l
long y = GET_Y_LPARAM(msg->lParam); long y = GET_Y_LPARAM(msg->lParam);
*result = 0; *result = 0;
if (!isMaxWin(this) && !isFullWin(this)) { //非最大化、非全屏时,进行命中测试,处理边框拖拽 if (!isMaxWin(this) && !isFullWin(this))
{ //非最大化、非全屏时,进行命中测试,处理边框拖拽
*result = hitTest(winrect, x, y, border_width); *result = hitTest(winrect, x, y, border_width);
if (0 != *result) { if (0 != *result)
{
return true; return true;
} }
} }
if (d->m_titleItem) { if (d->m_titleItem)
{
auto titlePos = d->m_titleItem->mapToGlobal({ 0, 0 }); auto titlePos = d->m_titleItem->mapToGlobal({ 0, 0 });
titlePos = mapFromGlobal(titlePos.toPoint()); titlePos = mapFromGlobal(titlePos.toPoint());
auto titleRect = QRect(titlePos.x(), titlePos.y(), d->m_titleItem->width(), d->m_titleItem->height()); auto titleRect = QRect(titlePos.x(), titlePos.y(), d->m_titleItem->width(), d->m_titleItem->height());
double dpr = qApp->devicePixelRatio(); double dpr = qApp->devicePixelRatio();
QPoint pos = mapFromGlobal(QPoint(x / dpr, y / dpr)); QPoint pos = mapFromGlobal(QPoint(x / dpr, y / dpr));
if (titleRect.contains(pos)) { if (titleRect.contains(pos))
{
*result = HTCAPTION; *result = HTCAPTION;
return true; return true;
} }

View File

@ -226,7 +226,7 @@ void QuickModelBase<T>::subtract(const QSet<T> &other)
return; return;
beginResetModel(); beginResetModel();
mAllDatas.subtract(other); mAllDatas.subtract(other);
mDatas = mAllDatas.toList(); mDatas = mAllDatas.values();
endResetModel(); endResetModel();
qDeleteAll(other); qDeleteAll(other);
updateCalcInfo(); updateCalcInfo();

View File

@ -12,3 +12,5 @@ CONFIG += build_TaoCommon_lib
DEFINES += TaoCommon_Library DEFINES += TaoCommon_Library
include(TaoCommon.pri) include(TaoCommon.pri)
include(TaoCommonInstall.pri)

View File

@ -0,0 +1,31 @@
headersTargetPath=$$[QT_INSTALL_HEADERS]/$$MODULE_INCNAME
message("QMAKE_INSTALL_DIR $$headersTargetPath")
gHeader.files=$$PWD/TaoCommonGlobal.h
gHeader.path=$$headersTargetPath
commonHeader.files=$$PWD/Common/*.h
commonHeader.path=$$headersTargetPath/Common
framelessHeader.files=$$PWD/Frameless/*.h
framelessHeader.path=$$headersTargetPath/Frameless
loggerHeader.files=$$PWD/Logger/*.h
loggerHeader.path=$$headersTargetPath/Logger
quickModelHeader.files=$$PWD/QuickModel/*.h
quickModelHeader.path=$$headersTargetPath/QuickModel
quickToolHeader.files=$$PWD/QuickTool/*.h
quickToolHeader.path=$$headersTargetPath/QuickTool
threadHeader.files=$$PWD/Thread/*.h
threadHeader.path=$$headersTargetPath/Thread
transHeader.files=$$PWD/Trans/*.h
transHeader.path=$$headersTargetPath/Trans
INSTALLS += \
gHeader commonHeader framelessHeader loggerHeader quickModelHeader \
quickToolHeader threadHeader transHeader

View File

@ -135,12 +135,5 @@ Rectangle {
Component.onCompleted: { Component.onCompleted: {
view.setTitleItem(blankItem) view.setTitleItem(blankItem)
} }
MoveArea {
anchors.fill: parent
onMove: {
view.x += xOffset
view.y += yOffset
}
}
} }
} }

View File

@ -80,7 +80,7 @@ int main(int argc, char **argv)
view.rootContext()->setContextProperty("deviceAddModel", &model); view.rootContext()->setContextProperty("deviceAddModel", &model);
const QUrl url(qmlPath + QStringLiteral("main.qml")); const QUrl url(qmlPath + QStringLiteral("main.qml"));
QObject::connect(&view, &QQuickView::statusChanged, [&](QQuickView::Status status) { QObject::connect(&view, &QQuickView::statusChanged, &view, [&](QQuickView::Status status) {
if (status == QQuickView::Status::Ready) { if (status == QQuickView::Status::Ready) {
trans.afterUiReady(); trans.afterUiReady();
appInfo.afterUiReady(); appInfo.afterUiReady();