TextAnnotPropertyViewModel.cs 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. using ComPDFKitViewer;
  2. using ComPDFKitViewer.AnnotEvent;
  3. using PDF_Office.CustomControl.CompositeControl;
  4. using PDF_Office.Model;
  5. using PDF_Office.Model.AnnotPanel;
  6. using PDF_Office.Properties;
  7. using PDF_Office.ViewModels.Tools;
  8. using Prism.Commands;
  9. using Prism.Mvvm;
  10. using Prism.Regions;
  11. using System;
  12. using System.Collections.Generic;
  13. using System.Collections.ObjectModel;
  14. using System.Globalization;
  15. using System.Windows;
  16. using System.Windows.Data;
  17. using System.Windows.Media;
  18. namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
  19. {
  20. public class AnnotArgsTypeConverter : IValueConverter
  21. {
  22. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  23. {
  24. if (value is AnnotArgsType)
  25. {
  26. if (parameter is string)
  27. {
  28. var args = (AnnotArgsType)value;
  29. if ((string)parameter == "AnnotHighlight" && args == AnnotArgsType.AnnotHighlight)
  30. {
  31. return Visibility.Visible;
  32. }
  33. if ((string)parameter == "AnnotUnderline" && args == AnnotArgsType.AnnotUnderline)
  34. {
  35. return Visibility.Visible;
  36. }
  37. if ((string)parameter == "AnnotSquiggly" && args == AnnotArgsType.AnnotSquiggly)
  38. {
  39. return Visibility.Visible;
  40. }
  41. if ((string)parameter == "AnnotStrikeout" && args == AnnotArgsType.AnnotStrikeout)
  42. {
  43. return Visibility.Visible;
  44. }
  45. if ((string)parameter == "AnnotSticky" && args == AnnotArgsType.AnnotSticky)
  46. {
  47. return Visibility.Visible;
  48. }
  49. }
  50. }
  51. return Visibility.Collapsed;
  52. }
  53. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  54. {
  55. throw new NotImplementedException();
  56. }
  57. }
  58. public class TextAnnotPropertyViewModel:BindableBase, INavigationAware
  59. {
  60. #region 属性
  61. private AnnotCommon _basicVm = new AnnotCommon();
  62. public AnnotCommon BasicVm
  63. {
  64. get { return _basicVm; }
  65. set => SetProperty(ref _basicVm, value);
  66. }
  67. public List<ColorItem> HighlightItems { get; set; }
  68. public List<ColorItem> UnderLineItems { get; set; }
  69. #endregion 属性
  70. public AnnotAttribEvent AnnotEvent { get; set; }
  71. private AnnotHandlerEventArgs Annot;
  72. private AnnotPropertyPanel PropertyPanel;
  73. public DelegateCommand<object> SelectedColorChangedCommand { get; set; }
  74. public DelegateCommand<object> SelectedOpacityChangedCommand { get; set; }
  75. public TextAnnotPropertyViewModel()
  76. {
  77. SelectedColorChangedCommand = new DelegateCommand<object>(SelectedColorChanged);
  78. SelectedOpacityChangedCommand = new DelegateCommand<object>(SelectedOpacityChanged);
  79. InitHighlightItems();
  80. InitUnderLinetItems();
  81. }
  82. private void InitHighlightItems()
  83. {
  84. HighlightItems = AnnotColorList.GetHighlightColorList();
  85. }
  86. private void InitUnderLinetItems()
  87. {
  88. UnderLineItems = AnnotColorList.GetBorderColorList();
  89. }
  90. //设置不透明度
  91. private void SelectedOpacityChanged(object obj)
  92. {
  93. if (obj != null)
  94. {
  95. BasicVm.FillOpacity = (double)obj;
  96. BasicVm.FontColor.Opacity = BasicVm.FillOpacity;
  97. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Transparency, BasicVm.FillOpacity);
  98. if (BasicVm.IsMultiSelected == false)
  99. {
  100. PropertyPanel.InvokeToMyTools(BasicVm.AnnotType, BasicVm.FillOpacity);
  101. }
  102. }
  103. }
  104. //设置颜色
  105. public void SelectedColorChanged(object color)
  106. {
  107. if (color != null && PropertyPanel != null)
  108. {
  109. var colorValue = (Color)color;
  110. if (colorValue != null)
  111. {
  112. BasicVm.FontColor = new SolidColorBrush(colorValue);
  113. BasicVm.FontColor.Opacity = BasicVm.FillOpacity;
  114. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Color, colorValue);
  115. if (BasicVm.IsMultiSelected == false)
  116. {
  117. PropertyPanel.InvokeToMyTools(BasicVm.AnnotType, color);
  118. }
  119. }
  120. }
  121. }
  122. private void SetAnnotType()
  123. {
  124. if(BasicVm.IsMultiSelected)
  125. {
  126. BasicVm.AnnotTypeTitle = "General Properties";
  127. return;
  128. }
  129. switch (BasicVm.AnnotType)
  130. {
  131. case AnnotArgsType.AnnotHighlight:
  132. BasicVm.AnnotTypeTitle = "高亮";
  133. break;
  134. case AnnotArgsType.AnnotUnderline:
  135. BasicVm.AnnotTypeTitle = "下划线";
  136. break;
  137. case AnnotArgsType.AnnotStrikeout:
  138. BasicVm.AnnotTypeTitle = "删除线";
  139. break;
  140. case AnnotArgsType.AnnotSquiggly:
  141. BasicVm.AnnotTypeTitle = "波浪线";
  142. break;
  143. }
  144. }
  145. public bool IsNavigationTarget(NavigationContext navigationContext)
  146. {
  147. return true;
  148. }
  149. public void OnNavigatedFrom(NavigationContext navigationContext)
  150. {
  151. BasicVm.IsMultiSelected = false;
  152. }
  153. public void OnNavigatedTo(NavigationContext navigationContext)
  154. {
  155. navigationContext.Parameters.TryGetValue<AnnotPropertyPanel>(ParameterNames.PropertyPanelContentViewModel, out PropertyPanel);
  156. if(PropertyPanel != null)
  157. {
  158. AllVariable();
  159. SetAnnotType();
  160. //多选注释,默认通用属性颜色为高亮注释的预设颜色
  161. if (BasicVm.IsMultiSelected)
  162. {
  163. BasicVm.ColorItems = HighlightItems;
  164. var annotate = Settings.Default.AppProperties.Annotate;
  165. if (annotate != null)
  166. {
  167. BasicVm.FontColor = new SolidColorBrush(annotate.HighLightColor);
  168. }
  169. else
  170. {
  171. BasicVm.FontColor = new SolidColorBrush(Colors.Transparent);
  172. }
  173. }
  174. else
  175. {
  176. SelectedColorItems();
  177. GetAnnotProperty();
  178. }
  179. }
  180. }
  181. private void SelectedColorItems()
  182. {
  183. if(BasicVm.AnnotType == AnnotArgsType.AnnotHighlight)
  184. {
  185. BasicVm.ColorItems = HighlightItems;
  186. }
  187. else
  188. {
  189. BasicVm.ColorItems = UnderLineItems;
  190. }
  191. }
  192. //全局变量,优先集中处理
  193. private void AllVariable()
  194. {
  195. AnnotEvent = PropertyPanel.AnnotEvent;
  196. Annot = PropertyPanel.annot;
  197. BasicVm.AnnotType = Annot.EventType;
  198. BasicVm.IsMultiSelected = PropertyPanel.IsMultiSelected;
  199. }
  200. private void GetAnnotProperty()
  201. {
  202. if (Annot != null)
  203. {
  204. switch (Annot.EventType)
  205. {
  206. case AnnotArgsType.AnnotHighlight:
  207. if (Annot is TextHighlightAnnotArgs)
  208. {
  209. var Hightlight = Annot as TextHighlightAnnotArgs;
  210. BasicVm.FillOpacity = Hightlight.Transparency;
  211. BasicVm.FontColor = new SolidColorBrush(Hightlight.Color);
  212. }
  213. break;
  214. case AnnotArgsType.AnnotUnderline:
  215. {
  216. var Underline = Annot as TextUnderlineAnnotArgs;
  217. BasicVm.FillOpacity = Underline.Transparency;
  218. BasicVm.FontColor = new SolidColorBrush(Underline.Color);
  219. }
  220. break;
  221. case AnnotArgsType.AnnotStrikeout:
  222. {
  223. var Strikeout = Annot as TextStrikeoutAnnotArgs;
  224. BasicVm.FillOpacity = Strikeout.Transparency;
  225. BasicVm.FontColor = new SolidColorBrush(Strikeout.Color);
  226. }
  227. break;
  228. case AnnotArgsType.AnnotSquiggly:
  229. {
  230. var Squiggly = Annot as TextSquigglyAnnotArgs;
  231. BasicVm.FillOpacity = Squiggly.Transparency;
  232. BasicVm.FontColor = new SolidColorBrush(Squiggly.Color);
  233. }
  234. break;
  235. }
  236. }
  237. }
  238. }
  239. }