TextAnnotPropertyViewModel.cs 9.7 KB

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