Sfoglia il codice sorgente

优化 - 更改多选注释、多属性的接口

chenrongqian@kdanmobile.com 2 anni fa
parent
commit
98ee889543

+ 6 - 27
PDF Office/ViewModels/PropertyPanel/AnnotPanel/FreehandAnnotPropertyViewModel.cs

@@ -102,22 +102,13 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
                 var colorValue = (Color)obj;
                 if (colorValue != null)
                 {
-                    if (BasicVm.IsMultiSelected)
-                    {
-                        foreach (var item in PropertyPanel.AnnotEvents)
-                        {
-                            item?.UpdateAttrib(AnnotAttrib.Color, colorValue);
-                            item?.UpdateAnnot();
-                        }
-                    }
-                    else
-                    {
-                        BasicVm.FontColor = new SolidColorBrush(colorValue);
-                        BasicVm.FontColor.Opacity = BasicVm.FillOpacity;
+                    BasicVm.FontColor = new SolidColorBrush(colorValue);
+                    BasicVm.FontColor.Opacity = BasicVm.FillOpacity;
 
-                        AnnotEvent?.UpdateAttrib(AnnotAttrib.Color, colorValue);
-                        AnnotEvent?.UpdateAnnot();
+                    PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Color, colorValue);
 
+                    if (BasicVm.IsMultiSelected == false)
+                    {
                         PropertyPanel.InvokeToMyTools(AnnotArgsType.AnnotFreehand, colorValue);
                     }
 
@@ -131,19 +122,7 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
             if (obj != null && obj is double)
             {
                 var thick = (double)obj;
-                if (BasicVm.IsMultiSelected)
-                {
-                    foreach (var itemEvent in PropertyPanel.AnnotEvents)
-                    {
-                        itemEvent?.UpdateAttrib(AnnotAttrib.Thickness, thick);
-                        itemEvent?.UpdateAnnot();
-                    }
-                }
-                else
-                {
-                    AnnotEvent?.UpdateAttrib(AnnotAttrib.Thickness, thick);
-                    AnnotEvent?.UpdateAnnot();
-                }
+                PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Thickness, thick);
             }
         }
 

+ 29 - 35
PDF Office/ViewModels/PropertyPanel/AnnotPanel/FreetextAnnotPropertyViewModel.cs

@@ -49,7 +49,7 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
         public DelegateCommand<object> SelectedFillColorCommand { get; set; }
         
 
-        public DelegateCommand<object> FontSizeChangedCommand { get; set; }
+        public DelegateCommand FontSizeChangedCommand { get; set; }
         public DelegateCommand<object> TextAlignCheckedCommand { get; set; }
         public DelegateCommand<object> LineModeCheckedCommand { get; set; }
         public DelegateCommand<object> SelectedOpacityValueCommand { get; set; }
@@ -69,7 +69,7 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
             //文本字重、字体
             FontStyleWeightChangedCommand = new DelegateCommand(FontStyleWeightChanged);
             //字体
-            FontFamilyChangedCommand = new DelegateCommand(FontFamilyChanged_Command);
+            FontFamilyChangedCommand = new DelegateCommand(FontFamilyChanged);
             //自定义
             CustomFontStyleCommand = new DelegateCommand(CustomFontStyle);
             //重新定义
@@ -80,9 +80,9 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
             SelectedFillOpacityCommand = new DelegateCommand<object>(SelectedFillOpacity);
            
             SelectedColorCommand = new DelegateCommand<object>(SelectedColor_Command);
-            SelectedFillColorCommand = new DelegateCommand<object>(SelectedFillColor_Command);
+            SelectedFillColorCommand = new DelegateCommand<object>(SelectedFillColorChange);
             
-            FontSizeChangedCommand = new DelegateCommand<object>(FontSizeChanged_Command);
+            FontSizeChangedCommand = new DelegateCommand(FontSizeChanged);
             TextAlignCheckedCommand = new DelegateCommand<object>(TextAlignChecked);
             LineModeCheckedCommand = new DelegateCommand<object>(LineMode_Checked);
             SelectedOpacityValueCommand = new DelegateCommand<object>(SelectedOpacityValue);
@@ -105,25 +105,25 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
                 switch ((string)obj)
                 {
                     case "AlignLeft":
-                        AnnotEvent?.UpdateAttrib(AnnotAttrib.TextAlign, TextAlignment.Left);
+                        PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.TextAlign, TextAlignment.Left);
                         break;
 
                     case "AlignCenter":
-                        AnnotEvent?.UpdateAttrib(AnnotAttrib.TextAlign, TextAlignment.Center);
+                        PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.TextAlign, TextAlignment.Center);
                         break;
 
                     case "AlignRight":
-                        AnnotEvent?.UpdateAttrib(AnnotAttrib.TextAlign, TextAlignment.Right);
+                        PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.TextAlign, TextAlignment.Right);
                         break;
 
                     case "Justify":
-                        AnnotEvent?.UpdateAttrib(AnnotAttrib.TextAlign, TextAlignment.Justify);
+                        PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.TextAlign, TextAlignment.Justify);
                         break;
                 }
 
-                AnnotEvent?.UpdateAnnot();
             }
         }
+
         private void LineMode_Checked(object obj)
         {
             if(obj != null)
@@ -158,11 +158,12 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
                     FontVm.GetCurrentFontFamily(item.mFontFamily.ToString(), item.mFontFamily.ToString());
                     FontVm.GetFontWeights_Style(item.mFontStyle, item.mFontWeight);
 
-                    AnnotEvent?.UpdateAttrib(AnnotAttrib.FontSize, item.mFontSize);
-                    AnnotEvent?.UpdateAttrib(AnnotAttrib.FontFamily, item.mFontFamily);
-                    AnnotEvent?.UpdateAttrib(AnnotAttrib.FontStyle, item.mFontStyle);
-                    AnnotEvent?.UpdateAttrib(AnnotAttrib.FontWeight, item.mFontWeight);
-                    AnnotEvent?.UpdateAnnot();
+                    Dictionary<AnnotAttrib, object> AnnotAttribDir = new Dictionary<AnnotAttrib, object>();
+                    AnnotAttribDir.Add(AnnotAttrib.FontSize, item.mFontSize);
+                    AnnotAttribDir.Add(AnnotAttrib.FontFamily, item.mFontFamily);
+                    AnnotAttribDir.Add(AnnotAttrib.FontStyle, item.mFontStyle);
+                    AnnotAttribDir.Add(AnnotAttrib.FontWeight, item.mFontWeight);
+                    PropertyPanel.UpdateAnnotAllAttribs(AnnotAttribDir);
                 }
             }
         }
@@ -173,9 +174,11 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
             if(FontVm.CurrrentFontWeightStyle != null)
             {
                 FontVm.UpdateFontWeight_Style();
-                AnnotEvent?.UpdateAttrib(AnnotAttrib.FontStyle, FontVm.FontWeightItem);
-                AnnotEvent?.UpdateAttrib(AnnotAttrib.FontWeight, FontVm.FontStyleItem);
-                AnnotEvent?.UpdateAnnot();
+
+                Dictionary<AnnotAttrib, object> AnnotAttribDir = new Dictionary<AnnotAttrib, object>();
+                AnnotAttribDir.Add(AnnotAttrib.FontStyle, FontVm.FontWeightItem);
+                AnnotAttribDir.Add(AnnotAttrib.FontWeight, FontVm.FontStyleItem);
+                PropertyPanel.UpdateAnnotAllAttribs(AnnotAttribDir);
             }
         }
         
@@ -204,43 +207,34 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
             }
         }
         
-        private void FontSizeChanged_Command(object obj)
+        //设置字体大小
+        private void FontSizeChanged()
         {
-            if (obj != null)
+            if (FontVm.CurrentFontSize != null)
             {
-                var item = (ComboBoxItem)obj;
-                var content = (string)item.Content;
-                if (content != null)
-                {
-                    var intData = int.Parse(content);
-                    AnnotEvent?.UpdateAttrib(AnnotAttrib.FontSize, intData);
-                   
-                    AnnotEvent?.UpdateAnnot();
-                }
+                PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.FontSize, FontVm.CurrentFontSize.Value);
             }
         }
 
-        private void FontFamilyChanged_Command()
+        //设置字体样式
+        private void FontFamilyChanged()
         {
             if (string.IsNullOrEmpty(FontVm.CurrentFontFamily.ValueStr) == false)
             {
-                AnnotEvent?.UpdateAttrib(AnnotAttrib.FontFamily, new FontFamily(FontVm.CurrentFontFamily.ValueStr));
-                AnnotEvent?.UpdateAnnot();
+                PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.FontFamily, new FontFamily(FontVm.CurrentFontFamily.ValueStr));
             }
         }
 
-        private void SelectedFillColor_Command(object obj)
+        private void SelectedFillColorChange(object obj)
         {
             if (obj != null)
             {
                 var colorValue = (Color)obj;
                 if (colorValue != null)
                 {
-
                     BasicVm.FillColor = new SolidColorBrush(colorValue);
+                    PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.FillColor, colorValue);
                     // BasicVm.FillColor.Opacity = BasicVmFillOpacity;
-                    AnnotEvent?.UpdateAttrib(AnnotAttrib.FillColor, colorValue);
-                    AnnotEvent?.UpdateAnnot();
                 }
             }
         }

+ 6 - 15
PDF Office/ViewModels/PropertyPanel/AnnotPanel/TextAnnotPropertyViewModel.cs

@@ -109,24 +109,15 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
                 var colorValue = (Color)color;
                 if (colorValue != null)
                 {
-                    if(BasicVm.IsMultiSelected)
-                    {
-                        foreach (var item in PropertyPanel.AnnotEvents)
-                        {
-                            item?.UpdateAttrib(AnnotAttrib.Color, colorValue);
-                            item?.UpdateAnnot();
-                        }
-                    }
-                    else
+                    BasicVm.FontColor = new SolidColorBrush(colorValue);
+                    BasicVm.FontColor.Opacity = BasicVm.FillOpacity;
+                    PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Color, colorValue);
+
+                    if (BasicVm.IsMultiSelected == false)
                     {
-                        BasicVm.FontColor = new SolidColorBrush(colorValue);
-                        BasicVm.FontColor.Opacity = BasicVm.FillOpacity;
-                        AnnotEvent?.UpdateAttrib(AnnotAttrib.Color, colorValue);
-                        AnnotEvent?.UpdateAnnot();
                         PropertyPanel.InvokeToMyTools(BasicVm.AnnotType, color);
                     }
-                   
-                   
+
                 }
             }
         }

+ 48 - 1
PDF Office/ViewModels/Tools/AnnotToolContentViewModel.Properties.cs

@@ -1,4 +1,5 @@
-using ComPDFKitViewer.AnnotEvent;
+using ComPDFKitViewer;
+using ComPDFKitViewer.AnnotEvent;
 using ComPDFKitViewer.PdfViewer;
 using PDF_Office.CustomControl;
 using PDF_Office.ViewModels.PropertyPanel.AnnotPanel;
@@ -34,6 +35,52 @@ namespace PDF_Office.ViewModels.Tools
         public AnnotPropertyPanel()
         { }
 
+        //单个属性更改
+        public void UpdateAnnotAAttrib(AnnotAttrib annotAttrib, object obj)
+        {
+
+            if (annotlists != null && annotlists.Count > 1)
+            {
+                foreach (var itemevent in AnnotEvents)
+                {
+                    itemevent?.UpdateAttrib(annotAttrib, obj);
+                    itemevent?.UpdateAnnot();
+                }
+            }
+            else
+            {
+                AnnotEvent?.UpdateAttrib(annotAttrib, obj);
+                AnnotEvent?.UpdateAnnot();
+            }
+
+        }
+
+        //多个属性更改
+        public void UpdateAnnotAllAttribs(Dictionary<AnnotAttrib, object> AnnotAttribDir)
+        {
+            if (annotlists != null && annotlists.Count > 1)
+            {
+                foreach (var itemevent in AnnotEvents)
+                {
+                    foreach (var item in AnnotAttribDir)
+                    {
+                        itemevent?.UpdateAttrib(item.Key, item.Value);
+                    }
+
+                    itemevent?.UpdateAnnot();
+                }
+            }
+            else
+            {
+                foreach (var item in AnnotAttribDir)
+                {
+                    AnnotEvent?.UpdateAttrib(item.Key, item.Value);
+                }
+
+                AnnotEvent?.UpdateAnnot();
+            }
+
+        }
         /// <summary>
         /// 更新多个属性,触发到工具栏注释工具,改变工具图标下的颜色值
         /// </summary>

+ 8 - 2
PDF Office/Views/PropertyPanel/AnnotPanel/FreetextAnnotProperty.xaml

@@ -152,7 +152,7 @@
                                 Height="32"
                                 HorizontalAlignment="Left"
                                 IsValueContent="True"
-                                ItemSource="{Binding FontVm.FontStyleItems}"
+                                ItemSource="{Binding FontVm.FontStyleItems,Mode=OneWay}"
                                 SelectedItems="{Binding FontVm.CurrrentFontWeightStyle, Mode=TwoWay}">
                             <i:Interaction.Triggers>
                                 <i:EventTrigger EventName="ValueChanged">
@@ -167,7 +167,13 @@
                                 Width="110"
                                 Height="32"
                                 HorizontalAlignment="Right"
-                                SelectedItems="{Binding FontVm.CurrentFontSize, Mode=TwoWay}" />
+                                SelectedItems="{Binding FontVm.CurrentFontSize, Mode=TwoWay}" >
+                            <i:Interaction.Triggers>
+                                <i:EventTrigger EventName="ValueChanged">
+                                    <i:InvokeCommandAction Command="{Binding FontSizeChangedCommand}"/>
+                                </i:EventTrigger>
+                            </i:Interaction.Triggers>
+                        </CompositeControl:CustomComboControl>
                     </Grid>
                     <Grid>
                         <StackPanel Orientation="Horizontal">