123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206 |
- using ComPDFKit.PDFDocument;
- using PDF_Office.Helper;
- using PDF_Office.Model.EditTools.Background;
- using Prism.Commands;
- using Prism.Mvvm;
- using Prism.Regions;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- namespace PDF_Office.ViewModels.EditTools.Background
- {
- public class BackgroundCreateFileContentViewModel : BindableBase, INavigationAware
- {
- public BackgroundInfo BackgroundInfo = new BackgroundInfo();
- private List<string> _rotationList = new List<string>();
- public List<string> RotationList
- {
- get { return _rotationList; }
- set { SetProperty(ref _rotationList, value); }
- }
- private List<string> _opacityList = new List<string>();
- public List<string> OpacityList
- {
- get { return _opacityList; }
- set
- {
- SetProperty(ref _opacityList, value);
- }
- }
- private List<string> _relativeRatioList = new List<string>();
- public List<string> RelativeRatioList
- {
- get { return _relativeRatioList; }
- set
- {
- SetProperty(ref _relativeRatioList, value);
- }
- }
- private int _rotationNumber = 0;
- public int RotationNumber
- {
- get { return _rotationNumber; }
- set
- {
- SetProperty(ref _rotationNumber, value);
- }
- }
- private int _opacityNumber = 100;
- public int OpacityNumber
- {
- get { return _opacityNumber; }
- set { SetProperty(ref _opacityNumber, value); }
- }
- private int _relativeRatioNumber = 0;
- public int RelativeRatioNumber
- {
- get { return _relativeRatioNumber; }
- set { SetProperty(ref _rotationNumber, value); }
- }
- private ObservableDictionary<string, bool> _getLocationFromNumber = new ObservableDictionary<string, bool>();
- public ObservableDictionary<string, bool> GetLocationFromNumber
- {
- get { return _getLocationFromNumber; }
- }
- private string _fileNameText = "";
- public string FileNameText
- {
- get { return _fileNameText; }
- set
- {
- SetProperty(ref _fileNameText, value);
- }
- }
- private bool isFirstEnter = true;
- public bool IsFirstEnter
- {
- get => isFirstEnter;
- set => isFirstEnter = value;
- }
- private Visibility _createModFileVisible = Visibility.Collapsed;
- public Visibility CreateModFileVisible
- {
- get => _createModFileVisible;
- set=>_createModFileVisible= value;
- }
-
- public DelegateCommand OpenFileCommand { get; set; }
- public BackgroundCreateFileContentViewModel()
- {
- ChangeLocationCommand = new DelegateCommand<object>(ChangeLocation);
- InitComponent();
- BackgroundInfo.BackgroundHorizalign = C_Background_Horizalign.BG_HORIZALIGN_CENTER;
- BackgroundInfo.BackgroundVertalign = C_Background_Vertalign.BG_VERTALIGN_CENTER;
- InitLocationButtonMatrix();
- OpenFileCommand = new DelegateCommand(OpenFile);
- }
- public void InitComponent()
- {
- InitOpacityList();
- InitRotationList();
- InitRelativeRatioList();
- }
- private void InitRotationList()
- {
- OpacityList.Clear();
- for (int defaultRotation = -45; defaultRotation <= 45; defaultRotation += 15)
- {
- RotationList.Add(defaultRotation.ToString());
- }
- }
- private void InitOpacityList()
- {
- OpacityList.Clear();
- for (int defaultOpacity = 10; defaultOpacity <= 100; defaultOpacity += 10)
- {
- OpacityList.Add(defaultOpacity.ToString() + " %");
- }
- }
- private void InitRelativeRatioList()
- {
- RelativeRatioList.Clear();
- for (int defaultRelativeRatioList = 10; defaultRelativeRatioList <= 100; defaultRelativeRatioList += 10)
- {
- RelativeRatioList.Add(defaultRelativeRatioList.ToString() + " %");
- }
- }
- private void InitLocationButtonMatrix()
- {
- GetLocationFromNumber.Clear();
- for (var temp = 0; temp <= 22; temp++)
- {
- GetLocationFromNumber.Add(temp.ToString(), true);
- if (temp % 10 == 2)
- {
- temp += 7;
- }
- }
- int Num = (int)BackgroundInfo.BackgroundVertalign * 10 + (int)BackgroundInfo.BackgroundHorizalign;
- GetLocationFromNumber[Num.ToString()] = false;
- }
- public DelegateCommand<object> ChangeLocationCommand { get; set; }
- public void OpenFile()
- {
- System.Windows.Forms.OpenFileDialog dlg = new System.Windows.Forms.OpenFileDialog();
- dlg.Multiselect = false;
- dlg.Filter = "PDF|*.png;*.jpg;";
- if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
- {
- FileNameText = dlg.SafeFileName;
- EditToolsHelper.ChooseFile(dlg.FileName, ref BackgroundInfo);
- }
- }
- public void ChangeLocation(object e)
- {
- string args = e as string;
- if (args != null)
- {
- BackgroundInfo.BackgroundVertalign = (C_Background_Vertalign)(int.Parse(args) / 10);
- BackgroundInfo.BackgroundHorizalign = (C_Background_Horizalign)(int.Parse(args) % 10);
- InitLocationButtonMatrix();
- }
- }
- public bool IsNavigationTarget(NavigationContext navigationContext)
- {
- return true;
- }
- public void OnNavigatedFrom(NavigationContext navigationContext)
- {
- }
- public void OnNavigatedTo(NavigationContext navigationContext)
- {
- }
- }
- }
|