AnnotToolContentViewModel.Properties.cs 11 KB

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