ModernControlButton.qml 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import QtQuick 2.15
  2. import QtQuick.Controls 2.15
  3. import QtQuick.Layouts 1.15
  4. import "." as Components
  5. // Pill button — flat fill, darker while pressed, no hover states (touch-only
  6. // device) and no effects layers (linuxfb). `icon` takes a Material icon name
  7. // resolved by Icon.qml. `outlined` renders the quiet variant: transparent
  8. // fill, buttonColor ring + label.
  9. Rectangle {
  10. id: root
  11. property alias text: buttonLabel.text
  12. property string icon: ""
  13. property color buttonColor: Components.ThemeManager.accent
  14. // Fill variant picks label contrast from the fill's lightness, so amber
  15. // gets ink text and rust/sage get bone automatically.
  16. property color textColor: outlined
  17. ? buttonColor
  18. : (buttonColor.hslLightness > 0.55 ? "#241a0c" : "#fdf8ee")
  19. property bool outlined: false
  20. property bool enabled: true
  21. property int fontSize: Components.ThemeManager.fontSizeBody
  22. property int iconSize: -1 // -1 means fontSize + 4
  23. signal clicked()
  24. implicitHeight: Components.ThemeManager.touchTarget
  25. radius: height / 2
  26. color: {
  27. if (outlined)
  28. return mouseArea.pressed ? Components.ThemeManager.pressedColor : "transparent"
  29. return mouseArea.pressed ? Qt.darker(buttonColor, 1.15) : buttonColor
  30. }
  31. opacity: enabled ? 1.0 : 0.45
  32. border.width: outlined ? 1 : 0
  33. border.color: buttonColor
  34. scale: mouseArea.pressed ? 0.97 : 1.0
  35. Behavior on scale {
  36. NumberAnimation { duration: 100; easing.type: Easing.OutQuad }
  37. }
  38. RowLayout {
  39. anchors.centerIn: parent
  40. spacing: Components.ThemeManager.spaceSm
  41. Components.Icon {
  42. name: root.icon
  43. size: root.iconSize > 0 ? root.iconSize : root.fontSize + 4
  44. color: root.textColor
  45. visible: root.icon !== ""
  46. }
  47. Label {
  48. id: buttonLabel
  49. color: root.textColor
  50. font.family: Components.ThemeManager.fontDisplay
  51. font.pixelSize: root.fontSize
  52. visible: text !== ""
  53. }
  54. }
  55. MouseArea {
  56. id: mouseArea
  57. anchors.fill: parent
  58. enabled: root.enabled
  59. onClicked: root.clicked()
  60. }
  61. }