From: sr55 Date: Thu, 25 Apr 2019 14:28:54 +0000 (+0100) Subject: WinGui: Refactor Filters View Model - (Deblock) X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0937a200e89bda04cbd6b7b231462be8b4701155;p=handbrake WinGui: Refactor Filters View Model - (Deblock) --- diff --git a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj index e85382f0e..9caf1ab38 100644 --- a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj +++ b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj @@ -272,6 +272,7 @@ + diff --git a/win/CS/HandBrakeWPF/ViewModelItems/Filters/DeblockFilter.cs b/win/CS/HandBrakeWPF/ViewModelItems/Filters/DeblockFilter.cs new file mode 100644 index 000000000..09b785e3b --- /dev/null +++ b/win/CS/HandBrakeWPF/ViewModelItems/Filters/DeblockFilter.cs @@ -0,0 +1,90 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// +// +// Defines the DeblockFilter type. +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace HandBrakeWPF.ViewModelItems.Filters +{ + using System.Globalization; + + using Caliburn.Micro; + + using HandBrakeWPF.Services.Encode.Model; + using HandBrakeWPF.Services.Presets.Model; + using HandBrakeWPF.Services.Scan.Model; + + using Action = System.Action; + + public class DeblockFilter : PropertyChangedBase + { + private readonly Action triggerTabChanged; + + public DeblockFilter(EncodeTask currentTask, Action triggerTabChanged) + { + this.triggerTabChanged = triggerTabChanged; + this.CurrentTask = currentTask; + this.DeblockValue = 4; // OFF + } + + public EncodeTask CurrentTask { get; private set; } + + public string DeblockText => + this.DeblockValue == 4 ? "Off" : this.DeblockValue.ToString(CultureInfo.InvariantCulture); + + public int DeblockValue + { + get + { + return this.CurrentTask.Deblock; + } + + set + { + this.CurrentTask.Deblock = value; + this.NotifyOfPropertyChange(() => this.DeblockValue); + this.NotifyOfPropertyChange(() => this.DeblockText); + this.triggerTabChanged(); + } + } + + public void SetPreset(Preset preset, EncodeTask task) + { + this.CurrentTask = task; + + if (preset == null) + { + this.DeblockValue = 4; // OFF + return; + } + + this.DeblockValue = preset.Task.Deblock == 0 ? 4 : preset.Task.Deblock; + } + + public void UpdateTask(EncodeTask task) + { + this.CurrentTask = task; + this.NotifyOfPropertyChange(() => this.DeblockValue); + } + + public bool MatchesPreset(Preset preset) + { + int presetDeblock = preset.Task.Deblock == 0 ? 4 : preset.Task.Deblock; + + if (presetDeblock != this.DeblockValue) + { + return false; + } + + return true; + } + + public void SetSource(Source source, Title title, Preset preset, EncodeTask task) + { + this.CurrentTask = task; + } + } +} diff --git a/win/CS/HandBrakeWPF/ViewModels/FiltersViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/FiltersViewModel.cs index 50d4a2d1f..4ee14632a 100644 --- a/win/CS/HandBrakeWPF/ViewModels/FiltersViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/FiltersViewModel.cs @@ -41,24 +41,15 @@ namespace HandBrakeWPF.ViewModels { #region Constructors and Destructors - /// - /// Initializes a new instance of the class. - /// - /// - /// The window manager. - /// - /// - /// The user Setting Service. - /// public FiltersViewModel(IWindowManager windowManager, IUserSettingService userSettingService) { this.CurrentTask = new EncodeTask(); - this.DeblockValue = 4; // OFF this.SharpenFilter = new SharpenItem(this.CurrentTask, () => this.OnTabStatusChanged(null)); this.DenoiseFilter = new DenoiseItem(this.CurrentTask, () => this.OnTabStatusChanged(null)); this.DetelecineFilter = new DetelecineItem(this.CurrentTask, () => this.OnTabStatusChanged(null)); this.DeinterlaceFilter = new DeinterlaceFilterItem(this.CurrentTask, () => this.OnTabStatusChanged(null)); + this.DeblockFilter = new DeblockFilter(this.CurrentTask, () => this.OnTabStatusChanged(null)); } #endregion @@ -67,44 +58,8 @@ namespace HandBrakeWPF.ViewModels #region Properties - /// - /// Gets CurrentTask. - /// public EncodeTask CurrentTask { get; private set; } - /// - /// Gets DeblockText. - /// - public string DeblockText - { - get - { - return this.DeblockValue == 4 ? "Off" : this.DeblockValue.ToString(CultureInfo.InvariantCulture); - } - } - - /// - /// Gets or sets DeblockValue. - /// - public int DeblockValue - { - get - { - return this.CurrentTask.Deblock; - } - - set - { - this.CurrentTask.Deblock = value; - this.NotifyOfPropertyChange(() => this.DeblockValue); - this.NotifyOfPropertyChange(() => this.DeblockText); - this.OnTabStatusChanged(null); - } - } - - /// - /// Gets or sets a value indicating whether Grayscale. - /// public bool Grayscale { get @@ -120,7 +75,6 @@ namespace HandBrakeWPF.ViewModels } } - public DenoiseItem DenoiseFilter { get; set; } public SharpenItem SharpenFilter { get; set; } @@ -129,14 +83,12 @@ namespace HandBrakeWPF.ViewModels public DeinterlaceFilterItem DeinterlaceFilter { get; set; } - /// - /// The rotation options. - /// + public DeblockFilter DeblockFilter { get; set; } + + + public BindingList RotationOptions => new BindingList { 0, 90, 180, 270 }; - /// - /// Selected Rotation. - /// public int SelectedRotation { get @@ -152,9 +104,6 @@ namespace HandBrakeWPF.ViewModels } } - /// - /// Flip the Video - /// public bool FlipVideo { get @@ -170,20 +119,8 @@ namespace HandBrakeWPF.ViewModels } } - #endregion - #region Implemented Interfaces - - /// - /// Setup this tab for the specified preset. - /// - /// - /// The preset. - /// - /// - /// The task. - /// public void SetPreset(Preset preset, EncodeTask task) { this.CurrentTask = task; @@ -191,15 +128,13 @@ namespace HandBrakeWPF.ViewModels if (preset != null) { // Properties - - this.Grayscale = preset.Task.Grayscale; - this.DeblockValue = preset.Task.Deblock == 0 ? 4 : preset.Task.Deblock; - + this.SharpenFilter.SetPreset(preset, task); this.DenoiseFilter.SetPreset(preset, task); this.DetelecineFilter.SetPreset(preset, task); this.DeinterlaceFilter.SetPreset(preset, task); + this.DeblockFilter.SetPreset(preset, task); this.SelectedRotation = preset.Task.Rotation; this.FlipVideo = preset.Task.FlipVideo; @@ -208,25 +143,16 @@ namespace HandBrakeWPF.ViewModels { // Default everything to off this.Grayscale = false; - this.DeblockValue = 0; this.SelectedRotation = 0; this.FlipVideo = false; } } - /// - /// Update all the UI controls based on the encode task passed in. - /// - /// - /// The task. - /// public void UpdateTask(EncodeTask task) { this.CurrentTask = task; this.NotifyOfPropertyChange(() => this.Grayscale); - this.NotifyOfPropertyChange(() => this.DeblockValue); - this.NotifyOfPropertyChange(() => this.FlipVideo); this.NotifyOfPropertyChange(() => this.SelectedRotation); @@ -235,6 +161,7 @@ namespace HandBrakeWPF.ViewModels this.DenoiseFilter.UpdateTask(task); this.DetelecineFilter.UpdateTask(task); this.DeinterlaceFilter.UpdateTask(task); + this.DeblockFilter.UpdateTask(task); } public bool MatchesPreset(Preset preset) @@ -259,9 +186,7 @@ namespace HandBrakeWPF.ViewModels return false; } - int presetDeblock = preset.Task.Deblock == 0 ? 4 : preset.Task.Deblock; - - if (presetDeblock != this.DeblockValue) + if (!this.DeblockFilter.MatchesPreset(preset)) { return false; } @@ -284,21 +209,6 @@ namespace HandBrakeWPF.ViewModels return true; } - /// - /// Setup this window for a new source - /// - /// - /// The source. - /// - /// - /// The title. - /// - /// - /// The preset. - /// - /// - /// The task. - /// public void SetSource(Source source, Title title, Preset preset, EncodeTask task) { this.CurrentTask = task; @@ -306,15 +216,12 @@ namespace HandBrakeWPF.ViewModels this.DenoiseFilter.SetSource(source, title, preset, task); this.DetelecineFilter.SetSource(source, title, preset, task); this.DeinterlaceFilter.SetSource(source, title, preset, task); + this.DeblockFilter.SetSource(source, title, preset, task); } - #endregion - - #region Private Methods protected virtual void OnTabStatusChanged(TabStatusEventArgs e) { this.TabStatusChanged?.Invoke(this, e); } - #endregion } } \ No newline at end of file diff --git a/win/CS/HandBrakeWPF/Views/FiltersView.xaml b/win/CS/HandBrakeWPF/Views/FiltersView.xaml index a311900eb..2030c5fae 100644 --- a/win/CS/HandBrakeWPF/Views/FiltersView.xaml +++ b/win/CS/HandBrakeWPF/Views/FiltersView.xaml @@ -172,10 +172,10 @@ - - +