Testing subtitle format dropdown for better dark theme

This commit is contained in:
niksedk 2023-07-29 09:43:14 +02:00
parent 814ad2cd09
commit 0419d372ce
8 changed files with 258 additions and 90 deletions

View File

@ -3115,5 +3115,10 @@ namespace Nikse.SubtitleEdit.Core.Common
return s;
}
public static SubtitleFormat GetSubtitleFormatByFriendlyName(object value)
{
throw new NotImplementedException();
}
}
}

View File

@ -79,7 +79,22 @@ namespace Nikse.SubtitleEdit.Controls
}
_selectedIndex = value;
_textBox.Text = Items[_selectedIndex].ToString();
SelectedIndexChanged?.Invoke(this, EventArgs.Empty);
Invalidate();
}
}
public object SelectedItem
{
get
{
if (_selectedIndex < 0)
{
return null;
}
return _items[_selectedIndex];
}
}
@ -141,6 +156,8 @@ namespace Nikse.SubtitleEdit.Controls
}
}
public Control DropDownControl => _listView;
private Color _buttonForeColor;
private Brush _buttonForeColorBrush;
[Category("NikseComboBox"), Description("Gets or sets the button foreground color"),
@ -158,6 +175,11 @@ namespace Nikse.SubtitleEdit.Controls
_buttonForeColor = value;
_buttonForeColorBrush?.Dispose();
_buttonForeColorBrush = new SolidBrush(_buttonForeColor);
if (_textBox != null)
{
_textBox.ForeColor = value;
}
Invalidate();
}
}
@ -486,85 +508,90 @@ namespace Nikse.SubtitleEdit.Controls
if (_buttonDownActive)
{
_listViewShown = true;
_textBox.Focus();
EnsureListViewInitialized();
_listView.BeginUpdate();
_listView.Items.Clear();
var listViewItems = new List<ListViewItem>();
foreach (var item in Items)
{
listViewItems.Add(new ListViewItem(item.ToString()));
}
_listView.Items.AddRange(listViewItems.ToArray());
_listView.Width = DropDownWidth;
_listView.EndUpdate();
var lvHeight = 5;
var top = Bottom;
var form = FindForm();
if (form == null)
{
return;
}
var ctl = (Control)this;
var totalX = ctl.Left;
var totalY = ctl.Top;
while (ctl.Parent != form)
{
ctl = ctl.Parent;
totalX += ctl.Left;
totalY += ctl.Top;
}
if (listViewItems.Count > 0)
{
var itemHeight = _listView.GetItemRect(0).Height;
lvHeight = itemHeight * listViewItems.Count + 6;
var spaceInPixelsTop = totalY;
var spaceInPixelsBottom = form.Height - (spaceInPixelsTop + Height);
var maxHeight = DropDownHeight;
if (spaceInPixelsBottom >= DropDownHeight ||
spaceInPixelsBottom * 1.2 > spaceInPixelsTop)
{
top = totalY + Height;
maxHeight = Math.Min(maxHeight, form.Height - Bottom - 18 - SystemInformation.CaptionHeight);
lvHeight = Math.Min(lvHeight, maxHeight);
}
else
{
maxHeight = Math.Min(maxHeight, spaceInPixelsTop - 18 - SystemInformation.CaptionHeight);
lvHeight = Math.Min(lvHeight, maxHeight);
top = totalY - lvHeight;
}
}
_listView.Height = lvHeight;
form.Controls.Add(_listView);
_listView.BringToFront();
_listView.Left = totalX;
_listView.Top = top;
if (_selectedIndex >= 0)
{
_listView.Focus();
_listView.Items[_selectedIndex].Selected = true;
_listView.EnsureVisible(_selectedIndex);
_listView.Items[_selectedIndex].Focused = true;
}
DropDown?.Invoke(this, EventArgs.Empty);
ShowListView();
}
Invalidate();
}
base.OnMouseDown(e);
}
private void ShowListView()
{
_textBox.Focus();
_listViewShown = true;
EnsureListViewInitialized();
_listView.BeginUpdate();
_listView.Items.Clear();
var listViewItems = new List<ListViewItem>();
foreach (var item in Items)
{
listViewItems.Add(new ListViewItem(item.ToString()));
}
_listView.Items.AddRange(listViewItems.ToArray());
_listView.Width = DropDownWidth;
_listView.EndUpdate();
var lvHeight = 5;
var top = Bottom;
var form = FindForm();
if (form == null)
{
return;
}
var ctl = (Control)this;
var totalX = ctl.Left;
var totalY = ctl.Top;
while (ctl.Parent != form)
{
ctl = ctl.Parent;
totalX += ctl.Left;
totalY += ctl.Top;
}
if (listViewItems.Count > 0)
{
var itemHeight = _listView.GetItemRect(0).Height;
lvHeight = itemHeight * listViewItems.Count + 6;
var spaceInPixelsBottom = form.Height - (totalY + Height);
var maxHeight = DropDownHeight;
if (spaceInPixelsBottom >= DropDownHeight ||
spaceInPixelsBottom * 1.2 > totalY)
{
top = totalY + Height;
maxHeight = Math.Min(maxHeight, form.Height - Bottom - 18 - SystemInformation.CaptionHeight);
lvHeight = Math.Min(lvHeight, maxHeight);
}
else
{
maxHeight = Math.Min(maxHeight, totalY - 18 - SystemInformation.CaptionHeight);
lvHeight = Math.Min(lvHeight, maxHeight);
top = totalY - lvHeight;
}
}
_listView.Height = lvHeight;
form.Controls.Add(_listView);
_listView.BringToFront();
_listView.Left = totalX;
_listView.Top = top;
if (_selectedIndex >= 0)
{
_listView.Focus();
_listView.Items[_selectedIndex].Selected = true;
_listView.EnsureVisible(_selectedIndex);
_listView.Items[_selectedIndex].Focused = true;
}
DropDown?.Invoke(this, EventArgs.Empty);
Invalidate();
}
private void EnsureListViewInitialized()
{
if (_listView != null)
@ -586,7 +613,7 @@ namespace Nikse.SubtitleEdit.Controls
}
_listView.MouseEnter += (sender, args) => { _hasItemsMouseOver = true; };
_listView.KeyDown += (sender, args) =>
{
if (args.KeyCode == Keys.Escape)
@ -678,6 +705,11 @@ namespace Nikse.SubtitleEdit.Controls
protected override void OnPaint(PaintEventArgs e)
{
if (_skipPaint)
{
return;
}
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
_textBox.BackColor = BackColor;
@ -732,6 +764,8 @@ namespace Nikse.SubtitleEdit.Controls
}
}
public bool DroppedDown => _listViewShown;
private static void DrawArrowDown(PaintEventArgs e, Brush brush, int left, int top, int height)
{
e.Graphics.FillPolygon(brush,
@ -766,5 +800,18 @@ namespace Nikse.SubtitleEdit.Controls
DrawArrowDown(e, brush, left, top, height);
}
}
private bool _skipPaint = false;
public void BeginUpdate()
{
_skipPaint = true;
}
public void EndUpdate()
{
_skipPaint = false;
Invalidate();
}
}
}

View File

@ -164,6 +164,8 @@ namespace Nikse.SubtitleEdit.Controls
}
}
public static Color DefaultBackColorDisabled = Color.FromArgb(240, 240, 240);
private Color _backColorDisabled;
[Category("NikseUpDown"), Description("Gets or sets the button foreground color"),
RefreshProperties(RefreshProperties.Repaint)]
@ -236,7 +238,7 @@ namespace Nikse.SubtitleEdit.Controls
ButtonForeColorDown = Color.Orange;
BorderColor = Color.FromArgb(171, 173, 179);
BorderColorDisabled = Color.FromArgb(120, 120, 120);
BackColorDisabled = Color.FromArgb(240, 240, 240);
BackColorDisabled = DefaultBackColorDisabled;
DoubleBuffered = true;
InterceptArrowKeys = true;

View File

@ -3,11 +3,9 @@ using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using System.Windows.Forms;
using System.Windows.Forms.Design;
namespace Nikse.SubtitleEdit.Controls
{
[ToolStripItemDesignerAvailability(ToolStripItemDesignerAvailability.ToolStrip)]
public class ToolStripNikseComboBox : ToolStripControlHost
{
// ReSharper disable once InconsistentNaming
@ -32,12 +30,17 @@ namespace Nikse.SubtitleEdit.Controls
private void Init()
{
if (DesignMode)
{
return;
}
if (Control is ToolStripNikseComboBoxControl cbc)
{
cbc.Owner = this;
}
Padding = new Padding(6);
Padding = new Padding(7);
ComboBox.SelectedIndexChanged += (sender, args) =>
{
@ -76,7 +79,7 @@ namespace Nikse.SubtitleEdit.Controls
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[Editor("System.Windows.Forms.Design.ListControlStringCollectionEditor, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))]
public NikseComboBoxCollection Items => ComboBox.Items;
public NikseComboBoxCollection Items => ComboBox?.Items;
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
@ -94,6 +97,18 @@ namespace Nikse.SubtitleEdit.Controls
set => ComboBox.SelectedText = value;
}
public ComboBoxStyle DropDownStyle
{
get => ComboBox.DropDownStyle;
set => ComboBox.DropDownStyle = value;
}
public int DropDownHeight
{
get => ComboBox.DropDownHeight;
set => ComboBox.DropDownHeight = value;
}
public Color ButtonForeColor
{
get => ComboBox.ButtonForeColor;
@ -130,6 +145,10 @@ namespace Nikse.SubtitleEdit.Controls
set => ComboBox.BorderColor = value;
}
public object SelectedItem => ComboBox.SelectedItem;
public bool DroppedDown => ComboBox.DroppedDown;
internal class ToolStripNikseComboBoxControl : NikseComboBox
{
public ToolStripNikseComboBoxControl()
@ -139,7 +158,15 @@ namespace Nikse.SubtitleEdit.Controls
public ToolStripNikseComboBox Owner { get; set; }
}
public void BeginUpdate()
{
ComboBox?.BeginUpdate();
}
public void EndUpdate()
{
ComboBox?.EndUpdate();
}
}
}

View File

@ -76,7 +76,7 @@
this.toolStripButtonToggleVideo = new System.Windows.Forms.ToolStripButton();
this.toolStripSeparatorSubtitleFormat = new System.Windows.Forms.ToolStripSeparator();
this.toolStripLabelSubtitleFormat = new System.Windows.Forms.ToolStripLabel();
this.comboBoxSubtitleFormats = new System.Windows.Forms.ToolStripComboBox();
this.comboBoxSubtitleFormats = new Nikse.SubtitleEdit.Controls.ToolStripNikseComboBox();
this.toolStripSeparatorEncoding = new System.Windows.Forms.ToolStripSeparator();
this.toolStripLabelEncoding = new System.Windows.Forms.ToolStripLabel();
this.comboBoxEncoding = new System.Windows.Forms.ToolStripComboBox();
@ -1032,10 +1032,10 @@
//
// comboBoxSubtitleFormats
//
this.comboBoxSubtitleFormats.DropDownHeight = 215;
this.comboBoxSubtitleFormats.DropDownHeight = 295;
this.comboBoxSubtitleFormats.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxSubtitleFormats.FlatStyle = System.Windows.Forms.FlatStyle.Standard;
this.comboBoxSubtitleFormats.IntegralHeight = false;
//this.comboBoxSubtitleFormats.FlatStyle = System.Windows.Forms.FlatStyle.Standard;
//this.comboBoxSubtitleFormats.IntegralHeight = false;
this.comboBoxSubtitleFormats.Name = "comboBoxSubtitleFormats";
this.comboBoxSubtitleFormats.Size = new System.Drawing.Size(150, 23);
this.comboBoxSubtitleFormats.DropDown += new System.EventHandler(this.comboBoxSubtitleFormats_DropDown);
@ -5969,7 +5969,7 @@
private System.Windows.Forms.Timer timerAutoDuration;
private System.Windows.Forms.Label labelAutoDuration;
private System.Windows.Forms.Timer timerAutoContinue;
private System.Windows.Forms.ToolStripComboBox comboBoxSubtitleFormats;
private Nikse.SubtitleEdit.Controls.ToolStripNikseComboBox comboBoxSubtitleFormats;
private System.Windows.Forms.ToolStripSeparator toolStripSeparatorToggle;
private System.Windows.Forms.ToolStripSeparator toolStripSeparatorSubtitleFormat;
private System.Windows.Forms.ToolStripLabel toolStripLabelSubtitleFormat;

View File

@ -25146,8 +25146,9 @@ namespace Nikse.SubtitleEdit.Forms
_changeSubtitleHash = GetFastSubtitleHash();
}
comboBoxSubtitleFormats.AutoCompleteSource = AutoCompleteSource.ListItems;
comboBoxSubtitleFormats.AutoCompleteMode = AutoCompleteMode.Append;
//TODO:
//comboBoxSubtitleFormats.AutoCompleteSource = AutoCompleteSource.ListItems;
//comboBoxSubtitleFormats.AutoCompleteMode = AutoCompleteMode.Append;
InitializePlayRateDropDown();
LoadPlugins();

View File

@ -111,6 +111,14 @@ namespace Nikse.SubtitleEdit.Logic
c.FlatStyle = FlatStyle.Flat;
}
var toolStripNikseComboBox = GetSubControls<ToolStripNikseComboBox>(form);
foreach (ToolStripNikseComboBox c in toolStripNikseComboBox)
{
c.BackColor = BackColor;
c.ForeColor = ForeColor;
SetDarkTheme(c.ComboBox);
}
var toolStripContentPanels = GetSubControls<ToolStripContentPanel>(form);
foreach (ToolStripContentPanel c in toolStripContentPanels)
{
@ -205,6 +213,14 @@ namespace Nikse.SubtitleEdit.Logic
c.FlatStyle = FlatStyle.Flat;
}
var toolStripNikseComboBox = GetSubControls<ToolStripNikseComboBox>(form);
foreach (ToolStripNikseComboBox c in toolStripNikseComboBox)
{
c.BackColor = BackColor;
c.ForeColor = ForeColor;
UnFixControl(c.ComboBox);
}
var toolStripContentPanels = GetSubControls<ToolStripContentPanel>(form);
foreach (ToolStripContentPanel c in toolStripContentPanels)
{
@ -263,7 +279,7 @@ namespace Nikse.SubtitleEdit.Logic
{
c.BackColor = Control.DefaultBackColor;
c.ForeColor = Control.DefaultForeColor;
var buttonBackColor = SystemColors.Window;
var buttonBackColor = SystemColors.Window;
if (c is Button b)
{
@ -366,18 +382,26 @@ namespace Nikse.SubtitleEdit.Logic
ud.BackColor = buttonBackColor;
ud.ForeColor = Control.DefaultForeColor;
ud.ButtonForeColor = Control.DefaultForeColor;
ud.BackColorDisabled = NikseUpDown.DefaultBackColorDisabled;
}
else if (c is NikseTimeUpDown tud)
{
tud.BackColor = buttonBackColor;
tud.ForeColor = Control.DefaultForeColor;
tud.ButtonForeColor = Control.DefaultForeColor;
tud.BackColorDisabled = NikseUpDown.DefaultBackColorDisabled;
}
else if (c is NikseComboBox ncb)
{
ncb.BackColor = buttonBackColor;
ncb.ForeColor = Control.DefaultForeColor;
ncb.ButtonForeColor = Control.DefaultForeColor;
ncb.BorderColor = Color.LightGray;
ncb.BackColorDisabled = NikseUpDown.DefaultBackColorDisabled; ;
if (ncb.DropDownControl != null)
{
UnFixControl(ncb.DropDownControl);
}
}
else if (c is Button bu)
{
@ -452,7 +476,7 @@ namespace Nikse.SubtitleEdit.Logic
if (c is GroupBox gBox)
{
gBox.Paint += PaintBorderDarkGray;
gBox.Paint += PaintBorderDarkGray;
}
if (c is NumericUpDown numeric)
@ -543,6 +567,11 @@ namespace Nikse.SubtitleEdit.Logic
ncb.ForeColor = ForeColor;
ncb.ButtonForeColor = ForeColor;
ncb.BackColorDisabled = BackColor;
ncb.BorderColor = Color.Gray;
if (ncb.DropDownControl != null)
{
FixControl(ncb.DropDownControl);
}
}
}

View File

@ -774,6 +774,17 @@ namespace Nikse.SubtitleEdit.Logic
comboBox.DropDownWidth += 5; // .Net quirk?
}
public static void InitializeSubtitleFormatComboBox(ToolStripNikseComboBox comboBox, SubtitleFormat format)
{
InitializeSubtitleFormatComboBox(comboBox.ComboBox, format);
//comboBox.DropDownWidth += 5; // .Net quirk?
}
public static void InitializeSubtitleFormatComboBox(NikseComboBox comboBox, SubtitleFormat format)
{
InitializeSubtitleFormatComboBox(comboBox, new List<string> { format.FriendlyName }, format.FriendlyName);
}
public static void InitializeSubtitleFormatComboBox(ComboBox comboBox, SubtitleFormat format)
{
InitializeSubtitleFormatComboBox(comboBox, new List<string> { format.FriendlyName }, format.FriendlyName);
@ -785,12 +796,24 @@ namespace Nikse.SubtitleEdit.Logic
comboBox.DropDownWidth += 5; // .Net quirk?
}
public static void InitializeSubtitleFormatComboBox(ToolStripNikseComboBox comboBox, string selectedName)
{
InitializeSubtitleFormatComboBox(comboBox.ComboBox, selectedName);
//comboBox.DropDownWidth += 5; // .Net quirk?
}
public static void InitializeSubtitleFormatComboBox(ComboBox comboBox, string selectedName)
{
var formatNames = SubtitleFormat.AllSubtitleFormats.Where(format => !format.IsVobSubIndexFile).Select(format => format.FriendlyName);
InitializeSubtitleFormatComboBox(comboBox, formatNames.ToList(), selectedName);
}
public static void InitializeSubtitleFormatComboBox(NikseComboBox comboBox, string selectedName)
{
var formatNames = SubtitleFormat.AllSubtitleFormats.Where(format => !format.IsVobSubIndexFile).Select(format => format.FriendlyName);
InitializeSubtitleFormatComboBox(comboBox, formatNames.ToList(), selectedName);
}
public static void InitializeSubtitleFormatComboBox(ComboBox comboBox, List<string> formatNames, string selectedName)
{
var selectedIndex = 0;
@ -825,6 +848,40 @@ namespace Nikse.SubtitleEdit.Logic
comboBox.EndUpdate();
}
public static void InitializeSubtitleFormatComboBox(NikseComboBox comboBox, List<string> formatNames, string selectedName)
{
var selectedIndex = 0;
using (var graphics = comboBox.CreateGraphics())
{
var maxWidth = (float)comboBox.DropDownWidth;
var max = formatNames.Count;
for (var index = 0; index < max; index++)
{
var name = formatNames[index];
if (name.Equals(selectedName, StringComparison.OrdinalIgnoreCase))
{
selectedIndex = index;
}
if (name.Length > 30)
{
var width = graphics.MeasureString(name, comboBox.Font).Width;
if (width > maxWidth)
{
maxWidth = width;
}
}
}
comboBox.DropDownWidth = (int)Math.Round(maxWidth + 17.5);
}
comboBox.BeginUpdate();
comboBox.Items.Clear();
comboBox.Items.AddRange(formatNames.ToArray<object>());
comboBox.SelectedIndex = selectedIndex;
comboBox.EndUpdate();
}
public static void InitializeTextEncodingComboBox(ComboBox comboBox)
{
var defaultEncoding = Configuration.Settings.General.DefaultEncoding;