123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290 |
- using ComPDFKitViewer;
- using ComPDFKitViewer.AnnotEvent;
- using PDF_Office.CustomControl.CompositeControl;
- using PDF_Office.Model;
- using PDF_Office.Model.AnnotPanel;
- using PDF_Office.ViewModels.Tools;
- using PDFSettings;
- using Prism.Commands;
- using Prism.Mvvm;
- using Prism.Regions;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Media;
- namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
- {
- public class StickyNotePropertyViewModel : BindableBase, INavigationAware
- {
- //外部UI引用
- public string strOtherTag { get; private set; }
- 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;
- 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<ColorItem> _colorItems = new List<ColorItem>();
- public List<ColorItem> ColorItems
- {
- get { return _colorItems; }
- set => SetProperty(ref _colorItems, value);
- }
- Dictionary<string, string> StickyNoteTypes = new Dictionary<string, string>();
- public event EventHandler<object> LoadPropertyHandler;
- public DelegateCommand<object> SelectedColorChangedCommand { get; set; }
- public DelegateCommand<object> SelectedValueChangedCommand { get; set; }
- public DelegateCommand<object> StrickyNoteShapeCommand { get; set; }
- public DelegateCommand<object> SelectedOpacityValueCommand { get; set; }
-
- public StickyNotePropertyViewModel()
- {
- SelectedValueChangedCommand = new DelegateCommand<object>(SelectedValueChanged_Command);
- SelectedColorChangedCommand = new DelegateCommand<object>(SelectedColorChanged_Click);
- StrickyNoteShapeCommand = new DelegateCommand<object>(StrickyNoteShape);
- SelectedOpacityValueCommand = new DelegateCommand<object>(SelectedOpacityValue);
- InitStickyNoteTypes();
- InitColorItems();
- var data = StickyNoteTypes["Comment"];
- var converter = TypeDescriptor.GetConverter(typeof(Geometry));
- ExmpleData = (Geometry)converter.ConvertFrom(data);
- }
- 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);
- }
- }
- 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");
- 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 AnnotPropertyPanel PropertyPanel;
- public void OnNavigatedTo(NavigationContext navigationContext)
- {
- navigationContext.Parameters.TryGetValue<AnnotPropertyPanel>(ParameterNames.PropertyPanelContentViewModel, out PropertyPanel);
- if (PropertyPanel != null)
- {
- AnnotEvent = PropertyPanel.AnnotEvent;
- Annot = PropertyPanel.annot;
- IsMultiSelected = PropertyPanel.IsMultiSelected;
- AnnotTypeTitle = "便签";
- if (IsMultiSelected)
- {
- IsAttributeEquals();
- }
- else
- {
- GetAnnotProperty();
- }
- }
- }
- private List<StickyAnnotArgs> ConvertLists()
- {
- List<StickyAnnotArgs> FreeTextLists = new List<StickyAnnotArgs>();
- 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<string, bool> isNoEqualsDir = new Dictionary<string, bool>();
- 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(Colors.Transparent);
- 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;
-
- }
-
- }
-
- }
- }
- }
|