using ComPDFKitViewer.AnnotEvent; using PDF_Office.CustomControl.CompositeControl; using PDF_Office.Helper; using PDF_Office.Properties; using PDFSettings; using Prism.Mvvm; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Media; namespace PDF_Office.Model.AnnotPanel { //注释的通用属性 public class AnnotCommon : BindableBase { //注释类型 private AnnotArgsType _annotType; public AnnotArgsType AnnotType { get { return _annotType; } set => SetProperty(ref _annotType, value); } //注释类型名称 private string _annotTypeTitle; public string AnnotTypeTitle { get { return _annotTypeTitle; } set => SetProperty(ref _annotTypeTitle, value); } #region 线条 //线条粗细大小 private double _annotThickness = 1; public double AnnotThickness { get { return _annotThickness; } set => SetProperty(ref _annotThickness, value); } //线条样式 private DashStyle dash = new DashStyle(); public DashStyle Dash { get { return dash; } set => SetProperty(ref dash, value); } #endregion 线条 #region 填充 //填充颜色透明度 private double fillOpacity = 1; public double FillOpacity { get { return fillOpacity; } set => SetProperty(ref fillOpacity, value); } //当前填充颜色 private Brush _currentFillColor = new SolidColorBrush(Colors.Transparent); public Brush CurrentFillColor { get { return _currentFillColor; } set => SetProperty(ref _currentFillColor, value); } //填充颜色 private Brush fillColor = new SolidColorBrush(Colors.Transparent); public Brush FillColor { get { return fillColor; } set { SetProperty(ref fillColor, value); CurrentFillColor = fillColor; } } //边框颜色集合 private List _colorItems = new List(); public List ColorItems { get { return _colorItems; } set => SetProperty(ref _colorItems, value); } //填充颜色集合 private List _fillColorItems = new List(); public List FillColorItems { get { return _fillColorItems; } set => SetProperty(ref _fillColorItems, value); } #endregion 填充 #region 边框 //边框颜色透明度 private double _borderOpacity = 1; public double BorderOpacity { get { return _borderOpacity; } set => SetProperty(ref _borderOpacity, value); } private Brush _borderColor = new SolidColorBrush(Colors.Transparent); public Brush BorderColor { get { return _borderColor; } set { SetProperty(ref _borderColor, value); CurrentBorderColor = _borderColor; } } //当前边框颜色 private Brush _currentBorderColor = new SolidColorBrush(Colors.Transparent); public Brush CurrentBorderColor { get { return _currentBorderColor; } set => SetProperty(ref _currentBorderColor, value); } private Brush _fontColor = new SolidColorBrush(Colors.Transparent); public Brush FontColor { get { return _fontColor; } set { SetProperty(ref _fontColor, value); CurrentFontColor = _fontColor; } } //当前边框颜色 private Brush _currentFontColor = new SolidColorBrush(Colors.Transparent); public Brush CurrentFontColor { get { return _currentFontColor; } set => SetProperty(ref _currentFontColor, value); } //外部UI引用,判断是否选中实线、虚线、或都不选中 public string strDashStyle { get; private set; } //VM赋值 public void SetStrDashStyle(string str) { strDashStyle = str; } //外部UI引用,其他:例如形状注释类型 public string strOtherTag { get; private set; } //VM赋值 public void SetOtherTag(string str) { strOtherTag = str; } #endregion #region 多选 //多选注释:用处 - 多选注释使得下拉框为空内容,刷新最新的UI布局 private bool _isMultiSelected = false; public bool IsMultiSelected { get { return _isMultiSelected; } set => SetProperty(ref _isMultiSelected, value); } #endregion /// /// VM触发到外部UI事件 /// public event EventHandler SelectedAnnotInvokeToUI; //Todo:由于考虑到有些UI在VM不太方便处理,因此需要触发该函数到外部xaml.cs里更改UI属性。 //更改多个属性:value可为键值对集合 //适应范围:若VM在Loaded进行绑定,需要UI初始化之后,才能起到作用 public void InvokeToUI(object sender, object value) { SelectedAnnotInvokeToUI?.Invoke(sender, value); } } //注释的通用颜色集合 public class AnnotColorList { //用于高亮注释颜色 public static List GetColorList(ColorSelectorType type) { ColorSelectorItem cacheColorItem = null; if (Settings.Default.ColorSelectors == null) { Settings.Default.ColorSelectors = new ColorSelectorList(); } else { //是否存在某类型的颜色列表 cacheColorItem = Settings.Default.ColorSelectors.FirstOrDefault(temp => temp.SelectorType == type); } List Items = GetSpecifiedColorList(type); if (cacheColorItem== null) { SaveInitSelector(Items, type); } else { //若存在,同步缓存里的数据 foreach(var item in Items) { var selector = SettingHelper.GetColorSelectorItem(type, item.Index); if (selector != null) { item.Color = new SolidColorBrush(selector.color); } } } return Items; } //缓存第一次初始化数据 private static void SaveInitSelector(List colors, ColorSelectorType type) { if (Settings.Default.ColorSelectors == null) { Settings.Default.ColorSelectors = new ColorSelectorList(); } foreach (var item in colors) { ColorSelectorItem colorSelectorItem = new ColorSelectorItem(); colorSelectorItem.color = (item.Color as SolidColorBrush).Color; colorSelectorItem.SelectorType = type; colorSelectorItem.Index = item.Index; colorSelectorItem.IsChangedColor = false; Settings.Default.ColorSelectors.Add(colorSelectorItem); } Settings.Default.Save(); } //选取某类型第一次初始化(默认值)的颜色列表 private static List GetSpecifiedColorList(ColorSelectorType type) { List Items = null; switch (type) { case ColorSelectorType.Highlight: Items = GetHighlightColorList(); break; case ColorSelectorType.Border: Items = GetBorderColorList(); break; case ColorSelectorType.Fill: Items = GetFillColorList(); break; case ColorSelectorType.Sticky: Items = GetStyleColorList(); break; default: Items = GetHighlightColorList(); break; } return Items; } //用于高亮注释颜色 private static List GetHighlightColorList() { List HighlightItems = new List(); HighlightItems = new List(); ColorItem colorItem = new ColorItem(Color.FromArgb(0xff, 0xff, 0xC7, 0x00), 0); HighlightItems.Add(colorItem); colorItem = new ColorItem(Color.FromArgb(0xff, 0xFC, 0x1F, 0x1F), 1); HighlightItems.Add(colorItem); colorItem = new ColorItem(Color.FromArgb(0xff, 0x3E, 0xED, 0x92), 2); HighlightItems.Add(colorItem); colorItem = new ColorItem(Color.FromArgb(0xff, 0x47, 0xC8, 0xFF), 3); HighlightItems.Add(colorItem); return HighlightItems; } //用于边框颜色 private static List GetBorderColorList() { List BorderItems = new List(); BorderItems = new List(); ColorItem colorItem = new ColorItem(Color.FromArgb(0xff, 0xFC, 0x1F, 0x1F), 0); BorderItems.Add(colorItem); colorItem = new ColorItem(Color.FromArgb(0xff, 0x29, 0x53, 0x93), 1); BorderItems.Add(colorItem); colorItem = new ColorItem(Color.FromArgb(0xff, 0x1E, 0x89, 0x56), 2); BorderItems.Add(colorItem); colorItem = new ColorItem(Color.FromArgb(0xff, 0xB8, 0x08, 0xD4), 3); BorderItems.Add(colorItem); return BorderItems; } //用于填充颜色 private static List GetFillColorList() { List FillItems = new List(); FillItems = new List(); ColorItem colorItem = new ColorItem(Colors.Transparent, 0); FillItems.Add(colorItem); colorItem = new ColorItem(Color.FromArgb(0xff, 0xff, 0xff, 0xff), 1); FillItems.Add(colorItem); colorItem = new ColorItem(Color.FromArgb(0xff, 0xDF, 0xE1, 0xE4), 2); FillItems.Add(colorItem); colorItem = new ColorItem(Color.FromArgb(0xff, 0xFF, 0xF1, 0xC1), 3); FillItems.Add(colorItem); return FillItems; } //用于注释样式颜色:如便签样式颜色 private static List GetStyleColorList() { List StyleItems = new List(); StyleItems = new List(); ColorItem colorItem = new ColorItem(Color.FromArgb(0xff, 0xff, 0xD5, 0x73), 0); StyleItems.Add(colorItem); colorItem = new ColorItem(Color.FromArgb(0xff, 0xF8, 0x59, 0xC8), 1); StyleItems.Add(colorItem); colorItem = new ColorItem(Color.FromArgb(0xff, 0x1A, 0xD5, 0x98), 2); StyleItems.Add(colorItem); colorItem = new ColorItem(Color.FromArgb(0xff, 0x68, 0xAC, 0xF8), 3); StyleItems.Add(colorItem); return StyleItems; } } }