FluItem.qml 1.6 KB

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