WinGui: Summary Tab - Make the preview controls operational. #833
authorsr55 <sr55.hb@outlook.com>
Wed, 23 Aug 2017 21:32:28 +0000 (22:32 +0100)
committersr55 <sr55.hb@outlook.com>
Wed, 23 Aug 2017 21:32:28 +0000 (22:32 +0100)
win/CS/HandBrakeWPF/Properties/ResourcesUI.Designer.cs
win/CS/HandBrakeWPF/Properties/ResourcesUI.resx
win/CS/HandBrakeWPF/ViewModels/Interfaces/ISummaryViewModel.cs
win/CS/HandBrakeWPF/ViewModels/SummaryViewModel.cs
win/CS/HandBrakeWPF/Views/SummaryView.xaml
win/CS/HandBrakeWPF/Views/SummaryView.xaml.cs

index 5765de23f744bcc1c720dd5721ee3b1c8de1851d..802eae0b4333c01e64c5a4892d0084588c74f7dc 100644 (file)
@@ -2420,6 +2420,15 @@ namespace HandBrakeWPF.Properties {
             }\r
         }\r
         \r
+        /// <summary>\r
+        ///   Looks up a localized string similar to Preview {0} of {1}.\r
+        /// </summary>\r
+        public static string SummaryView_PreviewInfo {\r
+            get {\r
+                return ResourceManager.GetString("SummaryView_PreviewInfo", resourceCulture);\r
+            }\r
+        }\r
+        \r
         /// <summary>\r
         ///   Looks up a localized string similar to Rotation.\r
         /// </summary>\r
index a9c6d388166ba4f4237ad104d0a42a0b1a527657..27a3a055ed927074e01d9c8f4747b6eb4ceec5cc 100644 (file)
@@ -968,4 +968,7 @@ This will not affect your current settings in the Subtitle tab.</value>
   <data name="QueueView_OpenSourceDir" xml:space="preserve">\r
     <value>Open Source Directory</value>\r
   </data>\r
+  <data name="SummaryView_PreviewInfo" xml:space="preserve">\r
+    <value>Preview {0} of {1}</value>\r
+  </data>\r
 </root>
\ No newline at end of file
index 8ed5deb7842d964b3759bf670c2dc92028064115..e7440b7a88eea78795d3cd5315c39c1b21d6d665 100644 (file)
@@ -19,5 +19,6 @@ namespace HandBrakeWPF.ViewModels.Interfaces
         event EventHandler<OutputFormatChangedEventArgs> OutputFormatChanged;
         void SetContainer(OutputFormat container);
         void UpdateDisplayedInfo();
+        void SetPreviewControlVisibility(bool isPreviousVisible, bool isNextVisible);
     }
 }
\ No newline at end of file
index cac78160bbf9c2c679f7d4969eb9bed752dc4109..10f53517fc89e2fda757a71ecd0e6f162470f3e8 100644 (file)
@@ -42,6 +42,7 @@ namespace HandBrakeWPF.ViewModels
         private Source source;
         private Title currentTitle;
         private bool isMkv;
+        private int selectedPreview = 2;
 
         public SummaryViewModel(IScan scanService, IUserSettingService userSettingService)
         {
@@ -137,6 +138,8 @@ namespace HandBrakeWPF.ViewModels
 
         public bool IsPreviousPreviewControlVisible { get; set; } = false;
         public bool IsNextPreviewControlVisible { get; set; } = false;
+        public bool IsPreviewInfoVisible { get; set; } = false;
+        public string PreviewInfo { get; set; }
 
         #endregion
 
@@ -289,6 +292,62 @@ namespace HandBrakeWPF.ViewModels
             this.SelectedOutputFormat = container;
         }
 
+        public void NextPreview()
+        {
+            int maxPreview = this.userSettingService.GetUserSetting<int>(UserSettingConstants.PreviewScanCount);
+            this.selectedPreview = this.selectedPreview + 1;
+            this.UpdatePreviewFrame();
+            this.PreviewInfo = string.Format(ResourcesUI.SummaryView_PreviewInfo, this.selectedPreview, maxPreview);
+            this.NotifyOfPropertyChange(() => this.PreviewInfo);
+
+            if (this.selectedPreview == maxPreview)
+            {
+                this.IsNextPreviewControlVisible = false;
+                this.NotifyOfPropertyChange(() => this.IsNextPreviewControlVisible);
+            }
+        }
+
+        public void PreviousPreview()
+        {
+            int maxPreview = this.userSettingService.GetUserSetting<int>(UserSettingConstants.PreviewScanCount);
+            this.selectedPreview = this.selectedPreview - 1;
+            this.UpdatePreviewFrame();
+            this.PreviewInfo = string.Format(ResourcesUI.SummaryView_PreviewInfo, this.selectedPreview, maxPreview);
+            this.NotifyOfPropertyChange(() => this.PreviewInfo);
+
+            if (this.selectedPreview == 1)
+            {
+                this.IsPreviousPreviewControlVisible = false;
+                this.NotifyOfPropertyChange(() => this.IsPreviousPreviewControlVisible);
+            }
+        }
+
+        public void SetPreviewControlVisibility(bool isPreviousVisible, bool isNextVisible)
+        {
+            if (this.selectedPreview > 1)
+            {
+                this.IsPreviousPreviewControlVisible = isPreviousVisible;
+            }
+            else
+            {
+                this.IsPreviousPreviewControlVisible = false;
+            }
+
+            if (this.selectedPreview < this.userSettingService.GetUserSetting<int>(UserSettingConstants.PreviewScanCount))
+            {
+                this.IsNextPreviewControlVisible = isNextVisible;
+            }
+            else
+            {
+                this.IsNextPreviewControlVisible = false;
+            }
+
+            this.NotifyOfPropertyChange(() => this.IsPreviousPreviewControlVisible);
+            this.NotifyOfPropertyChange(() => this.IsNextPreviewControlVisible);
+        }
+
+        #region Private Methods
+
         private void UpdateSettings(Preset selectedPreset)
         {
             // Main Window Settings
@@ -368,6 +427,10 @@ namespace HandBrakeWPF.ViewModels
 
             this.AspectInfo = string.Empty;
             this.NotifyOfPropertyChange(() => this.AspectInfo);
+
+            // Preview
+            this.PreviewInfo = string.Format(ResourcesUI.SummaryView_PreviewInfo, this.selectedPreview, this.userSettingService.GetUserSetting<int>(UserSettingConstants.PreviewScanCount));
+            this.NotifyOfPropertyChange(() => this.PreviewInfo);
         }
 
         private string GetFilterDescription()
@@ -506,6 +569,8 @@ namespace HandBrakeWPF.ViewModels
             if (this.Task.Anamorphic == Anamorphic.Loose && this.Task.Width < 32)
             {
                 this.PreviewNotAvailable = true;
+                this.IsPreviewInfoVisible = false;
+                this.NotifyOfPropertyChange(() => this.IsPreviewInfoVisible);
                 return;
             }
 
@@ -518,7 +583,7 @@ namespace HandBrakeWPF.ViewModels
             BitmapImage image = null;
             try
             {
-                image = this.scanService.GetPreview(this.Task, 2, HBConfigurationFactory.Create()); // TODO make preview image configurable? 
+                image = this.scanService.GetPreview(this.Task, this.selectedPreview - 1, HBConfigurationFactory.Create()); 
             }
             catch (Exception exc)
             {
@@ -530,6 +595,8 @@ namespace HandBrakeWPF.ViewModels
             {
                 this.PreviewNotAvailable = false;
                 this.PreviewImage = image;
+                this.IsPreviewInfoVisible = true;
+                this.NotifyOfPropertyChange(() => this.IsPreviewInfoVisible);
                 this.NotifyOfPropertyChange(() => this.PreviewImage);
             }
         }
@@ -538,5 +605,7 @@ namespace HandBrakeWPF.ViewModels
         {
             this.OutputFormatChanged?.Invoke(this, e);
         }
+
+        #endregion
     }
 }
index 8dd6b46e9984aa3ec416c690be19357af946f2d6..59a0ce04b7d1cb3d818ec803919825848af70ee0 100644 (file)
@@ -5,6 +5,7 @@
              xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
              xmlns:Properties="clr-namespace:HandBrakeWPF.Properties"
              xmlns:converters="clr-namespace:HandBrakeWPF.Converters"
+             xmlns:cal="http://www.caliburnproject.org"
              mc:Ignorable="d" 
              d:DesignHeight="400" d:DesignWidth="600">
 
                 <RowDefinition Height="*" />
             </Grid.RowDefinitions>
             
-            
-            <Image Source="{Binding PreviewImage}" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Margin="10,5,10,0" />
-
-            <Border BorderThickness="1,1,1,1" CornerRadius="8,8,8,8"  VerticalAlignment="Center" HorizontalAlignment="Left"  
-                    Background="Black" Opacity="0.55" Margin="10,5,20,0" Visibility="{Binding IsPreviousPreviewControlVisible, Converter={StaticResource boolToVisConverter}}">
-                <TextBlock Text="&lt;" FontSize="30" Foreground="White" VerticalAlignment="Center" HorizontalAlignment="Center" Padding="8,3" Margin="0" />
-            </Border>
-            
-            <Border BorderThickness="1,1,1,1" CornerRadius="8,8,8,8"  VerticalAlignment="Center" HorizontalAlignment="Right"  
-                    Background="Black" Opacity="0.55" Margin="10,5,20,0" Visibility="{Binding IsNextPreviewControlVisible, Converter={StaticResource boolToVisConverter}}">
-                <TextBlock Text="&gt;" FontSize="30" Foreground="White" VerticalAlignment="Center" HorizontalAlignment="Center" Padding="8,3" Margin="0" />
-            </Border>
-            
-            <Border BorderThickness="1,1,1,1" CornerRadius="8,8,8,8"  VerticalAlignment="Bottom" HorizontalAlignment="Center"  
-                    Background="Black" Opacity="0.66" Margin="10,5,20,5">
-                <TextBlock Text="Preview 2 of 10" FontSize="14" Foreground="White" Padding="8,3" Visibility="Collapsed" />
-            </Border>
+            <Grid>
+                <Image Source="{Binding PreviewImage}" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Margin="10,5,10,0" x:Name="previewImage" MouseMove="PreviewImage_OnMouseMove" Panel.ZIndex="0" />
+
+                <Border BorderThickness="1,1,1,1" CornerRadius="8,8,8,8"  VerticalAlignment="Center" HorizontalAlignment="Left"  Panel.ZIndex="1" cal:Message.Attach="[Event MouseDown] = [Action PreviousPreview]"
+                        Background="Black" Opacity="0.75" Margin="20,0,0,0" Visibility="{Binding IsPreviousPreviewControlVisible, Converter={StaticResource boolToVisConverter}}" >
+                    <TextBlock Text="&lt;" FontSize="30" Foreground="White" VerticalAlignment="Center" HorizontalAlignment="Center" Padding="8,3" Margin="0" />
+                </Border>
+
+                <Border BorderThickness="1,1,1,1" CornerRadius="8,8,8,8"  VerticalAlignment="Center" HorizontalAlignment="Right" Panel.ZIndex="1"  cal:Message.Attach="[Event MouseDown] = [Action NextPreview]"
+                        Background="Black" Opacity="0.75" Margin="0,0,20,0" Visibility="{Binding IsNextPreviewControlVisible, Converter={StaticResource boolToVisConverter}}">
+                        <TextBlock Text="&gt;" FontSize="30" Foreground="White" VerticalAlignment="Center" HorizontalAlignment="Center" Padding="8,3" Margin="0" />
+                </Border>
+
+                <Border BorderThickness="1,1,1,1" CornerRadius="8,8,8,8"  VerticalAlignment="Bottom" HorizontalAlignment="Center" 
+                        Background="Black" Opacity="0.75" Margin="0,5,0,10">
+                    <TextBlock Text="{Binding PreviewInfo}" FontSize="14" Foreground="White" Padding="8,3" Visibility="{Binding IsPreviewInfoVisible, Converter={StaticResource boolToVisConverter}}" />
+                </Border>
+            </Grid>
+          
 
             <Grid Margin="10,5,0,0" Grid.Row="1">
                 <Grid.ColumnDefinitions>
index e3c35b48e8f4163e64423fc9e05cd883fd597337..744003698ba8f2b637b1ba36e0f336e94e7a42a0 100644 (file)
 namespace HandBrakeWPF.Views
 {
     using System.Windows.Controls;
+    using System.Windows.Input;
+
+    using HandBrakeWPF.ViewModels.Interfaces;
+
+    using Image = System.Windows.Controls.Image;
+    using Point = System.Windows.Point;
 
     /// <summary>
     /// Interaction logic for SummaryView.xaml
@@ -20,5 +26,21 @@ namespace HandBrakeWPF.Views
         {
             this.InitializeComponent();
         }
+
+        private void PreviewImage_OnMouseMove(object sender, MouseEventArgs e)
+        {
+            Image image = sender as Image;
+
+            if (image != null && image.ActualWidth > 0)
+            {
+                Point p = Mouse.GetPosition(image);
+                double width = image.ActualWidth / 2;
+
+                bool leftHalf = p.X <= width;
+                bool rightHalf = p.X > width;
+
+                ((ISummaryViewModel)this.DataContext).SetPreviewControlVisibility(leftHalf, rightHalf);
+            }
+        }
     }
 }