using PaintDotNet.Annotation;
using PaintDotNet.Annotation.Enum;
using PaintDotNet.Annotation.Label;
using PaintDotNet.Annotation.Other;
using PaintDotNet.Base.SettingModel;
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;
using static PaintDotNet.Base.SettingModel.RulerModel;
namespace PaintDotNet.ImageLabel
{
///
/// 预存标尺
///
internal class PresetRulerDialog : PdnBaseForm
{
private GroupBox groupBox1;
private Button button2;
private ListView listView1;
private Button button1;
private AppWorkspace appWorkspace;
private RulerModel rulerModel = new RulerModel();
private PresetRuler tempPresetRuler = new PresetRuler();
public PresetRulerDialog(AppWorkspace appWorkspace)
{
this.appWorkspace = appWorkspace;
this.rulerModel = Startup.instance.rulerModel;
InitializeComponent();
InitializeLanguageText();
InitializeListView();
BuildListView();
}
private void InitializeLanguageText()
{
this.groupBox1.Text = PdnResources.GetString("Menu.operation.text");
this.button2.Text = PdnResources.GetString("Menu.ensure.text");
this.button1.Text = PdnResources.GetString("Menu.cancel.text");
this.Text = PdnResources.GetString("Menu.ImageOverlays.Pre-storedrulers.Listofpdrulers.text");
}
private void InitializeComponent()
{
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.button2 = new System.Windows.Forms.Button();
this.button1 = new System.Windows.Forms.Button();
this.listView1 = new System.Windows.Forms.ListView();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// groupBox1
//
this.groupBox1.Controls.Add(this.button2);
this.groupBox1.Controls.Add(this.button1);
this.groupBox1.Location = new System.Drawing.Point(13, 13);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(317, 57);
this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "操作";
//
// button2
//
this.button2.Location = new System.Drawing.Point(168, 20);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(64, 23);
this.button2.TabIndex = 1;
this.button2.Text = "确定";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// button1
//
this.button1.Location = new System.Drawing.Point(247, 20);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(64, 23);
this.button1.TabIndex = 0;
this.button1.Text = "取消";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// listView1
//
this.listView1.FullRowSelect = true;
this.listView1.GridLines = true;
this.listView1.HideSelection = false;
this.listView1.Location = new System.Drawing.Point(13, 85);
this.listView1.MultiSelect = false;
this.listView1.Name = "listView1";
this.listView1.Size = new System.Drawing.Size(317, 213);
this.listView1.TabIndex = 1;
this.listView1.UseCompatibleStateImageBehavior = false;
this.listView1.SelectedIndexChanged += new System.EventHandler(this.listView1_SelectedIndexChanged);
this.listView1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.listView1_MouseDown);
//
// PresetRulerDialog
//
this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
this.ClientSize = new System.Drawing.Size(342, 310);
this.Controls.Add(this.listView1);
this.Controls.Add(this.groupBox1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "PresetRulerDialog";
this.Text = "预存标尺列表";
this.Controls.SetChildIndex(this.groupBox1, 0);
this.Controls.SetChildIndex(this.listView1, 0);
this.groupBox1.ResumeLayout(false);
this.ResumeLayout(false);
}
private void InitializeListView()
{
this.listView1.View = View.Details;
ColumnHeader header = new ColumnHeader();
header.Text = PdnResources.GetString("Menu.name.text");
header.Width = 180;
this.listView1.Columns.Add(header);
header = new ColumnHeader();
header.Text = PdnResources.GetString("Menu.MeasureAction.MeasureLength.Text");
header.Width = 132;
this.listView1.Columns.Add(header);
}
///
/// 构建ListView数据
///
private void BuildListView()
{
this.listView1.Items.Clear();
this.listView1.BeginUpdate();
foreach (PresetRuler presetRuler in this.rulerModel.presetRulers)
{
ListViewItem lvi = new ListViewItem();
lvi.Text = presetRuler.name.ToString();
lvi.SubItems.Add(presetRuler.length.ToString());
this.listView1.Items.Add(lvi);
}
this.listView1.EndUpdate();
if (this.listView1.Items.Count > 0)
{
this.listView1.Items[0].Selected = true;
}
}
///
/// 取消按钮
///
///
///
private void button1_Click(object sender, EventArgs e)
{
this.Close();
}
///
/// 确定按钮
///
///
///
private void button2_Click(object sender, EventArgs e)
{
if (this.listView1.SelectedItems.Count <= 0)
{
MessageBox.Show(PdnResources.GetString("Menu.Pleaseseleasavedruler.Text"));
return;
}
ListViewItem item = this.listView1.SelectedItems[0];
int rulerLength = Convert.ToInt32(item.SubItems[1].Text);
//主窗体添加
if (this.appWorkspace.ActiveDocumentWorkspace != null)
{
this.appWorkspace.ActiveDocumentWorkspace.ActiveTool = DrawToolType.DrawPrestoredRuler;
List objList = this.appWorkspace.ActiveDocumentWorkspace.GraphicsList.GetDrawToolTypeList(DrawToolType.DrawPrestoredRuler);
if (objList.Count > 0)
{
DrawPrestoredRuler drawPrestoredRuler = (DrawPrestoredRuler)objList[0];
drawPrestoredRuler.lineLength = rulerLength;
this.appWorkspace.ActiveDocumentWorkspace.Refresh();
if (this.appWorkspace.Widgets.LabelListDialog != null)
this.appWorkspace.Widgets.LabelListDialog.RefreshDateGridView(null, null);
}
}
//预览窗口添加
if (this.appWorkspace.cameraPreviewDialog != null && !this.appWorkspace.cameraPreviewDialog.IsDisposed)
{
this.appWorkspace.cameraPreviewDialog.documentWorkspace.ActiveTool = DrawToolType.DrawPrestoredRuler;
List objList = this.appWorkspace.cameraPreviewDialog.documentWorkspace.GraphicsList.GetDrawToolTypeList(DrawToolType.DrawPrestoredRuler);
if (objList.Count > 0)
{
DrawPrestoredRuler drawPrestoredRuler = (DrawPrestoredRuler)objList[0];
drawPrestoredRuler.lineLength = rulerLength;
this.appWorkspace.cameraPreviewDialog.documentWorkspace.Refresh();
if (this.appWorkspace.Widgets.LabelListDialog != null)
this.appWorkspace.Widgets.LabelListDialog.RefreshDateGridView(null, null);
}
}
this.Close();
}
private void listView1_MouseDown(object sender, MouseEventArgs e)
{
if(e.Clicks == 2)
{
if (this.listView1.SelectedItems.Count <= 0)
{
MessageBox.Show(PdnResources.GetString("Menu.Pleaseseleasavedruler.Text"));
return;
}
ListViewItem item = this.listView1.SelectedItems[0];
int rulerLength = Convert.ToInt32(item.SubItems[1].Text);
//主窗体添加
if (this.appWorkspace.ActiveDocumentWorkspace != null)
{
this.appWorkspace.ActiveDocumentWorkspace.ActiveTool = DrawToolType.DrawPrestoredRuler;
List objList = this.appWorkspace.ActiveDocumentWorkspace.GraphicsList.GetDrawToolTypeList(DrawToolType.DrawPrestoredRuler);
if (objList.Count > 0)
{
DrawPrestoredRuler drawPrestoredRuler = (DrawPrestoredRuler)objList[0];
drawPrestoredRuler.lineLength = rulerLength;
this.appWorkspace.ActiveDocumentWorkspace.Refresh();
if (this.appWorkspace.Widgets.LabelListDialog != null)
this.appWorkspace.Widgets.LabelListDialog.RefreshDateGridView(null, null);
}
}
//预览窗口添加
if (this.appWorkspace.cameraPreviewDialog != null && !this.appWorkspace.cameraPreviewDialog.IsDisposed)
{
this.appWorkspace.cameraPreviewDialog.documentWorkspace.ActiveTool = DrawToolType.DrawPrestoredRuler;
List objList = this.appWorkspace.cameraPreviewDialog.documentWorkspace.GraphicsList.GetDrawToolTypeList(DrawToolType.DrawPrestoredRuler);
if (objList.Count > 0)
{
DrawPrestoredRuler drawPrestoredRuler = (DrawPrestoredRuler)objList[0];
drawPrestoredRuler.lineLength = rulerLength;
this.appWorkspace.cameraPreviewDialog.documentWorkspace.Refresh();
if (this.appWorkspace.Widgets.LabelListDialog != null)
this.appWorkspace.Widgets.LabelListDialog.RefreshDateGridView(null, null);
}
}
this.Close();
}
}
private void listView1_SelectedIndexChanged(object sender, EventArgs e)
{
ListViewItem defaultItem = new ListViewItem();
foreach (ListViewItem listViewItem in this.listView1.Items)
{
listViewItem.ForeColor = defaultItem.ForeColor;
listViewItem.BackColor = defaultItem.BackColor;
}
if (this.listView1.SelectedItems.Count <= 0)
{
return;
}
ListViewItem item = this.listView1.SelectedItems[0];
item.ForeColor = Color.White;
item.BackColor = Color.FromArgb(0, 120, 215);
}
}
}