|
@@ -1,6 +1,7 @@
|
|
|
using ComPDFKitViewer;
|
|
|
using ComPDFKitViewer.PdfViewer;
|
|
|
using Microsoft.Win32;
|
|
|
+using PDF_Office.Helper;
|
|
|
using PDF_Office.Model;
|
|
|
using Prism.Commands;
|
|
|
using Prism.Mvvm;
|
|
@@ -18,46 +19,84 @@ namespace PDF_Office.ViewModels.PropertyPanel.PDFEdit
|
|
|
{
|
|
|
public class ImageEditPropertyViewModel : PDFEditVM, INavigationAware
|
|
|
{
|
|
|
+ #region 变量
|
|
|
+ //防止自动保存属性值
|
|
|
+ private bool isCanSave = false;
|
|
|
+ public event EventHandler ClearCheckedAglin;
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region 属性
|
|
|
|
|
|
+ #region 是否为多选内容
|
|
|
+ private bool _isMultiSelectImage = false;
|
|
|
+ public bool IsMultiSelectImage { get { return _isMultiSelectImage; } set { SetProperty(ref _isMultiSelectImage, value); } }
|
|
|
+ #endregion
|
|
|
|
|
|
- #region 图像属性
|
|
|
- private double _transpent ;
|
|
|
- public double Transpent { get { return _transpent; } set { SetProperty(ref _transpent, value);
|
|
|
- if (TextEditEvent != null)
|
|
|
+ #region 不透明度
|
|
|
+ private double _transpent;
|
|
|
+ public double Transpent
|
|
|
+ {
|
|
|
+ get { return _transpent; }
|
|
|
+ set
|
|
|
+ {
|
|
|
+ SetProperty(ref _transpent, value);
|
|
|
+ if (TextEditEvent != null && isCanSave)
|
|
|
{
|
|
|
+ if (IsMultiSelectImage)
|
|
|
+ {
|
|
|
+ foreach (var item in TextEditEventList)
|
|
|
+ {
|
|
|
+ item.Transparent = (int)(_transpent * 2.55);
|
|
|
+ item.UpdatePDFEditByEventArgs();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ TextEditEvent.Transparent = (int)(_transpent * 2.55);
|
|
|
+ TextEditEvent.UpdatePDFEditByEventArgs();
|
|
|
+ }
|
|
|
|
|
|
- TextEditEvent.Transparent = (int)(_transpent*2.55);
|
|
|
- TextEditEvent.UpdatePDFEditByEventArgs();
|
|
|
}
|
|
|
- } }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region 是否为图片裁剪状态
|
|
|
private bool _isCrop = false;
|
|
|
- public bool IsCrop{get { return _isCrop; } set{SetProperty(ref _isCrop, value); }}
|
|
|
+ public bool IsCrop { get { return _isCrop; } set { SetProperty(ref _isCrop, value); } }
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region 当前显示图像
|
|
|
//选中的图像
|
|
|
private System.Windows.Media.Imaging.BitmapSource _currentImg;
|
|
|
- public System.Windows.Media.Imaging.BitmapSource CurrentImg {get { return _currentImg; } set{ SetProperty(ref _currentImg, value); }}
|
|
|
+ public System.Windows.Media.Imaging.BitmapSource CurrentImg { get { return _currentImg; } set { SetProperty(ref _currentImg, value); } }
|
|
|
+
|
|
|
+ #endregion
|
|
|
|
|
|
- private bool _isMultiSelectImage = false;
|
|
|
- public bool IsMultiSelectImage { get { return _isMultiSelectImage; } set { SetProperty(ref _isMultiSelectImage, value); }}
|
|
|
#endregion
|
|
|
|
|
|
- #region 图像Command
|
|
|
+ #region Command
|
|
|
+ //替换
|
|
|
public DelegateCommand ReplaceImgCommand { get; set; }
|
|
|
+ //导出
|
|
|
public DelegateCommand ExportImgCommand { get; set; }
|
|
|
+ //裁剪
|
|
|
public DelegateCommand CropImgCommand { get; set; }
|
|
|
+ //对齐
|
|
|
public DelegateCommand<object> ImgAlignCheckedCommand { get; set; }
|
|
|
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// 逆时针旋转
|
|
|
- /// </summary>
|
|
|
+ //逆时针旋转
|
|
|
public DelegateCommand AntiClockwiseCommand { get; set; }
|
|
|
- /// <summary>
|
|
|
- /// 顺时针旋转
|
|
|
- /// </summary>
|
|
|
+
|
|
|
+ //顺时针旋转
|
|
|
public DelegateCommand ClockwiseCommand { get; set; }
|
|
|
+ //裁剪状态
|
|
|
public DelegateCommand CropModeCommand { get; set; }
|
|
|
+ //取消裁剪状态
|
|
|
public DelegateCommand CancelCropCommand { get; set; }
|
|
|
+ //添加文本
|
|
|
public DelegateCommand AddTextCommand { get; set; }
|
|
|
+ //添加图片
|
|
|
public DelegateCommand AddImgCommand { get; set; }
|
|
|
#endregion
|
|
|
|
|
@@ -82,13 +121,14 @@ namespace PDF_Office.ViewModels.PropertyPanel.PDFEdit
|
|
|
CropModeCommand = new DelegateCommand(CropMode);
|
|
|
CancelCropCommand = new DelegateCommand(CancelCropImg);
|
|
|
}
|
|
|
+
|
|
|
+ #region Command实现
|
|
|
+
|
|
|
private void AddText()
|
|
|
{
|
|
|
PDFViewer.SetPDFEditCreateType(ComPDFKit.PDFPage.CPDFEditType.EditText);
|
|
|
}
|
|
|
|
|
|
- #region 图像处理
|
|
|
-
|
|
|
private void CancelCropImg()
|
|
|
{
|
|
|
if (TextEditEvent != null)
|
|
@@ -135,8 +175,8 @@ namespace PDF_Office.ViewModels.PropertyPanel.PDFEdit
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
+ var strFilePath = folder.SelectedPath + "\\0.png";
|
|
|
+ CommonHelper.ShowFileBrowser(strFilePath);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -183,16 +223,30 @@ namespace PDF_Office.ViewModels.PropertyPanel.PDFEdit
|
|
|
|
|
|
private void Clockwise()
|
|
|
{
|
|
|
- TextEditEvent.Rotate = TextEditEvent.Rotate + 90;
|
|
|
- TextEditEvent.UpdatePDFEditByEventArgs();
|
|
|
- GetImagePreView();
|
|
|
+ ImgRoateAngle(90);
|
|
|
}
|
|
|
|
|
|
private void AntiClockwise()
|
|
|
{
|
|
|
- TextEditEvent.Rotate = TextEditEvent.Rotate - 90;
|
|
|
- TextEditEvent?.UpdatePDFEditByEventArgs();
|
|
|
- GetImagePreView();
|
|
|
+ ImgRoateAngle(-90);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void ImgRoateAngle(int angle)
|
|
|
+ {
|
|
|
+ if (IsMultiSelectImage)
|
|
|
+ {
|
|
|
+ foreach (var item in TextEditEventList)
|
|
|
+ {
|
|
|
+ item.Rotate = item.Rotate + angle;
|
|
|
+ item.UpdatePDFEditByEventArgs();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ TextEditEvent.Rotate = TextEditEvent.Rotate + angle;
|
|
|
+ TextEditEvent.UpdatePDFEditByEventArgs();
|
|
|
+ GetImagePreView();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
@@ -256,37 +310,41 @@ namespace PDF_Office.ViewModels.PropertyPanel.PDFEdit
|
|
|
{
|
|
|
PDFViewer.PDFEditCommandHandler -= PDFViewer_PDFEditCommandHandler;
|
|
|
PDFViewer.PDFEditCommandHandler += PDFViewer_PDFEditCommandHandler;
|
|
|
- if (TextEditEventList != null && TextEditEventList.Count > 0)
|
|
|
+ LoadedPDFEdit();
|
|
|
+ isCanSave = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void LoadedPDFEdit()
|
|
|
+ {
|
|
|
+ if (TextEditEventList != null && TextEditEventList.Count > 0)
|
|
|
+ {
|
|
|
+ TextEditEvent = TextEditEventList[0];
|
|
|
+ if (TextEditEventList.Count > 1)
|
|
|
{
|
|
|
- TextEditEvent = TextEditEventList[0];
|
|
|
- if(TextEditEventList.Count >1)
|
|
|
- {
|
|
|
- IsMultiSelectImage = true;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- GetImagePreView();
|
|
|
- }
|
|
|
- if (TextEditEventList.Count == 2)
|
|
|
- {
|
|
|
- IsLayoutAlign = true;
|
|
|
- IsLayoutAvgAlign = false;
|
|
|
- }
|
|
|
- else if (TextEditEventList.Count > 2)
|
|
|
- {
|
|
|
- IsLayoutAlign = true;
|
|
|
- IsLayoutAvgAlign = true;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- IsLayoutAlign = false;
|
|
|
- IsLayoutAvgAlign = false;
|
|
|
- }
|
|
|
- GetPDFEdit();
|
|
|
+ IsMultiSelectImage = true;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ GetImagePreView();
|
|
|
+ }
|
|
|
+ if (TextEditEventList.Count == 2)
|
|
|
+ {
|
|
|
+ IsLayoutAlign = true;
|
|
|
+ IsLayoutAvgAlign = false;
|
|
|
+ }
|
|
|
+ else if (TextEditEventList.Count > 2)
|
|
|
+ {
|
|
|
+ IsLayoutAlign = true;
|
|
|
+ IsLayoutAvgAlign = true;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ IsLayoutAlign = false;
|
|
|
+ IsLayoutAvgAlign = false;
|
|
|
}
|
|
|
+ GetPDFEdit();
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
private void GetPDFEdit()
|
|
|
{
|
|
@@ -300,15 +358,13 @@ namespace PDF_Office.ViewModels.PropertyPanel.PDFEdit
|
|
|
private ContextMenu EmptyStateMenu(object sender)
|
|
|
{
|
|
|
var popMenu = App.Current.FindResource("NoneMenu") as ContextMenu;
|
|
|
- if (popMenu != null && popMenu.Items.Count == 3)
|
|
|
- {
|
|
|
- //粘贴
|
|
|
- SetPopMenuItem(popMenu.Items[0] as MenuItem, sender, ApplicationCommands.Paste);
|
|
|
- //添加文本
|
|
|
- SetPopMenuItem(popMenu.Items[1] as MenuItem, sender, AddTextCommand);
|
|
|
- //添加图像
|
|
|
- SetPopMenuItem(popMenu.Items[2] as MenuItem, sender, AddImgCommand);
|
|
|
- }
|
|
|
+ CustomPopMenu customMenu = new CustomPopMenu(popMenu);
|
|
|
+ //粘贴
|
|
|
+ customMenu.SetMenuBinding(0, sender, ApplicationCommands.Paste);
|
|
|
+ //添加文本
|
|
|
+ customMenu.SetMenuBinding(1, sender, AddTextCommand);
|
|
|
+ //添加图像
|
|
|
+ customMenu.SetMenuBinding(2, sender, AddImgCommand);
|
|
|
|
|
|
return popMenu;
|
|
|
}
|
|
@@ -316,23 +372,21 @@ namespace PDF_Office.ViewModels.PropertyPanel.PDFEdit
|
|
|
private ContextMenu SelectImgPDFEdit(object sender)
|
|
|
{
|
|
|
var popMenu = App.Current.FindResource("SelectImgMenu") as ContextMenu;
|
|
|
- if (popMenu != null && popMenu.Items.Count == 7)
|
|
|
- {
|
|
|
- //复制
|
|
|
- SetPopMenuItem(popMenu.Items[0] as MenuItem, sender, ApplicationCommands.Copy);
|
|
|
- //剪切
|
|
|
- SetPopMenuItem(popMenu.Items[1] as MenuItem, sender, ApplicationCommands.Cut);
|
|
|
- //粘贴
|
|
|
- SetPopMenuItem(popMenu.Items[2] as MenuItem, sender, ApplicationCommands.Paste);
|
|
|
- //删除
|
|
|
- SetPopMenuItem(popMenu.Items[3] as MenuItem, sender, ApplicationCommands.Delete);
|
|
|
- //裁剪
|
|
|
- SetPopMenuItem(popMenu.Items[4] as MenuItem, sender, CropModeCommand);
|
|
|
- //替换
|
|
|
- SetPopMenuItem(popMenu.Items[5] as MenuItem, sender, ReplaceImgCommand);
|
|
|
- //导出
|
|
|
- SetPopMenuItem(popMenu.Items[6] as MenuItem, sender, ExportImgCommand);
|
|
|
- }
|
|
|
+ CustomPopMenu customMenu = new CustomPopMenu(popMenu);
|
|
|
+ //复制
|
|
|
+ customMenu.SetMenuBinding(0, sender, ApplicationCommands.Copy);
|
|
|
+ //剪切
|
|
|
+ customMenu.SetMenuBinding(1, sender, ApplicationCommands.Cut);
|
|
|
+ //粘贴
|
|
|
+ customMenu.SetMenuBinding(2, sender, ApplicationCommands.Paste);
|
|
|
+ //删除
|
|
|
+ customMenu.SetMenuBinding(3, sender, ApplicationCommands.Delete);
|
|
|
+ //裁剪
|
|
|
+ customMenu.SetMenuBinding(4, sender, CropModeCommand);
|
|
|
+ //替换
|
|
|
+ customMenu.SetMenuBinding(5, sender, ReplaceImgCommand);
|
|
|
+ //导出
|
|
|
+ customMenu.SetMenuBinding(6, sender, ExportImgCommand);
|
|
|
return popMenu;
|
|
|
}
|
|
|
|
|
@@ -403,13 +457,13 @@ namespace PDF_Office.ViewModels.PropertyPanel.PDFEdit
|
|
|
}
|
|
|
#region 全局
|
|
|
|
|
|
- public event EventHandler ClearCheckedAglin;
|
|
|
#endregion
|
|
|
public bool IsNavigationTarget(NavigationContext navigationContext) { return true; }
|
|
|
|
|
|
|
|
|
public void OnNavigatedFrom(NavigationContext navigationContext)
|
|
|
{
|
|
|
+ isCanSave = false;
|
|
|
IsMultiSelectImage = false;
|
|
|
TextEditEvent = null;
|
|
|
ClearCheckedAglin?.Invoke(null, null);
|