add:使用橡皮后自动切回批注

This commit is contained in:
2026-02-22 11:25:30 +08:00
parent 3e701718d3
commit d8bbee8c76
8 changed files with 251 additions and 5 deletions
+22
View File
@@ -911,6 +911,28 @@
FontSize="12" Margin="12,0,0,0" VerticalAlignment="Center" />
</ui:SimpleStackPanel>
</ui:SimpleStackPanel>
<Line HorizontalAlignment="Center" X1="0" Y1="0" X2="400" Y2="0" Stroke="#3f3f46"
StrokeThickness="1" Margin="0,4,0,4" />
<ui:SimpleStackPanel Orientation="Horizontal" HorizontalAlignment="Left">
<TextBlock Foreground="#fafafa" Text="使用橡皮擦后自动切换回批注模式" VerticalAlignment="Center"
FontSize="14" Margin="0,0,16,0" />
<ui:ToggleSwitch OnContent="" OffContent="" Name="ToggleSwitchEnableEraserAutoSwitchBack"
IsOn="False" FontFamily="Microsoft YaHei UI" FontWeight="Bold"
Toggled="ToggleSwitchEnableEraserAutoSwitchBack_Toggled" />
</ui:SimpleStackPanel>
<TextBlock Text="# 开启后,使用橡皮擦进行擦除操作后静置一段时间将自动切换回批注模式" TextWrapping="Wrap" Foreground="#a1a1aa" />
<ui:SimpleStackPanel Orientation="Horizontal" HorizontalAlignment="Left"
Visibility="{Binding ElementName=ToggleSwitchEnableEraserAutoSwitchBack, Path=IsOn, Converter={StaticResource BooleanToVisibilityConverter}}">
<TextBlock Foreground="#fafafa" Text="自动切换延迟时间" VerticalAlignment="Center"
FontSize="14" Margin="0,0,16,0" />
<Slider Name="EraserAutoSwitchBackDelaySlider" Width="150" Minimum="1" Maximum="60"
Value="10" TickFrequency="1" IsSnapToTickEnabled="True"
ValueChanged="EraserAutoSwitchBackDelaySlider_ValueChanged" />
<TextBlock Foreground="#fafafa" Text="{Binding ElementName=EraserAutoSwitchBackDelaySlider, Path=Value, StringFormat={}{0:0}秒}"
VerticalAlignment="Center" FontSize="14" Margin="16,0,0,0" />
</ui:SimpleStackPanel>
<TextBlock Text="# 若在计时时间内再次进行擦除操作,计时器将重新开始计时" TextWrapping="Wrap" Foreground="#a1a1aa"
Visibility="{Binding ElementName=ToggleSwitchEnableEraserAutoSwitchBack, Path=IsOn, Converter={StaticResource BooleanToVisibilityConverter}}" />
</ui:SimpleStackPanel>
</GroupBox>
<!-- 崩溃后操作设置 -->
+102 -1
View File
@@ -200,6 +200,10 @@ namespace Ink_Canvas
inkCanvas.PreviewMouseDown += inkCanvas_PreviewMouseDown;
inkCanvas.StylusDown += inkCanvas_StylusDown;
inkCanvas.MouseRightButtonUp += InkCanvas_MouseRightButtonUp;
// 注册橡皮擦操作结束事件(StylusUp 用于自动切换回批注;MouseUp 在 MW_ShapeDrawing.cs 的 inkCanvas_MouseUp 中会调用 HandleEraserOperationEnded
inkCanvas.StylusUp += inkCanvas_StylusUp;
inkCanvas.MouseUp += inkCanvas_MouseUp;
// 初始化第一页Canvas
var firstCanvas = new System.Windows.Controls.Canvas();
@@ -1334,9 +1338,19 @@ namespace Ink_Canvas
// 初始化UIA置顶开关
ToggleSwitchUIAccessTopMost.IsOn = Settings.Advanced.EnableUIAccessTopMost;
UpdateUIAccessTopMostVisibility();
App.IsUIAccessTopMostEnabled = Settings.Advanced.EnableUIAccessTopMost;
// 初始化橡皮擦自动切换回批注模式开关
if (ToggleSwitchEnableEraserAutoSwitchBack != null)
{
ToggleSwitchEnableEraserAutoSwitchBack.IsOn = Settings.Canvas.EnableEraserAutoSwitchBack;
}
if (EraserAutoSwitchBackDelaySlider != null)
{
EraserAutoSwitchBackDelaySlider.Value = Settings.Canvas.EraserAutoSwitchBackDelaySeconds;
}
// 初始化剪贴板监控
InitializeClipboardMonitoring();
@@ -2166,6 +2180,43 @@ namespace Ink_Canvas
SetCursorBasedOnEditingMode(sender as InkCanvas);
}
// 手写笔抬起事件(用于橡皮擦自动切换)
private void inkCanvas_StylusUp(object sender, StylusEventArgs e)
{
HandleEraserOperationEnded();
}
/// <summary>
/// 处理橡皮擦操作结束事件
/// </summary>
private void HandleEraserOperationEnded()
{
try
{
// 检查是否在橡皮擦模式且启用了自动切换功能
if ((inkCanvas.EditingMode == InkCanvasEditingMode.EraseByPoint ||
inkCanvas.EditingMode == InkCanvasEditingMode.EraseByStroke) &&
Settings.Canvas.EnableEraserAutoSwitchBack)
{
// 启动或重启计时器
StartEraserAutoSwitchBackTimer();
}
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"处理橡皮擦操作结束事件失败: {ex.Message}", LogHelper.LogType.Error);
}
}
/// <summary>
/// 注册橡皮擦操作监听器(在切换到橡皮擦模式时调用)
/// </summary>
private void RegisterEraserOperationListeners()
{
// 事件已经在构造函数中注册,这里只需要确保计时器在操作结束时启动
// 实际的启动逻辑在HandleEraserOperationEnded中处理
}
// 触摸结束,恢复光标
#endregion Definations and Loading
@@ -3425,6 +3476,56 @@ namespace Ink_Canvas
}
}
/// <summary>
/// 橡皮擦自动切换回批注模式开关切换事件处理
/// </summary>
private void ToggleSwitchEnableEraserAutoSwitchBack_Toggled(object sender, RoutedEventArgs e)
{
try
{
if (!isLoaded) return;
Settings.Canvas.EnableEraserAutoSwitchBack = ToggleSwitchEnableEraserAutoSwitchBack.IsOn;
SaveSettingsToFile();
// 如果禁用,停止计时器
if (!Settings.Canvas.EnableEraserAutoSwitchBack)
{
StopEraserAutoSwitchBackTimer();
}
LogHelper.WriteLogToFile($"橡皮擦自动切换回批注模式已{(Settings.Canvas.EnableEraserAutoSwitchBack ? "" : "")}", LogHelper.LogType.Event);
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"切换橡皮擦自动切换回批注模式时出错: {ex.Message}", LogHelper.LogType.Error);
}
}
/// <summary>
/// 橡皮擦自动切换延迟时间滑块值改变事件处理
/// </summary>
private void EraserAutoSwitchBackDelaySlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
try
{
if (!isLoaded) return;
Settings.Canvas.EraserAutoSwitchBackDelaySeconds = (int)e.NewValue;
SaveSettingsToFile();
// 如果计时器正在运行,重新启动以应用新的延迟时间
if (_eraserAutoSwitchBackTimer != null && _eraserAutoSwitchBackTimer.IsEnabled)
{
StartEraserAutoSwitchBackTimer();
}
LogHelper.WriteLogToFile($"橡皮擦自动切换延迟时间已更新为 {Settings.Canvas.EraserAutoSwitchBackDelaySeconds} 秒", LogHelper.LogType.Event);
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"更新橡皮擦自动切换延迟时间时出错: {ex.Message}", LogHelper.LogType.Error);
}
}
/// <summary>
/// 根据开关状态启用或禁用画笔自动恢复:更新设置并保存,启用时初始化并安排恢复定时器,禁用时停止计时器。
/// </summary>
@@ -383,7 +383,6 @@ namespace Ink_Canvas
/// <param name="e">事件参数。</param>
private void BtnWhiteBoardSwitchNext_Click(object sender, EventArgs e)
{
Trace.WriteLine("113223234");
if (Settings.Automation.IsAutoSaveStrokesAtClear &&
inkCanvas.Strokes.Count > Settings.Automation.MinimumAutomationStrokeNumber) SaveScreenShot(true);
+4 -1
View File
@@ -1,4 +1,4 @@
using System;
using System;
using System.Diagnostics;
using System.Linq;
using System.Windows;
@@ -174,6 +174,9 @@ namespace Ink_Canvas
AddedStroke = null;
ReplacedStroke = null;
}
// 橡皮擦自动切换回批注
HandleEraserOperationEnded();
}
/// <summary>
@@ -2267,6 +2267,9 @@ namespace Ink_Canvas
// 禁用高级橡皮擦系统
DisableEraserOverlay();
// 停止橡皮擦自动切换计时器(如果正在运行)
StopEraserAutoSwitchBackTimer();
SetFloatingBarHighlightPosition("pen");
// 记录当前是否已经是批注模式且是否为高光显示模式
@@ -2526,6 +2529,12 @@ namespace Ink_Canvas
HideSubPanels("eraser"); // 高亮橡皮按钮
Trace.WriteLine($"Eraser: Eraser button clicked, current size: {eraserWidth}, circle: {isEraserCircleShape}");
// 如果启用了橡皮擦自动切换功能,停止之前的计时器(如果正在运行)
if (Settings.Canvas.EnableEraserAutoSwitchBack)
{
StopEraserAutoSwitchBackTimer();
}
if (isAlreadyEraser)
{
// 已是橡皮状态,再次点击才弹出/收起面板
@@ -2570,6 +2579,12 @@ namespace Ink_Canvas
SetCursorBasedOnEditingMode(inkCanvas);
HideSubPanels("eraser"); // 高亮橡皮按钮
// 如果启用了橡皮擦自动切换功能,停止之前的计时器(如果正在运行)
if (Settings.Canvas.EnableEraserAutoSwitchBack)
{
StopEraserAutoSwitchBackTimer();
}
if (isAlreadyEraser)
{
// 已是橡皮状态,再次点击才弹出/收起面板
@@ -2564,6 +2564,7 @@ namespace Ink_Canvas
/// </remarks>
private void inkCanvas_MouseUp(object sender, MouseButtonEventArgs e)
{
HandleEraserOperationEnded(); // 橡皮擦自动切换回批注模式:松手后启动/重置计时
inkCanvas.ReleaseMouseCapture();
ViewboxFloatingBar.IsHitTestVisible = true;
BlackboardUIGridForInkReplay.IsHitTestVisible = true;
+103 -2
View File
@@ -123,7 +123,6 @@ namespace Ink_Canvas
/// NTP时间同步定时器
/// </summary>
private Timer timerNtpSync = new Timer();
/// <summary>
/// 时间视图模型实例
/// </summary>
@@ -156,7 +155,10 @@ namespace Ink_Canvas
/// 防止重复NTP同步的标志
/// </summary>
private bool isNtpSyncing = false;
/// <summary>
/// 橡皮擦自动切换回批注模式的计时器
/// </summary>
private DispatcherTimer _eraserAutoSwitchBackTimer;
/// <summary>
/// 异步获取网络时间
/// </summary>
@@ -248,6 +250,9 @@ namespace Ink_Canvas
// 初始化定时保存墨迹定时器
InitAutoSaveStrokesTimer();
// 初始化橡皮擦自动切换回批注模式计时器
InitEraserAutoSwitchBackTimer();
}
/// <summary>
@@ -1381,5 +1386,101 @@ namespace Ink_Canvas
LogHelper.WriteLogToFile($"AutoUpdate | Error resetting retry state: {ex.Message}", LogHelper.LogType.Error);
}
}
/// <summary>
/// 初始化橡皮擦自动切换回批注模式计时器
/// </summary>
private void InitEraserAutoSwitchBackTimer()
{
if (_eraserAutoSwitchBackTimer == null)
{
_eraserAutoSwitchBackTimer = new DispatcherTimer();
_eraserAutoSwitchBackTimer.Tick += EraserAutoSwitchBackTimer_Tick;
}
}
/// <summary>
/// 启动橡皮擦自动切换回批注模式计时器
/// </summary>
public void StartEraserAutoSwitchBackTimer()
{
try
{
if (!Settings.Canvas.EnableEraserAutoSwitchBack) return;
if (_eraserAutoSwitchBackTimer == null) InitEraserAutoSwitchBackTimer();
// 停止之前的计时器
_eraserAutoSwitchBackTimer.Stop();
// 设置计时器间隔
int delaySeconds = Settings.Canvas.EraserAutoSwitchBackDelaySeconds;
if (delaySeconds < 1) delaySeconds = 10; // 最小1秒
_eraserAutoSwitchBackTimer.Interval = TimeSpan.FromSeconds(delaySeconds);
// 启动计时器
_eraserAutoSwitchBackTimer.Start();
LogHelper.WriteLogToFile($"橡皮擦自动切换计时器已启动,延迟 {delaySeconds} 秒", LogHelper.LogType.Trace);
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"启动橡皮擦自动切换计时器失败: {ex.Message}", LogHelper.LogType.Error);
}
}
/// <summary>
/// 停止橡皮擦自动切换回批注模式计时器
/// </summary>
public void StopEraserAutoSwitchBackTimer()
{
try
{
if (_eraserAutoSwitchBackTimer != null)
{
_eraserAutoSwitchBackTimer.Stop();
LogHelper.WriteLogToFile("橡皮擦自动切换计时器已停止", LogHelper.LogType.Trace);
}
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"停止橡皮擦自动切换计时器失败: {ex.Message}", LogHelper.LogType.Error);
}
}
/// <summary>
/// 橡皮擦自动切换回批注模式计时器事件处理
/// </summary>
private void EraserAutoSwitchBackTimer_Tick(object sender, EventArgs e)
{
try
{
// 检查是否仍然在橡皮擦模式
if (inkCanvas.EditingMode != InkCanvasEditingMode.EraseByPoint &&
inkCanvas.EditingMode != InkCanvasEditingMode.EraseByStroke)
{
StopEraserAutoSwitchBackTimer();
return;
}
// 检查设置是否仍然启用
if (!Settings.Canvas.EnableEraserAutoSwitchBack)
{
StopEraserAutoSwitchBackTimer();
return;
}
// 切换到批注模式
Dispatcher.Invoke(() =>
{
PenIcon_Click(null, null);
StopEraserAutoSwitchBackTimer();
LogHelper.WriteLogToFile("橡皮擦自动切换回批注模式", LogHelper.LogType.Event);
});
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"橡皮擦自动切换计时器事件处理失败: {ex.Message}", LogHelper.LogType.Error);
}
}
}
}
+4
View File
@@ -140,6 +140,10 @@ namespace Ink_Canvas
public double BrushAutoRestoreWidth { get; set; } =5;
[JsonProperty("brushAutoRestoreAlpha")]
public int BrushAutoRestoreAlpha { get; set; } = 255;
[JsonProperty("enableEraserAutoSwitchBack")]
public bool EnableEraserAutoSwitchBack { get; set; } = false;
[JsonProperty("eraserAutoSwitchBackDelaySeconds")]
public int EraserAutoSwitchBackDelaySeconds { get; set; } = 10; // 默认10秒
}