ThemesContentViewModel.cs 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. using ComPDFKitViewer;
  2. using ComPDFKitViewer.PdfViewer;
  3. using PDF_Master.CustomControl;
  4. using PDF_Master.Helper;
  5. using PDF_Master.Model;
  6. using PDF_Master.Properties;
  7. using PDF_Master.Views.PropertyPanel.ViewModular;
  8. using PDFSettings;
  9. using Prism.Commands;
  10. using Prism.Mvvm;
  11. using Prism.Regions;
  12. using System;
  13. using System.Collections.Generic;
  14. using System.Linq;
  15. using System.Text;
  16. using System.Threading.Tasks;
  17. using System.Windows;
  18. using System.Windows.Controls;
  19. using System.Windows.Documents;
  20. using System.Windows.Forms;
  21. using System.Windows.Input;
  22. using System.Windows.Media;
  23. using System.Windows.Shapes;
  24. using static PDF_Master.CustomControl.ColorDropBox;
  25. using RadioButton = System.Windows.Controls.RadioButton;
  26. namespace PDF_Master.ViewModels.PropertyPanel.ViewModular
  27. {
  28. public class ThemesContentViewModel : BindableBase, INavigationAware
  29. {
  30. public CPDFViewer PDFViewer { get; set; }
  31. public ViewModularContentViewModel ViewModularContentViewModel { get; set; }
  32. public Color? SelectedColor { get; set; }
  33. private bool resedaDrawMode;
  34. public bool ResedaDrawMode
  35. {
  36. get { return resedaDrawMode; }
  37. set
  38. {
  39. SetProperty(ref resedaDrawMode, value);
  40. if (value)
  41. {
  42. SetDrawModeEvent(null);
  43. }
  44. }
  45. }
  46. private bool darkDrawMode;
  47. public bool DarkDrawMode
  48. {
  49. get { return darkDrawMode; }
  50. set
  51. {
  52. SetProperty(ref darkDrawMode, value);
  53. if (value)
  54. {
  55. SetDrawModeEvent(null);
  56. }
  57. }
  58. }
  59. private bool sepiaDrawMode;
  60. public bool SepiaDrawMode
  61. {
  62. get { return sepiaDrawMode; }
  63. set
  64. {
  65. SetProperty(ref sepiaDrawMode, value);
  66. if (value)
  67. {
  68. SetDrawModeEvent(null);
  69. }
  70. }
  71. }
  72. private bool lightDrawMode;
  73. public bool LightDrawMode
  74. {
  75. get { return lightDrawMode; }
  76. set
  77. {
  78. SetProperty(ref lightDrawMode, value);
  79. if (value)
  80. {
  81. SetDrawModeEvent(null);
  82. }
  83. }
  84. }
  85. public DelegateCommand<object> LoadedCommand { get; set; }
  86. public DelegateCommand<object> SetDrawModeCommand { get; set; }
  87. public ThemesContentViewModel()
  88. {
  89. LoadedCommand = new DelegateCommand<object>(LoadedEvent);
  90. SetDrawModeCommand = new DelegateCommand<object>(SetDrawModeEvent);
  91. }
  92. private void LoadedEvent(object obj)
  93. {
  94. if (obj is WrapPanel wrapPanel)
  95. {
  96. InitBeforeShow(wrapPanel);
  97. }
  98. }
  99. /// <summary>
  100. /// 设置主题颜色
  101. /// </summary>
  102. /// <param name="obj"></param>
  103. private void SetDrawModeEvent(object obj)
  104. {
  105. if (PDFViewer == null)
  106. {
  107. return;
  108. }
  109. SetUpDrawMode(PDFViewer, obj);
  110. if (ViewModularContentViewModel.SplitScreenPDFViewer != null)
  111. {
  112. SetUpDrawMode(ViewModularContentViewModel.SplitScreenPDFViewer, obj);
  113. }
  114. }
  115. private void SetUpDrawMode(CPDFViewer pDFViewer, object obj)
  116. {
  117. DrawModes draw = DrawModes.Draw_Mode_Normal;
  118. UInt32 color = 0;
  119. if (LightDrawMode)
  120. {
  121. draw = DrawModes.Draw_Mode_Normal;
  122. SetDrawMode(draw, color, pDFViewer);
  123. }
  124. else if (SepiaDrawMode)
  125. {
  126. draw = DrawModes.Draw_Mode_Soft;
  127. SetDrawMode(draw, color, pDFViewer);
  128. }
  129. else if (ResedaDrawMode)
  130. {
  131. draw = DrawModes.Draw_Mode_Green;
  132. SetDrawMode(draw, color, pDFViewer);
  133. }
  134. else if (DarkDrawMode)
  135. {
  136. draw = DrawModes.Draw_Mode_Dark;
  137. SetDrawMode(draw, color, pDFViewer);
  138. }
  139. else
  140. {
  141. if (obj is RadioButton radioButton)
  142. {
  143. draw = SetOtherThemeColors(radioButton, pDFViewer);
  144. }
  145. }
  146. //App.SplitScreenDrawModes = draw;
  147. }
  148. private DrawModes SetOtherThemeColors(RadioButton radioButton, CPDFViewer pDFViewer)
  149. {
  150. DrawModes draw = DrawModes.Draw_Mode_Normal;
  151. StackPanel panel = radioButton.Content as StackPanel;
  152. Rectangle rec = (panel.Children[0] as Border).Child as Rectangle;
  153. OpenFileInfo file = SettingHelper.GetFileInfo(pDFViewer?.Document.FilePath);
  154. if (file != null)
  155. {
  156. file.LastFillBrushColor = ((SolidColorBrush)rec.Fill).Color;
  157. }
  158. var color1 = rec.Fill.ToString().Substring(1, 8);
  159. UInt32 c = Convert.ToUInt32(color1, 16);
  160. pDFViewer.SetDrawMode(DrawModes.Draw_Mode_Normal);
  161. pDFViewer.SetDrawMode(DrawModes.Draw_Mode_Custom, c);
  162. UpdateFileInfoList(DrawModes.Draw_Mode_Custom, c, pDFViewer);
  163. draw = DrawModes.Draw_Mode_Custom;
  164. //App.SplitScreenColor = c;
  165. return draw;
  166. }
  167. private void SetDrawMode(DrawModes drawMode, UInt32 color, CPDFViewer pDFViewer)
  168. {
  169. if (pDFViewer.GetDrawMode() != drawMode)
  170. {
  171. pDFViewer.SetDrawMode(drawMode);
  172. UpdateFileInfoList(drawMode, color, pDFViewer);
  173. }
  174. }
  175. /// <summary>
  176. /// 更新文件信息
  177. /// </summary>
  178. /// <param name="modes"></param>
  179. /// <param name="color"></param>
  180. private void UpdateFileInfoList(DrawModes modes, UInt32 color, CPDFViewer pDFViewer)
  181. {
  182. OpenFileInfo file = SettingHelper.GetFileInfo(pDFViewer?.Document.FilePath);
  183. if (file != null)
  184. {
  185. file.LastDrawMode = modes;
  186. if (color != 0)
  187. {
  188. file.LastFillColor = color;
  189. }
  190. }
  191. SettingHelper.SetFileInfo(file);
  192. }
  193. /// <summary>
  194. /// 初始化后
  195. /// </summary>
  196. /// <param name="wrapPanel"></param>
  197. private void InitBeforeShow(WrapPanel wrapPanel)
  198. {
  199. if (PDFViewer == null)
  200. {
  201. return;
  202. }
  203. var mode = PDFViewer.GetDrawMode();
  204. if (mode == DrawModes.Draw_Mode_Normal)
  205. {
  206. LightDrawMode = true;
  207. }
  208. else if (mode == DrawModes.Draw_Mode_Dark)
  209. {
  210. DarkDrawMode = true;
  211. }
  212. else if (mode == DrawModes.Draw_Mode_Green)
  213. {
  214. ResedaDrawMode = true;
  215. }
  216. else if (mode == DrawModes.Draw_Mode_Soft)
  217. {
  218. SepiaDrawMode = true;
  219. }
  220. else
  221. {
  222. OpenFileInfo info = SettingHelper.GetFileInfo(PDFViewer.Document.FilePath);
  223. var color = info.LastFillBrushColor;
  224. for (int i = 4; i < wrapPanel.Children.Count; i++)
  225. {
  226. var btn = wrapPanel.Children[i] as RadioButton;
  227. if (btn != null && Color.Equals(((SolidColorBrush)(((btn.Content as StackPanel).Children[0] as Border).Child as Rectangle).Fill).Color, color))
  228. {
  229. btn.IsChecked = true;
  230. }
  231. }
  232. }
  233. }
  234. public bool IsNavigationTarget(NavigationContext navigationContext)
  235. {
  236. return true;
  237. }
  238. public void OnNavigatedFrom(NavigationContext navigationContext)
  239. {
  240. }
  241. public void OnNavigatedTo(NavigationContext navigationContext)
  242. {
  243. if (navigationContext.Parameters[ParameterNames.PDFViewer] is CPDFViewer pdfview)
  244. {
  245. PDFViewer = pdfview;
  246. }
  247. if (navigationContext.Parameters[ParameterNames.ViewModularContentViewModel] is ViewModularContentViewModel viewModularContentViewModel)
  248. {
  249. ViewModularContentViewModel = viewModularContentViewModel;
  250. }
  251. }
  252. }
  253. }