LongClickRule.qml 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. import QtQuick
  2. import QtQuick.Controls
  3. import FluentUI
  4. import "../Component"
  5. Item {
  6. MirrorImage{
  7. id: mirrorImage
  8. anchors{
  9. left: parent.left
  10. top: parent.top
  11. }
  12. width: 1280
  13. height: 720 + 50
  14. imageWidth: 1280
  15. imageHeight: 720
  16. onRoi_red_changed: function(roi){
  17. if(typeof ruleFile.currentItem === "undefined"){
  18. return
  19. }
  20. ruleFile.currentItem.roiFront = roi
  21. }
  22. onRoi_green_changed: function(roi){
  23. if(typeof ruleFile.currentItem === "undefined"){
  24. return
  25. }
  26. ruleFile.currentItem.roiBack = roi
  27. }
  28. }
  29. RuleFile{
  30. id: ruleFile
  31. anchors{
  32. left: mirrorImage.right
  33. leftMargin: 10
  34. right: parent.right
  35. top: parent.top
  36. }
  37. height: 600
  38. addFunc: add
  39. editFunc: edit
  40. saveFunc: save
  41. onCurrentItemChanged: {
  42. if(currentItem === "" || typeof currentItem === "undefined"){
  43. return
  44. }
  45. var [x, y, width, height] = currentItem.roiFront.split(',')
  46. mirrorImage.roiRed_x = parseInt(x)
  47. mirrorImage.roiRed_y = parseInt(y)
  48. mirrorImage.roiRed_width = parseInt(width)
  49. mirrorImage.roiRed_height = parseInt(height)
  50. var [x, y, width, height] = currentItem.roiBack.split(',')
  51. mirrorImage.roiGreen_x = parseInt(x)
  52. mirrorImage.roiGreen_y = parseInt(y)
  53. mirrorImage.roiGreen_width = parseInt(width)
  54. mirrorImage.roiGreen_height = parseInt(height)
  55. }
  56. }
  57. FluArea {
  58. id: ruleArea
  59. anchors{
  60. left: mirrorImage.right
  61. leftMargin: 10
  62. right: parent.right
  63. top: ruleFile.bottom
  64. topMargin: 12
  65. bottom: parent.bottom
  66. }
  67. Column{
  68. id: coi
  69. anchors{
  70. top: parent.top
  71. bottom: parent.bottom
  72. left: parent.left
  73. leftMargin: 20
  74. right: parent.right
  75. rightMargin: 20
  76. }
  77. spacing: 5
  78. //头
  79. Item{
  80. width: coi.width
  81. height: 40
  82. FluText{
  83. anchors.left: parent.left
  84. anchors.verticalCenter: parent.verticalCenter
  85. text: "Editing rule"
  86. font: FluTextStyle.Subtitle
  87. }
  88. }
  89. //item name 这个参数项的名称
  90. Item{
  91. width: coi.width
  92. height: 40
  93. FluText{
  94. anchors.left: parent.left
  95. anchors.verticalCenter: parent.verticalCenter
  96. text: "Item name"
  97. font: FluTextStyle.BodyStrong
  98. }
  99. FluTextBox{
  100. id: itemName
  101. anchors{
  102. right: parent.right
  103. verticalCenter: parent.verticalCenter
  104. }
  105. placeholderText:"单行输入框"
  106. disabled: true
  107. text: (typeof ruleFile.currentItem === "undefined")? "" : ruleFile.currentItem.itemName
  108. width: 200
  109. }
  110. }
  111. // 文件名
  112. // roi front
  113. Item{
  114. width: coi.width
  115. height: 40
  116. FluText{
  117. anchors.left: parent.left
  118. anchors.verticalCenter: parent.verticalCenter
  119. text: "Roi front"
  120. font: FluTextStyle.BodyStrong
  121. }
  122. FluTextBox{
  123. id: roiFront
  124. anchors{
  125. right: parent.right
  126. verticalCenter: parent.verticalCenter
  127. }
  128. disabled: true
  129. text:(typeof ruleFile.currentItem === "undefined")? "" : ruleFile.currentItem.roiFront
  130. placeholderText:"0,0,100,100"
  131. width: 200
  132. }
  133. }
  134. //roi back
  135. Item{
  136. width: coi.width
  137. height: 40
  138. FluText{
  139. anchors.left: parent.left
  140. anchors.verticalCenter: parent.verticalCenter
  141. text: "Roi Back"
  142. font: FluTextStyle.BodyStrong
  143. }
  144. FluTextBox{
  145. id: roiBack
  146. anchors{
  147. right: parent.right
  148. verticalCenter: parent.verticalCenter
  149. }
  150. disabled: true
  151. text:(typeof ruleFile.currentItem === "undefined")? "" : ruleFile.currentItem.roiBack
  152. placeholderText:"0,0,100,100"
  153. width: 200
  154. }
  155. }
  156. //长按的时间间隔
  157. Item{
  158. width: coi.width
  159. height: 40
  160. FluText{
  161. anchors.left: parent.left
  162. anchors.verticalCenter: parent.verticalCenter
  163. text: "Duration"
  164. font: FluTextStyle.BodyStrong
  165. }
  166. FluTextBox{
  167. id: duration
  168. anchors{
  169. right: parent.right
  170. verticalCenter: parent.verticalCenter
  171. }
  172. width: 200
  173. text:(typeof ruleFile.currentItem === "undefined")? "" : ruleFile.currentItem.duration
  174. placeholderText:"1500"
  175. onEditingFinished: {
  176. if(typeof ruleFile.currentItem === "undefined"){
  177. return
  178. }
  179. ruleFile.currentItem.duration = parseInt(text)
  180. }
  181. }
  182. }
  183. //描述 description
  184. Item{
  185. width: coi.width
  186. height: 40
  187. FluText{
  188. anchors.left: parent.left
  189. anchors.verticalCenter: parent.verticalCenter
  190. text: "Description"
  191. font: FluTextStyle.BodyStrong
  192. }
  193. FluTextBox{
  194. id: description
  195. anchors{
  196. right: parent.right
  197. verticalCenter: parent.verticalCenter
  198. }
  199. width: 200
  200. text:(typeof ruleFile.currentItem === "undefined")? "" : ruleFile.currentItem.description
  201. placeholderText:"input your description"
  202. onEditingFinished: {
  203. if(typeof ruleFile.currentItem === "undefined"){
  204. return
  205. }
  206. ruleFile.currentItem.description = text
  207. }
  208. }
  209. }
  210. }
  211. }
  212. // 帮助
  213. FluArea{
  214. id: ruleHelp
  215. anchors{
  216. left: parent.left
  217. right: ruleArea.left
  218. rightMargin: 10
  219. top: mirrorImage.bottom
  220. topMargin: 10
  221. bottom: parent.bottom
  222. }
  223. FluText{
  224. leftPadding: 12
  225. topPadding: 12
  226. text: "红色的框(Roi front)表示这一个项点击的默认范围,绿色的框(Roi back)表示备用的范围。
  227. 在移动边框时右边的roi并不会实时显示,当切换软件的焦点时更新显示,但是具体的数值是更新的。
  228. 投屏的设置最上边点击即可"
  229. }
  230. }
  231. function add(){
  232. const item ={}
  233. item["itemName"] = "new"
  234. item["roiFront"] = "0,0,100,100"
  235. item["roiBack"] = "0,0,100,100"
  236. item["duration"] = 1500
  237. item["description"] = "description"
  238. showSuccess("Add new item")
  239. return item
  240. }
  241. function edit(model){
  242. }
  243. function save(){
  244. const data = []
  245. for(var i=0; i<ruleFile.list_model.count; i++){
  246. const item = ruleFile.list_model.get(i)
  247. const itemData = {}
  248. itemData["itemName"] = item["itemName"]
  249. itemData["roiFront"] = item["roiFront"]
  250. itemData["roiBack"] = item["roiBack"]
  251. itemData["duration"] = item["duration"]
  252. itemData["description"] = item["description"]
  253. data.push(itemData)
  254. }
  255. ruleFile.rule_file.write_file(ruleFile.file, JSON.stringify(data))
  256. showSuccess("Save file")
  257. }
  258. }