FluWindowResize.qml 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. import QtQuick
  2. import QtQuick.Controls
  3. import QtQuick.Window
  4. import FluentUI
  5. MouseArea {
  6. property int border: 4
  7. property var window: Window.window
  8. property bool fixedSize: {
  9. if(window == null)
  10. return true
  11. if(window.visibility === Window.Maximized || window.visibility === Window.FullScreen){
  12. return true
  13. }
  14. return (window.minimumWidth === window.maximumWidth && window.minimumHeight === window.maximumHeight)
  15. }
  16. anchors.fill: parent
  17. acceptedButtons: Qt.LeftButton
  18. hoverEnabled: true
  19. preventStealing: true
  20. propagateComposedEvents: true
  21. z: -65535
  22. onPressed :
  23. (mouse)=> {
  24. if (fixedSize) {
  25. return;
  26. }
  27. let e = 0;
  28. if (ptInRect(0,0,border,border, mouse.x, mouse.y)) {
  29. e = Qt.TopEdge | Qt.LeftEdge;
  30. window.startSystemResize(e);
  31. return;
  32. }
  33. if (ptInRect(border,0,window.width-border*2,border, mouse.x, mouse.y)) {
  34. e = Qt.TopEdge;
  35. window.startSystemResize(e);
  36. return;
  37. }
  38. if (ptInRect(window.width-border,0,border,border, mouse.x, mouse.y)) {
  39. e = Qt.TopEdge | Qt.RightEdge;
  40. window.startSystemResize(e);
  41. return;
  42. }
  43. if (ptInRect(window.width-border,border,border,window.height-border*2, mouse.x, mouse.y)) {
  44. e = Qt.RightEdge;
  45. window.startSystemResize(e);
  46. return;
  47. }
  48. if (ptInRect(window.width-border,window.height-border,border,border, mouse.x, mouse.y)) {
  49. e = Qt.BottomEdge | Qt.RightEdge;
  50. window.startSystemResize(e);
  51. return;
  52. }
  53. if (ptInRect(border,window.height-border,window.width-border*2,border, mouse.x, mouse.y)) {
  54. e = Qt.BottomEdge;
  55. window.startSystemResize(e);
  56. return;
  57. }
  58. if (ptInRect(0,window.height-border,border,border, mouse.x, mouse.y)) {
  59. e = Qt.BottomEdge | Qt.LeftEdge;
  60. window.startSystemResize(e);
  61. return;
  62. }
  63. if (ptInRect(0,border,border , window.height-border*2, mouse.x, mouse.y)) {
  64. e = Qt.LeftEdge;
  65. window.startSystemResize(e);
  66. return;
  67. }
  68. }
  69. onPositionChanged:
  70. (mouse)=> {
  71. if (fixedSize) {
  72. cursorShape = Qt.ArrowCursor;
  73. return;
  74. }
  75. if (ptInRect(0,0,border,border, mouse.x, mouse.y)) {
  76. cursorShape = Qt.SizeFDiagCursor;
  77. return;
  78. }
  79. if (ptInRect(border,0,window.width-border*2,border, mouse.x, mouse.y)) {
  80. cursorShape = Qt.SizeVerCursor;
  81. return;
  82. }
  83. if (ptInRect(window.width-border,0,border,border, mouse.x, mouse.y)) {
  84. cursorShape = Qt.SizeBDiagCursor;
  85. return;
  86. }
  87. if (ptInRect(window.width-border,border,border,window.height-border*2, mouse.x, mouse.y)) {
  88. cursorShape = Qt.SizeHorCursor;
  89. return;
  90. }
  91. if (ptInRect(window.width-border,window.height-border,border,border, mouse.x, mouse.y)) {
  92. cursorShape = Qt.SizeFDiagCursor;
  93. return;
  94. }
  95. if (ptInRect(border,window.height-border,window.width-border*2,border, mouse.x, mouse.y)) {
  96. cursorShape = Qt.SizeVerCursor;
  97. return;
  98. }
  99. if (ptInRect(0,window.height-border,border,border, mouse.x, mouse.y)) {
  100. cursorShape = Qt.SizeBDiagCursor;
  101. return;
  102. }
  103. if (ptInRect(0,border,border, window.height-border*2, mouse.x, mouse.y)) {
  104. cursorShape = Qt.SizeHorCursor;
  105. return;
  106. }
  107. cursorShape = Qt.ArrowCursor;
  108. }
  109. onExited: {
  110. cursorShape = Qt.ArrowCursor;
  111. }
  112. function ptInRect(rcx,rcy,rcwidth,rcheight, x, y)
  113. {
  114. if ((rcx <= x && x <= (rcx + rcwidth)) &&
  115. (rcy <= y && y <= (rcy + rcheight))) {
  116. return true;
  117. }
  118. return false;
  119. }
  120. }