TextAnnotPropertyViewModel.cs 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. using ComPDFKitViewer;
  2. using ComPDFKitViewer.AnnotEvent;
  3. using PDF_Office.Helper;
  4. using PDF_Office.Model;
  5. using PDF_Office.Properties;
  6. using PDF_Office.ViewModels.Tools;
  7. using PDFSettings;
  8. using Prism.Commands;
  9. using Prism.Mvvm;
  10. using Prism.Regions;
  11. using System;
  12. using System.Collections.Generic;
  13. using System.Globalization;
  14. using System.Linq;
  15. using System.Text;
  16. using System.Threading.Tasks;
  17. using System.Windows;
  18. using System.Windows.Data;
  19. using System.Windows.Media;
  20. namespace PDF_Office.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 AnnotBasePropertyVM _basicVm = new AnnotBasePropertyVM();
  64. public AnnotBasePropertyVM BasicVm
  65. {
  66. get { return _basicVm; }
  67. set => SetProperty(ref _basicVm, value);
  68. }
  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. }
  80. //设置不透明度
  81. private void SelectedOpacityChanged(object obj)
  82. {
  83. if (obj != null)
  84. {
  85. BasicVm.FillOpacity = (double)obj;
  86. BasicVm.FontColor.Opacity = BasicVm.FillOpacity;
  87. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Transparency, BasicVm.FillOpacity);
  88. if (BasicVm.IsMultiSelected == false)
  89. {
  90. PropertyPanel.InvokeToMyTools(BasicVm.AnnotType, BasicVm.FillOpacity);
  91. }
  92. }
  93. }
  94. //设置颜色
  95. public void SelectedColorChanged(object color)
  96. {
  97. if (color != null && PropertyPanel != null)
  98. {
  99. var colorValue = (Color)color;
  100. if (colorValue != null)
  101. {
  102. BasicVm.FontColor = new SolidColorBrush(colorValue);
  103. BasicVm.FontColor.Opacity = BasicVm.FillOpacity;
  104. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Color, colorValue);
  105. if (BasicVm.IsMultiSelected == false)
  106. {
  107. PropertyPanel.InvokeToMyTools(BasicVm.AnnotType, color);
  108. }
  109. }
  110. }
  111. }
  112. private void SetAnnotType()
  113. {
  114. if(BasicVm.IsMultiSelected)
  115. {
  116. BasicVm.AnnotTypeTitle = "General Properties";
  117. return;
  118. }
  119. switch (BasicVm.AnnotType)
  120. {
  121. case AnnotArgsType.AnnotHighlight:
  122. BasicVm.AnnotTypeTitle = "高亮";
  123. break;
  124. case AnnotArgsType.AnnotUnderline:
  125. BasicVm.AnnotTypeTitle = "下划线";
  126. break;
  127. case AnnotArgsType.AnnotStrikeout:
  128. BasicVm.AnnotTypeTitle = "删除线";
  129. break;
  130. case AnnotArgsType.AnnotSquiggly:
  131. BasicVm.AnnotTypeTitle = "波浪线";
  132. break;
  133. }
  134. }
  135. public bool IsNavigationTarget(NavigationContext navigationContext)
  136. {
  137. return true;
  138. }
  139. public void OnNavigatedFrom(NavigationContext navigationContext)
  140. {
  141. BasicVm.IsMultiSelected = false;
  142. }
  143. public void OnNavigatedTo(NavigationContext navigationContext)
  144. {
  145. navigationContext.Parameters.TryGetValue<AnnotPropertyPanel>(ParameterNames.PropertyPanelContentViewModel, out PropertyPanel);
  146. if(PropertyPanel != null)
  147. {
  148. AllVariable();
  149. SetAnnotType();
  150. //多选注释,默认通用属性颜色为高亮注释的预设颜色
  151. if (BasicVm.IsMultiSelected)
  152. {
  153. var annotate = Settings.Default.AppProperties.Annotate;
  154. if (annotate != null)
  155. {
  156. BasicVm.FontColor = new SolidColorBrush(annotate.HighLightColor);
  157. }
  158. else
  159. {
  160. BasicVm.FontColor = new SolidColorBrush(Colors.Transparent);
  161. }
  162. }
  163. else
  164. {
  165. GetAnnotProperty();
  166. }
  167. }
  168. }
  169. //全局变量,优先集中处理
  170. private void AllVariable()
  171. {
  172. AnnotEvent = PropertyPanel.AnnotEvent;
  173. Annot = PropertyPanel.annot;
  174. BasicVm.AnnotType = Annot.EventType;
  175. BasicVm.IsMultiSelected = PropertyPanel.IsMultiSelected;
  176. }
  177. private void GetAnnotProperty()
  178. {
  179. if (Annot != null)
  180. {
  181. switch (Annot.EventType)
  182. {
  183. case AnnotArgsType.AnnotHighlight:
  184. if (Annot is TextHighlightAnnotArgs)
  185. {
  186. var Hightlight = Annot as TextHighlightAnnotArgs;
  187. BasicVm.FillOpacity = Hightlight.Transparency;
  188. BasicVm.FontColor = new SolidColorBrush(Hightlight.Color);
  189. }
  190. break;
  191. case AnnotArgsType.AnnotUnderline:
  192. {
  193. var Underline = Annot as TextUnderlineAnnotArgs;
  194. BasicVm.FillOpacity = Underline.Transparency;
  195. BasicVm.FontColor = new SolidColorBrush(Underline.Color);
  196. }
  197. break;
  198. case AnnotArgsType.AnnotStrikeout:
  199. {
  200. var Strikeout = Annot as TextStrikeoutAnnotArgs;
  201. BasicVm.FillOpacity = Strikeout.Transparency;
  202. BasicVm.FontColor = new SolidColorBrush(Strikeout.Color);
  203. }
  204. break;
  205. case AnnotArgsType.AnnotSquiggly:
  206. {
  207. var Squiggly = Annot as TextSquigglyAnnotArgs;
  208. BasicVm.FillOpacity = Squiggly.Transparency;
  209. BasicVm.FontColor = new SolidColorBrush(Squiggly.Color);
  210. }
  211. break;
  212. }
  213. }
  214. }
  215. }
  216. }