1
0
mirror of https://github.com/jaredtao/TaoQuick.git synced 2025-02-06 21:48:24 +08:00

update TaoView

This commit is contained in:
jared 2020-08-07 10:58:37 +08:00
parent d1baadc1d3
commit 681bb0680a
4 changed files with 116 additions and 106 deletions

View File

@ -1,4 +1,6 @@
--- ---
# 关闭格式化
DisableFormat: false
# 语言: None, Cpp, Java, JavaScript, ObjC, Proto, TableGen, TextProto # 语言: None, Cpp, Java, JavaScript, ObjC, Proto, TableGen, TextProto
Language: Cpp Language: Cpp
# BasedOnStyle: WebKit # BasedOnStyle: WebKit
@ -9,7 +11,7 @@ AlignAfterOpenBracket: AlwaysBreak
# 连续赋值时,对齐所有等号 # 连续赋值时,对齐所有等号
AlignConsecutiveAssignments: false AlignConsecutiveAssignments: false
# 连续声明时,对齐所有声明的变量名 # 连续声明时,对齐所有声明的变量名
AlignConsecutiveDeclarations: false AlignConsecutiveDeclarations: true
# 左对齐逃脱换行(使用反斜杠换行)的反斜杠 # 左对齐逃脱换行(使用反斜杠换行)的反斜杠
AlignEscapedNewlines: Right AlignEscapedNewlines: Right
# 水平对齐二元和三元表达式的操作数 # 水平对齐二元和三元表达式的操作数
@ -74,18 +76,18 @@ BraceWrapping:
# 缩进大括号 # 缩进大括号
IndentBraces: false IndentBraces: false
SplitEmptyFunction: true #SplitEmptyFunction: true
SplitEmptyRecord: true #SplitEmptyRecord: true
SplitEmptyNamespace: true #SplitEmptyNamespace: true
# 在二元运算符前换行: None(在操作符后换行), NonAssignment(在非赋值的操作符前换行), All(在操作符前换行) # 在二元运算符前换行: None(在操作符后换行), NonAssignment(在非赋值的操作符前换行), All(在操作符前换行)
BreakBeforeBinaryOperators: All BreakBeforeBinaryOperators: All
# 继承列表的逗号前换行 # 继承列表的逗号前换行
BreakBeforeInheritanceComma: true BreakBeforeInheritanceComma: true
# 继承列表换行 # 继承列表换行
#BreakInheritanceList: BeforeColon BreakInheritanceList: BeforeColon
# 在三元运算符前换行 # 在三元运算符前换行
BreakBeforeTernaryOperators: true BreakBeforeTernaryOperators: true
# 在构造函数的初始化列表的逗号前换行 # 在构造函数的初始化列表的逗号前换行
@ -93,7 +95,7 @@ BreakConstructorInitializersBeforeComma: true
# 初始化列表前换行 # 初始化列表前换行
BreakConstructorInitializers: BeforeComma BreakConstructorInitializers: BeforeComma
# Java注解后换行 # Java注解后换行
BreakAfterJavaFieldAnnotations: false BreakAfterJavaFieldAnnotations: true
BreakStringLiterals: true BreakStringLiterals: true
# 每行字符的限制0表示没有限制 # 每行字符的限制0表示没有限制
@ -103,7 +105,7 @@ CommentPragmas: '^ IWYU pragma:'
# 紧凑 命名空间 # 紧凑 命名空间
CompactNamespaces: false CompactNamespaces: false
# 构造函数的初始化列表要么都在同一行,要么都各自一行 # 构造函数的初始化列表要么都在同一行,要么都各自一行
ConstructorInitializerAllOnOneLineOrOnePerLine: true ConstructorInitializerAllOnOneLineOrOnePerLine: false
# 构造函数的初始化列表的缩进宽度 # 构造函数的初始化列表的缩进宽度
ConstructorInitializerIndentWidth: 4 ConstructorInitializerIndentWidth: 4
# 延续的行的缩进宽度 # 延续的行的缩进宽度
@ -112,8 +114,7 @@ ContinuationIndentWidth: 4
Cpp11BracedListStyle: false Cpp11BracedListStyle: false
# 继承最常用的指针和引用的对齐方式 # 继承最常用的指针和引用的对齐方式
DerivePointerAlignment: false DerivePointerAlignment: false
# 关闭格式化
DisableFormat: false
# 自动检测函数的调用和定义是否被格式为每行一个参数(Experimental) # 自动检测函数的调用和定义是否被格式为每行一个参数(Experimental)
ExperimentalAutoDetectBinPacking: false ExperimentalAutoDetectBinPacking: false
# 固定命名空间注释 # 固定命名空间注释
@ -150,7 +151,7 @@ IndentWrappedFunctionNames: true
JavaScriptQuotes: Leave JavaScriptQuotes: Leave
JavaScriptWrapImports: true JavaScriptWrapImports: true
KeepLineBreaksForNonEmptyLines: false #KeepLineBreaksForNonEmptyLines: false
# 保留在块开始处的空行 # 保留在块开始处的空行
KeepEmptyLinesAtTheStartOfBlocks: true KeepEmptyLinesAtTheStartOfBlocks: true
# 开始一个块的宏的正则表达式 # 开始一个块的宏的正则表达式
@ -230,4 +231,3 @@ TabWidth: 4
# 使用tab字符: Never, ForIndentation, ForContinuationAndIndentation, Always # 使用tab字符: Never, ForIndentation, ForContinuationAndIndentation, Always
UseTab: Never UseTab: Never
... ...

View File

@ -10,6 +10,7 @@ Rectangle {
y: control.height * 1.1 y: control.height * 1.1
color: gConfig.reserverColor color: gConfig.reserverColor
opacity: 0.7 opacity: 0.7
visible: false
Text { Text {
id: t id: t
anchors.centerIn: parent anchors.centerIn: parent
@ -17,6 +18,9 @@ Rectangle {
SequentialAnimation { SequentialAnimation {
id: ani id: ani
alwaysRunToEnd: false alwaysRunToEnd: false
ScriptAction {
script: root.visible = true
}
NumberAnimation { NumberAnimation {
target: root target: root
property: "y" property: "y"
@ -35,6 +39,9 @@ Rectangle {
easing.type: Easing.Linear easing.type: Easing.Linear
to: control.height * 1.1 to: control.height * 1.1
} }
ScriptAction {
script: root.visible = false
}
} }
function notify(msg) { function notify(msg) {

View File

@ -19,37 +19,68 @@
#endif #endif
#ifdef WIN32
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)) {
return HTTOPLEFT;
} 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) {
return HTBOTTOMLEFT;
} 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) {
return HTLEFT;
} else if (x < winrect.right && x >= winrect.right - borderWidth) {
return HTRIGHT;
} else if (y >= winrect.top && y < winrect.top + borderWidth) {
return HTTOP;
} else if (y < winrect.bottom && y >= winrect.bottom - borderWidth) {
return HTBOTTOM;
} else {
return 0;
}
}
#endif
TaoView::TaoView(QWindow* parent) static bool isMaxWin(QWindow *win)
{
return win->windowStates() & Qt::WindowMaximized;
}
static bool isFullWin(QQuickView *win)
{
return win->windowStates() & Qt::WindowFullScreen;
}
TaoView::TaoView(QWindow *parent)
: QQuickView(parent) : QQuickView(parent)
{ {
setFlags(Qt::Window | Qt::FramelessWindowHint | Qt::WindowMinMaxButtonsHint); setFlags(Qt::Window | Qt::FramelessWindowHint | Qt::WindowMinMaxButtonsHint);
setResizeMode(SizeRootObjectToView); setResizeMode(SizeRootObjectToView);
setColor(QColor(Qt::transparent)); setColor(QColor(Qt::transparent));
resize(1440, 900); setMinimumSize({1440, 960});
resize(1440, 960);
#if WIN32 #if WIN32
DWORD style = ::GetWindowLong(HWND(winId()), GWL_STYLE); DWORD style = ::GetWindowLong(HWND(winId()), GWL_STYLE);
style |= WS_MINIMIZEBOX | WS_THICKFRAME | WS_CAPTION; style |= WS_MINIMIZEBOX | WS_THICKFRAME | WS_CAPTION;
::SetWindowLong(HWND(winId()), GWL_STYLE, style); ::SetWindowLong(HWND(winId()), GWL_STYLE, style);
// MARGINS rect{1, 1, -1, -1};
// DwmExtendFrameIntoClientArea(HWND(winId()), &rect);
#endif #endif
setIsMax(windowState() == Qt::WindowMaximized); setIsMax(isMaxWin(this));
connect(this, &QWindow::windowStateChanged, this, [&](Qt::WindowState state){ connect(this, &QWindow::windowStateChanged, this, [&](Qt::WindowState state) { setIsMax(state == Qt::WindowMaximized); });
setIsMax(state == Qt::WindowMaximized);
});
} }
TaoView::~TaoView() TaoView::~TaoView() {}
{
}
void TaoView::moveToScreenCenter() void TaoView::moveToScreenCenter()
{ {
auto screenGeo = qApp->primaryScreen()->geometry(); auto geo = screen()->availableGeometry();
auto viewGeo = geometry(); int w = width();
QPoint centerPos = { (screenGeo.width() - viewGeo.width()) / 2, (screenGeo.height() - viewGeo.height()) / 2 }; int h = height();
setPosition(centerPos); auto pos = QPoint{ geo.x() + (geo.width() - w) / 2, geo.y() + (geo.height() - h) / 2 };
setPosition(pos.x(), pos.y());
update();
} }
void TaoView::setIsMax(bool isMax) void TaoView::setIsMax(bool isMax)
@ -64,22 +95,32 @@ void TaoView::setIsMax(bool isMax)
#if WIN32 #if WIN32
const long border_width = 6; const long border_width = 6;
bool TaoView::nativeEvent(const QByteArray& eventType, void* message, long* result) bool TaoView::nativeEvent(const QByteArray &eventType, void *message, long *result)
{ {
#if (QT_VERSION == QT_VERSION_CHECK(5, 11, 1)) if (!result) {
MSG* msg = *reinterpret_cast<MSG**>(message); return false;
#else }
MSG* msg = reinterpret_cast<MSG*>(message); MSG *msg = reinterpret_cast<MSG *>(message);
#endif if (!msg || (msg && !msg->hwnd)) {
return false;
}
switch (msg->message) { switch (msg->message) {
case WM_NCCALCSIZE: { case WM_NCCALCSIZE: {
NCCALCSIZE_PARAMS& params = *reinterpret_cast<NCCALCSIZE_PARAMS*>(msg->lParam); const auto mode = static_cast<BOOL>(msg->wParam);
if (!(windowStates() & Qt::WindowFullScreen) && !(windowStates() & Qt::WindowMaximized)) { *result = mode ? WVR_REDRAW : 0;
if (params.rgrc[0].top != 0)
params.rgrc[0].top -= 1; const auto clientRect = mode ? &(reinterpret_cast<LPNCCALCSIZE_PARAMS>(msg->lParam)->rgrc[0]) : reinterpret_cast<LPRECT>(msg->lParam);
if (!isMaxWin(this) && !isFullWin(this)) {
if (clientRect->top != 0)
clientRect->top -= 1;
} else if (IsMaximized(HWND(winId()))) {
const int bw = ::GetSystemMetrics(SM_CXSIZEFRAME) + ::GetSystemMetrics(SM_CXPADDEDBORDER);
const int bh = ::GetSystemMetrics(SM_CYSIZEFRAME) + ::GetSystemMetrics(SM_CXPADDEDBORDER);
clientRect->top += bh;
clientRect->bottom -= bh;
clientRect->left += bw;
clientRect->right -= bw;
} }
//this kills the window frame and title bar we added with WS_THICKFRAME and WS_CAPTION
*result = WVR_REDRAW;
return true; return true;
} }
case WM_NCHITTEST: { case WM_NCHITTEST: {
@ -91,55 +132,17 @@ bool TaoView::nativeEvent(const QByteArray& eventType, void* message, long* resu
long x = GET_X_LPARAM(msg->lParam); long x = GET_X_LPARAM(msg->lParam);
long y = GET_Y_LPARAM(msg->lParam); long y = GET_Y_LPARAM(msg->lParam);
bool resizeWidth = minimumWidth() != maximumWidth(); *result = 0;
bool resizeHeight = minimumHeight() != maximumHeight(); if (!isMaxWin(this) && !isFullWin(this)) { //非最大化、非全屏时,进行命中测试,处理边框拖拽
*result = hitTest(winrect, x, y, border_width);
if (resizeWidth) {
//left border
if (x >= winrect.left && x < winrect.left + border_width) {
*result = HTLEFT;
}
//right border
if (x < winrect.right && x >= winrect.right - border_width) {
*result = HTRIGHT;
}
}
if (resizeHeight) {
//bottom border
if (y < winrect.bottom && y >= winrect.bottom - border_width) {
*result = HTBOTTOM;
}
//top border
if (y >= winrect.top && y < winrect.top + border_width) {
*result = HTTOP;
}
}
if (resizeWidth && resizeHeight) {
//bottom left corner
if (x >= winrect.left && x < winrect.left + border_width && y < winrect.bottom && y >= winrect.bottom - border_width) {
*result = HTBOTTOMLEFT;
}
//bottom right corner
if (x < winrect.right && x >= winrect.right - border_width && y < winrect.bottom && y >= winrect.bottom - border_width) {
*result = HTBOTTOMRIGHT;
}
//top left corner
if (x >= winrect.left && x < winrect.left + border_width && y >= winrect.top && y < winrect.top + border_width) {
*result = HTTOPLEFT;
}
//top right corner
if (x < winrect.right && x >= winrect.right - border_width && y >= winrect.top && y < winrect.top + border_width) {
*result = HTTOPRIGHT;
}
}
if (0 != *result) { if (0 != *result) {
return true; return true;
} }
}
double dpr = qApp->devicePixelRatio(); double dpr = qApp->devicePixelRatio();
QPoint pos = mapFromGlobal(QPoint(x/dpr,y/dpr)); QPoint pos = mapFromGlobal(QPoint(x / dpr, y / dpr));
QRect titleRect(border_width, border_width, width() * 0.8, 50); QRect titleRect(border_width, border_width, width() * 0.8, 50);
if (titleRect.contains(pos)) if (titleRect.contains(pos)) {
{
*result = HTCAPTION; *result = HTCAPTION;
return true; return true;
} }

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include <QtGlobal>
#include <QDebug> #include <QDebug>
#include <QtGlobal>
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) #if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
#include <QQmlEngineExtensionPlugin> #include <QQmlEngineExtensionPlugin>