Initial webcam interface for fermenter view

Tue, 09 Aug 2022 12:45:49 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Tue, 09 Aug 2022 12:45:49 +0200
changeset 391
42936c86cbac
parent 390
2a69be28a925
child 392
e5b14c5d646b

Initial webcam interface for fermenter view

CMakeLists.txt file | annotate | diff | comparison | revisions
src/DetailFermenter.cpp file | annotate | diff | comparison | revisions
src/DetailFermenter.h file | annotate | diff | comparison | revisions
src/Webcam.cpp file | annotate | diff | comparison | revisions
src/Webcam.h file | annotate | diff | comparison | revisions
--- a/CMakeLists.txt	Fri Aug 05 20:13:11 2022 +0200
+++ b/CMakeLists.txt	Tue Aug 09 12:45:49 2022 +0200
@@ -64,7 +64,7 @@
 # ===== Find Qt5 =====
 
 # Minimum versio 5.13 for debug messages.
-find_package(Qt5 5.13 REQUIRED COMPONENTS Core Widgets Network Sql LinguistTools PrintSupport WebSockets Charts)
+find_package(Qt5 5.13 REQUIRED COMPONENTS Core Widgets Network Sql LinguistTools PrintSupport WebSockets Charts WebEngineWidgets)
 INCLUDE_DIRECTORIES(${Qt5Core_INCLUDE_DIRS})
 INCLUDE_DIRECTORIES(${Qt5Widgets_INCLUDE_DIRS})
 INCLUDE_DIRECTORIES(${Qt5Network_INCLUDE_DIRS})
@@ -73,6 +73,7 @@
 INCLUDE_DIRECTORIES(${Qt5PrintSupport_INCLUDE_DIRS})
 INCLUDE_DIRECTORIES(${Qt5WebSockets_INCLUDE_DIRS})
 INCLUDE_DIRECTORIES(${Qt5Charts_INCLUDE_DIRS})
+INCLUDE_DIRECTORIES(${Qt5WebEngineWidgets_INCLUDE_DIRS})
 
 # Xml
 
@@ -228,6 +229,7 @@
     ${SRCDIR}/ChartCarbonate.cpp
     ${SRCDIR}/ChartFermenter.cpp
     ${SRCDIR}/ChartiSpindel.cpp
+    ${SRCDIR}/Webcam.cpp
     ${SRCDIR}/EditProduct.cpp
     ${SRCDIR}/ImportXML.cpp
     ${SRCDIR}/ImportBrew.cpp
@@ -293,6 +295,7 @@
     ${SRCDIR}/ChartCarbonate.h
     ${SRCDIR}/ChartFermenter.h
     ${SRCDIR}/ChartiSpindel.h
+    ${SRCDIR}/Webcam.h
     ${SRCDIR}/EditProduct.h
     ${SRCDIR}/ImportXML.h
     ${SRCDIR}/ImportBrew.h
@@ -377,7 +380,7 @@
   )
 
   add_executable(${bmsapp_EXECUTABLE} ${SOURCE_FILES} ${QM_FILES})
-  target_link_libraries(${bmsapp_EXECUTABLE} Qt5::Core Qt5::Widgets Qt5::Network Qt5::Sql Qt5::PrintSupport Qt5::WebSockets Qt5::Charts)
+  target_link_libraries(${bmsapp_EXECUTABLE} Qt5::Core Qt5::Widgets Qt5::Network Qt5::Sql Qt5::PrintSupport Qt5::WebSockets Qt5::Charts Qt5::WebEngineWidgets)
 
   # `make translations'
   add_custom_target(translations DEPENDS ${QM_FILES})
--- a/src/DetailFermenter.cpp	Fri Aug 05 20:13:11 2022 +0200
+++ b/src/DetailFermenter.cpp	Tue Aug 09 12:45:49 2022 +0200
@@ -16,6 +16,7 @@
  */
 #include "DetailFermenter.h"
 #include "ChartFermenter.h"
+#include "Webcam.h"
 #include "../ui/ui_DetailFermenter.h"
 #include "global.h"
 #include "MainWindow.h"
@@ -88,6 +89,7 @@
     connect(ui->codePick, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &DetailFermenter::code_changed);
     connect(ui->profilePick, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &DetailFermenter::profile_changed);
     connect(ui->logButton, SIGNAL(clicked()), this, SLOT(on_ChartButton_clicked()));
+    connect(ui->camButton, SIGNAL(clicked()), this, SLOT(on_WebcamButton_clicked()));
     connect(parent, SIGNAL(updateFermenter(QString)), this, SLOT(refreshFermenter(QString)));
     emit refreshTable();
 }
@@ -122,6 +124,8 @@
 	_uuid = query.value("uuid").toString();
 	_beercode = query.value("beercode").toString();
 	_beername = query.value("beername").toString();
+	_webcam_url = query.value("webcam_url").toString();
+	_webcam_light = query.value("webcam_light").toInt();
 
 	ui->uuidEdit->setText(_uuid);
 	ui->systemEdit->setText(_node+"/"+_alias);
@@ -278,7 +282,7 @@
 		_profile = QString("");
 	    }
 
-	    if (query.value("webcam_url").toString() == "") {
+	    if (_webcam_url == "") {
 		ui->camButton->hide();
 	    } else {
 		ui->camButton->show();
@@ -340,6 +344,14 @@
 }
 
 
+void DetailFermenter::on_WebcamButton_clicked()
+{
+    QString msg = QString("{\"device\":\"fermenters\",\"node\":\""+_node+"\",\"unit\":\""+_alias+"\",\"light_state\":100}");
+    webSocket->sendTextMessage(msg);
+    Webcam dialog(_webcam_url, this);
+}
+
+
 void DetailFermenter::on_quitButton_clicked()
 {
     this->close();
--- a/src/DetailFermenter.h	Fri Aug 05 20:13:11 2022 +0200
+++ b/src/DetailFermenter.h	Tue Aug 09 12:45:49 2022 +0200
@@ -40,14 +40,15 @@
     void code_changed(int val);
     void profile_changed(int val);
     void on_ChartButton_clicked();
+    void on_WebcamButton_clicked();
 
 public slots:
     void refreshFermenter(QString);
 
 private:
     Ui::DetailFermenter *ui;
-    QString _node, _alias, _uuid, _profile, _beercode, _beername;
-    int recno;
+    QString _node, _alias, _uuid, _profile, _beercode, _beername, _webcam_url;
+    int recno, _webcam_light;
     double lo_set = 0, hi_set = 0;
     bool heat_state = false;
     bool cool_state = false;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/Webcam.cpp	Tue Aug 09 12:45:49 2022 +0200
@@ -0,0 +1,56 @@
+/**
+ * Webcam.cpp is part of bmsapp.
+ *
+ * bmsapp is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * bmsapp is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#include "Webcam.h"
+#include "MainWindow.h"
+
+#include <QWebEngineView>
+
+Webcam::Webcam(QString url, QWidget *parent) : QDialog(parent)
+{
+    qDebug() << "Webcam:" << url;
+
+    dialog = new QDialog(parent);
+    dialog->setWindowTitle(tr("BMSapp - Webcam ") + url);
+    dialog->setObjectName(QString::fromUtf8("Webcam"));
+    dialog->setWindowFlags(Qt::Window | Qt::WindowTitleHint | Qt::CustomizeWindowHint);
+
+    QWebEngineView *m_view(new QWebEngineView(dialog));
+    QWebEnginePage *page = m_view->page();
+
+    connect(page, &QWebEnginePage::windowCloseRequested, this, &Webcam::windowClose);
+
+    page->load(QUrl(url));
+    dialog->resize(800, 600);
+    m_view->resize(780, 592);
+
+    dialog->setModal(true);
+    dialog->exec();
+}
+
+
+Webcam::~Webcam()
+{
+    qDebug() << "Webcam destroyed";
+}
+
+
+void Webcam::windowClose()
+{
+    dialog->close();
+}
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/Webcam.h	Tue Aug 09 12:45:49 2022 +0200
@@ -0,0 +1,28 @@
+#ifndef _WEBCAM_H
+#define _WEBCAM_H
+
+#include "MainWindow.h"
+
+#include <QDialog>
+#include <QDialogButtonBox>
+#include <QWebEngineView>
+
+
+namespace Ui {
+class Webcam;
+}
+
+class Webcam : public QDialog
+{
+    Q_OBJECT
+
+public:
+    explicit Webcam(QString url, QWidget *parent = 0);
+    ~Webcam();
+
+private:
+    QDialog* dialog;
+    void windowClose();
+};
+
+#endif

mercurial