Commit 02779f89b9660fc53b114dc57221b321524c63e4

Authored by Caio Lucena
1 parent 0dd519e8

Camera

camerawindow.cpp
... ... @@ -16,8 +16,8 @@ CameraWindow::CameraWindow(QWidget *parent) :
16 16 camera->start();
17 17  
18 18 zxing = new QZXing( QZXing::DecoderFormat_QR_CODE, this );
19   - //connect(zxing, SIGNAL(tagFound(QString)), this, SLOT(show_result(QString)));
20 19  
  20 + connect(zxing, SIGNAL(tagFound(QString)), this, SLOT(showResult(QString)));
21 21 connect(cameraSurface, SIGNAL(novoFrame(QByteArray&,int,int)), this, SLOT(frameHandler(QByteArray&,int,int)));
22 22 }
23 23  
... ... @@ -52,6 +52,17 @@ void CameraWindow::frameHandler(QByteArray &buff, int w, int h)
52 52 zxing->decodeImage( *img, w, h, true );
53 53  
54 54 QImage imgTmp = img->scaled(w*.30, h*.30);
55   - //ui->label->setPixmap(QPixmap::fromImage(imgTmp));
  55 + ui->label->setPixmap(QPixmap::fromImage(imgTmp));
56 56 buff.clear();
57 57 }
  58 +
  59 +void CameraWindow::closeEvent(QCloseEvent *event)
  60 +{
  61 + emit close();
  62 + event->accept();
  63 +}
  64 +
  65 +void CameraWindow::showResult(QString result)
  66 +{
  67 + ui->label_2->setText(result);
  68 +}
... ...
camerawindow.h
... ... @@ -5,6 +5,7 @@
5 5 #include <QCamera>
6 6 #include <QCameraImageCapture>
7 7 #include <QCameraViewfinder>
  8 +#include <QCloseEvent>
8 9 #include <QZXing.h>
9 10 #include "camerasurface.h"
10 11  
... ... @@ -29,9 +30,14 @@ class CameraWindow : public QMainWindow
29 30 public:
30 31 explicit CameraWindow(QWidget *parent = 0);
31 32 ~CameraWindow();
  33 + virtual void closeEvent(QCloseEvent * event);
  34 +
  35 + signals:
  36 + void close();
32 37  
33 38 public slots:
34 39 void frameHandler(QByteArray&,int,int);
  40 + void showResult(QString);
35 41 };
36 42  
37 43 #endif // CAMERAWINDOW_H
... ...
camerawindow.ui
  1 +<?xml version="1.0" encoding="UTF-8"?>
1 2 <ui version="4.0">
2   - <author/>
3   - <comment/>
4   - <exportmacro/>
5 3 <class>CameraWindow</class>
6 4 <widget class="QMainWindow" name="CameraWindow">
7 5 <property name="geometry">
... ... @@ -15,10 +13,46 @@
15 13 <property name="windowTitle">
16 14 <string>MainWindow</string>
17 15 </property>
18   - <widget class="QMenuBar" name="menubar"/>
19   - <widget class="QWidget" name="centralwidget"/>
  16 + <widget class="QWidget" name="centralwidget">
  17 + <widget class="QLabel" name="label">
  18 + <property name="geometry">
  19 + <rect>
  20 + <x>40</x>
  21 + <y>10</y>
  22 + <width>481</width>
  23 + <height>211</height>
  24 + </rect>
  25 + </property>
  26 + <property name="text">
  27 + <string>Carregando...</string>
  28 + </property>
  29 + </widget>
  30 + <widget class="QLabel" name="label_2">
  31 + <property name="geometry">
  32 + <rect>
  33 + <x>30</x>
  34 + <y>240</y>
  35 + <width>241</width>
  36 + <height>81</height>
  37 + </rect>
  38 + </property>
  39 + <property name="text">
  40 + <string>qrCode</string>
  41 + </property>
  42 + </widget>
  43 + </widget>
  44 + <widget class="QMenuBar" name="menubar">
  45 + <property name="geometry">
  46 + <rect>
  47 + <x>0</x>
  48 + <y>0</y>
  49 + <width>800</width>
  50 + <height>20</height>
  51 + </rect>
  52 + </property>
  53 + </widget>
20 54 <widget class="QStatusBar" name="statusbar"/>
21 55 </widget>
22   - <pixmapfunction/>
  56 + <resources/>
23 57 <connections/>
24 58 </ui>
... ...
mainwindow.cpp
... ... @@ -7,7 +7,7 @@ MainWindow::MainWindow(QWidget *parent) :
7 7 {
8 8 ui->setupUi(this);
9 9  
10   - connect(ui->pushButton, SIGNAL(clicked(bool)), this, SLOT(addGame()));
  10 + connect(ui->pushButton, SIGNAL(clicked(bool)), this, SLOT(startCamera()));
11 11 }
12 12  
13 13 MainWindow::~MainWindow()
... ... @@ -16,9 +16,14 @@ MainWindow::~MainWindow()
16 16 delete cameraWindow;
17 17 }
18 18  
19   -void MainWindow::addGame()
  19 +void MainWindow::startCamera()
20 20 {
21   - CameraWindow * cameraWindow = new CameraWindow();
  21 + cameraWindow = new CameraWindow();
22 22 cameraWindow->show();
23   - //hide();
  23 + connect(cameraWindow, SIGNAL(close()), this, SLOT(stopCamera()));
  24 +}
  25 +
  26 +void MainWindow::stopCamera()
  27 +{
  28 + delete cameraWindow;
24 29 }
... ...
mainwindow.h
... ... @@ -18,7 +18,8 @@ class MainWindow : public QMainWindow
18 18 explicit MainWindow(QWidget *parent = 0);
19 19 ~MainWindow();
20 20 public slots:
21   - void addGame();
  21 + void startCamera();
  22 + void stopCamera();
22 23 };
23 24  
24 25 #endif // MAINWINDOW_H
... ...