TextAnnotPropertyViewModel.cs 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Transparency, BasicVm.FillOpacity);
  87. if (BasicVm.IsMultiSelected == false)
  88. {
  89. PropertyPanel.InvokeToMyTools(BasicVm.AnnotType, BasicVm.FillOpacity);
  90. }
  91. }
  92. }
  93. //设置颜色
  94. public void SelectedColorChanged(object color)
  95. {
  96. if (color != null && PropertyPanel != null)
  97. {
  98. var colorValue = (Color)color;
  99. if (colorValue != null)
  100. {
  101. BasicVm.FontColor = new SolidColorBrush(colorValue);
  102. BasicVm.FontColor.Opacity = BasicVm.FillOpacity;
  103. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Color, colorValue);
  104. if (BasicVm.IsMultiSelected == false)
  105. {
  106. PropertyPanel.InvokeToMyTools(BasicVm.AnnotType, color);
  107. }
  108. }
  109. }
  110. }
  111. private void SetAnnotType()
  112. {
  113. switch (BasicVm.AnnotType)
  114. {
  115. case AnnotArgsType.AnnotHighlight:
  116. BasicVm.AnnotTypeTitle = "高亮";
  117. break;
  118. case AnnotArgsType.AnnotUnderline:
  119. BasicVm.AnnotTypeTitle = "下划线";
  120. break;
  121. case AnnotArgsType.AnnotStrikeout:
  122. BasicVm.AnnotTypeTitle = "删除线";
  123. break;
  124. case AnnotArgsType.AnnotSquiggly:
  125. BasicVm.AnnotTypeTitle = "波浪线";
  126. break;
  127. }
  128. }
  129. public bool IsNavigationTarget(NavigationContext navigationContext)
  130. {
  131. return true;
  132. }
  133. public void OnNavigatedFrom(NavigationContext navigationContext)
  134. {
  135. BasicVm.IsMultiSelected = false;
  136. }
  137. public void OnNavigatedTo(NavigationContext navigationContext)
  138. {
  139. navigationContext.Parameters.TryGetValue<AnnotPropertyPanel>(ParameterNames.PropertyPanelContentViewModel, out PropertyPanel);
  140. if(PropertyPanel != null)
  141. {
  142. AnnotEvent = PropertyPanel.AnnotEvent;
  143. Annot = PropertyPanel.annot;
  144. BasicVm.AnnotType = Annot.EventType;
  145. BasicVm.IsMultiSelected = PropertyPanel.IsMultiSelected;
  146. SetAnnotType();
  147. //多选注释,默认通用属性颜色为高亮注释的预设颜色
  148. if(BasicVm.IsMultiSelected)
  149. {
  150. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotHighlight);
  151. if (annotProperty != null)
  152. {
  153. BasicVm.FontColor = new SolidColorBrush(annotProperty.ForgoundColor);
  154. }
  155. }
  156. else
  157. {
  158. GetAnnotProperty();
  159. }
  160. }
  161. }
  162. private void GetAnnotProperty()
  163. {
  164. if (Annot != null)
  165. {
  166. switch (Annot.EventType)
  167. {
  168. case AnnotArgsType.AnnotHighlight:
  169. if (Annot is TextHighlightAnnotArgs)
  170. {
  171. var Hightlight = Annot as TextHighlightAnnotArgs;
  172. BasicVm.FillOpacity = Hightlight.Transparency;
  173. BasicVm.FontColor = new SolidColorBrush(Hightlight.Color);
  174. }
  175. break;
  176. case AnnotArgsType.AnnotUnderline:
  177. {
  178. var Underline = Annot as TextUnderlineAnnotArgs;
  179. BasicVm.FillOpacity = Underline.Transparency;
  180. BasicVm.FontColor = new SolidColorBrush(Underline.Color);
  181. }
  182. break;
  183. case AnnotArgsType.AnnotStrikeout:
  184. {
  185. var Strikeout = Annot as TextStrikeoutAnnotArgs;
  186. BasicVm.FillOpacity = Strikeout.Transparency;
  187. BasicVm.FontColor = new SolidColorBrush(Strikeout.Color);
  188. }
  189. break;
  190. case AnnotArgsType.AnnotSquiggly:
  191. {
  192. var Squiggly = Annot as TextSquigglyAnnotArgs;
  193. BasicVm.FillOpacity = Squiggly.Transparency;
  194. BasicVm.FontColor = new SolidColorBrush(Squiggly.Color);
  195. }
  196. break;
  197. }
  198. }
  199. }
  200. }
  201. }