ThemesContent.xaml.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. using ComPDFKitViewer;
  2. using ComPDFKitViewer.PdfViewer;
  3. using Microsoft.Office.Interop.PowerPoint;
  4. using PDF_Master.CustomControl;
  5. using PDF_Master.Helper;
  6. using PDF_Master.Properties;
  7. using PDF_Master.ViewModels.PropertyPanel.ViewModular;
  8. using PDFSettings;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. using System.Windows;
  15. using System.Windows.Controls;
  16. using System.Windows.Data;
  17. using System.Windows.Documents;
  18. using System.Windows.Input;
  19. using System.Windows.Media;
  20. using System.Windows.Media.Imaging;
  21. using System.Windows.Navigation;
  22. using System.Windows.Shapes;
  23. using static PDF_Master.CustomControl.ColorDropBox;
  24. namespace PDF_Master.Views.PropertyPanel.ViewModular
  25. {
  26. /// <summary>
  27. /// ThemesContent.xaml 的交互逻辑
  28. /// </summary>
  29. public partial class ThemesContent : UserControl
  30. {
  31. private ThemesContentViewModel viewModel = null;
  32. private ColorDropBoxPop colorPop = new ColorDropBoxPop();
  33. private AdornerLayer popLayer;
  34. private AdornerPresenter layerPresent;
  35. private Canvas popCanvas;
  36. public Color? SelectedColor { get; set; }
  37. public ThemesContent()
  38. {
  39. InitializeComponent();
  40. InitBeforeShow();
  41. }
  42. /// <summary>
  43. /// 设置自定义主题显示状态
  44. /// </summary>
  45. public void InitBeforeShow()
  46. {
  47. if (Settings.Default.AppProperties.CustomColorList != null && Settings.Default.AppProperties.CustomColorList.Count > 0)
  48. {
  49. var list = Settings.Default.AppProperties.CustomColorList;
  50. switch (list.Count)
  51. {
  52. case 1:
  53. (((RBtnThemes1.Content as StackPanel).Children[0] as Border).Child as Rectangle).Fill = new SolidColorBrush(list[0]);
  54. RBtnThemes1.Visibility = Visibility.Visible;
  55. break;
  56. case 2:
  57. (((RBtnThemes1.Content as StackPanel).Children[0] as Border).Child as Rectangle).Fill = new SolidColorBrush(list[0]);
  58. (((RBtnThemes2.Content as StackPanel).Children[0] as Border).Child as Rectangle).Fill = new SolidColorBrush(list[1]);
  59. RBtnThemes1.Visibility = Visibility.Visible;
  60. RBtnThemes2.Visibility = Visibility.Visible;
  61. break;
  62. case 3:
  63. (((RBtnThemes1.Content as StackPanel).Children[0] as Border).Child as Rectangle).Fill = new SolidColorBrush(list[0]);
  64. (((RBtnThemes2.Content as StackPanel).Children[0] as Border).Child as Rectangle).Fill = new SolidColorBrush(list[1]);
  65. (((RBtnThemes3.Content as StackPanel).Children[0] as Border).Child as Rectangle).Fill = new SolidColorBrush(list[2]);
  66. RBtnThemes1.Visibility = Visibility.Visible;
  67. RBtnThemes2.Visibility = Visibility.Visible;
  68. RBtnThemes3.Visibility = Visibility.Visible;
  69. break;
  70. case 4:
  71. (((RBtnThemes1.Content as StackPanel).Children[0] as Border).Child as Rectangle).Fill = new SolidColorBrush(list[0]);
  72. (((RBtnThemes2.Content as StackPanel).Children[0] as Border).Child as Rectangle).Fill = new SolidColorBrush(list[1]);
  73. (((RBtnThemes3.Content as StackPanel).Children[0] as Border).Child as Rectangle).Fill = new SolidColorBrush(list[2]);
  74. (((RBtnThemes4.Content as StackPanel).Children[0] as Border).Child as Rectangle).Fill = new SolidColorBrush(list[3]);
  75. RBtnThemes1.Visibility = Visibility.Visible;
  76. RBtnThemes2.Visibility = Visibility.Visible;
  77. RBtnThemes3.Visibility = Visibility.Visible;
  78. RBtnThemes4.Visibility = Visibility.Visible;
  79. break;
  80. }
  81. }
  82. }
  83. /// <summary>
  84. /// 页面加载
  85. /// </summary>
  86. /// <param name="sender"></param>
  87. /// <param name="e"></param>
  88. private void UserControl_Loaded(object sender, RoutedEventArgs e)
  89. {
  90. if (popLayer == null)
  91. {
  92. Window parentWnd = Window.GetWindow(this);
  93. if (parentWnd != null && parentWnd.Content is UIElement)
  94. {
  95. popLayer = AdornerLayer.GetAdornerLayer(parentWnd.Content as UIElement);
  96. if (popLayer != null && colorPop != null)
  97. {
  98. layerPresent = new AdornerPresenter(popLayer);
  99. popLayer.Add(layerPresent);
  100. colorPop.Visibility = Visibility.Collapsed;
  101. colorPop.ColorSelected += ColorPop_ColorSelected;
  102. popCanvas = new Canvas();
  103. popCanvas.Children.Add(colorPop);
  104. layerPresent.VisualContent = popCanvas;
  105. parentWnd.AddHandler(MouseDownEvent, new MouseButtonEventHandler((eventsender, param) =>
  106. {
  107. colorPop.Visibility = Visibility.Collapsed;
  108. }), false);
  109. }
  110. }
  111. }
  112. viewModel = (ThemesContentViewModel)this.DataContext;
  113. }
  114. /// <summary>
  115. /// 自定义主题颜色,选择
  116. /// </summary>
  117. /// <param name="sender"></param>
  118. /// <param name="e"></param>
  119. private void ColorPop_ColorSelected(object sender, Color e)
  120. {
  121. if (RBtnThemes1.Visibility == Visibility.Collapsed)
  122. {
  123. RBtnThemes1.Visibility = Visibility.Visible;
  124. var panel = RBtnThemes1.Content as StackPanel;
  125. var rec = (panel.Children[0] as Border).Child as Rectangle;
  126. rec.Fill = new SolidColorBrush(e);
  127. Settings.Default.AppProperties.CustomColorList.Add(e);
  128. }
  129. else if (RBtnThemes2.Visibility == Visibility.Collapsed)
  130. {
  131. RBtnThemes2.Visibility = Visibility.Visible;
  132. var panel = RBtnThemes2.Content as StackPanel;
  133. var rec = (panel.Children[0] as Border).Child as Rectangle;
  134. rec.Fill = new SolidColorBrush(e);
  135. Settings.Default.AppProperties.CustomColorList.Add(e);
  136. }
  137. else if (RBtnThemes3.Visibility == Visibility.Collapsed)
  138. {
  139. RBtnThemes3.Visibility = Visibility.Visible;
  140. var panel = RBtnThemes3.Content as StackPanel;
  141. var rec = (panel.Children[0] as Border).Child as Rectangle;
  142. rec.Fill = new SolidColorBrush(e);
  143. Settings.Default.AppProperties.CustomColorList.Add(e);
  144. }
  145. else if (RBtnThemes4.Visibility == Visibility.Collapsed)
  146. {
  147. RBtnThemes4.Visibility = Visibility.Visible;
  148. var panel = RBtnThemes4.Content as StackPanel;
  149. var rec = (panel.Children[0] as Border).Child as Rectangle;
  150. rec.Fill = new SolidColorBrush(e);
  151. Settings.Default.AppProperties.CustomColorList.Add(e);
  152. }
  153. #region to do
  154. //if(Settings.Default.AppProperties.CustomColorList.Count>4)
  155. //{
  156. // for(int i=4;i< Settings.Default.AppProperties.CustomColorList.Count;i++)
  157. // {
  158. // Settings.Default.AppProperties.CustomColorList.RemoveAt(i);
  159. // }
  160. //}
  161. #endregion to do
  162. Settings.Default.Save();
  163. if (SelectedColor != e)
  164. {
  165. SelectedColor = e;
  166. colorPop.AddColorToRecent(e);
  167. }
  168. }
  169. /// <summary>
  170. /// 自定义颜色显示状态发生变化时
  171. /// </summary>
  172. /// <param name="sender"></param>
  173. /// <param name="e"></param>
  174. private void RBtnThemes1_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
  175. {
  176. if (RBtnThemes1.Visibility == Visibility.Visible &&
  177. RBtnThemes2.Visibility == Visibility.Visible &&
  178. RBtnThemes3.Visibility == Visibility.Visible &&
  179. RBtnThemes4.Visibility == Visibility.Visible)
  180. {
  181. RBtnCustom.Visibility = Visibility.Collapsed;
  182. }
  183. else
  184. {
  185. RBtnCustom.Visibility = Visibility.Visible;
  186. }
  187. }
  188. /// <summary>
  189. /// 添加自定义主题颜色
  190. /// </summary>
  191. /// <param name="sender"></param>
  192. /// <param name="e"></param>
  193. private void RBtnCustom_Click(object sender, RoutedEventArgs e)
  194. {
  195. if (colorPop != null)
  196. {
  197. if (colorPop.Visibility == Visibility.Visible)
  198. {
  199. colorPop.Visibility = Visibility.Collapsed;
  200. return;
  201. }
  202. colorPop.Visibility = Visibility.Visible;
  203. System.Windows.Point offset = GetOffsetToWindow();
  204. Window parentWnd = Window.GetWindow(this);
  205. colorPop.Measure(new Size(parentWnd.ActualWidth, parentWnd.ActualHeight));
  206. colorPop.SetValue(Canvas.TopProperty, offset.Y - colorPop.DesiredSize.Height / 4);
  207. if (offset.X + colorPop.DesiredSize.Width + SystemParameters.ResizeFrameVerticalBorderWidth * 2 > parentWnd.ActualWidth)
  208. {
  209. colorPop.SetValue(Canvas.LeftProperty, parentWnd.ActualWidth - colorPop.DesiredSize.Width - 5 - SystemParameters.ResizeFrameVerticalBorderWidth * 2);
  210. }
  211. else
  212. {
  213. colorPop.SetValue(Canvas.LeftProperty, offset.X - colorPop.DesiredSize.Width / 2 - 30);
  214. }
  215. colorPop.AddColorToRecent((Color)ColorConverter.ConvertFromString("White")); ;
  216. }
  217. }
  218. public System.Windows.Point GetOffsetToWindow()
  219. {
  220. Window parentWnd = Window.GetWindow(this);
  221. return TransformToAncestor(parentWnd).Transform(new System.Windows.Point(0, 0));
  222. }
  223. /// <summary>
  224. /// 删除自定义颜色
  225. /// </summary>
  226. /// <param name="sender"></param>
  227. /// <param name="e"></param>
  228. private void MenuItem_Click(object sender, RoutedEventArgs e)
  229. {
  230. var contextmenu = (sender as MenuItem).Parent as ContextMenu;
  231. if (contextmenu != null)
  232. {
  233. RadioButton btn = contextmenu.PlacementTarget as RadioButton;
  234. btn.Visibility = Visibility.Collapsed;
  235. if (btn.IsChecked == true)
  236. {
  237. //如果删除了选中色 则更换主题为白色
  238. RBtnLight.IsChecked = true;
  239. }
  240. var color = (((btn.Content as StackPanel).Children[0] as Border).Child as Rectangle).Fill;
  241. if (Settings.Default.AppProperties.CustomColorList.Contains(((SolidColorBrush)color).Color))
  242. {
  243. Settings.Default.AppProperties.CustomColorList.Remove(((SolidColorBrush)color).Color);
  244. Settings.Default.Save();
  245. }
  246. }
  247. }
  248. private void RBtnDark_Click(object sender, RoutedEventArgs e)
  249. {
  250. if (Window.GetWindow(this) is MainWindow window)
  251. {
  252. if (window.TabablzControl.SelectedItem is MainContent main)
  253. {
  254. if (main.ContentMain.Content is ViewContent viewContent)
  255. {
  256. foreach (var item in viewContent.GridViewer.Children)
  257. {
  258. if (item is ContentControl control)
  259. {
  260. if (control.Content is SplitScreenContent splitScreenContent)
  261. {
  262. if (splitScreenContent.PDFViewerContent.Content != null)
  263. {
  264. viewModel.ViewModularContentViewModel.SplitScreenPDFViewer = (ComPDFKitViewer.PdfViewer.CPDFViewer)splitScreenContent.PDFViewerContent.Content;
  265. break;
  266. }
  267. }
  268. }
  269. }
  270. }
  271. }
  272. }
  273. viewModel.SetDrawModeCommand.Execute(sender);
  274. }
  275. }
  276. }