BackgroundCreateFileContentViewModel.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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. using System.Windows;
  13. namespace PDF_Office.ViewModels.EditTools.Background
  14. {
  15. public class BackgroundCreateFileContentViewModel : BindableBase, INavigationAware
  16. {
  17. public BackgroundInfo BackgroundInfo = new BackgroundInfo();
  18. private List<string> _rotationList = new List<string>();
  19. public List<string> RotationList
  20. {
  21. get { return _rotationList; }
  22. set { SetProperty(ref _rotationList, value); }
  23. }
  24. private List<string> _opacityList = new List<string>();
  25. public List<string> OpacityList
  26. {
  27. get { return _opacityList; }
  28. set
  29. {
  30. SetProperty(ref _opacityList, value);
  31. }
  32. }
  33. private List<string> _relativeRatioList = new List<string>();
  34. public List<string> RelativeRatioList
  35. {
  36. get { return _relativeRatioList; }
  37. set
  38. {
  39. SetProperty(ref _relativeRatioList, value);
  40. }
  41. }
  42. private int _rotationNumber = 0;
  43. public int RotationNumber
  44. {
  45. get { return _rotationNumber; }
  46. set
  47. {
  48. SetProperty(ref _rotationNumber, value);
  49. }
  50. }
  51. private int _opacityNumber = 100;
  52. public int OpacityNumber
  53. {
  54. get { return _opacityNumber; }
  55. set { SetProperty(ref _opacityNumber, value); }
  56. }
  57. private int _relativeRatioNumber = 0;
  58. public int RelativeRatioNumber
  59. {
  60. get { return _relativeRatioNumber; }
  61. set { SetProperty(ref _rotationNumber, value); }
  62. }
  63. private ObservableDictionary<string, bool> _getLocationFromNumber = new ObservableDictionary<string, bool>();
  64. public ObservableDictionary<string, bool> GetLocationFromNumber
  65. {
  66. get { return _getLocationFromNumber; }
  67. }
  68. private string _fileNameText = "";
  69. public string FileNameText
  70. {
  71. get { return _fileNameText; }
  72. set
  73. {
  74. SetProperty(ref _fileNameText, value);
  75. }
  76. }
  77. private bool isFirstEnter = true;
  78. public bool IsFirstEnter
  79. {
  80. get => isFirstEnter;
  81. set => isFirstEnter = value;
  82. }
  83. private Visibility _createModFileVisible = Visibility.Collapsed;
  84. public Visibility CreateModFileVisible
  85. {
  86. get => _createModFileVisible;
  87. set=>_createModFileVisible= value;
  88. }
  89. public DelegateCommand OpenFileCommand { get; set; }
  90. public BackgroundCreateFileContentViewModel()
  91. {
  92. ChangeLocationCommand = new DelegateCommand<object>(ChangeLocation);
  93. InitComponent();
  94. BackgroundInfo.BackgroundHorizalign = C_Background_Horizalign.BG_HORIZALIGN_CENTER;
  95. BackgroundInfo.BackgroundVertalign = C_Background_Vertalign.BG_VERTALIGN_CENTER;
  96. InitLocationButtonMatrix();
  97. OpenFileCommand = new DelegateCommand(OpenFile);
  98. }
  99. public void InitComponent()
  100. {
  101. InitOpacityList();
  102. InitRotationList();
  103. InitRelativeRatioList();
  104. }
  105. private void InitRotationList()
  106. {
  107. OpacityList.Clear();
  108. for (int defaultRotation = -45; defaultRotation <= 45; defaultRotation += 15)
  109. {
  110. RotationList.Add(defaultRotation.ToString());
  111. }
  112. }
  113. private void InitOpacityList()
  114. {
  115. OpacityList.Clear();
  116. for (int defaultOpacity = 10; defaultOpacity <= 100; defaultOpacity += 10)
  117. {
  118. OpacityList.Add(defaultOpacity.ToString() + " %");
  119. }
  120. }
  121. private void InitRelativeRatioList()
  122. {
  123. RelativeRatioList.Clear();
  124. for (int defaultRelativeRatioList = 10; defaultRelativeRatioList <= 100; defaultRelativeRatioList += 10)
  125. {
  126. RelativeRatioList.Add(defaultRelativeRatioList.ToString() + " %");
  127. }
  128. }
  129. private void InitLocationButtonMatrix()
  130. {
  131. GetLocationFromNumber.Clear();
  132. for (var temp = 0; temp <= 22; temp++)
  133. {
  134. GetLocationFromNumber.Add(temp.ToString(), true);
  135. if (temp % 10 == 2)
  136. {
  137. temp += 7;
  138. }
  139. }
  140. int Num = (int)BackgroundInfo.BackgroundVertalign * 10 + (int)BackgroundInfo.BackgroundHorizalign;
  141. GetLocationFromNumber[Num.ToString()] = false;
  142. }
  143. public DelegateCommand<object> ChangeLocationCommand { get; set; }
  144. public void OpenFile()
  145. {
  146. System.Windows.Forms.OpenFileDialog dlg = new System.Windows.Forms.OpenFileDialog();
  147. dlg.Multiselect = false;
  148. dlg.Filter = "PDF|*.png;*.jpg;";
  149. if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  150. {
  151. FileNameText = dlg.SafeFileName;
  152. EditToolsHelper.ChooseFile(dlg.FileName, ref BackgroundInfo);
  153. }
  154. }
  155. public void ChangeLocation(object e)
  156. {
  157. string args = e as string;
  158. if (args != null)
  159. {
  160. BackgroundInfo.BackgroundVertalign = (C_Background_Vertalign)(int.Parse(args) / 10);
  161. BackgroundInfo.BackgroundHorizalign = (C_Background_Horizalign)(int.Parse(args) % 10);
  162. InitLocationButtonMatrix();
  163. }
  164. }
  165. public bool IsNavigationTarget(NavigationContext navigationContext)
  166. {
  167. return true;
  168. }
  169. public void OnNavigatedFrom(NavigationContext navigationContext)
  170. {
  171. }
  172. public void OnNavigatedTo(NavigationContext navigationContext)
  173. {
  174. }
  175. }
  176. }