ShapFillPropertyViewModel.cs 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. using ComPDFKitViewer.AnnotEvent;
  2. using ComPDFKitViewer;
  3. using Prism.Mvvm;
  4. using Prism.Regions;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows;
  11. using System.Windows.Media;
  12. using Prism.Commands;
  13. using System.Windows.Controls;
  14. using ComPDFKit.PDFAnnotation;
  15. using PDF_Office.Helper;
  16. namespace PDF_Office.ViewModels.FillAndSign.PropertyPanel
  17. {
  18. public class ShapFillPropertyViewModel : BindableBase, INavigationAware
  19. {
  20. private Geometry dataPath = null;
  21. public Geometry DataPath
  22. {
  23. get { return dataPath; }
  24. set
  25. {
  26. SetProperty(ref dataPath, value);
  27. }
  28. }
  29. private Brush selectColor = new SolidColorBrush(Colors.GreenYellow);
  30. public Brush SelectColor
  31. {
  32. get { return selectColor; }
  33. set
  34. {
  35. SetProperty(ref selectColor, value);
  36. //AnnotEvent?.UpdateAttrib(AnnotAttrib.Color, (selectColor as SolidColorBrush).Color);
  37. //AnnotEvent?.UpdateAnnot();
  38. }
  39. }
  40. private double fillOpacity = 1;
  41. public double FillOpacity
  42. {
  43. get { return fillOpacity; }
  44. set
  45. {
  46. SetProperty(ref fillOpacity, value);
  47. }
  48. }
  49. private double lineWidth = 1;
  50. public double LineWidth
  51. {
  52. get { return lineWidth; }
  53. set
  54. {
  55. SetProperty(ref lineWidth, value);
  56. //if (annotType == AnnotArgsType.AnnotLine)
  57. // AnnotEvent?.UpdateAttrib(AnnotAttrib.Thickness, lineWidth);
  58. //else
  59. // AnnotEvent?.UpdateAttrib(AnnotAttrib.Thickness, lineWidth);
  60. //AnnotEvent?.UpdateAnnot();
  61. }
  62. }
  63. public DelegateCommand<object> SelectedThickCommand { get; set; }
  64. public DelegateCommand<object> SelectedColorCommand { get; set; }
  65. //public DelegateCommand<object> LineStyleCommand { get; set; }
  66. public DelegateCommand<object> SharpsTypeCommand { get; set; }
  67. public DelegateCommand<object> ThicknessChangedCommand { get; set; }
  68. public DelegateCommand<object> SelectedOpacityValueCommand { get; set; }
  69. public ShapFillPropertyViewModel()
  70. {
  71. SelectedThickCommand = new DelegateCommand<object>(SelectedThick_Command);
  72. SelectedColorCommand = new DelegateCommand<object>(SelectedColor_Command);
  73. //LineStyleCommand = new DelegateCommand<object>(LineStyle_Command);
  74. SharpsTypeCommand = new DelegateCommand<object>(SharpsType_Command);
  75. ThicknessChangedCommand = new DelegateCommand<object>(ThicknessChanged_Command);
  76. SelectedOpacityValueCommand = new DelegateCommand<object>(SelectedOpacityValue);
  77. }
  78. private void SharpsType_Command(object obj)
  79. {
  80. if (obj != null)
  81. {
  82. var tag = (string)obj;
  83. SharpsType(tag,obj);
  84. }
  85. }
  86. private void SharpsType(string tag, object obj, bool isFromToolsBtn = false)
  87. {
  88. Dictionary<AnnotArgsType, object> changeData = new Dictionary<AnnotArgsType, object>();
  89. switch (tag)
  90. {
  91. case "HookShape":
  92. var hookShape = new PathGeometry();
  93. hookShape.AddGeometry(Geometry.Parse("M0.599976 7.0286L5.57775 11.8L13.4 1.40002"));
  94. DataPath = hookShape;
  95. changeData[AnnotArgsType.AnnotLine] = tag;
  96. break;
  97. case "ForkShape":
  98. var forkShape = new PathGeometry();
  99. forkShape.AddGeometry(Geometry.Parse(" M3.19995 3.20001L12.8 12.8 M12.8 3.20001L3.20005 12.8"));
  100. DataPath = forkShape;
  101. changeData[AnnotArgsType.AnnotLine] = tag;
  102. break;
  103. case "RectShape":
  104. {
  105. RectangleGeometry rectPath = new RectangleGeometry();
  106. rectPath.Rect = new Rect(0, 5, 28, 22);
  107. DataPath = rectPath;
  108. changeData[AnnotArgsType.AnnotSquare] = tag;
  109. }
  110. break;
  111. case "LineShape":
  112. {
  113. var lineShape = new PathGeometry();
  114. lineShape.AddGeometry(Geometry.Parse(" M0,10L20,10"));
  115. DataPath = lineShape;
  116. changeData[AnnotArgsType.AnnotLine] = tag;
  117. }
  118. break;
  119. case "DotShape":
  120. {
  121. EllipseGeometry circlePath = new EllipseGeometry();
  122. circlePath.RadiusX = 2.4;
  123. circlePath.RadiusY = 2.4;
  124. circlePath.Center = new Point(2.4,2.4);
  125. DataPath = circlePath;
  126. changeData[AnnotArgsType.AnnotCircle] = tag;
  127. }
  128. break;
  129. }
  130. //if (isFromToolsBtn == false)
  131. // PropertyPanel.AnnotTypeChangedInvoke(this, changeData);
  132. }
  133. private void SelectedThick_Command(object obj)
  134. {
  135. if (obj is double)
  136. {
  137. var tran = (double)obj;
  138. //BorderOpacity = tran;
  139. SelectColor.Opacity = tran;
  140. //AnnotEvent?.UpdateAttrib(AnnotAttrib.Transparency, tran);
  141. //AnnotEvent?.UpdateAnnot();
  142. }
  143. }
  144. private void ThicknessChanged_Command(object obj)
  145. {
  146. if (obj != null)
  147. {
  148. var item = (ComboBoxItem)obj;
  149. var content = (string)item.Content;
  150. if (content != null)
  151. {
  152. var intData = int.Parse(content);
  153. LineWidth = intData;
  154. }
  155. }
  156. }
  157. private void SelectedColor_Command(object obj)
  158. {
  159. if (obj != null)
  160. {
  161. var colorValue = (Color)obj;
  162. if (colorValue != null)
  163. {
  164. SelectColor = new SolidColorBrush(colorValue);
  165. SelectColor.Opacity = FillOpacity;
  166. Dictionary<AnnotArgsType, object> changeData = new Dictionary<AnnotArgsType, object>();
  167. changeData[AnnotArgsType.AnnotFreehand] = obj;
  168. //PropertyPanel.DataChangedInvoke(this, changeData);
  169. }
  170. }
  171. }
  172. private void SelectedOpacityValue(object obj)
  173. {
  174. if (obj != null)
  175. {
  176. FillOpacity = (double)obj;
  177. SelectColor.Opacity = FillOpacity;
  178. //AnnotEvent?.UpdateAttrib(AnnotAttrib.Transparency, FillOpacity);
  179. //AnnotEvent?.UpdateAnnot();
  180. Dictionary<AnnotArgsType, object> changeData = new Dictionary<AnnotArgsType, object>();
  181. changeData[AnnotArgsType.AnnotFreehand] = FillOpacity;
  182. //PropertyPanel.DataChangedInvoke(this, changeData);
  183. }
  184. }
  185. public bool IsNavigationTarget(NavigationContext navigationContext)
  186. {
  187. return true;
  188. }
  189. public void OnNavigatedFrom(NavigationContext navigationContext)
  190. {
  191. }
  192. public void OnNavigatedTo(NavigationContext navigationContext)
  193. {
  194. RectangleGeometry rectPath = new RectangleGeometry();
  195. rectPath.Rect = new Rect(0, 5, 28, 22);
  196. DataPath = rectPath;
  197. }
  198. }
  199. }