Browse Source

便签 - 便签弹窗更改颜色属性、删除便签、样式

chenrongqian@kdanmobile.com 2 years ago
parent
commit
8a7bdf9eb4

+ 2 - 0
PDF Office/ViewModels/Tools/AnnotToolContentViewModel.Command.cs

@@ -381,6 +381,8 @@ namespace PDF_Office.ViewModels.Tools
 
                 case AnnotArgsType.AnnotSticky:
                     GetStickyNote(e.AnnotItemsList);
+                    customStickyPopup.GetCurrentAnnot = e.AnnotItemsList[0] as StickyAnnotArgs;
+                    customStickyPopup.GetPDFViewer = PDFViewer;
                     break;
             }
         }

+ 36 - 8
PDF Office/Views/PropertyPanel/AnnotPanel/StickyNotePopup.xaml

@@ -9,15 +9,43 @@
              d:DesignHeight="450" d:DesignWidth="800">
     <annotview:StickyPopupExt.Resources>
         <DataTemplate x:Key="listboxData">
-            <Ellipse
+            <Ellipse Stroke="{StaticResource color.sys.layout.divider}"
+                     StrokeThickness="1"
                     Width="20"
                     Height="20"
                     Fill="{Binding Color}" />
         </DataTemplate>
+
         <Style x:Key="listboxItemStyle" TargetType="{x:Type ListBoxItem}">
             <Setter Property="HorizontalContentAlignment" Value="Center" />
-            <Setter Property="Height" Value="32" />
+            <Setter Property="Height" Value="32"/>
+            <Setter Property="Width" Value="32"/>
             <Setter Property="Margin" Value="2,0,2,0" />
+            <Setter Property="Template">
+                <Setter.Value>
+                    <ControlTemplate TargetType="{x:Type ContentControl}">
+                        <Border CornerRadius="4"
+                                x:Name="border"
+                                Padding="0,0"
+                                Background="{TemplateBinding Background}">
+                            <ContentPresenter />
+                        </Border>
+                    </ControlTemplate>
+                </Setter.Value>
+            </Setter>
+
+            <Style.Triggers>
+                <Trigger Property="IsMouseOver" Value="True">
+                    <Setter Property="Background" Value="#e2e3e5" />
+                </Trigger>
+                <Trigger Property="IsMouseOver" Value="False">
+                    <Setter Property="Background" Value="Transparent" />
+                </Trigger>
+                <Trigger Property="IsSelected" Value="True">
+                    <Setter Property="Background" Value="#e2e3e5" />
+                </Trigger>
+            </Style.Triggers>
+
         </Style>
     </annotview:StickyPopupExt.Resources>
     <Grid MouseLeftButtonDown="Grid_MouseLeftButtonDown">
@@ -25,14 +53,14 @@
             <Border.Effect>
                 <DropShadowEffect BlurRadius="8" Direction="0" Opacity="0.16" ShadowDepth="0" Color="#000000" />
             </Border.Effect>
-            <Grid MinWidth="240" MinHeight="200" Background="White" Name="GridUi" Width="240" Height="200">
+            <Grid MinWidth="240" MinHeight="200" Background="Transparent" Name="GridUi" Width="240" Height="200">
                 <Grid.RowDefinitions>
-                    <RowDefinition Height="auto"></RowDefinition>
+                    <RowDefinition Height="32"></RowDefinition>
                     <RowDefinition Height="auto"></RowDefinition>
                     <RowDefinition Height="*"></RowDefinition>
                     <RowDefinition Height="auto"></RowDefinition>
                 </Grid.RowDefinitions>
-                <Grid>
+                <Grid Margin="8,0,8,0">
                     <Grid.ColumnDefinitions>
                         <ColumnDefinition Width="auto"></ColumnDefinition>
                         <ColumnDefinition Width="auto"></ColumnDefinition>
@@ -42,7 +70,7 @@
                     </Grid.ColumnDefinitions>
                     <TextBlock x:Name="AuthorText" Grid.Column="1" FontFamily="SegoeUI" FontSize="12" VerticalAlignment="Center" LineHeight="16" Margin="2,2,0,0"/>
                     <TextBlock Name="DateText" Grid.Column="3" Foreground="{StaticResource color.sys.text.neutral.lv2}" VerticalAlignment="Center"  Margin="0,-2,0,0" FontFamily="SegoeUI" FontSize="12" LineHeight="16"></TextBlock>
-                    <Border Grid.Column="4"  MouseUp="CloseText_MouseUp" Background="#01000000" Margin="0,-8,-3,0">
+                    <Border Grid.Column="4" Visibility="Collapsed" MouseUp="CloseText_MouseUp" Background="#01000000" Margin="0,-8,-3,0">
                         <Path Fill="#000000" Width="16" Height="16" >
                             <Path.Data>
                                 M9.48528137,2.98528137 L9.48428137,8.48428137 L14.9852814,8.48528137 L14.9852814,9.48528137 L9.48428137,9.48428137 L9.48528137,14.9852814 L8.48528137,14.9852814 L8.48428137,9.48428137 L2.98528137,9.48528137 L2.98528137,8.48528137 L8.48428137,8.48428137 L8.48528137,2.98528137 L9.48528137,2.98528137 Z
@@ -53,8 +81,8 @@
                         </Path>
                     </Border>
                 </Grid>
-              
-                <TextBox  Name="ContentText" Grid.Row="2" Margin="4,0,4,0" Background="#CCFFFFFF" BorderThickness="0" 
+                <Rectangle Margin="8,0,8,0" VerticalAlignment="Bottom" Height="1" Fill="{StaticResource color.sys.layout.divider}"/>
+                <TextBox  x:Name="ContentText" Grid.Row="2" Padding="2,4,0,0"  Margin="4,0,4,0" Background="#CCFFFFFF" BorderThickness="0" 
                      AcceptsReturn="True" TextWrapping="Wrap" VerticalScrollBarVisibility="Auto"></TextBox>
 
                 <Grid Grid.Row="3">

+ 78 - 9
PDF Office/Views/PropertyPanel/AnnotPanel/StickyNotePopup.xaml.cs

@@ -1,4 +1,6 @@
 using ComPDFKitViewer;
+using ComPDFKitViewer.AnnotEvent;
+using ComPDFKitViewer.PdfViewer;
 using PDF_Office.CustomControl.CompositeControl;
 using System;
 using System.Collections.Generic;
@@ -73,6 +75,22 @@ namespace PDF_Office.Views.PropertyPanel.AnnotPanel
             Color bkColor = (border.BorderBrush as SolidColorBrush).Color;
             bkColor.A = saveOpacity;
             border.BorderBrush = new SolidColorBrush(bkColor);
+            this.Background = new SolidColorBrush(Colors.Transparent);
+            this.BorderBrush = new SolidColorBrush(Colors.Transparent);
+
+            //为了点击某控件之后就直接关闭窗口
+            var ui = Mouse.DirectlyOver as FrameworkElement;
+            if (ui != null)
+            {
+
+                var colorItem = ui.DataContext as ColorItem;
+                if (colorItem != null)
+                {
+                    e.Handled = false;
+                    return;
+                }
+            }
+
             CloseText_MouseUp(this, null);
         }
 
@@ -82,13 +100,43 @@ namespace PDF_Office.Views.PropertyPanel.AnnotPanel
             saveOpacity = bkColor.A;
             bkColor.A = 255;
             border.BorderBrush = new SolidColorBrush(bkColor);
-            this.Background = new SolidColorBrush(this.StickyColor);
+            this.Background = new SolidColorBrush(Colors.Transparent);
+            this.BorderBrush = new SolidColorBrush(Colors.Transparent);
         }
 
         private void StickyPopupControl_Loaded(object sender, RoutedEventArgs e)
         {
             ContentText.Focus();
             ContentText.CaretIndex = ContentText.Text.Length;
+            LoadedColor();
+        }
+
+        public void LoadedColor()
+        {
+            if (colors != null && colors.Count > 0)
+            {
+                BtnDelete.DataContext = colors[0];//为了避免点击删除按钮之后,先执行取消焦点函数后,就没法执行点击事件
+
+                if (GetCurrentAnnot != null)
+                {
+                    foreach (var item in colors)
+                    {
+                        var colorItem = (item.Color as SolidColorBrush).Color;
+                        if (colorItem.A == GetCurrentAnnot.Color.A &&
+                            colorItem.R == GetCurrentAnnot.Color.R &&
+                            colorItem.G == GetCurrentAnnot.Color.G &&
+                            colorItem.B == GetCurrentAnnot.Color.B
+                            )
+                        {
+                            ListColor.SelectedItem = item;
+                            return;
+                        }
+                    }
+
+                }
+
+                ListColor.SelectedItem = null;
+            }
         }
 
         private void StickyPopupControl_MouseDown(object sender, MouseButtonEventArgs e)
@@ -139,6 +187,8 @@ namespace PDF_Office.Views.PropertyPanel.AnnotPanel
             }
         }
 
+        public StickyAnnotArgs GetCurrentAnnot { get; set; }
+        public CPDFViewer GetPDFViewer { get; set; }
         public bool CanMove { get; set; } = true;
         private void ResizeGrip_MouseMove(object sender, MouseEventArgs e)
         {
@@ -272,6 +322,8 @@ namespace PDF_Office.Views.PropertyPanel.AnnotPanel
         {
             base.SetStickyColor(newColor);
             border.BorderBrush = new SolidColorBrush(newColor);
+            this.Background = new SolidColorBrush(Colors.Transparent);
+            this.BorderBrush = new SolidColorBrush(Colors.Transparent);
         }
 
         public override void SetStickyNote(string note)
@@ -291,22 +343,39 @@ namespace PDF_Office.Views.PropertyPanel.AnnotPanel
             return StickyText;
         }
 
+
         private void ListColor_SelectionChanged(object sender, SelectionChangedEventArgs e)
         {
-            var color = ListColor.SelectedItem as ColorItem;
-            if (color != null)
+            var colorItem = ListColor.SelectedItem as ColorItem;
+            if (colorItem != null)
             {
-                this.SetStickyColor((color.Color as SolidColorBrush).Color);
-                border.BorderBrush = new SolidColorBrush((color.Color as SolidColorBrush).Color);
-                this.Background = new SolidColorBrush((color.Color as SolidColorBrush).Color);
+                var color = (colorItem.Color as SolidColorBrush).Color;
+                this.SetStickyColor(color);
+                var annot = GetCurrentAnnot as StickyAnnotArgs;
+                if (annot != null)
+                {
+                    annot.Color = color;
+                    var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
+                    AnnotEvent?.UpdateAttrib(AnnotAttrib.Color, color);
+                    AnnotEvent?.UpdateAnnot();
+                }
+                border.BorderBrush = new SolidColorBrush(color);
+                this.Background = new SolidColorBrush(Colors.Transparent);
+                this.BorderBrush = new SolidColorBrush(Colors.Transparent);
             }
         }
 
         private void BtnDelete_Click(object sender, RoutedEventArgs e)
         {
-            ContentText.Text = "";
-            this.SetStickyNote("");
-            Closed.Invoke(sender, EventArgs.Empty);
+            if (GetPDFViewer != null)
+            {
+                if (GetCurrentAnnot != null)
+                    GetPDFViewer.RemovePageAnnot(GetCurrentAnnot.PageIndex, GetCurrentAnnot.AnnotIndex);
+
+                // Closed.Invoke(sender, EventArgs.Empty);
+                CloseText_MouseUp(this, null);
+            }
+
         }
 
         private void Grid_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)