diff options
author | sr55 <[email protected]> | 2019-04-25 14:34:58 +0100 |
---|---|---|
committer | sr55 <[email protected]> | 2019-04-25 14:34:58 +0100 |
commit | 6ae63f3795c77c726f0d3ecebdc60b5d883f2e88 (patch) | |
tree | 622beac920999f54ec932034000728014a453719 /win/CS | |
parent | 23118c76a3cbc3fd810a41cdcbffb685d82e1f9b (diff) |
WinGui: Refactor Filters View Model - (Denoise Filter)
Diffstat (limited to 'win/CS')
-rw-r--r-- | win/CS/HandBrakeWPF/HandBrakeWPF.csproj | 1 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/ViewModelItems/Filters/DenoiseItem.cs | 178 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/ViewModelItems/Filters/SharpenItem.cs | 7 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/ViewModels/FiltersViewModel.cs | 152 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/Views/FiltersView.xaml | 22 |
5 files changed, 206 insertions, 154 deletions
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 @@ <Compile Include="Utilities\UwpDetect.cs" />
<Compile Include="Utilities\Win32.cs" />
<Compile Include="Utilities\Win7.cs" />
+ <Compile Include="ViewModelItems\Filters\DenoiseItem.cs" />
<Compile Include="ViewModelItems\Filters\SharpenItem.cs" />
<Compile Include="ViewModels\Interfaces\IManagePresetViewModel.cs" />
<Compile Include="ViewModels\Interfaces\ISummaryViewModel.cs" />
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 @@ +// -------------------------------------------------------------------------------------------------------------------- +// <copyright file="DenoiseItem.cs" company="HandBrake Project (http://handbrake.fr)"> +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// </copyright> +// <summary> +// Defines the DenoiseItem type. +// </summary> +// -------------------------------------------------------------------------------------------------------------------- + +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<DenoisePreset> DenoisePresets => EnumHelper<DenoisePreset>.GetEnumList(); + + public IEnumerable<DenoiseTune> DenoiseTunes => EnumHelper<DenoiseTune>.GetEnumList(); + + public IEnumerable<Denoise> DenoiseOptions => EnumHelper<Denoise>.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
@@ -73,24 +74,6 @@ namespace HandBrakeWPF.ViewModels public EncodeTask CurrentTask { get; private set; }
/// <summary>
- /// Gets or sets CustomDenoise.
- /// </summary>
- public string CustomDenoise
- {
- get
- {
- return this.CurrentTask.CustomDenoise;
- }
-
- set
- {
- this.CurrentTask.CustomDenoise = value;
- this.NotifyOfPropertyChange(() => this.CustomDenoise);
- this.OnTabStatusChanged(null);
- }
- }
-
- /// <summary>
/// Gets or sets CustomDetelecine.
/// </summary>
public string CustomDetelecine
@@ -139,17 +122,6 @@ namespace HandBrakeWPF.ViewModels }
/// <summary>
- /// Gets DenoiseOptions.
- /// </summary>
- public IEnumerable<Denoise> DenoiseOptions
- {
- get
- {
- return EnumHelper<Denoise>.GetEnumList();
- }
- }
-
- /// <summary>
/// Gets DetelecineOptions.
/// </summary>
public IEnumerable<Detelecine> DetelecineOptions
@@ -362,96 +334,10 @@ namespace HandBrakeWPF.ViewModels public bool ShowDetelecineCustom => this.CurrentTask.Detelecine == Detelecine.Custom;
- #region Denoise
-
- /// <summary>
- /// Gets or sets SelectedDenoise.
- /// </summary>
- 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);
- }
- }
-
- /// <summary>
- /// Gets or sets the selected denoise tune.
- /// </summary>
- public DenoiseTune SelectedDenoiseTune
- {
- get
- {
- return this.CurrentTask.DenoiseTune;
- }
-
- set
- {
- this.CurrentTask.DenoiseTune = value;
- this.NotifyOfPropertyChange(() => this.SelectedDenoiseTune);
- this.OnTabStatusChanged(null);
- }
- }
-
- /// <summary>
- /// Gets or sets the selected denoise preset.
- /// </summary>
- 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);
- }
- }
-
- /// <summary>
- /// Gets the denoise presets.
- /// </summary>
- public IEnumerable<DenoisePreset> DenoisePresets => EnumHelper<DenoisePreset>.GetEnumList();
-
- /// <summary>
- /// Gets the denoise tunes.
- /// </summary>
- public IEnumerable<DenoiseTune> DenoiseTunes => EnumHelper<DenoiseTune>.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
-
/// <summary>
/// The rotation options.
/// </summary>
@@ -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 @@ <!-- Denoise -->
<TextBlock Text="{x:Static Properties:Resources.FiltersView_Denoise}" Grid.Row="3" Grid.Column="0" Margin="0,0,0,10"/>
- <ComboBox Width="120" Grid.Row="3" ItemsSource="{Binding DenoiseOptions, Converter={StaticResource boolComboConverter}}"
- SelectedItem="{Binding SelectedDenoise, Converter={StaticResource boolComboConverter}}" Grid.Column="1"
+ <ComboBox Width="120" Grid.Row="3" ItemsSource="{Binding DenoiseFilter.DenoiseOptions, Converter={StaticResource boolComboConverter}}"
+ SelectedItem="{Binding DenoiseFilter.SelectedDenoise, Converter={StaticResource boolComboConverter}}" Grid.Column="1"
HorizontalAlignment="Left" VerticalAlignment="Center" Margin="0,0,0,10" ToolTip="{x:Static Properties:ResourcesTooltips.FilterView_Denoise}"
AutomationProperties.Name="{x:Static Properties:Resources.FiltersView_Denoise}"/>
<StackPanel Orientation="Horizontal" VerticalAlignment="Center" Grid.Row="3" Grid.Column="2" Margin="0,0,0,10"
- Visibility="{Binding ShowDenoiseOptions, Converter={StaticResource boolToVisConverter}}">
+ Visibility="{Binding DenoiseFilter.ShowDenoiseOptions, Converter={StaticResource boolToVisConverter}}">
<TextBlock Text="{x:Static Properties:Resources.FiltersView_Preset}" Margin="0,0,5,0" />
- <ComboBox SelectedItem="{Binding SelectedDenoisePreset}" ToolTip="{x:Static Properties:ResourcesTooltips.FilterView_DenoisePreset}"
+ <ComboBox SelectedItem="{Binding DenoiseFilter.SelectedDenoisePreset}" ToolTip="{x:Static Properties:ResourcesTooltips.FilterView_DenoisePreset}"
AutomationProperties.Name="{x:Static Properties:Resources.FiltersView_DenoisePresetAuto}"
MinWidth="100" HorizontalAlignment="Center" VerticalAlignment="Center">
<ComboBox.ItemsSource>
<MultiBinding Converter="{StaticResource DenoisePresetConverter}">
- <Binding Path="DenoisePresets" />
- <Binding Path="SelectedDenoise" />
+ <Binding Path="DenoiseFilter.DenoisePresets" />
+ <Binding Path="DenoiseFilter.SelectedDenoise" />
</MultiBinding>
</ComboBox.ItemsSource>
</ComboBox>
- <StackPanel Orientation="Horizontal" Visibility="{Binding ShowDenoiseTune, Converter={StaticResource boolToVisConverter}}">
+ <StackPanel Orientation="Horizontal" Visibility="{Binding DenoiseFilter.ShowDenoiseTune, Converter={StaticResource boolToVisConverter}}">
<TextBlock Text="{x:Static Properties:Resources.FiltersView_Tune}" Margin="5,0,5,0" />
- <ComboBox ItemsSource="{Binding DenoiseTunes}" SelectedItem="{Binding SelectedDenoiseTune}" MinWidth="100" ToolTip="{x:Static Properties:ResourcesTooltips.FilterView_DenoiseTune}"
+ <ComboBox ItemsSource="{Binding DenoiseFilter.DenoiseTunes}" SelectedItem="{Binding DenoiseFilter.SelectedDenoiseTune}" MinWidth="100" ToolTip="{x:Static Properties:ResourcesTooltips.FilterView_DenoiseTune}"
AutomationProperties.Name="{x:Static Properties:Resources.FiltersView_DenoiseTuneAuto}"
- Visibility="{Binding ShowDenoiseTune, Converter={StaticResource boolToVisConverter}}" VerticalAlignment="Center" />
+ Visibility="{Binding DenoiseFilter.ShowDenoiseTune, Converter={StaticResource boolToVisConverter}}" VerticalAlignment="Center" />
</StackPanel>
- <StackPanel Orientation="Horizontal" Visibility="{Binding ShowDenoiseCustom, Converter={StaticResource boolToVisConverter}}">
+ <StackPanel Orientation="Horizontal" Visibility="{Binding DenoiseFilter.ShowDenoiseCustom, Converter={StaticResource boolToVisConverter}}">
<TextBlock Text="{x:Static Properties:Resources.FiltersView_Custom}" Margin="5,0,5,0" />
- <TextBox Width="120" Margin="0" Text="{Binding CustomDenoise, UpdateSourceTrigger=PropertyChanged}" VerticalAlignment="Center" MinHeight="22"
+ <TextBox Width="120" Margin="0" Text="{Binding DenoiseFilter.CustomDenoise, UpdateSourceTrigger=PropertyChanged}" VerticalAlignment="Center" MinHeight="22"
ToolTip="{x:Static Properties:ResourcesTooltips.FilterView_CustomDenoiseParams}" />
</StackPanel>
|