-
Notifications
You must be signed in to change notification settings - Fork 12
/
qr_export.cpp
101 lines (87 loc) · 2.95 KB
/
qr_export.cpp
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
/* qr_export.cpp
* Copyright (C) 2016 Jonathan Bennett
* QR export class
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "qr_export.h"
BEGIN_EVENT_TABLE(qr_export, wxDialog)
// catch paint events
EVT_PAINT(qr_export::paintEvent)
END_EVENT_TABLE()
qr_export::qr_export(const wxString & title, const Config *selectedConfig)
: wxDialog(NULL, -1, title, wxDefaultPosition, wxSize(150, 150))
{
int i;
char tmpString[10024];
QRcode *ourQR = NULL;
wxImage *ourQRImage;
wxString QRBuf = wxT("");
wxBoxSizer* sizer = new wxBoxSizer(wxHORIZONTAL);
if (selectedConfig->KEY_BASE64)
QRBuf = (wxT("KEY_BASE64:"));
else
QRBuf = (wxT("KEY:"));
QRBuf.Append(selectedConfig->KEY);
if (!selectedConfig->HMAC.IsEmpty()) {
if (selectedConfig->HMAC_BASE64)
QRBuf.Append(wxT(" HMAC_KEY_BASE64:"));
else
QRBuf.Append(wxT(" HMAC_KEY:"));
QRBuf.Append(selectedConfig->HMAC);
}
strncpy(tmpString, (const char*)QRBuf.mb_str(wxConvUTF8), 10023);
ourQR = QRcode_encodeString((char *)tmpString, 0, QR_ECLEVEL_Q, QR_MODE_8, 1);
unsigned char *rawImage = new unsigned char[ourQR->width * ourQR->width * 3];
unsigned char *p = ourQR->data;
for (i=0; i < (ourQR->width * ourQR->width); i++) {
if (p[i] & 0x00000001) {
rawImage[i * 3] = 0x00;
rawImage[i * 3 + 1] = 0x00;
rawImage[i * 3 + 2] = 0x00;
} else {
rawImage[i * 3] = 0xff;
rawImage[i * 3 + 1] = 0xff;
rawImage[i * 3 + 2] = 0xff;
}
}
ourQRImage = new wxImage(ourQR->width, ourQR->width, rawImage);
ourQRImage->Rescale(ourQR->width * 4, ourQR->width * 4);
bmp = wxBitmap(*ourQRImage);
sizer->SetMinSize(bmp.GetHeight(), bmp.GetHeight());
SetSizer(sizer);
Layout();
this->Fit();
Centre();
ShowModal();
Destroy();
QRcode_free(ourQR);
}
void qr_export::paintEvent(wxPaintEvent & evt)
{
// depending on your system you may need to look at double-buffered dcs
wxPaintDC dc(this);
render(dc);
}
void qr_export::paintNow()
{
// depending on your system you may need to look at double-buffered dcs
wxClientDC dc(this);
render(dc);
}
void qr_export::render(wxDC& dc)
{
dc.DrawBitmap( bmp, 0, 0, false );
}