AnnotToolContentViewModel.Properties.cs 9.9 KB

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