From 6ae63f3795c77c726f0d3ecebdc60b5d883f2e88 Mon Sep 17 00:00:00 2001 From: sr55 Date: Thu, 25 Apr 2019 14:34:58 +0100 Subject: WinGui: Refactor Filters View Model - (Denoise Filter) --- win/CS/HandBrakeWPF/HandBrakeWPF.csproj | 1 + .../ViewModelItems/Filters/DenoiseItem.cs | 178 +++++++++++++++++++++ .../ViewModelItems/Filters/SharpenItem.cs | 7 + win/CS/HandBrakeWPF/ViewModels/FiltersViewModel.cs | 152 ++---------------- win/CS/HandBrakeWPF/Views/FiltersView.xaml | 22 +-- 5 files changed, 206 insertions(+), 154 deletions(-) create mode 100644 win/CS/HandBrakeWPF/ViewModelItems/Filters/DenoiseItem.cs (limited to 'win/CS') diff --git a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj index c813a6e92..fb40aa871 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/DenoiseItem.cs b/win/CS/HandBrakeWPF/ViewModelItems/Filters/DenoiseItem.cs new file mode 100644 index 000000000..7c7562b16 --- /dev/null +++ b/win/CS/HandBrakeWPF/ViewModelItems/Filters/DenoiseItem.cs @@ -0,0 +1,178 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// +// +// Defines the DenoiseItem type. +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace HandBrakeWPF.ViewModelItems.Filters +{ + using System.Collections.Generic; + + using Caliburn.Micro; + + using HandBrake.Interop.Interop.Model.Encoding; + + using HandBrakeWPF.Services.Encode.Model; + using HandBrakeWPF.Services.Encode.Model.Models; + using HandBrakeWPF.Services.Presets.Model; + using HandBrakeWPF.Services.Scan.Model; + using HandBrakeWPF.Utilities; + + using Action = System.Action; + + public class DenoiseItem : PropertyChangedBase + { + private readonly Action triggerTabChanged; + + public DenoiseItem(EncodeTask currentTask, Action triggerTabChanged) + { + this.triggerTabChanged = triggerTabChanged; + this.CurrentTask = currentTask; + } + + public EncodeTask CurrentTask { get; private set; } + + public Denoise SelectedDenoise + { + get + { + return this.CurrentTask.Denoise; + } + + set + { + this.CurrentTask.Denoise = value; + this.NotifyOfPropertyChange(() => this.SelectedDenoise); + + // Show / Hide the Custom Control + this.NotifyOfPropertyChange(() => this.ShowDenoiseCustom); + + this.SelectedDenoisePreset = this.CurrentTask.Denoise == Denoise.hqdn3d ? DenoisePreset.Weak : DenoisePreset.Ultralight; // Default so we don't have an invalid preset. + + this.NotifyOfPropertyChange(() => this.ShowDenoiseOptions); + this.NotifyOfPropertyChange(() => this.ShowDenoiseTune); + this.triggerTabChanged(); + } + } + + public DenoiseTune SelectedDenoiseTune + { + get + { + return this.CurrentTask.DenoiseTune; + } + + set + { + this.CurrentTask.DenoiseTune = value; + this.NotifyOfPropertyChange(() => this.SelectedDenoiseTune); + this.triggerTabChanged(); + } + } + + public DenoisePreset SelectedDenoisePreset + { + get + { + return this.CurrentTask.DenoisePreset; + } + + set + { + this.CurrentTask.DenoisePreset = value; + this.NotifyOfPropertyChange(() => this.SelectedDenoisePreset); + + // Show / Hide the Custom Control + if (value != DenoisePreset.Custom) this.CustomDenoise = string.Empty; + this.NotifyOfPropertyChange(() => this.ShowDenoiseCustom); + this.NotifyOfPropertyChange(() => this.ShowDenoiseOptions); + this.NotifyOfPropertyChange(() => this.ShowDenoiseTune); + this.triggerTabChanged(); + } + } + + public string CustomDenoise + { + get + { + return this.CurrentTask.CustomDenoise; + } + + set + { + this.CurrentTask.CustomDenoise = value; + this.NotifyOfPropertyChange(() => this.CustomDenoise); + this.triggerTabChanged(); + } + } + + public IEnumerable DenoisePresets => EnumHelper.GetEnumList(); + + public IEnumerable DenoiseTunes => EnumHelper.GetEnumList(); + + public IEnumerable DenoiseOptions => EnumHelper.GetEnumList(); + + public bool ShowDenoiseOptions => this.SelectedDenoise != Denoise.Off; + + public bool ShowDenoiseTune => this.SelectedDenoise == Denoise.NLMeans && this.SelectedDenoisePreset != DenoisePreset.Custom; + + public bool ShowDenoiseCustom => this.CurrentTask.DenoisePreset == DenoisePreset.Custom; + + public void SetPreset(Preset preset, EncodeTask task) + { + this.CurrentTask = task; + + if (preset == null) + { + this.SelectedDenoise = Denoise.Off; + return; + } + + this.SelectedDenoise = preset.Task.Denoise; + this.SelectedDenoisePreset = preset.Task.DenoisePreset; + this.SelectedDenoiseTune = preset.Task.DenoiseTune; + this.CustomDenoise = preset.Task.CustomDenoise; + } + + public void UpdateTask(EncodeTask task) + { + this.CurrentTask = task; + + this.NotifyOfPropertyChange(() => this.SelectedDenoise); + this.NotifyOfPropertyChange(() => this.SelectedDenoisePreset); + this.NotifyOfPropertyChange(() => this.SelectedDenoiseTune); + this.NotifyOfPropertyChange(() => this.ShowDenoiseOptions); + this.NotifyOfPropertyChange(() => this.ShowDenoiseCustom); + this.NotifyOfPropertyChange(() => this.ShowDenoiseTune); + this.NotifyOfPropertyChange(() => this.CustomDenoise); + } + + public void SetSource(Source source, Title title, Preset preset, EncodeTask task) + { + this.CurrentTask = task; + } + + public bool MatchesPreset(Preset preset) + { + if (preset.Task.Denoise != this.SelectedDenoise) + { + return false; + } + + if (this.SelectedDenoise != Denoise.Off && preset.Task.DenoisePreset != this.SelectedDenoisePreset) + { + return false; + } + + if (this.SelectedDenoise != Denoise.Off && preset.Task.DenoiseTune != this.SelectedDenoiseTune) + { + return false; + } + + return true; + } + } +} diff --git a/win/CS/HandBrakeWPF/ViewModelItems/Filters/SharpenItem.cs b/win/CS/HandBrakeWPF/ViewModelItems/Filters/SharpenItem.cs index c682135f8..188bb2675 100644 --- a/win/CS/HandBrakeWPF/ViewModelItems/Filters/SharpenItem.cs +++ b/win/CS/HandBrakeWPF/ViewModelItems/Filters/SharpenItem.cs @@ -158,6 +158,13 @@ namespace HandBrakeWPF.ViewModelItems.Filters public void SetPreset(Preset preset, EncodeTask task) { this.CurrentTask = task; + + if (preset == null) + { + this.SelectedSharpen = Sharpen.Off; + return; + } + this.SelectedSharpen = preset.Task.Sharpen; this.SelectedSharpenPreset = preset.Task.SharpenPreset; this.SelectedSharpenTune = preset.Task.SharpenTune; diff --git a/win/CS/HandBrakeWPF/ViewModels/FiltersViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/FiltersViewModel.cs index 16a9a5e5c..9e9271a48 100644 --- a/win/CS/HandBrakeWPF/ViewModels/FiltersViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/FiltersViewModel.cs @@ -59,6 +59,7 @@ namespace HandBrakeWPF.ViewModels this.SelectedDeinterlaceFilter = DeinterlaceFilter.Off; this.SharpenFilter = new SharpenItem(this.CurrentTask, () => this.OnTabStatusChanged(null)); + this.DenoiseFilter = new DenoiseItem(this.CurrentTask, () => this.OnTabStatusChanged(null)); } #endregion @@ -72,24 +73,6 @@ namespace HandBrakeWPF.ViewModels /// public EncodeTask CurrentTask { get; private set; } - /// - /// Gets or sets CustomDenoise. - /// - public string CustomDenoise - { - get - { - return this.CurrentTask.CustomDenoise; - } - - set - { - this.CurrentTask.CustomDenoise = value; - this.NotifyOfPropertyChange(() => this.CustomDenoise); - this.OnTabStatusChanged(null); - } - } - /// /// Gets or sets CustomDetelecine. /// @@ -138,17 +121,6 @@ namespace HandBrakeWPF.ViewModels } } - /// - /// Gets DenoiseOptions. - /// - public IEnumerable DenoiseOptions - { - get - { - return EnumHelper.GetEnumList(); - } - } - /// /// Gets DetelecineOptions. /// @@ -362,96 +334,10 @@ namespace HandBrakeWPF.ViewModels public bool ShowDetelecineCustom => this.CurrentTask.Detelecine == Detelecine.Custom; - #region Denoise - - /// - /// Gets or sets SelectedDenoise. - /// - public Denoise SelectedDenoise - { - get - { - return this.CurrentTask.Denoise; - } - - set - { - this.CurrentTask.Denoise = value; - this.NotifyOfPropertyChange(() => this.SelectedDenoise); - - // Show / Hide the Custom Control - this.NotifyOfPropertyChange(() => this.ShowDenoiseCustom); - - this.SelectedDenoisePreset = this.CurrentTask.Denoise == Denoise.hqdn3d ? DenoisePreset.Weak : DenoisePreset.Ultralight; // Default so we don't have an invalid preset. - - this.NotifyOfPropertyChange(() => this.ShowDenoiseOptions); - this.NotifyOfPropertyChange(() => this.ShowDenoiseTune); - this.OnTabStatusChanged(null); - } - } - - /// - /// Gets or sets the selected denoise tune. - /// - public DenoiseTune SelectedDenoiseTune - { - get - { - return this.CurrentTask.DenoiseTune; - } - - set - { - this.CurrentTask.DenoiseTune = value; - this.NotifyOfPropertyChange(() => this.SelectedDenoiseTune); - this.OnTabStatusChanged(null); - } - } - - /// - /// Gets or sets the selected denoise preset. - /// - public DenoisePreset SelectedDenoisePreset - { - get - { - return this.CurrentTask.DenoisePreset; - } - - set - { - this.CurrentTask.DenoisePreset = value; - this.NotifyOfPropertyChange(() => this.SelectedDenoisePreset); - - // Show / Hide the Custom Control - if (value != DenoisePreset.Custom) this.CustomDenoise = string.Empty; - this.NotifyOfPropertyChange(() => this.ShowDenoiseCustom); - this.NotifyOfPropertyChange(() => this.ShowDenoiseOptions); - this.NotifyOfPropertyChange(() => this.ShowDenoiseTune); - this.OnTabStatusChanged(null); - } - } - - /// - /// Gets the denoise presets. - /// - public IEnumerable DenoisePresets => EnumHelper.GetEnumList(); - - /// - /// Gets the denoise tunes. - /// - public IEnumerable DenoiseTunes => EnumHelper.GetEnumList(); - - public bool ShowDenoiseOptions => this.SelectedDenoise != Denoise.Off; - - public bool ShowDenoiseTune => this.SelectedDenoise == Denoise.NLMeans && this.SelectedDenoisePreset != DenoisePreset.Custom; - - public bool ShowDenoiseCustom => this.CurrentTask.DenoisePreset == DenoisePreset.Custom; + public DenoiseItem DenoiseFilter { get; set; } public SharpenItem SharpenFilter { get; set; } - #endregion - /// /// The rotation options. /// @@ -529,7 +415,6 @@ namespace HandBrakeWPF.ViewModels if (preset != null) { // Properties - this.SelectedDenoise = preset.Task.Denoise; this.SelectedDetelecine = preset.Task.Detelecine; this.SelectedDeinterlaceFilter = preset.Task.DeinterlaceFilter; @@ -539,25 +424,21 @@ namespace HandBrakeWPF.ViewModels this.Grayscale = preset.Task.Grayscale; this.DeblockValue = preset.Task.Deblock == 0 ? 4 : preset.Task.Deblock; - this.SelectedDenoisePreset = preset.Task.DenoisePreset; - this.SelectedDenoiseTune = preset.Task.DenoiseTune; - - // Sharpen + this.SharpenFilter.SetPreset(preset, task); + this.DenoiseFilter.SetPreset(preset, task); // Custom Values this.CustomDeinterlaceSettings = preset.Task.CustomDeinterlaceSettings; this.CustomCombDetect = preset.Task.CustomCombDetect; this.CustomDetelecine = preset.Task.CustomDetelecine; - this.CustomDenoise = preset.Task.CustomDenoise; - + this.SelectedRotation = preset.Task.Rotation; this.FlipVideo = preset.Task.FlipVideo; } else { // Default everything to off - this.SelectedDenoise = Denoise.Off; this.SelectedDeinterlaceFilter = DeinterlaceFilter.Off; this.SelectedDetelecine = Detelecine.Off; this.Grayscale = false; @@ -577,32 +458,26 @@ namespace HandBrakeWPF.ViewModels public void UpdateTask(EncodeTask task) { this.CurrentTask = task; - - this.NotifyOfPropertyChange(() => this.SelectedDenoise); this.NotifyOfPropertyChange(() => this.SelectedDeinterlaceFilter); this.NotifyOfPropertyChange(() => this.SelectedDeInterlacePreset); this.NotifyOfPropertyChange(() => this.SelectedDetelecine); this.NotifyOfPropertyChange(() => this.Grayscale); this.NotifyOfPropertyChange(() => this.DeblockValue); this.NotifyOfPropertyChange(() => this.SelectedCombDetectPreset); - this.NotifyOfPropertyChange(() => this.SelectedDenoisePreset); - this.NotifyOfPropertyChange(() => this.SelectedDenoiseTune); + this.NotifyOfPropertyChange(() => this.FlipVideo); this.NotifyOfPropertyChange(() => this.SelectedRotation); this.NotifyOfPropertyChange(() => this.CustomDeinterlaceSettings); this.NotifyOfPropertyChange(() => this.CustomDetelecine); - this.NotifyOfPropertyChange(() => this.CustomDenoise); this.NotifyOfPropertyChange(() => this.CustomCombDetect); - this.NotifyOfPropertyChange(() => this.ShowDenoiseOptions); - this.NotifyOfPropertyChange(() => this.ShowDenoiseCustom); - this.NotifyOfPropertyChange(() => this.ShowDenoiseTune); this.NotifyOfPropertyChange(() => this.ShowCustomDeinterlace); this.NotifyOfPropertyChange(() => this.ShowCombDetectCustom); this.NotifyOfPropertyChange(() => this.ShowDetelecineCustom); this.SharpenFilter.UpdateTask(task); + this.DenoiseFilter.UpdateTask(task); } public bool MatchesPreset(Preset preset) @@ -642,17 +517,7 @@ namespace HandBrakeWPF.ViewModels return false; } - if (preset.Task.Denoise != this.SelectedDenoise) - { - return false; - } - - if (this.SelectedDenoise != Denoise.Off && preset.Task.DenoisePreset != this.SelectedDenoisePreset) - { - return false; - } - - if (this.SelectedDenoise != Denoise.Off && preset.Task.DenoiseTune != this.SelectedDenoiseTune) + if (!this.DenoiseFilter.MatchesPreset(preset)) { return false; } @@ -706,6 +571,7 @@ namespace HandBrakeWPF.ViewModels { this.CurrentTask = task; this.SharpenFilter.SetSource(source, title, preset, task); + this.DenoiseFilter.SetSource(source, title, preset, task); } #endregion diff --git a/win/CS/HandBrakeWPF/Views/FiltersView.xaml b/win/CS/HandBrakeWPF/Views/FiltersView.xaml index 1833567b4..f360a0503 100644 --- a/win/CS/HandBrakeWPF/Views/FiltersView.xaml +++ b/win/CS/HandBrakeWPF/Views/FiltersView.xaml @@ -93,35 +93,35 @@ - + Visibility="{Binding DenoiseFilter.ShowDenoiseOptions, Converter={StaticResource boolToVisConverter}}"> - - - + + - + - + Visibility="{Binding DenoiseFilter.ShowDenoiseTune, Converter={StaticResource boolToVisConverter}}" VerticalAlignment="Center" /> - + - -- cgit v1.2.3