mirror of
https://github.com/jaredtao/TaoQuick.git
synced 2025-01-31 21:22:58 +08:00
update TaoView
This commit is contained in:
parent
d1baadc1d3
commit
681bb0680a
@ -1,4 +1,6 @@
|
||||
---
|
||||
# 关闭格式化
|
||||
DisableFormat: false
|
||||
# 语言: None, Cpp, Java, JavaScript, ObjC, Proto, TableGen, TextProto
|
||||
Language: Cpp
|
||||
# BasedOnStyle: WebKit
|
||||
@ -9,7 +11,7 @@ AlignAfterOpenBracket: AlwaysBreak
|
||||
# 连续赋值时,对齐所有等号
|
||||
AlignConsecutiveAssignments: false
|
||||
# 连续声明时,对齐所有声明的变量名
|
||||
AlignConsecutiveDeclarations: false
|
||||
AlignConsecutiveDeclarations: true
|
||||
# 左对齐逃脱换行(使用反斜杠换行)的反斜杠
|
||||
AlignEscapedNewlines: Right
|
||||
# 水平对齐二元和三元表达式的操作数
|
||||
@ -74,18 +76,18 @@ BraceWrapping:
|
||||
# 缩进大括号
|
||||
IndentBraces: false
|
||||
|
||||
SplitEmptyFunction: true
|
||||
#SplitEmptyFunction: true
|
||||
|
||||
SplitEmptyRecord: true
|
||||
#SplitEmptyRecord: true
|
||||
|
||||
SplitEmptyNamespace: true
|
||||
#SplitEmptyNamespace: true
|
||||
# 在二元运算符前换行: None(在操作符后换行), NonAssignment(在非赋值的操作符前换行), All(在操作符前换行)
|
||||
BreakBeforeBinaryOperators: All
|
||||
|
||||
# 继承列表的逗号前换行
|
||||
BreakBeforeInheritanceComma: true
|
||||
# 继承列表换行
|
||||
#BreakInheritanceList: BeforeColon
|
||||
BreakInheritanceList: BeforeColon
|
||||
# 在三元运算符前换行
|
||||
BreakBeforeTernaryOperators: true
|
||||
# 在构造函数的初始化列表的逗号前换行
|
||||
@ -93,7 +95,7 @@ BreakConstructorInitializersBeforeComma: true
|
||||
# 初始化列表前换行
|
||||
BreakConstructorInitializers: BeforeComma
|
||||
# Java注解后换行
|
||||
BreakAfterJavaFieldAnnotations: false
|
||||
BreakAfterJavaFieldAnnotations: true
|
||||
|
||||
BreakStringLiterals: true
|
||||
# 每行字符的限制,0表示没有限制
|
||||
@ -103,7 +105,7 @@ CommentPragmas: '^ IWYU pragma:'
|
||||
# 紧凑 命名空间
|
||||
CompactNamespaces: false
|
||||
# 构造函数的初始化列表要么都在同一行,要么都各自一行
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: true
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: false
|
||||
# 构造函数的初始化列表的缩进宽度
|
||||
ConstructorInitializerIndentWidth: 4
|
||||
# 延续的行的缩进宽度
|
||||
@ -112,8 +114,7 @@ ContinuationIndentWidth: 4
|
||||
Cpp11BracedListStyle: false
|
||||
# 继承最常用的指针和引用的对齐方式
|
||||
DerivePointerAlignment: false
|
||||
# 关闭格式化
|
||||
DisableFormat: false
|
||||
|
||||
# 自动检测函数的调用和定义是否被格式为每行一个参数(Experimental)
|
||||
ExperimentalAutoDetectBinPacking: false
|
||||
# 固定命名空间注释
|
||||
@ -150,7 +151,7 @@ IndentWrappedFunctionNames: true
|
||||
JavaScriptQuotes: Leave
|
||||
|
||||
JavaScriptWrapImports: true
|
||||
KeepLineBreaksForNonEmptyLines: false
|
||||
#KeepLineBreaksForNonEmptyLines: false
|
||||
# 保留在块开始处的空行
|
||||
KeepEmptyLinesAtTheStartOfBlocks: true
|
||||
# 开始一个块的宏的正则表达式
|
||||
@ -230,4 +231,3 @@ TabWidth: 4
|
||||
# 使用tab字符: Never, ForIndentation, ForContinuationAndIndentation, Always
|
||||
UseTab: Never
|
||||
...
|
||||
|
||||
|
@ -10,6 +10,7 @@ Rectangle {
|
||||
y: control.height * 1.1
|
||||
color: gConfig.reserverColor
|
||||
opacity: 0.7
|
||||
visible: false
|
||||
Text {
|
||||
id: t
|
||||
anchors.centerIn: parent
|
||||
@ -17,6 +18,9 @@ Rectangle {
|
||||
SequentialAnimation {
|
||||
id: ani
|
||||
alwaysRunToEnd: false
|
||||
ScriptAction {
|
||||
script: root.visible = true
|
||||
}
|
||||
NumberAnimation {
|
||||
target: root
|
||||
property: "y"
|
||||
@ -35,6 +39,9 @@ Rectangle {
|
||||
easing.type: Easing.Linear
|
||||
to: control.height * 1.1
|
||||
}
|
||||
ScriptAction {
|
||||
script: root.visible = false
|
||||
}
|
||||
|
||||
}
|
||||
function notify(msg) {
|
||||
|
@ -19,37 +19,68 @@
|
||||
|
||||
#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)
|
||||
{
|
||||
setFlags(Qt::Window | Qt::FramelessWindowHint | Qt::WindowMinMaxButtonsHint);
|
||||
setResizeMode(SizeRootObjectToView);
|
||||
setColor(QColor(Qt::transparent));
|
||||
resize(1440, 900);
|
||||
setMinimumSize({1440, 960});
|
||||
resize(1440, 960);
|
||||
#if WIN32
|
||||
DWORD style = ::GetWindowLong(HWND(winId()), GWL_STYLE);
|
||||
style |= WS_MINIMIZEBOX | WS_THICKFRAME | WS_CAPTION;
|
||||
::SetWindowLong(HWND(winId()), GWL_STYLE, style);
|
||||
// MARGINS rect{1, 1, -1, -1};
|
||||
// DwmExtendFrameIntoClientArea(HWND(winId()), &rect);
|
||||
#endif
|
||||
setIsMax(windowState() == Qt::WindowMaximized);
|
||||
connect(this, &QWindow::windowStateChanged, this, [&](Qt::WindowState state){
|
||||
setIsMax(state == Qt::WindowMaximized);
|
||||
});
|
||||
setIsMax(isMaxWin(this));
|
||||
connect(this, &QWindow::windowStateChanged, this, [&](Qt::WindowState state) { setIsMax(state == Qt::WindowMaximized); });
|
||||
}
|
||||
|
||||
TaoView::~TaoView()
|
||||
{
|
||||
}
|
||||
TaoView::~TaoView() {}
|
||||
|
||||
void TaoView::moveToScreenCenter()
|
||||
{
|
||||
auto screenGeo = qApp->primaryScreen()->geometry();
|
||||
auto viewGeo = geometry();
|
||||
QPoint centerPos = { (screenGeo.width() - viewGeo.width()) / 2, (screenGeo.height() - viewGeo.height()) / 2 };
|
||||
setPosition(centerPos);
|
||||
auto geo = screen()->availableGeometry();
|
||||
int w = width();
|
||||
int h = height();
|
||||
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)
|
||||
@ -64,87 +95,59 @@ void TaoView::setIsMax(bool isMax)
|
||||
#if WIN32
|
||||
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))
|
||||
MSG* msg = *reinterpret_cast<MSG**>(message);
|
||||
#else
|
||||
MSG* msg = reinterpret_cast<MSG*>(message);
|
||||
#endif
|
||||
switch (msg->message) {
|
||||
case WM_NCCALCSIZE: {
|
||||
NCCALCSIZE_PARAMS& params = *reinterpret_cast<NCCALCSIZE_PARAMS*>(msg->lParam);
|
||||
if (!(windowStates() & Qt::WindowFullScreen) && !(windowStates() & Qt::WindowMaximized)) {
|
||||
if (params.rgrc[0].top != 0)
|
||||
params.rgrc[0].top -= 1;
|
||||
}
|
||||
//this kills the window frame and title bar we added with WS_THICKFRAME and WS_CAPTION
|
||||
*result = WVR_REDRAW;
|
||||
return true;
|
||||
}
|
||||
case WM_NCHITTEST: {
|
||||
*result = 0;
|
||||
|
||||
RECT winrect;
|
||||
GetWindowRect(HWND(winId()), &winrect);
|
||||
|
||||
long x = GET_X_LPARAM(msg->lParam);
|
||||
long y = GET_Y_LPARAM(msg->lParam);
|
||||
|
||||
bool resizeWidth = minimumWidth() != maximumWidth();
|
||||
bool resizeHeight = minimumHeight() != maximumHeight();
|
||||
|
||||
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) {
|
||||
return true;
|
||||
}
|
||||
double dpr = qApp->devicePixelRatio();
|
||||
QPoint pos = mapFromGlobal(QPoint(x/dpr,y/dpr));
|
||||
QRect titleRect(border_width, border_width, width() * 0.8, 50);
|
||||
if (titleRect.contains(pos))
|
||||
{
|
||||
*result = HTCAPTION;
|
||||
return true;
|
||||
}
|
||||
if (!result) {
|
||||
return false;
|
||||
} //end case WM_NCHITTEST
|
||||
}
|
||||
MSG *msg = reinterpret_cast<MSG *>(message);
|
||||
if (!msg || (msg && !msg->hwnd)) {
|
||||
return false;
|
||||
}
|
||||
switch (msg->message) {
|
||||
case WM_NCCALCSIZE: {
|
||||
const auto mode = static_cast<BOOL>(msg->wParam);
|
||||
*result = mode ? WVR_REDRAW : 0;
|
||||
|
||||
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;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
case WM_NCHITTEST: {
|
||||
*result = 0;
|
||||
|
||||
RECT winrect;
|
||||
GetWindowRect(HWND(winId()), &winrect);
|
||||
|
||||
long x = GET_X_LPARAM(msg->lParam);
|
||||
long y = GET_Y_LPARAM(msg->lParam);
|
||||
|
||||
*result = 0;
|
||||
if (!isMaxWin(this) && !isFullWin(this)) { //非最大化、非全屏时,进行命中测试,处理边框拖拽
|
||||
*result = hitTest(winrect, x, y, border_width);
|
||||
if (0 != *result) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
double dpr = qApp->devicePixelRatio();
|
||||
QPoint pos = mapFromGlobal(QPoint(x / dpr, y / dpr));
|
||||
QRect titleRect(border_width, border_width, width() * 0.8, 50);
|
||||
if (titleRect.contains(pos)) {
|
||||
*result = HTCAPTION;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
} //end case WM_NCHITTEST
|
||||
}
|
||||
return QQuickView::nativeEvent(eventType, message, result);
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
#include <QtGlobal>
|
||||
#include <QDebug>
|
||||
#include <QtGlobal>
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
|
||||
#include <QQmlEngineExtensionPlugin>
|
||||
|
Loading…
x
Reference in New Issue
Block a user