AnnotToolContentViewModel.Properties.cs 11 KB

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