Restructured code and included capture button on form.
[toast/barcode2cash.git] / qtapp / barcode2cash / mainwindow.cpp
index 4fe6b38ab6a561cfeed72374e5f0ab6c87b44e3c..42d69fcce3f0818bd748ecb367f5deb10a35eb1b 100644 (file)
@@ -1,6 +1,5 @@
 #include "mainwindow.h"
 #include "ui_mainwindow.h"
-#include <QCameraInfo>
 
 bool checkCameraAvailability()
 {
@@ -16,10 +15,40 @@ MainWindow::MainWindow(QWidget *parent) :
 {
     ui->setupUi(this);
 
+    QCameraInfo info = QCameraInfo::defaultCamera();
+    if (!info.isNull()) {
+        camera = new QCamera(info);
+        camera->setCaptureMode(QCamera::CaptureStillImage);
+        viewfinder = new QCameraViewfinder;
+        camera->setViewfinder(viewfinder);
+        viewfinder->show();
+        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();
+}