浏览代码

注释 - 便签弹窗样式

chenrongqian@kdanmobile.com 2 年之前
父节点
当前提交
5043d2e7af

+ 13 - 0
PDF Office/ViewModels/Tools/AnnotToolContentViewModel.Function.cs

@@ -159,6 +159,19 @@ namespace PDF_Office.ViewModels.Tools
 
         public Dictionary<string, string> GetToolTipDict{get{return ToolTipDict;}}
 
+        //便签批注弹窗
+        private void LoaedStickyNotePopup()
+        {
+            if (PDFViewer == null) return;
+
+            if(customStickyPopup == null)
+            {
+                customStickyPopup = new StickyNotePopup();
+                PDFViewer.SetStickyNotePop(customStickyPopup);
+            }
+           
+        }
+
         #endregion 初始化数据
 
         #endregion 初始化

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

@@ -4,6 +4,7 @@ using ComPDFKitViewer.PdfViewer;
 using PDF_Office.CustomControl;
 using PDF_Office.Helper;
 using PDF_Office.ViewModels.PropertyPanel.AnnotPanel;
+using PDF_Office.Views.PropertyPanel.AnnotPanel;
 using Prism.Commands;
 using Prism.Events;
 using Prism.Regions;
@@ -264,7 +265,7 @@ namespace PDF_Office.ViewModels.Tools
         private AnnotPropertyPanel propertyPanel = new AnnotPropertyPanel();
         private Dictionary<string, AnnotArgsType> ToolExpandDict = new Dictionary<string, AnnotArgsType>();
         private Dictionary<string, string> ToolTipDict = new Dictionary<string, string>();
-
+        private StickyNotePopup customStickyPopup;
         private bool isHiddenAnnot = true;
         private bool isAddBookMark = true;
         private bool isRightMenuAddAnnot = false;

+ 1 - 0
PDF Office/ViewModels/Tools/AnnotToolContentViewModel.cs

@@ -647,6 +647,7 @@ namespace PDF_Office.ViewModels.Tools
             navigationContext.Parameters.TryGetValue<ViewContentViewModel>(ParameterNames.ViewContentViewModel, out viewContentViewModel);
             navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
             BindingPDFViewerHandler();
+            LoaedStickyNotePopup();
         }
 
         #endregion Navigation

+ 1 - 0
PDF Office/ViewModels/ViewContentViewModel.cs

@@ -25,6 +25,7 @@ using PDF_Office.Model.Dialog.ToolsDialogs;
 using DryIoc;
 using PDF_Office.Model.Dialog.ConverterDialogs;
 using static PDF_Office.Model.Dialog.ToolsDialogs.SaftyDialogs.DeleteSafetySettintgsModel;
+using PDF_Office.Views.PropertyPanel.AnnotPanel;
 
 namespace PDF_Office.ViewModels
 {

+ 68 - 65
PDF Office/Views/PropertyPanel/AnnotPanel/StickyNotePopup.xaml

@@ -20,30 +20,45 @@
             <Setter Property="Margin" Value="2,0,2,0" />
         </Style>
     </annotview:StickyPopupExt.Resources>
-    <Border  x:Name="border" Background="{StaticResource color.sys.layout.anti}" CornerRadius="8" BorderThickness="2" BorderBrush="#ffe49a" MinWidth="240" MinHeight="200" Width="240" Height="200" >
-        <Border.Effect>
-            <DropShadowEffect BlurRadius="8" Direction="0" Opacity="0.16" ShadowDepth="0" Color="#000000" />
-        </Border.Effect>
-        <Grid Name="GridUi" Margin="8">
-            <Grid.RowDefinitions>
-                <RowDefinition Height="32"/>
-                <RowDefinition Height="1"/>
-                <RowDefinition />
-                <RowDefinition Height="32"/>
-            </Grid.RowDefinitions>
-            <Grid >
-                <TextBlock x:Name="AuthorText" Text="test" FontSize="12" Foreground="{StaticResource color.sys.text.neutral.lv2}" VerticalAlignment="Center" HorizontalAlignment="Left"/>
-                <TextBlock x:Name="DateTextui" Text="date time" FontSize="12" Foreground="{StaticResource color.sys.text.neutral.lv2}" VerticalAlignment="Center" HorizontalAlignment="Right"/>
-            </Grid>
-            <Border MouseUp="CloseText_MouseUp"/>
-            <Rectangle Grid.Row="1" Fill="{StaticResource color.sys.layout.divider}" HorizontalAlignment="Stretch"  VerticalAlignment="Stretch"/>
-            <Grid Grid.Row="2" Margin="0,2,0,2">
-                <TextBox Name="ContentText" Grid.Row="2" Margin="4,0,4,0" Background="#CCFFFFFF" BorderThickness="0" 
+    <Grid MouseLeftButtonDown="Grid_MouseLeftButtonDown">
+        <Border  x:Name="border" Background="{StaticResource color.sys.layout.anti}" CornerRadius="8" BorderThickness="2" BorderBrush="#ffe49a" MinWidth="240" MinHeight="200" Width="240" Height="200" >
+            <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.RowDefinitions>
+                    <RowDefinition Height="auto"></RowDefinition>
+                    <RowDefinition Height="auto"></RowDefinition>
+                    <RowDefinition Height="*"></RowDefinition>
+                    <RowDefinition Height="auto"></RowDefinition>
+                </Grid.RowDefinitions>
+                <Grid>
+                    <Grid.ColumnDefinitions>
+                        <ColumnDefinition Width="auto"></ColumnDefinition>
+                        <ColumnDefinition Width="auto"></ColumnDefinition>
+                        <ColumnDefinition Width="*"></ColumnDefinition>
+                        <ColumnDefinition Width="auto"></ColumnDefinition>
+                        <ColumnDefinition Width="auto"></ColumnDefinition>
+                    </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">
+                        <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
+                            </Path.Data>
+                            <Path.LayoutTransform>
+                                <RotateTransform Angle="45"></RotateTransform>
+                            </Path.LayoutTransform>
+                        </Path>
+                    </Border>
+                </Grid>
+              
+                <TextBox  Name="ContentText" Grid.Row="2" Margin="4,0,4,0" Background="#CCFFFFFF" BorderThickness="0" 
                      AcceptsReturn="True" TextWrapping="Wrap" VerticalScrollBarVisibility="Auto"></TextBox>
-            </Grid>
 
-            <Grid Grid.Row="3">
-                <ListBox
+                <Grid Grid.Row="3">
+                    <ListBox
             x:Name="ListColor"
             Background="Transparent"
             BorderThickness="0"
@@ -51,48 +66,36 @@
             ItemTemplate="{StaticResource listboxData}"
             SelectionChanged="ListColor_SelectionChanged"
             >
-                    <ListBox.ItemsPanel>
-                        <ItemsPanelTemplate>
-                            <WrapPanel Orientation="Horizontal" />
-                        </ItemsPanelTemplate>
-                    </ListBox.ItemsPanel>
-                </ListBox>
-            </Grid>
-           
-            <!--<Grid.RowDefinitions>
-                <RowDefinition Height="auto"></RowDefinition>
-                <RowDefinition Height="auto"></RowDefinition>
-                <RowDefinition Height="*"></RowDefinition>
-                <RowDefinition Height="auto"></RowDefinition>
-            </Grid.RowDefinitions>
-            <Grid>
-                <Grid.ColumnDefinitions>
-                    <ColumnDefinition Width="auto"></ColumnDefinition>
-                    <ColumnDefinition Width="auto"></ColumnDefinition>
-                    <ColumnDefinition Width="*"></ColumnDefinition>
-                    <ColumnDefinition Width="auto"></ColumnDefinition>
-                    <ColumnDefinition Width="auto"></ColumnDefinition>
-                </Grid.ColumnDefinitions>
-                <Path Fill="#000000" Margin="2,2,0,0" Width="20" Height="20">
-                    <Path.Data>M19,2 L19,15 L9.137,15 L4,18.383095 L4,15 L1,15 L1,2 L19,2 Z M18,3 L2,3 L2,14 L5,14 L5,16.616 L8.86150802,14 L18,14 L18,3 Z M15,9 L15,10 L5,10 L5,9 L15,9 Z M11,6 L11,7 L5,7 L5,6 L11,6 Z</Path.Data>
-                </Path>
-                <TextBlock Grid.Column="1" FontFamily="SegoeUI" FontSize="12" VerticalAlignment="Center" LineHeight="16" Margin="2,2,0,0">Note</TextBlock>
-                <TextBlock Name="DateText" Grid.Column="3" Foreground="#000000" 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">
-                    <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
-                        </Path.Data>
-                        <Path.LayoutTransform>
-                            <RotateTransform Angle="45"></RotateTransform>
-                        </Path.LayoutTransform>
-                    </Path>
-                </Border>
+                        <ListBox.ItemsPanel>
+                            <ItemsPanelTemplate>
+                                <WrapPanel Orientation="Horizontal" />
+                            </ItemsPanelTemplate>
+                        </ListBox.ItemsPanel>
+                    </ListBox>
+                </Grid>
+
+
+                <Button
+                        x:Name="BtnDelete" HorizontalAlignment="Right"
+                        Width="32" Grid.Row="3"
+                        Height="32"
+                        MaxHeight="40"
+                        Margin="16,0,10,5" BorderThickness="0"
+                        Foreground="#6B6F7D" Click="BtnDelete_Click"
+                        
+                        Style="{StaticResource btn.sec}">
+                    <Path
+                            Width="32"
+                            Height="32"
+                            Data="M14 9.75H18V8.25H14V9.75ZM9 12.25H10.25V23C10.25 23.4142 10.5858 23.75 11 23.75H21C21.4142 23.75 21.75 23.4142 21.75 23V12.25H23V10.75H9V12.25ZM11.75 22.25V12.25H20.25V22.25H11.75ZM15.25 14.5V19.5H16.75V14.5H15.25Z"
+                            Fill="{Binding ElementName=BtnDelete, Path=Foreground}" />
+                </Button>
+
+
+                <ResizeGrip Name="GripControl" Visibility="Collapsed" Grid.Row="3" HorizontalAlignment="Right" Margin="0,2,0,0" Cursor="SizeNWSE" MouseMove="ResizeGrip_MouseMove"></ResizeGrip>
             </Grid>
-            <TextBlock Name="AuthorText" Grid.Row="1" FontFamily="SegoeUI" FontSize="12" LineHeight="16" Margin="2,2,0,0"></TextBlock>
-            <TextBox Name="ContentText" Grid.Row="2" Margin="4,0,4,0" Background="#CCFFFFFF" BorderThickness="0" 
-                     AcceptsReturn="True" TextWrapping="Wrap" VerticalScrollBarVisibility="Auto"></TextBox>-->
-            <!--<ResizeGrip Name="GripControl" Grid.Row="3" HorizontalAlignment="Right" Margin="0,2,0,0" Cursor="SizeNWSE" MouseMove="ResizeGrip_MouseMove"></ResizeGrip>-->
-        </Grid>
-    </Border>
+
+        </Border>
+       
+    </Grid>
 </annotview:StickyPopupExt>

+ 185 - 20
PDF Office/Views/PropertyPanel/AnnotPanel/StickyNotePopup.xaml.cs

@@ -8,6 +8,7 @@ using System.Text;
 using System.Threading.Tasks;
 using System.Windows;
 using System.Windows.Controls;
+using System.Windows.Controls.Primitives;
 using System.Windows.Data;
 using System.Windows.Documents;
 using System.Windows.Input;
@@ -21,22 +22,44 @@ namespace PDF_Office.Views.PropertyPanel.AnnotPanel
     /// <summary>
     /// StickyNotePopup.xaml 的交互逻辑
     /// </summary>
+   
+    public class GripThumb : Thumb
+    {
+        private Pen DrawPen;
+        private Brush FillBrush;
+        public GripThumb()
+        {
+            DefaultStyleKey = typeof(GripThumb);
+            DrawPen = new Pen(new SolidColorBrush(Colors.Blue), 2);
+            FillBrush = new SolidColorBrush(Color.FromArgb(0x0A, 0xFF, 0xFF, 0xFF));
+        }
+        protected override void OnRender(DrawingContext DrawContext)
+        {
+            DrawContext.DrawRectangle(FillBrush, null, new Rect(0, 0, Width, Height));
+            DrawContext.DrawLine(DrawPen, new Point(Width, 0), new Point(0, Height));
+            DrawContext.DrawLine(DrawPen, new Point(Width, Height / 3), new Point(Width / 3, Height));
+            DrawContext.DrawLine(DrawPen, new Point(Width, Height * 2 / 3), new Point(Width * 2 / 3, Height));
+        }
+    }
+    /// <summary>
+    /// StickyNotePopup.xaml 的交互逻辑
+    /// </summary>
     public partial class StickyNotePopup : StickyPopupExt
     {
         private ObservableCollection<ColorItem> colors = new ObservableCollection<ColorItem>();
         private Point PressPoint;
         public Point OffsetParent;
+
         private byte saveOpacity = 1;
-        public bool CanMove { get; set; } = true;
         public StickyNotePopup()
         {
             InitializeComponent();
             AddHandler(MouseUpEvent, new MouseButtonEventHandler(StickyPopupControl_MouseUp), true);
             ContentText.AddHandler(MouseDownEvent, new MouseButtonEventHandler(StickyPopupControl_MouseDown), true);
             Loaded += StickyPopupControl_Loaded;
-            Unloaded += StickyPopupControl_Unloaded;
             ContentText.GotFocus += ContentText_GotFocus;
             ContentText.LostFocus += ContentText_LostFocus;
+
             colors.Add(new ColorItem(Color.FromArgb(0xFF, 0xFF, 0xFF, 0x10)));
             colors.Add(new ColorItem(Color.FromArgb(0xFF, 0xFF, 0x10, 0x10)));
             colors.Add(new ColorItem(Color.FromArgb(0xFF, 0x10, 0xFF, 0x10)));
@@ -44,7 +67,6 @@ namespace PDF_Office.Views.PropertyPanel.AnnotPanel
             ListColor.ItemsSource = colors;
         }
 
-
         private void ContentText_LostFocus(object sender, RoutedEventArgs e)
         {
             e.Handled = true;
@@ -52,10 +74,6 @@ namespace PDF_Office.Views.PropertyPanel.AnnotPanel
             bkColor.A = saveOpacity;
             border.BorderBrush = new SolidColorBrush(bkColor);
             CloseText_MouseUp(this, null);
-            border.BorderBrush = this.Background;
-            this.Background = new SolidColorBrush(Colors.Transparent);
-            AuthorText.Text = this.Author;
-            DateTextui.Text = this.DateText;
         }
 
         private void ContentText_GotFocus(object sender, RoutedEventArgs e)
@@ -64,19 +82,13 @@ namespace PDF_Office.Views.PropertyPanel.AnnotPanel
             saveOpacity = bkColor.A;
             bkColor.A = 255;
             border.BorderBrush = new SolidColorBrush(bkColor);
-
-            border.BorderBrush = this.Background;
-            this.Background = new SolidColorBrush(Colors.Transparent);
-            AuthorText.Text = this.Author;
-            DateTextui.Text = this.DateText;
+            this.Background = new SolidColorBrush(this.StickyColor);
         }
 
         private void StickyPopupControl_Loaded(object sender, RoutedEventArgs e)
         {
             ContentText.Focus();
             ContentText.CaretIndex = ContentText.Text.Length;
-            ContentText.Text = this.StickyNote;
-           
         }
 
         private void StickyPopupControl_MouseDown(object sender, MouseButtonEventArgs e)
@@ -87,6 +99,7 @@ namespace PDF_Office.Views.PropertyPanel.AnnotPanel
         private void StickyPopupControl_MouseUp(object sender, MouseButtonEventArgs e)
         {
             CanMove = true;
+            GripControl.ReleaseMouseCapture();
         }
 
         public string StickyText
@@ -101,6 +114,7 @@ namespace PDF_Office.Views.PropertyPanel.AnnotPanel
             }
         }
 
+
         public string StickyAuthor
         {
             get
@@ -117,11 +131,39 @@ namespace PDF_Office.Views.PropertyPanel.AnnotPanel
         {
             get
             {
-                return DateTextui.Text;
+                return DateText.Text;
             }
             set
             {
-                DateTextui.Text = value;
+                DateText.Text = value;
+            }
+        }
+
+        public bool CanMove { get; set; } = true;
+        private void ResizeGrip_MouseMove(object sender, MouseEventArgs e)
+        {
+            e.Handled = true;
+            if (e.LeftButton == MouseButtonState.Pressed)
+            {
+                Point currentPos = e.GetPosition(ContainerElement);
+                double newWidth = GridUi.ActualWidth + currentPos.X - PressPoint.X;
+                double newHeight = GridUi.ActualHeight + currentPos.Y - PressPoint.Y;
+                if (Left + newWidth >= ContainerElement.ActualWidth)
+                {
+                    newWidth = ContainerElement.ActualWidth - Left - 5;
+                }
+                if (Top + newHeight >= ContainerElement.ActualHeight)
+                {
+                    newHeight = ContainerElement.ActualHeight - Top - 5;
+                }
+                GridUi.Width = newWidth;
+                GridUi.Height = newHeight;
+                PressPoint = currentPos;
+                CanMove = false;
+                if (GripControl.IsMouseCaptured == false)
+                {
+                    GripControl.CaptureMouse();
+                }
             }
         }
 
@@ -140,19 +182,142 @@ namespace PDF_Office.Views.PropertyPanel.AnnotPanel
             }
         }
 
+        protected override void OnMouseDown(MouseButtonEventArgs e)
+        {
+            e.Handled = true;
+            PressPoint = e.GetPosition(ContainerElement);
+        }
+
+        protected override void OnMouseEnter(MouseEventArgs e)
+        {
+            e.Handled = true;
+            if (PlaceChange != null)
+            {
+                PlaceChange.Invoke(this, new EventArgs());
+            }
+        }
+
+        protected override void OnMouseLeave(MouseEventArgs e)
+        {
+            e.Handled = true;
+            if (PlaceChange != null)
+            {
+                PlaceChange.Invoke(null, new EventArgs());
+            }
+            PressPoint = new Point(0, 0);
+        }
+
+        protected override void OnMouseUp(MouseButtonEventArgs e)
+        {
+            CanMove = true;
+            if (PlaceChange != null)
+            {
+                PlaceChange.Invoke(this, new EventArgs());
+            }
+            PressPoint = new Point(0, 0);
+            GripControl.ReleaseMouseCapture();
+        }
+        protected override void OnMouseMove(MouseEventArgs e)
+        {
+            e.Handled = true;
+            if (e.LeftButton == MouseButtonState.Pressed && e.Source.GetType() != typeof(TextBox) && e.Source.GetType() != typeof(GripThumb))
+            {
+                if (CanMove == false || (PressPoint.X == 0 && PressPoint.Y == 0))
+                {
+                    return;
+                }
+                Point currentPoint = e.GetPosition(ContainerElement);
+                double newLeft = Left + currentPoint.X - PressPoint.X;
+                double newTop = Top + currentPoint.Y - PressPoint.Y;
+                if (newLeft < 0)
+                {
+                    newLeft = 0;
+                }
+                if (newLeft + GridUi.ActualWidth > ContainerElement.ActualWidth)
+                {
+                    newLeft = ContainerElement.ActualWidth - GridUi.ActualWidth;
+                }
+                if (newTop < 0)
+                {
+                    newTop = 0;
+                }
+                if (newTop + GridUi.ActualHeight > ContainerElement.ActualHeight)
+                {
+                    newTop = ContainerElement.ActualHeight - GridUi.ActualHeight;
+                }
+                Left = newLeft;
+                Top = newTop;
+                PressPoint = currentPoint;
+                if (PlaceChange != null)
+                {
+                    PlaceChange.Invoke(null, new EventArgs());
+                }
+                RefreshPosition();
+            }
+        }
+
+        public override void SetAuthor(string author)
+        {
+            base.SetAuthor(author);
+            StickyAuthor = author;
+        }
+
+        public override void SetDateText(string dateText)
+        {
+            base.SetDateText(dateText);
+            StickyDate = dateText;
+        }
+
+        public override void SetStickyColor(Color newColor)
+        {
+            base.SetStickyColor(newColor);
+            border.BorderBrush = new SolidColorBrush(newColor);
+        }
+
+        public override void SetStickyNote(string note)
+        {
+            base.SetStickyNote(note);
+            StickyText = note;
+        }
+
+        public override void SetReadOnly(bool readOnly)
+        {
+            base.SetReadOnly(readOnly);
+            ContentText.IsReadOnly = readOnly;
+        }
+
+        public override string GetText()
+        {
+            return StickyText;
+        }
+
         private void ListColor_SelectionChanged(object sender, SelectionChangedEventArgs e)
         {
             var color = ListColor.SelectedItem as ColorItem;
-            if(color != null)
+            if (color != 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);
             }
         }
 
-        private void StickyPopupControl_Unloaded(object sender, RoutedEventArgs e)
+        private void BtnDelete_Click(object sender, RoutedEventArgs e)
         {
-            if (StickyNote != ContentText.Text)
-                this.SetStickyNote(ContentText.Text);
+            ContentText.Text = "";
+            this.SetStickyNote("");
+            Closed.Invoke(sender, EventArgs.Empty);
+        }
+
+        private void Grid_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
+        {
+          var frame = e.OriginalSource as Control;
+            if(frame != null)
+            {
+                var color = frame.Background as SolidColorBrush;
+                if(color != null && color.Color == Colors.Transparent)
+                    Closed.Invoke(sender, EventArgs.Empty);
+            }
         }
     }
 }