MenuButton.qml 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import QtQuick 2.5
  2. import QtQuick.Controls 1.4
  3. //import Qt.labs.controls 1.0
  4. import QtQuick.Controls 2.0
  5. import QtQuick.Controls.Styles 1.3
  6. import QtGraphicalEffects 1.0
  7. import ApplicationLauncher 1.0
  8. Button {
  9. property double buttGreyed: 0.0 //Saturation -1.0 greyed ... 0.0 colored
  10. property int imgBorder: 20 // in percent of parent.height defaults to 20%
  11. property string menuQML // next UI to goto
  12. property string menuImage // Image name
  13. // property string menuText // Text to display in Button Box
  14. property alias menuText: menTXT.text
  15. signal itemClicked
  16. width: parent.width
  17. height: parent.height
  18. background: Rectangle {
  19. id: backrectBUTT
  20. border.width: 0.0
  21. }
  22. Rectangle {
  23. id: buttRECT
  24. anchors.centerIn: parent
  25. //border.color: "red"
  26. //border.width: 2
  27. width: backrectBUTT.width - backrectBUTT.width * (parent.imgBorder / 100.0)
  28. height: backrectBUTT.height - backrectBUTT.height * (parent.imgBorder / 100.0)
  29. Image {
  30. id: idIMG
  31. anchors.centerIn: parent
  32. anchors.fill: parent
  33. source: menuImage
  34. fillMode: Image.PreserveAspectFit
  35. sourceSize: Qt.size(backrectBUTT.width ,
  36. backrectBUTT.height )
  37. width: backrectBUTT.width
  38. height: backrectBUTT.height
  39. onStatusChanged: {
  40. if (status == Image.Ready) {
  41. console.log(menuImage + '---' + backrectBUTT.width + ' ' + backrectBUTT.height + '==' + paintedWidth + ' ' + paintedHeight);
  42. }
  43. }
  44. Item {
  45. anchors.centerIn: parent
  46. width: idIMG.paintedWidth
  47. height: idIMG.paintedHeight
  48. Text {
  49. id: menTXT
  50. anchors.bottom: parent.bottom
  51. anchors.bottomMargin: 3
  52. x: 2
  53. width: parent.width - 2 * x
  54. color: "white"
  55. font.pixelSize: (parent.height * 0.21) / 2
  56. wrapMode: Text.WordWrap
  57. text: menuText
  58. }
  59. }
  60. }
  61. HueSaturation {
  62. id: idSaturation
  63. anchors.fill: idIMG
  64. source: idIMG
  65. hue: 0.0
  66. saturation: buttGreyed
  67. lightness: 0.0
  68. }
  69. }
  70. onClicked: {
  71. sysinfo.beep();
  72. itemClicked();
  73. }
  74. }