From 496830d01d41c174a8a1de4f2b128e8258e205e4 Mon Sep 17 00:00:00 2001 From: Michael Bucari-Tovo Date: Fri, 30 Dec 2022 19:25:11 -0700 Subject: [PATCH] Fix cell editor to work with desktop scaling --- .../GridView/LibraryBookEntry.cs | 2 +- .../GridView/MyRatingCellEditor.Designer.cs | 384 ++++++++++++++++++ ...{RatingPicker.cs => MyRatingCellEditor.cs} | 51 ++- ...ingPicker.resx => MyRatingCellEditor.resx} | 0 .../GridView/MyRatingGridViewColumn.cs | 58 +-- .../GridView/RatingPicker.Designer.cs | 348 ---------------- .../LibationWinForms/GridView/SeriesEntry.cs | 2 +- 7 files changed, 431 insertions(+), 414 deletions(-) create mode 100644 Source/LibationWinForms/GridView/MyRatingCellEditor.Designer.cs rename Source/LibationWinForms/GridView/{RatingPicker.cs => MyRatingCellEditor.cs} (77%) rename Source/LibationWinForms/GridView/{RatingPicker.resx => MyRatingCellEditor.resx} (100%) delete mode 100644 Source/LibationWinForms/GridView/RatingPicker.Designer.cs diff --git a/Source/LibationWinForms/GridView/LibraryBookEntry.cs b/Source/LibationWinForms/GridView/LibraryBookEntry.cs index 315232b8..ce029c79 100644 --- a/Source/LibationWinForms/GridView/LibraryBookEntry.cs +++ b/Source/LibationWinForms/GridView/LibraryBookEntry.cs @@ -80,7 +80,7 @@ namespace LibationWinForms.GridView Title = Book.Title; Series = Book.SeriesNames(); Length = Book.LengthInMinutes == 0 ? "" : $"{Book.LengthInMinutes / 60} hr {Book.LengthInMinutes % 60} min"; - MyRating = Book.UserDefinedItem.Rating; + _myRating = Book.UserDefinedItem.Rating; PurchaseDate = libraryBook.DateAdded.ToString("d"); ProductRating = Book.Rating?.ToStarString()?.DefaultIfNullOrWhiteSpace(""); Authors = Book.AuthorNames(); diff --git a/Source/LibationWinForms/GridView/MyRatingCellEditor.Designer.cs b/Source/LibationWinForms/GridView/MyRatingCellEditor.Designer.cs new file mode 100644 index 00000000..943847fc --- /dev/null +++ b/Source/LibationWinForms/GridView/MyRatingCellEditor.Designer.cs @@ -0,0 +1,384 @@ +namespace LibationWinForms.GridView +{ + partial class MyRatingCellEditor + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.lblOverall = new System.Windows.Forms.Label(); + this.lblPerform = new System.Windows.Forms.Label(); + this.lblStory = new System.Windows.Forms.Label(); + this.starOverall1 = new System.Windows.Forms.Label(); + this.starOverall2 = new System.Windows.Forms.Label(); + this.starOverall3 = new System.Windows.Forms.Label(); + this.starOverall4 = new System.Windows.Forms.Label(); + this.starOverall5 = new System.Windows.Forms.Label(); + this.panelOverall = new System.Windows.Forms.Panel(); + this.panelPerform = new System.Windows.Forms.Panel(); + this.starPerform1 = new System.Windows.Forms.Label(); + this.starPerform2 = new System.Windows.Forms.Label(); + this.starPerform3 = new System.Windows.Forms.Label(); + this.starPerform4 = new System.Windows.Forms.Label(); + this.starPerform5 = new System.Windows.Forms.Label(); + this.panelStory = new System.Windows.Forms.Panel(); + this.starStory1 = new System.Windows.Forms.Label(); + this.starStory2 = new System.Windows.Forms.Label(); + this.starStory3 = new System.Windows.Forms.Label(); + this.starStory4 = new System.Windows.Forms.Label(); + this.starStory5 = new System.Windows.Forms.Label(); + this.panelOverall.SuspendLayout(); + this.panelPerform.SuspendLayout(); + this.panelStory.SuspendLayout(); + this.SuspendLayout(); + // + // lblOverall + // + this.lblOverall.Anchor = System.Windows.Forms.AnchorStyles.Left; + this.lblOverall.AutoSize = true; + this.lblOverall.Location = new System.Drawing.Point(0, 0); + this.lblOverall.Margin = new System.Windows.Forms.Padding(0); + this.lblOverall.Name = "lblOverall"; + this.lblOverall.Size = new System.Drawing.Size(47, 15); + this.lblOverall.TabIndex = 6; + this.lblOverall.Text = "Overall:"; + // + // lblPerform + // + this.lblPerform.Anchor = System.Windows.Forms.AnchorStyles.Left; + this.lblPerform.AutoSize = true; + this.lblPerform.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.lblPerform.Location = new System.Drawing.Point(0, 15); + this.lblPerform.Margin = new System.Windows.Forms.Padding(0); + this.lblPerform.Name = "lblPerform"; + this.lblPerform.Size = new System.Drawing.Size(53, 15); + this.lblPerform.TabIndex = 8; + this.lblPerform.Text = "Perform:"; + // + // lblStory + // + this.lblStory.Anchor = System.Windows.Forms.AnchorStyles.Left; + this.lblStory.AutoSize = true; + this.lblStory.Location = new System.Drawing.Point(0, 30); + this.lblStory.Margin = new System.Windows.Forms.Padding(0); + this.lblStory.Name = "lblStory"; + this.lblStory.Size = new System.Drawing.Size(37, 15); + this.lblStory.TabIndex = 10; + this.lblStory.Text = "Story:"; + // + // starOverall1 + // + this.starOverall1.Font = new System.Drawing.Font("Segoe UI", 6.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.starOverall1.Location = new System.Drawing.Point(0, 0); + this.starOverall1.Margin = new System.Windows.Forms.Padding(0); + this.starOverall1.Name = "starOverall1"; + this.starOverall1.Size = new System.Drawing.Size(9, 10); + this.starOverall1.TabIndex = 0; + this.starOverall1.Text = "☆"; + this.starOverall1.UseCompatibleTextRendering = true; + this.starOverall1.MouseClick += new System.Windows.Forms.MouseEventHandler(this.Star_MouseClick); + this.starOverall1.MouseEnter += new System.EventHandler(this.Star_MouseEnter); + this.starOverall1.MouseLeave += new System.EventHandler(this.Star_MouseLeave); + // + // starOverall2 + // + this.starOverall2.Font = new System.Drawing.Font("Segoe UI", 6.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.starOverall2.Location = new System.Drawing.Point(9, 0); + this.starOverall2.Margin = new System.Windows.Forms.Padding(0); + this.starOverall2.Name = "starOverall2"; + this.starOverall2.Size = new System.Drawing.Size(9, 10); + this.starOverall2.TabIndex = 1; + this.starOverall2.Text = "☆"; + this.starOverall2.UseCompatibleTextRendering = true; + this.starOverall2.MouseClick += new System.Windows.Forms.MouseEventHandler(this.Star_MouseClick); + this.starOverall2.MouseEnter += new System.EventHandler(this.Star_MouseEnter); + this.starOverall2.MouseLeave += new System.EventHandler(this.Star_MouseLeave); + // + // starOverall3 + // + this.starOverall3.Font = new System.Drawing.Font("Segoe UI", 6.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.starOverall3.Location = new System.Drawing.Point(18, 0); + this.starOverall3.Margin = new System.Windows.Forms.Padding(0); + this.starOverall3.Name = "starOverall3"; + this.starOverall3.Size = new System.Drawing.Size(9, 10); + this.starOverall3.TabIndex = 3; + this.starOverall3.Text = "☆"; + this.starOverall3.UseCompatibleTextRendering = true; + this.starOverall3.MouseClick += new System.Windows.Forms.MouseEventHandler(this.Star_MouseClick); + this.starOverall3.MouseEnter += new System.EventHandler(this.Star_MouseEnter); + this.starOverall3.MouseLeave += new System.EventHandler(this.Star_MouseLeave); + // + // starOverall4 + // + this.starOverall4.Font = new System.Drawing.Font("Segoe UI", 6.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.starOverall4.Location = new System.Drawing.Point(27, 0); + this.starOverall4.Margin = new System.Windows.Forms.Padding(0); + this.starOverall4.Name = "starOverall4"; + this.starOverall4.Size = new System.Drawing.Size(9, 10); + this.starOverall4.TabIndex = 2; + this.starOverall4.Text = "☆"; + this.starOverall4.UseCompatibleTextRendering = true; + this.starOverall4.MouseClick += new System.Windows.Forms.MouseEventHandler(this.Star_MouseClick); + this.starOverall4.MouseEnter += new System.EventHandler(this.Star_MouseEnter); + this.starOverall4.MouseLeave += new System.EventHandler(this.Star_MouseLeave); + // + // starOverall5 + // + this.starOverall5.Font = new System.Drawing.Font("Segoe UI", 6.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.starOverall5.Location = new System.Drawing.Point(36, 0); + this.starOverall5.Margin = new System.Windows.Forms.Padding(0); + this.starOverall5.Name = "starOverall5"; + this.starOverall5.Size = new System.Drawing.Size(9, 10); + this.starOverall5.TabIndex = 4; + this.starOverall5.Text = "☆"; + this.starOverall5.UseCompatibleTextRendering = true; + this.starOverall5.MouseClick += new System.Windows.Forms.MouseEventHandler(this.Star_MouseClick); + this.starOverall5.MouseEnter += new System.EventHandler(this.Star_MouseEnter); + this.starOverall5.MouseLeave += new System.EventHandler(this.Star_MouseLeave); + // + // panelOverall + // + this.panelOverall.Anchor = System.Windows.Forms.AnchorStyles.Left; + this.panelOverall.Controls.Add(this.starOverall1); + this.panelOverall.Controls.Add(this.starOverall2); + this.panelOverall.Controls.Add(this.starOverall3); + this.panelOverall.Controls.Add(this.starOverall4); + this.panelOverall.Controls.Add(this.starOverall5); + this.panelOverall.Location = new System.Drawing.Point(55, 3); + this.panelOverall.Name = "panelOverall"; + this.panelOverall.Size = new System.Drawing.Size(45, 10); + this.panelOverall.TabIndex = 5; + // + // panelPerform + // + this.panelPerform.Anchor = System.Windows.Forms.AnchorStyles.Left; + this.panelPerform.Controls.Add(this.starPerform1); + this.panelPerform.Controls.Add(this.starPerform2); + this.panelPerform.Controls.Add(this.starPerform3); + this.panelPerform.Controls.Add(this.starPerform4); + this.panelPerform.Controls.Add(this.starPerform5); + this.panelPerform.Location = new System.Drawing.Point(55, 18); + this.panelPerform.Name = "panelPerform"; + this.panelPerform.Size = new System.Drawing.Size(45, 10); + this.panelPerform.TabIndex = 7; + // + // starPerform1 + // + this.starPerform1.Font = new System.Drawing.Font("Segoe UI", 6.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.starPerform1.Location = new System.Drawing.Point(0, 0); + this.starPerform1.Margin = new System.Windows.Forms.Padding(0); + this.starPerform1.Name = "starPerform1"; + this.starPerform1.Size = new System.Drawing.Size(9, 10); + this.starPerform1.TabIndex = 0; + this.starPerform1.Text = "☆"; + this.starPerform1.UseCompatibleTextRendering = true; + this.starPerform1.MouseClick += new System.Windows.Forms.MouseEventHandler(this.Star_MouseClick); + this.starPerform1.MouseEnter += new System.EventHandler(this.Star_MouseEnter); + this.starPerform1.MouseLeave += new System.EventHandler(this.Star_MouseLeave); + // + // starPerform2 + // + this.starPerform2.Font = new System.Drawing.Font("Segoe UI", 6.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.starPerform2.Location = new System.Drawing.Point(9, 0); + this.starPerform2.Margin = new System.Windows.Forms.Padding(0); + this.starPerform2.Name = "starPerform2"; + this.starPerform2.Size = new System.Drawing.Size(9, 10); + this.starPerform2.TabIndex = 1; + this.starPerform2.Text = "☆"; + this.starPerform2.UseCompatibleTextRendering = true; + this.starPerform2.MouseClick += new System.Windows.Forms.MouseEventHandler(this.Star_MouseClick); + this.starPerform2.MouseEnter += new System.EventHandler(this.Star_MouseEnter); + this.starPerform2.MouseLeave += new System.EventHandler(this.Star_MouseLeave); + // + // starPerform3 + // + this.starPerform3.Font = new System.Drawing.Font("Segoe UI", 6.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.starPerform3.Location = new System.Drawing.Point(18, 0); + this.starPerform3.Margin = new System.Windows.Forms.Padding(0); + this.starPerform3.Name = "starPerform3"; + this.starPerform3.Size = new System.Drawing.Size(9, 10); + this.starPerform3.TabIndex = 3; + this.starPerform3.Text = "☆"; + this.starPerform3.UseCompatibleTextRendering = true; + this.starPerform3.MouseClick += new System.Windows.Forms.MouseEventHandler(this.Star_MouseClick); + this.starPerform3.MouseEnter += new System.EventHandler(this.Star_MouseEnter); + this.starPerform3.MouseLeave += new System.EventHandler(this.Star_MouseLeave); + // + // starPerform4 + // + this.starPerform4.Font = new System.Drawing.Font("Segoe UI", 6.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.starPerform4.Location = new System.Drawing.Point(27, 0); + this.starPerform4.Margin = new System.Windows.Forms.Padding(0); + this.starPerform4.Name = "starPerform4"; + this.starPerform4.Size = new System.Drawing.Size(9, 10); + this.starPerform4.TabIndex = 2; + this.starPerform4.Text = "☆"; + this.starPerform4.UseCompatibleTextRendering = true; + this.starPerform4.MouseClick += new System.Windows.Forms.MouseEventHandler(this.Star_MouseClick); + this.starPerform4.MouseEnter += new System.EventHandler(this.Star_MouseEnter); + this.starPerform4.MouseLeave += new System.EventHandler(this.Star_MouseLeave); + // + // starPerform5 + // + this.starPerform5.Font = new System.Drawing.Font("Segoe UI", 6.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.starPerform5.Location = new System.Drawing.Point(36, 0); + this.starPerform5.Margin = new System.Windows.Forms.Padding(0); + this.starPerform5.Name = "starPerform5"; + this.starPerform5.Size = new System.Drawing.Size(9, 10); + this.starPerform5.TabIndex = 4; + this.starPerform5.Text = "☆"; + this.starPerform5.UseCompatibleTextRendering = true; + this.starPerform5.MouseClick += new System.Windows.Forms.MouseEventHandler(this.Star_MouseClick); + this.starPerform5.MouseEnter += new System.EventHandler(this.Star_MouseEnter); + this.starPerform5.MouseLeave += new System.EventHandler(this.Star_MouseLeave); + // + // panelStory + // + this.panelStory.Anchor = System.Windows.Forms.AnchorStyles.Left; + this.panelStory.Controls.Add(this.starStory1); + this.panelStory.Controls.Add(this.starStory2); + this.panelStory.Controls.Add(this.starStory3); + this.panelStory.Controls.Add(this.starStory4); + this.panelStory.Controls.Add(this.starStory5); + this.panelStory.Location = new System.Drawing.Point(55, 33); + this.panelStory.Name = "panelStory"; + this.panelStory.Size = new System.Drawing.Size(45, 10); + this.panelStory.TabIndex = 9; + // + // starStory1 + // + this.starStory1.Font = new System.Drawing.Font("Segoe UI", 6.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.starStory1.Location = new System.Drawing.Point(0, 0); + this.starStory1.Margin = new System.Windows.Forms.Padding(0); + this.starStory1.Name = "starStory1"; + this.starStory1.Size = new System.Drawing.Size(9, 10); + this.starStory1.TabIndex = 0; + this.starStory1.Text = "☆"; + this.starStory1.UseCompatibleTextRendering = true; + this.starStory1.MouseClick += new System.Windows.Forms.MouseEventHandler(this.Star_MouseClick); + this.starStory1.MouseEnter += new System.EventHandler(this.Star_MouseEnter); + this.starStory1.MouseLeave += new System.EventHandler(this.Star_MouseLeave); + // + // starStory2 + // + this.starStory2.Font = new System.Drawing.Font("Segoe UI", 6.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.starStory2.Location = new System.Drawing.Point(9, 0); + this.starStory2.Margin = new System.Windows.Forms.Padding(0); + this.starStory2.Name = "starStory2"; + this.starStory2.Size = new System.Drawing.Size(9, 10); + this.starStory2.TabIndex = 1; + this.starStory2.Text = "☆"; + this.starStory2.UseCompatibleTextRendering = true; + this.starStory2.MouseClick += new System.Windows.Forms.MouseEventHandler(this.Star_MouseClick); + this.starStory2.MouseEnter += new System.EventHandler(this.Star_MouseEnter); + this.starStory2.MouseLeave += new System.EventHandler(this.Star_MouseLeave); + // + // starStory3 + // + this.starStory3.Font = new System.Drawing.Font("Segoe UI", 6.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.starStory3.Location = new System.Drawing.Point(18, 0); + this.starStory3.Margin = new System.Windows.Forms.Padding(0); + this.starStory3.Name = "starStory3"; + this.starStory3.Size = new System.Drawing.Size(9, 10); + this.starStory3.TabIndex = 3; + this.starStory3.Text = "☆"; + this.starStory3.UseCompatibleTextRendering = true; + this.starStory3.MouseClick += new System.Windows.Forms.MouseEventHandler(this.Star_MouseClick); + this.starStory3.MouseEnter += new System.EventHandler(this.Star_MouseEnter); + this.starStory3.MouseLeave += new System.EventHandler(this.Star_MouseLeave); + // + // starStory4 + // + this.starStory4.Font = new System.Drawing.Font("Segoe UI", 6.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.starStory4.Location = new System.Drawing.Point(27, 0); + this.starStory4.Margin = new System.Windows.Forms.Padding(0); + this.starStory4.Name = "starStory4"; + this.starStory4.Size = new System.Drawing.Size(9, 10); + this.starStory4.TabIndex = 2; + this.starStory4.Text = "☆"; + this.starStory4.UseCompatibleTextRendering = true; + this.starStory4.MouseClick += new System.Windows.Forms.MouseEventHandler(this.Star_MouseClick); + this.starStory4.MouseEnter += new System.EventHandler(this.Star_MouseEnter); + this.starStory4.MouseLeave += new System.EventHandler(this.Star_MouseLeave); + // + // starStory5 + // + this.starStory5.Font = new System.Drawing.Font("Segoe UI", 6.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.starStory5.Location = new System.Drawing.Point(36, 0); + this.starStory5.Margin = new System.Windows.Forms.Padding(0); + this.starStory5.Name = "starStory5"; + this.starStory5.Size = new System.Drawing.Size(9, 10); + this.starStory5.TabIndex = 4; + this.starStory5.Text = "☆"; + this.starStory5.UseCompatibleTextRendering = true; + this.starStory5.MouseClick += new System.Windows.Forms.MouseEventHandler(this.Star_MouseClick); + this.starStory5.MouseEnter += new System.EventHandler(this.Star_MouseEnter); + this.starStory5.MouseLeave += new System.EventHandler(this.Star_MouseLeave); + // + // MyRatingCellEditor + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.lblStory); + this.Controls.Add(this.panelStory); + this.Controls.Add(this.lblPerform); + this.Controls.Add(this.panelPerform); + this.Controls.Add(this.lblOverall); + this.Controls.Add(this.panelOverall); + this.Name = "MyRatingCellEditor"; + this.Size = new System.Drawing.Size(108, 45); + this.panelOverall.ResumeLayout(false); + this.panelPerform.ResumeLayout(false); + this.panelStory.ResumeLayout(false); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Label starOverall1; + private System.Windows.Forms.Label starOverall2; + private System.Windows.Forms.Label starOverall3; + private System.Windows.Forms.Label starOverall4; + private System.Windows.Forms.Label starOverall5; + private System.Windows.Forms.Panel panelOverall; + private System.Windows.Forms.Label lblOverall; + private System.Windows.Forms.Label lblPerform; + private System.Windows.Forms.Panel panelPerform; + private System.Windows.Forms.Label starPerform1; + private System.Windows.Forms.Label starPerform2; + private System.Windows.Forms.Label starPerform3; + private System.Windows.Forms.Label starPerform4; + private System.Windows.Forms.Label starPerform5; + private System.Windows.Forms.Label lblStory; + private System.Windows.Forms.Panel panelStory; + private System.Windows.Forms.Label starStory1; + private System.Windows.Forms.Label starStory2; + private System.Windows.Forms.Label starStory3; + private System.Windows.Forms.Label starStory4; + private System.Windows.Forms.Label starStory5; + } +} diff --git a/Source/LibationWinForms/GridView/RatingPicker.cs b/Source/LibationWinForms/GridView/MyRatingCellEditor.cs similarity index 77% rename from Source/LibationWinForms/GridView/RatingPicker.cs rename to Source/LibationWinForms/GridView/MyRatingCellEditor.cs index 94478dec..53e5623e 100644 --- a/Source/LibationWinForms/GridView/RatingPicker.cs +++ b/Source/LibationWinForms/GridView/MyRatingCellEditor.cs @@ -1,18 +1,12 @@ using DataLayer; -using Mpeg4Lib.Boxes; using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; using System.Drawing; using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Windows.Forms; namespace LibationWinForms.GridView { - public partial class RatingPicker : UserControl, IDataGridViewEditingControl + public partial class MyRatingCellEditor : UserControl, IDataGridViewEditingControl { private const string SOLID_STAR = "★"; private const string HOLLOW_STAR = "☆"; @@ -24,21 +18,22 @@ namespace LibationWinForms.GridView { _rating = value; int rating = 0; - foreach (Label star in panel1.Controls) + foreach (Label star in panelOverall.Controls) star.Tag = star.Text = _rating.OverallRating > rating++ ? SOLID_STAR : HOLLOW_STAR; rating = 0; - foreach (Label star in panel2.Controls) + foreach (Label star in panelPerform.Controls) star.Tag = star.Text = _rating.PerformanceRating > rating++ ? SOLID_STAR : HOLLOW_STAR; rating = 0; - foreach (Label star in panel3.Controls) + foreach (Label star in panelStory.Controls) star.Tag = star.Text = _rating.StoryRating > rating++ ? SOLID_STAR : HOLLOW_STAR; } } - public RatingPicker() + public MyRatingCellEditor() { InitializeComponent(); + this.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Bottom; } private void Star_MouseEnter(object sender, EventArgs e) @@ -79,46 +74,48 @@ namespace LibationWinForms.GridView var thisTbox = sender as Label; var panel = thisTbox.Parent as Panel; - int newRating = 0; + int newRatingValue = 0; foreach (var child in panel.Controls) { - newRating++; + newRatingValue++; if (child == thisTbox) break; } - if (panel == panel1) - overall = newRating; - else if (panel == panel2) - perform = newRating; - else if (panel == panel3) - story = newRating; + if (panel == panelOverall) + overall = newRatingValue; + else if (panel == panelPerform) + perform = newRatingValue; + else if (panel == panelStory) + story = newRatingValue; if (overall + perform + story == 0f) return; - Rating = new Rating(overall, perform, story); + var newRating = new Rating(overall, perform, story); + + if (newRating == Rating) return; + EditingControlValueChanged = true; EditingControlDataGridView.NotifyCurrentCellDirty(true); } + #region IDataGridViewEditingControl + DataGridView dataGridView; private bool valueChanged = false; int rowIndex; - #region IDataGridViewEditingControl public DataGridView EditingControlDataGridView { get => dataGridView; set => dataGridView = value; } - public object EditingControlFormattedValue { get => Rating.ToStarString(); set { } } public int EditingControlRowIndex { get => rowIndex; set => rowIndex = value; } public bool EditingControlValueChanged { get => valueChanged; set => valueChanged = value; } - + public object EditingControlFormattedValue { get => Rating; set => Rating = (Rating)value; } public Cursor EditingPanelCursor => base.Cursor; - public bool RepositionEditingControlOnValueChange => false; public void ApplyCellStyleToEditingControl(DataGridViewCellStyle dataGridViewCellStyle) { - this.Font = dataGridViewCellStyle.Font; - this.ForeColor = dataGridViewCellStyle.ForeColor; - this.BackColor = dataGridViewCellStyle.BackColor; + Font = dataGridViewCellStyle.Font; + ForeColor = dataGridViewCellStyle.ForeColor; + BackColor = dataGridViewCellStyle.BackColor; } public bool EditingControlWantsInputKey(Keys keyData, bool dataGridViewWantsInputKey) diff --git a/Source/LibationWinForms/GridView/RatingPicker.resx b/Source/LibationWinForms/GridView/MyRatingCellEditor.resx similarity index 100% rename from Source/LibationWinForms/GridView/RatingPicker.resx rename to Source/LibationWinForms/GridView/MyRatingCellEditor.resx diff --git a/Source/LibationWinForms/GridView/MyRatingGridViewColumn.cs b/Source/LibationWinForms/GridView/MyRatingGridViewColumn.cs index fdab268e..ea174443 100644 --- a/Source/LibationWinForms/GridView/MyRatingGridViewColumn.cs +++ b/Source/LibationWinForms/GridView/MyRatingGridViewColumn.cs @@ -1,6 +1,7 @@ using DataLayer; using System; using System.ComponentModel; +using System.Drawing; using System.Linq; using System.Windows.Forms; @@ -16,7 +17,7 @@ namespace LibationWinForms.GridView set { if (value is not MyRatingGridViewCell) - throw new InvalidCastException("Must be a MyRatingGridViewCell"); + throw new InvalidCastException($"Must be a {nameof(MyRatingGridViewCell)}"); base.CellTemplate = value; } @@ -25,49 +26,32 @@ namespace LibationWinForms.GridView internal class MyRatingGridViewCell : DataGridViewTextBoxCell { + private Rating DefaultRating => new Rating(0, 0, 0); + public override object DefaultNewRowValue => DefaultRating; + public override Type EditType => typeof(MyRatingCellEditor); + public override Type ValueType => typeof(Rating); + public override void InitializeEditingControl(int rowIndex, object initialFormattedValue, DataGridViewCellStyle dataGridViewCellStyle) { base.InitializeEditingControl(rowIndex, initialFormattedValue, dataGridViewCellStyle); - var ctl = DataGridView.EditingControl as RatingPicker; + var ctl = DataGridView.EditingControl as MyRatingCellEditor; - ctl.Rating = - Value is Rating rating - ? rating - : (Rating)DefaultNewRowValue; + ctl.Rating = Value is Rating rating ? rating : DefaultRating; + } + + protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) + { + if (value is Rating rating) + { + var starString = rating.ToStarString(); + base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, starString, starString, errorText, cellStyle, advancedBorderStyle, paintParts); + } + else + base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, string.Empty, string.Empty, errorText, cellStyle, advancedBorderStyle, paintParts); } public override object ParseFormattedValue(object formattedValue, DataGridViewCellStyle cellStyle, TypeConverter formattedValueTypeConverter, TypeConverter valueTypeConverter) - { - const char SOLID_STAR = '★'; - if (formattedValue is string s) - { - int overall = 0, performance = 0, story = 0; - - foreach (var line in s.Split('\n')) - { - if (line.Contains("Overall")) - overall = line.Count(c => c == SOLID_STAR); - else if (line.Contains("Perform")) - performance = line.Count(c => c == SOLID_STAR); - else if (line.Contains("Story")) - story = line.Count(c => c == SOLID_STAR); - } - - return new Rating(overall, performance, story); - } - else - return DefaultNewRowValue; - } - - - protected override object GetFormattedValue(object value, int rowIndex, ref DataGridViewCellStyle cellStyle, TypeConverter valueTypeConverter, TypeConverter formattedValueTypeConverter, DataGridViewDataErrorContexts context) - => value is Rating rating - ? rating.ToStarString() - : base.GetFormattedValue(value, rowIndex, ref cellStyle, valueTypeConverter, formattedValueTypeConverter, context); - - public override Type EditType => typeof(RatingPicker); - public override object DefaultNewRowValue => new Rating(0, 0, 0); - public override Type ValueType => typeof(Rating); + => formattedValue; } } diff --git a/Source/LibationWinForms/GridView/RatingPicker.Designer.cs b/Source/LibationWinForms/GridView/RatingPicker.Designer.cs deleted file mode 100644 index d6705129..00000000 --- a/Source/LibationWinForms/GridView/RatingPicker.Designer.cs +++ /dev/null @@ -1,348 +0,0 @@ -namespace LibationWinForms.GridView -{ - partial class RatingPicker - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Component Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.label1 = new System.Windows.Forms.Label(); - this.label2 = new System.Windows.Forms.Label(); - this.label3 = new System.Windows.Forms.Label(); - this.label4 = new System.Windows.Forms.Label(); - this.label5 = new System.Windows.Forms.Label(); - this.panel1 = new System.Windows.Forms.Panel(); - this.label6 = new System.Windows.Forms.Label(); - this.label7 = new System.Windows.Forms.Label(); - this.panel2 = new System.Windows.Forms.Panel(); - this.label8 = new System.Windows.Forms.Label(); - this.label9 = new System.Windows.Forms.Label(); - this.label10 = new System.Windows.Forms.Label(); - this.label11 = new System.Windows.Forms.Label(); - this.label12 = new System.Windows.Forms.Label(); - this.label13 = new System.Windows.Forms.Label(); - this.panel3 = new System.Windows.Forms.Panel(); - this.label14 = new System.Windows.Forms.Label(); - this.label15 = new System.Windows.Forms.Label(); - this.label16 = new System.Windows.Forms.Label(); - this.label17 = new System.Windows.Forms.Label(); - this.label18 = new System.Windows.Forms.Label(); - this.panel1.SuspendLayout(); - this.panel2.SuspendLayout(); - this.panel3.SuspendLayout(); - this.SuspendLayout(); - // - // label1 - // - this.label1.Location = new System.Drawing.Point(0, 0); - this.label1.Margin = new System.Windows.Forms.Padding(0); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(12, 15); - this.label1.TabIndex = 0; - this.label1.Text = "☆"; - this.label1.MouseClick += new System.Windows.Forms.MouseEventHandler(this.Star_MouseClick); - this.label1.MouseEnter += new System.EventHandler(this.Star_MouseEnter); - this.label1.MouseLeave += new System.EventHandler(this.Star_MouseLeave); - // - // label2 - // - this.label2.Location = new System.Drawing.Point(12, 0); - this.label2.Margin = new System.Windows.Forms.Padding(0); - this.label2.Name = "label2"; - this.label2.Size = new System.Drawing.Size(12, 15); - this.label2.TabIndex = 1; - this.label2.Text = "☆"; - this.label2.MouseClick += new System.Windows.Forms.MouseEventHandler(this.Star_MouseClick); - this.label2.MouseEnter += new System.EventHandler(this.Star_MouseEnter); - this.label2.MouseLeave += new System.EventHandler(this.Star_MouseLeave); - // - // label3 - // - this.label3.Location = new System.Drawing.Point(24, 0); - this.label3.Margin = new System.Windows.Forms.Padding(0); - this.label3.Name = "label3"; - this.label3.Size = new System.Drawing.Size(12, 15); - this.label3.TabIndex = 3; - this.label3.Text = "☆"; - this.label3.MouseClick += new System.Windows.Forms.MouseEventHandler(this.Star_MouseClick); - this.label3.MouseEnter += new System.EventHandler(this.Star_MouseEnter); - this.label3.MouseLeave += new System.EventHandler(this.Star_MouseLeave); - // - // label4 - // - this.label4.Location = new System.Drawing.Point(36, 0); - this.label4.Margin = new System.Windows.Forms.Padding(0); - this.label4.Name = "label4"; - this.label4.Size = new System.Drawing.Size(12, 15); - this.label4.TabIndex = 2; - this.label4.Text = "☆"; - this.label4.MouseClick += new System.Windows.Forms.MouseEventHandler(this.Star_MouseClick); - this.label4.MouseEnter += new System.EventHandler(this.Star_MouseEnter); - this.label4.MouseLeave += new System.EventHandler(this.Star_MouseLeave); - // - // label5 - // - this.label5.Location = new System.Drawing.Point(48, 0); - this.label5.Margin = new System.Windows.Forms.Padding(0); - this.label5.Name = "label5"; - this.label5.Size = new System.Drawing.Size(12, 15); - this.label5.TabIndex = 4; - this.label5.Text = "☆"; - this.label5.MouseClick += new System.Windows.Forms.MouseEventHandler(this.Star_MouseClick); - this.label5.MouseEnter += new System.EventHandler(this.Star_MouseEnter); - this.label5.MouseLeave += new System.EventHandler(this.Star_MouseLeave); - // - // panel1 - // - this.panel1.Controls.Add(this.label1); - this.panel1.Controls.Add(this.label2); - this.panel1.Controls.Add(this.label3); - this.panel1.Controls.Add(this.label4); - this.panel1.Controls.Add(this.label5); - this.panel1.Location = new System.Drawing.Point(45, 13); - this.panel1.Name = "panel1"; - this.panel1.Size = new System.Drawing.Size(60, 15); - this.panel1.TabIndex = 5; - // - // label6 - // - this.label6.AutoSize = true; - this.label6.Location = new System.Drawing.Point(0, 13); - this.label6.Margin = new System.Windows.Forms.Padding(0); - this.label6.Name = "label6"; - this.label6.Size = new System.Drawing.Size(47, 15); - this.label6.TabIndex = 6; - this.label6.Text = "Overall:"; - // - // label7 - // - this.label7.AutoSize = true; - this.label7.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); - this.label7.Location = new System.Drawing.Point(0, 32); - this.label7.Margin = new System.Windows.Forms.Padding(0); - this.label7.Name = "label7"; - this.label7.Size = new System.Drawing.Size(46, 15); - this.label7.TabIndex = 8; - this.label7.Text = "Perfrm:"; - // - // panel2 - // - this.panel2.Controls.Add(this.label8); - this.panel2.Controls.Add(this.label9); - this.panel2.Controls.Add(this.label10); - this.panel2.Controls.Add(this.label11); - this.panel2.Controls.Add(this.label12); - this.panel2.Location = new System.Drawing.Point(45, 32); - this.panel2.Name = "panel2"; - this.panel2.Size = new System.Drawing.Size(60, 15); - this.panel2.TabIndex = 7; - // - // label8 - // - this.label8.Location = new System.Drawing.Point(0, 0); - this.label8.Margin = new System.Windows.Forms.Padding(0); - this.label8.Name = "label8"; - this.label8.Size = new System.Drawing.Size(12, 15); - this.label8.TabIndex = 0; - this.label8.Text = "☆"; - this.label8.MouseClick += new System.Windows.Forms.MouseEventHandler(this.Star_MouseClick); - this.label8.MouseEnter += new System.EventHandler(this.Star_MouseEnter); - this.label8.MouseLeave += new System.EventHandler(this.Star_MouseLeave); - // - // label9 - // - this.label9.Location = new System.Drawing.Point(12, 0); - this.label9.Margin = new System.Windows.Forms.Padding(0); - this.label9.Name = "label9"; - this.label9.Size = new System.Drawing.Size(12, 15); - this.label9.TabIndex = 1; - this.label9.Text = "☆"; - this.label9.MouseClick += new System.Windows.Forms.MouseEventHandler(this.Star_MouseClick); - this.label9.MouseEnter += new System.EventHandler(this.Star_MouseEnter); - this.label9.MouseLeave += new System.EventHandler(this.Star_MouseLeave); - // - // label10 - // - this.label10.Location = new System.Drawing.Point(24, 0); - this.label10.Margin = new System.Windows.Forms.Padding(0); - this.label10.Name = "label10"; - this.label10.Size = new System.Drawing.Size(12, 15); - this.label10.TabIndex = 3; - this.label10.Text = "☆"; - this.label10.MouseClick += new System.Windows.Forms.MouseEventHandler(this.Star_MouseClick); - this.label10.MouseEnter += new System.EventHandler(this.Star_MouseEnter); - this.label10.MouseLeave += new System.EventHandler(this.Star_MouseLeave); - // - // label11 - // - this.label11.Location = new System.Drawing.Point(36, 0); - this.label11.Margin = new System.Windows.Forms.Padding(0); - this.label11.Name = "label11"; - this.label11.Size = new System.Drawing.Size(12, 15); - this.label11.TabIndex = 2; - this.label11.Text = "☆"; - this.label11.MouseClick += new System.Windows.Forms.MouseEventHandler(this.Star_MouseClick); - this.label11.MouseEnter += new System.EventHandler(this.Star_MouseEnter); - this.label11.MouseLeave += new System.EventHandler(this.Star_MouseLeave); - // - // label12 - // - this.label12.Location = new System.Drawing.Point(48, 0); - this.label12.Margin = new System.Windows.Forms.Padding(0); - this.label12.Name = "label12"; - this.label12.Size = new System.Drawing.Size(12, 15); - this.label12.TabIndex = 4; - this.label12.Text = "☆"; - this.label12.MouseClick += new System.Windows.Forms.MouseEventHandler(this.Star_MouseClick); - this.label12.MouseEnter += new System.EventHandler(this.Star_MouseEnter); - this.label12.MouseLeave += new System.EventHandler(this.Star_MouseLeave); - // - // label13 - // - this.label13.AutoSize = true; - this.label13.Location = new System.Drawing.Point(0, 51); - this.label13.Margin = new System.Windows.Forms.Padding(0); - this.label13.Name = "label13"; - this.label13.Size = new System.Drawing.Size(37, 15); - this.label13.TabIndex = 10; - this.label13.Text = "Story:"; - // - // panel3 - // - this.panel3.Controls.Add(this.label14); - this.panel3.Controls.Add(this.label15); - this.panel3.Controls.Add(this.label16); - this.panel3.Controls.Add(this.label17); - this.panel3.Controls.Add(this.label18); - this.panel3.Location = new System.Drawing.Point(45, 51); - this.panel3.Name = "panel3"; - this.panel3.Size = new System.Drawing.Size(60, 15); - this.panel3.TabIndex = 9; - // - // label14 - // - this.label14.Location = new System.Drawing.Point(0, 0); - this.label14.Margin = new System.Windows.Forms.Padding(0); - this.label14.Name = "label14"; - this.label14.Size = new System.Drawing.Size(12, 15); - this.label14.TabIndex = 0; - this.label14.Text = "☆"; - this.label14.MouseClick += new System.Windows.Forms.MouseEventHandler(this.Star_MouseClick); - this.label14.MouseEnter += new System.EventHandler(this.Star_MouseEnter); - this.label14.MouseLeave += new System.EventHandler(this.Star_MouseLeave); - // - // label15 - // - this.label15.Location = new System.Drawing.Point(12, 0); - this.label15.Margin = new System.Windows.Forms.Padding(0); - this.label15.Name = "label15"; - this.label15.Size = new System.Drawing.Size(12, 15); - this.label15.TabIndex = 1; - this.label15.Text = "☆"; - this.label15.MouseClick += new System.Windows.Forms.MouseEventHandler(this.Star_MouseClick); - this.label15.MouseEnter += new System.EventHandler(this.Star_MouseEnter); - this.label15.MouseLeave += new System.EventHandler(this.Star_MouseLeave); - // - // label16 - // - this.label16.Location = new System.Drawing.Point(24, 0); - this.label16.Margin = new System.Windows.Forms.Padding(0); - this.label16.Name = "label16"; - this.label16.Size = new System.Drawing.Size(12, 15); - this.label16.TabIndex = 3; - this.label16.Text = "☆"; - this.label16.MouseClick += new System.Windows.Forms.MouseEventHandler(this.Star_MouseClick); - this.label16.MouseEnter += new System.EventHandler(this.Star_MouseEnter); - this.label16.MouseLeave += new System.EventHandler(this.Star_MouseLeave); - // - // label17 - // - this.label17.Location = new System.Drawing.Point(36, 0); - this.label17.Margin = new System.Windows.Forms.Padding(0); - this.label17.Name = "label17"; - this.label17.Size = new System.Drawing.Size(12, 15); - this.label17.TabIndex = 2; - this.label17.Text = "☆"; - this.label17.MouseClick += new System.Windows.Forms.MouseEventHandler(this.Star_MouseClick); - this.label17.MouseEnter += new System.EventHandler(this.Star_MouseEnter); - this.label17.MouseLeave += new System.EventHandler(this.Star_MouseLeave); - // - // label18 - // - this.label18.Location = new System.Drawing.Point(48, 0); - this.label18.Margin = new System.Windows.Forms.Padding(0); - this.label18.Name = "label18"; - this.label18.Size = new System.Drawing.Size(12, 15); - this.label18.TabIndex = 4; - this.label18.Text = "☆"; - this.label18.MouseClick += new System.Windows.Forms.MouseEventHandler(this.Star_MouseClick); - this.label18.MouseEnter += new System.EventHandler(this.Star_MouseEnter); - this.label18.MouseLeave += new System.EventHandler(this.Star_MouseLeave); - // - // RatingPicker - // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.Controls.Add(this.label13); - this.Controls.Add(this.panel3); - this.Controls.Add(this.label7); - this.Controls.Add(this.panel2); - this.Controls.Add(this.label6); - this.Controls.Add(this.panel1); - this.Name = "RatingPicker"; - this.Size = new System.Drawing.Size(108, 80); - this.panel1.ResumeLayout(false); - this.panel2.ResumeLayout(false); - this.panel3.ResumeLayout(false); - this.ResumeLayout(false); - this.PerformLayout(); - - } - - #endregion - - private System.Windows.Forms.Label label1; - private System.Windows.Forms.Label label2; - private System.Windows.Forms.Label label3; - private System.Windows.Forms.Label label4; - private System.Windows.Forms.Label label5; - private System.Windows.Forms.Panel panel1; - private System.Windows.Forms.Label label6; - private System.Windows.Forms.Label label7; - private System.Windows.Forms.Panel panel2; - private System.Windows.Forms.Label label8; - private System.Windows.Forms.Label label9; - private System.Windows.Forms.Label label10; - private System.Windows.Forms.Label label11; - private System.Windows.Forms.Label label12; - private System.Windows.Forms.Label label13; - private System.Windows.Forms.Panel panel3; - private System.Windows.Forms.Label label14; - private System.Windows.Forms.Label label15; - private System.Windows.Forms.Label label16; - private System.Windows.Forms.Label label17; - private System.Windows.Forms.Label label18; - } -} diff --git a/Source/LibationWinForms/GridView/SeriesEntry.cs b/Source/LibationWinForms/GridView/SeriesEntry.cs index 53191808..f8d004f9 100644 --- a/Source/LibationWinForms/GridView/SeriesEntry.cs +++ b/Source/LibationWinForms/GridView/SeriesEntry.cs @@ -89,7 +89,7 @@ namespace LibationWinForms.GridView Title = Book.Title; Series = Book.SeriesNames(); - MyRating = Book.UserDefinedItem.Rating; + _myRating = Book.UserDefinedItem.Rating; PurchaseDate = Children.Min(c => c.LibraryBook.DateAdded).ToString("d"); ProductRating = Book.Rating?.ToStarString()?.DefaultIfNullOrWhiteSpace(""); Authors = Book.AuthorNames();