Browse Source

填写与签名-选中

liyijie 2 years ago
parent
commit
c44004b103

+ 58 - 16
PDF Office/ViewModels/FillAndSign/FillAndSignContentViewModel.cs

@@ -50,6 +50,7 @@ using System.Windows.Controls.Primitives;
 using Window = System.Windows.Window;
 using Task = System.Threading.Tasks.Task;
 using Size = System.Windows.Size;
+using System.Windows.Markup;
 
 namespace PDF_Office.ViewModels.FillAndSign
 {
@@ -66,6 +67,7 @@ namespace PDF_Office.ViewModels.FillAndSign
         private PopMenu FreeHandAnnotPopMenu;
         private PopMenu FreeTextAnnotPopMenu;
         private PopMenu MultiAnnotPopMenu;
+        public bool isFirst=true;
         private IRegionManager regions { get; set; }
         private Dictionary<string, AnnotArgsType> ToolExpandDict = new Dictionary<string, AnnotArgsType>();
         public static bool IsEdit = false;
@@ -100,7 +102,8 @@ namespace PDF_Office.ViewModels.FillAndSign
         #endregion
 
         public FillAndSignContentViewModel(IRegionManager regionManager, IEventAggregator events)
-        {
+        {
+           
             regions = regionManager;
             this.events = events;
             CheckCommand = new DelegateCommand<RoutedEventArgs>(CheckedEvent);
@@ -112,6 +115,15 @@ namespace PDF_Office.ViewModels.FillAndSign
             FreeTextAglin_MenuCommand = new DelegateCommand<object>(FreeTextAglin_Menu);
             InitSelectFreeHandAnnotMenu();
             InitSelectFreeTextAnnotMenu();
+           
+        }
+        private void InitFillAndSignProperty()
+        {
+
+            var FreehandDefault = GetAnnotDefault(AnnotArgsType.AnnotFreehand, "FillAndSign");
+            SelectColor = new SolidColorBrush(FreehandDefault.BorderColor != Color.FromArgb(0, 0, 0, 0) ? FreehandDefault.BorderColor : Colors.GreenYellow);
+            FillOpacity = FreehandDefault.Opacity > 0 ? FreehandDefault.Opacity : 1;
+            LineWidth = FreehandDefault.Thickness > 0 ? FreehandDefault.Thickness : 1;
         }
         private System.Windows.Controls.Primitives.Popup popup = null;
         private async void AnnotColorPalette_Menu(object obj)
@@ -276,13 +288,13 @@ namespace PDF_Office.ViewModels.FillAndSign
                         var freeHand = annot as FreehandAnnotArgs;
                         var color = freeHand.InkColor;
 
-                        Settings.Default.AppProperties.Annotate.FreeHandColor = color;
+                        //Settings.Default.AppProperties.Annotate.FreeHandColor = color;
 
-                        var FreehandDefault = GetAnnotDefault(AnnotArgsType.AnnotFreehand);
-                        FreehandDefault.ForgoundColor = color;
+                        var FreehandDefault = GetAnnotDefault(AnnotArgsType.AnnotFreehand, "FillAndSign");
+                        FreehandDefault.BorderColor = color;
                         FreehandDefault.Opacity = freeHand.Transparency;
                         FreehandDefault.Thickness = freeHand.LineWidth;
-
+                        FreehandDefault.SaveKey = "FillAndSign";
                         var isSolid = AnnotPropertyPanel.IsSolidStyle(freeHand.LineDash);
                         if (isSolid)
                         {
@@ -299,13 +311,32 @@ namespace PDF_Office.ViewModels.FillAndSign
 
                         SettingHelper.SetAnnotDefaultProperty(FreehandDefault);
                     }
+
+                    else if (annot is FreeTextAnnotArgs)
+                    {
+                        var freeText = annot as FreeTextAnnotArgs;
+                        Settings.Default.AppProperties.Annotate.TextAnnoteColor = freeText.FontColor;
+                        Settings.Default.AppProperties.Annotate.TextFontFamaily = freeText.FontFamily.ToString();
+                        Settings.Default.AppProperties.Annotate.TextAlign = freeText.Align;
+
+                        var FreeTextDefalut = GetAnnotDefault(AnnotArgsType.AnnotFreeText);
+                        FreeTextDefalut.ForgoundColor = freeText.FontColor;
+                        FreeTextDefalut.FontFamily = freeText.FontFamily.ToString();
+                        FreeTextDefalut.TextAlign = freeText.Align;
+                        FreeTextDefalut.FontSize = freeText.FontSize;
+                        FreeTextDefalut.FontWeight = freeText.FontWeight;
+                        FreeTextDefalut.FontStyle = freeText.FontStyle;
+                        FreeTextDefalut.BackgroundColor = freeText.BgColor;
+                        FreeTextDefalut.Opacity = (annot as FreeTextAnnotArgs).Transparency;
+                        SettingHelper.SetAnnotDefaultProperty(FreeTextDefalut);
+                    }
                 }
             }
         }
 
-        private DefaultAnnotProperty GetAnnotDefault(AnnotArgsType annotArgsType)
+        private DefaultAnnotProperty GetAnnotDefault(AnnotArgsType annotArgsType,string savaKey="")
         {
-            var Annot = SettingHelper.GetAnnotDefaultProperty(annotArgsType);
+            var Annot = SettingHelper.GetAnnotDefaultProperty(annotArgsType, savaKey);
             if (Annot == null)
             {
                 Annot = new DefaultAnnotProperty();
@@ -371,7 +402,7 @@ namespace PDF_Office.ViewModels.FillAndSign
         private void InitCheckedEvent(string e)
         {
             IsEdit = false;
-
+           
 
             //NavigateToProperty(control.Name);
             //不创建注释,属于注释模板
@@ -421,7 +452,7 @@ namespace PDF_Office.ViewModels.FillAndSign
                     ShowPropertyPanel(true);
                 }
             }
-
+         
         }
         //注释工具
         private void FindAnnotTypeKey(string tag, ref AnnotHandlerEventArgs annotArgs, bool isRightMenuAdd = false)
@@ -509,6 +540,7 @@ namespace PDF_Office.ViewModels.FillAndSign
             List<AnnotHandlerEventArgs> stampAnnotArgsList = new List<AnnotHandlerEventArgs>();
             if (stampAnnotArgs != null)
                 stampAnnotArgsList.Add(stampAnnotArgs);
+           
             //if (selectedArgs != null) { 
             //var annot = selectedArgs[0];
             //if (annot != null)
@@ -547,7 +579,7 @@ namespace PDF_Office.ViewModels.FillAndSign
             if (stampAnnotArgs != null)
                 stampAnnotArgsList.Add(stampAnnotArgs);
 
-            AddToPropertyPanel("ShapFillProperty", "", stampAnnotArgsList, annotAttribsList);
+            //AddToPropertyPanel("ShapFillProperty", "", stampAnnotArgsList, annotAttribsList);
             bool isTemplateAnnot = false;
             bool isSnapshotEdit = false;
             AnnotHandlerEventArgs annotArgs = stampAnnotArgs;
@@ -558,6 +590,7 @@ namespace PDF_Office.ViewModels.FillAndSign
                 annotArgs.Author = Settings.Default.AppProperties.Description.Author;
                 PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
                 PDFViewer.SetToolParam(annotArgs);
+                
                 isRightMenuAddAnnot = false;
             }
 
@@ -775,13 +808,15 @@ namespace PDF_Office.ViewModels.FillAndSign
                 {
                     if (propertyPanel.AnnotEvents == null)
                         propertyPanel.AnnotEvents = new List<AnnotAttribEvent>();
-
+                    
                     propertyPanel.AnnotEvents.Clear();
 
                     foreach (var itemAnnot in annots)
                     {
-                        var eventitem = AnnotAttribEvent.GetAnnotAttribEvent(itemAnnot, annotAttribsList);
+                        var eventitem = AnnotAttribEvent.GetAnnotAttribEvent(itemAnnot, annotAttribsList);
+                        PDFViewer.SelectAnnotation(itemAnnot.PageIndex, itemAnnot.AnnotIndex);
                         propertyPanel.AnnotEvents.Add(eventitem);
+
                     }
                 }
 
@@ -789,6 +824,7 @@ namespace PDF_Office.ViewModels.FillAndSign
                 if (annots[0] is LinkAnnotArgs && annotAttribEvent != null)
                 {
                     propertyPanel.AnnotEvent = annotAttribEvent;
+
                 }
             }
 
@@ -806,7 +842,9 @@ namespace PDF_Office.ViewModels.FillAndSign
 
                 if (isUpData) { return; }
 
-                if (viewContent == "ShapFillProperty") { NavigateToProperty(viewContent, propertyPanel); return; }
+                if (viewContent == "ShapFillProperty") {
+                    
+                    NavigateToProperty(viewContent, propertyPanel); return; }
                 viewContentViewModel.SelectedPrpoertyPanel(viewContent, propertyPanel);
             }
 
@@ -1349,6 +1387,7 @@ namespace PDF_Office.ViewModels.FillAndSign
                 return false;
             }
         }
+        //注释编辑事件
 
         private void PDFViewer_AnnotEditHandler(object sender, List<AnnotEditEvent> e)
         {
@@ -1363,6 +1402,7 @@ namespace PDF_Office.ViewModels.FillAndSign
                             int pageindex = editEvent.PageIndex;
                             int annotindex = editEvent.AnnotIndex;
                             viewContentViewModel.FillAndSign.Add(new Point(pageindex, annotindex));
+                             PDFViewer.SelectAnnotation(pageindex, annotindex);
                             break;
                     }
                 }
@@ -1387,12 +1427,12 @@ namespace PDF_Office.ViewModels.FillAndSign
                         {
 
                             GetSelectedAnnots(e);
+
                             //记录这次选中的注释,之后创建注释会跟随上次选中注释的属性值
                             //PDFViewer.SetToolParam(annot);
                         }
                         else
                         {
-
                             //TODO: 设计已重新调整为(仅限高亮注释):修改注释后,会作用到之后添加的注释中。因此先把此逻辑“创建注释后,会自动回到默认值”注释掉
                             if (annot.EventType != AnnotArgsType.AnnotStrikeout &&
                                 annot.EventType != AnnotArgsType.AnnotUnderline &&
@@ -1427,7 +1467,7 @@ namespace PDF_Office.ViewModels.FillAndSign
                             else
                             {
                                 ShowPropertyPanel();
-
+                               
                             }
                         }
                     }
@@ -1593,9 +1633,11 @@ namespace PDF_Office.ViewModels.FillAndSign
             navigationContext.Parameters.TryGetValue<ViewContentViewModel>(ParameterNames.ViewContentViewModel, out viewContentViewModel);
             navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
             BindingPDFViewerHandler();
-            HookShapeIsCheck = true;
+            HookShapeIsCheck = true;
+            InitFillAndSignProperty();
             InitCheckedEvent("RbtnTick");
             IsEdit = false;
+
         }
         #endregion
     }

+ 73 - 31
PDF Office/ViewModels/FillAndSign/PropertyPanel/ShapFillPropertyViewModel.cs

@@ -50,15 +50,22 @@ namespace PDF_Office.ViewModels.FillAndSign.PropertyPanel
         {
             get { return selectColor; }
             set
-            {
-                SetProperty(ref selectColor, value);
-                fillAndSignContentViewModel.SelectColor = value;
-                if (FillAndSignContentViewModel.IsEdit)
+            {
+                SetProperty(ref selectColor, value);
+                if (!fillAndSignContentViewModel.isFirst)
                 {
-                    //  PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Thickness, LineWidth * fillAndSignContentViewModel.LineWidthMultiple);
-                    PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Color, (selectColor as SolidColorBrush).Color);
-                }
-                else { fillAndSignContentViewModel.SetStamp(); }
+                    fillAndSignContentViewModel.SelectColor = value;
+                    //if (FillAndSignContentViewModel.IsEdit)
+                    {
+                        //  PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Thickness, LineWidth * fillAndSignContentViewModel.LineWidthMultiple);
+                        PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Color, (selectColor as SolidColorBrush).Color);
+                    }
+                    //else
+                    {
+                        fillAndSignContentViewModel.SetStamp();
+                    }
+
+                }
 
             }
         }
@@ -70,14 +77,21 @@ namespace PDF_Office.ViewModels.FillAndSign.PropertyPanel
             set
             {
                 SetProperty(ref fillOpacity, value);
-                fillAndSignContentViewModel.FillOpacity = value;
-
-                if (FillAndSignContentViewModel.IsEdit)
+                if (!fillAndSignContentViewModel.isFirst)
                 {
-                    PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Transparency, fillOpacity);
-                }
-
-                else { fillAndSignContentViewModel.SetStamp(); }
+                    fillAndSignContentViewModel.FillOpacity = value;
+
+                    //if (FillAndSignContentViewModel.IsEdit)
+                    {
+                        PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Transparency, fillOpacity);
+                    }
+
+                    //else
+                    {
+                        fillAndSignContentViewModel.SetStamp();
+                    }
+
+                }
 
             }
         }
@@ -103,19 +117,25 @@ namespace PDF_Office.ViewModels.FillAndSign.PropertyPanel
             set
             {
                 SetProperty(ref lineWidth, value);
-                fillAndSignContentViewModel.LineWidth = value;
-
-                if (FillAndSignContentViewModel.IsEdit)
+                if (!fillAndSignContentViewModel.isFirst)
                 {
+                    fillAndSignContentViewModel.LineWidth = value;
 
-                    PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Height, 60);
-                    PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Width, 60);
-                    PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Thickness, LineWidth * fillAndSignContentViewModel.LineWidthMultiple);
-                    PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Path, updatapath);
+                    //if (FillAndSignContentViewModel.IsEdit)
+                    {
 
-                }
-                else { fillAndSignContentViewModel.SetStamp(); }
+                        PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Height, 60);
+                        PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Width, 60);
+                        PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Thickness, LineWidth * fillAndSignContentViewModel.LineWidthMultiple);
+                        PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Path, updatapath);
+
+                    }
+                   // else
+                    {
+                        fillAndSignContentViewModel.SetStamp();
+                    }
 
+                }
             }
         }
         public DelegateCommand<object> SelectedThickCommand { get; set; }
@@ -138,6 +158,29 @@ namespace PDF_Office.ViewModels.FillAndSign.PropertyPanel
             SelectedOpacityValueCommand = new DelegateCommand<object>(SelectedOpacityValue);
         }
 
+        private void InitFillAndSignProperty()
+        {
+            if (fillAndSignContentViewModel.isFirst)
+            {
+                SelectColor = fillAndSignContentViewModel.SelectColor;
+                FillOpacity = fillAndSignContentViewModel.FillOpacity;
+                LineWidth = fillAndSignContentViewModel.LineWidth;
+            }
+
+            fillAndSignContentViewModel.isFirst = false;
+        }
+
+        private DefaultAnnotProperty GetAnnotDefault(AnnotArgsType annotArgsType)
+        {
+            var Annot = SettingHelper.GetAnnotDefaultProperty(annotArgsType, "FillAndSign");
+            if (Annot == null)
+            {
+                Annot = new DefaultAnnotProperty();
+                Annot.AnnotToolType = annotArgsType;
+            }
+            return Annot;
+        }
+
         private void SharpsType_Command(object obj)
         {
             if (obj != null)
@@ -160,7 +203,7 @@ namespace PDF_Office.ViewModels.FillAndSign.PropertyPanel
                     var hookShape = new PathGeometry();
                     hookShape.AddGeometry(Geometry.Parse("M0.599976 7.0286L5.57775 11.8L13.4 1.40002"));
                     DataPath = hookShape;
-                    if (FillAndSignContentViewModel.IsEdit)
+                    //if (FillAndSignContentViewModel.IsEdit)
                     {
                         PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Thickness, LineWidth * fillAndSignContentViewModel.LineWidthMultiple);
                         updatapath = new List<List<Point>> { new List<Point> { new Point(0.599976, 7.0286), new Point(5.57775, 11.8), new Point(13.4, 1.40002) } };
@@ -177,7 +220,7 @@ namespace PDF_Office.ViewModels.FillAndSign.PropertyPanel
                     var forkShape = new PathGeometry();
                     forkShape.AddGeometry(Geometry.Parse("M3.19995 3.20001L12.8 12.8 M12.8 3.20001L3.20005 12.8"));
                     DataPath = forkShape;
-                    if (FillAndSignContentViewModel.IsEdit)
+                   // if (FillAndSignContentViewModel.IsEdit)
                     {
                         PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Thickness, LineWidth * fillAndSignContentViewModel.LineWidthMultiple);
                         updatapath = new List<List<Point>> { new List<Point> { new Point(3.19995, 3.20001), new Point(12.8, 12.8) }, new List<Point> { new Point(12.8, 3.20001), new Point(3.20005, 12.8) } };
@@ -193,7 +236,7 @@ namespace PDF_Office.ViewModels.FillAndSign.PropertyPanel
                         RectangleGeometry rectPath = new RectangleGeometry();
                         rectPath.Rect = new Rect(0, 5, 28, 22);
                         DataPath = rectPath;
-                        if (FillAndSignContentViewModel.IsEdit)
+                        //if (FillAndSignContentViewModel.IsEdit)
                         {
                             PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Thickness, LineWidth * fillAndSignContentViewModel.LineWidthMultiple);
                             updatapath = new List<List<Point>> { new List<Point> { new Point(5, 5), new Point(28, 5) }, new List<Point> { new Point(28, 5), new Point(28, 27) }, new List<Point> { new Point(28, 27), new Point(5, 27) }, new List<Point> { new Point(5, 27), new Point(5, 5) } };
@@ -210,7 +253,7 @@ namespace PDF_Office.ViewModels.FillAndSign.PropertyPanel
                         var lineShape = new PathGeometry();
                         lineShape.AddGeometry(Geometry.Parse(" M0,10L20,10"));
                         DataPath = lineShape;
-                        if (FillAndSignContentViewModel.IsEdit)
+                       // if (FillAndSignContentViewModel.IsEdit)
                         {
                             PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Thickness, LineWidth * fillAndSignContentViewModel.LineWidthMultiple);
                             updatapath = new List<List<Point>> { new List<Point> { new Point(3.19995, 3.20001), new Point(28, 3.20001) } };
@@ -230,7 +273,7 @@ namespace PDF_Office.ViewModels.FillAndSign.PropertyPanel
                         circlePath.RadiusY = 2.4;
                         circlePath.Center = new Point(2.4, 2.4);
                         DataPath = circlePath;
-                        if (FillAndSignContentViewModel.IsEdit)
+                       // if (FillAndSignContentViewModel.IsEdit)
                         {
                             fillAndSignContentViewModel.LineWidthMultiple = 4;
                             updatapath = new List<List<Point>> { new List<Point> { new Point(3.19995, 3.19995), new Point(3.19995, 3.19995) } };
@@ -398,8 +441,7 @@ namespace PDF_Office.ViewModels.FillAndSign.PropertyPanel
                 IsSelected = !FillAndSignContentViewModel.IsEdit;
 
 
-
-
+                InitFillAndSignProperty();
 
                 if (IsMultiSelected)
                 {

+ 0 - 1
PDF Office/Views/FillAndSign/PropertyPanel/ShapFillProperty.xaml.cs

@@ -27,7 +27,6 @@ namespace PDF_Office.Views.FillAndSign.PropertyPanel
         private ShapFillPropertyViewModel ViewModel => DataContext as ShapFillPropertyViewModel;
         public ShapFillProperty()
         {
-            InitializeComponent();
             InitializeComponent();
             cusColor.SelectedColorHandler += cusColor_SelectedColor;