AnnotToolContentViewModel.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. using ComPDFKit.PDFAnnotation;
  2. using ComPDFKitViewer;
  3. using ComPDFKitViewer.AnnotEvent;
  4. using ComPDFKitViewer.PdfViewer;
  5. using Microsoft.Win32;
  6. using PDF_Office.CustomControl;
  7. using PDF_Office.Helper;
  8. using PDF_Office.Model;
  9. using PDF_Office.Properties;
  10. using PDF_Office.ViewModels.PropertyPanel;
  11. using PDF_Office.Views.PropertyPanel.AnnotPanel;
  12. using PDFSettings;
  13. using Prism.Commands;
  14. using Prism.Mvvm;
  15. using Prism.Regions;
  16. using System;
  17. using System.Collections.Generic;
  18. using System.Linq;
  19. using System.Text;
  20. using System.Threading.Tasks;
  21. using System.Windows;
  22. using System.Windows.Controls;
  23. using System.Windows.Media;
  24. namespace PDF_Office.ViewModels.Tools
  25. {
  26. public sealed partial class AnnotToolContentViewModel : BindableBase, INavigationAware
  27. {
  28. public AnnotToolContentViewModel(IRegionManager regionManager)
  29. {
  30. region = regionManager;
  31. MyToolsCommand = new DelegateCommand<CustomIconToggleBtn>(BtnMyTools_Click);
  32. PropertyRegionName = Guid.NewGuid().ToString();
  33. BindingEvent();
  34. InitDefaultValue();
  35. }
  36. private Dictionary<string, bool> ToolExpandDict = new Dictionary<string, bool>();
  37. public void BtnMyTools_Click(CustomIconToggleBtn annotBtn)
  38. {
  39. if(annotBtn.IsChecked == true)
  40. {
  41. AnnotHandlerEventArgs annotArgs = null;
  42. switch (annotBtn.Tag.ToString())
  43. {
  44. case "SnapshotEdit":
  45. break;
  46. case "HighLight":
  47. annotArgs = GetHighLight();
  48. break;
  49. case "UnderLine":
  50. annotArgs = GetUnderLine();
  51. break;
  52. case "Squiggly":
  53. annotArgs = GetSquiggly();
  54. break;
  55. case "Strikeout":
  56. annotArgs = GetStrikeout();
  57. break;
  58. case "Freehand":
  59. annotArgs = GetFreehand();
  60. break;
  61. case "Freetext":
  62. annotArgs = GetFreetext();
  63. break;
  64. case "StickyNote":
  65. annotArgs = GetStickyNote();
  66. break;
  67. case "Rect":
  68. annotArgs = GetRect();
  69. break;
  70. case "Circle":
  71. annotArgs = GetCircle();
  72. break;
  73. case "Arrow":
  74. case "Line":
  75. annotArgs = GetArrowLine(annotBtn.Tag.ToString());
  76. break;
  77. case "Stamp":
  78. annotArgs = GetStamp();
  79. break;
  80. case "Image":
  81. annotArgs = GetImage(annotBtn);
  82. break;
  83. case "Signature":
  84. break;
  85. case "Link":
  86. break;
  87. }
  88. if (annotArgs != null)
  89. {
  90. annotArgs.Author = Settings.Default.AppProperties.Description.Author;
  91. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  92. PDFViewer.SetToolParam(annotArgs);
  93. }
  94. ShowPropertyPanel();
  95. }
  96. else
  97. {
  98. PDFViewer.SetMouseMode(MouseModes.PanTool);
  99. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent",null);
  100. ShowPropertyPanel(false);
  101. }
  102. }
  103. private void AnnotProperty_DefaultStored(object sender, object e)
  104. {
  105. }
  106. private void AnnotPropertyPanel_DataChanged(object sender, Dictionary<AnnotArgsType, object> e)
  107. {
  108. if (e != null)
  109. {
  110. foreach (AnnotArgsType argsType in e.Keys)
  111. {
  112. switch (argsType)
  113. {
  114. case AnnotArgsType.AnnotHighlight:
  115. if (e[argsType] is Color)
  116. {
  117. HighLightColor = new SolidColorBrush((Color)e[argsType]);
  118. }
  119. if (e[argsType] is double)
  120. {
  121. HighLightOpacity = (double)e[argsType];
  122. }
  123. break;
  124. case AnnotArgsType.AnnotUnderline:
  125. if (e[argsType] is Color)
  126. {
  127. UnderLineColor = new SolidColorBrush((Color)e[argsType]);
  128. }
  129. if (e[argsType] is double)
  130. {
  131. underLineOpacity = (double)e[argsType];
  132. }
  133. break;
  134. case AnnotArgsType.AnnotSquiggly:
  135. if (e[argsType] is Color)
  136. {
  137. SquigglyColor = new SolidColorBrush((Color)e[argsType]);
  138. }
  139. if (e[argsType] is double)
  140. {
  141. SquigglyOpacity = (double)e[argsType];
  142. }
  143. break;
  144. case AnnotArgsType.AnnotStrikeout:
  145. if (e[argsType] is Color)
  146. {
  147. StrikeoutColor = new SolidColorBrush((Color)e[argsType]);
  148. }
  149. if (e[argsType] is double)
  150. {
  151. StrikeoutOpacity = (double)e[argsType];
  152. }
  153. break;
  154. }
  155. }
  156. }
  157. }
  158. public IRegionManager region;
  159. public string PropertyRegionName { get; set; }
  160. public bool IsNavigationTarget(NavigationContext navigationContext)
  161. {
  162. return true;
  163. }
  164. public void OnNavigatedFrom(NavigationContext navigationContext)
  165. {
  166. }
  167. public void OnNavigatedTo(NavigationContext navigationContext)
  168. {
  169. navigationContext.Parameters.TryGetValue<ViewContentViewModel>(ParameterNames.ViewContentViewModel, out viewContentViewModel);
  170. navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
  171. // navigationContext.Parameters.TryGetValue<PropertyPanelContentViewModel>(ParameterNames.PropertyPanelContentViewModel, out propertyPanelContentViewModel);
  172. if (PDFViewer != null)
  173. {
  174. }
  175. }
  176. /// <summary>
  177. /// 展开显示属性面板
  178. /// </summary>
  179. private void ShowPropertyPanel(bool show=true)
  180. {
  181. viewContentViewModel.IsPropertyOpen = show;
  182. }
  183. }
  184. }