FluentUI/src/controls/FluWindowResize.qml

143 lines
4.3 KiB
QML
Raw Normal View History

2023-03-30 21:52:55 +08:00
import QtQuick
import QtQuick.Window
2023-03-02 18:21:43 +08:00
MouseArea {
property int border: 4
2023-03-06 18:08:01 +08:00
property var window: Window.window
2023-03-02 18:21:43 +08:00
property bool fixedSize: {
2023-03-06 18:08:01 +08:00
if(window == null)
2023-03-02 18:21:43 +08:00
return true
2023-03-06 18:08:01 +08:00
if(window.visibility === Window.Maximized || window.visibility === Window.FullScreen){
2023-03-02 18:21:43 +08:00
return true
}
2023-03-06 18:08:01 +08:00
return (window.minimumWidth === window.maximumWidth && window.minimumHeight === window.maximumHeight)
2023-03-02 18:21:43 +08:00
}
anchors.fill: parent
acceptedButtons: Qt.LeftButton
hoverEnabled: true
preventStealing: true
propagateComposedEvents: true
z: -65535
onPressed :
(mouse)=> {
if (fixedSize) {
return;
}
let e = 0;
2023-03-03 18:19:48 +08:00
if (ptInRect(0,0,border,border, mouse.x, mouse.y)) {
2023-03-02 18:21:43 +08:00
e = Qt.TopEdge | Qt.LeftEdge;
window.startSystemResize(e);
return;
}
2023-03-03 18:19:48 +08:00
if (ptInRect(border,0,window.width-border*2,border, mouse.x, mouse.y)) {
2023-03-02 18:21:43 +08:00
e = Qt.TopEdge;
window.startSystemResize(e);
return;
}
2023-03-03 18:19:48 +08:00
if (ptInRect(window.width-border,0,border,border, mouse.x, mouse.y)) {
2023-03-02 18:21:43 +08:00
e = Qt.TopEdge | Qt.RightEdge;
window.startSystemResize(e);
return;
}
2023-03-03 18:19:48 +08:00
if (ptInRect(window.width-border,border,border,window.height-border*2, mouse.x, mouse.y)) {
2023-03-02 18:21:43 +08:00
e = Qt.RightEdge;
window.startSystemResize(e);
return;
}
2023-03-03 18:19:48 +08:00
if (ptInRect(window.width-border,window.height-border,border,border, mouse.x, mouse.y)) {
2023-03-02 18:21:43 +08:00
e = Qt.BottomEdge | Qt.RightEdge;
window.startSystemResize(e);
return;
}
2023-03-03 18:19:48 +08:00
if (ptInRect(border,window.height-border,window.width-border*2,border, mouse.x, mouse.y)) {
2023-03-02 18:21:43 +08:00
e = Qt.BottomEdge;
window.startSystemResize(e);
return;
}
2023-03-03 18:19:48 +08:00
if (ptInRect(0,window.height-border,border,border, mouse.x, mouse.y)) {
2023-03-02 18:21:43 +08:00
e = Qt.BottomEdge | Qt.LeftEdge;
window.startSystemResize(e);
return;
}
2023-03-03 18:19:48 +08:00
if (ptInRect(0,border,border , window.height-border*2, mouse.x, mouse.y)) {
2023-03-02 18:21:43 +08:00
e = Qt.LeftEdge;
window.startSystemResize(e);
return;
}
}
onPositionChanged:
(mouse)=> {
if (fixedSize) {
cursorShape = Qt.ArrowCursor;
return;
}
2023-03-03 18:19:48 +08:00
if (ptInRect(0,0,border,border, mouse.x, mouse.y)) {
2023-03-02 18:21:43 +08:00
cursorShape = Qt.SizeFDiagCursor;
return;
}
2023-03-03 18:19:48 +08:00
if (ptInRect(border,0,window.width-border*2,border, mouse.x, mouse.y)) {
2023-03-02 18:21:43 +08:00
cursorShape = Qt.SizeVerCursor;
return;
}
2023-03-03 18:19:48 +08:00
if (ptInRect(window.width-border,0,border,border, mouse.x, mouse.y)) {
2023-03-02 18:21:43 +08:00
cursorShape = Qt.SizeBDiagCursor;
return;
}
2023-03-03 18:19:48 +08:00
if (ptInRect(window.width-border,border,border,window.height-border*2, mouse.x, mouse.y)) {
2023-03-02 18:21:43 +08:00
cursorShape = Qt.SizeHorCursor;
return;
}
2023-03-03 18:19:48 +08:00
if (ptInRect(window.width-border,window.height-border,border,border, mouse.x, mouse.y)) {
2023-03-02 18:21:43 +08:00
cursorShape = Qt.SizeFDiagCursor;
return;
}
2023-03-03 18:19:48 +08:00
if (ptInRect(border,window.height-border,window.width-border*2,border, mouse.x, mouse.y)) {
2023-03-02 18:21:43 +08:00
cursorShape = Qt.SizeVerCursor;
return;
}
2023-03-03 18:19:48 +08:00
if (ptInRect(0,window.height-border,border,border, mouse.x, mouse.y)) {
2023-03-02 18:21:43 +08:00
cursorShape = Qt.SizeBDiagCursor;
return;
}
2023-03-03 18:19:48 +08:00
if (ptInRect(0,border,border, window.height-border*2, mouse.x, mouse.y)) {
2023-03-02 18:21:43 +08:00
cursorShape = Qt.SizeHorCursor;
return;
}
cursorShape = Qt.ArrowCursor;
}
onExited: {
cursorShape = Qt.ArrowCursor;
}
2023-03-03 18:19:48 +08:00
function ptInRect(rcx,rcy,rcwidth,rcheight, x, y)
2023-03-02 18:21:43 +08:00
{
2023-03-03 18:19:48 +08:00
if ((rcx <= x && x <= (rcx + rcwidth)) &&
(rcy <= y && y <= (rcy + rcheight))) {
2023-03-02 18:21:43 +08:00
return true;
}
return false;
}
}