MainEvent.qml 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. pragma Singleton
  2. import QtQuick
  3. import QtQuick.Controls
  4. import FluentUI
  5. QtObject {
  6. id: mainEvent
  7. enum RunStatus {
  8. Error,
  9. Run,
  10. Free, //空闲
  11. Empty //不显示
  12. }
  13. // 界面的自定义设置
  14. property var settings: {""}
  15. property int displayMode : FluNavigationView.Compact
  16. property int darkMode: FluDarkMode.System
  17. property QtObject primaryColor: FluColors.Orange
  18. property bool nativeText: true
  19. property string language: ""
  20. property int runStatus: MainEvent.RunStatus.Empty
  21. property string menuTitle: ""
  22. property bool addOpen: false
  23. property string scriptName: ""
  24. //切换语言中文是"zh_CN" 英文是"en_US"
  25. function switchLocale(locale) {
  26. }
  27. Component.onCompleted:{
  28. var set = JSON.parse(setting.read())
  29. mainEvent.settings = set
  30. if(mainEvent.settings === ""){
  31. mainEvent.settings = {
  32. "displayMode": 1,
  33. "darkMode": 2,
  34. "primaryColor": "Orange",
  35. "nativeText": true,
  36. "language": "简体中文"}
  37. }
  38. mainEvent.displayMode = set["displayMode"]
  39. mainEvent.darkMode = set["darkMode"]
  40. mainEvent.nativeText = set["nativeText"]
  41. mainEvent.language = set["language"]
  42. switchLocale("zh_CN")
  43. var primary_color = set["primaryColor"]
  44. if(primary_color === "Yellow"){mainEvent.primaryColor = FluColors.Yellow}
  45. else if(primary_color === "Orange"){mainEvent.primaryColor = FluColors.Orange}
  46. else if(primary_color === "Red"){mainEvent.primaryColor = FluColors.Red}
  47. else if(primary_color === "Magenta"){mainEvent.primaryColor = FluColors.Magenta}
  48. else if(primary_color === "Purple"){mainEvent.primaryColor = FluColors.Purple}
  49. else if(primary_color === "Blue"){mainEvent.primaryColor = FluColors.Blue}
  50. else if(primary_color === "Teal"){mainEvent.primaryColor = FluColors.Teal}
  51. else if(primary_color === "Green"){mainEvent.primaryColor = FluColors.Green}
  52. }
  53. onDisplayModeChanged: {
  54. if(mainEvent.settings === ""){
  55. console.debug('display mode and is none')
  56. }
  57. mainEvent.settings["displayMode"] = mainEvent.displayMode
  58. setting.update(JSON.stringify(mainEvent.settings))
  59. // showSuccess('update dark mode')
  60. }
  61. onDarkModeChanged: {
  62. if(mainEvent.settings === ""){
  63. console.debug('darkMode and is none')
  64. }
  65. FluTheme.darkMode = mainEvent.darkMode
  66. mainEvent.settings["darkMode"] = FluTheme.darkMode
  67. setting.update(JSON.stringify(mainEvent.settings))
  68. // showSuccess('update dark mode' + FluTheme.darkMode)
  69. }
  70. onPrimaryColorChanged: {
  71. if(mainEvent.settings === ""){
  72. console.debug('primaryColor and is none')
  73. var set = JSON.parse(setting.read())
  74. mainEvent.settings = set
  75. return
  76. }
  77. FluTheme.primaryColor = mainEvent.primaryColor
  78. var primary_color = "Yellow"
  79. if(FluTheme.primaryColor === FluColors.Yellow){primary_color="Yellow"}
  80. else if(FluTheme.primaryColor === FluColors.Orange){primary_color="Orange"}
  81. else if(FluTheme.primaryColor === FluColors.Red){primary_color="Red"}
  82. else if(FluTheme.primaryColor === FluColors.Magenta){primary_color="Magenta"}
  83. else if(FluTheme.primaryColor === FluColors.Purple){primary_color="Purple"}
  84. else if(FluTheme.primaryColor === FluColors.Blue){primary_color="Blue"}
  85. else if(FluTheme.primaryColor === FluColors.Teal){primary_color="Teal"}
  86. else if(FluTheme.primaryColor === FluColors.Green){primary_color="Green"}
  87. mainEvent.settings["primaryColor"] = primary_color
  88. setting.update(JSON.stringify(mainEvent.settings))
  89. // showSuccess('update primary color' + FluTheme.primaryColor)
  90. }
  91. onNativeTextChanged: {
  92. if(mainEvent.settings === ""){
  93. console.debug('nativeText and is none')
  94. }
  95. FluTheme.nativeText = mainEvent.nativeText
  96. mainEvent.settings["nativeText"] = FluTheme.nativeText
  97. setting.update(JSON.stringify(mainEvent.settings))
  98. // var message = 'update native text' + FluTheme.nativeText
  99. // showSuccess(message)
  100. }
  101. onLanguageChanged: {
  102. if(mainEvent.settings === ""){
  103. console.debug('language and is none')
  104. }
  105. mainEvent.settings["language"] = mainEvent.language
  106. setting.update(JSON.stringify(mainEvent.settings))
  107. translator.set_language(mainEvent.language)
  108. }
  109. }