TouchSelectionMenu.qml 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. // Copyright (C) 2018 The Qt Company Ltd.
  2. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
  3. import QtQuick
  4. import QtQuick.Layouts
  5. Rectangle {
  6. id: menu
  7. signal cutTriggered
  8. signal copyTriggered
  9. signal pasteTriggered
  10. signal contextMenuTriggered
  11. property bool isCutEnabled: false
  12. property bool isCopyEnabled: false
  13. property bool isPasteEnabled: false
  14. property color borderColor: "darkGray"
  15. property color bgColor: "white"
  16. radius: 4
  17. border.color: borderColor
  18. color: borderColor
  19. antialiasing: true
  20. RowLayout {
  21. anchors.fill: parent
  22. spacing: parent.border.width
  23. anchors.margins: parent.border.width
  24. Rectangle {
  25. Layout.fillHeight: true
  26. Layout.fillWidth: true
  27. radius: menu.radius
  28. color: bgColor
  29. visible: isCutEnabled
  30. Text {
  31. id: cutText
  32. anchors.centerIn: parent
  33. text: "Cut"
  34. }
  35. MouseArea {
  36. anchors.fill: parent
  37. onPressed: {
  38. parent.color = borderColor;
  39. cutText.color = "white";
  40. }
  41. onReleased: {
  42. parent.color = bgColor;
  43. cutText.color = "black";
  44. cutTriggered();
  45. }
  46. }
  47. }
  48. Rectangle {
  49. Layout.fillHeight: true
  50. Layout.fillWidth: true
  51. radius: menu.radius
  52. color: bgColor
  53. visible: isCopyEnabled
  54. Text {
  55. id: copyText
  56. anchors.centerIn: parent
  57. text: "Copy"
  58. }
  59. MouseArea {
  60. anchors.fill: parent
  61. onPressed: {
  62. parent.color = borderColor;
  63. copyText.color = "white";
  64. }
  65. onReleased: {
  66. parent.color = bgColor;
  67. copyText.color = "black";
  68. copyTriggered();
  69. }
  70. }
  71. }
  72. Rectangle {
  73. Layout.fillHeight: true
  74. Layout.fillWidth: true
  75. radius: menu.radius
  76. color: bgColor
  77. visible: isPasteEnabled
  78. Text {
  79. id: pasteText
  80. anchors.centerIn: parent
  81. text: "Paste"
  82. }
  83. MouseArea {
  84. anchors.fill: parent
  85. onPressed: {
  86. parent.color = borderColor;
  87. pasteText.color = "white";
  88. }
  89. onReleased: {
  90. parent.color = bgColor;
  91. pasteText.color = "black";
  92. pasteTriggered();
  93. }
  94. }
  95. }
  96. Rectangle {
  97. Layout.fillHeight: true
  98. Layout.fillWidth: true
  99. radius: menu.radius
  100. color: bgColor
  101. Text {
  102. id: contextMenuText
  103. anchors.centerIn: parent
  104. text: "..."
  105. }
  106. MouseArea {
  107. anchors.fill: parent
  108. onPressed: {
  109. parent.color = borderColor;
  110. contextMenuText.color = "white";
  111. }
  112. onReleased: {
  113. parent.color = bgColor;
  114. contextMenuText.color = "black";
  115. contextMenuTriggered();
  116. }
  117. }
  118. }
  119. }
  120. }