Browse Source

页面编辑 插入自定义页面

OYXH\oyxh 1 year ago
parent
commit
bf304c01f1

+ 16 - 0
PDF Office/Model/PageEdit/PageSizeInfo.cs

@@ -0,0 +1,16 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace PDF_Master.Model.PageEdit
+{
+    public class PageSizeInfo
+    {
+        public string Name { get; set; }
+        public string Width { get; set; }
+        public string Height { get; set; }
+        public string Unit { get; set; }
+    }
+}

+ 10 - 0
PDF Office/Model/ParameterNames.cs

@@ -127,5 +127,15 @@ namespace PDF_Master.Model
 
         public static string PasswordResult = "PasswordResult";
         public static string Password = "Password";
+
+        /// <summary>
+        /// 页面编辑-插入自定义页面 页面大小
+        /// </summary>
+        public static string CurrentPageSize = "CurrentPageSize";
+
+        /// <summary>
+        /// 页面编辑-插入自定义页面 选中的页面
+        /// </summary>
+        public static string ListSelectedIndex = "ListSelectedIndex";
     }
 }

+ 1 - 0
PDF Office/PDF Master.csproj

@@ -481,6 +481,7 @@
     <Compile Include="Model\PageEdit\PageEditHistory.cs" />
     <Compile Include="Model\PageEdit\PageEditItem.cs" />
     <Compile Include="Model\PageEdit\PageItemUnits.cs" />
+    <Compile Include="Model\PageEdit\PageSizeInfo.cs" />
     <Compile Include="Model\ParameterNames.cs" />
     <Compile Include="Model\PDFTool\ToolItem.cs" />
     <Compile Include="Model\PropertyPanel\AnnotPanel\FontStyleItem.cs" />

+ 159 - 34
PDF Office/ViewModels/Dialog/PageEditDialogs/InsertDialogViewModel.cs

@@ -7,6 +7,7 @@ using Prism.Services.Dialogs;
 using System;
 using System.Collections.Generic;
 using System.Collections.ObjectModel;
+using System.Drawing.Printing;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
@@ -41,6 +42,17 @@ namespace PDF_Master.ViewModels.Dialog.PageEditDialogs
             }
         }
 
+        private int listSelectedIndex;
+
+        public int ListSelectedIndex
+        {
+            get { return listSelectedIndex; }
+            set
+            {
+                SetProperty(ref listSelectedIndex, value);
+            }
+        }
+
         private int itemSelectedIndex = 0;
 
         /// <summary>
@@ -59,8 +71,8 @@ namespace PDF_Master.ViewModels.Dialog.PageEditDialogs
             }
         }
 
-
         private string customWidth;
+
         /// <summary>
         /// 自定义页面宽度
         /// </summary>
@@ -74,6 +86,7 @@ namespace PDF_Master.ViewModels.Dialog.PageEditDialogs
         }
 
         private string customHeight;
+
         /// <summary>
         /// 自定义页面高度
         /// </summary>
@@ -87,6 +100,7 @@ namespace PDF_Master.ViewModels.Dialog.PageEditDialogs
         }
 
         private int unitsSelectedIndex = 0;
+
         /// <summary>
         /// 单位下拉框的选中项索引
         /// </summary>
@@ -110,6 +124,35 @@ namespace PDF_Master.ViewModels.Dialog.PageEditDialogs
             set
             {
                 SetProperty(ref pageSizeSelectedIndex, value);
+                if (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);
+
+                        //V_Width = CustomWidth;
+                        //V_Height = CustomHeight;
+
+                        //H_Width = CustomHeight;
+                        //H_Height = CustomWidth;
+                    }
+                }
+            }
+        }
+
+        private bool isCurrentIsEnabled = true;
+
+        public bool IsCurrentIsEnabled
+        {
+            get { return isCurrentIsEnabled; }
+            set
+            {
+                SetProperty(ref isCurrentIsEnabled, value);
             }
         }
 
@@ -151,6 +194,19 @@ namespace PDF_Master.ViewModels.Dialog.PageEditDialogs
             set
             {
                 SetProperty(ref isVerticalSelected, value);
+                if (isVerticalSelected)
+                {
+                    //if (V_Width != null && V_Height != null)
+                    //{
+                    //    CustomHeight = V_Height;
+                    //    CustomWidth = V_Width;
+                    //}
+                    if (Model.height != 0 && Model.width != 0)
+                    {
+                        CustomHeight = Model.height.ToString();
+                        CustomWidth = Model.width.ToString();
+                    }
+                }
             }
         }
 
@@ -162,12 +218,26 @@ namespace PDF_Master.ViewModels.Dialog.PageEditDialogs
             set
             {
                 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)
+                    {
+                        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>
         /// 自定义页面的路径集合
@@ -180,7 +250,7 @@ namespace PDF_Master.ViewModels.Dialog.PageEditDialogs
         public List<string> Units { get; set; }
 
         public List<string> PageSize { get; set; }
-
+        public List<PageSizeInfo> PageSizeInfos { get; set; }
         public DelegateCommand CancelCommand { get; set; }
 
         public DelegateCommand InsertCommnad { get; set; }
@@ -198,18 +268,39 @@ namespace PDF_Master.ViewModels.Dialog.PageEditDialogs
         private void InitPage()
         {
             PageSize = new List<string>();
-            PageSize.Add("Letter(8.5x11 inches)");
-            PageSize.Add("Legal (210 x 297mm)");
-            PageSize.Add("A3 (297 x 420mm)");
-            PageSize.Add("A4 (210 x 297mm)");
-            PageSize.Add("A5 (148 x 210mm)");
-            PageSize.Add("B4 (250 x 353mm)");
-            PageSize.Add("B5 (176 x 250mm)");
-            PageSize.Add("Executive (7.25x10.5 inches)");
-            PageSize.Add("US4x6 (4x6 inches)");
-            PageSize.Add("US4x8 (4x8 inches)");
-            PageSize.Add("US5x7 (5x7 inches)");
-            PageSize.Add("Comm10 (4.125x9.5 inches)");
+            //PageSize.Add("Letter(8.5x11 inches)");
+            //PageSize.Add("Legal (210 x 297mm)");
+            //PageSize.Add("A3 (297 x 420mm)");
+            //PageSize.Add("A4 (210 x 297mm)");
+            //PageSize.Add("A5 (148 x 210mm)");
+            //PageSize.Add("B4 (250 x 353mm)");
+            //PageSize.Add("B5 (176 x 250mm)");
+            //PageSize.Add("Executive (7.25x10.5 inches)");
+            //PageSize.Add("US4x6 (4x6 inches)");
+            //PageSize.Add("US4x8 (4x8 inches)");
+            //PageSize.Add("US5x7 (5x7 inches)");
+            //PageSize.Add("Comm10 (4.125x9.5 inches)");
+
+            PageSizeInfos = new List<PageSizeInfo>() {
+             new PageSizeInfo(){ Name="A3",Width="297",Height="420",Unit="mm"},
+             new PageSizeInfo(){ Name="A4",Width="210",Height="297",Unit="mm"},
+             new PageSizeInfo(){ Name="A5",Width="148",Height="210",Unit="mm"},
+             new PageSizeInfo(){ Name="B5",Width="176",Height="250",Unit="mm"},
+             new PageSizeInfo(){ Name="10号信封",Width="105",Height="241",Unit="mm"},
+             new PageSizeInfo(){ Name="Choukei 3信封",Width="120",Height="235",Unit="mm"},
+             new PageSizeInfo(){ Name="DL信封",Width="110",Height="220",Unit="mm"},
+             new PageSizeInfo(){ Name="JIS B5",Width="182",Height="257",Unit="mm"},
+             new PageSizeInfo(){ Name="ROC 16K",Width="197",Height="273",Unit="mm"},
+             new PageSizeInfo(){ Name="超大B/A3型",Width="330",Height="483",Unit="mm"},
+             new PageSizeInfo(){ Name="小报用纸",Width="279",Height="432",Unit="mm"},
+             new PageSizeInfo(){ Name="小报用纸(特大)",Width="305",Height="457",Unit="mm"},
+             new PageSizeInfo(){ Name="美国法定用纸",Width="216",Height="356",Unit="mm"},
+             new PageSizeInfo(){ Name="美国信纸",Width="216",Height="279",Unit="mm"},
+            };
+            foreach (var item in PageSizeInfos)
+            {
+                PageSize.Add($"{item.Name}({item.Width} x {item.Height} {item.Unit})");
+            }
         }
 
         /// <summary>
@@ -235,7 +326,6 @@ namespace PDF_Master.ViewModels.Dialog.PageEditDialogs
             Pages.Add(new CustomPageItem() { Name = "格子线", FilePath = System.IO.Path.Combine(Environment.CurrentDirectory, @"Resources\PageEdit\GridLine.jpg") });
         }
 
-
         private void cancel()
         {
             RequestClose.Invoke(new DialogResult(ButtonResult.Cancel));
@@ -244,26 +334,31 @@ namespace PDF_Master.ViewModels.Dialog.PageEditDialogs
         private void insert()
         {
             //最后统一处理页面尺寸
-            if(IsCurrentSelected)
+            if (IsCurrentSelected)
             {
                 Model.width = (int)size.Width;
                 Model.height = (int)size.Height;
             }
-            else if(IsStandSelected)
+            else if (IsStandSelected)
             {
-                //TODO:
+                PageSizeInfo pageSizeInfo = PageSizeInfos[PageSizeSelectedIndex];
+                if (pageSizeInfo != null)
+                {
+                    Model.width = Convert.ToInt32(pageSizeInfo.Width);
+                    Model.height = Convert.ToInt32(pageSizeInfo.Height);
+                }
             }
             else
             {
                 int width = (int)size.Width;
                 int height = (int)size.Height;
-                int.TryParse(customWidth,out width);
-                int.TryParse(customHeight,out height);
-                if(width <= 0)
+                int.TryParse(customWidth, out width);
+                int.TryParse(customHeight, out height);
+                if (width <= 0)
                 {
                     width = (int)size.Width;
                 }
-                if(height<=0)
+                if (height <= 0)
                 {
                     height = (int)size.Height;
                 }
@@ -273,10 +368,12 @@ namespace PDF_Master.ViewModels.Dialog.PageEditDialogs
                         width = width / 10;
                         height = height / 10;
                         break;
+
                     case 2:
                         width = (int)(width / 25.4);
                         height = (int)(height / 25.4);
                         break;
+
                     case 0:
                     default:
                         break;
@@ -322,21 +419,49 @@ namespace PDF_Master.ViewModels.Dialog.PageEditDialogs
 
         public void OnDialogClosed()
         {
-
         }
 
         public void OnDialogOpened(IDialogParameters parameters)
         {
             if (parameters != null)
             {
-                size = parameters.GetValue<Size>("CurrentPageSize");
-                CurrentPageSize = $"({size.Width.ToString("F0")}mm*{size.Height.ToString("F0")}mm)";
-                CustomWidth = size.Width.ToString("F2");
-                CustomHeight = size.Height.ToString("F2");
-                Model.width = (int)size.Width;
-                Model.height = (int)size.Height;
+                size = parameters.GetValue<Size>(ParameterNames.CurrentPageSize);
+                ListSelectedIndex = parameters.GetValue<int>(ParameterNames.ListSelectedIndex);
+
+                //未选择页面时,【当前页】项置灰不可点击,默认选中【标准】A4
+                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);
+                    }
+                }
+                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;
+                }
+                //V_Width = CustomWidth;
+                //V_Height = CustomHeight;
+
+                //H_Width = CustomHeight;
+                //H_Height = CustomWidth;
+                //IsVerticalSelected = true;
             }
         }
-        #endregion
+
+        #endregion 弹窗接口
     }
-}
+}

+ 7 - 2
PDF Office/ViewModels/PageEdit/PageEditContentViewModel.cs

@@ -698,7 +698,9 @@ namespace PDF_Master.ViewModels.PageEdit
                 Size size = new Size();
                 size.Width = CommonHelper.GetUnitsFromPageSize(PDFViewer.Document.GetPageSize(listSelecedIndex).Width);
                 size.Height = CommonHelper.GetUnitsFromPageSize(PDFViewer.Document.GetPageSize(listSelecedIndex).Height);
-                keyValuePairs.Add("CurrentPageSize", size);
+                keyValuePairs.Add(ParameterNames.CurrentPageSize, size);
+                keyValuePairs.Add(ParameterNames.ListSelectedIndex, ListSelectedIndex);
+                //int o = ListSelectedIndex;
                 //插入自定义页面
                 dialogs.ShowDialog(DialogNames.InsertDialog, keyValuePairs, e =>
                 {
@@ -2022,7 +2024,10 @@ namespace PDF_Master.ViewModels.PageEdit
                 }
                 else
                 {
-                    RefreshItemImage(pageRange.Item1, pageRange.Item2);
+                    RefreshItemImage(pageRange.Item1, pageRange.Item2);
+                    //插入后 滚动到 选中的页面
+                    List<int> pageRanges = new List<int>() { pageRange.Item2 };
+                    NotifyUIToRefresh(pageRanges);
                 }
             }
             PDFViewer.UndoManager.CanSave = true;

+ 12 - 8
PDF Office/Views/Dialog/PageEditDialogs/InsertDialog.xaml

@@ -11,8 +11,8 @@
     xmlns:model="clr-namespace:PDF_Master.Model.PageEdit"
     xmlns:pageeditdialogs="clr-namespace:PDF_Master.ViewModels.Dialog.PageEditDialogs"
     xmlns:prism="http://prismlibrary.com/"
-    Width="480"
-    Height="472"
+    Width="380"
+    Height="350"
     d:DataContext="{d:DesignInstance Type=pageeditdialogs:InsertDialogViewModel}"
     d:DesignHeight="450"
     d:DesignWidth="800"
@@ -58,7 +58,7 @@
         <cus:DialogContent.Content>
             <Grid>
                 <Grid.RowDefinitions>
-                    <RowDefinition />
+                    <!--<RowDefinition />-->
                     <RowDefinition Height="auto" />
                     <RowDefinition Height="auto" />
                 </Grid.RowDefinitions>
@@ -68,7 +68,7 @@
                     BorderThickness="0"
                     ItemTemplate="{StaticResource CustomItem}"
                     ItemsSource="{Binding Pages}"
-                    SelectedIndex="{Binding ItemSelectedIndex, Mode=TwoWay}">
+                    SelectedIndex="{Binding ItemSelectedIndex, Mode=TwoWay}" Visibility="Hidden">
                     <ListBox.ItemContainerStyle>
                         <Style TargetType="{x:Type ListBoxItem}">
                             <Setter Property="Template" Value="{StaticResource ListBoxItemControlTemplate}" />
@@ -81,7 +81,7 @@
                         </ItemsPanelTemplate>
                     </ListBox.ItemsPanel>
                 </ListBox>
-                <StackPanel Grid.Row="1" Margin="16,0">
+                <StackPanel Grid.Row="0" Margin="16,0">
                     <TextBlock
                         FontSize="14"
                         FontWeight="SemiBold"
@@ -95,6 +95,7 @@
                             VerticalContentAlignment="Center"
                             Content="当前页"
                             GroupName="PageSize"
+                            IsEnabled="{Binding IsCurrentIsEnabled,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
                             IsChecked="{Binding IsCurrentSelected, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                         <Label
                             Height="32"
@@ -149,7 +150,7 @@
                             SelectedIndex="{Binding UnitsSelectedIndex}" />
                     </StackPanel>
                 </StackPanel>
-                <StackPanel Grid.Row="2" Margin="16,0">
+                <StackPanel Grid.Row="1" Margin="16,0">
                     <TextBlock
                         FontSize="14"
                         FontWeight="SemiBold"
@@ -158,12 +159,15 @@
                         <RadioButton
                             Margin="0,12,0,16"
                             Content="纵向页面"
-                            IsChecked="{Binding IsVerticalSelected, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
+                            IsChecked="{Binding IsVerticalSelected, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
+                            Tag="Vertical"
+                            GroupName="Direction"/>
                         <RadioButton
                             Margin="24,12,0,16"
                             Content="横向页面"
                             IsChecked="{Binding IsHorizontalSelected, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
-                            Tag="Vertical" />
+                            Tag="Horizontal"
+                            GroupName="Direction"/>
                     </StackPanel>
                 </StackPanel>
             </Grid>