Browse Source

综合-阅读页右键菜单-添加注释-显示属性面板、bug修复

OYXH\oyxh 2 years ago
parent
commit
8154a62c7b

+ 69 - 12
PDF Office/ViewModels/Dialog/BOTA/ScreenAnnotationDialogViewModel.cs

@@ -279,18 +279,75 @@ namespace PDF_Office.ViewModels.Dialog.BOTA
             {
                 if (composite.Parameter is Object[] arrys)
                 {
-                    btnHighlight = arrys[0] as CustomIconToggleBtn;
-                    btnFreeHand = arrys[1] as CustomIconToggleBtn;
-                    btnAnnotSticky = arrys[2] as CustomIconToggleBtn;
-                    btnAnnotStamp = arrys[3] as CustomIconToggleBtn;
-                    btnSharpLine = arrys[4] as CustomIconToggleBtn;
-                    btnSharpArrow = arrys[5] as CustomIconToggleBtn;
-                    btnAnnotCircle = arrys[6] as CustomIconToggleBtn;
-                    btnAnnotSquare = arrys[7] as CustomIconToggleBtn;
-                    btnAnnotFreeText = arrys[8] as CustomIconToggleBtn;
-                    btnAnnotStrikeout = arrys[9] as CustomIconToggleBtn;
-                    btnUnderLine = arrys[10] as CustomIconToggleBtn;
-                    btnAnnotLink = arrys[11] as CustomIconToggleBtn;
+                    foreach (var item in arrys)
+                    {
+                        if (item is CustomIconToggleBtn iconToggleBtn)
+                        {
+                            string tag = iconToggleBtn.Tag.ToString();
+                            switch (tag)
+                            {
+                                case "Highlight":
+                                    btnHighlight = iconToggleBtn;
+                                    break;
+
+                                case "FreeHand":
+                                    btnFreeHand = iconToggleBtn;
+                                    break;
+
+                                case "AnnotSticky":
+                                    btnAnnotSticky = iconToggleBtn;
+                                    break;
+
+                                case "AnnotStamp":
+                                    btnAnnotStamp = iconToggleBtn;
+                                    break;
+
+                                case "SharpLine":
+                                    btnSharpLine = iconToggleBtn;
+                                    break;
+
+                                case "SharpArrow":
+                                    btnSharpArrow = iconToggleBtn;
+                                    break;
+
+                                case "AnnotCircle":
+                                    btnAnnotCircle = iconToggleBtn;
+                                    break;
+
+                                case "AnnotSquare":
+                                    btnAnnotSquare = iconToggleBtn;
+                                    break;
+
+                                case "AnnotFreeText":
+                                    btnAnnotFreeText = iconToggleBtn;
+                                    break;
+
+                                case "AnnotStrikeout":
+                                    btnAnnotStrikeout = iconToggleBtn;
+                                    break;
+
+                                case "Underline":
+                                    btnUnderLine = iconToggleBtn;
+                                    break;
+
+                                case "AnnotLink":
+                                    btnAnnotLink = iconToggleBtn;
+                                    break;
+                            }
+                        }
+                    }
+                    //btnHighlight = arrys[0] as CustomIconToggleBtn;
+                    //btnFreeHand = arrys[1] as CustomIconToggleBtn;
+                    //btnAnnotSticky = arrys[2] as CustomIconToggleBtn;
+                    //btnAnnotStamp = arrys[3] as CustomIconToggleBtn;
+                    //btnSharpLine = arrys[4] as CustomIconToggleBtn;
+                    //btnSharpArrow = arrys[5] as CustomIconToggleBtn;
+                    //btnAnnotCircle = arrys[6] as CustomIconToggleBtn;
+                    //btnAnnotSquare = arrys[7] as CustomIconToggleBtn;
+                    //btnAnnotFreeText = arrys[8] as CustomIconToggleBtn;
+                    //btnAnnotStrikeout = arrys[9] as CustomIconToggleBtn;
+                    //btnUnderLine = arrys[10] as CustomIconToggleBtn;
+                    //btnAnnotLink = arrys[11] as CustomIconToggleBtn;
                     for (int i = 0; i < arrys.Length - 2; i++)
                     {
                         iconToggleBtns.Add(arrys[i] as CustomIconToggleBtn);

+ 21 - 21
PDF Office/ViewModels/PropertyPanel/AnnotPanel/SharpsAnnotPropertyViewModel.cs

@@ -29,7 +29,7 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
                 var dash = value as DashStyle;
                 if (dash.Dashes == null || dash.Dashes.Count == 0 || dash.Dashes[0] == 0)
                 {
-                   return DashStyles.Solid.Dashes; 
+                    return DashStyles.Solid.Dashes;
                 }
                 else
                 {
@@ -123,7 +123,7 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
         public DelegateCommand<object> SharpsTypeCommand { get; set; }
         public DelegateCommand<object> ThicknessChangedCommand { get; set; }
         public DelegateCommand<object> SelectedOpacityValueCommand { get; set; }
-        
+
 
         public event EventHandler<object> LoadPropertyHandler;
         public SharpsAnnotPropertyViewModel()
@@ -149,21 +149,21 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
                 if (content != null)
                 {
                     var intData = int.Parse(content);
-                    BasicVm.AnnotThickness = intData; 
+                    BasicVm.AnnotThickness = intData;
                 }
             }
         }
 
         private void SharpsType_Command(object obj)
         {
-            if(obj != null)
+            if (obj != null)
             {
                 var tag = (string)obj;
                 SharpsType(tag);
             }
         }
 
-        private void SharpsType(string tag,bool isFromToolsBtn = false)
+        private void SharpsType(string tag, bool isFromToolsBtn = false)
         {
             Dictionary<AnnotArgsType, object> changeData = new Dictionary<AnnotArgsType, object>();
             switch (tag)
@@ -188,7 +188,7 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
 
                 case "Arrow":
                     {
-                   
+
                         ArrowHelper arrowLine = new ArrowHelper();
                         arrowLine.ArrowLength = 8;
                         arrowLine.LineStart = new Point(8, 24);
@@ -212,22 +212,22 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
                         changeData[AnnotArgsType.AnnotLine] = tag;
                         IsLineAnnot = true;
                     }
-                   
+
                     break;
             }
 
-            if (isFromToolsBtn == false)
-                PropertyPanel.AnnotTypeChangedInvoke(this, changeData);
+            //if (isFromToolsBtn == false)
+            //     PropertyPanel.AnnotTypeChangedInvoke(this, changeData);
 
             BasicVm.SetOtherTag(tag);
         }
 
         private void LineStyle_Command(object obj)
         {
-            if(obj!= null)
+            if (obj != null)
             {
                 var tag = obj as string;
-                if(tag == "Solid")
+                if (tag == "Solid")
                 {
                     DashStyle dashAnnot = new DashStyle();
                     dashAnnot.Dashes.Add(0);
@@ -261,7 +261,7 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
                 }
             }
 
-           
+
         }
 
         private void SelectedFillOpacity_Command(object obj)
@@ -273,7 +273,7 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
 
                 PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Transparency, BasicVm.FillOpacity);
                 PropertyPanel.InvokeToMyTools(AnnotArgsType.AnnotFreehand, BasicVm.FillOpacity);
-               
+
             }
 
         }
@@ -291,7 +291,7 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
 
         }
 
-        
+
 
         private void SelectedBorderColor(object obj)
         {
@@ -340,8 +340,8 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
                     BasicVm.AnnotTypeTitle = "矩形";
                     break;
                 case AnnotArgsType.AnnotLine:
-                
-                  var annotLine =  Annot as LineAnnotArgs;
+
+                    var annotLine = Annot as LineAnnotArgs;
                     if (annotLine != null)
                     {
                         if (annotLine.TailLineType == C_LINE_TYPE.LINETYPE_ARROW && annotLine.HeadLineType == C_LINE_TYPE.LINETYPE_NONE)
@@ -366,7 +366,7 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
                 BasicVm.AnnotType = PropertyPanel.annot.EventType;
                 Annot = PropertyPanel.annot;
                 BasicVm.IsMultiSelected = PropertyPanel.IsMultiSelected;
-                if(BasicVm.IsMultiSelected)
+                if (BasicVm.IsMultiSelected)
                 {
                     IsAttributeEquals();
                 }
@@ -374,7 +374,7 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
                 {
                     GetAnnotProperty();
                 }
-                
+
                 LoadPropertyHandler?.Invoke(null, Annot);
             }
 
@@ -496,12 +496,12 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
                 var Square = Annot as SquareAnnotArgs;
                 isSolid = AnnotPropertyPanel.IsSolidStyle(Square.LineDash);
             }
-            else if(annot is CircleAnnotArgs)
+            else if (annot is CircleAnnotArgs)
             {
                 var Circle = Annot as CircleAnnotArgs;
                 isSolid = AnnotPropertyPanel.IsSolidStyle(Circle.LineDash);
             }
-            else if(annot is LineAnnotArgs)
+            else if (annot is LineAnnotArgs)
             {
                 var line = Annot as LineAnnotArgs;
                 isSolid = AnnotPropertyPanel.IsSolidStyle(line.LineDash);
@@ -527,7 +527,7 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
                             BasicVm.FillOpacity = Square.Transparency;
                             BasicVm.AnnotThickness = Square.LineWidth;
                             Dash = Square.LineDash;
-                            SharpsType("Rect",true);
+                            SharpsType("Rect", true);
                             BasicVm.AnnotTypeTitle = "矩形";
                             IsLineAnnot = false;
                         }

+ 15 - 11
PDF Office/ViewModels/Tools/AnnotToolContentViewModel.Command.cs

@@ -76,7 +76,6 @@ namespace PDF_Office.ViewModels.Tools
             }
         }
 
-
         private void PDFViewer_PDFActionHandler(object sender, ComPDFKit.PDFDocument.Action.CPDFAction action)
         {
             if (action == null)
@@ -184,15 +183,20 @@ namespace PDF_Office.ViewModels.Tools
                             }
                             //else
                             PDFViewer.SetToolParam(annot);
-                            //设计重新调整,阅读页空白处,右键菜单,添加链接,和pro mac一样的效果,不显示属性栏
-                            if (isRightMenuAddAnnot)
-                            {
-                                ShowPropertyPanel(false);
-                            }
-                            else
-                            {
-                                ShowPropertyPanel();
-                            }
+
+                            #region TO DO
+
+                            //设计重新调整,阅读页空白处,右键菜单,添加链接需要显示,其他和pro mac一样的效果,不显示属性栏
+                            //if (isRightMenuAddAnnot && annot.EventType!=AnnotArgsType.AnnotLink)
+                            //{
+                            //    ShowPropertyPanel(false);
+                            //}
+                            //else
+                            //{
+                            //    ShowPropertyPanel();
+                            //}
+
+                            #endregion TO DO
                         }
                     }
                     else
@@ -655,7 +659,7 @@ namespace PDF_Office.ViewModels.Tools
                     e.PaintRect.Top - 2,
                     e.PaintRect.Width + 4,
                     e.PaintRect.Height + 4);
-                Pen hoverPen = new Pen(new SolidColorBrush(Color.FromArgb(0xff, 0x11, 0x8A, 0xff)),1);
+                Pen hoverPen = new Pen(new SolidColorBrush(Color.FromArgb(0xff, 0x11, 0x8A, 0xff)), 1);
                 hoverPen.DashStyle = DashStyles.Dash;
                 e.DrawContext?.DrawRectangle(null, hoverPen, hoverRect);
             }

+ 3 - 1
PDF Office/ViewModels/Tools/AnnotToolContentViewModel.Function.cs

@@ -1198,7 +1198,9 @@ namespace PDF_Office.ViewModels.Tools
                     annot.Author = Settings.Default.AppProperties.Description.Author;
                     PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
                     PDFViewer.SetToolParam(annot);
-                    isRightMenuAddAnnot = false;
+                    #region 设计重新调整,阅读页空白处,右键菜单,添加链接需要显示,其他和pro mac一样的效果,不显示属性栏
+                    //isRightMenuAddAnnot = false;
+                    #endregion
                 }
 
             }

+ 23 - 3
PDF Office/ViewModels/Tools/AnnotToolContentViewModel.cs

@@ -75,6 +75,7 @@ namespace PDF_Office.ViewModels.Tools
             PropertyRegionName = Guid.NewGuid().ToString();
 
             #region 注释 - 右键菜单
+
             //公共command
             AnnotDefaultValue_MenuCommand = new DelegateCommand<object>(AnnotDefaultValues_Menu);
             AnnotColorPalette_MenuCommand = new DelegateCommand<object>(AnnotColorPalette_Menu);
@@ -93,6 +94,7 @@ namespace PDF_Office.ViewModels.Tools
             ShapeLineDirect_MenuCommand = new DelegateCommand<object>(ShapeLineDirect_Menu);
             //图章
             StampExportPicture_MenuCommand = new DelegateCommand<object>(StampExportPicture_Menu);
+
             #endregion 注释 - 右键菜单
         }
 
@@ -127,7 +129,12 @@ namespace PDF_Office.ViewModels.Tools
                     annotArgs.Author = Settings.Default.AppProperties.Description.Author;
                     PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
                     PDFViewer.SetToolParam(annotArgs);
-                    isRightMenuAddAnnot = false;
+
+                    #region 设计重新调整,阅读页空白处,右键菜单,添加链接需要显示,其他和pro mac一样的效果,不显示属性栏
+
+                    //isRightMenuAddAnnot = false;
+
+                    #endregion 设计重新调整,阅读页空白处,右键菜单,添加链接需要显示,其他和pro mac一样的效果,不显示属性栏
                 }
             }
 
@@ -206,8 +213,21 @@ namespace PDF_Office.ViewModels.Tools
                     annotHandler.Author = Settings.Default.AppProperties.Description.Author;
                     PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
                     PDFViewer.SetToolParam(annotHandler);
-                    isRightMenuAddAnnot = true;
-                    ShowPropertyPanel(false);
+                    ShowPropertyPanel(true);
+
+                    #region 设计重新调整,阅读页空白处,右键菜单,添加链接需要显示,其他和pro mac一样的效果,不显示属性栏
+
+                    //isRightMenuAddAnnot = true;
+                    //if (str != AddAnnotType.AnnotLink.ToString())
+                    //{
+                    //    ShowPropertyPanel(false);
+                    //}
+                    //else
+                    //{
+                    //    ShowPropertyPanel(true);
+                    //}
+
+                    #endregion 设计重新调整,阅读页空白处,右键菜单,添加链接需要显示,其他和pro mac一样的效果,不显示属性栏
                 }
             }
         }

+ 0 - 1
PDF Office/Views/BOTA/AnnotationListItem.xaml

@@ -352,7 +352,6 @@
             <Image
                 Name="ImageContext"
                 Grid.Row="1"
-                MinHeight="12"
                 Source="{Binding WriteableBitmap}" />
 
             <StackPanel Grid.Row="2" Margin="0,2">

+ 33 - 21
PDF Office/Views/BOTA/AnnotationListItem.xaml.cs

@@ -25,6 +25,7 @@ using System.Windows.Media;
 using System.Windows.Media.Imaging;
 using System.Windows.Navigation;
 using System.Windows.Shapes;
+using static Dropbox.Api.Files.SearchMatchTypeV2;
 
 namespace PDF_Office.Views.BOTA
 {
@@ -76,27 +77,7 @@ namespace PDF_Office.Views.BOTA
 
                     TxbMarkupContent.Visibility = Visibility.Collapsed;
 
-                    if (args.WriteableBitmap.Width > 180)
-                    {
-                        if (ImageContext.Stretch != Stretch.Fill)
-                        {
-                            ImageContext.Stretch = Stretch.Fill;
-                        }
-                    }
-                    else if (args.WriteableBitmap.Height > 100)
-                    {
-                        if (ImageContext.Stretch != Stretch.Fill)
-                        {
-                            ImageContext.Stretch = Stretch.Fill;
-                        }
-                    }
-                    else
-                    {
-                        if (ImageContext.Stretch != Stretch.None)
-                        {
-                            ImageContext.Stretch = Stretch.None;
-                        }
-                    }
+                    SetImageContext(args, data as FreehandAnnotArgs);
 
                     //var encoder = new PngBitmapEncoder();
                     //encoder.Frames.Add(BitmapFrame.Create((BitmapSource)ImageContext.Source));
@@ -250,6 +231,37 @@ namespace PDF_Office.Views.BOTA
             }
         }
 
+        private void SetImageContext(AnnotationHandlerEventArgs args, FreehandAnnotArgs freehandAnnotArgs)
+        {
+            double width = args.WriteableBitmap.Width;
+            double height = args.WriteableBitmap.Height;
 
+            if (width > 180)
+            {
+                ImageContext.Stretch = Stretch.Uniform;
+            }
+            else
+            {
+                if (height >= 900)
+                {
+                    ImageContext.MaxHeight = 900;
+                    ImageContext.Stretch = Stretch.Uniform;
+                }
+
+                if (height < 900)
+                {
+                    if (height <= 20)
+                    {
+                        ImageContext.MinHeight = height;
+                        ImageContext.MinHeight = 30;
+                    }
+                    ImageContext.Stretch = Stretch.None;
+                }
+                else
+                {
+                    ImageContext.Stretch = Stretch.Uniform;
+                }
+            }
+        }
     }
 }

File diff suppressed because it is too large
+ 15 - 16
PDF Office/Views/Dialog/BOTA/ScreenAnnotationDialog.xaml