QtSDKとqrencodeを使ったQRコード画像生成
Revision | 22699fa0f0eea5d7d7a6906f651158baae94f9b0 (tree) |
---|---|
Zeit | 2012-10-23 22:24:59 |
Autor | arakaki <alucky4416@user...> |
Commiter | arakaki |
ADD: add size, margin Parameter on Panel. add ToClipboard Function on Edit->ToClipboard menu.
@@ -3,6 +3,8 @@ | ||
3 | 3 | |
4 | 4 | #include <QFileDialog> |
5 | 5 | #include <QMessageBox> |
6 | +#include <QTextCodec> | |
7 | +#include <QClipboard> | |
6 | 8 | |
7 | 9 | #include <QDebug> |
8 | 10 |
@@ -25,14 +27,14 @@ MainWindow::~MainWindow() | ||
25 | 27 | delete ui; |
26 | 28 | } |
27 | 29 | |
28 | -QRcode *MainWindow::encode(const unsigned char *intext) | |
30 | +QRcode *MainWindow::encode(const unsigned char *intext, int length) | |
29 | 31 | { |
30 | 32 | QRcode *code; |
31 | 33 | |
32 | - int casesensitive = 1; | |
34 | +// int casesensitive = 1; | |
33 | 35 | int version = 0; |
34 | 36 | QRecLevel level = QR_ECLEVEL_L; |
35 | - QRencodeMode hint = QR_MODE_8; | |
37 | +// QRencodeMode hint = QR_MODE_8; | |
36 | 38 | |
37 | 39 | // if(micro) { |
38 | 40 | // if(eightbit) { |
@@ -42,19 +44,19 @@ QRcode *MainWindow::encode(const unsigned char *intext) | ||
42 | 44 | // } |
43 | 45 | // } else { |
44 | 46 | // if(eightbit) { |
45 | -// code = QRcode_encodeData(length, intext, version, level); | |
47 | + code = QRcode_encodeData(length, intext, version, level); | |
46 | 48 | // } else { |
47 | - code = QRcode_encodeString((char *)intext, version, level, hint, casesensitive); | |
49 | +// code = QRcode_encodeString((char *)intext, version, level, hint, casesensitive); | |
48 | 50 | // } |
49 | 51 | // } |
50 | 52 | |
51 | 53 | return code; |
52 | 54 | } |
53 | 55 | |
54 | -QPixmap MainWindow::encodeTextToPixmap( QString text ) | |
56 | +QPixmap MainWindow::encodeTextToPixmap( QString text, int size = 3, int margin = 3 ) | |
55 | 57 | { |
56 | - int margin = 3; | |
57 | - int size = 3; | |
58 | +// int margin = 3; | |
59 | +// int size = 3; | |
58 | 60 | |
59 | 61 | #if 0 |
60 | 62 | QByteArray a = text.toUtf8(); |
@@ -64,9 +66,10 @@ QPixmap MainWindow::encodeTextToPixmap( QString text ) | ||
64 | 66 | a.insert( 0, BOM ); |
65 | 67 | } |
66 | 68 | #else |
67 | - QByteArray a = text.toAscii(); | |
69 | + QTextCodec* sjisCodec = QTextCodec::codecForName( "SJIS" ); // should be ShiftJIS for Japanese MobilePhone. | |
70 | + QByteArray a = sjisCodec->fromUnicode( text ); | |
68 | 71 | #endif |
69 | - QRcode* qrcode = encode( (unsigned char*)a.constData() ); // Generate QRCode from string. | |
72 | + QRcode* qrcode = encode( (unsigned char*)a.constData(), a.length() ); // Generate QRCode from string. | |
70 | 73 | if ( qrcode == NULL ) |
71 | 74 | { |
72 | 75 | return NULL; |
@@ -118,7 +121,7 @@ void MainWindow::on_btnStart_clicked() | ||
118 | 121 | { |
119 | 122 | |
120 | 123 | scene.clear(); |
121 | - QPixmap pixmap = encodeTextToPixmap(ui->lineEdit->text()); | |
124 | + QPixmap pixmap = encodeTextToPixmap(ui->lineEdit->text(), ui->spinBox_size->value(), ui->spinBox_margin->value()); | |
122 | 125 | scene.addPixmap( pixmap ); |
123 | 126 | |
124 | 127 | } |
@@ -148,6 +151,16 @@ void MainWindow::on_actionSave_triggered() | ||
148 | 151 | } |
149 | 152 | } |
150 | 153 | |
154 | +void MainWindow::on_actionToClibboard_triggered() | |
155 | +{ | |
156 | + if (image == NULL || image->isNull()) { | |
157 | + ; | |
158 | + } else { | |
159 | + QClipboard *clipboard = QApplication::clipboard(); | |
160 | + clipboard->setImage(*image); | |
161 | + } | |
162 | +} | |
163 | + | |
151 | 164 | void MainWindow::on_actionAbout_triggered() |
152 | 165 | { |
153 | 166 | QMessageBox::about(this, "About", tr("QtQREncode v0.1, uses libqrencode library.")); |
@@ -28,18 +28,21 @@ private slots: | ||
28 | 28 | |
29 | 29 | void on_actionSave_triggered(); |
30 | 30 | |
31 | + void on_actionToClibboard_triggered(); | |
32 | + | |
31 | 33 | void on_actionAbout_triggered(); |
32 | 34 | |
33 | 35 | void on_actionAbout_Qt_triggered(); |
34 | 36 | |
37 | + | |
35 | 38 | private: |
36 | 39 | Ui::MainWindow *ui; |
37 | 40 | |
38 | 41 | QImage *image; // 表示画像を保存しておく場所 |
39 | 42 | QGraphicsScene scene; // QGraphicsView 上に表示させるための準備 |
40 | 43 | |
41 | - QRcode *encode(const unsigned char *intext); | |
42 | - QPixmap encodeTextToPixmap( QString text ); | |
44 | + QRcode *encode(const unsigned char *intext, int length); | |
45 | + QPixmap encodeTextToPixmap( QString text, int size, int margin ); | |
43 | 46 | |
44 | 47 | // int qrdata_expand(unsigned char *qrcode_data, int qrcode_width, int margin, int size, unsigned char* img_data); |
45 | 48 | }; |
@@ -6,8 +6,8 @@ | ||
6 | 6 | <rect> |
7 | 7 | <x>0</x> |
8 | 8 | <y>0</y> |
9 | - <width>480</width> | |
10 | - <height>497</height> | |
9 | + <width>410</width> | |
10 | + <height>530</height> | |
11 | 11 | </rect> |
12 | 12 | </property> |
13 | 13 | <property name="windowTitle"> |
@@ -17,8 +17,8 @@ | ||
17 | 17 | <widget class="QGraphicsView" name="imgView"> |
18 | 18 | <property name="geometry"> |
19 | 19 | <rect> |
20 | - <x>50</x> | |
21 | - <y>90</y> | |
20 | + <x>20</x> | |
21 | + <y>130</y> | |
22 | 22 | <width>371</width> |
23 | 23 | <height>331</height> |
24 | 24 | </rect> |
@@ -27,8 +27,8 @@ | ||
27 | 27 | <widget class="QLabel" name="label"> |
28 | 28 | <property name="geometry"> |
29 | 29 | <rect> |
30 | - <x>50</x> | |
31 | - <y>10</y> | |
30 | + <x>20</x> | |
31 | + <y>60</y> | |
32 | 32 | <width>91</width> |
33 | 33 | <height>16</height> |
34 | 34 | </rect> |
@@ -43,8 +43,8 @@ | ||
43 | 43 | <widget class="QLabel" name="label_2"> |
44 | 44 | <property name="geometry"> |
45 | 45 | <rect> |
46 | - <x>50</x> | |
47 | - <y>70</y> | |
46 | + <x>20</x> | |
47 | + <y>110</y> | |
48 | 48 | <width>52</width> |
49 | 49 | <height>14</height> |
50 | 50 | </rect> |
@@ -59,8 +59,8 @@ | ||
59 | 59 | <widget class="QWidget" name="layoutWidget"> |
60 | 60 | <property name="geometry"> |
61 | 61 | <rect> |
62 | - <x>50</x> | |
63 | - <y>30</y> | |
62 | + <x>20</x> | |
63 | + <y>80</y> | |
64 | 64 | <width>371</width> |
65 | 65 | <height>27</height> |
66 | 66 | </rect> |
@@ -72,19 +72,92 @@ | ||
72 | 72 | <item> |
73 | 73 | <widget class="QPushButton" name="btnStart"> |
74 | 74 | <property name="text"> |
75 | - <string>Go!</string> | |
75 | + <string>Encode</string> | |
76 | 76 | </property> |
77 | 77 | </widget> |
78 | 78 | </item> |
79 | 79 | </layout> |
80 | 80 | </widget> |
81 | + <widget class="QWidget" name=""> | |
82 | + <property name="geometry"> | |
83 | + <rect> | |
84 | + <x>20</x> | |
85 | + <y>20</y> | |
86 | + <width>83</width> | |
87 | + <height>26</height> | |
88 | + </rect> | |
89 | + </property> | |
90 | + <layout class="QHBoxLayout" name="horizontalLayout_2"> | |
91 | + <item> | |
92 | + <widget class="QLabel" name="label_3"> | |
93 | + <property name="text"> | |
94 | + <string>Size</string> | |
95 | + </property> | |
96 | + </widget> | |
97 | + </item> | |
98 | + <item> | |
99 | + <widget class="QSpinBox" name="spinBox_size"> | |
100 | + <property name="alignment"> | |
101 | + <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> | |
102 | + </property> | |
103 | + <property name="minimum"> | |
104 | + <number>3</number> | |
105 | + </property> | |
106 | + <property name="maximum"> | |
107 | + <number>12</number> | |
108 | + </property> | |
109 | + </widget> | |
110 | + </item> | |
111 | + </layout> | |
112 | + </widget> | |
113 | + <widget class="QWidget" name=""> | |
114 | + <property name="geometry"> | |
115 | + <rect> | |
116 | + <x>140</x> | |
117 | + <y>20</y> | |
118 | + <width>96</width> | |
119 | + <height>26</height> | |
120 | + </rect> | |
121 | + </property> | |
122 | + <layout class="QHBoxLayout" name="horizontalLayout_3"> | |
123 | + <item> | |
124 | + <widget class="QLabel" name="label_4"> | |
125 | + <property name="text"> | |
126 | + <string>Margin</string> | |
127 | + </property> | |
128 | + </widget> | |
129 | + </item> | |
130 | + <item> | |
131 | + <widget class="QSpinBox" name="spinBox_margin"> | |
132 | + <property name="alignment"> | |
133 | + <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> | |
134 | + </property> | |
135 | + <property name="minimum"> | |
136 | + <number>3</number> | |
137 | + </property> | |
138 | + <property name="maximum"> | |
139 | + <number>12</number> | |
140 | + </property> | |
141 | + </widget> | |
142 | + </item> | |
143 | + </layout> | |
144 | + </widget> | |
145 | + <zorder>imgView</zorder> | |
146 | + <zorder>label</zorder> | |
147 | + <zorder>label_2</zorder> | |
148 | + <zorder>layoutWidget</zorder> | |
149 | + <zorder>spinBox_size</zorder> | |
150 | + <zorder>spinBox_margin</zorder> | |
151 | + <zorder>lineEdit</zorder> | |
152 | + <zorder>label_3</zorder> | |
153 | + <zorder>label_4</zorder> | |
81 | 154 | </widget> |
82 | 155 | <widget class="QMenuBar" name="menuBar"> |
83 | 156 | <property name="geometry"> |
84 | 157 | <rect> |
85 | 158 | <x>0</x> |
86 | 159 | <y>0</y> |
87 | - <width>480</width> | |
160 | + <width>410</width> | |
88 | 161 | <height>22</height> |
89 | 162 | </rect> |
90 | 163 | </property> |
@@ -103,7 +176,14 @@ | ||
103 | 176 | <addaction name="actionAbout"/> |
104 | 177 | <addaction name="actionAbout_Qt"/> |
105 | 178 | </widget> |
179 | + <widget class="QMenu" name="menuEdit"> | |
180 | + <property name="title"> | |
181 | + <string>Edit</string> | |
182 | + </property> | |
183 | + <addaction name="actionToClibboard"/> | |
184 | + </widget> | |
106 | 185 | <addaction name="menuFile"/> |
186 | + <addaction name="menuEdit"/> | |
107 | 187 | <addaction name="menuHelp"/> |
108 | 188 | </widget> |
109 | 189 | <widget class="QToolBar" name="mainToolBar"> |
@@ -141,6 +221,11 @@ | ||
141 | 221 | <string>About Qt</string> |
142 | 222 | </property> |
143 | 223 | </action> |
224 | + <action name="actionToClibboard"> | |
225 | + <property name="text"> | |
226 | + <string>toClibboard</string> | |
227 | + </property> | |
228 | + </action> | |
144 | 229 | </widget> |
145 | 230 | <layoutdefault spacing="6" margin="11"/> |
146 | 231 | <resources/> |