mirror of
https://github.com/QL-Win/QuickLook.git
synced 2025-09-12 18:39:45 +00:00
More natural scroll behaviour
This commit is contained in:
@@ -56,6 +56,7 @@ namespace QuickLook.Plugin.ImageViewer
|
|||||||
viewPanel.MouseLeftButtonDown += ViewPanel_MouseLeftButtonDown;
|
viewPanel.MouseLeftButtonDown += ViewPanel_MouseLeftButtonDown;
|
||||||
viewPanel.MouseMove += ViewPanel_MouseMove;
|
viewPanel.MouseMove += ViewPanel_MouseMove;
|
||||||
|
|
||||||
|
viewPanel.ManipulationInertiaStarting += ViewPanel_ManipulationInertiaStarting;
|
||||||
viewPanel.ManipulationStarting += ViewPanel_ManipulationStarting;
|
viewPanel.ManipulationStarting += ViewPanel_ManipulationStarting;
|
||||||
viewPanel.ManipulationDelta += ViewPanel_ManipulationDelta;
|
viewPanel.ManipulationDelta += ViewPanel_ManipulationDelta;
|
||||||
}
|
}
|
||||||
@@ -128,7 +129,16 @@ namespace QuickLook.Plugin.ImageViewer
|
|||||||
private void ImagePanel_SizeChanged(object sender, SizeChangedEventArgs e)
|
private void ImagePanel_SizeChanged(object sender, SizeChangedEventArgs e)
|
||||||
{
|
{
|
||||||
if (ZoomToFit)
|
if (ZoomToFit)
|
||||||
DoZoomToFit(false);
|
DoZoomToFit();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ViewPanel_ManipulationInertiaStarting(object sender, ManipulationInertiaStartingEventArgs e)
|
||||||
|
{
|
||||||
|
e.TranslationBehavior = new InertiaTranslationBehavior
|
||||||
|
{
|
||||||
|
InitialVelocity = e.InitialVelocities.LinearVelocity,
|
||||||
|
DesiredDeceleration = 10.0 * 96.0 / (1000.0 * 1000.0)
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ViewPanel_ManipulationStarting(object sender, ManipulationStartingEventArgs e)
|
private void ViewPanel_ManipulationStarting(object sender, ManipulationStartingEventArgs e)
|
||||||
@@ -220,7 +230,7 @@ namespace QuickLook.Plugin.ImageViewer
|
|||||||
viewPanel.ScrollToVerticalOffset(point.Y);
|
viewPanel.ScrollToVerticalOffset(point.Y);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DoZoomToFit(bool suppressEvent)
|
public void DoZoomToFit()
|
||||||
{
|
{
|
||||||
if (viewPanelImage.Source == null)
|
if (viewPanelImage.Source == null)
|
||||||
return;
|
return;
|
||||||
@@ -228,7 +238,7 @@ namespace QuickLook.Plugin.ImageViewer
|
|||||||
var factor = Math.Min(viewPanel.ActualWidth / viewPanelImage.Source.Width,
|
var factor = Math.Min(viewPanel.ActualWidth / viewPanelImage.Source.Width,
|
||||||
viewPanel.ActualHeight / viewPanelImage.Source.Height);
|
viewPanel.ActualHeight / viewPanelImage.Source.Height);
|
||||||
|
|
||||||
Zoom(factor, true, suppressEvent);
|
Zoom(factor, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ResetZoom()
|
public void ResetZoom()
|
||||||
|
@@ -34,6 +34,8 @@ namespace QuickLook.Plugin.PDFViewer
|
|||||||
{
|
{
|
||||||
private const double MinZoomFactor = 0.1d;
|
private const double MinZoomFactor = 0.1d;
|
||||||
private const double MaxZoomFactor = 3d;
|
private const double MaxZoomFactor = 3d;
|
||||||
|
private int _changePageDeltaSum;
|
||||||
|
|
||||||
private bool _pdfLoaded;
|
private bool _pdfLoaded;
|
||||||
private double _viewRenderFactor = 1d;
|
private double _viewRenderFactor = 1d;
|
||||||
|
|
||||||
@@ -103,9 +105,23 @@ namespace QuickLook.Plugin.PDFViewer
|
|||||||
|
|
||||||
const double tolerance = 0.0001d;
|
const double tolerance = 0.0001d;
|
||||||
if (Math.Abs(pos.Y) < tolerance && delta > 0)
|
if (Math.Abs(pos.Y) < tolerance && delta > 0)
|
||||||
|
{
|
||||||
|
_changePageDeltaSum += delta;
|
||||||
|
if (Math.Abs(_changePageDeltaSum) < 20)
|
||||||
|
return;
|
||||||
|
|
||||||
PrevPage();
|
PrevPage();
|
||||||
else if (Math.Abs(pos.Y - size.Height) < tolerance && delta < 0)
|
_changePageDeltaSum = 0;
|
||||||
|
}
|
||||||
|
else if (Math.Abs(pos.Y - size.Height) < tolerance && delta < -0)
|
||||||
|
{
|
||||||
|
_changePageDeltaSum += delta;
|
||||||
|
if (Math.Abs(_changePageDeltaSum) < 20)
|
||||||
|
return;
|
||||||
|
|
||||||
NextPage();
|
NextPage();
|
||||||
|
_changePageDeltaSum = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void NextPage()
|
private void NextPage()
|
||||||
@@ -193,7 +209,7 @@ namespace QuickLook.Plugin.PDFViewer
|
|||||||
OnPropertyChanged("PageIds");
|
OnPropertyChanged("PageIds");
|
||||||
|
|
||||||
CurrentPage = 0;
|
CurrentPage = 0;
|
||||||
pagePanel.DoZoomToFit(true);
|
pagePanel.DoZoomToFit();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
|
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
|
||||||
|
@@ -11,6 +11,6 @@
|
|||||||
UseLayoutRounding="True">
|
UseLayoutRounding="True">
|
||||||
<Grid>
|
<Grid>
|
||||||
<avalonEdit:TextEditor x:Name="viewer" Background="#00FFFFFF" FontSize="14" ShowLineNumbers="True"
|
<avalonEdit:TextEditor x:Name="viewer" Background="#00FFFFFF" FontSize="14" ShowLineNumbers="True"
|
||||||
WordWrap="True" IsReadOnly="True" />
|
WordWrap="True" IsReadOnly="True" IsManipulationEnabled="True" />
|
||||||
</Grid>
|
</Grid>
|
||||||
</UserControl>
|
</UserControl>
|
@@ -18,6 +18,7 @@
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
|
using System.Windows.Input;
|
||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
using ICSharpCode.AvalonEdit.Highlighting;
|
using ICSharpCode.AvalonEdit.Highlighting;
|
||||||
|
|
||||||
@@ -32,12 +33,48 @@ namespace QuickLook.Plugin.TextViewer
|
|||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
|
viewer.ManipulationInertiaStarting += Viewer_ManipulationInertiaStarting;
|
||||||
|
viewer.ManipulationStarting += Viewer_ManipulationStarting;
|
||||||
|
viewer.ManipulationDelta += Viewer_ManipulationDelta;
|
||||||
|
|
||||||
|
viewer.PreviewMouseWheel += Viewer_MouseWheel;
|
||||||
|
|
||||||
viewer.FontFamily =
|
viewer.FontFamily =
|
||||||
new FontFamily(context.GetString("Editor_FontFamily", failsafe: "Consolas"));
|
new FontFamily(context.GetString("Editor_FontFamily", failsafe: "Consolas"));
|
||||||
|
|
||||||
LoadFile(path);
|
LoadFile(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void Viewer_ManipulationInertiaStarting(object sender, ManipulationInertiaStartingEventArgs e)
|
||||||
|
{
|
||||||
|
e.TranslationBehavior = new InertiaTranslationBehavior
|
||||||
|
{
|
||||||
|
InitialVelocity = e.InitialVelocities.LinearVelocity,
|
||||||
|
DesiredDeceleration = 10.0 * 96.0 / (1000.0 * 1000.0)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Viewer_MouseWheel(object sender, MouseWheelEventArgs e)
|
||||||
|
{
|
||||||
|
e.Handled = true;
|
||||||
|
|
||||||
|
viewer.ScrollToVerticalOffset(viewer.VerticalOffset - e.Delta);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Viewer_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
|
||||||
|
{
|
||||||
|
e.Handled = true;
|
||||||
|
|
||||||
|
var delta = e.DeltaManipulation;
|
||||||
|
viewer.ScrollToVerticalOffset(viewer.VerticalOffset - delta.Translation.Y);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Viewer_ManipulationStarting(object sender, ManipulationStartingEventArgs e)
|
||||||
|
{
|
||||||
|
e.ManipulationContainer = this;
|
||||||
|
e.Mode = ManipulationModes.Translate;
|
||||||
|
}
|
||||||
|
|
||||||
private void LoadFile(string path)
|
private void LoadFile(string path)
|
||||||
{
|
{
|
||||||
using (var s = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
|
using (var s = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
|
||||||
|
Reference in New Issue
Block a user