-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQRview.cs
174 lines (145 loc) · 5.77 KB
/
QRview.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
using System.Drawing.Drawing2D;
namespace QRGenerator
{
public partial class QRview : Form
{
public QRview()
{
setting = Setting.GetInstance();
InitializeComponent();
}
private void generate_button_Click(object sender, EventArgs e)
{
if (!string.IsNullOrWhiteSpace(toEncode_textBox.Text))
{
QRGenerator qRGenerator = new(toEncode_textBox.Text);
pictureBox.Image = qRGenerator.GenerateQrCode();
setting.measurmentToDisplay = ((int)(pictureBox.Image.Height * 0.2645833333)).ToString() + "mm";
tabPage1.Invalidate();
tabPage1.Update();
}
else
{
MessageBox.Show("Brak tekstu do zakodowania!", "Uwaga", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
private void save_button_Click(object sender, EventArgs e)
{
if (pictureBox.Image != null)
{
saveFileDialog.ShowDialog();
if (saveFileDialog.FileName != "")
{
using (FileStream fs = (FileStream)saveFileDialog.OpenFile())
{
pictureBox.Image.Save(fs, System.Drawing.Imaging.ImageFormat.Png);
}
pictureBox.Image = null;
tabPage1.Invalidate();
tabPage1.Update();
}
}
else
{
MessageBox.Show("Brak wygenerowanego QRkodu do zapisania!", "Uwaga", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
private void readIcon_button_Click(object sender, EventArgs e)
{
openFileDialog.ShowDialog();
if (openFileDialog.FileName != "")
{
iconName_textBox.Text = openFileDialog.FileName;
setting.bitmap = new Bitmap(openFileDialog.FileName);
}
}
private void remove_button_Click(object sender, EventArgs e)
{
iconName_textBox.Text = "";
setting.bitmap = null;
}
private void panel_lightColor_Click(object sender, EventArgs e)
{
colorDialog_lightColor.ShowDialog();
setting.lightColor = colorDialog_lightColor.Color;
panel_lightColor.BackColor = setting.lightColor;
}
private void panel_darkColor_Click(object sender, EventArgs e)
{
colorDialog_darkColor.ShowDialog();
setting.darkColor = colorDialog_darkColor.Color;
panel_darkColor.BackColor = setting.darkColor;
}
private void panel_iconBackground_Click(object sender, EventArgs e)
{
colorDialog_iconBackground.ShowDialog();
setting.iconBackground = colorDialog_iconBackground.Color;
panel_iconBackground.BackColor = setting.iconBackground;
}
private void scrollBar_pixelPerModule_ValueChanged(object sender, EventArgs e)
{
textBox_pixelPerModule.Text = scrollBar_pixelPerModule.Value.ToString();
setting.pixelPerModule = scrollBar_pixelPerModule.Value;
}
private void scrollBar_iconSize_ValueChanged(object sender, EventArgs e)
{
textBox_iconSize.Text = scrollBar_iconSize.Value.ToString();
setting.iconSize = scrollBar_iconSize.Value;
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
setting.drawQuietZones = !setting.drawQuietZones;
}
private void tabPage1_Paint(object sender, PaintEventArgs e)
{
if (pictureBox.Image != null)
{
int labelGap = 60;
using (Pen p = new Pen(Color.Gray))
{
p.EndCap = LineCap.ArrowAnchor;
e.Graphics.DrawLine(p, 10, 72 + 350 / 2 - labelGap / 2, 10, 72);
p.EndCap = LineCap.ArrowAnchor;
e.Graphics.DrawLine(p, 10, 72 + 350 / 2 + labelGap / 2, 10, 422);
}
verticalLabel.Visible = true;
verticalLabel.Location = new Point(0, 72 + 350 / 2 - labelGap / 2);
verticalLabel.Width = 20;
verticalLabel.Height = labelGap;
verticalLabel.ForeColor = Color.Black;
verticalLabel.NewText = setting.measurmentToDisplay;
verticalLabel.Invalidate();
}
else
{
verticalLabel.Visible = false;
}
}
private void numericUpDown_iconBorderWidth_ValueChanged(object sender, EventArgs e)
{
setting.iconBorderWidth = (int)numericUpDown_iconBorderWidth.Value;
}
private void comboBox_ecc_SelectedIndexChanged(object sender, EventArgs e)
{
setting.eccLevel = comboBox_ecc.Text;
}
}
class VerticalLabel : Label
{
public int RotateAngle { get; set; }
public string NewText { get; set; }
protected override void OnPaint(PaintEventArgs e)
{
Brush b = new SolidBrush(this.ForeColor);
SizeF stringSize = e.Graphics.MeasureString(this.NewText, this.Font);
float x = (this.Width - stringSize.Width) / 2;
float y = (this.Height - stringSize.Height) / 2;
e.Graphics.TranslateTransform(this.Width / 2, this.Height / 2);
e.Graphics.RotateTransform(this.RotateAngle);
e.Graphics.TranslateTransform(-this.Width / 2, -this.Height / 2);
e.Graphics.DrawString(this.NewText, this.Font, b, x, y);
e.Graphics.ResetTransform();
base.OnPaint(e);
}
}
}