ListRule.qml 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  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. ruleFile.roiBack = roi
  28. }
  29. }
  30. RuleFile2{
  31. id: ruleFile
  32. anchors{
  33. left: mirrorImage.right
  34. leftMargin: 10
  35. right: parent.right
  36. top: parent.top
  37. }
  38. height: 600
  39. addFunc: add
  40. editFunc: edit
  41. saveFunc: save
  42. onCurrentItemChanged: {
  43. if(currentItem === "" || typeof currentItem === "undefined"){
  44. return
  45. }
  46. var [x, y, width, height] = currentItem.roiFront.split(',')
  47. mirrorImage.roiRed_x = parseInt(x)
  48. mirrorImage.roiRed_y = parseInt(y)
  49. mirrorImage.roiRed_width = parseInt(width)
  50. mirrorImage.roiRed_height = parseInt(height)
  51. }
  52. onRoiBackChanged: {
  53. var [x, y, width, height] = ruleFile.roiBack.split(',')
  54. mirrorImage.roiGreen_x = parseInt(x)
  55. mirrorImage.roiGreen_y = parseInt(y)
  56. mirrorImage.roiGreen_width = parseInt(width)
  57. mirrorImage.roiGreen_height = parseInt(height)
  58. }
  59. }
  60. FluArea {
  61. id: ruleArea
  62. anchors{
  63. left: mirrorImage.right
  64. leftMargin: 10
  65. right: parent.right
  66. top: ruleFile.bottom
  67. topMargin: 12
  68. bottom: parent.bottom
  69. }
  70. Column{
  71. id: coi
  72. anchors{
  73. top: parent.top
  74. bottom: parent.bottom
  75. left: parent.left
  76. leftMargin: 20
  77. right: parent.right
  78. rightMargin: 20
  79. }
  80. spacing: 5
  81. //头
  82. Item{
  83. width: coi.width
  84. height: 40
  85. FluText{
  86. anchors.left: parent.left
  87. anchors.verticalCenter: parent.verticalCenter
  88. text: "Editing rule"
  89. font: FluTextStyle.Subtitle
  90. }
  91. }
  92. // name 这个参数项的名称
  93. Item{
  94. width: coi.width
  95. height: 40
  96. FluText{
  97. anchors.left: parent.left
  98. anchors.verticalCenter: parent.verticalCenter
  99. text: "List name"
  100. font: FluTextStyle.BodyStrong
  101. }
  102. FluTextBox{
  103. id: itemName
  104. anchors{
  105. right: parent.right
  106. verticalCenter: parent.verticalCenter
  107. }
  108. placeholderText:"itemName"
  109. disabled: false
  110. text: ruleFile.name
  111. width: 200
  112. onEditingFinished: {
  113. ruleFile.name = text
  114. }
  115. }
  116. }
  117. // roi front
  118. Item{
  119. width: coi.width
  120. height: 40
  121. FluText{
  122. anchors.left: parent.left
  123. anchors.verticalCenter: parent.verticalCenter
  124. text: "Roi front"
  125. font: FluTextStyle.BodyStrong
  126. }
  127. FluTextBox{
  128. id: roiFront
  129. anchors{
  130. right: parent.right
  131. verticalCenter: parent.verticalCenter
  132. }
  133. disabled: true
  134. text:(typeof ruleFile.currentItem === "undefined")? "" : ruleFile.currentItem.roiFront
  135. placeholderText:"0,0,100,100"
  136. width: 200
  137. }
  138. }
  139. //roi back
  140. Item{
  141. width: coi.width
  142. height: 40
  143. FluText{
  144. anchors.left: parent.left
  145. anchors.verticalCenter: parent.verticalCenter
  146. text: "Roi Back"
  147. font: FluTextStyle.BodyStrong
  148. }
  149. FluTextBox{
  150. id: roiBack
  151. anchors{
  152. right: parent.right
  153. verticalCenter: parent.verticalCenter
  154. }
  155. disabled: true
  156. text: ruleFile.roiBack
  157. placeholderText:"0,0,100,100"
  158. width: 200
  159. }
  160. }
  161. //水平还是竖直方向
  162. Item{
  163. width: coi.width
  164. height: 40
  165. FluText{
  166. anchors.left: parent.left
  167. anchors.verticalCenter: parent.verticalCenter
  168. text: "Direction"
  169. font: FluTextStyle.BodyStrong
  170. }
  171. FComboBox{
  172. id: direction
  173. anchors{
  174. right: parent.right
  175. verticalCenter: parent.verticalCenter
  176. }
  177. width: 200
  178. currentIndex: if(ruleFile.direction === "vertical"){
  179. return 0
  180. }else{
  181. return 1
  182. }
  183. model: ["vertical", "horizontal"]
  184. onActivated: {
  185. if(currentIndex === 0){
  186. ruleFile.direction = "vertical"
  187. }
  188. else{
  189. ruleFile.direction = "horizontal"
  190. }
  191. }
  192. }
  193. }
  194. // 类型 图片还是ocr
  195. Item{
  196. width: coi.width
  197. height: 40
  198. FluText{
  199. anchors.left: parent.left
  200. anchors.verticalCenter: parent.verticalCenter
  201. text: "Type"
  202. font: FluTextStyle.BodyStrong
  203. }
  204. FComboBox{
  205. id: type
  206. anchors{
  207. right: parent.right
  208. verticalCenter: parent.verticalCenter
  209. }
  210. width: 200
  211. model: ["image", "ocr"]
  212. currentIndex: {if(ruleFile.type === "image"){
  213. return 0
  214. }else{
  215. return 1
  216. }}
  217. onActivated: {
  218. if(currentIndex === 0){
  219. ruleFile.type = "image"
  220. }
  221. else{
  222. ruleFile.type = "ocr"
  223. }
  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:ruleFile.description
  245. placeholderText:"input your description"
  246. onEditingFinished: {
  247. ruleFile.description = text
  248. }
  249. }
  250. }
  251. }
  252. }
  253. // 帮助
  254. FluArea{
  255. id: ruleHelp
  256. anchors{
  257. left: parent.left
  258. right: ruleArea.left
  259. rightMargin: 10
  260. top: mirrorImage.bottom
  261. topMargin: 10
  262. bottom: parent.bottom
  263. }
  264. FluText{
  265. leftPadding: 12
  266. topPadding: 12
  267. text: "红色的框(Roi front)表示这一个项要匹配的图片,绿色的框(Roi back)表示匹配的范围。
  268. 在移动边框时右边的roi并不会实时显示,当切换软件的焦点时更新显示。但是具体的数值是更新的,可以放心的保存截图"
  269. }
  270. FluFilledButton{
  271. anchors{
  272. right: parent.right
  273. rightMargin: 10
  274. top: parent.top
  275. topMargin: 10
  276. }
  277. text:"Save image"
  278. onClicked: {
  279. const i = ruleFile.file.lastIndexOf("/")
  280. const imagepath = ruleFile.file.substring(0, i)
  281. mirrorImage.save_target_image(ruleFile.currentItem.roiFront, imagepath +"/"+ruleFile.currentItem.itemName+'.png')
  282. showSuccess("Save target image")
  283. }
  284. }
  285. }
  286. function add(){
  287. const item ={}
  288. item["itemName"] = "new"
  289. item["roiFront"] = "0,0,100,100"
  290. showSuccess("Add new item")
  291. return item
  292. }
  293. function edit(model){
  294. }
  295. function save(){
  296. const data = {}
  297. const list = []
  298. for(var i=0; i<ruleFile.list_model.count; i++){
  299. const item = ruleFile.list_model.get(i)
  300. const itemData = {}
  301. itemData["itemName"] = item["itemName"]
  302. itemData["roiFront"] = item["roiFront"]
  303. list.push(itemData)
  304. }
  305. data["name"] = ruleFile.name
  306. data["direction"] = ruleFile.direction
  307. data["type"] = ruleFile.type
  308. data["roiBack"] = ruleFile.roiBack
  309. data["description"] = ruleFile.description
  310. data["list"] = list
  311. ruleFile.rule_file.write_file(ruleFile.file, JSON.stringify(data, null, " "))
  312. showSuccess("Save file")
  313. }
  314. }