BackgroundCreateFileContentViewModel.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. using ComPDFKit.PDFDocument;
  2. using PDF_Office.Helper;
  3. using PDF_Office.Model.EditTools.Background;
  4. using Prism.Commands;
  5. using Prism.Mvvm;
  6. using Prism.Regions;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. namespace PDF_Office.ViewModels.EditTools.Background
  13. {
  14. public class BackgroundCreateFileContentViewModel : BindableBase, INavigationAware
  15. {
  16. public BackgroundInfo BackgroundInfo { get; set; } = new BackgroundInfo();
  17. private List<string> _rotationList = new List<string>();
  18. public List<string> RotationList
  19. {
  20. get { return _rotationList; }
  21. set { SetProperty(ref _rotationList, value); }
  22. }
  23. private List<string> _opacityList = new List<string>();
  24. public List<string> OpacityList
  25. {
  26. get { return _opacityList; }
  27. set
  28. {
  29. SetProperty(ref _opacityList, value);
  30. }
  31. }
  32. private List<string> _relativeRatioList = new List<string>();
  33. public List<string> RelativeRatioList
  34. {
  35. get { return _relativeRatioList; }
  36. set
  37. {
  38. SetProperty(ref _relativeRatioList, value);
  39. }
  40. }
  41. private int _rotationNumber = 0;
  42. public int RotationNumber
  43. {
  44. get { return _rotationNumber; }
  45. set
  46. {
  47. SetProperty(ref _rotationNumber, value);
  48. }
  49. }
  50. private int _opacityNumber = 100;
  51. public int OpacityNumber
  52. {
  53. get { return _opacityNumber; }
  54. set { SetProperty(ref _opacityNumber, value); }
  55. }
  56. private int _relativeRatioNumber = 0;
  57. public int RelativeRatioNumber
  58. {
  59. get { return _relativeRatioNumber; }
  60. set { SetProperty(ref _rotationNumber, value); }
  61. }
  62. private ObservableDictionary<string, bool> _getLocationFromNumber = new ObservableDictionary<string, bool>();
  63. public ObservableDictionary<string, bool> GetLocationFromNumber
  64. {
  65. get { return _getLocationFromNumber; }
  66. }
  67. public BackgroundCreateFileContentViewModel()
  68. {
  69. ChangeLocationCommand = new DelegateCommand<object>(ChangeLocation);
  70. InitComponent();
  71. BackgroundInfo.BackgroundHorizalign = C_Background_Horizalign.BG_HORIZALIGN_CENTER;
  72. BackgroundInfo.BackgroundVertalign = C_Background_Vertalign.BG_VERTALIGN_CENTER;
  73. InitLocationButtonMatrix();
  74. }
  75. public void InitComponent()
  76. {
  77. InitOpacityList();
  78. InitRotationList();
  79. InitRelativeRatioList();
  80. }
  81. private void InitRotationList()
  82. {
  83. OpacityList.Clear();
  84. for (int defaultRotation = -45; defaultRotation <= 45; defaultRotation += 15)
  85. {
  86. RotationList.Add(defaultRotation.ToString());
  87. }
  88. }
  89. private void InitOpacityList()
  90. {
  91. OpacityList.Clear();
  92. for (int defaultOpacity = 10; defaultOpacity <= 100; defaultOpacity += 10)
  93. {
  94. OpacityList.Add(defaultOpacity.ToString() + " %");
  95. }
  96. }
  97. private void InitRelativeRatioList()
  98. {
  99. RelativeRatioList.Clear();
  100. for (int defaultRelativeRatioList = 10; defaultRelativeRatioList <= 100; defaultRelativeRatioList += 10)
  101. {
  102. RelativeRatioList.Add(defaultRelativeRatioList.ToString() + " %");
  103. }
  104. }
  105. private void InitLocationButtonMatrix()
  106. {
  107. GetLocationFromNumber.Clear();
  108. for (var temp = 0; temp <= 22; temp++)
  109. {
  110. GetLocationFromNumber.Add(temp.ToString(), true);
  111. if (temp % 10 == 2)
  112. {
  113. temp += 7;
  114. }
  115. }
  116. int Num = (int)BackgroundInfo.BackgroundVertalign * 10 + (int)BackgroundInfo.BackgroundHorizalign;
  117. GetLocationFromNumber[Num.ToString()] = false;
  118. }
  119. public DelegateCommand<object> ChangeLocationCommand { get; set; }
  120. public void ChangeLocation(object e)
  121. {
  122. string args = e as string;
  123. if (args != null)
  124. {
  125. BackgroundInfo.BackgroundVertalign = (C_Background_Vertalign)(int.Parse(args) / 10);
  126. BackgroundInfo.BackgroundHorizalign = (C_Background_Horizalign)(int.Parse(args) % 10);
  127. InitLocationButtonMatrix();
  128. }
  129. }
  130. public bool IsNavigationTarget(NavigationContext navigationContext)
  131. {
  132. return true;
  133. }
  134. public void OnNavigatedFrom(NavigationContext navigationContext)
  135. {
  136. }
  137. public void OnNavigatedTo(NavigationContext navigationContext)
  138. {
  139. }
  140. }
  141. }