WindowsFocusFrame.qml 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Copyright (C) 2023 The Qt Company Ltd.
  2. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
  3. // Qt-Security score:significant reason:default
  4. import QtQuick
  5. Canvas {
  6. id: root
  7. x: targetItem ? targetItem.x + leftOffset - frameSize : 0
  8. y: targetItem ? targetItem.y + topOffset - frameSize : 0
  9. // Stack on top of all siblings of the targetItem
  10. z: 100
  11. width: targetItem ? targetItem.width - leftOffset - rightOffset + (frameSize * 2) : 0
  12. height: targetItem ? targetItem.height - topOffset - bottomOffset + (frameSize * 2) : 0
  13. visible: targetItem && targetItem.visible
  14. function moveToItem(item, margins, radius) {
  15. if (!item) {
  16. targetItem = null;
  17. parent = null;
  18. return;
  19. }
  20. parent = item.parent
  21. targetItem = item
  22. leftOffset = margins.left
  23. rightOffset = margins.right
  24. topOffset = margins.top
  25. bottomOffset = margins.bottom
  26. frameRadius = radius
  27. }
  28. property Item targetItem
  29. property real leftOffset: 0
  30. property real rightOffset: 0
  31. property real topOffset: 0
  32. property real bottomOffset: 0
  33. property real frameOpacity: 0
  34. property real frameSize: 0
  35. property real frameRadius: 0
  36. onPaint: {
  37. let context = getContext("2d")
  38. context.strokeStyle = Qt.rgba(0, 0, 0, 1)
  39. context.setLineDash([1, 1])
  40. context.beginPath()
  41. context.roundedRect(0.5, 0.5, width - 1, height - 1, root.frameRadius, root.frameRadius)
  42. context.stroke()
  43. }
  44. }