StyleImage.qml 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Copyright (C) 2024 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. @Deprecated {
  6. reason: "StyleImage component has been moved to private FluentWinUI3.impl module \
  7. and is no longer part of the public QML API."
  8. }
  9. // This item will resize the child image in such a way that any drop shadow
  10. // or blur (or other effects) will be drawn outside its own bounds.
  11. // The effect is that users of this item won't have to take e.g shadows
  12. // into account when positioning it, as such effects will only be visual, and
  13. // not be a part of the geometry.
  14. Item {
  15. id: root
  16. Component.onCompleted: {
  17. print("StyleImage has been moved to private FluentWinUI3.impl module "
  18. + "and is no longer part of the public QML API.")
  19. }
  20. implicitWidth: horizontal ? imageConfig.width : imageConfig.height
  21. implicitHeight: horizontal ? imageConfig.height : imageConfig.width
  22. required property var imageConfig
  23. // Set horizontal to false if you want the image to be rotated 90 degrees
  24. // Doing so will rotate the image, but also flip it, to make sure that
  25. // the shadow ends up on the correct side. The implicit geometry of the
  26. // item will also be adjusted to match the rotated image.
  27. property bool horizontal: true
  28. // The minimum size of the image should be at least 1px tall and wide, even without any offsets
  29. property real minimumWidth: Math.max(1, imageConfig.leftOffset + imageConfig.rightOffset)
  30. property real minimumHeight: Math.max(1, imageConfig.topOffset + imageConfig.bottomOffset)
  31. BorderImage {
  32. x: -imageConfig.leftShadow
  33. y: -imageConfig.topShadow
  34. width: Math.max(root.minimumWidth, (root.horizontal ? root.width : root.height))
  35. + imageConfig.leftShadow + imageConfig.rightShadow
  36. height: Math.max(root.minimumHeight, (root.horizontal ? root.height : root.width))
  37. + imageConfig.topShadow + imageConfig.bottomShadow
  38. source: Qt.resolvedUrl(imageConfig.filePath)
  39. border {
  40. top: Math.min(height / 2, imageConfig.topOffset + imageConfig.topShadow)
  41. left: Math.min(width / 2, imageConfig.leftOffset + imageConfig.leftShadow)
  42. bottom: Math.min(height / 2, imageConfig.bottomOffset + imageConfig.bottomShadow)
  43. right: Math.min(width / 2, imageConfig.rightOffset + imageConfig.rightShadow)
  44. }
  45. transform: [
  46. Rotation {
  47. angle: root.horizontal ? 0 : 90
  48. },
  49. Scale {
  50. xScale: root.horizontal ? 1 : -1
  51. }
  52. ]
  53. }
  54. }