Commit 02779f89b9660fc53b114dc57221b321524c63e4

Authored by Caio Lucena
1 parent 0dd519e8

Camera

camerawindow.cpp
@@ -16,8 +16,8 @@ CameraWindow::CameraWindow(QWidget *parent) : @@ -16,8 +16,8 @@ CameraWindow::CameraWindow(QWidget *parent) :
16 camera->start(); 16 camera->start();
17 17
18 zxing = new QZXing( QZXing::DecoderFormat_QR_CODE, this ); 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 connect(cameraSurface, SIGNAL(novoFrame(QByteArray&,int,int)), this, SLOT(frameHandler(QByteArray&,int,int))); 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,6 +52,17 @@ void CameraWindow::frameHandler(QByteArray &buff, int w, int h)
52 zxing->decodeImage( *img, w, h, true ); 52 zxing->decodeImage( *img, w, h, true );
53 53
54 QImage imgTmp = img->scaled(w*.30, h*.30); 54 QImage imgTmp = img->scaled(w*.30, h*.30);
55 - //ui->label->setPixmap(QPixmap::fromImage(imgTmp)); 55 + ui->label->setPixmap(QPixmap::fromImage(imgTmp));
56 buff.clear(); 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,6 +5,7 @@
5 #include <QCamera> 5 #include <QCamera>
6 #include <QCameraImageCapture> 6 #include <QCameraImageCapture>
7 #include <QCameraViewfinder> 7 #include <QCameraViewfinder>
  8 +#include <QCloseEvent>
8 #include <QZXing.h> 9 #include <QZXing.h>
9 #include "camerasurface.h" 10 #include "camerasurface.h"
10 11
@@ -29,9 +30,14 @@ class CameraWindow : public QMainWindow @@ -29,9 +30,14 @@ class CameraWindow : public QMainWindow
29 public: 30 public:
30 explicit CameraWindow(QWidget *parent = 0); 31 explicit CameraWindow(QWidget *parent = 0);
31 ~CameraWindow(); 32 ~CameraWindow();
  33 + virtual void closeEvent(QCloseEvent * event);
  34 +
  35 + signals:
  36 + void close();
32 37
33 public slots: 38 public slots:
34 void frameHandler(QByteArray&,int,int); 39 void frameHandler(QByteArray&,int,int);
  40 + void showResult(QString);
35 }; 41 };
36 42
37 #endif // CAMERAWINDOW_H 43 #endif // CAMERAWINDOW_H
camerawindow.ui
  1 +<?xml version="1.0" encoding="UTF-8"?>
1 <ui version="4.0"> 2 <ui version="4.0">
2 - <author/>  
3 - <comment/>  
4 - <exportmacro/>  
5 <class>CameraWindow</class> 3 <class>CameraWindow</class>
6 <widget class="QMainWindow" name="CameraWindow"> 4 <widget class="QMainWindow" name="CameraWindow">
7 <property name="geometry"> 5 <property name="geometry">
@@ -15,10 +13,46 @@ @@ -15,10 +13,46 @@
15 <property name="windowTitle"> 13 <property name="windowTitle">
16 <string>MainWindow</string> 14 <string>MainWindow</string>
17 </property> 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 <widget class="QStatusBar" name="statusbar"/> 54 <widget class="QStatusBar" name="statusbar"/>
21 </widget> 55 </widget>
22 - <pixmapfunction/> 56 + <resources/>
23 <connections/> 57 <connections/>
24 </ui> 58 </ui>
mainwindow.cpp
@@ -7,7 +7,7 @@ MainWindow::MainWindow(QWidget *parent) : @@ -7,7 +7,7 @@ MainWindow::MainWindow(QWidget *parent) :
7 { 7 {
8 ui->setupUi(this); 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 MainWindow::~MainWindow() 13 MainWindow::~MainWindow()
@@ -16,9 +16,14 @@ MainWindow::~MainWindow() @@ -16,9 +16,14 @@ MainWindow::~MainWindow()
16 delete cameraWindow; 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 cameraWindow->show(); 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,7 +18,8 @@ class MainWindow : public QMainWindow
18 explicit MainWindow(QWidget *parent = 0); 18 explicit MainWindow(QWidget *parent = 0);
19 ~MainWindow(); 19 ~MainWindow();
20 public slots: 20 public slots:
21 - void addGame(); 21 + void startCamera();
  22 + void stopCamera();
22 }; 23 };
23 24
24 #endif // MAINWINDOW_H 25 #endif // MAINWINDOW_H