1
0
mirror of https://github.com/jaredtao/TaoQuick.git synced 2025-01-17 20:12:54 +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 <QWindow>
#include <windows.h>
#include <WinUser.h>
#include <dwmapi.h>
#include <objidl.h> // Fixes error C2504: 'IUnknown' : base class undefined
#include <windows.h>
#include <windowsx.h>
#pragma comment(lib, "Dwmapi.lib") // Adds missing library, fixes error LNK2019: unresolved
#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_CAPTION: enables aero minimize animation/transition
// 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,
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
@ -35,7 +37,8 @@ static Style selectBorderLessStyle()
}
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 } };
::DwmExtendFrameIntoClientArea(handle, &shadow_state[enabled]);
}
@ -43,51 +46,68 @@ static void setShadow(HWND handle, bool enabled)
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;
} 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;
} 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;
} 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;
} else if (x >= winrect.left && x < winrect.left + borderWidth) {
}
else if (x >= winrect.left && x < winrect.left + borderWidth)
{
return HTLEFT;
} else if (x < winrect.right && x >= winrect.right - borderWidth) {
}
else if (x < winrect.right && x >= winrect.right - borderWidth)
{
return HTRIGHT;
} else if (y >= winrect.top && y < winrect.top + borderWidth) {
}
else if (y >= winrect.top && y < winrect.top + borderWidth)
{
return HTTOP;
} else if (y < winrect.bottom && y >= winrect.bottom - borderWidth) {
}
else if (y < winrect.bottom && y >= winrect.bottom - borderWidth)
{
return HTBOTTOM;
} else {
}
else
{
return 0;
}
}
static bool isMaxWin(QWindow *win)
static bool isMaxWin(QWindow* win)
{
return win->windowState() == Qt::WindowMaximized;
}
static bool isFullWin(QQuickView *win)
static bool isFullWin(QQuickView* win)
{
return win->windowState() == Qt::WindowFullScreen;
}
class TaoFrameLessViewPrivate
{
public:
bool m_isMax;
QQuickItem *m_titleItem = nullptr;
bool borderless = true; // is the window currently borderless
QQuickItem* m_titleItem = nullptr;
bool borderless = true; // is the window currently borderless
bool borderless_resize = true; // should the window allow resizing by dragging the borders while borderless
bool borderless_drag = true; // should the window allow moving my dragging the client area
bool borderless_drag = true; // should the window allow moving my dragging the client area
bool borderless_shadow = true; // should the window display a native aero shadow while borderless
void setBorderLess(HWND handle, bool enabled)
{
auto newStyle = enabled ? selectBorderLessStyle() : Style::windowed;
auto oldStyle = static_cast<Style>(::GetWindowLongPtrW(handle, GWL_STYLE));
if (oldStyle != newStyle) {
if (oldStyle != newStyle)
{
borderless = enabled;
::SetWindowLongPtrW(handle, GWL_STYLE, static_cast<LONG>(newStyle));
@ -101,18 +121,21 @@ public:
}
void setBorderLessShadow(HWND handle, bool enabled)
{
if (borderless) {
if (borderless)
{
borderless_shadow = 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);
setResizeMode(SizeRootObjectToView);
d->setBorderLess((HWND)(winId()), d->borderless);
d->setBorderLess((HWND)(winId()), d->borderless);
d->setBorderLessShadow((HWND)(winId()), d->borderless_shadow);
setIsMax(isMaxWin(this));
@ -127,25 +150,27 @@ bool TaoFrameLessView::isMax() const
{
return d->m_isMax;
}
QQuickItem *TaoFrameLessView::titleItem() const
QQuickItem* TaoFrameLessView::titleItem() const
{
return d->m_titleItem;
}
void TaoFrameLessView::setTitleItem(QQuickItem *item)
void TaoFrameLessView::setTitleItem(QQuickItem* item)
{
d->m_titleItem = item;
}
QRect TaoFrameLessView::calcCenterGeo(const QRect &screenGeo, const QSize &normalSize)
QRect TaoFrameLessView::calcCenterGeo(const QRect& screenGeo, const QSize& normalSize)
{
int w = normalSize.width();
int h = normalSize.height();
int x = screenGeo.x() + (screenGeo.width() - w) / 2;
int y = screenGeo.y() + (screenGeo.height() - h) / 2;
if (screenGeo.width() < w) {
if (screenGeo.width() < w)
{
x = screenGeo.x();
w = screenGeo.width();
}
if (screenGeo.height() < h) {
if (screenGeo.height() < h)
{
y = screenGeo.y();
h = screenGeo.height();
}
@ -155,7 +180,8 @@ QRect TaoFrameLessView::calcCenterGeo(const QRect &screenGeo, const QSize &norma
void TaoFrameLessView::moveToScreenCenter()
{
auto geo = calcCenterGeo(screen()->availableGeometry(), size());
if (minimumWidth() > geo.width() || minimumHeight() > geo.height()) {
if (minimumWidth() > geo.width() || minimumHeight() > geo.height())
{
setMinimumSize(geo.size());
}
setGeometry(geo);
@ -171,24 +197,22 @@ void TaoFrameLessView::setIsMax(bool isMax)
emit isMaxChanged(d->m_isMax);
}
void TaoFrameLessView::resizeEvent(QResizeEvent *e)
void TaoFrameLessView::resizeEvent(QResizeEvent* e)
{
// SetWindowRgn(HWND(winId()),
// CreateRoundRectRgn(0, 0, width(), height(), 4, 4),
// true);
//SetWindowRgn(HWND(winId()), CreateRoundRectRgn(0, 0, width(), height(), 4, 4), true);
Super::resizeEvent(e);
}
#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
bool TaoFrameLessView::nativeEvent(const QByteArray &eventType, void *message, long *result)
bool TaoFrameLessView::nativeEvent(const QByteArray& eventType, void* message, long* result)
#endif
{
const long border_width = 4;
if (!result) {
if (!result)
{
//防御式编程
//一般不会发生这种情况win7一些极端情况会传空指针进来。解决方案是升级驱动、切换到basic主题。
return false;
@ -196,27 +220,35 @@ bool TaoFrameLessView::nativeEvent(const QByteArray &eventType, void *message, l
#if (QT_VERSION == QT_VERSION_CHECK(5, 11, 1))
// Work-around a bug caused by typo which only exists in Qt 5.11.1
const auto msg = *reinterpret_cast<MSG **>(message);
const auto msg = *reinterpret_cast<MSG**>(message);
#else
const auto msg = static_cast<LPMSG>(message);
#endif
if (!msg || !msg->hwnd) {
if (!msg || !msg->hwnd)
{
return false;
}
switch (msg->message) {
switch (msg->message)
{
case WM_NCCALCSIZE: {
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);
if (mode == TRUE && d->borderless) {
if (mode == TRUE && d->borderless)
{
*result = WVR_REDRAW;
//规避 拖动border进行resize时界面闪烁
if (!isMaxWin(this) && !isFullWin(this)) {
if (clientRect->top != 0) {
if (!isMaxWin(this) && !isFullWin(this))
{
if (clientRect->top != 0)
{
clientRect->top -= 0.1;
}
} else {
if (clientRect->top != 0) {
}
else
{
if (clientRect->top != 0)
{
clientRect->top += 0.1;
}
}
@ -225,7 +257,8 @@ bool TaoFrameLessView::nativeEvent(const QByteArray &eventType, void *message, l
break;
}
case WM_NCACTIVATE: {
if (!isCompositionEnabled()) {
if (!isCompositionEnabled())
{
// Prevents window frame reappearing on window activation
// in "basic" theme, where no aero shadow is present.
*result = 1;
@ -234,7 +267,8 @@ bool TaoFrameLessView::nativeEvent(const QByteArray &eventType, void *message, l
break;
}
case WM_NCHITTEST: {
if (d->borderless) {
if (d->borderless)
{
RECT 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);
*result = 0;
if (!isMaxWin(this) && !isFullWin(this)) { //非最大化、非全屏时,进行命中测试,处理边框拖拽
if (!isMaxWin(this) && !isFullWin(this))
{ //非最大化、非全屏时,进行命中测试,处理边框拖拽
*result = hitTest(winrect, x, y, border_width);
if (0 != *result) {
if (0 != *result)
{
return true;
}
}
if (d->m_titleItem) {
auto titlePos = d->m_titleItem->mapToGlobal({0, 0});
if (d->m_titleItem)
{
auto titlePos = d->m_titleItem->mapToGlobal({ 0, 0 });
titlePos = mapFromGlobal(titlePos.toPoint());
auto titleRect = QRect(titlePos.x(), titlePos.y(), d->m_titleItem->width(), d->m_titleItem->height());
double dpr = qApp->devicePixelRatio();
QPoint pos = mapFromGlobal(QPoint(x / dpr, y / dpr));
if (titleRect.contains(pos)) {
if (titleRect.contains(pos))
{
*result = HTCAPTION;
return true;
}

View File

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

View File

@ -12,3 +12,5 @@ CONFIG += build_TaoCommon_lib
DEFINES += TaoCommon_Library
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: {
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);
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) {
trans.afterUiReady();
appInfo.afterUiReady();