AnnotToolContentViewModel.Properties.cs 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  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 static 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. public static DashStyle GetLineDashStyle(bool isSolid)
  51. {
  52. DashStyle newDash = new DashStyle();
  53. if(isSolid == false)
  54. {
  55. newDash.Dashes.Add(2);
  56. newDash.Dashes.Add(2);
  57. }
  58. else
  59. {
  60. newDash = DashStyles.Solid;
  61. }
  62. return newDash;
  63. }
  64. //单个属性更改
  65. public void UpdateAnnotAAttrib(AnnotAttrib annotAttrib, object obj)
  66. {
  67. if (annotlists != null && annotlists.Count > 1)
  68. {
  69. foreach (var itemevent in AnnotEvents)
  70. {
  71. itemevent?.UpdateAttrib(annotAttrib, obj);
  72. itemevent?.UpdateAnnot();
  73. }
  74. }
  75. else
  76. {
  77. AnnotEvent?.UpdateAttrib(annotAttrib, obj);
  78. AnnotEvent?.UpdateAnnot();
  79. }
  80. }
  81. //多个属性更改
  82. public void UpdateAnnotAllAttribs(Dictionary<AnnotAttrib, object> AnnotAttribDir)
  83. {
  84. if (annotlists != null && annotlists.Count > 1)
  85. {
  86. foreach (var itemevent in AnnotEvents)
  87. {
  88. foreach (var item in AnnotAttribDir)
  89. {
  90. itemevent?.UpdateAttrib(item.Key, item.Value);
  91. }
  92. itemevent?.UpdateAnnot();
  93. }
  94. }
  95. else
  96. {
  97. foreach (var item in AnnotAttribDir)
  98. {
  99. AnnotEvent?.UpdateAttrib(item.Key, item.Value);
  100. }
  101. AnnotEvent?.UpdateAnnot();
  102. }
  103. }
  104. //是否为多选
  105. public bool IsMultiSelected
  106. { get { return (annotlists != null && annotlists.Count > 1); } }
  107. /// <summary>
  108. /// 更新多个属性,触发到工具栏注释工具,改变工具图标下的颜色值
  109. /// </summary>
  110. public void InvokeToMyTools(object sender, Dictionary<AnnotArgsType, object> keyValues)
  111. {
  112. DataChanged?.Invoke(sender, keyValues);
  113. }
  114. /// <summary>
  115. /// 更新单个属性
  116. /// </summary>
  117. public void InvokeToMyTools(AnnotArgsType argsType, object obj)
  118. {
  119. Dictionary<AnnotArgsType, object> changeData = new Dictionary<AnnotArgsType, object>();
  120. changeData[argsType] = obj;
  121. DataChanged?.Invoke(null, changeData);
  122. }
  123. //同一属性面板,切换注释工具
  124. public void AnnotTypeChangedInvoke(object sender, Dictionary<AnnotArgsType, object> keyValues)
  125. {
  126. AnnotTypeChanged?.Invoke(sender, keyValues);
  127. }
  128. }
  129. public sealed partial class AnnotToolContentViewModel
  130. {
  131. #region 属性
  132. #region 注释工具
  133. //高亮
  134. private Brush highLightColor = new SolidColorBrush(Color.FromRgb(0xFF, 0xBB, 0x00));
  135. public Brush HighLightColor
  136. { get { return highLightColor; } set { SetProperty(ref highLightColor, value); } }
  137. //
  138. private double highLightOpacity = 1;
  139. public double HighLightOpacity
  140. { get { return highLightOpacity; } set { SetProperty(ref highLightOpacity, value); } }
  141. //
  142. private Brush underLine = new SolidColorBrush(Color.FromRgb(0xFF, 0xBB, 0x00));
  143. public Brush UnderLineColor
  144. { get { return underLine; } set { SetProperty(ref underLine, value); } }
  145. //
  146. private double underLineOpacity = 1;
  147. public double UnderLineOpacity
  148. { get { return underLineOpacity; } set { SetProperty(ref underLineOpacity, value); } }
  149. //
  150. private Brush squigglyColor = new SolidColorBrush(Color.FromRgb(0xFF, 0xBB, 0x00));
  151. public Brush SquigglyColor
  152. { get { return squigglyColor; } set { SetProperty(ref squigglyColor, value); } }
  153. //
  154. private double squigglyOpacity = 1;
  155. public double SquigglyOpacity
  156. { get { return squigglyOpacity; } set { SetProperty(ref squigglyOpacity, value); } }
  157. //
  158. private Brush strikeoutColor = new SolidColorBrush(Color.FromRgb(0xFF, 0xBB, 0x00));
  159. public Brush StrikeoutColor
  160. { get { return strikeoutColor; } set { SetProperty(ref strikeoutColor, value); } }
  161. //
  162. private double strikeoutOpacity = 1;
  163. public double StrikeoutOpacity
  164. { get { return strikeoutOpacity; } set { SetProperty(ref strikeoutOpacity, value); } }
  165. private bool btnSelecttoolIsChecked = false;
  166. public bool BtnSelecttoolIsChecked
  167. {
  168. get { return btnSelecttoolIsChecked; }
  169. set
  170. {
  171. SetProperty(ref btnSelecttoolIsChecked, value);
  172. }
  173. }
  174. private bool btnLinkIsChecked = false;
  175. public bool BtnLinkIsChecked
  176. {
  177. get { return btnLinkIsChecked; }
  178. set
  179. {
  180. SetProperty(ref btnLinkIsChecked, value);
  181. }
  182. }
  183. private bool btnHandIsChecked = false;
  184. public bool BtnHandIsChecked
  185. {
  186. get { return btnHandIsChecked; }
  187. set
  188. {
  189. SetProperty(ref btnHandIsChecked, value);
  190. }
  191. }
  192. #endregion 注释工具
  193. #endregion 属性
  194. public string PropertyRegionName { get; set; }
  195. private IEventAggregator events;
  196. public IDialogService dialogs;
  197. public IRegionManager region;
  198. private CPDFViewer PDFViewer;
  199. private ViewContentViewModel viewContentViewModel;
  200. private AnnotPropertyPanel propertyPanel = new AnnotPropertyPanel();
  201. private Dictionary<string, AnnotArgsType> ToolExpandDict = new Dictionary<string, AnnotArgsType>();
  202. private bool isHiddenAnnot = true;
  203. private bool isAddBookMark = true;
  204. private bool isRightMenuAddAnnot = false;
  205. #region 事件
  206. public DelegateCommand<CustomIconToggleBtn> MyToolsCommand { get; set; }
  207. private SnapshotEditMenuViewModel snapshotEditMenuViewModel = new SnapshotEditMenuViewModel();
  208. public SnapshotEditMenuViewModel SnapshotEditMenuViewModel { get => snapshotEditMenuViewModel; set => snapshotEditMenuViewModel = value; }
  209. public DelegateCommand<object> SetAddAnnotationCommand { get; set; }
  210. public DelegateCommand AddBookMarkCommand { get; set; }
  211. #region 注释 - 右键菜单
  212. //公共
  213. public DelegateCommand<object> AnnotDefaultValue_MenuCommand { get; set; }
  214. public DelegateCommand<object> AnnotColorPalette_MenuCommand { get; set; }
  215. public DelegateCommand<object> AnnotAddNoteText_MenuCommand { get; set; }
  216. //高亮、下划线、删除
  217. public DelegateCommand<object> HightAnnotCopyText_MenuCommand { get; set; }
  218. //手绘
  219. public DelegateCommand<object> FreeHandLineStyle_MenuCommand { get; set; }
  220. //文本
  221. public DelegateCommand<object> FreeTextFontFamily_MenuCommand { get; set; }
  222. public DelegateCommand<object> FreeTextAglin_MenuCommand { get; set; }
  223. //便签
  224. public DelegateCommand<object> StrikeNoteEditStrike_MenuCommand { get; set; }
  225. //形状
  226. public DelegateCommand<object> ShapeLineStyle_MenuCommand { get; set; }
  227. public DelegateCommand<object> ShapeLineDirect_MenuCommand { get; set; }
  228. //图章
  229. public DelegateCommand<object> StampExportPicture_MenuCommand { get; set; }
  230. #endregion 注释 - 右键菜单
  231. #endregion 事件
  232. }
  233. public enum AddAnnotType
  234. {
  235. AnnotFreehand,//绘制
  236. AnnotFreeText = 1,//文本
  237. AnnotSticky,//便签
  238. AnnotSquare,//矩形
  239. AnnotCircle,//椭圆形
  240. AnnotArrow,//箭头
  241. AnnotLine,//直线
  242. AnnotLink,//链接
  243. AnnotStamp,//图章
  244. AnnotAutograph //签名
  245. }
  246. }