runhey 3 лет назад
Родитель
Сommit
bfb2bb1739

+ 1 - 1
module/config/argument/setting-template.json

@@ -1 +1 @@
-{"displayMode":1,"darkMode":2,"primaryColor":"Yellow","nativeText":true,"language":"简体中文"}
+{"displayMode":1,"darkMode":2,"primaryColor":"Yellow","nativeText":true,"language":"简体中文","dpiStrategy":"default"}

BIN
module/config/i18n/zh_CN.qm


+ 24 - 0
module/config/i18n/zh_CN.ts

@@ -73,6 +73,30 @@
         <source>Locale</source>
         <source>Locale</source>
         <translation>语言环境</translation>
         <translation>语言环境</translation>
     </message>
     </message>
+	<message>
+        <source>Dpi Strategy</source>
+        <translation>分辨率DPI缩放策略</translation>
+    </message>
+	<message>
+        <source>default</source>
+        <translation>默认不缩放</translation>
+    </message>
+	<message>
+        <source>floor</source>
+        <translation>始终不缩放</translation>
+    </message>
+	<message>
+        <source>ceil</source>
+        <translation>始终缩放</translation>
+    </message>
+	<message>
+        <source>round</source>
+        <translation>设备像素比0.5及以上的,进行缩放</translation>
+    </message>
+	<message>
+        <source>round_prefer_floor</source>
+        <translation>设备像素比0.75及以上的,进行缩放</translation>
+    </message>
 </context>
 </context>
 <context>
 <context>
     <name>O_Home</name>
     <name>O_Home</name>

+ 27 - 4
module/gui/fluent_app.py

@@ -20,14 +20,16 @@ class FluentApp():
     app = None
     app = None
     engine = None
     engine = None
     translator = None
     translator = None
+    dpi = None
 
 
     def __init__(self):
     def __init__(self):
         super().__init__()
         super().__init__()
         # 适配高分辨率、声明、设置Logo、设置软件名字
         # 适配高分辨率、声明、设置Logo、设置软件名字
-        QGuiApplication.setHighDpiScaleFactorRoundingPolicy(Qt.HighDpiScaleFactorRoundingPolicy.Round)
-        QGuiApplication.setAttribute(Qt.AA_EnableHighDpiScaling)
-        QGuiApplication.setAttribute(Qt.AA_UseHighDpiPixmaps)
-        QGuiApplication.setAttribute(Qt.AA_ShareOpenGLContexts)
+        # 后面的这三条失效了 使用 QGuiApplication.setHighDpiScaleFactorRoundingPolicy
+        # https://blog.weimo.info/archives/602/
+        # QGuiApplication.setAttribute(Qt.AA_EnableHighDpiScaling)
+        # QGuiApplication.setAttribute(Qt.AA_UseHighDpiPixmaps)
+        # QGuiApplication.setAttribute(Qt.AA_ShareOpenGLContexts)
         os.putenv("QT_QUICK_CONTROLS_STYLE", "Basic")
         os.putenv("QT_QUICK_CONTROLS_STYLE", "Basic")
 
 
         FluentApp.app = QGuiApplication(sys.argv)
         FluentApp.app = QGuiApplication(sys.argv)
@@ -39,7 +41,9 @@ class FluentApp():
         FluentApp.engine.addImportPath(os.fspath(Path(__file__).resolve().parent))
         FluentApp.engine.addImportPath(os.fspath(Path(__file__).resolve().parent))
 
 
         FluentApp.translator = Translator(engine=FluentApp.engine, app=FluentApp.app)
         FluentApp.translator = Translator(engine=FluentApp.engine, app=FluentApp.app)
+        FluentApp.dpi = DpiScale()
         self.set_context_property(context=FluentApp.translator, name='translator')
         self.set_context_property(context=FluentApp.translator, name='translator')
+        self.set_context_property(context=FluentApp.dpi, name='dpi')
 
 
     @classmethod
     @classmethod
     def run(cls):
     def run(cls):
@@ -102,5 +106,24 @@ class Translator(QObject):
             self._engine.retranslate()
             self._engine.retranslate()
             return
             return
 
 
+class DpiScale(QObject):
+    def __init__(self) -> None:
+        super().__init__()
+
+    @Slot(str)
+    def set_dpi_scale(self, strategy: str) -> None:
+        """
+        设置dpi缩放
+        :param strategy:
+        :return:
+        """
+        match strategy:
+            case "default": QGuiApplication.setHighDpiScaleFactorRoundingPolicy(Qt.HighDpiScaleFactorRoundingPolicy.PassThrough)  # 不缩放
+            case "round": QGuiApplication.setHighDpiScaleFactorRoundingPolicy(Qt.HighDpiScaleFactorRoundingPolicy.Round)  # 设备像素比0.5及以上的,进行缩放
+            case "floor": QGuiApplication.setHighDpiScaleFactorRoundingPolicy(Qt.HighDpiScaleFactorRoundingPolicy.Floor)  # 始终不缩放
+            case "ceil": QGuiApplication.setHighDpiScaleFactorRoundingPolicy(Qt.HighDpiScaleFactorRoundingPolicy.Ceil)  # 始终缩放
+            case "round_prefer_floor": QGuiApplication.setHighDpiScaleFactorRoundingPolicy(Qt.HighDpiScaleFactorRoundingPolicy.RoundPreferFloor)  # 设备像素比0.75及以上的,进行缩放
+            case _: QGuiApplication.setHighDpiScaleFactorRoundingPolicy(Qt.HighDpiScaleFactorRoundingPolicy.PassThrough)
+
 
 
 
 

+ 318 - 1
module/gui/qml/Content/ClickRule.qml

@@ -1,5 +1,322 @@
-import QtQuick 2.0
+import QtQuick
+import QtQuick.Controls
+import FluentUI
+import "../Component"
 
 
 Item {
 Item {
 
 
+    MirrorImage{
+        id: mirrorImage
+        anchors{
+            left: parent.left
+            top: parent.top
+        }
+        width: 1280
+        height: 720 + 50
+        imageWidth: 1280
+        imageHeight: 720
+
+        onRoi_red_changed: function(roi){
+            if(typeof ruleFile.currentItem === "undefined"){
+                return
+            }
+            ruleFile.currentItem.roiFront = roi
+        }
+
+        onRoi_green_changed: function(roi){
+            if(typeof ruleFile.currentItem === "undefined"){
+                return
+            }
+            ruleFile.currentItem.roiBack = roi
+        }
+    }
+    RuleFile{
+        id: ruleFile
+        anchors{
+            left: mirrorImage.right
+            leftMargin: 10
+            right: parent.right
+            top: parent.top
+        }
+        height: 600
+        addFunc: add
+        editFunc: edit
+        saveFunc: save
+
+        onCurrentItemChanged: {
+            if(currentItem === "" || typeof currentItem === "undefined"){
+                return
+            }
+            var [x, y, width, height] = currentItem.roiFront.split(',')
+            mirrorImage.roiRed_x = parseInt(x)
+            mirrorImage.roiRed_y = parseInt(y)
+            mirrorImage.roiRed_width = parseInt(width)
+            mirrorImage.roiRed_height = parseInt(height)
+            var [x, y, width, height] = currentItem.roiBack.split(',')
+            mirrorImage.roiGreen_x = parseInt(x)
+            mirrorImage.roiGreen_y = parseInt(y)
+            mirrorImage.roiGreen_width = parseInt(width)
+            mirrorImage.roiGreen_height = parseInt(height)
+
+        }
+    }
+
+    FluArea {
+        id: ruleArea
+        anchors{
+            left: mirrorImage.right
+            leftMargin: 10
+            right: parent.right
+            top: ruleFile.bottom
+            topMargin: 12
+            bottom: parent.bottom
+        }
+        Column{
+            id: coi
+            anchors{
+                top: parent.top
+                bottom: parent.bottom
+                left: parent.left
+                leftMargin: 20
+                right: parent.right
+                rightMargin: 20
+            }
+            spacing: 5
+            //头
+            Item{
+                width: coi.width
+                height: 40
+                FluText{
+                    anchors.left: parent.left
+                    anchors.verticalCenter: parent.verticalCenter
+                    text: "Editing rule"
+                    font: FluTextStyle.Subtitle
+                }
+            }
+            //item name 这个参数项的名称
+            Item{
+                width: coi.width
+                height: 40
+                FluText{
+                    anchors.left: parent.left
+                    anchors.verticalCenter: parent.verticalCenter
+                    text: "Item name"
+                    font: FluTextStyle.BodyStrong
+                }
+                FluTextBox{
+                    id: itemName
+                    anchors{
+                        right: parent.right
+                        verticalCenter: parent.verticalCenter
+                    }
+                    placeholderText:"单行输入框"
+                    disabled: true
+                    text: (typeof ruleFile.currentItem === "undefined")? "" : ruleFile.currentItem.itemName
+                    width: 200
+                }
+            }
+            // 文件名
+//            Item{
+//                width: coi.width
+//                height: 40
+//                FluText{
+//                    anchors.left: parent.left
+//                    anchors.verticalCenter: parent.verticalCenter
+//                    text: "Image name"
+//                    font: FluTextStyle.BodyStrong
+//                }
+//                FluTextBox{
+//                    id: imageName
+//                    anchors{
+//                        right: parent.right
+//                        verticalCenter: parent.verticalCenter
+//                    }
+//                    disabled: true
+//                    text:(typeof ruleFile.currentItem === "undefined")? "" : ruleFile.currentItem.imageName
+//                    placeholderText:"Save image name"
+//                    width: 200
+//                }
+//            }
+            // roi front
+            Item{
+                width: coi.width
+                height: 40
+                FluText{
+                    anchors.left: parent.left
+                    anchors.verticalCenter: parent.verticalCenter
+                    text: "Roi front"
+                    font: FluTextStyle.BodyStrong
+                }
+                FluTextBox{
+                    id: roiFront
+                    anchors{
+                        right: parent.right
+                        verticalCenter: parent.verticalCenter
+                    }
+                    disabled: true
+                    text:(typeof ruleFile.currentItem === "undefined")? "" : ruleFile.currentItem.roiFront
+                    placeholderText:"0,0,100,100"
+                    width: 200
+                }
+            }
+            //roi back
+            Item{
+                width: coi.width
+                height: 40
+                FluText{
+                    anchors.left: parent.left
+                    anchors.verticalCenter: parent.verticalCenter
+                    text: "Roi Back"
+                    font: FluTextStyle.BodyStrong
+                }
+                FluTextBox{
+                    id: roiBack
+                    anchors{
+                        right: parent.right
+                        verticalCenter: parent.verticalCenter
+                    }
+                    disabled: true
+                    text:(typeof ruleFile.currentItem === "undefined")? "" : ruleFile.currentItem.roiBack
+                    placeholderText:"0,0,100,100"
+                    width: 200
+
+
+                }
+            }
+            //找图的方法
+//            Item{
+//                width: coi.width
+//                height: 40
+//                FluText{
+//                    anchors.left: parent.left
+//                    anchors.verticalCenter: parent.verticalCenter
+//                    text: "Find method"
+//                    font: FluTextStyle.BodyStrong
+//                }
+//                FComboBox{
+//                    id: method
+//                    anchors{
+//                        right: parent.right
+//                        verticalCenter: parent.verticalCenter
+//                    }
+//                    width: 200
+//                    currentIndex: 0
+//                    model: ["Template matching"]
+//                    onActivated: {
+
+//                    }
+//                }
+//            }
+            //阈值
+//            Item{
+//                width: coi.width
+//                height: 40
+//                FluText{
+//                    anchors.left: parent.left
+//                    anchors.verticalCenter: parent.verticalCenter
+//                    text: "Threshod"
+//                    font: FluTextStyle.BodyStrong
+//                }
+//                FluTextBox{
+//                    id: threshold
+//                    anchors{
+//                        right: parent.right
+//                        verticalCenter: parent.verticalCenter
+//                    }
+//                    width: 200
+//                    text:(typeof ruleFile.currentItem === "undefined")? "" : ruleFile.currentItem.threshold
+//                    placeholderText:"0.8"
+//                    onEditingFinished: {
+//                        if(typeof ruleFile.currentItem === "undefined"){
+//                            return
+//                        }
+//                        ruleFile.currentItem.threshold = parseFloat(text)
+//                    }
+//                }
+//            }
+            //描述 description
+            Item{
+                width: coi.width
+                height: 40
+                FluText{
+                    anchors.left: parent.left
+                    anchors.verticalCenter: parent.verticalCenter
+                    text: "Description"
+                    font: FluTextStyle.BodyStrong
+                }
+                FluTextBox{
+                    id: description
+                    anchors{
+                        right: parent.right
+                        verticalCenter: parent.verticalCenter
+                    }
+                    width: 200
+                    text:(typeof ruleFile.currentItem === "undefined")? "" : ruleFile.currentItem.description
+                    placeholderText:"input your description"
+                    onEditingFinished: {
+                        if(typeof ruleFile.currentItem === "undefined"){
+                            return
+                        }
+                        ruleFile.currentItem.description = text
+                    }
+                }
+            }
+
+        }
+
+    }
+
+    // 帮助
+    FluArea{
+        id: ruleHelp
+        anchors{
+            left: parent.left
+            right: ruleArea.left
+            rightMargin: 10
+            top: mirrorImage.bottom
+            topMargin: 10
+            bottom: parent.bottom
+        }
+        FluText{
+            leftPadding: 12
+            topPadding: 12
+            text: "红色的框(Roi front)表示这一个项点击的默认范围,绿色的框(Roi back)表示备用的范围。
+在移动边框时右边的roi并不会实时显示,当切换软件的焦点时更新显示,但是具体的数值是更新的。
+投屏的设置最上边点击即可"
+        }
+
+    }
+
+    function add(){
+        const item ={}
+        item["itemName"] = "new"
+        item["roiFront"] = "0,0,100,100"
+        item["roiBack"] = "0,0,100,100"
+        item["description"] = "description"
+        showSuccess("Add new item")
+        return item
+    }
+
+    function edit(model){
+
+    }
+
+    function save(){
+        const data = []
+        for(var i=0; i<ruleFile.list_model.count; i++){
+            const item = ruleFile.list_model.get(i)
+            const itemData = {}
+            itemData["itemName"] = item["itemName"]
+            itemData["roiFront"] = item["roiFront"]
+            itemData["roiBack"] = item["roiBack"]
+            itemData["description"] = item["description"]
+            data.push(itemData)
+        }
+
+        ruleFile.rule_file.write_file(ruleFile.file, JSON.stringify(data))
+        showSuccess("Save file")
+
+    }
+
+
 }
 }

+ 38 - 8
module/gui/qml/Global/MainEvent.qml

@@ -16,11 +16,13 @@ QtObject {
 
 
     // 界面的自定义设置
     // 界面的自定义设置
     property var settings: {""}
     property var settings: {""}
+    property bool settingInit: true  // 表示这个时候是初始化的,初始化后变为false
     property int displayMode : FluNavigationView.Compact
     property int displayMode : FluNavigationView.Compact
     property int darkMode: FluDarkMode.System
     property int darkMode: FluDarkMode.System
     property QtObject primaryColor: FluColors.Orange
     property QtObject primaryColor: FluColors.Orange
     property bool nativeText: true
     property bool nativeText: true
     property string language: ""
     property string language: ""
+    property string dpiStrategy: ""
 
 
     property int runStatus: MainEvent.RunStatus.Empty
     property int runStatus: MainEvent.RunStatus.Empty
     property string menuTitle: ""
     property string menuTitle: ""
@@ -41,14 +43,15 @@ QtObject {
                 "darkMode": 2,
                 "darkMode": 2,
                 "primaryColor": "Orange",
                 "primaryColor": "Orange",
                 "nativeText": true,
                 "nativeText": true,
-                "language": "简体中文"}
+                "language": "简体中文",
+                "dpiStrategy": ""}
         }
         }
 
 
         mainEvent.displayMode = set["displayMode"]
         mainEvent.displayMode = set["displayMode"]
         mainEvent.darkMode = set["darkMode"]
         mainEvent.darkMode = set["darkMode"]
         mainEvent.nativeText = set["nativeText"]
         mainEvent.nativeText = set["nativeText"]
         mainEvent.language = set["language"]
         mainEvent.language = set["language"]
-        switchLocale("zh_CN")
+        mainEvent.dpiStrategy = set["dpiStrategy"]
 
 
         var primary_color = set["primaryColor"]
         var primary_color = set["primaryColor"]
         if(primary_color === "Yellow"){mainEvent.primaryColor = FluColors.Yellow}
         if(primary_color === "Yellow"){mainEvent.primaryColor = FluColors.Yellow}
@@ -59,24 +62,32 @@ QtObject {
         else if(primary_color === "Blue"){mainEvent.primaryColor = FluColors.Blue}
         else if(primary_color === "Blue"){mainEvent.primaryColor = FluColors.Blue}
         else if(primary_color === "Teal"){mainEvent.primaryColor = FluColors.Teal}
         else if(primary_color === "Teal"){mainEvent.primaryColor = FluColors.Teal}
         else if(primary_color === "Green"){mainEvent.primaryColor = FluColors.Green}
         else if(primary_color === "Green"){mainEvent.primaryColor = FluColors.Green}
+
+        settingInit = false
     }
     }
     onDisplayModeChanged: {
     onDisplayModeChanged: {
+
         if(mainEvent.settings === ""){
         if(mainEvent.settings === ""){
             console.debug('display mode and is none')
             console.debug('display mode and is none')
         }
         }
 
 
         mainEvent.settings["displayMode"] = mainEvent.displayMode
         mainEvent.settings["displayMode"] = mainEvent.displayMode
+        if(settingInit){
+            return
+        }
         setting.update(JSON.stringify(mainEvent.settings))
         setting.update(JSON.stringify(mainEvent.settings))
-//        showSuccess('update dark mode')
     }
     }
     onDarkModeChanged: {
     onDarkModeChanged: {
+
         if(mainEvent.settings === ""){
         if(mainEvent.settings === ""){
             console.debug('darkMode and is none')
             console.debug('darkMode and is none')
         }
         }
         FluTheme.darkMode = mainEvent.darkMode
         FluTheme.darkMode = mainEvent.darkMode
         mainEvent.settings["darkMode"] = FluTheme.darkMode
         mainEvent.settings["darkMode"] = FluTheme.darkMode
+        if(settingInit){
+            return
+        }
         setting.update(JSON.stringify(mainEvent.settings))
         setting.update(JSON.stringify(mainEvent.settings))
-//        showSuccess('update dark mode' + FluTheme.darkMode)
     }
     }
     onPrimaryColorChanged: {
     onPrimaryColorChanged: {
         if(mainEvent.settings === ""){
         if(mainEvent.settings === ""){
@@ -97,19 +108,23 @@ QtObject {
         else if(FluTheme.primaryColor === FluColors.Teal){primary_color="Teal"}
         else if(FluTheme.primaryColor === FluColors.Teal){primary_color="Teal"}
         else if(FluTheme.primaryColor === FluColors.Green){primary_color="Green"}
         else if(FluTheme.primaryColor === FluColors.Green){primary_color="Green"}
         mainEvent.settings["primaryColor"] = primary_color
         mainEvent.settings["primaryColor"] = primary_color
+        if(settingInit){
+            return
+        }
         setting.update(JSON.stringify(mainEvent.settings))
         setting.update(JSON.stringify(mainEvent.settings))
-//        showSuccess('update primary color' + FluTheme.primaryColor)
     }
     }
     onNativeTextChanged: {
     onNativeTextChanged: {
+
         if(mainEvent.settings === ""){
         if(mainEvent.settings === ""){
             console.debug('nativeText and is none')
             console.debug('nativeText and is none')
         }
         }
 
 
         FluTheme.nativeText = mainEvent.nativeText
         FluTheme.nativeText = mainEvent.nativeText
         mainEvent.settings["nativeText"] = FluTheme.nativeText
         mainEvent.settings["nativeText"] = FluTheme.nativeText
+        if(settingInit){
+            return
+        }
         setting.update(JSON.stringify(mainEvent.settings))
         setting.update(JSON.stringify(mainEvent.settings))
-//        var message = 'update native text' + FluTheme.nativeText
-//        showSuccess(message)
     }
     }
     onLanguageChanged: {
     onLanguageChanged: {
         if(mainEvent.settings === ""){
         if(mainEvent.settings === ""){
@@ -117,7 +132,22 @@ QtObject {
         }
         }
 
 
         mainEvent.settings["language"] = mainEvent.language
         mainEvent.settings["language"] = mainEvent.language
-        setting.update(JSON.stringify(mainEvent.settings))
         translator.set_language(mainEvent.language)
         translator.set_language(mainEvent.language)
+        if(settingInit){
+            return
+        }
+        setting.update(JSON.stringify(mainEvent.settings))
+
+    }
+    onDpiStrategyChanged: {
+        if(mainEvent.settings === ""){
+            console.debug('dpiStrategy and is none')
+        }
+        mainEvent.settings["dpiStrategy"] = mainEvent.dpiStrategy
+        dpi.set_dpi_scale(mainEvent.dpiStrategy)
+        if(settingInit){
+            return
+        }
+        setting.update(JSON.stringify(mainEvent.settings))
     }
     }
 }
 }

+ 37 - 0
module/gui/qml/Page/O_Settings.qml

@@ -171,4 +171,41 @@ FluScrollablePage{
     }
     }
 
 
 
 
+    FluArea{
+        Layout.fillWidth: true
+        Layout.topMargin: 20
+        height: 200
+        paddings: 10
+
+        ColumnLayout{
+            spacing: 10
+            anchors{
+                top: parent.top
+                left: parent.left
+            }
+
+            FluText{
+                text: qsTr("Dpi Strategy")
+                font: FluTextStyle.BodyStrong
+                Layout.bottomMargin: 4
+            }
+            Repeater{
+                model: [{title:qsTr("default"),mode:"default"},  // 默认不缩放
+                        {title:qsTr("floor"),mode:"floor"},  // 始终不缩放
+                        {title:qsTr("ceil"),mode:"ceil"},  // 始终缩放
+                        {title:qsTr("round"),mode:"round"}, // 设备像素比0.5及以上的,进行缩放
+                        {title:qsTr("round_prefer_floor"),mode:"round_prefer_floor"} // 设备像素比0.75及以上的,进行缩放
+                        ]
+                delegate:  FluRadioButton{
+                    selected : MainEvent.dpiStrategy===modelData.mode
+                    text:modelData.title
+                    onClicked:{
+                        MainEvent.dpiStrategy = modelData.mode
+                    }
+                }
+            }
+        }
+    }
+
+
 }
 }