AnnotToolContentViewModel.Properties.cs 10 KB

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