AnnotToolContentViewModel.Properties.cs 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  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
  92. { get { return (annotlists != null && annotlists.Count > 1); } }
  93. /// <summary>
  94. /// 更新多个属性,触发到工具栏注释工具,改变工具图标下的颜色值
  95. /// </summary>
  96. public void InvokeToMyTools(object sender, Dictionary<AnnotArgsType, object> keyValues)
  97. {
  98. DataChanged?.Invoke(sender, keyValues);
  99. }
  100. /// <summary>
  101. /// 更新单个属性
  102. /// </summary>
  103. public void InvokeToMyTools(AnnotArgsType argsType, object obj)
  104. {
  105. Dictionary<AnnotArgsType, object> changeData = new Dictionary<AnnotArgsType, object>();
  106. changeData[argsType] = obj;
  107. DataChanged?.Invoke(null, changeData);
  108. }
  109. //同一属性面板,切换注释工具
  110. public void AnnotTypeChangedInvoke(object sender, Dictionary<AnnotArgsType, object> keyValues)
  111. {
  112. AnnotTypeChanged?.Invoke(sender, keyValues);
  113. }
  114. }
  115. public sealed partial class AnnotToolContentViewModel
  116. {
  117. #region 属性
  118. #region 注释工具
  119. //高亮
  120. private Brush highLightColor = new SolidColorBrush(Color.FromRgb(0xFF, 0xBB, 0x00));
  121. public Brush HighLightColor
  122. { get { return highLightColor; } set { SetProperty(ref highLightColor, value); } }
  123. //
  124. private double highLightOpacity = 1;
  125. public double HighLightOpacity
  126. { get { return highLightOpacity; } set { SetProperty(ref highLightOpacity, value); } }
  127. //
  128. private Brush underLine = new SolidColorBrush(Color.FromRgb(0xFF, 0xBB, 0x00));
  129. public Brush UnderLineColor
  130. { get { return underLine; } set { SetProperty(ref underLine, value); } }
  131. //
  132. private double underLineOpacity = 1;
  133. public double UnderLineOpacity
  134. { get { return underLineOpacity; } set { SetProperty(ref underLineOpacity, value); } }
  135. //
  136. private Brush squigglyColor = new SolidColorBrush(Color.FromRgb(0xFF, 0xBB, 0x00));
  137. public Brush SquigglyColor
  138. { get { return squigglyColor; } set { SetProperty(ref squigglyColor, value); } }
  139. //
  140. private double squigglyOpacity = 1;
  141. public double SquigglyOpacity
  142. { get { return squigglyOpacity; } set { SetProperty(ref squigglyOpacity, value); } }
  143. //
  144. private Brush strikeoutColor = new SolidColorBrush(Color.FromRgb(0xFF, 0xBB, 0x00));
  145. public Brush StrikeoutColor
  146. { get { return strikeoutColor; } set { SetProperty(ref strikeoutColor, value); } }
  147. //
  148. private double strikeoutOpacity = 1;
  149. public double StrikeoutOpacity
  150. { get { return strikeoutOpacity; } set { SetProperty(ref strikeoutOpacity, value); } }
  151. private bool btnSelecttoolIsChecked = false;
  152. public bool BtnSelecttoolIsChecked
  153. {
  154. get { return btnSelecttoolIsChecked; }
  155. set
  156. {
  157. SetProperty(ref btnSelecttoolIsChecked, value);
  158. }
  159. }
  160. private bool btnLinkIsChecked = false;
  161. public bool BtnLinkIsChecked
  162. {
  163. get { return btnLinkIsChecked; }
  164. set
  165. {
  166. SetProperty(ref btnLinkIsChecked, value);
  167. }
  168. }
  169. private bool btnHandIsChecked = false;
  170. public bool BtnHandIsChecked
  171. {
  172. get { return btnHandIsChecked; }
  173. set
  174. {
  175. SetProperty(ref btnHandIsChecked, value);
  176. }
  177. }
  178. #endregion 注释工具
  179. #endregion 属性
  180. public string PropertyRegionName { get; set; }
  181. private IEventAggregator events;
  182. public IDialogService dialogs;
  183. public IRegionManager region;
  184. private CPDFViewer PDFViewer;
  185. private ViewContentViewModel viewContentViewModel;
  186. private AnnotPropertyPanel propertyPanel = new AnnotPropertyPanel();
  187. private Dictionary<string, AnnotArgsType> ToolExpandDict = new Dictionary<string, AnnotArgsType>();
  188. private bool isHiddenAnnot = true;
  189. private bool isAddBookMark = true;
  190. private bool isRightMenuAddAnnot = false;
  191. #region 事件
  192. public DelegateCommand<CustomIconToggleBtn> MyToolsCommand { get; set; }
  193. private SnapshotEditMenuViewModel snapshotEditMenuViewModel = new SnapshotEditMenuViewModel();
  194. public SnapshotEditMenuViewModel SnapshotEditMenuViewModel { get => snapshotEditMenuViewModel; set => snapshotEditMenuViewModel = value; }
  195. public DelegateCommand<object> SetAddAnnotationCommand { get; set; }
  196. public DelegateCommand AddBookMarkCommand { get; set; }
  197. #region 注释 - 右键菜单
  198. //公共
  199. public DelegateCommand<object> AnnotDefaultValue_MenuCommand { get; set; }
  200. public DelegateCommand<object> AnnotColorPalette_MenuCommand { get; set; }
  201. public DelegateCommand<object> AnnotAddNoteText_MenuCommand { get; set; }
  202. //高亮、下划线、删除
  203. public DelegateCommand<object> HightAnnotCopyText_MenuCommand { get; set; }
  204. //手绘
  205. public DelegateCommand<object> FreeHandLineStyle_MenuCommand { get; set; }
  206. //文本
  207. public DelegateCommand<object> FreeTextFontFamily_MenuCommand { get; set; }
  208. public DelegateCommand<object> FreeTextAglin_MenuCommand { get; set; }
  209. //便签
  210. public DelegateCommand<object> StrikeNoteEditStrike_MenuCommand { get; set; }
  211. //形状
  212. public DelegateCommand<object> ShapeLineStyle_MenuCommand { get; set; }
  213. public DelegateCommand<object> ShapeLineDirect_MenuCommand { get; set; }
  214. #endregion 注释 - 右键菜单
  215. #endregion 事件
  216. }
  217. public enum AddAnnotType
  218. {
  219. AnnotFreehand,//绘制
  220. AnnotFreeText = 1,//文本
  221. AnnotSticky,//便签
  222. AnnotSquare,//矩形
  223. AnnotCircle,//椭圆形
  224. AnnotArrow,//箭头
  225. AnnotLine,//直线
  226. AnnotLink,//链接
  227. AnnotStamp,//图章
  228. AnnotAutograph //签名
  229. }
  230. }