• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

QtSDKとqrencodeを使ったQRコード画像生成


Commit MetaInfo

Revision22699fa0f0eea5d7d7a6906f651158baae94f9b0 (tree)
Zeit2012-10-23 22:24:59
Autorarakaki <alucky4416@user...>
Commiterarakaki

Log Message

ADD: add size, margin Parameter on Panel. add ToClipboard Function on Edit->ToClipboard menu.

Ändern Zusammenfassung

Diff

--- a/mainwindow.cpp
+++ b/mainwindow.cpp
@@ -3,6 +3,8 @@
33
44 #include <QFileDialog>
55 #include <QMessageBox>
6+#include <QTextCodec>
7+#include <QClipboard>
68
79 #include <QDebug>
810
@@ -25,14 +27,14 @@ MainWindow::~MainWindow()
2527 delete ui;
2628 }
2729
28-QRcode *MainWindow::encode(const unsigned char *intext)
30+QRcode *MainWindow::encode(const unsigned char *intext, int length)
2931 {
3032 QRcode *code;
3133
32- int casesensitive = 1;
34+// int casesensitive = 1;
3335 int version = 0;
3436 QRecLevel level = QR_ECLEVEL_L;
35- QRencodeMode hint = QR_MODE_8;
37+// QRencodeMode hint = QR_MODE_8;
3638
3739 // if(micro) {
3840 // if(eightbit) {
@@ -42,19 +44,19 @@ QRcode *MainWindow::encode(const unsigned char *intext)
4244 // }
4345 // } else {
4446 // if(eightbit) {
45-// code = QRcode_encodeData(length, intext, version, level);
47+ code = QRcode_encodeData(length, intext, version, level);
4648 // } else {
47- code = QRcode_encodeString((char *)intext, version, level, hint, casesensitive);
49+// code = QRcode_encodeString((char *)intext, version, level, hint, casesensitive);
4850 // }
4951 // }
5052
5153 return code;
5254 }
5355
54-QPixmap MainWindow::encodeTextToPixmap( QString text )
56+QPixmap MainWindow::encodeTextToPixmap( QString text, int size = 3, int margin = 3 )
5557 {
56- int margin = 3;
57- int size = 3;
58+// int margin = 3;
59+// int size = 3;
5860
5961 #if 0
6062 QByteArray a = text.toUtf8();
@@ -64,9 +66,10 @@ QPixmap MainWindow::encodeTextToPixmap( QString text )
6466 a.insert( 0, BOM );
6567 }
6668 #else
67- QByteArray a = text.toAscii();
69+ QTextCodec* sjisCodec = QTextCodec::codecForName( "SJIS" ); // should be ShiftJIS for Japanese MobilePhone.
70+ QByteArray a = sjisCodec->fromUnicode( text );
6871 #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.
7073 if ( qrcode == NULL )
7174 {
7275 return NULL;
@@ -118,7 +121,7 @@ void MainWindow::on_btnStart_clicked()
118121 {
119122
120123 scene.clear();
121- QPixmap pixmap = encodeTextToPixmap(ui->lineEdit->text());
124+ QPixmap pixmap = encodeTextToPixmap(ui->lineEdit->text(), ui->spinBox_size->value(), ui->spinBox_margin->value());
122125 scene.addPixmap( pixmap );
123126
124127 }
@@ -148,6 +151,16 @@ void MainWindow::on_actionSave_triggered()
148151 }
149152 }
150153
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+
151164 void MainWindow::on_actionAbout_triggered()
152165 {
153166 QMessageBox::about(this, "About", tr("QtQREncode v0.1, uses libqrencode library."));
--- a/mainwindow.h
+++ b/mainwindow.h
@@ -28,18 +28,21 @@ private slots:
2828
2929 void on_actionSave_triggered();
3030
31+ void on_actionToClibboard_triggered();
32+
3133 void on_actionAbout_triggered();
3234
3335 void on_actionAbout_Qt_triggered();
3436
37+
3538 private:
3639 Ui::MainWindow *ui;
3740
3841 QImage *image; // 表示画像を保存しておく場所
3942 QGraphicsScene scene; // QGraphicsView 上に表示させるための準備
4043
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 );
4346
4447 // int qrdata_expand(unsigned char *qrcode_data, int qrcode_width, int margin, int size, unsigned char* img_data);
4548 };
--- a/mainwindow.ui
+++ b/mainwindow.ui
@@ -6,8 +6,8 @@
66 <rect>
77 <x>0</x>
88 <y>0</y>
9- <width>480</width>
10- <height>497</height>
9+ <width>410</width>
10+ <height>530</height>
1111 </rect>
1212 </property>
1313 <property name="windowTitle">
@@ -17,8 +17,8 @@
1717 <widget class="QGraphicsView" name="imgView">
1818 <property name="geometry">
1919 <rect>
20- <x>50</x>
21- <y>90</y>
20+ <x>20</x>
21+ <y>130</y>
2222 <width>371</width>
2323 <height>331</height>
2424 </rect>
@@ -27,8 +27,8 @@
2727 <widget class="QLabel" name="label">
2828 <property name="geometry">
2929 <rect>
30- <x>50</x>
31- <y>10</y>
30+ <x>20</x>
31+ <y>60</y>
3232 <width>91</width>
3333 <height>16</height>
3434 </rect>
@@ -43,8 +43,8 @@
4343 <widget class="QLabel" name="label_2">
4444 <property name="geometry">
4545 <rect>
46- <x>50</x>
47- <y>70</y>
46+ <x>20</x>
47+ <y>110</y>
4848 <width>52</width>
4949 <height>14</height>
5050 </rect>
@@ -59,8 +59,8 @@
5959 <widget class="QWidget" name="layoutWidget">
6060 <property name="geometry">
6161 <rect>
62- <x>50</x>
63- <y>30</y>
62+ <x>20</x>
63+ <y>80</y>
6464 <width>371</width>
6565 <height>27</height>
6666 </rect>
@@ -72,19 +72,92 @@
7272 <item>
7373 <widget class="QPushButton" name="btnStart">
7474 <property name="text">
75- <string>Go!</string>
75+ <string>Encode</string>
7676 </property>
7777 </widget>
7878 </item>
7979 </layout>
8080 </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>
81154 </widget>
82155 <widget class="QMenuBar" name="menuBar">
83156 <property name="geometry">
84157 <rect>
85158 <x>0</x>
86159 <y>0</y>
87- <width>480</width>
160+ <width>410</width>
88161 <height>22</height>
89162 </rect>
90163 </property>
@@ -103,7 +176,14 @@
103176 <addaction name="actionAbout"/>
104177 <addaction name="actionAbout_Qt"/>
105178 </widget>
179+ <widget class="QMenu" name="menuEdit">
180+ <property name="title">
181+ <string>Edit</string>
182+ </property>
183+ <addaction name="actionToClibboard"/>
184+ </widget>
106185 <addaction name="menuFile"/>
186+ <addaction name="menuEdit"/>
107187 <addaction name="menuHelp"/>
108188 </widget>
109189 <widget class="QToolBar" name="mainToolBar">
@@ -141,6 +221,11 @@
141221 <string>About Qt</string>
142222 </property>
143223 </action>
224+ <action name="actionToClibboard">
225+ <property name="text">
226+ <string>toClibboard</string>
227+ </property>
228+ </action>
144229 </widget>
145230 <layoutdefault spacing="6" margin="11"/>
146231 <resources/>