FluBadge.qml 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import QtQuick
  2. import QtQuick.Controls
  3. import FluentUI
  4. Rectangle{
  5. property bool isDot: false
  6. property bool showZero: true
  7. property int count: 0
  8. id:control
  9. color:Qt.rgba(255/255,77/255,79/255,1)
  10. width: {
  11. if(isDot)
  12. return 10
  13. if(count<10){
  14. return 20
  15. }else if(count<100){
  16. return 30
  17. }
  18. return 40
  19. }
  20. height: {
  21. if(isDot)
  22. return 10
  23. return 20
  24. }
  25. radius: {
  26. if(isDot)
  27. return 5
  28. return 10
  29. }
  30. border.width: 1
  31. border.color: Qt.rgba(1,1,1,1)
  32. visible: {
  33. if(showZero)
  34. return true
  35. return count!==0
  36. }
  37. anchors{
  38. right: {
  39. if(parent)
  40. return parent.right
  41. return undefined
  42. }
  43. top: {
  44. if(parent)
  45. return parent.top
  46. return undefined
  47. }
  48. rightMargin: {
  49. if(isDot){
  50. return -2.5
  51. }
  52. return -(control.width/2)
  53. }
  54. topMargin: {
  55. if(isDot){
  56. return -2.5
  57. }
  58. return -10
  59. }
  60. }
  61. Text{
  62. anchors.centerIn: parent
  63. color: Qt.rgba(1,1,1,1)
  64. visible: !isDot
  65. text:{
  66. if(count<100)
  67. return count
  68. return count+"+"
  69. }
  70. }
  71. }