123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316 |
- 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
- {
-
- public string strOtherTag { get; private set; }
- 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<ColorItem> _colorItems = new List<ColorItem>();
- public List<ColorItem> ColorItems
- {
- get { return _colorItems; }
- set => SetProperty(ref _colorItems, value);
- }
- public 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; }
- private IEventAggregator eventAggregator;
- public string Unicode = "";
- public StickyNotePropertyViewModel(IEventAggregator eventAggregator)
- {
- this.eventAggregator = eventAggregator;
- Unicode = App.mainWindowViewModel.SelectedItem.Unicode;
- 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);
- eventAggregator.GetEvent<StickyNoteColorEvent>().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<StickyNotePopupColorEvent>().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.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<AnnotTransfer>(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<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(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);
- }
- }
- }
- }
- }
|