fix #70, #126: switch between Light and Dark background

This commit is contained in:
Paddy Xu
2018-06-02 16:34:10 +03:00
parent d36da88f31
commit 3f1b943876
3 changed files with 58 additions and 12 deletions

View File

@@ -33,6 +33,7 @@ using System.Windows.Threading;
using QuickLook.Common.Annotations;
using QuickLook.Common.ExtensionMethods;
using QuickLook.Common.Helpers;
using QuickLook.Common.Plugin;
using QuickLook.Plugin.ImageViewer.Exiv2;
namespace QuickLook.Plugin.ImageViewer
@@ -42,6 +43,7 @@ namespace QuickLook.Plugin.ImageViewer
/// </summary>
public partial class ImagePanel : UserControl, INotifyPropertyChanged, IDisposable
{
private readonly ContextObject _context;
private Visibility _backgroundVisibility = Visibility.Visible;
private Point? _dragInitPos;
private Uri _imageSource;
@@ -70,10 +72,7 @@ namespace QuickLook.Plugin.ImageViewer
? Visibility.Visible
: Visibility.Collapsed;
var scale = DpiHelper.GetCurrentScaleFactor();
backgroundBrush.Viewport = new Rect(new Size(
backgroundBrush.ImageSource.Width / scale.Horizontal,
backgroundBrush.ImageSource.Height / scale.Vertical));
buttonBackgroundColour.Click += OnBackgroundColourOnClick;
SizeChanged += ImagePanel_SizeChanged;
@@ -86,11 +85,13 @@ namespace QuickLook.Plugin.ImageViewer
viewPanel.ManipulationDelta += ViewPanel_ManipulationDelta;
}
internal ImagePanel(Meta meta) : this()
internal ImagePanel(ContextObject context, Meta meta) : this()
{
_context = context;
Meta = meta;
ShowMeta();
Theme = _context.Theme;
}
public bool ShowZoomLevelInfo
@@ -104,6 +105,16 @@ namespace QuickLook.Plugin.ImageViewer
}
}
public Themes Theme
{
get => _context?.Theme ?? Themes.Dark;
set
{
_context.Theme = value;
OnPropertyChanged();
}
}
public BitmapScalingMode RenderMode
{
get => _renderMode;
@@ -235,6 +246,13 @@ namespace QuickLook.Plugin.ImageViewer
public event PropertyChangedEventHandler PropertyChanged;
private void OnBackgroundColourOnClick(object sender, RoutedEventArgs e)
{
Theme = Theme == Themes.Dark ? Themes.Light : Themes.Dark;
SettingHelper.Set("LastTheme", (int) Theme);
}
private void ShowMeta()
{
textMeta.Inlines.Clear();