ClickRule.qml 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  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. // Item{
  113. // width: coi.width
  114. // height: 40
  115. // FluText{
  116. // anchors.left: parent.left
  117. // anchors.verticalCenter: parent.verticalCenter
  118. // text: "Image name"
  119. // font: FluTextStyle.BodyStrong
  120. // }
  121. // FluTextBox{
  122. // id: imageName
  123. // anchors{
  124. // right: parent.right
  125. // verticalCenter: parent.verticalCenter
  126. // }
  127. // disabled: true
  128. // text:(typeof ruleFile.currentItem === "undefined")? "" : ruleFile.currentItem.imageName
  129. // placeholderText:"Save image name"
  130. // width: 200
  131. // }
  132. // }
  133. // roi front
  134. Item{
  135. width: coi.width
  136. height: 40
  137. FluText{
  138. anchors.left: parent.left
  139. anchors.verticalCenter: parent.verticalCenter
  140. text: "Roi front"
  141. font: FluTextStyle.BodyStrong
  142. }
  143. FluTextBox{
  144. id: roiFront
  145. anchors{
  146. right: parent.right
  147. verticalCenter: parent.verticalCenter
  148. }
  149. disabled: true
  150. text:(typeof ruleFile.currentItem === "undefined")? "" : ruleFile.currentItem.roiFront
  151. placeholderText:"0,0,100,100"
  152. width: 200
  153. }
  154. }
  155. //roi back
  156. Item{
  157. width: coi.width
  158. height: 40
  159. FluText{
  160. anchors.left: parent.left
  161. anchors.verticalCenter: parent.verticalCenter
  162. text: "Roi Back"
  163. font: FluTextStyle.BodyStrong
  164. }
  165. FluTextBox{
  166. id: roiBack
  167. anchors{
  168. right: parent.right
  169. verticalCenter: parent.verticalCenter
  170. }
  171. disabled: true
  172. text:(typeof ruleFile.currentItem === "undefined")? "" : ruleFile.currentItem.roiBack
  173. placeholderText:"0,0,100,100"
  174. width: 200
  175. }
  176. }
  177. //找图的方法
  178. // Item{
  179. // width: coi.width
  180. // height: 40
  181. // FluText{
  182. // anchors.left: parent.left
  183. // anchors.verticalCenter: parent.verticalCenter
  184. // text: "Find method"
  185. // font: FluTextStyle.BodyStrong
  186. // }
  187. // FComboBox{
  188. // id: method
  189. // anchors{
  190. // right: parent.right
  191. // verticalCenter: parent.verticalCenter
  192. // }
  193. // width: 200
  194. // currentIndex: 0
  195. // model: ["Template matching"]
  196. // onActivated: {
  197. // }
  198. // }
  199. // }
  200. //阈值
  201. // Item{
  202. // width: coi.width
  203. // height: 40
  204. // FluText{
  205. // anchors.left: parent.left
  206. // anchors.verticalCenter: parent.verticalCenter
  207. // text: "Threshod"
  208. // font: FluTextStyle.BodyStrong
  209. // }
  210. // FluTextBox{
  211. // id: threshold
  212. // anchors{
  213. // right: parent.right
  214. // verticalCenter: parent.verticalCenter
  215. // }
  216. // width: 200
  217. // text:(typeof ruleFile.currentItem === "undefined")? "" : ruleFile.currentItem.threshold
  218. // placeholderText:"0.8"
  219. // onEditingFinished: {
  220. // if(typeof ruleFile.currentItem === "undefined"){
  221. // return
  222. // }
  223. // ruleFile.currentItem.threshold = parseFloat(text)
  224. // }
  225. // }
  226. // }
  227. //描述 description
  228. Item{
  229. width: coi.width
  230. height: 40
  231. FluText{
  232. anchors.left: parent.left
  233. anchors.verticalCenter: parent.verticalCenter
  234. text: "Description"
  235. font: FluTextStyle.BodyStrong
  236. }
  237. FluTextBox{
  238. id: description
  239. anchors{
  240. right: parent.right
  241. verticalCenter: parent.verticalCenter
  242. }
  243. width: 200
  244. text:(typeof ruleFile.currentItem === "undefined")? "" : ruleFile.currentItem.description
  245. placeholderText:"input your description"
  246. onEditingFinished: {
  247. if(typeof ruleFile.currentItem === "undefined"){
  248. return
  249. }
  250. ruleFile.currentItem.description = text
  251. }
  252. }
  253. }
  254. }
  255. }
  256. // 帮助
  257. FluArea{
  258. id: ruleHelp
  259. anchors{
  260. left: parent.left
  261. right: ruleArea.left
  262. rightMargin: 10
  263. top: mirrorImage.bottom
  264. topMargin: 10
  265. bottom: parent.bottom
  266. }
  267. FluText{
  268. leftPadding: 12
  269. topPadding: 12
  270. text: "红色的框(Roi front)表示这一个项点击的默认范围,绿色的框(Roi back)表示备用的范围。
  271. 在移动边框时右边的roi并不会实时显示,当切换软件的焦点时更新显示,但是具体的数值是更新的。
  272. 投屏的设置最上边点击即可"
  273. }
  274. }
  275. function add(){
  276. const item ={}
  277. item["itemName"] = "new"
  278. item["roiFront"] = "0,0,100,100"
  279. item["roiBack"] = "0,0,100,100"
  280. item["description"] = "description"
  281. showSuccess("Add new item")
  282. return item
  283. }
  284. function edit(model){
  285. }
  286. function save(){
  287. const data = []
  288. for(var i=0; i<ruleFile.list_model.count; i++){
  289. const item = ruleFile.list_model.get(i)
  290. const itemData = {}
  291. itemData["itemName"] = item["itemName"]
  292. itemData["roiFront"] = item["roiFront"]
  293. itemData["roiBack"] = item["roiBack"]
  294. itemData["description"] = item["description"]
  295. data.push(itemData)
  296. }
  297. ruleFile.rule_file.write_file(ruleFile.file, JSON.stringify(data))
  298. showSuccess("Save file")
  299. }
  300. }