mirror of
https://github.com/jaredtao/TaoQuick.git
synced 2025-01-17 20:12:54 +08:00
update border
This commit is contained in:
parent
d1cf1fc92d
commit
d166eab881
@ -1,7 +1,9 @@
|
||||
#pragma once
|
||||
#include "TaoCommonGlobal.h"
|
||||
#include <QQuickView>
|
||||
//无边框窗口,实现自定义标题栏。支持拖动和改变大小,支持Windows平台Aero效果
|
||||
//无边框窗口,主要用来实现自定义标题栏。
|
||||
//Windows平台支持拖动和改变大小,支持Windows平台Aero效果
|
||||
//非Windows平台,去掉边框,不做其它处理。由Qml模拟编译resize和拖动。
|
||||
class TaoFrameLessViewPrivate;
|
||||
class TAO_API TaoFrameLessView : public QQuickView
|
||||
{
|
||||
@ -23,13 +25,12 @@ signals:
|
||||
void isMaxChanged(bool isMax);
|
||||
|
||||
protected:
|
||||
#if WIN32
|
||||
# if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
bool nativeEvent(const QByteArray &eventType, void *message, qintptr *result) override;
|
||||
# else
|
||||
bool nativeEvent(const QByteArray &eventType, void *message, long *result) override;
|
||||
# endif
|
||||
#endif
|
||||
|
||||
private:
|
||||
TaoFrameLessViewPrivate *d;
|
||||
};
|
||||
|
@ -7,10 +7,17 @@
|
||||
class TaoFrameLessViewPrivate
|
||||
{
|
||||
public:
|
||||
bool m_isMax;
|
||||
bool m_isMax = false;
|
||||
QQuickItem *m_titleItem = nullptr;
|
||||
};
|
||||
TaoFrameLessView::TaoFrameLessView(QWindow *parent) : Super(parent), d(new TaoFrameLessViewPrivate) { }
|
||||
TaoFrameLessView::TaoFrameLessView(QWindow *parent) : Super(parent), d(new TaoFrameLessViewPrivate)
|
||||
{
|
||||
setFlags(Qt::CustomizeWindowHint | Qt::Window | Qt::FramelessWindowHint | Qt::WindowMinMaxButtonsHint | Qt::WindowTitleHint | Qt::WindowSystemMenuHint);
|
||||
setResizeMode(SizeRootObjectToView);
|
||||
|
||||
setIsMax(windowState() == Qt::WindowMaximized);
|
||||
connect(this, &QWindow::windowStateChanged, this, [&](Qt::WindowState state) { setIsMax(state == Qt::WindowMaximized); });
|
||||
}
|
||||
TaoFrameLessView::~TaoFrameLessView()
|
||||
{
|
||||
delete d;
|
||||
@ -61,3 +68,13 @@ void TaoFrameLessView::setTitleItem(QQuickItem *item)
|
||||
{
|
||||
d->m_titleItem = item;
|
||||
}
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
bool TaoFrameLessView::nativeEvent(const QByteArray &eventType, void *message, qintptr *result)
|
||||
#else
|
||||
bool TaoFrameLessView::nativeEvent(const QByteArray &eventType, void *message, long *result)
|
||||
#endif
|
||||
|
||||
{
|
||||
return Super::nativeEvent(eventType, message, result);
|
||||
}
|
||||
|
@ -180,7 +180,7 @@ bool TaoFrameLessView::nativeEvent(const QByteArray &eventType, void *message, l
|
||||
#endif
|
||||
|
||||
{
|
||||
const long border_width = 6;
|
||||
const long border_width = 4;
|
||||
if (!result) {
|
||||
//防御式编程
|
||||
//一般不会发生这种情况,win7一些极端情况,会传空指针进来。解决方案是升级驱动、切换到basic主题。
|
||||
@ -226,23 +226,6 @@ bool TaoFrameLessView::nativeEvent(const QByteArray &eventType, void *message, l
|
||||
}
|
||||
break;
|
||||
}
|
||||
// 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);
|
||||
// //规避 拖动border进行resize时界面闪烁
|
||||
// if (!isMaxWin(this) && !isFullWin(this)) {
|
||||
// if (clientRect->top != 0) {
|
||||
// clientRect->top -= 0.1;
|
||||
// }
|
||||
// } else {
|
||||
// if (clientRect->top != 0) {
|
||||
// clientRect->top += 0.1;
|
||||
// }
|
||||
// }
|
||||
// return true;
|
||||
// }
|
||||
case WM_NCHITTEST: {
|
||||
if (d->borderless) {
|
||||
RECT winrect;
|
47
3rdparty/TaoCommon/TaoCommon.pri
vendored
47
3rdparty/TaoCommon/TaoCommon.pri
vendored
@ -4,23 +4,38 @@
|
||||
|
||||
INCLUDEPATH += $$PWD
|
||||
|
||||
hFile = $$files($$PWD/*.h, true)
|
||||
hppFile = $$files($$PWD/*.hpp, true)
|
||||
cppFile = $$files($$PWD/*.cpp, true)
|
||||
win32 {
|
||||
hFile -= $$files($$PWD/Frameless/Unix/*.h)
|
||||
hppFile -= $$files($$PWD/Frameless/Unix/*.hpp)
|
||||
cppFile -= $$files($$PWD/Frameless/Unix/*.cpp)
|
||||
} else {
|
||||
hFile -= $$files($$PWD/Frameless/Win/*.h)
|
||||
hppFile -= $$files($$PWD/Frameless/Win/*.hpp)
|
||||
cppFile -= $$files($$PWD/Frameless/Win/*.cpp)
|
||||
}
|
||||
HEADERS += \
|
||||
$$hFile \
|
||||
$$hppFile
|
||||
|
||||
$$PWD/Common/FileReadWrite.h \
|
||||
$$PWD/Common/JsonSerialize.h \
|
||||
$$PWD/Common/ObjectMap.h \
|
||||
$$PWD/Common/Package.h \
|
||||
$$PWD/Common/PropertyHelper.h \
|
||||
$$PWD/Common/Subject.h \
|
||||
$$PWD/Frameless/TaoFrameLessView.h \
|
||||
$$PWD/Logger/Logger.h \
|
||||
$$PWD/Logger/LoggerTemplate.h \
|
||||
$$PWD/QuickTool/QuickTool.h \
|
||||
$$PWD/TaoCommonGlobal.h \
|
||||
$$PWD/TaoModel/TaoListItemBase.h \
|
||||
$$PWD/TaoModel/TaoListModel.h \
|
||||
$$PWD/TaoModel/TaoListModelBase.hpp \
|
||||
$$PWD/Thread/ThreadCommon.h \
|
||||
$$PWD/Thread/ThreadPool.h \
|
||||
$$PWD/Thread/ThreadWorkerController.h \
|
||||
$$PWD/Trans/Trans.h
|
||||
|
||||
SOURCES += \
|
||||
$$cppFile
|
||||
$$PWD/Logger/Logger.cpp \
|
||||
$$PWD/QuickTool/QuickTool.cpp \
|
||||
$$PWD/TaoModel/TaoListItemBase.cpp \
|
||||
$$PWD/TaoModel/TaoListModel.cpp \
|
||||
$$PWD/Thread/ThreadPool.cpp \
|
||||
$$PWD/Trans/Trans.cpp
|
||||
|
||||
win32 {
|
||||
SOURCES += \
|
||||
$$PWD/Frameless/TaoFrameLessView_win.cpp
|
||||
} else {
|
||||
SOURCES += \
|
||||
$$PWD/Frameless/TaoFrameLessView_unix.cpp
|
||||
}
|
||||
|
@ -126,12 +126,21 @@ Rectangle {
|
||||
objectName: "blankItem"
|
||||
anchors {
|
||||
left: parent.left
|
||||
leftMargin: 4
|
||||
right: toolRow.left
|
||||
top: parent.top
|
||||
topMargin: 4
|
||||
bottom: parent.bottom
|
||||
}
|
||||
Component.onCompleted: {
|
||||
view.setTitleItem(blankItem)
|
||||
}
|
||||
MoveArea {
|
||||
anchors.fill: parent
|
||||
onMove: {
|
||||
view.x += xOffset
|
||||
view.y += yOffset
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -30,6 +30,14 @@ CusBackground {
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
CusResizeBorder {
|
||||
id: resizeBorder
|
||||
visible: Qt.platform.os !== "windows"
|
||||
borderWidth: 4
|
||||
enabled: visible
|
||||
anchors.fill: rootBackground
|
||||
control: view
|
||||
}
|
||||
AboutDialog {
|
||||
id: aboutDialog
|
||||
}
|
||||
@ -43,10 +51,12 @@ CusBackground {
|
||||
}
|
||||
Item {
|
||||
id: content
|
||||
width: parent.width
|
||||
width: parent.width - resizeBorder.borderWidth * 2
|
||||
x: resizeBorder.borderWidth
|
||||
anchors {
|
||||
top: title.bottom
|
||||
bottom: parent.bottom
|
||||
bottomMargin: resizeBorder.borderWidth
|
||||
}
|
||||
CusFPS {
|
||||
anchors {
|
||||
|
@ -6,12 +6,15 @@ Item {
|
||||
//controller 要控制大小的目标,可以是Item,也可以是view,只要提供x、y、width、height等属性的修改
|
||||
//默认值为parent
|
||||
property var control: parent
|
||||
property int borderWidth: 12
|
||||
//左上角的拖拽
|
||||
CusDragItem {
|
||||
id: leftTopHandle
|
||||
posType: posLeftTop
|
||||
width: borderWidth
|
||||
height: borderWidth
|
||||
onPosChange: {
|
||||
//不要简化这个判断条件,至少让以后维护的人能看懂。我当然知道能化简,化简过几分钟之后我自己都看不懂了。
|
||||
//不要简化这个判断条件,化简之后不容易看懂. Qml引擎会自动简化
|
||||
if (control.x + xOffset < control.x + control.width)
|
||||
control.x += xOffset;
|
||||
if (control.y + yOffset < control.y + control.height)
|
||||
@ -27,6 +30,8 @@ Item {
|
||||
id: rightTopHandle
|
||||
posType: posRightTop
|
||||
x: parent.width - width
|
||||
width: borderWidth
|
||||
height: borderWidth
|
||||
onPosChange: {
|
||||
//向左拖动时,xOffset为负数
|
||||
if (control.width + xOffset > 0)
|
||||
@ -42,6 +47,8 @@ Item {
|
||||
id: leftBottomHandle
|
||||
posType: posLeftBottom
|
||||
y: parent.height - height
|
||||
width: borderWidth
|
||||
height: borderWidth
|
||||
onPosChange: {
|
||||
if (control.x + xOffset < control.x + control.width)
|
||||
control.x += xOffset;
|
||||
@ -57,6 +64,8 @@ Item {
|
||||
posType: posRightBottom
|
||||
x: parent.width - width
|
||||
y: parent.height - height
|
||||
width: borderWidth
|
||||
height: borderWidth
|
||||
onPosChange: {
|
||||
if (control.width + xOffset > 0)
|
||||
control.width += xOffset;
|
||||
@ -68,6 +77,7 @@ Item {
|
||||
CusDragItem {
|
||||
posType: posTop
|
||||
width: parent.width - leftTopHandle.width - rightTopHandle.width
|
||||
height: borderWidth
|
||||
x: leftBottomHandle.width
|
||||
onPosChange: {
|
||||
if (control.y + yOffset < control.y + control.height)
|
||||
@ -81,6 +91,8 @@ Item {
|
||||
CusDragItem {
|
||||
posType: posLeft
|
||||
height: parent.height - leftTopHandle.height - leftBottomHandle.height
|
||||
width: borderWidth
|
||||
|
||||
y: leftTopHandle.height
|
||||
onPosChange: {
|
||||
if (control.x + xOffset < control.x + control.width)
|
||||
@ -94,6 +106,8 @@ Item {
|
||||
posType: posRight
|
||||
x: parent.width - width
|
||||
height: parent.height - rightTopHandle.height - rightBottomHandle.height
|
||||
width: borderWidth
|
||||
|
||||
y: rightTopHandle.height
|
||||
onPosChange: {
|
||||
if (control.width + xOffset > 0)
|
||||
@ -106,10 +120,10 @@ Item {
|
||||
x: leftBottomHandle.width
|
||||
y: parent.height - height
|
||||
width: parent.width - leftBottomHandle.width - rightBottomHandle.width
|
||||
height: borderWidth
|
||||
onPosChange: {
|
||||
if (control.height + yOffset > 0)
|
||||
control.height += yOffset;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user