MirrorImage.qml 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. import QtQuick 2.0
  2. import QtQuick.Controls
  3. import QtQuick.Dialogs
  4. import FluentUI
  5. import Oas
  6. import "../Global"
  7. Item {
  8. id: imageItem
  9. implicitWidth: 1280
  10. implicitHeight: 720 + 50
  11. property alias imageWidth: paintImage.width
  12. property alias imageHeight: paintImage.height
  13. property alias roiRed_x: roi_Red.x
  14. property alias roiRed_y: roi_Red.y
  15. property alias roiRed_width: roi_Red.width
  16. property alias roiRed_height: roi_Red.height
  17. property alias roiGreen_x: roi_Green.x
  18. property alias roiGreen_y: roi_Green.y
  19. property alias roiGreen_width: roi_Green.width
  20. property alias roiGreen_height: roi_Green.height
  21. signal roi_red_changed(string roi)
  22. signal roi_green_changed(string roi)
  23. onRoiRed_xChanged: {
  24. // roi_red_changed( '${roiRed_x},${roiRed_y},${roiRed_width},${roiRed_height}' )
  25. roi_red_changed( roiRed_x + "," + roiRed_y + "," + roiRed_width + "," + roiRed_height)
  26. }
  27. onRoiRed_yChanged: {
  28. roi_red_changed( roiRed_x + "," + roiRed_y + "," + roiRed_width + "," + roiRed_height)
  29. }
  30. onRoiRed_widthChanged: {
  31. roi_red_changed( roiRed_x + "," + roiRed_y + "," + roiRed_width + "," + roiRed_height)
  32. }
  33. onRoiRed_heightChanged: {
  34. roi_red_changed( roiRed_x + "," + roiRed_y + "," + roiRed_width + "," + roiRed_height)
  35. }
  36. onRoiGreen_xChanged: {
  37. roi_green_changed( roiGreen_x + "," + roiGreen_y + "," + roiGreen_width + "," + roiGreen_height )
  38. }
  39. onRoiGreen_yChanged: {
  40. roi_green_changed( roiGreen_x + "," + roiGreen_y + "," + roiGreen_width + "," + roiGreen_height )
  41. }
  42. onRoiGreen_widthChanged: {
  43. roi_green_changed( roiGreen_x + "," + roiGreen_y + "," + roiGreen_width + "," + roiGreen_height )
  44. }
  45. onRoiGreen_heightChanged: {
  46. roi_green_changed( roiGreen_x + "," + roiGreen_y + "," + roiGreen_width + "," + roiGreen_height )
  47. }
  48. enum RoiMode {
  49. None,
  50. Same,
  51. Include
  52. }
  53. property int roi_mode: MirrorImage.RoiMode.None
  54. Item{
  55. anchors{
  56. left: parent.left
  57. top: parent.top
  58. topMargin: 45
  59. }
  60. width: imageWidth
  61. height: imageHeight
  62. PaintImage{
  63. id: paintImage
  64. width: 1280
  65. height: 720
  66. Timer{
  67. id: timerImage
  68. repeat: true
  69. running: if(imageSoucre.currentText === "Device Image"){return true}
  70. else{ return false}
  71. interval: 1000
  72. onTriggered: {
  73. paintImage.update_image()
  74. }
  75. }
  76. function update_image(){
  77. if(imageSoucre.currentText === "Local Image"){
  78. const imagePath = localImageName.text
  79. if(!imagePath.startsWith("file:///")){
  80. return
  81. }
  82. paintImage.set_local(imagePath)
  83. }
  84. else{
  85. const i = process_manager.gui_mirror_image(MainEvent.scriptName)
  86. paintImage.image = i
  87. }
  88. }
  89. Component.onCompleted:{
  90. timerImage.start()
  91. }
  92. }
  93. Rectangle{
  94. id: roi_Green // 默认第二个是 back
  95. width: 100
  96. height: 100
  97. color: "transparent"
  98. border.width: 3
  99. border.color: "green"
  100. ResizableRectangle{
  101. resizeTarget: roi_Green//设置调整目标ID
  102. }
  103. }
  104. Rectangle{
  105. id: roi_Red // 默认第一个是红色的front
  106. width: 100
  107. height: 100
  108. color: "transparent"
  109. border.width: 1
  110. border.color: "red"
  111. ResizableRectangle{
  112. resizeTarget: roi_Red//设置调整目标ID
  113. }
  114. onXChanged: {
  115. if(roi_mode === MirrorImage.RoiMode.Include){
  116. if(roi_Red.x < roi_Green.x || roi_Red.x+roi_Red.width > roi_Green.x+roi_Green.width){
  117. roi_Red.x = roi_Green.x + roi_Green.width/2 - roi_Red.width/2
  118. }
  119. }
  120. else if(roi_mode === MirrorImage.RoiMode.Same){
  121. roi_Green.x = roi_Red.x
  122. }
  123. }
  124. onYChanged: {
  125. if(roi_mode === MirrorImage.RoiMode.Include){
  126. if(roi_Red.y < roi_Green.y || roi_Red.y+roi_Red.height > roi_Green.y+roi_Green.height){
  127. roi_Red.y = roi_Green.y + roi_Green.height/2 - roi_Red.height/2
  128. }
  129. }
  130. else if(roi_mode === MirrorImage.RoiMode.Same){
  131. roi_Green.y = roi_Red.y
  132. }
  133. }
  134. onWidthChanged: {
  135. if(roi_mode === MirrorImage.RoiMode.Include){
  136. if(roi_Red.width > roi_Green.width){
  137. roi_Red.width = roi_Green.width - 5
  138. }
  139. }
  140. else if(roi_mode === MirrorImage.RoiMode.Same){
  141. roi_Green.width = roi_Red.width
  142. }
  143. }
  144. onHeightChanged: {
  145. if(roi_mode === MirrorImage.RoiMode.Include){
  146. if(roi_Red.height > roi_Green.height){
  147. roi_Red.height = roi_Green.height - 5
  148. }
  149. }
  150. else if(roi_mode === MirrorImage.RoiMode.Same){
  151. roi_Green.height = roi_Red.height
  152. }
  153. }
  154. }
  155. }
  156. FluExpander{
  157. id: imageExpander
  158. headerText: qsTr("Screen Settings")
  159. width: parent.width
  160. anchors.left: parent.left
  161. anchors.top: parent.top
  162. contentHeight: paintImage.height
  163. Column{
  164. anchors.fill: parent
  165. anchors.leftMargin: 20
  166. // 设置你的图片源
  167. Item{
  168. width: imageExpander.width
  169. height: 50
  170. FluText{
  171. anchors.left: parent.left
  172. anchors.verticalCenter: parent.verticalCenter
  173. text: "Image Source"
  174. }
  175. FComboBox{
  176. id: imageSoucre
  177. anchors{
  178. left: parent.left
  179. leftMargin: 150
  180. verticalCenter: parent.verticalCenter
  181. }
  182. width: 200
  183. model: ["Device Image", "Local Image"]
  184. Component.onCompleted:{
  185. currentIndex = 0
  186. }
  187. }
  188. }
  189. // 设置你的本地的图片地址
  190. Item{
  191. width: imageExpander.width
  192. height: 50
  193. FluText{
  194. anchors.left: parent.left
  195. anchors.verticalCenter: parent.verticalCenter
  196. text: "Local Image Name"
  197. }
  198. FluFilledButton{
  199. id: localImageName
  200. anchors{
  201. left: parent.left
  202. leftMargin: 150
  203. verticalCenter: parent.verticalCenter
  204. }
  205. width: 200
  206. text:"select your image"
  207. clip: true
  208. // horizontalAlignment: Text.AlignRight
  209. // elide: Text.ElideRight
  210. onClicked: {
  211. imageFileDialog.open()
  212. }
  213. }
  214. FileDialog{
  215. id: imageFileDialog
  216. title: "select your image"
  217. nameFilters: ["Image Files (*.png *.jpg)"]
  218. onAccepted: {
  219. const selectedUrl = imageFileDialog.selectedFile.toString()
  220. localImageName.text = selectedUrl
  221. paintImage.update_image()
  222. }
  223. }
  224. }
  225. // 设置两个框的交互模式
  226. Item{
  227. width: imageExpander.width
  228. height: 50
  229. FluText{
  230. anchors.left: parent.left
  231. anchors.verticalCenter: parent.verticalCenter
  232. text: "ROI Model"
  233. }
  234. FComboBox{
  235. id: roiModel
  236. anchors{
  237. left: parent.left
  238. verticalCenter: parent.verticalCenter
  239. leftMargin: 150
  240. }
  241. width: 200
  242. model: ["None", "Same Size", "Include", ]
  243. function setMode(){
  244. if(currentText === "None"){
  245. imageItem.roi_mode = MirrorImage.RoiMode.None
  246. }
  247. else if(currentText === "Same Size"){
  248. imageItem.roi_mode = MirrorImage.RoiMode.Same
  249. }
  250. else{
  251. imageItem.roi_mode = MirrorImage.RoiMode.Include
  252. }
  253. }
  254. function updateRoi(){
  255. if(roi_mode === MirrorImage.RoiMode.Include){
  256. roi_Red.x = roi_Green.x + 5
  257. roi_Red.y = roi_Green.y + 5
  258. roi_Red.width = roi_Green.width - 5
  259. roi_Red.height = roi_Green.height - 5
  260. }
  261. else if(roi_mode === MirrorImage.RoiMode.Same){
  262. roi_Red.x = roi_Green.x
  263. roi_Red.y = roi_Green.y
  264. roi_Red.width = roi_Green.width
  265. roi_Red.height = roi_Green.height
  266. }
  267. }
  268. onActivated: {
  269. setMode()
  270. updateRoi()
  271. }
  272. }
  273. }
  274. // 设置显示的帧率
  275. Item{
  276. width: imageExpander.width
  277. height: 50
  278. FluText{
  279. anchors.left: parent.left
  280. anchors.verticalCenter: parent.verticalCenter
  281. text: "Frame Rate"
  282. }
  283. FluSlider{
  284. id: frameRate
  285. anchors{
  286. left: parent.left
  287. verticalCenter: parent.verticalCenter
  288. leftMargin: 150
  289. }
  290. size: 200
  291. value: 2
  292. maxValue: 10
  293. onReleased: {
  294. if(value > 0){
  295. timerImage.interval = 1000 / value
  296. }
  297. }
  298. }
  299. }
  300. // 帮助
  301. Item{
  302. width: imageExpander.width
  303. height: 50
  304. FluText{
  305. anchors.left: parent.left
  306. anchors.verticalCenter: parent.verticalCenter
  307. text: "python+qml 就别想着高帧率了,而且是以截图方式而不是视频流"
  308. }
  309. }
  310. }
  311. }
  312. function save_target_image(roi, file){
  313. paintImage.save_target_image(roi, file)
  314. }
  315. }