Added a project written on Qt framework for Symbian and added tutorials for both...
[zxing.git] / symbian / QQrDecoder / QQrDecoder.cpp
1 /****************************************************************************\r
2  **\r
3  ** Trolltech hereby grants a license to use the Qt/Eclipse Integration\r
4  ** plug-in (the software contained herein), in binary form, solely for the\r
5  ** purpose of creating code to be used with Trolltech's Qt software.\r
6  **\r
7  ** Qt Designer is licensed under the terms of the GNU General Public\r
8  ** License versions 2.0 and 3.0 ("GPL License"). Trolltech offers users the\r
9  ** right to use certain no GPL licensed software under the terms of its GPL\r
10  ** Exception version 1.2 (http://trolltech.com/products/qt/gplexception).\r
11  **\r
12  ** THIS SOFTWARE IS PROVIDED BY TROLLTECH AND ITS CONTRIBUTORS (IF ANY) "AS\r
13  ** IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED\r
14  ** TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A\r
15  ** PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER\r
16  ** OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,\r
17  ** EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,\r
18  ** PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\r
19  ** PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\r
20  ** LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\r
21  ** NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\r
22  ** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."\r
23  **\r
24  ** Since we now have the GPL exception I think that the "special exception\r
25  ** is no longer needed. The license text proposed above (other than the\r
26  ** special exception portion of it) is the BSD license and we have added\r
27  ** the BSD license as a permissible license under the exception.\r
28  **\r
29  ****************************************************************************/\r
30 \r
31 #include "QQrDecoder.h"\r
32 #include <zxing/qrcode/QRCodeReader.h>\r
33 \r
34 #include <zxing/common/GlobalHistogramBinarizer.h>\r
35 #include <zxing/Binarizer.h>\r
36 #include <zxing/BinaryBitmap.h>\r
37 #include <QFileDialog>\r
38 #include <QGraphicsView>\r
39 #include <QPainter>\r
40 #include <QPoint>\r
41 #include <QPixmap>\r
42 \r
43 using namespace zxing;\r
44 using namespace zxing::qrcode;\r
45 \r
46 QQrDecoder::QQrDecoder(QWidget *parent): QMainWindow(parent)\r
47 {\r
48     ui.setupUi(this);\r
49     connect(ui.startDecode, SIGNAL(clicked()), this, SLOT(findAndDecode()));\r
50     connect(ui.cameraWidget, SIGNAL(imageCaptured(QImage)), this, SLOT(decodeImage(QImage)));\r
51     connect(ui.cameraWidget, SIGNAL(logMessage(QString)), ui.resultLabel, SLOT(setText(QString)));\r
52 }\r
53 \r
54 QQrDecoder::~QQrDecoder()\r
55 {\r
56 }\r
57 \r
58 void QQrDecoder::InitializeSymbianCamera()\r
59 {\r
60 \r
61 }\r
62 \r
63 void QQrDecoder::findAndDecode()\r
64 {\r
65     ui.cameraWidget->CaptureImage();\r
66 }\r
67 \r
68 void QQrDecoder::decodeImage(QImage originalImage)\r
69 {\r
70     QRCodeReader decoder;\r
71 \r
72     image.setImage(originalImage);\r
73 \r
74     Ref<Result> res;\r
75 \r
76     try{\r
77         Ref<LuminanceSource> imageRef(new CameraImageWrapper(image));\r
78         GlobalHistogramBinarizer* binz = new GlobalHistogramBinarizer(imageRef);\r
79 \r
80         Ref<Binarizer> bz (binz);\r
81         BinaryBitmap* bb = new BinaryBitmap(bz);\r
82 \r
83         Ref<BinaryBitmap> ref(bb);\r
84 \r
85         res = decoder.decode(ref);\r
86 \r
87         QString string = QString(res->getText()->getText().c_str());\r
88         ui.resultLabel->setText(string);\r
89     }\r
90     catch(zxing::Exception& e)\r
91     {\r
92         ui.resultLabel->setText("Error");\r
93     }\r
94 }\r
95 \r
96 void QQrDecoder::reloadFormatedPicture(int x)\r
97 {\r
98 }\r
99 \r