Support SMTP URLs
[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 #include <zxing/MultiFormatReader.h>\r
34 \r
35 #include <zxing/common/GlobalHistogramBinarizer.h>\r
36 #include <zxing/Binarizer.h>\r
37 #include <zxing/BinaryBitmap.h>\r
38 #include <QFileDialog>\r
39 #include <QGraphicsView>\r
40 #include <QPainter>\r
41 #include <QPoint>\r
42 #include <QPixmap>\r
43 \r
44 using namespace zxing;\r
45 //using namespace zxing::qrcode;\r
46 \r
47 QQrDecoder::QQrDecoder(QWidget *parent): QMainWindow(parent)\r
48 {\r
49     ui.setupUi(this);\r
50     connect(ui.startDecode, SIGNAL(clicked()), this, SLOT(findAndDecode()));\r
51     connect(ui.cameraWidget, SIGNAL(imageCaptured(QImage)), this, SLOT(decodeImage(QImage)));\r
52     connect(ui.cameraWidget, SIGNAL(logMessage(QString)), ui.resultLabel, SLOT(setText(QString)));\r
53 }\r
54 \r
55 QQrDecoder::~QQrDecoder()\r
56 {\r
57 }\r
58 \r
59 void QQrDecoder::InitializeSymbianCamera()\r
60 {\r
61 \r
62 }\r
63 \r
64 void QQrDecoder::findAndDecode()\r
65 {\r
66     ui.cameraWidget->CaptureImage();\r
67 }\r
68 \r
69 void QQrDecoder::decodeImage(QImage originalImage)\r
70 {\r
71     MultiFormatReader decoder;\r
72 \r
73     image.setImage(originalImage);\r
74 \r
75     Ref<Result> res;\r
76 \r
77     try{\r
78         Ref<LuminanceSource> imageRef(new CameraImageWrapper(image));\r
79         GlobalHistogramBinarizer* binz = new GlobalHistogramBinarizer(imageRef);\r
80 \r
81         Ref<Binarizer> bz (binz);\r
82         BinaryBitmap* bb = new BinaryBitmap(bz);\r
83 \r
84         Ref<BinaryBitmap> ref(bb);\r
85 \r
86         res = decoder.decode(ref);\r
87 \r
88         QString string = QString(res->getText()->getText().c_str());\r
89         ui.resultLabel->setText(string);\r
90     }\r
91     catch(zxing::Exception& e)\r
92     {\r
93         ui.resultLabel->setText("Error");\r
94     }\r
95 }\r
96 \r
97 void QQrDecoder::reloadFormatedPicture(int x)\r
98 {\r
99 }\r
100 \r