Jelajahi Sumber

feat(gui): roi

runhey 3 tahun lalu
induk
melakukan
fa29a07743

+ 1 - 0
module/gui/qml.qrc

@@ -29,5 +29,6 @@
         <file>qml/Content/SwipeRule.qml</file>
         <file>qml/Content/OcrRule.qml</file>
         <file>qml/Component/MirrorImage.qml</file>
+        <file>qml/Component/ResizableRectangle.qml</file>
     </qresource>
 </RCC>

+ 126 - 9
module/gui/qml/Component/MirrorImage.qml

@@ -6,18 +6,29 @@ import Oas
 import "../Global"
 
 Item {
+    id: imageItem
     implicitWidth: 1280
     implicitHeight: 720 + 50
+
     property alias imageWidth: paintImage.width
     property alias imageHeight: paintImage.height
-
+    enum RoiMode {
+        None,
+        Same,
+        Include
+    }
+    property int roi_mode: MirrorImage.RoiMode.None
 
     Item{
-        anchors{
-            left: parent.left
-            top: parent.top
-            topMargin: 45
-        }
+
+    anchors{
+        left: parent.left
+        top: parent.top
+        topMargin: 45
+    }
+    width: imageWidth
+    height: imageHeight
+
     PaintImage{
         id: paintImage
         width: 1280
@@ -27,7 +38,7 @@ Item {
             repeat: true
             running: if(imageSoucre.currentText === "Device Image"){return true}
                      else{ return false}
-            interval: 500
+            interval: 1000
 
             onTriggered: {
                 paintImage.update_image()
@@ -50,7 +61,80 @@ Item {
         Component.onCompleted:{
             timerImage.start()
         }
-    }}
+    }
+
+
+    Rectangle{
+        id: roi_Green // 默认第二个是 back
+        width: 100
+        height: 100
+        color: "transparent"
+        border.width: 1
+        border.color: "green"
+        ResizableRectangle{
+            resizeTarget: roi_Green//设置调整目标ID
+        }
+    }
+
+    Rectangle{
+        id: roi_Red // 默认第一个是红色的front
+        width: 100
+        height: 100
+        color: "transparent"
+        border.width: 1
+        border.color: "red"
+
+        ResizableRectangle{
+            resizeTarget: roi_Red//设置调整目标ID
+        }
+        onXChanged: {
+            if(roi_mode ===  MirrorImage.RoiMode.Include){
+                if(roi_Red.x < roi_Green.x || roi_Red.x+roi_Red.width > roi_Green.x+roi_Green.width){
+                    roi_Red.x = roi_Green.x + roi_Green.width/2 - roi_Red.width/2
+
+                }
+            }
+            else if(roi_mode ===  MirrorImage.RoiMode.Same){
+                roi_Green.x = roi_Red.x
+            }
+        }
+        onYChanged: {
+            if(roi_mode ===  MirrorImage.RoiMode.Include){
+                if(roi_Red.y < roi_Green.y || roi_Red.y+roi_Red.height > roi_Green.y+roi_Green.height){
+                    roi_Red.y = roi_Green.y + roi_Green.height/2 - roi_Red.height/2
+
+                }
+            }
+            else if(roi_mode ===  MirrorImage.RoiMode.Same){
+                roi_Green.y = roi_Red.y
+            }
+        }
+        onWidthChanged: {
+            if(roi_mode ===  MirrorImage.RoiMode.Include){
+                if(roi_Red.width > roi_Green.width){
+                    roi_Red.width = roi_Green.width - 5
+                }
+            }
+            else if(roi_mode ===  MirrorImage.RoiMode.Same){
+                roi_Green.width = roi_Red.width
+            }
+        }
+        onHeightChanged: {
+            if(roi_mode ===  MirrorImage.RoiMode.Include){
+                if(roi_Red.height > roi_Green.height){
+                    roi_Red.height = roi_Green.height - 5
+                }
+            }
+            else if(roi_mode ===  MirrorImage.RoiMode.Same){
+                roi_Green.height = roi_Red.height
+            }
+        }
+    }
+    }
+
+
+
+
 
     FluExpander{
         id: imageExpander
@@ -142,7 +226,40 @@ Item {
                     leftMargin: 150
                 }
                 width: 200
-                model: ["Same Size", "Include", "None"]
+                model: ["None", "Same Size", "Include", ]
+
+                function setMode(){
+                    if(currentText === "None"){
+                        imageItem.roi_mode = MirrorImage.RoiMode.None
+                    }
+                    else if(currentText === "Same Size"){
+                        imageItem.roi_mode = MirrorImage.RoiMode.Same
+                    }
+                    else{
+                        imageItem.roi_mode = MirrorImage.RoiMode.Include
+                    }
+                }
+
+                function updateRoi(){
+                    if(roi_mode ===  MirrorImage.RoiMode.Include){
+                        roi_Red.x = roi_Green.x + 5
+                        roi_Red.y = roi_Green.y + 5
+                        roi_Red.width = roi_Green.width - 5
+                        roi_Red.height = roi_Green.height - 5
+
+                    }
+                    else if(roi_mode ===  MirrorImage.RoiMode.Same){
+                        roi_Red.x = roi_Green.x
+                        roi_Red.y = roi_Green.y
+                        roi_Red.width = roi_Green.width
+                        roi_Red.height = roi_Green.height
+                    }
+                }
+
+                onActivated: {
+                    setMode()
+                    updateRoi()
+                }
             }
         }
         // 设置显示的帧率

+ 257 - 0
module/gui/qml/Component/ResizableRectangle.qml

@@ -0,0 +1,257 @@
+import QtQuick 2.0
+import QtQuick.Window 2.15
+
+Item {
+    id:rect
+    property int minimumWidth: 20
+    property int minimumHeight: 20
+    property int mouseRegion: 5
+    property var resizeTarget: rect
+    anchors.fill: resizeTarget
+
+    MouseArea{
+        id: move
+        anchors.fill: parent
+        anchors.margins: mouseRegion
+        cursorShape: Qt.ClosedHandCursor
+        property int xPosition: 0
+        property int yPosition: 0
+        onPressed: function(mouse){
+            xPosition = mouse.x
+            yPosition = mouse.y
+        }
+        onPositionChanged: function(mouse){
+            var xOffset = mouse.x-xPosition
+            var yOffset = mouse.y-yPosition
+
+            if(rect.resizeTarget.x+xOffset>0 && rect.resizeTarget.width+xOffset+rect.resizeTarget.x < rect.resizeTarget.parent.width){
+                rect.resizeTarget.x = rect.resizeTarget.x+xOffset
+            }
+
+            if(rect.resizeTarget.y+yOffset>0 && rect.resizeTarget.height+yOffset+rect.resizeTarget.y < rect.resizeTarget.parent.height){
+                rect.resizeTarget.y = rect.resizeTarget.y+yOffset
+            }
+        }
+    }
+
+    MouseArea {
+        id:leftX
+        width: mouseRegion
+        anchors.left: parent.left
+        anchors.top: parent.top
+        anchors.bottom: parent.bottom
+        anchors.leftMargin: 0
+        anchors.bottomMargin: 0
+        anchors.topMargin: 0
+        cursorShape: Qt.SizeHorCursor
+        property int xPosition: 0
+        onPressed: function(mouse){
+            xPosition = mouse.x
+        }
+
+        onPositionChanged: function(mouse){
+            var xOffset = mouse.x-xPosition
+            if(rect.resizeTarget.x+xOffset>0 && rect.resizeTarget.width-xOffset>minimumWidth){
+                rect.resizeTarget.x = rect.resizeTarget.x+xOffset
+                rect.resizeTarget.width = rect.resizeTarget.width-xOffset
+            }
+        }
+    }
+
+    MouseArea{
+        id:rightX
+        width: mouseRegion
+        anchors.right: parent.right
+        anchors.top: parent.top
+        anchors.bottom: parent.bottom
+        anchors.bottomMargin: 0
+        anchors.topMargin: 0
+        anchors.rightMargin: 0
+        cursorShape: Qt.SizeHorCursor
+        property int xPosition: 0
+        onPressed: function(mouse){
+            xPosition = mouse.x
+        }
+
+        onPositionChanged: function(mouse){
+            var xOffset = mouse.x-xPosition
+            var xWidth = rect.resizeTarget.width+xOffset
+            var availableWidth = rect.resizeTarget.parent ? rect.resizeTarget.parent.width:Screen.desktopAvailableWidth
+            if(xWidth+rect.resizeTarget.x<availableWidth && xWidth>minimumWidth){
+                rect.resizeTarget.width = xWidth
+            }
+        }
+    }
+
+    MouseArea{
+        id:topY
+        height: mouseRegion
+        anchors.left: parent.left
+        anchors.right: parent.right
+        anchors.top: parent.top
+        anchors.rightMargin: 0
+        anchors.leftMargin: 0
+        anchors.topMargin: 0
+        cursorShape: Qt.SizeVerCursor
+        property int yPosition: 0
+        onPressed: function(mouse){
+            yPosition = mouse.y
+        }
+
+        onPositionChanged: function(mouse){
+            var yOffset = mouse.y-yPosition
+            if(rect.resizeTarget.y+yOffset>0 && rect.resizeTarget.height-yOffset>minimumHeight){
+                rect.resizeTarget.y = rect.resizeTarget.y+yOffset
+                rect.resizeTarget.height = rect.resizeTarget.height-yOffset
+            }
+        }
+    }
+
+    MouseArea{
+        id:bottomY
+        height: mouseRegion
+        anchors.left: parent.left
+        anchors.right: parent.right
+        anchors.bottom: parent.bottom
+        anchors.rightMargin: 0
+        anchors.leftMargin: 0
+        anchors.bottomMargin: 0
+        cursorShape: Qt.SizeVerCursor
+        property int yPosition: 0
+        onPressed: function(mouse){
+            yPosition = mouse.y
+        }
+
+        onPositionChanged: function(mouse){
+            var yOffset = mouse.y-yPosition
+            var yHeight = rect.resizeTarget.height+yOffset
+            var availableHeight = rect.resizeTarget.parent ? rect.resizeTarget.parent.height : Screen.desktopAvailableHeight
+            if(yHeight+rect.resizeTarget.y<availableHeight && yHeight>minimumHeight){
+                rect.resizeTarget.height = yHeight
+            }
+        }
+    }
+
+    MouseArea{
+        width: mouseRegion
+        height: mouseRegion
+        anchors.left: parent.left
+        anchors.top: parent.top
+        anchors.topMargin: 0
+        anchors.leftMargin: 0
+        cursorShape: Qt.SizeFDiagCursor
+        property int xPosition: 0
+        property int yPosition: 0
+        onPressed: function(mouse){
+            xPosition = mouse.x
+            yPosition = mouse.y
+        }
+
+        onPositionChanged: function(mouse){
+            var xOffset = mouse.x-xPosition
+            if(rect.resizeTarget.x+xOffset>0 && rect.resizeTarget.width-xOffset>minimumWidth){
+                rect.resizeTarget.x = rect.resizeTarget.x+xOffset
+                rect.resizeTarget.width = rect.resizeTarget.width-xOffset
+            }
+            var yOffset = mouse.y-yPosition
+            if(rect.resizeTarget.y+yOffset>0 && rect.resizeTarget.height-yOffset>minimumHeight){
+                rect.resizeTarget.y = rect.resizeTarget.y+yOffset
+                rect.resizeTarget.height = rect.resizeTarget.height-yOffset
+            }
+        }
+    }
+
+    MouseArea{
+        width: mouseRegion
+        height: mouseRegion
+        anchors.right: parent.right
+        anchors.top: parent.top
+        anchors.topMargin: 0
+        anchors.rightMargin: 0
+        cursorShape: Qt.SizeBDiagCursor
+        property int xPosition: 0
+        property int yPosition: 0
+        onPressed: function(mouse){
+            xPosition = mouse.x
+            yPosition = mouse.y
+        }
+
+        onPositionChanged: function(mouse){
+            var xOffset = mouse.x-xPosition
+            var xWidth = rect.resizeTarget.width+xOffset
+            var availableWidth = rect.resizeTarget.parent ? rect.resizeTarget.parent.width:Screen.desktopAvailableWidth
+            var availableHeight = rect.resizeTarget.parent ? rect.resizeTarget.parent.height : Screen.desktopAvailableHeight
+
+            if(xWidth+rect.resizeTarget.x<availableWidth && xWidth>minimumWidth){
+                rect.resizeTarget.width = xWidth
+            }
+            var yOffset = mouse.y-yPosition
+            if(rect.resizeTarget.y+yOffset>0 && rect.resizeTarget.height-yOffset>minimumHeight){
+                rect.resizeTarget.y = rect.resizeTarget.y+yOffset
+                rect.resizeTarget.height = rect.resizeTarget.height-yOffset
+            }
+        }
+    }
+
+    MouseArea{
+        width: mouseRegion
+        height: mouseRegion
+        anchors.left: parent.left
+        anchors.bottom: parent.bottom
+        anchors.leftMargin: 0
+        anchors.bottomMargin: 0
+        cursorShape: Qt.SizeBDiagCursor
+        property int xPosition: 0
+        property int yPosition: 0
+        onPressed: function(mouse){
+            xPosition = mouse.x
+            yPosition = mouse.y
+        }
+        onPositionChanged: function(mouse){
+            var xOffset = mouse.x-xPosition
+            var availableWidth = rect.resizeTarget.parent ? rect.resizeTarget.parent.width:Screen.desktopAvailableWidth
+            var availableHeight = rect.resizeTarget.parent ? rect.resizeTarget.parent.height : Screen.desktopAvailableHeight
+            if(rect.resizeTarget.x+xOffset>0 && availableWidth-xOffset>minimumWidth){
+                rect.resizeTarget.x = rect.resizeTarget.x+xOffset
+                rect.resizeTarget.width = rect.resizeTarget.width-xOffset
+            }
+            var yOffset = mouse.y-yPosition
+            var yHeight = rect.resizeTarget.height+yOffset
+            if(yHeight+rect.resizeTarget.y<availableHeight && yHeight>minimumHeight){
+                rect.resizeTarget.height = yHeight
+            }
+        }
+    }
+
+
+    MouseArea{
+        width: mouseRegion
+        height: mouseRegion
+        anchors.right: parent.right
+        anchors.bottom: parent.bottom
+        anchors.rightMargin: 0
+        anchors.bottomMargin: 0
+        cursorShape: Qt.SizeFDiagCursor
+        property int xPosition: 0
+        property int yPosition: 0
+        onPressed: function(mouse){
+            xPosition = mouse.x
+            yPosition = mouse.y
+        }
+        onPositionChanged: function(mouse){
+            var xOffset = mouse.x-xPosition
+            var xWidth = rect.resizeTarget.width+xOffset
+            var availableWidth = rect.resizeTarget.parent ? rect.resizeTarget.parent.width:Screen.desktopAvailableWidth
+            var availableHeight = rect.resizeTarget.parent ? rect.resizeTarget.parent.height : Screen.desktopAvailableHeight
+
+            if(xWidth+rect.resizeTarget.x<availableWidth && xWidth>minimumWidth){
+                rect.resizeTarget.width = xWidth
+            }
+            var yOffset = mouse.y-yPosition
+            var yHeight = rect.resizeTarget.height+yOffset
+            if(yHeight+rect.resizeTarget.y<availableHeight && yHeight>minimumHeight){
+                rect.resizeTarget.height = yHeight
+            }
+        }
+    }
+}