mirror of
https://github.com/QL-Win/QuickLook.git
synced 2025-09-11 09:49:07 +00:00
Add a copy button to the image viewer #1399
This commit is contained in:
@@ -91,25 +91,34 @@
|
||||
</Border.Resources>
|
||||
</Border>
|
||||
|
||||
<Button x:Name="buttonMeta"
|
||||
Width="24"
|
||||
Height="24"
|
||||
Margin="0,8,40,0"
|
||||
HorizontalAlignment="Right"
|
||||
VerticalAlignment="Top"
|
||||
Content=""
|
||||
Style="{StaticResource CaptionButtonStyle}"
|
||||
Visibility="{Binding ElementName=imagePanel, Path=MetaIconVisibility}" />
|
||||
<StackPanel Margin="0,8,0,0"
|
||||
HorizontalAlignment="Right"
|
||||
VerticalAlignment="Top"
|
||||
Orientation="Horizontal">
|
||||
<Button x:Name="buttonCopy"
|
||||
Width="24"
|
||||
Height="24"
|
||||
Margin="0,0,8,0"
|
||||
Content=""
|
||||
Style="{StaticResource CaptionButtonStyle}"
|
||||
Visibility="{Binding ElementName=imagePanel, Path=CopyIconVisibility}" />
|
||||
|
||||
<Button x:Name="buttonBackgroundColour"
|
||||
Width="24"
|
||||
Height="24"
|
||||
Margin="0,8,8,0"
|
||||
HorizontalAlignment="Right"
|
||||
VerticalAlignment="Top"
|
||||
Content=""
|
||||
Style="{StaticResource CaptionButtonStyle}"
|
||||
Visibility="{Binding ElementName=imagePanel, Path=BackgroundVisibility}" />
|
||||
<Button x:Name="buttonMeta"
|
||||
Width="24"
|
||||
Height="24"
|
||||
Margin="0,0,8,0"
|
||||
Content=""
|
||||
Style="{StaticResource CaptionButtonStyle}"
|
||||
Visibility="{Binding ElementName=imagePanel, Path=MetaIconVisibility}" />
|
||||
|
||||
<Button x:Name="buttonBackgroundColour"
|
||||
Width="24"
|
||||
Height="24"
|
||||
Margin="0,0,8,0"
|
||||
Content=""
|
||||
Style="{StaticResource CaptionButtonStyle}"
|
||||
Visibility="{Binding ElementName=imagePanel, Path=BackgroundVisibility}" />
|
||||
</StackPanel>
|
||||
|
||||
<TextBlock x:Name="textMeta"
|
||||
Margin="0,40,8,0"
|
||||
|
@@ -49,6 +49,7 @@ public partial class ImagePanel : UserControl, INotifyPropertyChanged, IDisposab
|
||||
private bool _isZoomFactorFirstSet = true;
|
||||
private DateTime _lastZoomTime = DateTime.MinValue;
|
||||
private double _maxZoomFactor = 3d;
|
||||
private Visibility _copyIconVisibility = Visibility.Visible;
|
||||
private MetaProvider _meta;
|
||||
private Visibility _metaIconVisibility = Visibility.Visible;
|
||||
private double _minZoomFactor = 0.1d;
|
||||
@@ -67,6 +68,8 @@ public partial class ImagePanel : UserControl, INotifyPropertyChanged, IDisposab
|
||||
|
||||
Resources.MergedDictionaries.Clear();
|
||||
|
||||
buttonCopy.Click += OnCopyOnClick;
|
||||
|
||||
buttonMeta.Click += (sender, e) =>
|
||||
textMeta.Visibility = textMeta.Visibility == Visibility.Collapsed
|
||||
? Visibility.Visible
|
||||
@@ -162,6 +165,16 @@ public partial class ImagePanel : UserControl, INotifyPropertyChanged, IDisposab
|
||||
}
|
||||
}
|
||||
|
||||
public Visibility CopyIconVisibility
|
||||
{
|
||||
get => _copyIconVisibility;
|
||||
set
|
||||
{
|
||||
_copyIconVisibility = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public Visibility BackgroundVisibility
|
||||
{
|
||||
get => _backgroundVisibility;
|
||||
@@ -274,6 +287,28 @@ public partial class ImagePanel : UserControl, INotifyPropertyChanged, IDisposab
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
private void OnCopyOnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_source is not null)
|
||||
{
|
||||
Clipboard.SetImage(_source);
|
||||
return;
|
||||
}
|
||||
|
||||
if (viewPanelImage.Source is BitmapSource bitmapSource)
|
||||
{
|
||||
Clipboard.SetImage(bitmapSource);
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
///
|
||||
}
|
||||
}
|
||||
|
||||
private void OnBackgroundColourOnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Theme = Theme == Themes.Dark ? Themes.Light : Themes.Dark;
|
||||
@@ -499,7 +534,7 @@ public partial class ImagePanel : UserControl, INotifyPropertyChanged, IDisposab
|
||||
|
||||
Debug.WriteLine($"FireZoomChangedEvent fired: {Thread.CurrentThread.ManagedThreadId}");
|
||||
|
||||
Dispatcher.BeginInvoke(new Action(() => ZoomChanged?.Invoke(this, new EventArgs())),
|
||||
Dispatcher.BeginInvoke(new Action(() => ZoomChanged?.Invoke(this, EventArgs.Empty)),
|
||||
DispatcherPriority.Background);
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user