StickyNotePropertyViewModel.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. using ComPDFKitViewer;
  2. using ComPDFKitViewer.AnnotEvent;
  3. using PDF_Office.CustomControl.CompositeControl;
  4. using PDF_Office.Model;
  5. using PDF_Office.Model.AnnotPanel;
  6. using PDF_Office.ViewModels.Tools;
  7. using PDF_Office.ViewModels.Tools.AnnotManager;
  8. using PDFSettings;
  9. using Prism.Commands;
  10. using Prism.Mvvm;
  11. using Prism.Regions;
  12. using System;
  13. using System.Collections.Generic;
  14. using System.ComponentModel;
  15. using System.Linq;
  16. using System.Text;
  17. using System.Threading.Tasks;
  18. using System.Windows.Media;
  19. namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
  20. {
  21. public class StickyNotePropertyViewModel : BindableBase, INavigationAware
  22. {
  23. //外部UI引用
  24. public string strOtherTag { get; private set; }
  25. private double _transpent;
  26. public double Transpent
  27. {
  28. get { return _transpent; }
  29. set { SetProperty(ref _transpent, value); }
  30. }
  31. private Geometry _exmpleData;
  32. public Geometry ExmpleData
  33. {
  34. get { return _exmpleData; }
  35. set { SetProperty(ref _exmpleData, value); }
  36. }
  37. private Brush _sharpColor;
  38. public Brush SharpColor
  39. {
  40. get { return _sharpColor; }
  41. set { SetProperty(ref _sharpColor, value); SharpCurrentColor = _sharpColor; }
  42. }
  43. private Brush _sharpCurrentColor;
  44. public Brush SharpCurrentColor
  45. {
  46. get { return _sharpCurrentColor; }
  47. set { SetProperty(ref _sharpCurrentColor, value); }
  48. }
  49. private bool _isMultiSelected = false;
  50. public bool IsMultiSelected
  51. {
  52. get { return _isMultiSelected; }
  53. set => SetProperty(ref _isMultiSelected, value);
  54. }
  55. //注释类型名称
  56. private string _annotTypeTitle;
  57. public string AnnotTypeTitle
  58. {
  59. get { return _annotTypeTitle; }
  60. set => SetProperty(ref _annotTypeTitle, value);
  61. }
  62. //样式颜色集合
  63. private List<ColorItem> _colorItems = new List<ColorItem>();
  64. public List<ColorItem> ColorItems
  65. {
  66. get { return _colorItems; }
  67. set => SetProperty(ref _colorItems, value);
  68. }
  69. Dictionary<string, string> StickyNoteTypes = new Dictionary<string, string>();
  70. public event EventHandler<object> LoadPropertyHandler;
  71. public DelegateCommand<object> SelectedColorChangedCommand { get; set; }
  72. public DelegateCommand<object> SelectedValueChangedCommand { get; set; }
  73. public DelegateCommand<object> StrickyNoteShapeCommand { get; set; }
  74. public DelegateCommand<object> SelectedOpacityValueCommand { get; set; }
  75. public StickyNotePropertyViewModel()
  76. {
  77. SelectedValueChangedCommand = new DelegateCommand<object>(SelectedValueChanged_Command);
  78. SelectedColorChangedCommand = new DelegateCommand<object>(SelectedColorChanged_Click);
  79. StrickyNoteShapeCommand = new DelegateCommand<object>(StrickyNoteShape);
  80. SelectedOpacityValueCommand = new DelegateCommand<object>(SelectedOpacityValue);
  81. InitStickyNoteTypes();
  82. InitColorItems();
  83. var data = StickyNoteTypes["Comment"];
  84. var converter = TypeDescriptor.GetConverter(typeof(Geometry));
  85. ExmpleData = (Geometry)converter.ConvertFrom(data);
  86. }
  87. private void InitColorItems()
  88. {
  89. ColorItems = AnnotColorList.GetColorList(ColorSelectorType.Sticky);
  90. }
  91. private void SelectedValueChanged_Command(object obj)
  92. {
  93. if (obj != null)
  94. {
  95. double value = (double)obj;
  96. Transpent = value;
  97. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Transparency, value);
  98. }
  99. }
  100. private void SelectedColorChanged_Click(object obj)
  101. {
  102. if (obj != null && PropertyPanel != null)
  103. {
  104. var color = (Color)obj;
  105. SharpColor =new SolidColorBrush(color);
  106. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Color, color);
  107. }
  108. }
  109. private void StrickyNoteShape(object obj)
  110. {
  111. if (obj != null)
  112. {
  113. var tag = (string)obj;
  114. if (tag == (Annot as StickyAnnotArgs).StickyNote)
  115. return;
  116. var data = StickyNoteTypes[tag];
  117. var converter = TypeDescriptor.GetConverter(typeof(Geometry));
  118. ExmpleData = (Geometry)converter.ConvertFrom(data);
  119. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.StickyIcon, tag);
  120. }
  121. }
  122. private void SelectedOpacityValue(object obj)
  123. {
  124. if (obj != null)
  125. {
  126. double value = (double)obj;
  127. Transpent = value;
  128. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Transparency, value);
  129. }
  130. }
  131. private void InitStickyNoteTypes()
  132. {
  133. StickyNoteTypes.Add("Comment", "M1.54167 2.5C0.96637 2.5 0.5 2.96637 0.5 3.54167V15.2083C0.5 15.7836 0.96637 16.25 1.54167 16.25H3.83344V19.131C3.83344 19.5239 4.25193 19.7753 4.59884 19.5908L10.8802 16.25H19.4583C20.0336 16.25 20.5 15.7836 20.5 15.2083V3.54167C20.5 2.96637 20.0336 2.5 19.4583 2.5H1.54167ZM16.75 8.4375H4.25V6.5625H16.75V8.4375ZM4.25 12.1875H11.75V10.3125H4.25V12.1875Z");
  134. StickyNoteTypes.Add("Note", "M3 1H17V14H12V19H3V1ZM13 19V15H17L13 19ZM15 5V3.5H5V5H15ZM15 8V6.5H5V8H15ZM12 9.5V11H5V9.5H12Z");
  135. StickyNoteTypes.Add("Key", "M14.9552 12.2029C16.009 10.168 15.6751 7.61085 13.9536 5.907C11.8179 3.7932 8.35526 3.7932 6.21956 5.907C4.08386 8.0208 4.08386 11.4479 6.21956 13.5617C7.85915 15.1845 10.2808 15.5615 12.2837 14.6926L17.8206 20.1727H20.6329L20.6329 15.9974L18.1721 15.6495L17.8206 12.518L14.9552 12.2029ZM10.0868 7.64673C10.6692 8.22322 10.6692 9.1579 10.0868 9.73439C9.50432 10.3109 8.55996 10.3109 7.97749 9.73439C7.39503 9.1579 7.39503 8.22322 7.97749 7.64673C8.55996 7.07024 9.50432 7.07024 10.0868 7.64673Z");
  136. StickyNoteTypes.Add("Help", "M12.5 21C17.4706 21 21.5 16.9706 21.5 12C21.5 7.02944 17.4706 3 12.5 3C7.52944 3 3.5 7.02944 3.5 12C3.5 16.9706 7.52944 21 12.5 21ZM13.0439 13.9512V13.5068C13.0439 12.7891 13.29 12.4062 14.1582 11.8936C15.0332 11.3672 15.5869 10.6084 15.5869 9.54199V9.52832C15.5869 8.12695 14.4111 7.06055 12.6885 7.06055C10.7676 7.06055 9.7832 8.23633 9.70801 9.70605V9.71973L10.8701 9.71289L10.8838 9.70605C10.9521 8.73535 11.6084 8.12695 12.6406 8.12695C13.6592 8.12695 14.3154 8.74902 14.3154 9.58984V9.60352C14.3154 10.3281 14.0078 10.7588 13.2148 11.2441C12.2783 11.8047 11.8408 12.4199 11.8477 13.3223V13.9512H13.0439ZM12.5381 17.123C13.0918 17.123 13.4814 16.7266 13.4814 16.1729C13.4814 15.6123 13.0918 15.2158 12.5381 15.2158C11.9844 15.2158 11.5879 15.6123 11.5879 16.1729C11.5879 16.7266 11.9844 17.123 12.5381 17.123Z");
  137. StickyNoteTypes.Add("Insert", "M10.25 13C10.5059 13 10.7565 12.9774 11 12.934V19.5H13V6.5H15V19.5H17V6.5H18.5V4.5H17H15H13H11H10.5V4.50723C10.4173 4.50243 10.3339 4.5 10.25 4.5C7.90279 4.5 6 6.40279 6 8.75C6 11.0972 7.90279 13 10.25 13Z");
  138. StickyNoteTypes.Add("Paragraph", "M12.5 4L19.5 18H5.5L12.5 4Z");
  139. StickyNoteTypes.Add("NewParagraph", "M19.5 13L12.5 2L5.5 13H19.5ZM7.46177 17.0425V22H5.90952V14.2495H7.26304L10.8402 19.1855H10.9261V14.2495H12.4784V22H11.1356L7.54771 17.0425H7.46177ZM15.5803 19.5562V22H13.9583V14.2495H17.1541C18.7869 14.2495 19.8772 15.3022 19.8772 16.8975V16.9082C19.8772 18.5034 18.7869 19.5562 17.1541 19.5562H15.5803ZM16.7566 18.2886H15.5803V15.5332H16.7566C17.6858 15.5332 18.2336 16.022 18.2336 16.9028V16.9136C18.2336 17.7944 17.6858 18.2886 16.7566 18.2886Z");
  140. CommonDrawData.StickyIconDict = StickyNoteTypes;
  141. }
  142. public bool IsNavigationTarget(NavigationContext navigationContext)
  143. {
  144. return true;
  145. }
  146. public void OnNavigatedFrom(NavigationContext navigationContext)
  147. {
  148. IsMultiSelected = false;
  149. }
  150. public AnnotAttribEvent AnnotEvent { get; set; }
  151. private AnnotHandlerEventArgs Annot;
  152. private AnnotTransfer PropertyPanel;
  153. public void OnNavigatedTo(NavigationContext navigationContext)
  154. {
  155. navigationContext.Parameters.TryGetValue<AnnotTransfer>(ParameterNames.PropertyPanelContentViewModel, out PropertyPanel);
  156. if (PropertyPanel != null)
  157. {
  158. AnnotEvent = PropertyPanel.AnnotEvent;
  159. Annot = PropertyPanel.annot;
  160. IsMultiSelected = PropertyPanel.IsMultiSelected;
  161. AnnotTypeTitle = "便签";
  162. if (IsMultiSelected)
  163. {
  164. IsAttributeEquals();
  165. }
  166. else
  167. {
  168. GetAnnotProperty();
  169. }
  170. }
  171. }
  172. private List<StickyAnnotArgs> ConvertLists()
  173. {
  174. List<StickyAnnotArgs> FreeTextLists = new List<StickyAnnotArgs>();
  175. foreach (var item in PropertyPanel.annotlists)
  176. {
  177. var itemFreeText = item as StickyAnnotArgs;
  178. if (itemFreeText != null)
  179. {
  180. FreeTextLists.Add(itemFreeText);
  181. }
  182. }
  183. if (FreeTextLists.Count != PropertyPanel.annotlists.Count)
  184. return null;
  185. else
  186. return FreeTextLists;
  187. }
  188. private void IsAttributeEquals()
  189. {
  190. var list = ConvertLists();
  191. if (list != null)
  192. {
  193. var temp = list[0];
  194. Dictionary<string, bool> isNoEqualsDir = new Dictionary<string, bool>();
  195. isNoEqualsDir.Add("SharpColor", false);
  196. isNoEqualsDir.Add("tag", false);
  197. foreach (var item in list)
  198. {
  199. if (item == list[0])
  200. continue;
  201. if (isNoEqualsDir["SharpColor"] == false)
  202. {
  203. if (temp.Color.A != item.Color.A || temp.Color.R != item.Color.R || temp.Color.G != item.Color.G || temp.Color.B != item.Color.B)
  204. {
  205. SharpColor = new SolidColorBrush(Color.FromArgb(0x01, 0xff, 0xff, 0xff));
  206. isNoEqualsDir["SharpColor"] = true;
  207. }
  208. }
  209. if (isNoEqualsDir["tag"] == false)
  210. {
  211. if (temp.IconName != item.IconName)
  212. {
  213. isNoEqualsDir["tag"] = true;
  214. }
  215. }
  216. }
  217. ////以下是多选注释的属性相等时
  218. if (isNoEqualsDir["SharpColor"] == false)
  219. {
  220. SharpColor = new SolidColorBrush(temp.Color);
  221. }
  222. if (isNoEqualsDir["tag"] == false)
  223. {
  224. strOtherTag = temp.IconName;
  225. }
  226. else
  227. {
  228. strOtherTag = "None";
  229. }
  230. }
  231. }
  232. private void GetAnnotProperty()
  233. {
  234. if (Annot is StickyAnnotArgs)
  235. {
  236. var annot = Annot as StickyAnnotArgs;
  237. if(annot != null)
  238. {
  239. SharpColor = new SolidColorBrush(annot.Color);
  240. Transpent = annot.Transparency;
  241. strOtherTag = annot.IconName;
  242. }
  243. }
  244. }
  245. }
  246. }