123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278 |
- using ComPDFKitViewer;
- using ComPDFKitViewer.PdfViewer;
- using PDF_Master.CustomControl;
- using PDF_Master.Helper;
- using PDF_Master.Model;
- using PDF_Master.Properties;
- using PDF_Master.Views.PropertyPanel.ViewModular;
- using PDFSettings;
- using Prism.Commands;
- using Prism.Mvvm;
- using Prism.Regions;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Documents;
- using System.Windows.Forms;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Shapes;
- using static PDF_Master.CustomControl.ColorDropBox;
- using RadioButton = System.Windows.Controls.RadioButton;
- namespace PDF_Master.ViewModels.PropertyPanel.ViewModular
- {
- public class ThemesContentViewModel : BindableBase, INavigationAware
- {
- public CPDFViewer PDFViewer { get; set; }
- public ViewModularContentViewModel ViewModularContentViewModel { get; set; }
- public Color? SelectedColor { get; set; }
- private bool resedaDrawMode;
- public bool ResedaDrawMode
- {
- get { return resedaDrawMode; }
- set
- {
- SetProperty(ref resedaDrawMode, value);
- if (value)
- {
- SetDrawModeEvent(null);
- }
- }
- }
- private bool darkDrawMode;
- public bool DarkDrawMode
- {
- get { return darkDrawMode; }
- set
- {
- SetProperty(ref darkDrawMode, value);
- if (value)
- {
- SetDrawModeEvent(null);
- }
- }
- }
- private bool sepiaDrawMode;
- public bool SepiaDrawMode
- {
- get { return sepiaDrawMode; }
- set
- {
- SetProperty(ref sepiaDrawMode, value);
- if (value)
- {
- SetDrawModeEvent(null);
- }
- }
- }
- private bool lightDrawMode;
- public bool LightDrawMode
- {
- get { return lightDrawMode; }
- set
- {
- SetProperty(ref lightDrawMode, value);
- if (value)
- {
- SetDrawModeEvent(null);
- }
- }
- }
- public DelegateCommand<object> LoadedCommand { get; set; }
- public DelegateCommand<object> SetDrawModeCommand { get; set; }
- public ThemesContentViewModel()
- {
- LoadedCommand = new DelegateCommand<object>(LoadedEvent);
- SetDrawModeCommand = new DelegateCommand<object>(SetDrawModeEvent);
- }
- private void LoadedEvent(object obj)
- {
- if (obj is WrapPanel wrapPanel)
- {
- InitBeforeShow(wrapPanel);
- }
- }
- /// <summary>
- /// 设置主题颜色
- /// </summary>
- /// <param name="obj"></param>
- private void SetDrawModeEvent(object obj)
- {
- if (PDFViewer == null)
- {
- return;
- }
- SetUpDrawMode(PDFViewer, obj);
- if (ViewModularContentViewModel.SplitScreenPDFViewer != null)
- {
- SetUpDrawMode(ViewModularContentViewModel.SplitScreenPDFViewer, obj);
- }
- }
- private void SetUpDrawMode(CPDFViewer pDFViewer, object obj)
- {
- DrawModes draw = DrawModes.Draw_Mode_Normal;
- UInt32 color = 0;
- if (LightDrawMode)
- {
- draw = DrawModes.Draw_Mode_Normal;
- SetDrawMode(draw, color, pDFViewer);
- }
- else if (SepiaDrawMode)
- {
- draw = DrawModes.Draw_Mode_Soft;
- SetDrawMode(draw, color, pDFViewer);
- }
- else if (ResedaDrawMode)
- {
- draw = DrawModes.Draw_Mode_Green;
- SetDrawMode(draw, color, pDFViewer);
- }
- else if (DarkDrawMode)
- {
- draw = DrawModes.Draw_Mode_Dark;
- SetDrawMode(draw, color, pDFViewer);
- }
- else
- {
- if (obj is RadioButton radioButton)
- {
- draw = SetOtherThemeColors(radioButton, pDFViewer);
- }
- }
- //App.SplitScreenDrawModes = draw;
- }
- private DrawModes SetOtherThemeColors(RadioButton radioButton, CPDFViewer pDFViewer)
- {
- DrawModes draw = DrawModes.Draw_Mode_Normal;
- StackPanel panel = radioButton.Content as StackPanel;
- Rectangle rec = (panel.Children[0] as Border).Child as Rectangle;
- OpenFileInfo file = SettingHelper.GetFileInfo(pDFViewer?.Document.FilePath);
- if (file != null)
- {
- file.LastFillBrushColor = ((SolidColorBrush)rec.Fill).Color;
- }
- var color1 = rec.Fill.ToString().Substring(1, 8);
- UInt32 c = Convert.ToUInt32(color1, 16);
- pDFViewer.SetDrawMode(DrawModes.Draw_Mode_Normal);
- pDFViewer.SetDrawMode(DrawModes.Draw_Mode_Custom, c);
- UpdateFileInfoList(DrawModes.Draw_Mode_Custom, c, pDFViewer);
- draw = DrawModes.Draw_Mode_Custom;
- //App.SplitScreenColor = c;
- return draw;
- }
- private void SetDrawMode(DrawModes drawMode, UInt32 color, CPDFViewer pDFViewer)
- {
- if (pDFViewer.GetDrawMode() != drawMode)
- {
- pDFViewer.SetDrawMode(drawMode);
- UpdateFileInfoList(drawMode, color, pDFViewer);
- }
- }
- /// <summary>
- /// 更新文件信息
- /// </summary>
- /// <param name="modes"></param>
- /// <param name="color"></param>
- private void UpdateFileInfoList(DrawModes modes, UInt32 color, CPDFViewer pDFViewer)
- {
- OpenFileInfo file = SettingHelper.GetFileInfo(pDFViewer?.Document.FilePath);
- if (file != null)
- {
- file.LastDrawMode = modes;
- if (color != 0)
- {
- file.LastFillColor = color;
- }
- }
- SettingHelper.SetFileInfo(file);
- }
- /// <summary>
- /// 初始化后
- /// </summary>
- /// <param name="wrapPanel"></param>
- private void InitBeforeShow(WrapPanel wrapPanel)
- {
- if (PDFViewer == null)
- {
- return;
- }
- var mode = PDFViewer.GetDrawMode();
- if (mode == DrawModes.Draw_Mode_Normal)
- {
- LightDrawMode = true;
- }
- else if (mode == DrawModes.Draw_Mode_Dark)
- {
- DarkDrawMode = true;
- }
- else if (mode == DrawModes.Draw_Mode_Green)
- {
- ResedaDrawMode = true;
- }
- else if (mode == DrawModes.Draw_Mode_Soft)
- {
- SepiaDrawMode = true;
- }
- else
- {
- OpenFileInfo info = SettingHelper.GetFileInfo(PDFViewer.Document.FilePath);
- var color = info.LastFillBrushColor;
- for (int i = 4; i < wrapPanel.Children.Count; i++)
- {
- var btn = wrapPanel.Children[i] as RadioButton;
- if (btn != null && Color.Equals(((SolidColorBrush)(((btn.Content as StackPanel).Children[0] as Border).Child as Rectangle).Fill).Color, color))
- {
- btn.IsChecked = true;
- }
- }
- }
- }
- public bool IsNavigationTarget(NavigationContext navigationContext)
- {
- return true;
- }
- public void OnNavigatedFrom(NavigationContext navigationContext)
- {
- }
- public void OnNavigatedTo(NavigationContext navigationContext)
- {
- if (navigationContext.Parameters[ParameterNames.PDFViewer] is CPDFViewer pdfview)
- {
- PDFViewer = pdfview;
- }
- if (navigationContext.Parameters[ParameterNames.ViewModularContentViewModel] is ViewModularContentViewModel viewModularContentViewModel)
- {
- ViewModularContentViewModel = viewModularContentViewModel;
- }
- }
- }
- }
|