123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372 |
- using ComPDFKitViewer;
- using ComPDFKitViewer.AnnotEvent;
- using PDF_Master.CustomControl.CompositeControl;
- using PDF_Master.Model;
- using PDF_Master.Model.AnnotPanel;
- using PDF_Master.Properties;
- using PDF_Master.ViewModels.Tools;
- using PDF_Master.ViewModels.Tools.AnnotManager;
- using PDFSettings;
- using Prism.Commands;
- using Prism.Mvvm;
- using Prism.Regions;
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Diagnostics;
- using System.Diagnostics.Eventing.Reader;
- using System.Globalization;
- using System.Windows;
- using System.Windows.Data;
- using System.Windows.Media;
- namespace PDF_Master.ViewModels.PropertyPanel.AnnotPanel
- {
- public class AnnotArgsTypeConverter : IValueConverter
- {
- public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
- {
- if (value is AnnotArgsType)
- {
- if (parameter is string)
- {
- var args = (AnnotArgsType)value;
- if ((string)parameter == "AnnotHighlight" && args == AnnotArgsType.AnnotHighlight)
- {
- return Visibility.Visible;
- }
- if ((string)parameter == "AnnotUnderline" && args == AnnotArgsType.AnnotUnderline)
- {
- return Visibility.Visible;
- }
- if ((string)parameter == "AnnotSquiggly" && args == AnnotArgsType.AnnotSquiggly)
- {
- return Visibility.Visible;
- }
- if ((string)parameter == "AnnotStrikeout" && args == AnnotArgsType.AnnotStrikeout)
- {
- return Visibility.Visible;
- }
- if ((string)parameter == "AnnotSticky" && args == AnnotArgsType.AnnotSticky)
- {
- return Visibility.Visible;
- }
- }
- }
- return Visibility.Collapsed;
- }
- public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
- {
- throw new NotImplementedException();
- }
- }
- public class TextAnnotPropertyViewModel : BindableBase, INavigationAware
- {
- #region 属性
- private ViewContentViewModel ViewContentViewModel;
- //当前边框颜色
- private Brush _textDefaultColor;
- public Brush TextDefaultColor
- {
- get { return _textDefaultColor; }
- set => SetProperty(ref _textDefaultColor, value);
- }
- private AnnotCommon _basicVm = new AnnotCommon();
- public AnnotCommon BasicVm
- {
- get { return _basicVm; }
- set => SetProperty(ref _basicVm, value);
- }
- private ColorSelectorType _colorType = ColorSelectorType.Highlight;
- public ColorSelectorType ColorType
- {
- get { return _colorType; }
- set => SetProperty(ref _colorType, value);
- }
- //保存类型对应默认颜色
- private Brush HighlightDefaultColor = App.Current.FindResource("color.sys.layout.divider.highlight") as Brush;
- private Brush UnderlineDefaultColor = App.Current.FindResource("color.sys.layout.divider.strikethough") as Brush;
- private Brush StrikeoutDefaultColor = App.Current.FindResource("color.sys.layout.divider.underline") as Brush;
- private AnnotArgsType annotArgsType = AnnotArgsType.AnnotHighlight;
- public List<ColorItem> HighlightItems { get; set; }
- public List<ColorItem> UnderLineItems { get; set; }
- public List<ColorItem> StrikeoutItems { get; set; }
- #endregion 属性
- public AnnotAttribEvent AnnotEvent { get; set; }
- private AnnotHandlerEventArgs Annot;
- public AnnotTransfer PropertyPanel;
- public DelegateCommand<object> SelectedColorChangedCommand { get; set; }
- public DelegateCommand<object> SelectedOpacityChangedCommand { get; set; }
- public DelegateCommand<object> DefaultColorChangedCommand { get; set; }
- public TextAnnotPropertyViewModel()
- {
- SelectedColorChangedCommand = new DelegateCommand<object>(SelectedColorChanged);
- DefaultColorChangedCommand = new DelegateCommand<object>(DefaultColorChanged);
- SelectedOpacityChangedCommand = new DelegateCommand<object>(SelectedOpacityChanged);
- InitHighlightItems();
- InitUnderLinetItems();
- }
- private void InitHighlightItems()
- {
- HighlightItems = AnnotColorList.GetColorList(ColorSelectorType.Highlight);
- }
- private void InitUnderLinetItems()
- {
- UnderLineItems = AnnotColorList.GetColorList(ColorSelectorType.Border);
- StrikeoutItems = AnnotColorList.GetColorList(ColorSelectorType.Border);
- }
- //设置不透明度
- private void SelectedOpacityChanged(object obj)
- {
- if (obj != null)
- {
- BasicVm.FillOpacity = (double)obj;
- BasicVm.FontColor.Opacity = BasicVm.FillOpacity;
- PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Transparency, BasicVm.FillOpacity);
- if (BasicVm.IsMultiSelected == false)
- {
- PropertyPanel.InvokeToMyTools(BasicVm.AnnotType, BasicVm.FillOpacity);
- }
- }
- }
- //设置颜色
- public void SelectedColorChanged(object color)
- {
- if (color != null && PropertyPanel != null)
- {
- var colorValue = (Color)color;
- if (colorValue != null)
- {
- BasicVm.FontColor = new SolidColorBrush(colorValue);
- BasicVm.FontColor.Opacity = BasicVm.FillOpacity;
- PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Color, colorValue);
- if (BasicVm.IsMultiSelected == false)
- {
- PropertyPanel.InvokeToMyTools(BasicVm.AnnotType, color);
- }
- }
- }
- }
- public void DefaultColorChanged(object color)
- {
- if (color != null)
- {
- var colorValue = (Color)color;
- if (colorValue != null)
- {
- TextDefaultColor = new SolidColorBrush(colorValue);
- switch (annotArgsType)
- {
- case AnnotArgsType.AnnotHighlight:
- {
- HighlightDefaultColor = new SolidColorBrush(colorValue);
- }
- break;
- case AnnotArgsType.AnnotUnderline:
- {
- UnderlineDefaultColor = new SolidColorBrush(colorValue);
- }
- break;
- case AnnotArgsType.AnnotStrikeout:
- {
- StrikeoutDefaultColor = new SolidColorBrush(colorValue);
- }
- break;
- case AnnotArgsType.AnnotSquiggly:
- {
- }
- break;
- }
- }
- }
- }
- private void SetAnnotType()
- {
- if (BasicVm.IsMultiSelected)
- {
- BasicVm.AnnotTypeTitle = "General Properties";
- return;
- }
- switch (BasicVm.AnnotType)
- {
- case AnnotArgsType.AnnotHighlight:
- BasicVm.AnnotTypeTitle = App.MainPageLoader.GetString("Highlight_Title");
- break;
- case AnnotArgsType.AnnotUnderline:
- BasicVm.AnnotTypeTitle = App.MainPageLoader.GetString("Underline_Title");
- break;
- case AnnotArgsType.AnnotStrikeout:
- BasicVm.AnnotTypeTitle = App.MainPageLoader.GetString("Strikethrough_Title");
- break;
- case AnnotArgsType.AnnotSquiggly:
- BasicVm.AnnotTypeTitle = "波浪线";
- break;
- }
- }
- public bool IsNavigationTarget(NavigationContext navigationContext)
- {
- return true;
- }
- public void OnNavigatedFrom(NavigationContext navigationContext)
- {
- BasicVm.IsMultiSelected = false;
- }
- public void OnNavigatedTo(NavigationContext navigationContext)
- {
- navigationContext.Parameters.TryGetValue<ViewContentViewModel>(ParameterNames.ViewContentViewModel, out ViewContentViewModel);
- navigationContext.Parameters.TryGetValue<AnnotTransfer>(ParameterNames.PropertyPanelContentViewModel, out PropertyPanel);
- if (PropertyPanel != null)
- {
- AllVariable();
- SetAnnotType();
- //多选注释,默认通用属性颜色为高亮注释的预设颜色
- if (BasicVm.IsMultiSelected)
- {
- BasicVm.ColorItems = HighlightItems;
- ColorType = ColorSelectorType.Highlight;
- var annotate = Settings.Default.AppProperties.Annotate;
- if (annotate != null)
- {
- BasicVm.FontColor = new SolidColorBrush(annotate.HighLightColor);
- }
- else
- {
- BasicVm.FontColor = new SolidColorBrush(Color.FromArgb(0x01, 0xff, 0xff, 0xff));
- }
- }
- else
- {
- SelectedColorItems();
- GetAnnotProperty();
- }
- }
- }
- private void SelectedColorItems()
- {
- if (BasicVm.AnnotType == AnnotArgsType.AnnotHighlight)
- {
- BasicVm.ColorItems = HighlightItems;
- ColorType = ColorSelectorType.Highlight;
- }
- else if (BasicVm.AnnotType == AnnotArgsType.AnnotUnderline)
- {
- BasicVm.ColorItems = UnderLineItems;
- ColorType = ColorSelectorType.Border;
- }
- else
- {
- BasicVm.ColorItems = StrikeoutItems;
- ColorType = ColorSelectorType.Border;
- }
- }
- //全局变量,优先集中处理
- private void AllVariable()
- {
- AnnotEvent = PropertyPanel.AnnotEvent;
- Annot = PropertyPanel.annot;
- BasicVm.AnnotType = Annot.EventType;
- BasicVm.IsMultiSelected = PropertyPanel.IsMultiSelected;
- }
- private void GetAnnotProperty()
- {
- if (Annot != null)
- {
- annotArgsType = Annot.EventType;
- switch (Annot.EventType)
- {
- case AnnotArgsType.AnnotHighlight:
- if (Annot is TextHighlightAnnotArgs)
- {
- var Hightlight = Annot as TextHighlightAnnotArgs;
- if (ViewContentViewModel.IsSettingOut)
- {
- HighlightDefaultColor = new SolidColorBrush(Hightlight.Color);
- ViewContentViewModel.IsSettingOut = false;
- }
- TextDefaultColor = HighlightDefaultColor;
- BasicVm.FillOpacity = Hightlight.Transparency;
- BasicVm.FontColor = new SolidColorBrush(Hightlight.Color);
- }
- break;
- case AnnotArgsType.AnnotUnderline:
- {
- var Underline = Annot as TextUnderlineAnnotArgs;
- if (ViewContentViewModel.IsSettingOut)
- {
- UnderlineDefaultColor = new SolidColorBrush(Underline.Color);
- ViewContentViewModel.IsSettingOut = false;
- }
- TextDefaultColor = UnderlineDefaultColor;
- BasicVm.FillOpacity = Underline.Transparency;
- BasicVm.FontColor = new SolidColorBrush(Underline.Color);
- }
- break;
- case AnnotArgsType.AnnotStrikeout:
- {
- var Strikeout = Annot as TextStrikeoutAnnotArgs;
- if (ViewContentViewModel.IsSettingOut)
- {
- StrikeoutDefaultColor = new SolidColorBrush(Strikeout.Color);
- ViewContentViewModel.IsSettingOut = false;
- }
- TextDefaultColor = StrikeoutDefaultColor;
- BasicVm.FillOpacity = Strikeout.Transparency;
- BasicVm.FontColor = new SolidColorBrush(Strikeout.Color);
- }
- break;
- case AnnotArgsType.AnnotSquiggly:
- {
- var Squiggly = Annot as TextSquigglyAnnotArgs;
- BasicVm.FillOpacity = Squiggly.Transparency;
- BasicVm.FontColor = new SolidColorBrush(Squiggly.Color);
- }
- break;
- }
- }
- }
- }
- }
|