TextAnnotPropertyViewModel.cs 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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. switch (BasicVm.AnnotType)
  115. {
  116. case AnnotArgsType.AnnotHighlight:
  117. BasicVm.AnnotTypeTitle = "高亮";
  118. break;
  119. case AnnotArgsType.AnnotUnderline:
  120. BasicVm.AnnotTypeTitle = "下划线";
  121. break;
  122. case AnnotArgsType.AnnotStrikeout:
  123. BasicVm.AnnotTypeTitle = "删除线";
  124. break;
  125. case AnnotArgsType.AnnotSquiggly:
  126. BasicVm.AnnotTypeTitle = "波浪线";
  127. break;
  128. }
  129. }
  130. public bool IsNavigationTarget(NavigationContext navigationContext)
  131. {
  132. return true;
  133. }
  134. public void OnNavigatedFrom(NavigationContext navigationContext)
  135. {
  136. BasicVm.IsMultiSelected = false;
  137. }
  138. public void OnNavigatedTo(NavigationContext navigationContext)
  139. {
  140. navigationContext.Parameters.TryGetValue<AnnotPropertyPanel>(ParameterNames.PropertyPanelContentViewModel, out PropertyPanel);
  141. if(PropertyPanel != null)
  142. {
  143. AnnotEvent = PropertyPanel.AnnotEvent;
  144. Annot = PropertyPanel.annot;
  145. BasicVm.AnnotType = Annot.EventType;
  146. BasicVm.IsMultiSelected = PropertyPanel.IsMultiSelected;
  147. SetAnnotType();
  148. //多选注释,默认通用属性颜色为高亮注释的预设颜色
  149. if(BasicVm.IsMultiSelected)
  150. {
  151. var annotate = Settings.Default.AppProperties.Annotate;
  152. if (annotate != null)
  153. {
  154. BasicVm.FontColor = new SolidColorBrush(annotate.HighLightColor);
  155. }
  156. else
  157. {
  158. BasicVm.FontColor = new SolidColorBrush(Colors.Transparent);
  159. }
  160. }
  161. else
  162. {
  163. GetAnnotProperty();
  164. }
  165. }
  166. }
  167. private void GetAnnotProperty()
  168. {
  169. if (Annot != null)
  170. {
  171. switch (Annot.EventType)
  172. {
  173. case AnnotArgsType.AnnotHighlight:
  174. if (Annot is TextHighlightAnnotArgs)
  175. {
  176. var Hightlight = Annot as TextHighlightAnnotArgs;
  177. BasicVm.FillOpacity = Hightlight.Transparency;
  178. BasicVm.FontColor = new SolidColorBrush(Hightlight.Color);
  179. }
  180. break;
  181. case AnnotArgsType.AnnotUnderline:
  182. {
  183. var Underline = Annot as TextUnderlineAnnotArgs;
  184. BasicVm.FillOpacity = Underline.Transparency;
  185. BasicVm.FontColor = new SolidColorBrush(Underline.Color);
  186. }
  187. break;
  188. case AnnotArgsType.AnnotStrikeout:
  189. {
  190. var Strikeout = Annot as TextStrikeoutAnnotArgs;
  191. BasicVm.FillOpacity = Strikeout.Transparency;
  192. BasicVm.FontColor = new SolidColorBrush(Strikeout.Color);
  193. }
  194. break;
  195. case AnnotArgsType.AnnotSquiggly:
  196. {
  197. var Squiggly = Annot as TextSquigglyAnnotArgs;
  198. BasicVm.FillOpacity = Squiggly.Transparency;
  199. BasicVm.FontColor = new SolidColorBrush(Squiggly.Color);
  200. }
  201. break;
  202. }
  203. }
  204. }
  205. }
  206. }