A preview windows shows something from the camera.
[toast/barcode2cash.git] / qtapp / barcode2cash / mainwindow.cpp
1 #include "mainwindow.h"
2 #include "ui_mainwindow.h"
3 #include <QCameraInfo>
4 #include <QCameraImageCapture>
5 #include <QCameraViewfinder>
6
7 bool checkCameraAvailability()
8 {
9     if (QCameraInfo::availableCameras().count() > 0)
10         return true;
11     else
12         return false;
13 }
14
15 MainWindow::MainWindow(QWidget *parent) :
16     QMainWindow(parent),
17     ui(new Ui::MainWindow)
18 {
19     ui->setupUi(this);
20
21     QCameraInfo info = QCameraInfo::defaultCamera();
22     if (!info.isNull()) {
23         QCamera* camera = new QCamera(info);
24         camera->setCaptureMode(QCamera::CaptureStillImage);
25         QCameraViewfinder* viewfinder = new QCameraViewfinder;
26         camera->setViewfinder(viewfinder);
27         viewfinder->show();
28         QCameraImageCapture imageCapture(camera);
29         camera->start();
30         camera->searchAndLock();
31         imageCapture.capture("test.png");
32         camera->unlock();
33         //delete camera;
34     }
35
36     ui->statusBar->showMessage(tr("There are %1 cameras").arg(checkCameraAvailability()));
37 }
38
39 MainWindow::~MainWindow()
40 {
41     delete ui;
42 }