using ComPDFKitViewer; using ComPDFKitViewer.AnnotEvent; using PDF_Master.CustomControl.CompositeControl; using PDF_Master.EventAggregators; using PDF_Master.Model; using PDF_Master.Model.AnnotPanel; using PDF_Master.ViewModels.Tools; using PDF_Master.ViewModels.Tools.AnnotManager; using PDFSettings; using Prism.Commands; using Prism.Events; using Prism.Mvvm; using Prism.Regions; using System; using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Media; namespace PDF_Master.ViewModels.PropertyPanel.AnnotPanel { public class StickyNotePropertyViewModel : BindableBase, INavigationAware { //外部UI引用 //public string strOtherTag { get; private set; } private string _strOtherTag; public string strOtherTag { get { return _strOtherTag; } set { SetProperty(ref _strOtherTag, value); } } public bool IsFirst = true; private double _transpent; public double Transpent { get { return _transpent; } set { SetProperty(ref _transpent, value); } } private Geometry _exmpleData; public Geometry ExmpleData { get { return _exmpleData; } set { SetProperty(ref _exmpleData, value); } } private Brush _sharpColor; public Brush SharpColor { get { return _sharpColor; } set { SetProperty(ref _sharpColor, value); SharpCurrentColor = _sharpColor; } } private Brush _sharpCurrentColor = App.Current.FindResource("color.sys.layout.divider.note") as Brush; public Brush SharpCurrentColor { get { return _sharpCurrentColor; } set { SetProperty(ref _sharpCurrentColor, value); } } private bool _isMultiSelected = false; public bool IsMultiSelected { get { return _isMultiSelected; } set => SetProperty(ref _isMultiSelected, value); } //注释类型名称 private string _annotTypeTitle; public string AnnotTypeTitle { get { return _annotTypeTitle; } set => SetProperty(ref _annotTypeTitle, value); } //样式颜色集合 private List _colorItems = new List(); public List ColorItems { get { return _colorItems; } set => SetProperty(ref _colorItems, value); } public Dictionary StickyNoteTypes = new Dictionary(); public DelegateCommand SelectedColorChangedCommand { get; set; } public DelegateCommand SelectedValueChangedCommand { get; set; } public DelegateCommand StrickyNoteShapeCommand { get; set; } public DelegateCommand SelectedOpacityValueCommand { get; set; } private IEventAggregator eventAggregator; public string Unicode = ""; public StickyNotePropertyViewModel(IEventAggregator eventAggregator) { this.eventAggregator = eventAggregator; Unicode = App.mainWindowViewModel.SelectedItem.Unicode; SelectedValueChangedCommand = new DelegateCommand(SelectedValueChanged_Command); SelectedColorChangedCommand = new DelegateCommand(SelectedColorChanged_Click); StrickyNoteShapeCommand = new DelegateCommand(StrickyNoteShape); SelectedOpacityValueCommand = new DelegateCommand(SelectedOpacityValue); InitStickyNoteTypes(); InitColorItems(); var data = StickyNoteTypes["Comment"]; var converter = TypeDescriptor.GetConverter(typeof(Geometry)); ExmpleData = (Geometry)converter.ConvertFrom(data); eventAggregator.GetEvent().Subscribe(SetStickyNoteColor, e => e.Unicode == Unicode); } private void SetStickyNoteColor(StickyNoteColorUnicode stickyNoteColorUnicode) { SharpColor = stickyNoteColorUnicode.brush; PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Color, (SharpColor as SolidColorBrush).Color); } private void InitColorItems() { ColorItems = AnnotColorList.GetColorList(ColorSelectorType.Sticky); } private void SelectedValueChanged_Command(object obj) { if (obj != null) { double value = (double)obj; Transpent = value; PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Transparency, value); } } private void SelectedColorChanged_Click(object obj) { if (obj != null && PropertyPanel != null) { var color = (Color)obj; SharpColor = new SolidColorBrush(color); PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Color, color); eventAggregator.GetEvent().Publish(new StickyNoteColorUnicode { Unicode = Unicode, brush = new SolidColorBrush(color) }); } } private void StrickyNoteShape(object obj) { if (obj != null) { var tag = (string)obj; if (tag == (Annot as StickyAnnotArgs).StickyNote) return; var data = StickyNoteTypes[tag]; var converter = TypeDescriptor.GetConverter(typeof(Geometry)); ExmpleData = (Geometry)converter.ConvertFrom(data); PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.StickyIcon, tag); } } private void SelectedOpacityValue(object obj) { if (obj != null) { double value = (double)obj; Transpent = value; PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Transparency, value); } } private void InitStickyNoteTypes() { //StickyNoteTypes.Add("Comment", "M1.54167 2.5C0.96637 2.5 0.5 2.96637 0.5 3.54167V15.2083C0.5 15.7836 0.96637 16.25 1.54167 16.25H3.83344V19.131C3.83344 19.5239 4.25193 19.7753 4.59884 19.5908L10.8802 16.25H19.4583C20.0336 16.25 20.5 15.7836 20.5 15.2083V3.54167C20.5 2.96637 20.0336 2.5 19.4583 2.5H1.54167ZM16.75 8.4375H4.25V6.5625H16.75V8.4375ZM4.25 12.1875H11.75V10.3125H4.25V12.1875Z"); //StickyNoteTypes.Add("Note", "M3 1H17V14H12V19H3V1ZM13 19V15H17L13 19ZM15 5V3.5H5V5H15ZM15 8V6.5H5V8H15ZM12 9.5V11H5V9.5H12Z"); //StickyNoteTypes.Add("Key", "M14.9552 12.2029C16.009 10.168 15.6751 7.61085 13.9536 5.907C11.8179 3.7932 8.35526 3.7932 6.21956 5.907C4.08386 8.0208 4.08386 11.4479 6.21956 13.5617C7.85915 15.1845 10.2808 15.5615 12.2837 14.6926L17.8206 20.1727H20.6329L20.6329 15.9974L18.1721 15.6495L17.8206 12.518L14.9552 12.2029ZM10.0868 7.64673C10.6692 8.22322 10.6692 9.1579 10.0868 9.73439C9.50432 10.3109 8.55996 10.3109 7.97749 9.73439C7.39503 9.1579 7.39503 8.22322 7.97749 7.64673C8.55996 7.07024 9.50432 7.07024 10.0868 7.64673Z"); //StickyNoteTypes.Add("Help", "M12.5 21C17.4706 21 21.5 16.9706 21.5 12C21.5 7.02944 17.4706 3 12.5 3C7.52944 3 3.5 7.02944 3.5 12C3.5 16.9706 7.52944 21 12.5 21ZM13.0439 13.9512V13.5068C13.0439 12.7891 13.29 12.4062 14.1582 11.8936C15.0332 11.3672 15.5869 10.6084 15.5869 9.54199V9.52832C15.5869 8.12695 14.4111 7.06055 12.6885 7.06055C10.7676 7.06055 9.7832 8.23633 9.70801 9.70605V9.71973L10.8701 9.71289L10.8838 9.70605C10.9521 8.73535 11.6084 8.12695 12.6406 8.12695C13.6592 8.12695 14.3154 8.74902 14.3154 9.58984V9.60352C14.3154 10.3281 14.0078 10.7588 13.2148 11.2441C12.2783 11.8047 11.8408 12.4199 11.8477 13.3223V13.9512H13.0439ZM12.5381 17.123C13.0918 17.123 13.4814 16.7266 13.4814 16.1729C13.4814 15.6123 13.0918 15.2158 12.5381 15.2158C11.9844 15.2158 11.5879 15.6123 11.5879 16.1729C11.5879 16.7266 11.9844 17.123 12.5381 17.123Z"); //StickyNoteTypes.Add("Insert", "M10.25 13C10.5059 13 10.7565 12.9774 11 12.934V19.5H13V6.5H15V19.5H17V6.5H18.5V4.5H17H15H13H11H10.5V4.50723C10.4173 4.50243 10.3339 4.5 10.25 4.5C7.90279 4.5 6 6.40279 6 8.75C6 11.0972 7.90279 13 10.25 13Z"); //StickyNoteTypes.Add("Paragraph", "M12.5 4L19.5 18H5.5L12.5 4Z"); //StickyNoteTypes.Add("NewParagraph", "M19.5 13L12.5 2L5.5 13H19.5ZM7.46177 17.0425V22H5.90952V14.2495H7.26304L10.8402 19.1855H10.9261V14.2495H12.4784V22H11.1356L7.54771 17.0425H7.46177ZM15.5803 19.5562V22H13.9583V14.2495H17.1541C18.7869 14.2495 19.8772 15.3022 19.8772 16.8975V16.9082C19.8772 18.5034 18.7869 19.5562 17.1541 19.5562H15.5803ZM16.7566 18.2886H15.5803V15.5332H16.7566C17.6858 15.5332 18.2336 16.022 18.2336 16.9028V16.9136C18.2336 17.7944 17.6858 18.2886 16.7566 18.2886Z"); StickyNoteTypes.Add("Comment", "M1.66667 4C0.746192 4 0 4.74619 0 5.66667V24.3333C0 25.2538 0.746192 26 1.66667 26H5.3335V30.6095C5.3335 31.2382 6.00309 31.6405 6.55814 31.3453L16.6082 26H30.3333C31.2538 26 32 25.2538 32 24.3333V5.66667C32 4.74619 31.2538 4 30.3333 4H1.66667ZM26 13.2H6V10.8H26V13.2ZM6 19.2H18V16.8H6V19.2Z"); StickyNoteTypes.Add("Note", "M4.80005 1.59998H27.2V22.4H19.2V30.4H4.80005V1.59998ZM20.8 30.4V24H27.2L20.8 30.4ZM24 7.99998V5.59998H8.00005V7.99998H24ZM24 10.4V12.8H8.00005V10.4H24ZM19.2 17.6V15.2H8.00005V17.6H19.2Z"); StickyNoteTypes.Add("Key", "M19.9281 16.3244C21.6141 13.0687 21.0799 8.9772 18.3255 6.25104C14.9084 2.86896 9.36814 2.86896 5.95102 6.25104C2.5339 9.63312 2.5339 15.1166 5.95102 18.4986C8.57435 21.0951 12.449 21.6982 15.6537 20.3081L24.5126 29.0762H29.0124L29.0124 22.3957L25.0751 21.839L24.5126 16.8286L19.9281 16.3244ZM12.1386 9.03461C13.0705 9.95699 13.0705 11.4525 12.1386 12.3749C11.2066 13.2972 9.69565 13.2972 8.76371 12.3749C7.83177 11.4525 7.83177 9.95699 8.76371 9.03461C9.69565 8.11222 11.2066 8.11222 12.1386 9.03461Z"); StickyNoteTypes.Add("Help", "M16.0001 30.4C23.953 30.4 30.4001 23.9529 30.4001 16C30.4001 8.04707 23.953 1.59998 16.0001 1.59998C8.0472 1.59998 1.6001 8.04707 1.6001 16C1.6001 23.9529 8.0472 30.4 16.0001 30.4ZM16.8704 19.1218V18.4109C16.8704 17.2625 17.2642 16.65 18.6532 15.8297C20.0532 14.9875 20.9392 13.7734 20.9392 12.0672V12.0453C20.9392 9.8031 19.0579 8.09685 16.3017 8.09685C13.2282 8.09685 11.6532 9.9781 11.5329 12.3297V12.3515L13.3923 12.3406L13.4142 12.3297C13.5235 10.7765 14.5735 9.8031 16.2251 9.8031C17.8548 9.8031 18.9048 10.7984 18.9048 12.1437V12.1656C18.9048 13.325 18.4126 14.014 17.1438 14.7906C15.6454 15.6875 14.9454 16.6719 14.9563 18.1156V19.1218H16.8704ZM16.061 24.1968C16.947 24.1968 17.5704 23.5625 17.5704 22.6765C17.5704 21.7797 16.947 21.1453 16.061 21.1453C15.1751 21.1453 14.5407 21.7797 14.5407 22.6765C14.5407 23.5625 15.1751 24.1968 16.061 24.1968Z"); StickyNoteTypes.Add("Paragraph", "M16 3.19995L27.2 25.6H4.80005L16 3.19995Z"); StickyNoteTypes.Add("Insert", "M12.8001 4.81162V4.80005H13.6001H16.8001H20.0001H23.2001H25.6001V8.00005H23.2001V28.8H20.0001V8.00005H16.8001V28.8H13.6001V18.2945C13.2106 18.3639 12.8096 18.4 12.4001 18.4C8.64456 18.4 5.6001 15.3556 5.6001 11.6C5.6001 7.84451 8.64456 4.80005 12.4001 4.80005C12.5344 4.80005 12.6677 4.80394 12.8001 4.81162Z"); StickyNoteTypes.Add("NewParagraph", "M27.2 17.6L16 0L4.80005 17.6H27.2ZM7.93888 24.068V32H5.45528V19.5992H7.62091L13.3443 27.4969H13.4818V19.5992H15.9654V32H13.817L8.07638 24.068H7.93888ZM20.9286 28.0898V32H18.3333V19.5992H23.4465C26.059 19.5992 27.8036 21.2836 27.8036 23.8359V23.8531C27.8036 26.4055 26.059 28.0898 23.4465 28.0898H20.9286ZM22.8106 26.0617H20.9286V21.6531H22.8106C24.2973 21.6531 25.1739 22.4352 25.1739 23.8445V23.8617C25.1739 25.2711 24.2973 26.0617 22.8106 26.0617Z"); CommonDrawData.StickyIconDefault = StickyNoteTypes.First().Value; CommonDrawData.StickyIconDict = StickyNoteTypes; } public bool IsNavigationTarget(NavigationContext navigationContext) { return true; } public void OnNavigatedFrom(NavigationContext navigationContext) { IsMultiSelected = false; } public AnnotAttribEvent AnnotEvent { get; set; } private AnnotHandlerEventArgs Annot; private AnnotTransfer PropertyPanel; public void OnNavigatedTo(NavigationContext navigationContext) { navigationContext.Parameters.TryGetValue(ParameterNames.PropertyPanelContentViewModel, out PropertyPanel); if (PropertyPanel != null) { AnnotEvent = PropertyPanel.AnnotEvent; Annot = PropertyPanel.annot; IsMultiSelected = PropertyPanel.IsMultiSelected; AnnotTypeTitle = App.MainPageLoader.GetString("ViewRightMenuBlankSpaceAddComment_StickyNote"); if (IsMultiSelected) { IsAttributeEquals(); } else { GetAnnotProperty(); } } } private List ConvertLists() { List FreeTextLists = new List(); foreach (var item in PropertyPanel.annotlists) { var itemFreeText = item as StickyAnnotArgs; if (itemFreeText != null) { FreeTextLists.Add(itemFreeText); } } if (FreeTextLists.Count != PropertyPanel.annotlists.Count) return null; else return FreeTextLists; } private void IsAttributeEquals() { var list = ConvertLists(); if (list != null) { var temp = list[0]; Dictionary isNoEqualsDir = new Dictionary(); isNoEqualsDir.Add("SharpColor", false); isNoEqualsDir.Add("tag", false); foreach (var item in list) { if (item == list[0]) continue; if (isNoEqualsDir["SharpColor"] == false) { if (temp.Color.A != item.Color.A || temp.Color.R != item.Color.R || temp.Color.G != item.Color.G || temp.Color.B != item.Color.B) { SharpColor = new SolidColorBrush(Color.FromArgb(0x01, 0xff, 0xff, 0xff)); isNoEqualsDir["SharpColor"] = true; } } if (isNoEqualsDir["tag"] == false) { if (temp.IconName != item.IconName) { isNoEqualsDir["tag"] = true; } } } ////以下是多选注释的属性相等时 if (isNoEqualsDir["SharpColor"] == false) { SharpColor = new SolidColorBrush(temp.Color); } if (isNoEqualsDir["tag"] == false) { strOtherTag = temp.IconName; } else { strOtherTag = "None"; } } } private void GetAnnotProperty() { if (Annot is StickyAnnotArgs) { var annot = Annot as StickyAnnotArgs; if (annot != null) { SharpColor = new SolidColorBrush(annot.Color); Transpent = annot.Transparency; strOtherTag = annot.IconName; Trace.WriteLine("annot.IconName" + annot.IconName); } } } } }