SwipeRule.qml 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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. FComboBox{
  167. id: mode
  168. anchors{
  169. right: parent.right
  170. verticalCenter: parent.verticalCenter
  171. }
  172. width: 200
  173. model: ["defalut", "vector"]
  174. currentIndex: if(typeof ruleFile.currentItem !== "undefined"){
  175. if(ruleFile.currentItem.mode === "default"){
  176. return 0
  177. }else{
  178. return 1
  179. }
  180. }else{return 0}
  181. onActivated: {
  182. console.debug('接收',currentIndex, currentText)
  183. if(currentIndex === 0){
  184. ruleFile.currentItem.mode = "default"
  185. }
  186. else if(currentIndex === 1){
  187. ruleFile.currentItem.mode = "vector"
  188. }
  189. }
  190. }
  191. }
  192. //描述 description
  193. Item{
  194. width: coi.width
  195. height: 40
  196. FluText{
  197. anchors.left: parent.left
  198. anchors.verticalCenter: parent.verticalCenter
  199. text: "Description"
  200. font: FluTextStyle.BodyStrong
  201. }
  202. FluTextBox{
  203. id: description
  204. anchors{
  205. right: parent.right
  206. verticalCenter: parent.verticalCenter
  207. }
  208. width: 200
  209. text:(typeof ruleFile.currentItem === "undefined")? "" : ruleFile.currentItem.description
  210. placeholderText:"input your description"
  211. onEditingFinished: {
  212. if(typeof ruleFile.currentItem === "undefined"){
  213. return
  214. }
  215. ruleFile.currentItem.description = text
  216. }
  217. }
  218. }
  219. }
  220. }
  221. // 帮助
  222. FluArea{
  223. id: ruleHelp
  224. anchors{
  225. left: parent.left
  226. right: ruleArea.left
  227. rightMargin: 10
  228. top: mirrorImage.bottom
  229. topMargin: 10
  230. bottom: parent.bottom
  231. }
  232. FluText{
  233. leftPadding: 12
  234. topPadding: 12
  235. text: "红色的框(Roi front)表示滑动的起始范围,绿色的框(Roi back)表示滑动的停止范围。
  236. 在移动边框时右边的roi并不会实时显示,当切换软件的焦点时更新显示,但是具体的数值是更新的。
  237. 投屏的设置最上边点击即可"
  238. }
  239. }
  240. function add(){
  241. const item ={}
  242. item["itemName"] = "new"
  243. item["roiFront"] = "0,0,100,100"
  244. item["roiBack"] = "0,0,100,100"
  245. item["mode"] = "default"
  246. item["description"] = "description"
  247. showSuccess("Add new item")
  248. return item
  249. }
  250. function edit(model){
  251. }
  252. function save(){
  253. const data = []
  254. for(var i=0; i<ruleFile.list_model.count; i++){
  255. const item = ruleFile.list_model.get(i)
  256. const itemData = {}
  257. itemData["itemName"] = item["itemName"]
  258. itemData["roiFront"] = item["roiFront"]
  259. itemData["roiBack"] = item["roiBack"]
  260. itemData["mode"] = item["mode"]
  261. itemData["description"] = item["description"]
  262. data.push(itemData)
  263. }
  264. ruleFile.rule_file.write_file(ruleFile.file, JSON.stringify(data, null, " "))
  265. showSuccess("Save file")
  266. }
  267. }