FluRectangle.qml 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import QtQuick
  2. import QtQuick.Controls
  3. import Qt5Compat.GraphicalEffects
  4. import FluentUI
  5. Item{
  6. property var radius:[0,0,0,0]
  7. property color color : "#FFFFFF"
  8. property bool shadow: true
  9. default property alias contentItem: container.data
  10. id:control
  11. FluShadow{
  12. anchors.fill: container
  13. radius: control.radius[0]
  14. visible: {
  15. if(control.radius[0] === control.radius[1] && control.radius[0] === control.radius[2] && control.radius[0] === control.radius[3] && control.shadow){
  16. return true
  17. }
  18. return false
  19. }
  20. }
  21. Rectangle{
  22. id:container
  23. width: control.width
  24. height: control.height
  25. opacity: 0
  26. color:control.color
  27. }
  28. Canvas {
  29. id: canvas
  30. anchors.fill: parent
  31. visible: false
  32. onPaint: {
  33. var ctx = getContext("2d");
  34. var x = 0;
  35. var y = 0;
  36. var w = control.width;
  37. var h = control.height;
  38. ctx.setTransform(1, 0, 0, 1, 0, 0);
  39. ctx.clearRect(0, 0, canvas.width, canvas.height);
  40. ctx.save();
  41. ctx.beginPath();
  42. ctx.moveTo(x + radius[0], y);
  43. ctx.lineTo(x + w - radius[1], y);
  44. ctx.arcTo(x + w, y, x + w, y + radius[1], radius[1]);
  45. ctx.lineTo(x + w, y + h - radius[2]);
  46. ctx.arcTo(x + w, y + h, x + w - radius[2], y + h, radius[2]);
  47. ctx.lineTo(x + radius[3], y + h);
  48. ctx.arcTo(x, y + h, x, y + h - radius[3], radius[3]);
  49. ctx.lineTo(x, y + radius[0]);
  50. ctx.arcTo(x, y, x + radius[0], y, radius[0]);
  51. ctx.closePath();
  52. ctx.fillStyle = control.color;
  53. ctx.fill();
  54. ctx.restore();
  55. }
  56. }
  57. OpacityMask {
  58. anchors.fill: container
  59. source: container
  60. maskSource: canvas
  61. }
  62. }