diff options
author | sr55 <[email protected]> | 2019-04-25 15:41:15 +0100 |
---|---|---|
committer | sr55 <[email protected]> | 2019-04-25 15:41:15 +0100 |
commit | b2253ebf5320f0bd5f0743300a5ec82b91b67c6d (patch) | |
tree | d4041f41a9d272b5cc36a5d1b424af36adb611ff | |
parent | abea2134024a3aedca3b2b5c9437ed3b5d17de72 (diff) |
WinGui: Refactor Filters View Model - (Grayscale)
-rw-r--r-- | win/CS/HandBrakeWPF/HandBrakeWPF.csproj | 1 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/ViewModelItems/Filters/GrayscaleFilter.cs | 85 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/ViewModels/FiltersViewModel.cs | 49 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/Views/FiltersView.xaml | 2 |
4 files changed, 99 insertions, 38 deletions
diff --git a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj index ffee949ff..590ef559b 100644 --- a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj +++ b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj @@ -276,6 +276,7 @@ <Compile Include="ViewModelItems\Filters\DeinterlaceFilterItem.cs" />
<Compile Include="ViewModelItems\Filters\DenoiseItem.cs" />
<Compile Include="ViewModelItems\Filters\DetelecineItem.cs" />
+ <Compile Include="ViewModelItems\Filters\GrayscaleFilter.cs" />
<Compile Include="ViewModelItems\Filters\RotateFlipFilter.cs" />
<Compile Include="ViewModelItems\Filters\SharpenItem.cs" />
<Compile Include="ViewModels\Interfaces\IManagePresetViewModel.cs" />
diff --git a/win/CS/HandBrakeWPF/ViewModelItems/Filters/GrayscaleFilter.cs b/win/CS/HandBrakeWPF/ViewModelItems/Filters/GrayscaleFilter.cs new file mode 100644 index 000000000..0ea9f25c6 --- /dev/null +++ b/win/CS/HandBrakeWPF/ViewModelItems/Filters/GrayscaleFilter.cs @@ -0,0 +1,85 @@ +// -------------------------------------------------------------------------------------------------------------------- +// <copyright file="GrayscaleFilter.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 GrayscaleFilter type. +// </summary> +// -------------------------------------------------------------------------------------------------------------------- + +namespace HandBrakeWPF.ViewModelItems.Filters +{ + using System.ComponentModel; + + using Caliburn.Micro; + + using HandBrakeWPF.Services.Encode.Model; + using HandBrakeWPF.Services.Presets.Model; + using HandBrakeWPF.Services.Scan.Model; + + using Action = System.Action; + + public class GrayscaleFilter : PropertyChangedBase + { + private readonly Action triggerTabChanged; + + public GrayscaleFilter(EncodeTask currentTask, Action triggerTabChanged) + { + this.triggerTabChanged = triggerTabChanged; + this.CurrentTask = currentTask; + + } + + public EncodeTask CurrentTask { get; private set; } + + public bool Grayscale + { + get + { + return this.CurrentTask.Grayscale; + } + + set + { + this.CurrentTask.Grayscale = value; + this.NotifyOfPropertyChange(() => this.Grayscale); + this.triggerTabChanged(); + } + } + + public void SetPreset(Preset preset, EncodeTask task) + { + this.CurrentTask = task; + + if (preset == null) + { + this.Grayscale = false; + return; + } + + this.Grayscale = preset.Task.Grayscale; + + } + + public void UpdateTask(EncodeTask task) + { + this.CurrentTask = task; + this.NotifyOfPropertyChange(() => this.Grayscale); + } + + public bool MatchesPreset(Preset preset) + { + if (preset.Task.Grayscale != this.Grayscale) + { + 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 4f7565cda..d2c1899c6 100644 --- a/win/CS/HandBrakeWPF/ViewModels/FiltersViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/FiltersViewModel.cs @@ -30,8 +30,6 @@ namespace HandBrakeWPF.ViewModels using HandBrakeWPF.ViewModelItems.Filters;
using HandBrakeWPF.ViewModels.Interfaces;
- using DenoisePreset = HandBrakeWPF.Services.Encode.Model.Models.DenoisePreset;
- using DenoiseTune = HandBrakeWPF.Services.Encode.Model.Models.DenoiseTune;
using EncodeTask = HandBrakeWPF.Services.Encode.Model.EncodeTask;
/// <summary>
@@ -49,27 +47,13 @@ namespace HandBrakeWPF.ViewModels this.DeinterlaceFilter = new DeinterlaceFilterItem(this.CurrentTask, () => this.OnTabStatusChanged(null));
this.DeblockFilter = new DeblockFilter(this.CurrentTask, () => this.OnTabStatusChanged(null));
this.RotateFlipFilter = new RotateFlipFilter(this.CurrentTask, () => this.OnTabStatusChanged(null));
+ this.GrayscaleFilter = new GrayscaleFilter(this.CurrentTask, () => this.OnTabStatusChanged(null));
}
public event EventHandler<TabStatusEventArgs> TabStatusChanged;
public EncodeTask CurrentTask { get; private set; }
- public bool Grayscale
- {
- get
- {
- return this.CurrentTask.Grayscale;
- }
-
- set
- {
- this.CurrentTask.Grayscale = value;
- this.NotifyOfPropertyChange(() => this.Grayscale);
- this.OnTabStatusChanged(null);
- }
- }
-
public DenoiseItem DenoiseFilter { get; set; }
public SharpenItem SharpenFilter { get; set; }
@@ -81,34 +65,24 @@ namespace HandBrakeWPF.ViewModels public DeblockFilter DeblockFilter { get; set; }
public RotateFlipFilter RotateFlipFilter { get; set; }
+
+ public GrayscaleFilter GrayscaleFilter { get; set; }
public void SetPreset(Preset preset, EncodeTask task)
{
this.CurrentTask = task;
- if (preset != null)
- {
- // Properties
- this.Grayscale = preset.Task.Grayscale;
-
- 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.RotateFlipFilter.SetPreset(preset, task);
- }
- else
- {
- // Default everything to off
- this.Grayscale = false;
- }
+ 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.RotateFlipFilter.SetPreset(preset, task);
}
public void UpdateTask(EncodeTask task)
{
this.CurrentTask = task;
- this.NotifyOfPropertyChange(() => this.Grayscale);
this.SharpenFilter.UpdateTask(task);
this.DenoiseFilter.UpdateTask(task);
@@ -116,6 +90,7 @@ namespace HandBrakeWPF.ViewModels this.DeinterlaceFilter.UpdateTask(task);
this.DeblockFilter.UpdateTask(task);
this.RotateFlipFilter.UpdateTask(task);
+ this.GrayscaleFilter.UpdateTask(task);
}
public bool MatchesPreset(Preset preset)
@@ -150,12 +125,11 @@ namespace HandBrakeWPF.ViewModels return false;
}
- if (preset.Task.Grayscale != this.Grayscale)
+ if (!this.GrayscaleFilter.MatchesPreset(preset))
{
return false;
}
-
return true;
}
@@ -168,6 +142,7 @@ namespace HandBrakeWPF.ViewModels this.DeinterlaceFilter.SetSource(source, title, preset, task);
this.DeblockFilter.SetSource(source, title, preset, task);
this.RotateFlipFilter.SetSource(source, title, preset, task);
+ this.GrayscaleFilter.SetSource(source, title, preset, task);
}
protected virtual void OnTabStatusChanged(TabStatusEventArgs e)
diff --git a/win/CS/HandBrakeWPF/Views/FiltersView.xaml b/win/CS/HandBrakeWPF/Views/FiltersView.xaml index d3aa13793..d1b567ae2 100644 --- a/win/CS/HandBrakeWPF/Views/FiltersView.xaml +++ b/win/CS/HandBrakeWPF/Views/FiltersView.xaml @@ -177,7 +177,7 @@ AutomationProperties.Name="{x:Static Properties:Resources.FiltersView_Deblock}" />
<TextBlock Text="{Binding DeblockFilter.DeblockText}" Grid.Row="5" Grid.Column="2" Margin="0,0,0,10"/>
- <CheckBox Content="{x:Static Properties:Resources.FiltersView_Grayscale}" IsChecked="{Binding Grayscale}" Grid.Row="6" Grid.Column="1" Margin="0,0,0,10"
+ <CheckBox Content="{x:Static Properties:Resources.FiltersView_Grayscale}" IsChecked="{Binding GrayscaleFilter.Grayscale}" Grid.Row="6" Grid.Column="1" Margin="0,0,0,10"
ToolTip="{x:Static Properties:ResourcesTooltips.FilterView_Grayscale}" />
<!-- Rotation -->
|