]> granicus.if.org Git - handbrake/commitdiff
WinGui: Refactor Filters View Model - (Deblock)
authorsr55 <sr55.hb@outlook.com>
Thu, 25 Apr 2019 14:28:54 +0000 (15:28 +0100)
committersr55 <sr55.hb@outlook.com>
Thu, 25 Apr 2019 14:28:54 +0000 (15:28 +0100)
win/CS/HandBrakeWPF/HandBrakeWPF.csproj
win/CS/HandBrakeWPF/ViewModelItems/Filters/DeblockFilter.cs [new file with mode: 0644]
win/CS/HandBrakeWPF/ViewModels/FiltersViewModel.cs
win/CS/HandBrakeWPF/Views/FiltersView.xaml

index e85382f0ec8a9a6e93add7f49906a2653a72511b..9caf1ab38a875b2e9c1ecd7d544011af95f44b4b 100644 (file)
     <Compile Include="Utilities\UwpDetect.cs" />\r
     <Compile Include="Utilities\Win32.cs" />\r
     <Compile Include="Utilities\Win7.cs" />\r
+    <Compile Include="ViewModelItems\Filters\DeblockFilter.cs" />\r
     <Compile Include="ViewModelItems\Filters\DeinterlaceFilterItem.cs" />\r
     <Compile Include="ViewModelItems\Filters\DenoiseItem.cs" />\r
     <Compile Include="ViewModelItems\Filters\DetelecineItem.cs" />\r
diff --git a/win/CS/HandBrakeWPF/ViewModelItems/Filters/DeblockFilter.cs b/win/CS/HandBrakeWPF/ViewModelItems/Filters/DeblockFilter.cs
new file mode 100644 (file)
index 0000000..09b785e
--- /dev/null
@@ -0,0 +1,90 @@
+// --------------------------------------------------------------------------------------------------------------------
+// <copyright file="DeblockFilter.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 DeblockFilter type.
+// </summary>
+// --------------------------------------------------------------------------------------------------------------------
+
+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;
+        }
+    }
+}
index 50d4a2d1f7f265bd885c6dd6d57c94081abbb90d..4ee14632afff82fea0d61db8b5b4a89ac3e35e37 100644 (file)
@@ -41,24 +41,15 @@ namespace HandBrakeWPF.ViewModels
     {\r
         #region Constructors and Destructors\r
 \r
-        /// <summary>\r
-        /// Initializes a new instance of the <see cref="FiltersViewModel"/> class.\r
-        /// </summary>\r
-        /// <param name="windowManager">\r
-        /// The window manager.\r
-        /// </param>\r
-        /// <param name="userSettingService">\r
-        /// The user Setting Service.\r
-        /// </param>\r
         public FiltersViewModel(IWindowManager windowManager, IUserSettingService userSettingService)\r
         {\r
             this.CurrentTask = new EncodeTask();\r
-            this.DeblockValue = 4; // OFF\r
    \r
             this.SharpenFilter = new SharpenItem(this.CurrentTask, () => this.OnTabStatusChanged(null));\r
             this.DenoiseFilter = new DenoiseItem(this.CurrentTask, () => this.OnTabStatusChanged(null));\r
             this.DetelecineFilter = new DetelecineItem(this.CurrentTask, () => this.OnTabStatusChanged(null));\r
             this.DeinterlaceFilter = new DeinterlaceFilterItem(this.CurrentTask, () => this.OnTabStatusChanged(null));\r
+            this.DeblockFilter = new DeblockFilter(this.CurrentTask, () => this.OnTabStatusChanged(null));\r
         }\r
 \r
         #endregion\r
@@ -67,44 +58,8 @@ namespace HandBrakeWPF.ViewModels
 \r
         #region Properties\r
 \r
-        /// <summary>\r
-        /// Gets CurrentTask.\r
-        /// </summary>\r
         public EncodeTask CurrentTask { get; private set; }\r
 \r
-        /// <summary>\r
-        /// Gets DeblockText.\r
-        /// </summary>\r
-        public string DeblockText\r
-        {\r
-            get\r
-            {\r
-                return this.DeblockValue == 4 ? "Off" : this.DeblockValue.ToString(CultureInfo.InvariantCulture);\r
-            }\r
-        }\r
-\r
-        /// <summary>\r
-        /// Gets or sets DeblockValue.\r
-        /// </summary>\r
-        public int DeblockValue\r
-        {\r
-            get\r
-            {\r
-                return this.CurrentTask.Deblock;\r
-            }\r
-\r
-            set\r
-            {\r
-                this.CurrentTask.Deblock = value;\r
-                this.NotifyOfPropertyChange(() => this.DeblockValue);\r
-                this.NotifyOfPropertyChange(() => this.DeblockText);\r
-                this.OnTabStatusChanged(null);\r
-            }\r
-        }\r
-\r
-        /// <summary>\r
-        /// Gets or sets a value indicating whether Grayscale.\r
-        /// </summary>\r
         public bool Grayscale\r
         {\r
             get\r
@@ -120,7 +75,6 @@ namespace HandBrakeWPF.ViewModels
             }\r
         }\r
 \r
-\r
         public DenoiseItem DenoiseFilter { get; set; }\r
 \r
         public SharpenItem SharpenFilter { get; set; }\r
@@ -129,14 +83,12 @@ namespace HandBrakeWPF.ViewModels
 \r
         public DeinterlaceFilterItem DeinterlaceFilter { get; set; }\r
 \r
-        /// <summary>\r
-        /// The rotation options.\r
-        /// </summary>\r
+        public DeblockFilter DeblockFilter { get; set; }\r
+\r
+\r
+\r
         public BindingList<int> RotationOptions => new BindingList<int> { 0, 90, 180, 270 };\r
 \r
-        /// <summary>\r
-        /// Selected Rotation.\r
-        /// </summary>\r
         public int SelectedRotation\r
         {\r
             get\r
@@ -152,9 +104,6 @@ namespace HandBrakeWPF.ViewModels
             }\r
         }\r
 \r
-        /// <summary>\r
-        /// Flip the Video\r
-        /// </summary>\r
         public bool FlipVideo\r
         {\r
             get\r
@@ -170,20 +119,8 @@ namespace HandBrakeWPF.ViewModels
             }\r
         }\r
 \r
-\r
         #endregion\r
 \r
-        #region Implemented Interfaces\r
-\r
-        /// <summary>\r
-        /// Setup this tab for the specified preset.\r
-        /// </summary>\r
-        /// <param name="preset">\r
-        /// The preset.\r
-        /// </param>\r
-        /// <param name="task">\r
-        /// The task.\r
-        /// </param>\r
         public void SetPreset(Preset preset, EncodeTask task)\r
         {\r
             this.CurrentTask = task;\r
@@ -191,15 +128,13 @@ namespace HandBrakeWPF.ViewModels
             if (preset != null)\r
             {\r
                 // Properties\r
-               \r
-\r
                 this.Grayscale = preset.Task.Grayscale;\r
-                this.DeblockValue = preset.Task.Deblock == 0 ? 4 : preset.Task.Deblock;\r
-                \r
+                            \r
                 this.SharpenFilter.SetPreset(preset, task);\r
                 this.DenoiseFilter.SetPreset(preset, task);\r
                 this.DetelecineFilter.SetPreset(preset, task);\r
                 this.DeinterlaceFilter.SetPreset(preset, task);\r
+                this.DeblockFilter.SetPreset(preset, task);\r
 \r
                 this.SelectedRotation = preset.Task.Rotation;\r
                 this.FlipVideo = preset.Task.FlipVideo;\r
@@ -208,25 +143,16 @@ namespace HandBrakeWPF.ViewModels
             {\r
                 // Default everything to off\r
                 this.Grayscale = false;\r
-                this.DeblockValue = 0;\r
 \r
                 this.SelectedRotation = 0;\r
                 this.FlipVideo = false;\r
             }\r
         }\r
 \r
-        /// <summary>\r
-        /// Update all the UI controls based on the encode task passed in.\r
-        /// </summary>\r
-        /// <param name="task">\r
-        /// The task.\r
-        /// </param>\r
         public void UpdateTask(EncodeTask task)\r
         {\r
             this.CurrentTask = task;\r
             this.NotifyOfPropertyChange(() => this.Grayscale);\r
-            this.NotifyOfPropertyChange(() => this.DeblockValue);\r
-            \r
 \r
             this.NotifyOfPropertyChange(() => this.FlipVideo);\r
             this.NotifyOfPropertyChange(() => this.SelectedRotation);\r
@@ -235,6 +161,7 @@ namespace HandBrakeWPF.ViewModels
             this.DenoiseFilter.UpdateTask(task);\r
             this.DetelecineFilter.UpdateTask(task);\r
             this.DeinterlaceFilter.UpdateTask(task);\r
+            this.DeblockFilter.UpdateTask(task);\r
         }\r
 \r
         public bool MatchesPreset(Preset preset)\r
@@ -259,9 +186,7 @@ namespace HandBrakeWPF.ViewModels
                 return false;\r
             }\r
 \r
-            int presetDeblock = preset.Task.Deblock == 0 ? 4 : preset.Task.Deblock;\r
-\r
-            if (presetDeblock != this.DeblockValue)\r
+            if (!this.DeblockFilter.MatchesPreset(preset))\r
             {\r
                 return false;\r
             }\r
@@ -284,21 +209,6 @@ namespace HandBrakeWPF.ViewModels
             return true;\r
         }\r
 \r
-        /// <summary>\r
-        /// Setup this window for a new source\r
-        /// </summary>\r
-        /// <param name="source">\r
-        /// The source.\r
-        /// </param>\r
-        /// <param name="title">\r
-        /// The title.\r
-        /// </param>\r
-        /// <param name="preset">\r
-        /// The preset.\r
-        /// </param>\r
-        /// <param name="task">\r
-        /// The task.\r
-        /// </param>\r
         public void SetSource(Source source, Title title, Preset preset, EncodeTask task)\r
         {\r
             this.CurrentTask = task;\r
@@ -306,15 +216,12 @@ namespace HandBrakeWPF.ViewModels
             this.DenoiseFilter.SetSource(source, title, preset, task);\r
             this.DetelecineFilter.SetSource(source, title, preset, task);\r
             this.DeinterlaceFilter.SetSource(source, title, preset, task);\r
+            this.DeblockFilter.SetSource(source, title, preset, task);\r
         }\r
 \r
-        #endregion\r
-\r
-        #region Private Methods\r
         protected virtual void OnTabStatusChanged(TabStatusEventArgs e)\r
         {\r
             this.TabStatusChanged?.Invoke(this, e);\r
         }\r
-        #endregion\r
     }\r
 }
\ No newline at end of file
index a311900eb8bbca29ee0aad02d726eda73dde9b05..2030c5fae402a9f76806dfeba9c9795a4503155a 100644 (file)
 \r
                 <!-- Deblock -->\r
                 <TextBlock Text="{x:Static Properties:Resources.FiltersView_Deblock}" Grid.Row="5" Grid.Column="0" Margin="0,0,0,10"/>\r
-                <Slider Width="120" Value="{Binding DeblockValue}" TickPlacement="BottomRight" Minimum="4" Maximum="15" Grid.Row="5" Grid.Column="1" Margin="0,0,0,10"\r
+                <Slider Width="120" Value="{Binding DeblockFilter.DeblockValue}" TickPlacement="BottomRight" Minimum="4" Maximum="15" Grid.Row="5" Grid.Column="1" Margin="0,0,0,10"\r
                         HorizontalAlignment="Left" ToolTip="{x:Static Properties:ResourcesTooltips.FilterView_Deblock}"\r
                         AutomationProperties.Name="{x:Static Properties:Resources.FiltersView_Deblock}" />\r
-                <TextBlock Text="{Binding DeblockText}" Grid.Row="5" Grid.Column="2" Margin="0,0,0,10"/>\r
+                <TextBlock Text="{Binding DeblockFilter.DeblockText}" Grid.Row="5" Grid.Column="2" Margin="0,0,0,10"/>\r
 \r
                 <CheckBox Content="{x:Static Properties:Resources.FiltersView_Grayscale}" IsChecked="{Binding Grayscale}" Grid.Row="6" Grid.Column="1" Margin="0,0,0,10"\r
                           ToolTip="{x:Static Properties:ResourcesTooltips.FilterView_Grayscale}" />\r