AppConfig.cs 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. 
  2. using GeekDesk.Constant;
  3. using GeekDesk.Util;
  4. using System;
  5. using System.Collections.ObjectModel;
  6. using System.ComponentModel;
  7. using System.Drawing;
  8. using System.Windows;
  9. using System.Windows.Input;
  10. using System.Windows.Media.Imaging;
  11. /// <summary>
  12. /// 程序设置
  13. /// </summary>
  14. namespace GeekDesk.ViewModel
  15. {
  16. [Serializable]
  17. public class AppConfig : INotifyPropertyChanged
  18. {
  19. private SortType menuSortType = SortType.CUSTOM; //菜单排序类型
  20. private SortType iconSortType = SortType.CUSTOM; //图表排序类型
  21. private double windowWidth = (double)DefaultConstant.WINDOW_WIDTH; //窗口宽度
  22. private double windowHeight = (double)DefaultConstant.WINDOW_HEIGHT; //窗口高度
  23. private double menuCardWidth = (double)DefaultConstant.MENU_CARD_WIDHT;//菜单栏宽度
  24. private int selectedMenuIndex = 0; //上次选中菜单索引
  25. private bool followMouse = true; //面板跟随鼠标 默认是
  26. private Visibility configIconVisible = Visibility.Visible; // 设置按钮是否显示
  27. private AppHideType appHideType = AppHideType.START_EXE; //面板关闭方式 (默认启动程序后)
  28. private bool startedShowPanel = true; //启动时是否显示主面板 默认显示
  29. [field: NonSerialized]
  30. private BitmapImage bitmapImage; //位图
  31. private byte[] imageByteArr; //背景图片 byte数组
  32. private string bacImgName = "系统默认";
  33. private int cardOpacity = 10; //默认0.1的不透明度 此处显示数值 * 100
  34. private int bgOpacity = 100; // 背景图片不透明度 此处显示数值 * 100
  35. private int pannelOpacity = 100; //主面板不透明度 此处显示数值 * 100
  36. private int pannelCornerRadius = 4; //面板圆角 默认4
  37. [field: NonSerialized]
  38. private ObservableCollection<IconInfo> selectedMenuIcons;
  39. private string hotkeyStr = "Ctrl + Q";
  40. private HotkeyModifiers hotkeyModifiers = HotkeyModifiers.MOD_CONTROL;
  41. private Key hotkey = Key.Q;
  42. #region GetSet
  43. public Key Hotkey
  44. {
  45. get
  46. {
  47. return hotkey;
  48. }
  49. set
  50. {
  51. hotkey = value;
  52. OnPropertyChanged("Hotkey");
  53. }
  54. }
  55. public string HotkeyStr
  56. {
  57. get
  58. {
  59. return hotkeyStr;
  60. }
  61. set
  62. {
  63. hotkeyStr = value;
  64. OnPropertyChanged("HotkeyStr");
  65. }
  66. }
  67. public HotkeyModifiers HotkeyModifiers
  68. {
  69. get
  70. {
  71. return hotkeyModifiers;
  72. }
  73. set
  74. {
  75. hotkeyModifiers = value;
  76. OnPropertyChanged("HotkeyModifiers");
  77. }
  78. }
  79. public ObservableCollection<IconInfo> SelectedMenuIcons
  80. {
  81. get
  82. {
  83. return selectedMenuIcons;
  84. }
  85. set
  86. {
  87. selectedMenuIcons = value;
  88. OnPropertyChanged("SelectedMenuIcons");
  89. }
  90. }
  91. public int PannelCornerRadius
  92. {
  93. get
  94. {
  95. return pannelCornerRadius;
  96. }
  97. set
  98. {
  99. pannelCornerRadius = value;
  100. OnPropertyChanged("pannelCornerRadius");
  101. }
  102. }
  103. public int PannelOpacity
  104. {
  105. get
  106. {
  107. return pannelOpacity;
  108. }
  109. set
  110. {
  111. pannelOpacity = value;
  112. OnPropertyChanged("PannelOpacity");
  113. }
  114. }
  115. public int BgOpacity
  116. {
  117. get
  118. {
  119. return bgOpacity;
  120. }
  121. set
  122. {
  123. bgOpacity = value;
  124. OnPropertyChanged("BgOpacity");
  125. }
  126. }
  127. public int CardOpacity
  128. {
  129. get
  130. {
  131. return cardOpacity;
  132. }
  133. set
  134. {
  135. cardOpacity = value;
  136. OnPropertyChanged("CardOpacity");
  137. }
  138. }
  139. public string BacImgName
  140. {
  141. get
  142. {
  143. return bacImgName;
  144. }
  145. set
  146. {
  147. bacImgName = value;
  148. OnPropertyChanged("BacImgName");
  149. }
  150. }
  151. public byte[] ImageByteArr
  152. {
  153. get
  154. {
  155. return imageByteArr;
  156. }
  157. set
  158. {
  159. imageByteArr = value;
  160. OnPropertyChanged("ImageByteArr");
  161. }
  162. }
  163. public BitmapImage BitmapImage
  164. {
  165. get
  166. {
  167. if (imageByteArr == null || imageByteArr.Length == 0)
  168. {
  169. bacImgName = "系统默认";
  170. //Image image = ImageUtil.ByteArrayToImage(Convert.FromBase64String(Constants.DEFAULT_BAC_IMAGE_BASE64));
  171. return ImageUtil.ByteArrToImage(Convert.FromBase64String(Constants.DEFAULT_BAC_IMAGE_BASE64));
  172. } else
  173. {
  174. return ImageUtil.ByteArrToImage(ImageByteArr);
  175. }
  176. }
  177. set
  178. {
  179. bitmapImage = value;
  180. imageByteArr = ImageUtil.BitmapImageToByte(bitmapImage);
  181. OnPropertyChanged("BitmapImage");
  182. }
  183. }
  184. public bool StartedShowPanel
  185. {
  186. get
  187. {
  188. return startedShowPanel;
  189. }
  190. set
  191. {
  192. startedShowPanel = value;
  193. OnPropertyChanged("StartedShowPanel");
  194. }
  195. }
  196. public AppHideType AppHideType
  197. {
  198. get
  199. {
  200. return appHideType;
  201. }
  202. set
  203. {
  204. appHideType = value;
  205. OnPropertyChanged("AppHideType");
  206. }
  207. }
  208. public Visibility ConfigIconVisible
  209. {
  210. get
  211. {
  212. return configIconVisible;
  213. }
  214. set
  215. {
  216. configIconVisible = value;
  217. OnPropertyChanged("ConfigIconVisible");
  218. }
  219. }
  220. public bool FollowMouse
  221. {
  222. get
  223. {
  224. return followMouse;
  225. }
  226. set
  227. {
  228. followMouse = value;
  229. OnPropertyChanged("FollowMouse");
  230. }
  231. }
  232. public int SelectedMenuIndex
  233. {
  234. get
  235. {
  236. return selectedMenuIndex;
  237. }
  238. set
  239. {
  240. selectedMenuIndex = value;
  241. OnPropertyChanged("SelectedMenuIndex");
  242. }
  243. }
  244. public SortType MenuSortType
  245. {
  246. get
  247. {
  248. return menuSortType;
  249. }
  250. set
  251. {
  252. menuSortType = value;
  253. OnPropertyChanged("MenuSortType");
  254. }
  255. }
  256. public SortType IconSortType
  257. {
  258. get
  259. {
  260. return iconSortType;
  261. }
  262. set
  263. {
  264. iconSortType = value;
  265. OnPropertyChanged("IconSortType");
  266. }
  267. }
  268. public double WindowWidth
  269. {
  270. get
  271. {
  272. return windowWidth;
  273. }
  274. set
  275. {
  276. windowWidth = value;
  277. OnPropertyChanged("WindowWidth");
  278. }
  279. }
  280. public double WindowHeight
  281. {
  282. get
  283. {
  284. return windowHeight;
  285. }
  286. set
  287. {
  288. windowHeight = value;
  289. OnPropertyChanged("WindowHeight");
  290. }
  291. }
  292. public double MenuCardWidth
  293. {
  294. get
  295. {
  296. return menuCardWidth;
  297. }
  298. set
  299. {
  300. menuCardWidth = value;
  301. OnPropertyChanged("MenuCardWidth");
  302. }
  303. }
  304. [field: NonSerializedAttribute()]
  305. public event PropertyChangedEventHandler PropertyChanged;
  306. private void OnPropertyChanged(string propertyName)
  307. {
  308. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
  309. CommonCode.SaveAppData(MainWindow.appData);
  310. }
  311. #endregion
  312. }
  313. }