123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266 |
- using ComPDFKitViewer;
- using ComPDFKitViewer.AnnotEvent;
- using PDF_Office.Model;
- using PDF_Office.Model.PropertyPanel.AnnotPanel;
- using PDF_Office.ViewModels.Tools;
- using Prism.Commands;
- using Prism.Mvvm;
- using Prism.Regions;
- using System;
- using System.Collections.Generic;
- using System.Globalization;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Controls;
- using System.Windows.Controls.Primitives;
- using System.Windows.Data;
- using System.Windows.Media;
- namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
- {
- public class EraseThicknessConverter : IValueConverter
- {
- public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
- {
- if (value is double)
- {
- return (double)value * 6;
- }
- return value;
- }
- public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
- {
- throw new NotImplementedException();
- }
- }
- public class FreehandAnnotPropertyViewModel : BindableBase, INavigationAware
- {
- private bool isPen = true;
- public bool IsPen
- {
- get { return isPen; }
- set
- {
- SetProperty(ref isPen, value);
- }
- }
- private Brush selectColor = new SolidColorBrush(Colors.Transparent);
- public Brush SelectColor
- {
- get { return selectColor; }
- set { SetProperty(ref selectColor, value);
- AnnotEvent?.UpdateAttrib(AnnotAttrib.Color, (SelectColor as SolidColorBrush).Color);
- AnnotEvent?.UpdateAnnot();
- }
- }
- private double annotOpacity = 1;
- public double AnnotOpacity
- {
- get { return annotOpacity; }
- set
- {
- SetProperty(ref annotOpacity, value);
- }
- }
- private double thicknessLine = 1;
- public double ThicknessLine
- {
- get { return thicknessLine; }
- set
- {
- SetProperty(ref thicknessLine, value);
- AnnotEvent?.UpdateAttrib(AnnotAttrib.Thickness, thicknessLine);
- AnnotEvent?.UpdateAnnot();
- }
- }
- private double erasethicknessLine = 1;
- public double EraseThicknessLine
- {
- get { return erasethicknessLine; }
- set
- {
- SetProperty(ref erasethicknessLine, value);
- AnnotEvent?.UpdateAttrib(AnnotAttrib.Thickness, erasethicknessLine);
- AnnotEvent?.UpdateAnnot();
- }
- }
-
- public AnnotAttribEvent AnnotEvent { get; set; }
- private AnnotHandlerEventArgs Annot;
- private AnnotPropertyPanel PropertyPanel;
- public DelegateCommand<object> EraseCommand { get; set; }
- public DelegateCommand<object> PenCommand { get; set; }
- public DelegateCommand<object> SelectedColorChangedCommand { get; set; }
- public DelegateCommand<object> SelectedValueChangedCommand { get; set; }
- public DelegateCommand<object> SelectPenThickChangedCommand { get; set; }
- public DelegateCommand<object> SetEraserThickCommand { get; set; }
-
- public FreehandAnnotPropertyViewModel()
- {
- EraseCommand = new DelegateCommand<object>(Erase_Command);
- PenCommand = new DelegateCommand<object>(Pen_Command);
- SelectedColorChangedCommand = new DelegateCommand<object>(SelectedColorChanged_Click);
- SelectedValueChangedCommand = new DelegateCommand<object>(SelectedValueChanged_Command);
- SelectPenThickChangedCommand = new DelegateCommand<object>(SelectPenThickChanged_Command);
- SetEraserThickCommand = new DelegateCommand<object>(SelectEraserThickChanged_Command);
- InitVariable();
- }
- private void InitVariable()
- {
- }
- private void SelectEraserThickChanged_Command(object obj)
- {
- if (obj != null)
- {
- var item = (ComboBoxItem)obj;
- var content = (string)item.Content;
- if (content != null)
- {
- var intData = double.Parse(content);
- AnnotEvent?.UpdateAttrib(AnnotAttrib.Thickness, intData);
- AnnotEvent?.UpdateAnnot();
- EraseThicknessLine = intData;
- }
- }
- }
- private void SelectPenThickChanged_Command(object obj)
- {
- if (obj != null)
- {
- var item = (ComboBoxItem)obj;
- var content = (string)item.Content;
- if (content != null)
- {
- var intData = double.Parse(content);
- AnnotEvent?.UpdateAttrib(AnnotAttrib.Thickness, intData);
- AnnotEvent?.UpdateAnnot();
- ThicknessLine = intData;
- }
- }
- }
- private void SelectedValueChanged_Command(object obj)
- {
- if (obj != null)
- {
- annotOpacity = (double)obj;
- SelectColor.Opacity = annotOpacity;
- AnnotEvent?.UpdateAttrib(AnnotAttrib.Transparency, annotOpacity);
- AnnotEvent?.UpdateAnnot();
- Dictionary<AnnotArgsType, object> changeData = new Dictionary<AnnotArgsType, object>();
- changeData[AnnotArgsType.AnnotFreehand] = annotOpacity;
- PropertyPanel.DataChangedInvoke(this, changeData);
- }
- }
- private void SelectedColorChanged_Click(object obj)
- {
- if (obj != null)
- {
- var colorValue = (Color)obj;
- if (colorValue != null)
- {
- SelectColor = new SolidColorBrush(colorValue);
- SelectColor.Opacity = AnnotOpacity;
- Dictionary<AnnotArgsType, object> changeData = new Dictionary<AnnotArgsType, object>();
- changeData[AnnotArgsType.AnnotFreehand] = obj;
- PropertyPanel.DataChangedInvoke(this, changeData);
- }
- }
- }
- private void Erase_Command(object obj)
- {
- var btn = obj as ToggleButton;
- if(btn.IsChecked == true)
- {
- Dictionary<AnnotArgsType, object> changeData = new Dictionary<AnnotArgsType, object>();
- changeData[AnnotArgsType.AnnotErase] = btn;
- PropertyPanel.DataChangedInvoke(this, changeData);
- IsPen = false;
- }
- }
- private void Pen_Command(object obj)
- {
- var btn = obj as ToggleButton;
- if (btn.IsChecked == true)
- {
- Dictionary<AnnotArgsType, object> changeData = new Dictionary<AnnotArgsType, object>();
- changeData[AnnotArgsType.AnnotErase] = btn;
- PropertyPanel.DataChangedInvoke(this, changeData);
- IsPen = true;
- }
- }
- public bool IsNavigationTarget(NavigationContext navigationContext)
- {
- return true;
- }
- public void OnNavigatedFrom(NavigationContext navigationContext)
- {
- }
- public void OnNavigatedTo(NavigationContext navigationContext)
- {
- navigationContext.Parameters.TryGetValue<AnnotPropertyPanel>(ParameterNames.PropertyPanelContentViewModel, out PropertyPanel);
- if (PropertyPanel != null)
- {
- AnnotEvent = PropertyPanel.AnnotEvent;
- Annot = PropertyPanel.annot;
- GetAnnotProperty();
- }
- }
- private void GetAnnotProperty()
- {
- if (Annot is FreehandAnnotArgs)
- {
- var annot = Annot as FreehandAnnotArgs;
- if (annot != null)
- {
- AnnotOpacity = annot.Transparency;
- SelectColor = new SolidColorBrush(annot.InkColor);
- ThicknessLine = annot.LineWidth;
- IsPen = true;
- }
- }
- if (Annot is EraseArgs)
- {
- var annot = Annot as EraseArgs;
- if (annot != null)
- {
- EraseThicknessLine = annot.Thickness;
- IsPen = false;
- }
- }
- }
- }
- }
|