TextAnnotPropertyViewModel.cs 14 KB

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