AnnotToolContentViewModel.Properties.cs 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. using ComPDFKitViewer;
  2. using ComPDFKitViewer.AnnotEvent;
  3. using ComPDFKitViewer.PdfViewer;
  4. using PDF_Office.CustomControl;
  5. using PDF_Office.ViewModels.PropertyPanel.AnnotPanel;
  6. using Prism.Commands;
  7. using Prism.Events;
  8. using Prism.Regions;
  9. using Prism.Services.Dialogs;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Threading.Tasks;
  15. using System.Windows.Media;
  16. namespace PDF_Office.ViewModels.Tools
  17. {
  18. /// <summary>
  19. /// 改变工具栏注释属性值,主要用来传参数:注释属性和同步工具栏对应图标的属性(颜色)
  20. /// </summary>
  21. public class AnnotPropertyPanel
  22. {
  23. public AnnotAttribEvent AnnotEvent { get; set; }
  24. public List<AnnotAttribEvent> AnnotEvents = new List<AnnotAttribEvent>();
  25. public AnnotHandlerEventArgs annot;
  26. public List<AnnotHandlerEventArgs> annotlists;
  27. public event EventHandler<Dictionary<AnnotArgsType, object>> DataChanged;
  28. public event EventHandler<Dictionary<AnnotArgsType, object>> AnnotTypeChanged;
  29. public event EventHandler<object> DefaultStored;
  30. public AnnotPropertyPanel()
  31. { }
  32. //外部UI控件选中状态
  33. public bool IsSolidStyle(DashStyle LineDash)
  34. {
  35. bool isSolid = true;
  36. if (LineDash == null || LineDash.Dashes.Count == 0)
  37. {
  38. return isSolid;
  39. }
  40. foreach (var item in LineDash.Dashes)
  41. {
  42. if (item > 0)
  43. {
  44. isSolid = false;
  45. break;
  46. }
  47. }
  48. return isSolid;
  49. }
  50. //单个属性更改
  51. public void UpdateAnnotAAttrib(AnnotAttrib annotAttrib, object obj)
  52. {
  53. if (annotlists != null && annotlists.Count > 1)
  54. {
  55. foreach (var itemevent in AnnotEvents)
  56. {
  57. itemevent?.UpdateAttrib(annotAttrib, obj);
  58. itemevent?.UpdateAnnot();
  59. }
  60. }
  61. else
  62. {
  63. AnnotEvent?.UpdateAttrib(annotAttrib, obj);
  64. AnnotEvent?.UpdateAnnot();
  65. }
  66. }
  67. //多个属性更改
  68. public void UpdateAnnotAllAttribs(Dictionary<AnnotAttrib, object> AnnotAttribDir)
  69. {
  70. if (annotlists != null && annotlists.Count > 1)
  71. {
  72. foreach (var itemevent in AnnotEvents)
  73. {
  74. foreach (var item in AnnotAttribDir)
  75. {
  76. itemevent?.UpdateAttrib(item.Key, item.Value);
  77. }
  78. itemevent?.UpdateAnnot();
  79. }
  80. }
  81. else
  82. {
  83. foreach (var item in AnnotAttribDir)
  84. {
  85. AnnotEvent?.UpdateAttrib(item.Key, item.Value);
  86. }
  87. AnnotEvent?.UpdateAnnot();
  88. }
  89. }
  90. //是否为多选
  91. public bool IsMultiSelected { get { return (annotlists != null && annotlists.Count > 1); } }
  92. /// <summary>
  93. /// 更新多个属性,触发到工具栏注释工具,改变工具图标下的颜色值
  94. /// </summary>
  95. public void InvokeToMyTools(object sender, Dictionary<AnnotArgsType, object> keyValues)
  96. {
  97. DataChanged?.Invoke(sender, keyValues);
  98. }
  99. /// <summary>
  100. /// 更新单个属性
  101. /// </summary>
  102. public void InvokeToMyTools(AnnotArgsType argsType, object obj)
  103. {
  104. Dictionary<AnnotArgsType, object> changeData = new Dictionary<AnnotArgsType, object>();
  105. changeData[argsType] = obj;
  106. DataChanged?.Invoke(null, changeData);
  107. }
  108. //同一属性面板,切换注释工具
  109. public void AnnotTypeChangedInvoke(object sender, Dictionary<AnnotArgsType, object> keyValues)
  110. {
  111. AnnotTypeChanged?.Invoke(sender, keyValues);
  112. }
  113. }
  114. public sealed partial class AnnotToolContentViewModel
  115. {
  116. #region 属性
  117. #region 注释工具
  118. //高亮
  119. private Brush highLightColor = new SolidColorBrush(Color.FromRgb(0xFF, 0xBB, 0x00));
  120. public Brush HighLightColor
  121. { get { return highLightColor; } set { SetProperty(ref highLightColor, value); } }
  122. //
  123. private double highLightOpacity = 1;
  124. public double HighLightOpacity
  125. { get { return highLightOpacity; } set { SetProperty(ref highLightOpacity, value); } }
  126. //
  127. private Brush underLine = new SolidColorBrush(Color.FromRgb(0xFF, 0xBB, 0x00));
  128. public Brush UnderLineColor
  129. { get { return underLine; } set { SetProperty(ref underLine, value); } }
  130. //
  131. private double underLineOpacity = 1;
  132. public double UnderLineOpacity
  133. { get { return underLineOpacity; } set { SetProperty(ref underLineOpacity, value); } }
  134. //
  135. private Brush squigglyColor = new SolidColorBrush(Color.FromRgb(0xFF, 0xBB, 0x00));
  136. public Brush SquigglyColor
  137. { get { return squigglyColor; } set { SetProperty(ref squigglyColor, value); } }
  138. //
  139. private double squigglyOpacity = 1;
  140. public double SquigglyOpacity
  141. { get { return squigglyOpacity; } set { SetProperty(ref squigglyOpacity, value); } }
  142. //
  143. private Brush strikeoutColor = new SolidColorBrush(Color.FromRgb(0xFF, 0xBB, 0x00));
  144. public Brush StrikeoutColor
  145. { get { return strikeoutColor; } set { SetProperty(ref strikeoutColor, value); } }
  146. //
  147. private double strikeoutOpacity = 1;
  148. public double StrikeoutOpacity
  149. { get { return strikeoutOpacity; } set { SetProperty(ref strikeoutOpacity, value); } }
  150. private bool btnSelecttoolIsChecked = false;
  151. public bool BtnSelecttoolIsChecked
  152. {
  153. get { return btnSelecttoolIsChecked; }
  154. set
  155. {
  156. SetProperty(ref btnSelecttoolIsChecked, value);
  157. }
  158. }
  159. private bool btnLinkIsChecked = false;
  160. public bool BtnLinkIsChecked
  161. {
  162. get { return btnLinkIsChecked; }
  163. set
  164. {
  165. SetProperty(ref btnLinkIsChecked, value);
  166. }
  167. }
  168. private bool btnHandIsChecked = false;
  169. public bool BtnHandIsChecked
  170. {
  171. get { return btnHandIsChecked; }
  172. set
  173. {
  174. SetProperty(ref btnHandIsChecked, value);
  175. }
  176. }
  177. #endregion 注释工具
  178. #endregion 属性
  179. public string PropertyRegionName { get; set; }
  180. private IEventAggregator events;
  181. public IDialogService dialogs;
  182. public IRegionManager region;
  183. private CPDFViewer PDFViewer;
  184. private ViewContentViewModel viewContentViewModel;
  185. private AnnotPropertyPanel propertyPanel = new AnnotPropertyPanel();
  186. private Dictionary<string, AnnotArgsType> ToolExpandDict = new Dictionary<string, AnnotArgsType>();
  187. private bool isHiddenAnnot = true;
  188. private bool isAddBookMark = true;
  189. private bool isRightMenuAddAnnot = false;
  190. #region 事件
  191. public DelegateCommand<CustomIconToggleBtn> MyToolsCommand { get; set; }
  192. private SnapshotEditMenuViewModel snapshotEditMenuViewModel = new SnapshotEditMenuViewModel();
  193. public SnapshotEditMenuViewModel SnapshotEditMenuViewModel { get => snapshotEditMenuViewModel; set => snapshotEditMenuViewModel = value; }
  194. public DelegateCommand<object> SetAddAnnotationCommand { get; set; }
  195. #endregion 事件
  196. }
  197. public enum AddAnnotType
  198. {
  199. AnnotFreehand,//绘制
  200. AnnotFreeText = 1,//文本
  201. AnnotSticky,//便签
  202. AnnotSquare,//矩形
  203. AnnotCircle,//椭圆形
  204. AnnotArrow,//箭头
  205. AnnotLine,//直线
  206. AnnotLink,//链接
  207. AnnotStamp,//图章
  208. AnnotAutograph //签名
  209. }
  210. }