TextAnnotPropertyViewModel.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. using ComPDFKitViewer;
  2. using ComPDFKitViewer.AnnotEvent;
  3. using PDF_Master.CustomControl.CompositeControl;
  4. using PDF_Master.Model;
  5. using PDF_Master.Model.AnnotPanel;
  6. using PDF_Master.Properties;
  7. using PDF_Master.ViewModels.Tools;
  8. using PDF_Master.ViewModels.Tools.AnnotManager;
  9. using PDFSettings;
  10. using Prism.Commands;
  11. using Prism.Mvvm;
  12. using Prism.Regions;
  13. using System;
  14. using System.Collections.Generic;
  15. using System.Collections.ObjectModel;
  16. using System.Diagnostics;
  17. using System.Diagnostics.Eventing.Reader;
  18. using System.Globalization;
  19. using System.Windows;
  20. using System.Windows.Data;
  21. using System.Windows.Media;
  22. namespace PDF_Master.ViewModels.PropertyPanel.AnnotPanel
  23. {
  24. public class AnnotArgsTypeConverter : IValueConverter
  25. {
  26. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  27. {
  28. if (value is AnnotArgsType)
  29. {
  30. if (parameter is string)
  31. {
  32. var args = (AnnotArgsType)value;
  33. if ((string)parameter == "AnnotHighlight" && args == AnnotArgsType.AnnotHighlight)
  34. {
  35. return Visibility.Visible;
  36. }
  37. if ((string)parameter == "AnnotUnderline" && args == AnnotArgsType.AnnotUnderline)
  38. {
  39. return Visibility.Visible;
  40. }
  41. if ((string)parameter == "AnnotSquiggly" && args == AnnotArgsType.AnnotSquiggly)
  42. {
  43. return Visibility.Visible;
  44. }
  45. if ((string)parameter == "AnnotStrikeout" && args == AnnotArgsType.AnnotStrikeout)
  46. {
  47. return Visibility.Visible;
  48. }
  49. if ((string)parameter == "AnnotSticky" && args == AnnotArgsType.AnnotSticky)
  50. {
  51. return Visibility.Visible;
  52. }
  53. }
  54. }
  55. return Visibility.Collapsed;
  56. }
  57. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  58. {
  59. throw new NotImplementedException();
  60. }
  61. }
  62. public class TextAnnotPropertyViewModel : BindableBase, INavigationAware
  63. {
  64. #region 属性
  65. private ViewContentViewModel ViewContentViewModel;
  66. //当前边框颜色
  67. private Brush _textDefaultColor;
  68. public Brush TextDefaultColor
  69. {
  70. get { return _textDefaultColor; }
  71. set => SetProperty(ref _textDefaultColor, value);
  72. }
  73. private AnnotCommon _basicVm = new AnnotCommon();
  74. public AnnotCommon BasicVm
  75. {
  76. get { return _basicVm; }
  77. set => SetProperty(ref _basicVm, value);
  78. }
  79. private ColorSelectorType _colorType = ColorSelectorType.Highlight;
  80. public ColorSelectorType ColorType
  81. {
  82. get { return _colorType; }
  83. set => SetProperty(ref _colorType, value);
  84. }
  85. //保存类型对应默认颜色
  86. private Brush HighlightDefaultColor = App.Current.FindResource("color.sys.layout.divider.highlight") as Brush;
  87. private Brush UnderlineDefaultColor = App.Current.FindResource("color.sys.layout.divider.strikethough") as Brush;
  88. private Brush StrikeoutDefaultColor = App.Current.FindResource("color.sys.layout.divider.underline") as Brush;
  89. private AnnotArgsType annotArgsType = AnnotArgsType.AnnotHighlight;
  90. public List<ColorItem> HighlightItems { get; set; }
  91. public List<ColorItem> UnderLineItems { get; set; }
  92. public List<ColorItem> StrikeoutItems { get; set; }
  93. #endregion 属性
  94. public AnnotAttribEvent AnnotEvent { get; set; }
  95. private AnnotHandlerEventArgs Annot;
  96. public AnnotTransfer PropertyPanel;
  97. public DelegateCommand<object> SelectedColorChangedCommand { get; set; }
  98. public DelegateCommand<object> SelectedOpacityChangedCommand { get; set; }
  99. public DelegateCommand<object> DefaultColorChangedCommand { get; set; }
  100. public TextAnnotPropertyViewModel()
  101. {
  102. SelectedColorChangedCommand = new DelegateCommand<object>(SelectedColorChanged);
  103. DefaultColorChangedCommand = new DelegateCommand<object>(DefaultColorChanged);
  104. SelectedOpacityChangedCommand = new DelegateCommand<object>(SelectedOpacityChanged);
  105. InitHighlightItems();
  106. InitUnderLinetItems();
  107. }
  108. private void InitHighlightItems()
  109. {
  110. HighlightItems = AnnotColorList.GetColorList(ColorSelectorType.Highlight);
  111. }
  112. private void InitUnderLinetItems()
  113. {
  114. UnderLineItems = AnnotColorList.GetColorList(ColorSelectorType.Border);
  115. StrikeoutItems = AnnotColorList.GetColorList(ColorSelectorType.Border);
  116. }
  117. //设置不透明度
  118. private void SelectedOpacityChanged(object obj)
  119. {
  120. if (obj != null)
  121. {
  122. BasicVm.FillOpacity = (double)obj;
  123. BasicVm.FontColor.Opacity = BasicVm.FillOpacity;
  124. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Transparency, BasicVm.FillOpacity);
  125. if (BasicVm.IsMultiSelected == false)
  126. {
  127. PropertyPanel.InvokeToMyTools(BasicVm.AnnotType, BasicVm.FillOpacity);
  128. }
  129. }
  130. }
  131. //设置颜色
  132. public void SelectedColorChanged(object color)
  133. {
  134. if (color != null && PropertyPanel != null)
  135. {
  136. var colorValue = (Color)color;
  137. if (colorValue != null)
  138. {
  139. BasicVm.FontColor = new SolidColorBrush(colorValue);
  140. BasicVm.FontColor.Opacity = BasicVm.FillOpacity;
  141. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Color, colorValue);
  142. if (BasicVm.IsMultiSelected == false)
  143. {
  144. PropertyPanel.InvokeToMyTools(BasicVm.AnnotType, color);
  145. }
  146. }
  147. }
  148. }
  149. public void DefaultColorChanged(object color)
  150. {
  151. if (color != null)
  152. {
  153. var colorValue = (Color)color;
  154. if (colorValue != null)
  155. {
  156. TextDefaultColor = new SolidColorBrush(colorValue);
  157. switch (annotArgsType)
  158. {
  159. case AnnotArgsType.AnnotHighlight:
  160. {
  161. HighlightDefaultColor = new SolidColorBrush(colorValue);
  162. }
  163. break;
  164. case AnnotArgsType.AnnotUnderline:
  165. {
  166. UnderlineDefaultColor = new SolidColorBrush(colorValue);
  167. }
  168. break;
  169. case AnnotArgsType.AnnotStrikeout:
  170. {
  171. StrikeoutDefaultColor = new SolidColorBrush(colorValue);
  172. }
  173. break;
  174. case AnnotArgsType.AnnotSquiggly:
  175. {
  176. }
  177. break;
  178. }
  179. }
  180. }
  181. }
  182. private void SetAnnotType()
  183. {
  184. if (BasicVm.IsMultiSelected)
  185. {
  186. BasicVm.AnnotTypeTitle = "General Properties";
  187. return;
  188. }
  189. switch (BasicVm.AnnotType)
  190. {
  191. case AnnotArgsType.AnnotHighlight:
  192. BasicVm.AnnotTypeTitle = App.MainPageLoader.GetString("Highlight_Title");
  193. break;
  194. case AnnotArgsType.AnnotUnderline:
  195. BasicVm.AnnotTypeTitle = App.MainPageLoader.GetString("Underline_Title");
  196. break;
  197. case AnnotArgsType.AnnotStrikeout:
  198. BasicVm.AnnotTypeTitle = App.MainPageLoader.GetString("Strikethrough_Title");
  199. break;
  200. case AnnotArgsType.AnnotSquiggly:
  201. BasicVm.AnnotTypeTitle = "波浪线";
  202. break;
  203. }
  204. }
  205. public bool IsNavigationTarget(NavigationContext navigationContext)
  206. {
  207. return true;
  208. }
  209. public void OnNavigatedFrom(NavigationContext navigationContext)
  210. {
  211. BasicVm.IsMultiSelected = false;
  212. }
  213. public void OnNavigatedTo(NavigationContext navigationContext)
  214. {
  215. navigationContext.Parameters.TryGetValue<ViewContentViewModel>(ParameterNames.ViewContentViewModel, out ViewContentViewModel);
  216. navigationContext.Parameters.TryGetValue<AnnotTransfer>(ParameterNames.PropertyPanelContentViewModel, out PropertyPanel);
  217. if (PropertyPanel != null)
  218. {
  219. AllVariable();
  220. SetAnnotType();
  221. //多选注释,默认通用属性颜色为高亮注释的预设颜色
  222. if (BasicVm.IsMultiSelected)
  223. {
  224. BasicVm.ColorItems = HighlightItems;
  225. ColorType = ColorSelectorType.Highlight;
  226. var annotate = Settings.Default.AppProperties.Annotate;
  227. if (annotate != null)
  228. {
  229. BasicVm.FontColor = new SolidColorBrush(annotate.HighLightColor);
  230. }
  231. else
  232. {
  233. BasicVm.FontColor = new SolidColorBrush(Color.FromArgb(0x01, 0xff, 0xff, 0xff));
  234. }
  235. }
  236. else
  237. {
  238. SelectedColorItems();
  239. GetAnnotProperty();
  240. }
  241. }
  242. }
  243. private void SelectedColorItems()
  244. {
  245. if (BasicVm.AnnotType == AnnotArgsType.AnnotHighlight)
  246. {
  247. BasicVm.ColorItems = HighlightItems;
  248. ColorType = ColorSelectorType.Highlight;
  249. }
  250. else if (BasicVm.AnnotType == AnnotArgsType.AnnotUnderline)
  251. {
  252. BasicVm.ColorItems = UnderLineItems;
  253. ColorType = ColorSelectorType.Border;
  254. }
  255. else
  256. {
  257. BasicVm.ColorItems = StrikeoutItems;
  258. ColorType = ColorSelectorType.Border;
  259. }
  260. }
  261. //全局变量,优先集中处理
  262. private void AllVariable()
  263. {
  264. AnnotEvent = PropertyPanel.AnnotEvent;
  265. Annot = PropertyPanel.annot;
  266. BasicVm.AnnotType = Annot.EventType;
  267. BasicVm.IsMultiSelected = PropertyPanel.IsMultiSelected;
  268. }
  269. private void GetAnnotProperty()
  270. {
  271. if (Annot != null)
  272. {
  273. annotArgsType = Annot.EventType;
  274. switch (Annot.EventType)
  275. {
  276. case AnnotArgsType.AnnotHighlight:
  277. if (Annot is TextHighlightAnnotArgs)
  278. {
  279. var Hightlight = Annot as TextHighlightAnnotArgs;
  280. if (ViewContentViewModel.IsSettingOut)
  281. {
  282. HighlightDefaultColor = new SolidColorBrush(Hightlight.Color);
  283. ViewContentViewModel.IsSettingOut = false;
  284. }
  285. TextDefaultColor = HighlightDefaultColor;
  286. BasicVm.FillOpacity = Hightlight.Transparency;
  287. BasicVm.FontColor = new SolidColorBrush(Hightlight.Color);
  288. }
  289. break;
  290. case AnnotArgsType.AnnotUnderline:
  291. {
  292. var Underline = Annot as TextUnderlineAnnotArgs;
  293. if (ViewContentViewModel.IsSettingOut)
  294. {
  295. UnderlineDefaultColor = new SolidColorBrush(Underline.Color);
  296. ViewContentViewModel.IsSettingOut = false;
  297. }
  298. TextDefaultColor = UnderlineDefaultColor;
  299. BasicVm.FillOpacity = Underline.Transparency;
  300. BasicVm.FontColor = new SolidColorBrush(Underline.Color);
  301. }
  302. break;
  303. case AnnotArgsType.AnnotStrikeout:
  304. {
  305. var Strikeout = Annot as TextStrikeoutAnnotArgs;
  306. if (ViewContentViewModel.IsSettingOut)
  307. {
  308. StrikeoutDefaultColor = new SolidColorBrush(Strikeout.Color);
  309. ViewContentViewModel.IsSettingOut = false;
  310. }
  311. TextDefaultColor = StrikeoutDefaultColor;
  312. BasicVm.FillOpacity = Strikeout.Transparency;
  313. BasicVm.FontColor = new SolidColorBrush(Strikeout.Color);
  314. }
  315. break;
  316. case AnnotArgsType.AnnotSquiggly:
  317. {
  318. var Squiggly = Annot as TextSquigglyAnnotArgs;
  319. BasicVm.FillOpacity = Squiggly.Transparency;
  320. BasicVm.FontColor = new SolidColorBrush(Squiggly.Color);
  321. }
  322. break;
  323. }
  324. }
  325. }
  326. }
  327. }