diff options
author | sr55 <[email protected]> | 2019-04-25 15:36:24 +0100 |
---|---|---|
committer | sr55 <[email protected]> | 2019-04-25 15:36:24 +0100 |
commit | abea2134024a3aedca3b2b5c9437ed3b5d17de72 (patch) | |
tree | 002f8f6abb3a602eff13318da0635313c2343073 /win | |
parent | 0937a200e89bda04cbd6b7b231462be8b4701155 (diff) |
WinGui: Refactor Filters View Model - (Rotate and Flip)
Diffstat (limited to 'win')
-rw-r--r-- | win/CS/HandBrakeWPF/HandBrakeWPF.csproj | 1 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/ViewModelItems/Filters/RotateFlipFilter.cs | 110 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/ViewModels/FiltersViewModel.cs | 65 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/Views/FiltersView.xaml | 6 |
4 files changed, 122 insertions, 60 deletions
diff --git a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj index 9caf1ab38..ffee949ff 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\RotateFlipFilter.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/RotateFlipFilter.cs b/win/CS/HandBrakeWPF/ViewModelItems/Filters/RotateFlipFilter.cs new file mode 100644 index 000000000..aba4a3d9c --- /dev/null +++ b/win/CS/HandBrakeWPF/ViewModelItems/Filters/RotateFlipFilter.cs @@ -0,0 +1,110 @@ +// -------------------------------------------------------------------------------------------------------------------- +// <copyright file="RotateFlipFilter.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 RotateFlipFilter 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 RotateFlipFilter : PropertyChangedBase + { + private readonly Action triggerTabChanged; + + public RotateFlipFilter(EncodeTask currentTask, Action triggerTabChanged) + { + this.triggerTabChanged = triggerTabChanged; + this.CurrentTask = currentTask; + + } + + public EncodeTask CurrentTask { get; private set; } + + public BindingList<int> RotationOptions => new BindingList<int> { 0, 90, 180, 270 }; + + public int SelectedRotation + { + get + { + return this.CurrentTask.Rotation; + } + + set + { + this.CurrentTask.Rotation = value; + this.NotifyOfPropertyChange(() => this.SelectedRotation); + this.triggerTabChanged(); + } + } + + public bool FlipVideo + { + get + { + return this.CurrentTask.FlipVideo; + } + + set + { + this.CurrentTask.FlipVideo = value; + this.NotifyOfPropertyChange(() => this.FlipVideo); + this.triggerTabChanged(); + } + } + + public void SetPreset(Preset preset, EncodeTask task) + { + this.CurrentTask = task; + + if (preset == null) + { + this.SelectedRotation = 0; + this.FlipVideo = false; + return; + } + + this.SelectedRotation = preset.Task.Rotation; + this.FlipVideo = preset.Task.FlipVideo; + + } + + public void UpdateTask(EncodeTask task) + { + this.CurrentTask = task; + this.NotifyOfPropertyChange(() => this.FlipVideo); + this.NotifyOfPropertyChange(() => this.SelectedRotation); + } + + public bool MatchesPreset(Preset preset) + { + if (preset.Task.Rotation != this.SelectedRotation) + { + return false; + } + + if (preset.Task.FlipVideo != this.FlipVideo) + { + 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 4ee14632a..4f7565cda 100644 --- a/win/CS/HandBrakeWPF/ViewModels/FiltersViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/FiltersViewModel.cs @@ -39,8 +39,6 @@ namespace HandBrakeWPF.ViewModels /// </summary>
public class FiltersViewModel : ViewModelBase, IFiltersViewModel
{
- #region Constructors and Destructors
-
public FiltersViewModel(IWindowManager windowManager, IUserSettingService userSettingService)
{
this.CurrentTask = new EncodeTask();
@@ -50,14 +48,11 @@ namespace HandBrakeWPF.ViewModels 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));
+ this.RotateFlipFilter = new RotateFlipFilter(this.CurrentTask, () => this.OnTabStatusChanged(null));
}
- #endregion
-
public event EventHandler<TabStatusEventArgs> TabStatusChanged;
- #region Properties
-
public EncodeTask CurrentTask { get; private set; }
public bool Grayscale
@@ -85,42 +80,8 @@ namespace HandBrakeWPF.ViewModels public DeblockFilter DeblockFilter { get; set; }
-
-
- public BindingList<int> RotationOptions => new BindingList<int> { 0, 90, 180, 270 };
-
- public int SelectedRotation
- {
- get
- {
- return this.CurrentTask.Rotation;
- }
-
- set
- {
- this.CurrentTask.Rotation = value;
- this.NotifyOfPropertyChange(() => this.SelectedRotation);
- this.OnTabStatusChanged(null);
- }
- }
-
- public bool FlipVideo
- {
- get
- {
- return this.CurrentTask.FlipVideo;
- }
-
- set
- {
- this.CurrentTask.FlipVideo = value;
- this.NotifyOfPropertyChange(() => this.FlipVideo);
- this.OnTabStatusChanged(null);
- }
- }
-
- #endregion
-
+ public RotateFlipFilter RotateFlipFilter { get; set; }
+
public void SetPreset(Preset preset, EncodeTask task)
{
this.CurrentTask = task;
@@ -135,17 +96,12 @@ namespace HandBrakeWPF.ViewModels 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;
+ this.RotateFlipFilter.SetPreset(preset, task);
}
else
{
// Default everything to off
this.Grayscale = false;
-
- this.SelectedRotation = 0;
- this.FlipVideo = false;
}
}
@@ -154,14 +110,12 @@ namespace HandBrakeWPF.ViewModels this.CurrentTask = task;
this.NotifyOfPropertyChange(() => this.Grayscale);
- this.NotifyOfPropertyChange(() => this.FlipVideo);
- this.NotifyOfPropertyChange(() => this.SelectedRotation);
-
this.SharpenFilter.UpdateTask(task);
this.DenoiseFilter.UpdateTask(task);
this.DetelecineFilter.UpdateTask(task);
this.DeinterlaceFilter.UpdateTask(task);
this.DeblockFilter.UpdateTask(task);
+ this.RotateFlipFilter.UpdateTask(task);
}
public bool MatchesPreset(Preset preset)
@@ -191,20 +145,16 @@ namespace HandBrakeWPF.ViewModels return false;
}
- if (preset.Task.Grayscale != this.Grayscale)
+ if (!this.RotateFlipFilter.MatchesPreset(preset))
{
return false;
}
- if (preset.Task.Rotation != this.SelectedRotation)
+ if (preset.Task.Grayscale != this.Grayscale)
{
return false;
}
- if (preset.Task.FlipVideo != this.FlipVideo)
- {
- return false;
- }
return true;
}
@@ -217,6 +167,7 @@ namespace HandBrakeWPF.ViewModels this.DetelecineFilter.SetSource(source, title, preset, task);
this.DeinterlaceFilter.SetSource(source, title, preset, task);
this.DeblockFilter.SetSource(source, title, preset, task);
+ this.RotateFlipFilter.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 2030c5fae..d3aa13793 100644 --- a/win/CS/HandBrakeWPF/Views/FiltersView.xaml +++ b/win/CS/HandBrakeWPF/Views/FiltersView.xaml @@ -182,12 +182,12 @@ <!-- Rotation -->
<TextBlock Text="{x:Static Properties:Resources.FiltersView_Rotate}" Grid.Row="7" Grid.Column="0" Margin="0,0,0,0"/>
- <ComboBox Width="120" ItemsSource="{Binding RotationOptions}" Grid.Row="7" Grid.Column="1"
- SelectedItem="{Binding SelectedRotation}" ToolTip="{x:Static Properties:ResourcesTooltips.FilterView_Rotate}"
+ <ComboBox Width="120" ItemsSource="{Binding RotateFlipFilter.RotationOptions}" Grid.Row="7" Grid.Column="1"
+ SelectedItem="{Binding RotateFlipFilter.SelectedRotation}" ToolTip="{x:Static Properties:ResourcesTooltips.FilterView_Rotate}"
AutomationProperties.Name="{x:Static Properties:Resources.FiltersView_Rotate}"
HorizontalAlignment="Left" VerticalAlignment="Center" />
- <CheckBox Content="{x:Static Properties:Resources.FiltersView_FlipVideo}" Margin="5,0,0,0" VerticalAlignment="Center" Grid.Row="7" Grid.Column="2" IsChecked="{Binding FlipVideo, UpdateSourceTrigger=PropertyChanged}"
+ <CheckBox Content="{x:Static Properties:Resources.FiltersView_FlipVideo}" Margin="5,0,0,0" VerticalAlignment="Center" Grid.Row="7" Grid.Column="2" IsChecked="{Binding RotateFlipFilter.FlipVideo, UpdateSourceTrigger=PropertyChanged}"
ToolTip="{x:Static Properties:ResourcesTooltips.FilterView_Flip}"/>
</Grid>
|