TextAnnotPropertyViewModel.cs 13 KB

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