Ver código fonte

Merge branch 'practice2' of http://git.kdan.cc:8865/Windows/PDFOffice_Windows_exe into practice2

OYXH\oyxh 2 anos atrás
pai
commit
fe0aa9ed05

+ 12 - 0
PDF Office/PDF Office.csproj

@@ -222,6 +222,7 @@
     <Compile Include="DataConvert\FileFormatToIconConvert.cs" />
     <Compile Include="DataConvert\GroupHeaderConverter.cs" />
     <Compile Include="DataConvert\IntToBooleanConvert.cs" />
+    <Compile Include="DataConvert\FileToImageSourceConvert.cs" />
     <Compile Include="DataConvert\InvertBoolConvert.cs" />
     <Compile Include="DataConvert\ObjectConvert.cs" />
     <Compile Include="DataConvert\PropertyPanelVisible.cs" />
@@ -278,6 +279,8 @@
     <Compile Include="Model\Dialog\HomePageToolsDialogs\HomePageInsertDialogModel.cs" />
     <Compile Include="Model\Dialog\HomePageToolsDialogs\HomePagePrinter\HomePagePrinterDialogModel.cs" />
     <Compile Include="Model\Dialog\HomePageToolsDialogs\HomePageSplitDialogModel.cs" />
+    <Compile Include="Model\PageEdit\CustomInsertModel.cs" />
+    <Compile Include="Model\PageEdit\CustomPageItem.cs" />
     <Compile Include="Model\PageEdit\ExtractModel.cs" />
     <Compile Include="Model\PageEdit\PageEditItem.cs" />
     <Compile Include="Model\ParameterNames.cs" />
@@ -1258,6 +1261,15 @@
     <Resource Include="Resources\HomeIcon\PDFTools\security.png" />
     <Resource Include="Resources\HomeIcon\PDFTools\split.png" />
     <Resource Include="Resources\HomeIcon\PDFTools\watermark.png" />
+    <Resource Include="Resources\PageEdit\GridLine.png">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </Resource>
+    <Resource Include="Resources\PageEdit\HorizontalLine.png">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </Resource>
+    <Resource Include="Resources\PageEdit\Staff.png">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </Resource>
     <Content Include="source\AnalysisWord\Res\_rels\.rels">
       <CopyToOutputDirectory>Always</CopyToOutputDirectory>
     </Content>

+ 152 - 3
PDF Office/ViewModels/Dialog/PageEditDialogs/InsertDialogViewModel.cs

@@ -1,11 +1,15 @@
-using Prism.Commands;
+using PDF_Office.Model;
+using PDF_Office.Model.PageEdit;
+using Prism.Commands;
 using Prism.Mvvm;
 using Prism.Services.Dialogs;
 using System;
 using System.Collections.Generic;
+using System.Collections.ObjectModel;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
+using System.Windows;
 
 namespace PDF_Office.ViewModels.Dialog.PageEditDialogs
 {
@@ -13,16 +17,152 @@ namespace PDF_Office.ViewModels.Dialog.PageEditDialogs
     {
         public string Title =>"";
 
+        /// <summary>
+        /// 数据模型
+        /// </summary>
+        private CustomInsertModel Model = new CustomInsertModel();
+
         public event Action<IDialogResult> RequestClose;
 
+        private string currentPageSize;
+
+        /// <summary>
+        /// 当前页的尺寸大小  括号显示的形式
+        /// </summary>
+        public string CurrentPageSize
+        {
+            get { return currentPageSize; }
+            set
+            {
+                SetProperty(ref currentPageSize, value);
+            }
+        }
+
+        private int itemSelectedIndex = 0;
+
+        /// <summary>
+        /// 自定义页面的选中索引
+        /// </summary>
+        public int ItemSelectedIndex
+        {
+            get { return itemSelectedIndex; }
+            set
+            {
+                SetProperty(ref itemSelectedIndex, value);
+                if(Model!=null)
+                {
+                    Model.filepath = Pages[itemSelectedIndex].FilePath;
+                }
+            }
+        }
+
+
+        private string customWidth;
+        /// <summary>
+        /// 自定义页面宽度
+        /// </summary>
+        public string CustomWidth
+        {
+            get { return customWidth; }
+            set
+            {
+                SetProperty(ref customWidth, value);
+            }
+        }
+
+        private string customHeight;
+        /// <summary>
+        /// 自定义页面高度
+        /// </summary>
+        public string CustomHeight
+        {
+            get { return customHeight; }
+            set
+            {
+                SetProperty(ref customHeight, value);
+            }
+        }
+
+
+
+
+        /// <summary>
+        /// 自定义页面的路径集合
+        /// </summary>
+        public ObservableCollection<CustomPageItem> Pages { get; set; }
+
+        /// <summary>
+        /// 页面单位集合
+        /// </summary>
+        public List<string> Units { get; set; }
+
         public DelegateCommand CancelCommand { get; set; }
 
         public DelegateCommand InsertCommnad { get; set; }
 
+        /// <summary>
+        /// 页面方向选择的事件
+        /// </summary>
+        public DelegateCommand<string> OrientationCheckedCommand { get; set; }
+
         public InsertDialogViewModel()
         {
+            InitPageSource();
+            InitUnits();
+
             CancelCommand = new DelegateCommand(cancel);
             InsertCommnad = new DelegateCommand(insert);
+            OrientationCheckedCommand = new DelegateCommand<string>(OrientationChecked);
+        }
+
+        /// <summary>
+        /// 初始化页面大小单位集合
+        /// </summary>
+        private  void InitUnits()
+        {
+
+        }
+
+        /// <summary>
+        /// 初始化自定义页面集合
+        /// </summary>
+        private void InitPageSource()
+        {
+            Pages = new ObservableCollection<CustomPageItem>();
+            Pages.Add(new CustomPageItem() {Name="空白页",FilePath = ""});
+            Pages.Add(new CustomPageItem() { Name="横线",FilePath= System.IO.Path.Combine(Environment.CurrentDirectory, @"Resources\PageEdit\HorizontalLine.png")});
+            Pages.Add(new CustomPageItem() { Name = "五线谱", FilePath = System.IO.Path.Combine(Environment.CurrentDirectory, @"Resources\PageEdit\Staff.png") });
+            Pages.Add(new CustomPageItem() { Name = "格子线", FilePath = System.IO.Path.Combine(Environment.CurrentDirectory, @"Resources\PageEdit\GridLine.png") });
+        }
+
+        /// <summary>
+        /// 页面方向选中事件
+        /// </summary>
+        /// <param name="orientation"></param>
+        private void OrientationChecked(string orientation)
+        {
+            switch (orientation)
+            {
+                //如果宽高不符合条件就对调宽高
+                case "Vertical":
+                    if(Model.height<=Model.width)
+                    {
+                        var temp = Model.height;
+                        Model.height = Model.width;
+                        Model.width = Model.height;
+                    }
+                    break;
+                case "Horizontal":
+                    if (Model.height> Model.width)
+                    {
+                        var temp = Model.height;
+                        Model.height = Model.width;
+                        Model.width = Model.height;
+                    }
+                    break;
+                default:
+                    break;
+            }
         }
 
         private void cancel()
@@ -33,10 +173,12 @@ namespace PDF_Office.ViewModels.Dialog.PageEditDialogs
         private void insert()
         {
             DialogParameters valuePairs = new DialogParameters();
-            //valuePairs.Add(ParameterNames.DataModel, Model);
+            valuePairs.Add(ParameterNames.DataModel, Model);
             RequestClose.Invoke(new DialogResult(ButtonResult.OK, valuePairs));
         }
 
+        #region 弹窗接口
+
         public bool CanCloseDialog()
         {
             return true;
@@ -49,7 +191,14 @@ namespace PDF_Office.ViewModels.Dialog.PageEditDialogs
 
         public void OnDialogOpened(IDialogParameters parameters)
         {
-           
+            if(parameters!=null)
+            {
+                var size = parameters.GetValue<Size>("CurrentPageSize");
+                CurrentPageSize = $"({size.Width.ToString("F2")}mm*{size.Height.ToString("F2")}mm)";
+                Model.width = (int)size.Width;
+                Model.height = (int)size.Height;
+            }
         }
+        #endregion
     }
 }

+ 21 - 1
PDF Office/ViewModels/PageEdit/PageEditContentViewModel.cs

@@ -477,8 +477,28 @@ namespace PDF_Office.ViewModels.PageEdit
             }
             else
             {
+                DialogParameters keyValuePairs = new DialogParameters();
+                keyValuePairs.Add("CurrentPageSize", PDFViewer.Document.GetPageSize(ListSelectedIndex));
                 //插入自定义页面
-                dialogs.ShowDialog(DialogNames.InsertDialog, null, null);
+                dialogs.ShowDialog(DialogNames.InsertDialog, keyValuePairs,e=> { 
+                    if(e.Result == ButtonResult.OK&&e.Parameters!=null)
+                    {
+                        var model = e.Parameters.GetValue<CustomInsertModel>(ParameterNames.DataModel);
+
+                        var pageIndex = ListSelectedIndex;
+                        //文档层插入
+                        var result = PDFViewer.Document.InsertPage(pageIndex, model.width,model.height,model.filepath);
+                        if(!result)
+                        {
+                            ShowTip = Visibility.Visible;
+                            return;
+                        }
+                        PageEditItem item = new PageEditItem();
+                        PageEditItems.Insert(pageIndex, item);
+                        ReloadAfterOption(true,true,Tuple.Create(pageIndex-1,pageIndex+1));
+
+                    }
+                });
             }
             IsLoading = Visibility.Collapsed;
         }

+ 80 - 10
PDF Office/Views/Dialog/PageEditDialogs/InsertDialog.xaml

@@ -2,10 +2,13 @@
     x:Class="PDF_Office.Views.Dialog.PageEditDialogs.InsertDialog"
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+    xmlns:convert="clr-namespace:PDF_Office.DataConvert"
     xmlns:cus="clr-namespace:PDF_Office.CustomControl"
     xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+    xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
     xmlns:local="clr-namespace:PDF_Office.Views.Dialog.PageEditDialogs"
     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+    xmlns:model="clr-namespace:PDF_Office.Model.PageEdit"
     xmlns:pageeditdialogs="clr-namespace:PDF_Office.ViewModels.Dialog.PageEditDialogs"
     xmlns:prism="http://prismlibrary.com/"
     Width="480"
@@ -16,6 +19,26 @@
     prism:Dialog.WindowStyle="{StaticResource DialogWindowStyle}"
     prism:ViewModelLocator.AutoWireViewModel="True"
     mc:Ignorable="d">
+    <UserControl.Resources>
+        <ResourceDictionary>
+            <convert:FileToImageSourceConvert x:Key="FileToImageSourceConvert" />
+            <DataTemplate x:Key="CustomItem" DataType="{x:Type model:CustomPageItem}">
+                <StackPanel HorizontalAlignment="Center">
+                    <Border>
+                        <Image
+                            Width="208"
+                            Height="230"
+                            Source="{Binding FilePath, Converter={StaticResource FileToImageSourceConvert}}" />
+                    </Border>
+                    <Label
+                        Width="auto"
+                        Margin="0,4,0,0"
+                        Content="{Binding Name}"
+                        FontSize="12" />
+                </StackPanel>
+            </DataTemplate>
+        </ResourceDictionary>
+    </UserControl.Resources>
     <cus:DialogContent Header="插入自定义页面">
         <cus:DialogContent.Content>
             <Grid>
@@ -24,22 +47,49 @@
                     <RowDefinition Height="auto" />
                     <RowDefinition Height="auto" />
                 </Grid.RowDefinitions>
-                <ListBox BorderThickness="0" />
+                <ListBox
+                    BorderThickness="0"
+                    ItemTemplate="{StaticResource CustomItem}"
+                    ItemsSource="{Binding Pages}"
+                    SelectedIndex="{Binding ItemSelectedIndex, Mode=TwoWay}">
+                    <ListBox.ItemsPanel>
+                        <ItemsPanelTemplate>
+                            <WrapPanel />
+                        </ItemsPanelTemplate>
+                    </ListBox.ItemsPanel>
+                </ListBox>
                 <StackPanel Grid.Row="1" Margin="16,0">
                     <TextBlock
                         FontSize="14"
                         FontWeight="SemiBold"
                         Text="页面大小" />
-                    <RadioButton
+                    <StackPanel
                         Margin="0,12,0,0"
-                        Content="当前页"
-                        GroupName="PageSize" />
+                        VerticalAlignment="Bottom"
+                        Orientation="Horizontal">
+                        <RadioButton
+                            Height="32"
+                            VerticalContentAlignment="Center"
+                            Content="当前页"
+                            GroupName="PageSize"
+                            IsChecked="True" />
+                        <Label
+                            Height="32"
+                            Margin="8,0"
+                            HorizontalAlignment="Center"
+                            VerticalContentAlignment="Center"
+                            Content="{Binding CurrentPageSize}"
+                            FontSize="14" />
+                    </StackPanel>
                     <StackPanel Margin="0,12" Orientation="Horizontal">
                         <RadioButton
                             VerticalAlignment="Center"
                             Content="标准"
                             GroupName="PageSize" />
-                        <ComboBox Margin="8,0" />
+                        <ComboBox
+                            Width="228"
+                            Height="32"
+                            Margin="8,0" />
                     </StackPanel>
                     <StackPanel Margin="0,0,0,12" Orientation="Horizontal">
                         <RadioButton
@@ -50,13 +100,15 @@
                             Width="80"
                             Height="32"
                             Margin="8,0"
-                            VerticalAlignment="Center" />
+                            VerticalAlignment="Center"
+                            Text="{Binding CustomWidth, Mode=TwoWay}" />
                         <TextBlock VerticalAlignment="Center" Text="X" />
                         <TextBox
                             Width="80"
                             Height="32"
                             Margin="8,0"
-                            VerticalAlignment="Center" />
+                            VerticalAlignment="Center"
+                            Text="{Binding CustomHeight, Mode=TwoWay}" />
                         <ComboBox Width="80" />
                     </StackPanel>
                 </StackPanel>
@@ -66,13 +118,31 @@
                         FontWeight="SemiBold"
                         Text="方向" />
                     <StackPanel Orientation="Horizontal">
-                        <RadioButton Margin="0,12,0,16" Content="纵向页面" />
-                        <RadioButton Margin="24,12,0,16" Content="横向页面" />
+                        <RadioButton
+                            Margin="0,12,0,16"
+                            Content="纵向页面"
+                            IsChecked="True">
+                            <i:Interaction.Triggers>
+                                <i:EventTrigger EventName="Checked">
+                                    <i:InvokeCommandAction Command="{Binding OrientationCheckedCommand}" CommandParameter="Vertical" />
+                                </i:EventTrigger>
+                            </i:Interaction.Triggers>
+                        </RadioButton>
+                        <RadioButton
+                            Margin="24,12,0,16"
+                            Content="横向页面"
+                            Tag="Vertical">
+                            <i:Interaction.Triggers>
+                                <i:EventTrigger EventName="Checked">
+                                    <i:InvokeCommandAction Command="{Binding OrientationCheckedCommand}" CommandParameter="Horizontal" />
+                                </i:EventTrigger>
+                            </i:Interaction.Triggers>
+                        </RadioButton>
                     </StackPanel>
                 </StackPanel>
             </Grid>
         </cus:DialogContent.Content>
-        <cus:DialogContent.BottmBar >
+        <cus:DialogContent.BottmBar>
             <Grid>
                 <Button
                     Width="98"