Restructured code and included capture button on form.
authorPhilipp Spitzer <philipp@spitzer.priv.at>
Wed, 21 Jun 2017 21:05:04 +0000 (23:05 +0200)
committerPhilipp Spitzer <philipp@spitzer.priv.at>
Wed, 21 Jun 2017 21:05:04 +0000 (23:05 +0200)
qtapp/barcode2cash/barcode2cash.pro
qtapp/barcode2cash/mainwindow.cpp
qtapp/barcode2cash/mainwindow.h
qtapp/barcode2cash/mainwindow.ui

index d4399f50b91f2f4bf6f546b7eb68b0976023349c..d4db412cc4a1797d7f479bc7d254e2c606a43b47 100644 (file)
@@ -18,3 +18,5 @@ SOURCES += main.cpp\
 HEADERS  += mainwindow.h
 
 FORMS    += mainwindow.ui
+
+CONFIG += c++11
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();
+}
index a3948a91785f23b0d16b2459b21c04ee7f0a845e..afe03a050cf58aa11f0cd6022035689f1a0c0d1c 100644 (file)
@@ -2,6 +2,10 @@
 #define MAINWINDOW_H
 
 #include <QMainWindow>
+#include <QCameraInfo>
+#include <QCameraImageCapture>
+#include <QCameraViewfinder>
+
 
 namespace Ui {
 class MainWindow;
@@ -17,6 +21,14 @@ public:
 
 private:
     Ui::MainWindow *ui;
+
+    QCamera* camera = nullptr;
+    QCameraViewfinder* viewfinder = nullptr;
+    QCameraImageCapture* imageCapture = nullptr;
+
+public slots:
+    void updateCameraInfo();
+    void capture();
 };
 
 #endif // MAINWINDOW_H
index 6050363fa71ed2da04105077f9fef06150d05ee2..a73edd65a424235dd975a3bfdbb1764ed35fb99c 100644 (file)
@@ -1,7 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
 <ui version="4.0">
  <class>MainWindow</class>
- <widget class="QMainWindow" name="MainWindow" >
-  <property name="geometry" >
+ <widget class="QMainWindow" name="MainWindow">
+  <property name="geometry">
    <rect>
     <x>0</x>
     <y>0</y>
     <height>300</height>
    </rect>
   </property>
-  <property name="windowTitle" >
+  <property name="windowTitle">
    <string>MainWindow</string>
   </property>
-  <widget class="QMenuBar" name="menuBar" />
-  <widget class="QToolBar" name="mainToolBar" />
-  <widget class="QWidget" name="centralWidget" />
-  <widget class="QStatusBar" name="statusBar" />
+  <widget class="QWidget" name="centralWidget">
+   <widget class="QPushButton" name="pbCapture">
+    <property name="geometry">
+     <rect>
+      <x>40</x>
+      <y>50</y>
+      <width>81</width>
+      <height>22</height>
+     </rect>
+    </property>
+    <property name="text">
+     <string>Capture</string>
+    </property>
+   </widget>
+   <widget class="QLabel" name="labCameraReady">
+    <property name="geometry">
+     <rect>
+      <x>50</x>
+      <y>20</y>
+      <width>59</width>
+      <height>14</height>
+     </rect>
+    </property>
+    <property name="text">
+     <string>TextLabel</string>
+    </property>
+   </widget>
+  </widget>
+  <widget class="QMenuBar" name="menuBar">
+   <property name="geometry">
+    <rect>
+     <x>0</x>
+     <y>0</y>
+     <width>400</width>
+     <height>19</height>
+    </rect>
+   </property>
+  </widget>
+  <widget class="QToolBar" name="mainToolBar">
+   <attribute name="toolBarArea">
+    <enum>TopToolBarArea</enum>
+   </attribute>
+   <attribute name="toolBarBreak">
+    <bool>false</bool>
+   </attribute>
+  </widget>
+  <widget class="QStatusBar" name="statusBar"/>
  </widget>
- <layoutDefault spacing="6" margin="11" />
- <pixmapfunction></pixmapfunction>
+ <layoutdefault spacing="6" margin="11"/>
  <resources/>
  <connections/>
 </ui>