Saving the image works.
[toast/barcode2cash.git] / qtapp / barcode2cash / mainwindow.cpp
1 #include "mainwindow.h"
2 #include "ui_mainwindow.h"
3
4 bool checkCameraAvailability()
5 {
6     if (QCameraInfo::availableCameras().count() > 0)
7         return true;
8     else
9         return false;
10 }
11
12 MainWindow::MainWindow(QWidget *parent) :
13     QMainWindow(parent),
14     ui(new Ui::MainWindow)
15 {
16     ui->setupUi(this);
17
18     QCameraInfo info = QCameraInfo::defaultCamera();
19     if (!info.isNull()) {
20         camera = new QCamera(info);
21         camera->setCaptureMode(QCamera::CaptureStillImage);
22         viewfinder = new QCameraViewfinder;
23         camera->setViewfinder(viewfinder);
24         viewfinder->show();
25         imageCapture = new QCameraImageCapture(camera);
26         connect(imageCapture, SIGNAL(readyForCaptureChanged(bool)), SLOT(updateCameraInfo()));
27         updateCameraInfo();
28         connect(ui->pbCapture, SIGNAL(clicked()), SLOT(capture()));
29         camera->start();
30     }
31
32
33     ui->statusBar->showMessage(tr("There are %1 cameras").arg(checkCameraAvailability()));
34
35 }
36
37 MainWindow::~MainWindow() {
38     delete imageCapture;
39     delete viewfinder;
40     delete camera;
41     delete ui;
42 }
43
44
45 void MainWindow::updateCameraInfo() {
46     ui->labCameraReady->setText(imageCapture->isReadyForCapture() ? "ready" : "not ready");
47 }
48
49
50 void MainWindow::capture() {
51     QImageEncoderSettings imageSettings;
52     imageSettings.setCodec("image/jpeg");
53     imageCapture->setEncodingSettings(imageSettings);
54     camera->searchAndLock();
55     imageCapture->capture("test.jpg");
56     camera->unlock();
57 }