TextAnnotPropertyViewModel.cs 9.8 KB

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