ActivityActionButton.qml 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. import QtQuick 2.5
  2. import QtQuick.Controls 2.3
  3. import Style 1.0
  4. Item {
  5. id: root
  6. readonly property bool labelVisible: label.visible
  7. readonly property bool iconVisible: icon.visible
  8. // label value
  9. property string text: ""
  10. // font value
  11. property var font: label.font
  12. // icon value
  13. property string imageSource: ""
  14. // Tooltip value
  15. property string tooltipText: text
  16. // text color
  17. property color textColor: Style.ncTextColor
  18. property color textColorHovered: Style.lightHover
  19. // text background color
  20. property color textBgColor: "transparent"
  21. property color textBgColorHovered: Style.lightHover
  22. // icon background color
  23. property color iconBgColor: "transparent"
  24. property color iconBgColorHovered: Style.lightHover
  25. // text border color
  26. property color textBorderColor: "transparent"
  27. property alias hovered: mouseArea.containsMouse
  28. signal clicked()
  29. Accessible.role: Accessible.Button
  30. Accessible.name: text !== "" ? text : (tooltipText !== "" ? tooltipText : qsTr("Activity action button"))
  31. Accessible.onPressAction: clicked()
  32. // background with border around the Text
  33. Rectangle {
  34. visible: parent.labelVisible
  35. anchors.fill: parent
  36. // padding
  37. anchors.topMargin: 10
  38. anchors.bottomMargin: 10
  39. border.color: parent.textBorderColor
  40. border.width: 1
  41. color: parent.hovered ? parent.textBgColorHovered : parent.textBgColor
  42. radius: 25
  43. }
  44. // background with border around the Image
  45. Rectangle {
  46. visible: parent.iconVisible
  47. anchors.fill: parent
  48. color: parent.hovered ? parent.iconBgColorHovered : parent.iconBgColor
  49. }
  50. // label
  51. Text {
  52. id: label
  53. visible: parent.text !== ""
  54. text: parent.text
  55. font: parent.font
  56. color: parent.hovered ? parent.textColorHovered : parent.textColor
  57. anchors.fill: parent
  58. anchors.leftMargin: 10
  59. anchors.rightMargin: 10
  60. horizontalAlignment: Text.AlignHCenter
  61. verticalAlignment: Text.AlignVCenter
  62. elide: Text.ElideRight
  63. }
  64. // icon
  65. Image {
  66. id: icon
  67. visible: parent.imageSource !== ""
  68. anchors.centerIn: parent
  69. source: parent.imageSource
  70. sourceSize.width: visible ? 32 : 0
  71. sourceSize.height: visible ? 32 : 0
  72. }
  73. MouseArea {
  74. id: mouseArea
  75. anchors.fill: parent
  76. onClicked: parent.clicked()
  77. hoverEnabled: true
  78. }
  79. ToolTip {
  80. text: parent.tooltipText
  81. delay: 1000
  82. visible: text != "" && parent.hovered
  83. }
  84. }