• 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

Revisãoeaa3528a40a5c350adc3a4bb66cac1b439c8dcd9 (tree)
Hora2012-10-22 22:56:17
Autorarakaki <alucky4416@user...>
Commiterarakaki

Mensagem de Log

ADD: add Save QRCodeImage Function, add MenuBar.

Mudança Sumário

Diff

--- a/mainwindow.cpp
+++ b/mainwindow.cpp
@@ -1,6 +1,9 @@
11 #include "mainwindow.h"
22 #include "ui_mainwindow.h"
33
4+#include <QFileDialog>
5+#include <QMessageBox>
6+
47 #include <QDebug>
58
69 MainWindow::MainWindow(QWidget *parent) :
@@ -9,9 +12,11 @@ MainWindow::MainWindow(QWidget *parent) :
912 {
1013 ui->setupUi(this);
1114
15+ image = NULL;
1216 ui->imgView->setScene(&scene);
1317
1418 ui->lineEdit->setText("");
19+ ui->lineEdit->setFocus();
1520 ui->btnStart->setDisabled(true);
1621 }
1722
@@ -61,14 +66,17 @@ QPixmap MainWindow::encodeTextToPixmap( QString text )
6166 #else
6267 QByteArray a = text.toAscii();
6368 #endif
64- QRcode* qrcode = encode( (unsigned char*)a.constData() );
69+ QRcode* qrcode = encode( (unsigned char*)a.constData() ); // Generate QRCode from string.
6570 if ( qrcode == NULL )
6671 {
6772 return NULL;
6873 }
6974
7075 int realwidth = (qrcode->width + margin * 2) * size;
71- QImage* image = new QImage( realwidth, realwidth, QImage::Format_Mono );
76+ if (image != NULL) {
77+ delete(image);
78+ }
79+ image = new QImage( realwidth, realwidth, QImage::Format_Mono );
7280 QPainter painter(image);
7381
7482 painter.fillRect( QRect( 0, 0, realwidth, realwidth ), QColor( Qt::white ) );
@@ -100,7 +108,8 @@ QPixmap MainWindow::encodeTextToPixmap( QString text )
100108 painter.end();
101109
102110 QPixmap pixmap = QPixmap::fromImage(*image);
103- delete(image);
111+
112+ QRcode_free(qrcode);
104113
105114 return pixmap;
106115 }
@@ -122,3 +131,29 @@ void MainWindow::on_lineEdit_textChanged(const QString &arg1)
122131 ui->btnStart->setDisabled(false);
123132 }
124133 }
134+
135+void MainWindow::on_actionExit_triggered()
136+{
137+ close();
138+}
139+
140+void MainWindow::on_actionSave_triggered()
141+{
142+ if (image == NULL || image->isNull()) {
143+ ; // empty imagedata
144+ } else {
145+ QString fileName = QFileDialog::getSaveFileName( this, "Save Image", "./", "Image Files (*.png)" );
146+ if ( fileName.isEmpty() ) return;
147+ image->save( fileName, "PNG");
148+ }
149+}
150+
151+void MainWindow::on_actionAbout_triggered()
152+{
153+ QMessageBox::about(this, "About", tr("QtQREncode v0.1, uses libqrencode library."));
154+}
155+
156+void MainWindow::on_actionAbout_Qt_triggered()
157+{
158+ QApplication::aboutQt();
159+}
--- a/mainwindow.h
+++ b/mainwindow.h
@@ -24,10 +24,18 @@ private slots:
2424
2525 void on_lineEdit_textChanged(const QString &arg1);
2626
27+ void on_actionExit_triggered();
28+
29+ void on_actionSave_triggered();
30+
31+ void on_actionAbout_triggered();
32+
33+ void on_actionAbout_Qt_triggered();
34+
2735 private:
2836 Ui::MainWindow *ui;
2937
30- QImage image; // 表示画像を保存しておく場所
38+ QImage *image; // 表示画像を保存しておく場所
3139 QGraphicsScene scene; // QGraphicsView 上に表示させるための準備
3240
3341 QRcode *encode(const unsigned char *intext);
--- a/mainwindow.ui
+++ b/mainwindow.ui
@@ -11,14 +11,14 @@
1111 </rect>
1212 </property>
1313 <property name="windowTitle">
14- <string>MainWindow</string>
14+ <string>QtQREncode</string>
1515 </property>
1616 <widget class="QWidget" name="centralWidget">
1717 <widget class="QGraphicsView" name="imgView">
1818 <property name="geometry">
1919 <rect>
2020 <x>50</x>
21- <y>80</y>
21+ <y>90</y>
2222 <width>371</width>
2323 <height>331</height>
2424 </rect>
@@ -36,12 +36,15 @@
3636 <property name="text">
3737 <string>Input String</string>
3838 </property>
39+ <property name="buddy">
40+ <cstring>lineEdit</cstring>
41+ </property>
3942 </widget>
4043 <widget class="QLabel" name="label_2">
4144 <property name="geometry">
4245 <rect>
4346 <x>50</x>
44- <y>60</y>
47+ <y>70</y>
4548 <width>52</width>
4649 <height>14</height>
4750 </rect>
@@ -49,8 +52,11 @@
4952 <property name="text">
5053 <string>QRcode</string>
5154 </property>
55+ <property name="buddy">
56+ <cstring>imgView</cstring>
57+ </property>
5258 </widget>
53- <widget class="QWidget" name="">
59+ <widget class="QWidget" name="layoutWidget">
5460 <property name="geometry">
5561 <rect>
5662 <x>50</x>
@@ -82,6 +88,23 @@
8288 <height>22</height>
8389 </rect>
8490 </property>
91+ <widget class="QMenu" name="menuFile">
92+ <property name="title">
93+ <string>File</string>
94+ </property>
95+ <addaction name="actionSave"/>
96+ <addaction name="separator"/>
97+ <addaction name="actionExit"/>
98+ </widget>
99+ <widget class="QMenu" name="menuHelp">
100+ <property name="title">
101+ <string>Help</string>
102+ </property>
103+ <addaction name="actionAbout"/>
104+ <addaction name="actionAbout_Qt"/>
105+ </widget>
106+ <addaction name="menuFile"/>
107+ <addaction name="menuHelp"/>
85108 </widget>
86109 <widget class="QToolBar" name="mainToolBar">
87110 <attribute name="toolBarArea">
@@ -92,6 +115,32 @@
92115 </attribute>
93116 </widget>
94117 <widget class="QStatusBar" name="statusBar"/>
118+ <action name="actionSave">
119+ <property name="text">
120+ <string>Save</string>
121+ </property>
122+ <property name="shortcut">
123+ <string>Ctrl+S</string>
124+ </property>
125+ </action>
126+ <action name="actionExit">
127+ <property name="text">
128+ <string>Exit</string>
129+ </property>
130+ <property name="shortcut">
131+ <string>Ctrl+Q</string>
132+ </property>
133+ </action>
134+ <action name="actionAbout">
135+ <property name="text">
136+ <string>About</string>
137+ </property>
138+ </action>
139+ <action name="actionAbout_Qt">
140+ <property name="text">
141+ <string>About Qt</string>
142+ </property>
143+ </action>
95144 </widget>
96145 <layoutdefault spacing="6" margin="11"/>
97146 <resources/>