PresetRulerDialog.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. using PaintDotNet.Annotation;
  2. using PaintDotNet.Annotation.Enum;
  3. using PaintDotNet.Annotation.Label;
  4. using PaintDotNet.Annotation.Other;
  5. using PaintDotNet.Base.SettingModel;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.ComponentModel;
  9. using System.Data;
  10. using System.Drawing;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. using System.Windows.Forms;
  15. using static PaintDotNet.Base.SettingModel.RulerModel;
  16. namespace PaintDotNet.ImageLabel
  17. {
  18. /// <summary>
  19. /// 预存标尺
  20. /// </summary>
  21. internal class PresetRulerDialog : PdnBaseForm
  22. {
  23. private GroupBox groupBox1;
  24. private Button button2;
  25. private ListView listView1;
  26. private Button button1;
  27. private AppWorkspace appWorkspace;
  28. private RulerModel rulerModel = new RulerModel();
  29. private PresetRuler tempPresetRuler = new PresetRuler();
  30. public PresetRulerDialog(AppWorkspace appWorkspace)
  31. {
  32. this.appWorkspace = appWorkspace;
  33. this.rulerModel = Startup.instance.rulerModel;
  34. InitializeComponent();
  35. InitializeLanguageText();
  36. InitializeListView();
  37. BuildListView();
  38. }
  39. private void InitializeLanguageText()
  40. {
  41. this.groupBox1.Text = PdnResources.GetString("Menu.operation.text");
  42. this.button2.Text = PdnResources.GetString("Menu.ensure.text");
  43. this.button1.Text = PdnResources.GetString("Menu.cancel.text");
  44. this.Text = PdnResources.GetString("Menu.ImageOverlays.Pre-storedrulers.Listofpdrulers.text");
  45. }
  46. private void InitializeComponent()
  47. {
  48. this.groupBox1 = new System.Windows.Forms.GroupBox();
  49. this.button2 = new System.Windows.Forms.Button();
  50. this.button1 = new System.Windows.Forms.Button();
  51. this.listView1 = new System.Windows.Forms.ListView();
  52. this.groupBox1.SuspendLayout();
  53. this.SuspendLayout();
  54. //
  55. // groupBox1
  56. //
  57. this.groupBox1.Controls.Add(this.button2);
  58. this.groupBox1.Controls.Add(this.button1);
  59. this.groupBox1.Location = new System.Drawing.Point(13, 13);
  60. this.groupBox1.Name = "groupBox1";
  61. this.groupBox1.Size = new System.Drawing.Size(317, 57);
  62. this.groupBox1.TabIndex = 0;
  63. this.groupBox1.TabStop = false;
  64. this.groupBox1.Text = "操作";
  65. //
  66. // button2
  67. //
  68. this.button2.Location = new System.Drawing.Point(168, 20);
  69. this.button2.Name = "button2";
  70. this.button2.Size = new System.Drawing.Size(64, 23);
  71. this.button2.TabIndex = 1;
  72. this.button2.Text = "确定";
  73. this.button2.UseVisualStyleBackColor = true;
  74. this.button2.Click += new System.EventHandler(this.button2_Click);
  75. //
  76. // button1
  77. //
  78. this.button1.Location = new System.Drawing.Point(247, 20);
  79. this.button1.Name = "button1";
  80. this.button1.Size = new System.Drawing.Size(64, 23);
  81. this.button1.TabIndex = 0;
  82. this.button1.Text = "取消";
  83. this.button1.UseVisualStyleBackColor = true;
  84. this.button1.Click += new System.EventHandler(this.button1_Click);
  85. //
  86. // listView1
  87. //
  88. this.listView1.FullRowSelect = true;
  89. this.listView1.GridLines = true;
  90. this.listView1.HideSelection = false;
  91. this.listView1.Location = new System.Drawing.Point(13, 85);
  92. this.listView1.MultiSelect = false;
  93. this.listView1.Name = "listView1";
  94. this.listView1.Size = new System.Drawing.Size(317, 213);
  95. this.listView1.TabIndex = 1;
  96. this.listView1.UseCompatibleStateImageBehavior = false;
  97. this.listView1.SelectedIndexChanged += new System.EventHandler(this.listView1_SelectedIndexChanged);
  98. this.listView1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.listView1_MouseDown);
  99. //
  100. // PresetRulerDialog
  101. //
  102. this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
  103. this.ClientSize = new System.Drawing.Size(342, 310);
  104. this.Controls.Add(this.listView1);
  105. this.Controls.Add(this.groupBox1);
  106. this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
  107. this.MaximizeBox = false;
  108. this.MinimizeBox = false;
  109. this.Name = "PresetRulerDialog";
  110. this.Text = "预存标尺列表";
  111. this.Controls.SetChildIndex(this.groupBox1, 0);
  112. this.Controls.SetChildIndex(this.listView1, 0);
  113. this.groupBox1.ResumeLayout(false);
  114. this.ResumeLayout(false);
  115. }
  116. private void InitializeListView()
  117. {
  118. this.listView1.View = View.Details;
  119. ColumnHeader header = new ColumnHeader();
  120. header.Text = PdnResources.GetString("Menu.name.text");
  121. header.Width = 180;
  122. this.listView1.Columns.Add(header);
  123. header = new ColumnHeader();
  124. header.Text = PdnResources.GetString("Menu.MeasureAction.MeasureLength.Text");
  125. header.Width = 132;
  126. this.listView1.Columns.Add(header);
  127. }
  128. /// <summary>
  129. /// 构建ListView数据
  130. /// </summary>
  131. private void BuildListView()
  132. {
  133. this.listView1.Items.Clear();
  134. this.listView1.BeginUpdate();
  135. foreach (PresetRuler presetRuler in this.rulerModel.presetRulers)
  136. {
  137. ListViewItem lvi = new ListViewItem();
  138. lvi.Text = presetRuler.name.ToString();
  139. lvi.SubItems.Add(presetRuler.length.ToString());
  140. this.listView1.Items.Add(lvi);
  141. }
  142. this.listView1.EndUpdate();
  143. if (this.listView1.Items.Count > 0)
  144. {
  145. this.listView1.Items[0].Selected = true;
  146. }
  147. }
  148. /// <summary>
  149. /// 取消按钮
  150. /// </summary>
  151. /// <param name="sender"></param>
  152. /// <param name="e"></param>
  153. private void button1_Click(object sender, EventArgs e)
  154. {
  155. this.Close();
  156. }
  157. /// <summary>
  158. /// 确定按钮
  159. /// </summary>
  160. /// <param name="sender"></param>
  161. /// <param name="e"></param>
  162. private void button2_Click(object sender, EventArgs e)
  163. {
  164. if (this.listView1.SelectedItems.Count <= 0)
  165. {
  166. MessageBox.Show(PdnResources.GetString("Menu.Pleaseseleasavedruler.Text"));
  167. return;
  168. }
  169. ListViewItem item = this.listView1.SelectedItems[0];
  170. int rulerLength = Convert.ToInt32(item.SubItems[1].Text);
  171. //主窗体添加
  172. if (this.appWorkspace.ActiveDocumentWorkspace != null)
  173. {
  174. this.appWorkspace.ActiveDocumentWorkspace.ActiveTool = DrawToolType.DrawPrestoredRuler;
  175. List<DrawObject> objList = this.appWorkspace.ActiveDocumentWorkspace.GraphicsList.GetDrawToolTypeList(DrawToolType.DrawPrestoredRuler);
  176. if (objList.Count > 0)
  177. {
  178. DrawPrestoredRuler drawPrestoredRuler = (DrawPrestoredRuler)objList[0];
  179. drawPrestoredRuler.lineLength = rulerLength;
  180. this.appWorkspace.ActiveDocumentWorkspace.Refresh();
  181. if (this.appWorkspace.Widgets.LabelListDialog != null)
  182. this.appWorkspace.Widgets.LabelListDialog.RefreshDateGridView(null, null);
  183. }
  184. }
  185. //预览窗口添加
  186. if (this.appWorkspace.cameraPreviewDialog != null && !this.appWorkspace.cameraPreviewDialog.IsDisposed)
  187. {
  188. this.appWorkspace.cameraPreviewDialog.documentWorkspace.ActiveTool = DrawToolType.DrawPrestoredRuler;
  189. List<DrawObject> objList = this.appWorkspace.cameraPreviewDialog.documentWorkspace.GraphicsList.GetDrawToolTypeList(DrawToolType.DrawPrestoredRuler);
  190. if (objList.Count > 0)
  191. {
  192. DrawPrestoredRuler drawPrestoredRuler = (DrawPrestoredRuler)objList[0];
  193. drawPrestoredRuler.lineLength = rulerLength;
  194. this.appWorkspace.cameraPreviewDialog.documentWorkspace.Refresh();
  195. if (this.appWorkspace.Widgets.LabelListDialog != null)
  196. this.appWorkspace.Widgets.LabelListDialog.RefreshDateGridView(null, null);
  197. }
  198. }
  199. this.Close();
  200. }
  201. private void listView1_MouseDown(object sender, MouseEventArgs e)
  202. {
  203. if(e.Clicks == 2)
  204. {
  205. if (this.listView1.SelectedItems.Count <= 0)
  206. {
  207. MessageBox.Show(PdnResources.GetString("Menu.Pleaseseleasavedruler.Text"));
  208. return;
  209. }
  210. ListViewItem item = this.listView1.SelectedItems[0];
  211. int rulerLength = Convert.ToInt32(item.SubItems[1].Text);
  212. //主窗体添加
  213. if (this.appWorkspace.ActiveDocumentWorkspace != null)
  214. {
  215. this.appWorkspace.ActiveDocumentWorkspace.ActiveTool = DrawToolType.DrawPrestoredRuler;
  216. List<DrawObject> objList = this.appWorkspace.ActiveDocumentWorkspace.GraphicsList.GetDrawToolTypeList(DrawToolType.DrawPrestoredRuler);
  217. if (objList.Count > 0)
  218. {
  219. DrawPrestoredRuler drawPrestoredRuler = (DrawPrestoredRuler)objList[0];
  220. drawPrestoredRuler.lineLength = rulerLength;
  221. this.appWorkspace.ActiveDocumentWorkspace.Refresh();
  222. if (this.appWorkspace.Widgets.LabelListDialog != null)
  223. this.appWorkspace.Widgets.LabelListDialog.RefreshDateGridView(null, null);
  224. }
  225. }
  226. //预览窗口添加
  227. if (this.appWorkspace.cameraPreviewDialog != null && !this.appWorkspace.cameraPreviewDialog.IsDisposed)
  228. {
  229. this.appWorkspace.cameraPreviewDialog.documentWorkspace.ActiveTool = DrawToolType.DrawPrestoredRuler;
  230. List<DrawObject> objList = this.appWorkspace.cameraPreviewDialog.documentWorkspace.GraphicsList.GetDrawToolTypeList(DrawToolType.DrawPrestoredRuler);
  231. if (objList.Count > 0)
  232. {
  233. DrawPrestoredRuler drawPrestoredRuler = (DrawPrestoredRuler)objList[0];
  234. drawPrestoredRuler.lineLength = rulerLength;
  235. this.appWorkspace.cameraPreviewDialog.documentWorkspace.Refresh();
  236. if (this.appWorkspace.Widgets.LabelListDialog != null)
  237. this.appWorkspace.Widgets.LabelListDialog.RefreshDateGridView(null, null);
  238. }
  239. }
  240. this.Close();
  241. }
  242. }
  243. private void listView1_SelectedIndexChanged(object sender, EventArgs e)
  244. {
  245. ListViewItem defaultItem = new ListViewItem();
  246. foreach (ListViewItem listViewItem in this.listView1.Items)
  247. {
  248. listViewItem.ForeColor = defaultItem.ForeColor;
  249. listViewItem.BackColor = defaultItem.BackColor;
  250. }
  251. if (this.listView1.SelectedItems.Count <= 0)
  252. {
  253. return;
  254. }
  255. ListViewItem item = this.listView1.SelectedItems[0];
  256. item.ForeColor = Color.White;
  257. item.BackColor = Color.FromArgb(0, 120, 215);
  258. }
  259. }
  260. }