Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions OpenUtau/Controls/PianoRoll.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@
<CheckBox IsChecked="{Binding PianoRollDetached}" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="{DynamicResource pianoroll.menu.view.pianoroll.hide}" Click="OnMenuHidePianoRoll"/>
<MenuItem Header="{DynamicResource pianoroll.menu.view.pianoroll.hide}" Click="OnMenuHidePianoRoll" IsVisible="{Binding HideMenuItemVisible}"/>
</MenuItem>
</MenuItem>

Expand Down Expand Up @@ -538,6 +538,7 @@
</Button>
</StackPanel>
</Border>
<Border Grid.Column="3" Background="Transparent" PointerPressed="OnToolbarPointerPressed"/>
<Border Grid.Column="4">
<StackPanel Orientation="Horizontal">
<ToggleButton Classes="toolbar" Margin="0" Padding="1" Height="20" Width="20" IsChecked="{Binding NotesViewModel.ShowNoteParams}"
Expand All @@ -553,6 +554,10 @@
</Path>
</Grid>
</ToggleButton>
<!-- 占位:内嵌模式 + 参数面板收起时显示,空出位置给浮动关闭按钮,避免重叠 -->
<Border IsVisible="{Binding HideMenuItemVisible}">
<Border Width="20" IsVisible="{Binding !NotesViewModel.ShowNoteParams}"/>
</Border>
</StackPanel>
</Border>
</Grid>
Expand Down Expand Up @@ -626,6 +631,20 @@
<c:NotePropertiesControl/>
</Border>

<!-- 关闭钢琴卷帘按钮:始终浮在最右上角,位置固定 -->
<ToggleButton x:Name="HidePianoRollButton"
Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="4"
Classes="toolbar" Margin="0,2,4,0"
HorizontalAlignment="Right" VerticalAlignment="Top"
Height="20" Width="20" Padding="1"
Click="OnMenuHidePianoRoll"
IsVisible="{Binding HideMenuItemVisible}"
ToolTip.Tip="{DynamicResource pianoroll.menu.view.pianoroll.hide}">
<Grid Width="18" Height="18">
<Path Stroke="{DynamicResource SystemControlForegroundBaseHighBrush}" StrokeThickness="1" Data="M 4 4 L 14 14 M 14 4 L 4 14"/>
</Grid>
</ToggleButton>

<Border Grid.Row="2" Grid.RowSpan="2" Grid.Column="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
BoxShadow="inset 0 0 5 1 #3F000000" ClipToBounds="True" IsHitTestVisible="False">
<Grid>
Expand Down Expand Up @@ -678,4 +697,4 @@
<ProgressBar Grid.Row="6" Grid.ColumnSpan="4" Value="{Binding Progress}" IsVisible="{Binding PianoRollDetached}"/>
</Grid>
</Border>
</UserControl>
</UserControl>
39 changes: 37 additions & 2 deletions OpenUtau/Controls/PianoRoll.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
Expand All @@ -11,6 +11,7 @@
using Avalonia.Controls.Primitives;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.Threading;
using OpenUtau.App.ViewModels;
using OpenUtau.App.Views;
using OpenUtau.Core;
Expand Down Expand Up @@ -349,9 +350,25 @@ void OnMenuSearchNote(object sender, RoutedEventArgs args) {
void OnMenuDetachPianoRoll(object sender, RoutedEventArgs args) {
MainWindow?.SetPianoRollAttachment();
ViewModel.RaisePropertyChanged(nameof(ViewModel.PianoRollDetached));
// 延迟通知,等窗口切换完成后再更新,避免切换过程中触发 UI 更新导致崩溃
Dispatcher.UIThread.Post(() => {
ViewModel.RaisePropertyChanged(nameof(ViewModel.HideMenuItemVisible));
});
}

void OnMenuHidePianoRoll(object sender, RoutedEventArgs args) {
// Reset ToggleButton checked state / 重置 ToggleButton 的 checked 状态
// Reason / 原因:
// ToggleButton keeps IsChecked=true after click, causing darker background.
// But this close button is a one-shot action, not a state toggle.
// So we manually reset it to false immediately after click.
// Since piano roll hides instantly, users never see this momentary state change.
//
// 详细说明:
// ToggleButton 点击后会保持 IsChecked=true,导致底纹变深。
// 但关闭按钮是一次性操作,不应该保持状态,所以手动重置为 false。
// 因为点击后钢琴卷帘立即隐藏,用户看不到这个瞬间的状态变化。
HidePianoRollButton.IsChecked = false;
if (RootWindow.DataContext is MainWindowViewModel mwvm) {
mwvm.ShowPianoRoll = false;
} else {
Expand All @@ -360,6 +377,24 @@ void OnMenuHidePianoRoll(object sender, RoutedEventArgs args) {
}

// Edit Tools
private long _lastToolbarClickTime = 0;
private const long DoubleClickThreshold = 300; // 毫秒

void OnToolbarPointerPressed(object sender, PointerPressedEventArgs args) {
// 双击工具栏空白处关闭钢琴卷帘(仅嵌入模式生效)
if (!args.GetCurrentPoint(this).Properties.IsLeftButtonPressed) return;

long now = DateTimeOffset.Now.ToUnixTimeMilliseconds();
if (now - _lastToolbarClickTime < DoubleClickThreshold) {
// 双击
if (RootWindow.DataContext is MainWindowViewModel mwvm) {
mwvm.ShowPianoRoll = false;
}
// 分离模式下不响应,保持和原来一模一样
}
_lastToolbarClickTime = now;
}

private CancellationTokenSource? _longPressCts;
private async void OnToolButtonPointerPressed(object? sender, PointerPressedEventArgs args) {
if (!args.GetCurrentPoint(this).Properties.IsLeftButtonPressed) return;
Expand Down Expand Up @@ -2017,4 +2052,4 @@ public void OnNext(UCommand cmd, bool isUndo) {
}
}
}
}
}
5 changes: 3 additions & 2 deletions OpenUtau/ViewModels/PianoRollViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive;
Expand Down Expand Up @@ -68,6 +68,7 @@ public class PianoRollViewModel : ViewModelBase, ICmdSubscriber {
public bool PlaybackAutoScroll1 { get => Preferences.Default.PlaybackAutoScroll == 1 ? true : false; }
public bool PlaybackAutoScroll2 { get => Preferences.Default.PlaybackAutoScroll == 2 ? true : false; }
public bool PianoRollDetached { get => Preferences.Default.DetachPianoRoll; }
public bool HideMenuItemVisible => !Preferences.Default.DetachPianoRoll;
public bool ShowPhonemizerTags {
get => Preferences.Default.ShowPhonemizerTags;
set {
Expand Down Expand Up @@ -319,4 +320,4 @@ public void OnNext(UCommand cmd, bool isUndo) {

#endregion
}
}
}