using ComPDFKitViewer;
using ComPDFKitViewer.PdfViewer;
using Microsoft.Win32;
using PDF_Master.EventAggregators;
using PDF_Master.Helper;
using PDF_Master.Model;
using PDF_Master.ViewModels.Tools;
using Prism.Commands;
using Prism.Events;
using Prism.Mvvm;
using Prism.Regions;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
namespace PDF_Master.ViewModels.PropertyPanel.PDFEdit
{
public class ImageEditPropertyViewModel : PDFEditVM, INavigationAware
{
public TextEditToolContentViewModel TextEditToolContentViewModel;
private IEventAggregator events;
///
/// 用于区分事件的唯一码
///
private string unicode;
#region 快捷键
private void ShortCut_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Escape)
{
if (PDFViewer != null)
{
if (PDFViewer.ToolManager != null && IsCrop == true)
{
CancelCropImg();
}
}
}
else if (e.Key == Key.Enter)
{
CropImg();
}
}
#endregion 快捷键
#region 属性和变量
//防止自动保存属性值
private bool isCanSave = false;
public event EventHandler ClearCheckedAglin;
#region 是否为多选内容
private bool _isMultiSelectImage = false;
public bool IsMultiSelectImage
{ get { return _isMultiSelectImage; } set { SetProperty(ref _isMultiSelectImage, value); } }
#endregion 是否为多选内容
private string _opacity1 = "Opacity";
public string Opacity
{
get { return _opacity1; }
set { SetProperty(ref _opacity1, value); }
}
//不透明度
private double _opacity;
public double OpacityUI
{
get { return _opacity; }
set { SetProperty(ref _opacity, value); }
}
private int _OpacitySelectedIndex = 1;
public int OpacitySelectedIndex
{
get { return _OpacitySelectedIndex; }
set { SetProperty(ref _OpacitySelectedIndex, value); }
}
private double _transpent;
public double Transpent
{
get { return _transpent; }
set
{
SetProperty(ref _transpent, value);
if (Transpent == 100 || Transpent == 75 || Transpent == 50 || (Transpent == 25))
{
TextEditEvent.Transparency = (int)((_transpent * 255) / 100.0);
TextEditEvent.UpdatePDFEditByEventArgs();
OpacityUI = _transpent / 100.0;
}
else
{
OpacitySelectedIndex = -1;
}
}
}
//是否为图片裁剪状态
private bool _isCrop = false;
public bool IsCrop
{ get { return _isCrop; } set { SetProperty(ref _isCrop, value); } }
public TextEditToolContentViewModel _viewModel1;
//public ImageEditPropertyViewModel(TextEditToolContentViewModel viewModel1)
//{
// _viewModel1 = viewModel1;
// _viewModel1.PropertyChanged += OnViewModel1PropertyChanged;
//}
private void OnViewModel1PropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == "flg")
{
IsCrop = _viewModel1.flg;
}
if (e.PropertyName == "ReplaceImgflg")
{
if (_viewModel1.ReplaceImgflg == true)
{
ReplaceImg();
_viewModel1.ReplaceImgflg = false;
}
}
if (e.PropertyName == "REImgflg")
{
if (_viewModel1.REImgflg == true)
{
GetImagePreView();
_viewModel1.REImgflg = false;
}
}
if (e.PropertyName == "CropImgflg")
{
if (_viewModel1.CropImgflg == true)
{
GetImagePreView();
_viewModel1.CropImgflg = false;
}
}
}
//选中的图像
private System.Windows.Media.Imaging.BitmapSource _currentImg;
public System.Windows.Media.Imaging.BitmapSource CurrentImg
{ get { return _currentImg; } set { SetProperty(ref _currentImg, value); } }
#endregion 属性和变量
#region Command
//替换
public DelegateCommand ReplaceImgCommand { get; set; }
//导出
public DelegateCommand ExportImgCommand { get; set; }
//裁剪
public DelegateCommand CropImgCommand { get; set; }
//对齐
public DelegateCommand