TextAnnotPropertyViewModel.cs 8.1 KB

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