瀏覽代碼

图章-右键编辑文字图章

zhuyi 2 年之前
父節點
當前提交
5eeae48d75

+ 37 - 0
PDF Office/DataConvert/IntAndTagToBoolMultiBinding.cs

@@ -0,0 +1,37 @@
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Data;
+
+namespace PDF_Office.DataConvert
+{
+    class IntAndTagToBoolMultiBinding : IMultiValueConverter
+    {
+        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
+        {
+            if (values[0] == null|| values[1]==null)
+            {
+                return false;
+            }
+            else
+            {
+                if (values[0].ToString()== values[1].ToString())
+                {
+                    return true;
+                }
+                else
+                {
+                    return false;
+                }
+            }
+        }
+
+        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
+        {
+            throw new NotImplementedException();
+        }
+    }
+}

+ 22 - 0
PDF Office/Model/AnnotPanel/Stamp.cs

@@ -131,5 +131,27 @@ namespace PDF_Office.Model.AnnotPanel
             }
         }
 
+        private bool isCheckedDate;
+
+        public bool IsCheckedDate
+        {
+            get { return isCheckedDate; }
+            set
+            {
+                SetProperty(ref isCheckedDate, value);
+            }
+        }
+
+        private bool isCheckedTime;
+
+        public bool IsCheckedTime
+        {
+            get { return isCheckedTime; }
+            set
+            {
+                SetProperty(ref isCheckedTime, value);
+            }
+        }
+
     }
 }

+ 1 - 0
PDF Office/PDF Office.csproj

@@ -230,6 +230,7 @@
     </Compile>
     <Compile Include="DataConvert\FileFormatToIconConvert.cs" />
     <Compile Include="DataConvert\FileToImageSourceConvert.cs" />
+    <Compile Include="DataConvert\IntAndTagToBoolMultiBinding.cs" />
     <Compile Include="DataConvert\InvertBoolConvert.cs" />
     <Compile Include="DataConvert\ObjectConvert.cs" />
     <Compile Include="DataConvert\PropertyPanelVisible.cs" />

+ 91 - 0
PDF Office/ViewModels/PropertyPanel/AnnotPanel/CustomCreateDialogViewModel.cs

@@ -3,6 +3,7 @@ using ComPDFKitViewer.AnnotEvent;
 using ComPDFKitViewer.PdfViewer;
 using Microsoft.Win32;
 using PDF_Office.Model;
+using PDF_Office.Model.AnnotPanel;
 using Prism.Commands;
 using Prism.Mvvm;
 using Prism.Services.Dialogs;
@@ -97,6 +98,17 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
             }
         }
 
+        private int radioButtonIndex;
+
+        public int RadioButtonIndex
+        {
+            get { return radioButtonIndex; }
+            set
+            {
+                SetProperty(ref radioButtonIndex, value);
+            }
+        }
+
 
         private C_TEXTSTAMP_SHAPE shape = C_TEXTSTAMP_SHAPE.TEXTSTAMP_RECT;
 
@@ -122,6 +134,7 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
 
         public void SetStampStyle(int index)
         {
+            RadioButtonIndex = index;
             switch (index)
             {
                 case 1:
@@ -347,8 +360,86 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
         }
         public void OnDialogOpened(IDialogParameters parameters)
         {
+            if (parameters != null)
+            {
+                Stamp stamp = parameters.GetValue<Stamp>(ParameterNames.DataModel);
+                if (stamp!=null)
+                {
+                    IsCheckedTime = stamp.IsCheckedTime;
+                    IsCheckedDate = stamp.IsCheckedDate;
+                    StampText = stamp.StampText;
+                    SaveToPath = stamp.SourcePath;
+                    Color = (C_TEXTSTAMP_COLOR)(int)stamp.TextColor;
+                    Shape = (C_TEXTSTAMP_SHAPE)(int)stamp.TextSharp;
+                    UpDataRadioButton(stamp.TextSharp, stamp.TextColor);
+                }
+            }
             UpDataStamp();
             return;
         }
+
+        private void UpDataRadioButton(TextStampSharp textStampSharp, TextStampColor textStampColor)
+        {
+            int index = 1;
+            switch (textStampColor)
+            {
+                case TextStampColor.TEXTSTAMP_WHITE:
+                    switch (textStampSharp)
+                    {
+                        case TextStampSharp.TEXTSTAMP_RECT:
+                            index = 2;
+                            break;
+                        case TextStampSharp.TEXTSTAMP_NONE:
+                            index = 1;
+                            break;
+                    }
+                    break;
+                case TextStampColor.TEXTSTAMP_RED:
+                    switch (textStampSharp)
+                    {
+                        case TextStampSharp.TEXTSTAMP_RECT:
+                            index = 4;
+                            break;
+                        case TextStampSharp.TEXTSTAMP_LEFT_TRIANGLE:
+                            index = 7;
+                            break;
+                        case TextStampSharp.TEXTSTAMP_RIGHT_TRIANGLE:
+                            index = 10;
+                            break;
+                    }
+                    break;
+                case TextStampColor.TEXTSTAMP_GREEN:
+                    switch (textStampSharp)
+                    {
+                        case TextStampSharp.TEXTSTAMP_RECT:
+                            index = 3;
+                            break;
+                        case TextStampSharp.TEXTSTAMP_LEFT_TRIANGLE:
+                            index = 6;
+                            break;
+                        case TextStampSharp.TEXTSTAMP_RIGHT_TRIANGLE:
+                            index = 9;
+                            break;
+                    }
+                    break;
+                case TextStampColor.TEXTSTAMP_BLUE:
+                    switch (textStampSharp)
+                    {
+                        case TextStampSharp.TEXTSTAMP_RECT:
+                            index = 5;
+                            break;
+                        case TextStampSharp.TEXTSTAMP_LEFT_TRIANGLE:
+                            index = 8;
+                            break;
+                        case TextStampSharp.TEXTSTAMP_RIGHT_TRIANGLE:
+                            index = 11;
+                            break;
+                    }
+                    break;
+                default:
+                    break;
+            }
+            RadioButtonIndex = index;
+        }
     }
 }

+ 74 - 3
PDF Office/ViewModels/PropertyPanel/AnnotPanel/StampAnnotPropertyViewModel.cs

@@ -187,6 +187,8 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
                     customStamp.Type = stamps[i].Type;
                     customStamp.TextSharp = stamps[i].TextSharp;
                     customStamp.TextColor = stamps[i].TextColor;
+                    customStamp.IsCheckedTime = stamps[i].IsCheckedTime;
+                    customStamp.IsCheckedDate = stamps[i].IsCheckedDate;
                     CustomStampList.Add(customStamp);
                 }
             }
@@ -329,6 +331,8 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
                 standardStamp.MaxHeight = (int)DpiHelpers.GetDpiUnrelatedNum(stampHeight / 72D * DpiHelpers.Dpi);
                 standardStamp.Type = StampType.TEXT_STAMP;
                 standardStamp.ImageSource = bps;
+                standardStamp.IsCheckedDate = true;
+                standardStamp.IsCheckedTime = true;
                 switch (DynamicColor[i])
                 {
                     case C_TEXTSTAMP_COLOR.TEXTSTAMP_WHITE:
@@ -423,7 +427,7 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
                     ShowDynamicPropertyDialog();
                     break;
                 case 2:
-                    ShowCustomCreateDialog();
+                    ShowCustomCreateDialog(null);
                     break;
                 default:
                     break;
@@ -455,11 +459,11 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
             }
         }
 
-        private void ShowCustomCreateDialog()
+        private void ShowCustomCreateDialog(Stamp stamp)
         {
             bool result = true;
             DialogParameters value = new DialogParameters();
-            value.Add(ParameterNames.PDFViewer, PDFViewer);
+            value.Add(ParameterNames.DataModel, stamp);
             dialogs.ShowDialog(DialogNames.CustomCreateDialog, value, e =>
             {
                 if (e.Result != ButtonResult.OK)
@@ -478,6 +482,69 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
             }
         }
 
+        public void EditorCustomStamp(Stamp stamp)
+        {
+            bool result = true;
+            DialogParameters value = new DialogParameters();
+            value.Add(ParameterNames.DataModel, stamp);
+            dialogs.ShowDialog(DialogNames.CustomCreateDialog, value, e =>
+            {
+                if (e.Result != ButtonResult.OK)
+                {
+                    result = false;
+                }
+                CustomCreateDialogViewModel CustomVM = e.Parameters.GetValue<CustomCreateDialogViewModel>(ParameterNames.DataModel);
+                if (CustomVM != null)
+                {
+                    UpDataCustomStamp(CustomVM, stamp);
+                }
+            });
+            if (!result)
+            {
+                return;
+            }
+        }
+
+        private void UpDataCustomStamp(CustomCreateDialogViewModel viewModel, Stamp oldstamp)
+        {
+            Stamp stamp = new Stamp();
+            stamp.Author = "";
+            stamp.Opacity = 1;
+            stamp.SourcePath = viewModel.SaveToPath;
+            stamp.StampText = viewModel.StampText;
+            stamp.MaxWidth = (int)DpiHelpers.GetDpiUnrelatedNum(viewModel.StampWidth / 72D * DpiHelpers.Dpi);
+            stamp.MaxHeight = (int)DpiHelpers.GetDpiUnrelatedNum(viewModel.StampHeight / 72D * DpiHelpers.Dpi);
+            stamp.StampTextDate = viewModel.StampTextDate;
+            stamp.Type = viewModel.Type;
+            stamp.TextColor = (TextStampColor)(int)viewModel.Color;
+            stamp.TextSharp = (TextStampSharp)(int)viewModel.Shape;
+            stamp.IsCheckedDate = viewModel.IsCheckedDate;
+            stamp.IsCheckedTime = viewModel.IsCheckedTime;
+            int index= CustomStampList.IndexOf(oldstamp);
+            CustomStampList[index] = stamp;
+
+            PDFSettings.CustomStampList stamps = Settings.Default.CustomStampList;
+            if (stamps == null)
+            {
+                stamps = Settings.Default.CustomStampList = new PDFSettings.CustomStampList();
+            }
+            PDFSettings.StampAnnote annote = new PDFSettings.StampAnnote();
+            Stamp customStamp = new Stamp();
+            annote.Author = stamp.Author;
+            annote.StampText = stamp.StampText;
+            annote.StampTextDate = stamp.StampTextDate;
+            annote.ImageWidth = stamp.MaxWidth;
+            annote.ImageHeight = stamp.MaxHeight;
+            annote.SourcePath = stamp.SourcePath;
+            annote.Type = stamp.Type;
+            annote.TextSharp = stamp.TextSharp;
+            annote.TextColor = stamp.TextColor;
+            annote.IsCheckedDate = stamp.IsCheckedDate;
+            annote.IsCheckedTime = stamp.IsCheckedTime;
+            stamps[index] = annote;
+            Settings.Default.Save();
+        }
+
         /// <summary>
         /// 创建自定义图章,并且保存到APP缓存
         /// </summary>
@@ -494,6 +561,8 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
             stamp.Type = viewModel.Type;
             stamp.TextColor = (TextStampColor)(int)viewModel.Color;
             stamp.TextSharp = (TextStampSharp)(int)viewModel.Shape;
+            stamp.IsCheckedDate = viewModel.IsCheckedDate;
+            stamp.IsCheckedTime = viewModel.IsCheckedTime;
             CustomStampList.Add(stamp);
 
             PDFSettings.CustomStampList stamps = Settings.Default.CustomStampList;
@@ -512,6 +581,8 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
             annote.Type = stamp.Type;
             annote.TextSharp = stamp.TextSharp;
             annote.TextColor = stamp.TextColor;
+            annote.IsCheckedDate = stamp.IsCheckedDate;
+            annote.IsCheckedTime = stamp.IsCheckedTime;
             stamps.Add(annote);
             Settings.Default.Save();
         }

+ 89 - 11
PDF Office/Views/PropertyPanel/AnnotPanel/CustomCreateDialog.xaml

@@ -10,6 +10,7 @@
     <UserControl.Resources>
         <PathGeometry x:Key="Ic_AddButtonPath" Figures="M8.5,2.5 L8.5,7.5 L13.5,7.5 L13.5,8.5 L8.5,8.5 L8.5,13.5 L7.5,13.5 L7.5,8.5 L2.5,8.5 L2.5,7.5 L7.5,7.5 L7.5,2.5 L8.5,2.5 Z"/>
         <dataconvert:UnVisivleConvert x:Key="UnVisivleConvert"/>
+        <dataconvert:IntAndTagToBoolMultiBinding x:Key="IntAndTagToBoolMultiBinding"/>
     </UserControl.Resources>
     <cus:DialogContent Header="新建图章">
         <cus:DialogContent.Content>
@@ -42,17 +43,94 @@
                         </TextBox>
                         <Grid Grid.Row="2">
                             <StackPanel Orientation="Horizontal">
-                                <RadioButton Tag="1" Checked="RadioButton_Checked"/>
-                                <RadioButton Tag="2" Checked="RadioButton_Checked"/>
-                                <RadioButton Tag="3" Checked="RadioButton_Checked"/>
-                                <RadioButton Tag="4" Checked="RadioButton_Checked"/>
-                                <RadioButton Tag="5" Checked="RadioButton_Checked"/>
-                                <RadioButton Tag="6" Checked="RadioButton_Checked"/>
-                                <RadioButton Tag="7" Checked="RadioButton_Checked"/>
-                                <RadioButton Tag="8" Checked="RadioButton_Checked"/>
-                                <RadioButton Tag="9" Checked="RadioButton_Checked"/>
-                                <RadioButton Tag="10" Checked="RadioButton_Checked"/>
-                                <RadioButton Tag="11" Checked="RadioButton_Checked"/>
+                                <RadioButton Tag="1" Checked="RadioButton_Checked" >
+                                    <RadioButton.IsChecked>
+                                        <MultiBinding Converter="{StaticResource IntAndTagToBoolMultiBinding }" Mode="OneWay">
+                                            <Binding Source="1"/>
+                                            <Binding Path="RadioButtonIndex"/>
+                                        </MultiBinding>
+                                    </RadioButton.IsChecked>
+                                </RadioButton>
+                                <RadioButton Tag="2" Checked="RadioButton_Checked">
+                                    <RadioButton.IsChecked>
+                                        <MultiBinding Converter="{StaticResource IntAndTagToBoolMultiBinding }" Mode="OneWay">
+                                            <Binding Source="2"/>
+                                            <Binding Path="RadioButtonIndex"/>
+                                        </MultiBinding>
+                                    </RadioButton.IsChecked>
+                                </RadioButton>
+                                <RadioButton Tag="3" Checked="RadioButton_Checked">
+                                    <RadioButton.IsChecked>
+                                        <MultiBinding  Converter="{StaticResource IntAndTagToBoolMultiBinding }" Mode="OneWay">
+                                            <Binding Source="3"/>
+                                            <Binding Path="RadioButtonIndex"/>
+                                        </MultiBinding>
+                                    </RadioButton.IsChecked>
+                                </RadioButton>
+                                <RadioButton Tag="4" Checked="RadioButton_Checked">
+                                    <RadioButton.IsChecked>
+                                        <MultiBinding Converter="{StaticResource IntAndTagToBoolMultiBinding }" Mode="OneWay">
+                                            <Binding Source="4"/>
+                                            <Binding Path="RadioButtonIndex"/>
+                                        </MultiBinding>
+                                    </RadioButton.IsChecked>
+                                </RadioButton>
+                                <RadioButton Tag="5" Checked="RadioButton_Checked">
+                                    <RadioButton.IsChecked>
+                                        <MultiBinding Converter="{StaticResource IntAndTagToBoolMultiBinding }" Mode="OneWay">
+                                            <Binding Source="5"/>
+                                            <Binding Path="RadioButtonIndex"/>
+                                        </MultiBinding>
+                                    </RadioButton.IsChecked>
+                                </RadioButton>
+                                <RadioButton Tag="6" Checked="RadioButton_Checked">
+                                    <RadioButton.IsChecked>
+                                        <MultiBinding Converter="{StaticResource IntAndTagToBoolMultiBinding }" Mode="OneWay">
+                                            <Binding Source="6"/>
+                                            <Binding Path="RadioButtonIndex"/>
+                                        </MultiBinding>
+                                    </RadioButton.IsChecked>
+                                </RadioButton>
+                                <RadioButton Tag="7" Checked="RadioButton_Checked">
+                                    <RadioButton.IsChecked>
+                                        <MultiBinding Converter="{StaticResource IntAndTagToBoolMultiBinding }" Mode="OneWay">
+                                            <Binding Source="7"/>
+                                            <Binding Path="RadioButtonIndex"/>
+                                        </MultiBinding>
+                                    </RadioButton.IsChecked>
+                                </RadioButton>
+                                <RadioButton Tag="8" Checked="RadioButton_Checked">
+                                    <RadioButton.IsChecked>
+                                        <MultiBinding Converter="{StaticResource IntAndTagToBoolMultiBinding }" Mode="OneWay">
+                                            <Binding Source="8"/>
+                                            <Binding Path="RadioButtonIndex"/>
+                                        </MultiBinding>
+                                    </RadioButton.IsChecked>
+                                </RadioButton>
+                                <RadioButton Tag="9" Checked="RadioButton_Checked">
+                                    <RadioButton.IsChecked>
+                                        <MultiBinding Converter="{StaticResource IntAndTagToBoolMultiBinding }" Mode="OneWay">
+                                            <Binding Source="9"/>
+                                            <Binding Path="RadioButtonIndex"/>
+                                        </MultiBinding>
+                                    </RadioButton.IsChecked>
+                                </RadioButton>
+                                <RadioButton Tag="10" Checked="RadioButton_Checked">
+                                    <RadioButton.IsChecked>
+                                        <MultiBinding Converter="{StaticResource IntAndTagToBoolMultiBinding }" Mode="OneWay">
+                                            <Binding Source="10"/>
+                                            <Binding Path="RadioButtonIndex"/>
+                                        </MultiBinding>
+                                    </RadioButton.IsChecked>
+                                </RadioButton>
+                                <RadioButton Tag="11" Checked="RadioButton_Checked">
+                                    <RadioButton.IsChecked>
+                                        <MultiBinding Converter="{StaticResource IntAndTagToBoolMultiBinding}" Mode="OneWay">
+                                            <Binding Source="11"/>
+                                            <Binding Path="RadioButtonIndex"/>
+                                        </MultiBinding>
+                                    </RadioButton.IsChecked>
+                                </RadioButton>
                             </StackPanel>
                         </Grid>
                         <StackPanel Grid.Row="3" Orientation="Horizontal" HorizontalAlignment="Center">

+ 1 - 0
PDF Office/Views/PropertyPanel/AnnotPanel/StampAnnotProperty.xaml

@@ -121,6 +121,7 @@
                                             <MenuItem x:Name="SavePNG" Header="PNG" Tag="PNG" Click="Save_Click"/>
                                             <MenuItem x:Name="SavePDF" Header="PDF" Tag="PDF" Click="Save_Click"/>
                                         </MenuItem>
+                                        <MenuItem Header="编辑文字图章" Click="Editor_Click"/>
                                     </ContextMenu>
                                 </Grid.ContextMenu>
                                 <Image Source="{Binding SourcePath}"/>

+ 6 - 0
PDF Office/Views/PropertyPanel/AnnotPanel/StampAnnotProperty.xaml.cs

@@ -53,5 +53,11 @@ namespace PDF_Office.Views.PropertyPanel.AnnotPanel
         {
             (DataContext as StampAnnotPropertyViewModel).DeleteAll();
         }
+
+        private void Editor_Click(object sender, RoutedEventArgs e)
+        {
+            MenuItem item = sender as MenuItem;
+            (DataContext as StampAnnotPropertyViewModel).EditorCustomStamp(item.DataContext as Stamp);
+        }
     }
 }

+ 2 - 0
PDFSettings/CustomStampList.cs

@@ -27,5 +27,7 @@ namespace PDFSettings
         public TextStampSharp TextSharp;
         public TextStampColor TextColor;
         public string ImageType;
+        public bool IsCheckedDate;
+        public bool IsCheckedTime;
     }
 }