Browse Source

页面编辑-插入自定义页面 逻辑调整

OYXH\oyxh 1 year ago
parent
commit
7419a0f5e4
1 changed files with 72 additions and 55 deletions
  1. 72 55
      PDF Office/ViewModels/Dialog/PageEditDialogs/InsertDialogViewModel.cs

+ 72 - 55
PDF Office/ViewModels/Dialog/PageEditDialogs/InsertDialogViewModel.cs

@@ -1,4 +1,5 @@
-using Microsoft.AppCenter.Utils.Files;
+using DotNetSpeech;
+using Microsoft.AppCenter.Utils.Files;
 using PDF_Master.Helper;
 using PDF_Master.Model;
 using PDF_Master.Model.PageEdit;
@@ -131,17 +132,16 @@ namespace PDF_Master.ViewModels.Dialog.PageEditDialogs
                     PageSizeInfo pageSizeInfo = PageSizeInfos[pageSizeSelectedIndex];
                     if (pageSizeInfo != null)
                     {
+                        if (IsVerticalSelected == false)
+                        {
+                            IsVerticalSelected = true;
+                        }
+
                         CustomWidth = pageSizeInfo.Width;
                         CustomHeight = pageSizeInfo.Height;
 
                         Model.width = Convert.ToInt32(pageSizeInfo.Width);
                         Model.height = Convert.ToInt32(pageSizeInfo.Height);
-
-                        //V_Width = CustomWidth;
-                        //V_Height = CustomHeight;
-
-                        //H_Width = CustomHeight;
-                        //H_Height = CustomWidth;
                     }
                 }
             }
@@ -163,7 +163,23 @@ namespace PDF_Master.ViewModels.Dialog.PageEditDialogs
         public bool IsCurrentSelected
         {
             get { return isCurrentSelected; }
-            set { SetProperty(ref isCurrentSelected, value); }
+            set
+            {
+                SetProperty(ref isCurrentSelected, value);
+                if (IsCurrentSelected && size != null)
+                {
+                    if (IsVerticalSelected == false)
+                    {
+                        IsVerticalSelected = true;
+                    }
+
+                    CustomWidth = size.Width.ToString("F0");
+                    CustomHeight = size.Height.ToString("F0");
+
+                    Model.width = Convert.ToInt32(size.Width);
+                    Model.height = Convert.ToInt32(size.Height);
+                }
+            }
         }
 
         private bool isStandSelcted;
@@ -174,6 +190,18 @@ namespace PDF_Master.ViewModels.Dialog.PageEditDialogs
             set
             {
                 SetProperty(ref isStandSelcted, value);
+                PageSizeInfo pageSizeInfo = PageSizeInfos[PageSizeSelectedIndex];
+                if (IsStandSelected && pageSizeInfo != null)
+                {
+                    if (IsVerticalSelected == false)
+                    {
+                        IsVerticalSelected = true;
+                    }
+                    CustomWidth = pageSizeInfo.Width;
+                    CustomHeight = pageSizeInfo.Height;
+                    Model.width = Convert.ToInt32(pageSizeInfo.Width);
+                    Model.height = Convert.ToInt32(pageSizeInfo.Height);
+                }
             }
         }
 
@@ -185,6 +213,10 @@ namespace PDF_Master.ViewModels.Dialog.PageEditDialogs
             set
             {
                 SetProperty(ref isCustomSelected, value);
+                if (IsCustomSelected)
+                {
+                    IsVerticalSelected = true;
+                }
             }
         }
 
@@ -198,11 +230,12 @@ namespace PDF_Master.ViewModels.Dialog.PageEditDialogs
                 SetProperty(ref isVerticalSelected, value);
                 if (isVerticalSelected)
                 {
-                    //if (V_Width != null && V_Height != null)
-                    //{
-                    //    CustomHeight = V_Height;
-                    //    CustomWidth = V_Width;
-                    //}
+                    if (IsCustomSelected)
+                    {
+                        Model.height = int.Parse(CustomWidth);
+                        Model.width = int.Parse(CustomHeight);
+                    }
+
                     if (Model.height != 0 && Model.width != 0)
                     {
                         CustomHeight = Model.height.ToString();
@@ -222,25 +255,26 @@ namespace PDF_Master.ViewModels.Dialog.PageEditDialogs
                 SetProperty(ref isHorizontalSelected, value);
                 if (isHorizontalSelected)
                 {
-                    //if (H_Width != null && H_Height != null)
-                    //{
-                    //    CustomHeight = H_Height;
-                    //    CustomWidth = H_Width;
-                    //}
-                    if (Model.height != 0 && Model.width != 0)
+                    if (IsCustomSelected)
+                    {
+                        Model.height = int.Parse(CustomWidth);
+                        Model.width = int.Parse(CustomHeight);
+
+                        CustomHeight = Model.height.ToString();
+                        CustomWidth = Model.width.ToString();
+                    }
+                    else
                     {
-                        CustomHeight = Model.width.ToString();
-                        CustomWidth = Model.height.ToString();
+                        if (Model.height != 0 && Model.width != 0)
+                        {
+                            CustomHeight = Model.width.ToString();
+                            CustomWidth = Model.height.ToString();
+                        }
                     }
                 }
             }
         }
 
-        //public string H_Width = null;
-        //public string H_Height = null;
-        //public string V_Width = null;
-        //public string V_Height = null;
-
         /// <summary>
         /// 自定义页面的路径集合
         /// </summary>
@@ -356,8 +390,8 @@ namespace PDF_Master.ViewModels.Dialog.PageEditDialogs
             //最后统一处理页面尺寸
             if (IsCurrentSelected)
             {
-                Model.width = (int)size.Width;
-                Model.height = (int)size.Height;
+                Model.width = Convert.ToInt32(size.Width);
+                Model.height = Convert.ToInt32(size.Height);
             }
             else if (IsStandSelected)
             {
@@ -370,17 +404,17 @@ namespace PDF_Master.ViewModels.Dialog.PageEditDialogs
             }
             else
             {
-                int width = (int)size.Width;
-                int height = (int)size.Height;
+                int width = Convert.ToInt32(size.Width);
+                int height = Convert.ToInt32(size.Height);
                 int.TryParse(customWidth, out width);
                 int.TryParse(customHeight, out height);
                 if (width <= 0)
                 {
-                    width = (int)size.Width;
+                    width = Convert.ToInt32(size.Width);
                 }
                 if (height <= 0)
                 {
-                    height = (int)size.Height;
+                    height = Convert.ToInt32(size.Height);
                 }
                 switch (unitsSelectedIndex)
                 {
@@ -390,8 +424,8 @@ namespace PDF_Master.ViewModels.Dialog.PageEditDialogs
                         break;
 
                     case 2:
-                        width = (int)(width / 25.4);
-                        height = (int)(height / 25.4);
+                        width = Convert.ToInt32(width / 25.4);
+                        height = Convert.ToInt32(height / 25.4);
                         break;
 
                     case 0:
@@ -453,33 +487,16 @@ namespace PDF_Master.ViewModels.Dialog.PageEditDialogs
                 if (ListSelectedIndex == -1)
                 {
                     IsCurrentIsEnabled = false;
-                    IsStandSelected = true;
                     PageSizeSelectedIndex = 1;
-                    PageSizeInfo pageSizeInfo = PageSizeInfos[PageSizeSelectedIndex];
-                    if (pageSizeInfo != null)
-                    {
-                        CustomWidth = pageSizeInfo.Width;
-                        CustomHeight = pageSizeInfo.Height;
-                        Model.width = Convert.ToInt32(pageSizeInfo.Width);
-                        Model.height = Convert.ToInt32(pageSizeInfo.Height);
-                    }
+                    IsStandSelected = true;
                 }
                 else
                 {
-                    IsCurrentIsEnabled = true;
                     CurrentPageSize = $"({size.Width.ToString("F0")}mm*{size.Height.ToString("F0")}mm)";
-                    CustomWidth = size.Width.ToString("F0");
-                    CustomHeight = size.Height.ToString("F0");
-
-                    Model.width = (int)size.Width;
-                    Model.height = (int)size.Height;
+                    IsCurrentIsEnabled = true;
+                    IsCurrentSelected = true;
                 }
-                //V_Width = CustomWidth;
-                //V_Height = CustomHeight;
-
-                //H_Width = CustomHeight;
-                //H_Height = CustomWidth;
-                //IsVerticalSelected = true;
+                IsVerticalSelected = true;
             }
         }