Restructured code and included capture button on form.
[toast/barcode2cash.git] / qtapp / barcode2cash / mainwindow.cpp
index 94285c256edeb20f2b3d86cd77e869aed2fd333a..42d69fcce3f0818bd748ecb367f5deb10a35eb1b 100644 (file)
@@ -1,8 +1,5 @@
 #include "mainwindow.h"
 #include "ui_mainwindow.h"
-#include <QCameraInfo>
-#include <QCameraImageCapture>
-#include <QCameraViewfinder>
 
 bool checkCameraAvailability()
 {
@@ -20,23 +17,38 @@ MainWindow::MainWindow(QWidget *parent) :
 
     QCameraInfo info = QCameraInfo::defaultCamera();
     if (!info.isNull()) {
-        QCamera* camera = new QCamera(info);
+        camera = new QCamera(info);
         camera->setCaptureMode(QCamera::CaptureStillImage);
-        QCameraViewfinder* viewfinder = new QCameraViewfinder;
+        viewfinder = new QCameraViewfinder;
         camera->setViewfinder(viewfinder);
         viewfinder->show();
-        QCameraImageCapture imageCapture(camera);
-        camera->start();
-        camera->searchAndLock();
-        imageCapture.capture("test.png");
-        camera->unlock();
-        //delete camera;
+        imageCapture = new QCameraImageCapture(camera);
+        connect(imageCapture, SIGNAL(readyForCaptureChanged(bool)), SLOT(updateCameraInfo()));
+        updateCameraInfo();
+        connect(ui->pbCapture, SIGNAL(clicked()), SLOT(capture()));
     }
 
+
     ui->statusBar->showMessage(tr("There are %1 cameras").arg(checkCameraAvailability()));
+
 }
 
-MainWindow::~MainWindow()
-{
+MainWindow::~MainWindow() {
+    delete imageCapture;
+    delete viewfinder;
+    delete camera;
     delete ui;
 }
+
+
+void MainWindow::updateCameraInfo() {
+    ui->labCameraReady->setText(imageCapture->isReadyForCapture() ? "ready" : "not ready");
+}
+
+
+void MainWindow::capture() {
+    camera->start();
+    camera->searchAndLock();
+    imageCapture->capture("test.png");
+    camera->unlock();
+}