From 30ac2c75709a5f81bb5d69a9c395c45476117cb3 Mon Sep 17 00:00:00 2001
From: Olivier SOLDANO <olivier.soldano@savoirfairelinux.com>
Date: Fri, 4 Aug 2017 09:14:47 -0400
Subject: [PATCH] replace photoboothdialog code
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

photoboothwidget was created to integrate the dialog inside
the account creation wizard.
the widget is now reused as the core of the photobooth dialog
used in the profile configuration.

Change-Id: I794d7964195bc468452f2f1e63fe1b157baaab97
Reviewed-by: Anthony Léonard <anthony.leonard@savoirfairelinux.com>
---
 configurationwidget.cpp |  2 +-
 photoboothdialog.cpp    | 48 ++++---------------------
 photoboothdialog.h      | 12 ++-----
 photoboothdialog.ui     | 79 +++++++++--------------------------------
 4 files changed, 26 insertions(+), 115 deletions(-)

diff --git a/configurationwidget.cpp b/configurationwidget.cpp
index 745dab3..4a9e1e6 100644
--- a/configurationwidget.cpp
+++ b/configurationwidget.cpp
@@ -432,7 +432,7 @@ ConfigurationWidget::on_avatarButton_clicked()
     PhotoBoothDialog dlg;
     dlg.exec();
     if (dlg.result() == QDialog::Accepted) {
-        auto image = QImage(dlg.fileName_);
+        auto image = QImage(dlg.getOutputFileName());
         auto avatar = image.scaled(100, 100, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);
         ProfileModel::instance().selectedProfile()->person()->setPhoto(avatar);
         ProfileModel::instance().selectedProfile()->save();
diff --git a/photoboothdialog.cpp b/photoboothdialog.cpp
index 6a804f3..5ea8091 100644
--- a/photoboothdialog.cpp
+++ b/photoboothdialog.cpp
@@ -26,54 +26,18 @@
 
 PhotoBoothDialog::PhotoBoothDialog(QWidget* parent) :
     QDialog(parent),
-    fileName_(QStandardPaths::standardLocations(QStandardPaths::TempLocation).first()
-              + QStringLiteral("profile.png")),
     ui(new Ui::PhotoBoothDialog)
 {
     ui->setupUi(this);
-
-    Qt::WindowFlags flags = windowFlags();
-    flags = flags & (~Qt::WindowContextHelpButtonHint);
-    setWindowFlags(flags);
-
-    ui->videoFeed->setIsFullPreview(true);
-    ui->videoFeed->setPhotoMode(true);
-    Video::PreviewManager::instance().startPreview();
+    setWindowFlags(windowFlags() & (~Qt::WindowContextHelpButtonHint));
+    connect(ui->Photobooth, &PhotoboothWidget::photoTaken, [this](QString fileName){
+        fileName_ = fileName;
+        accept();
+        }
+    );
 }
 
 PhotoBoothDialog::~PhotoBoothDialog()
 {
     delete ui;
 }
-
-void
-PhotoBoothDialog::closeEvent(QCloseEvent* event)
-{
-    Q_UNUSED(event)
-    Video::PreviewManager::instance().stopPreview();
-}
-
-void
-PhotoBoothDialog::on_importButton_clicked()
-{
-    fileName_ = QFileDialog::getOpenFileName(this, tr("Choose File"),
-                                            "",
-                                            tr("Files (*)"));
-    if (fileName_.isEmpty())
-        fileName_ = QStandardPaths::standardLocations(
-                    QStandardPaths::TempLocation).first()
-                + QStringLiteral("profile.png");
-    else {
-        Video::PreviewManager::instance().stopPreview();
-        accept();
-    }
-}
-
-void
-PhotoBoothDialog::on_takePhotoButton_clicked()
-{
-    auto photo = ui->videoFeed->takePhoto();
-    Video::PreviewManager::instance().stopPreview();
-    photo.save(fileName_);
-    accept();
-}
diff --git a/photoboothdialog.h b/photoboothdialog.h
index 9330f97..ac16f10 100644
--- a/photoboothdialog.h
+++ b/photoboothdialog.h
@@ -31,17 +31,9 @@ class PhotoBoothDialog : public QDialog
 public:
     explicit PhotoBoothDialog(QWidget* parent = 0);
     ~PhotoBoothDialog();
-public:
-    QString fileName_;
-
-protected:
-    void closeEvent(QCloseEvent* event);
-
-//UI SLOTS
-private slots:
-    void on_importButton_clicked();
-    void on_takePhotoButton_clicked();
+    QString& getOutputFileName() { return fileName_;}
 
 private:
     Ui::PhotoBoothDialog* ui;
+    QString fileName_;
 };
diff --git a/photoboothdialog.ui b/photoboothdialog.ui
index 8c98b55..748b015 100644
--- a/photoboothdialog.ui
+++ b/photoboothdialog.ui
@@ -13,77 +13,32 @@
   <property name="windowTitle">
    <string>Photobooth</string>
   </property>
-  <layout class="QVBoxLayout" name="verticalLayout" stretch="1,0,0,0">
+  <layout class="QVBoxLayout" name="verticalLayout" stretch="0">
+   <property name="leftMargin">
+    <number>0</number>
+   </property>
+   <property name="topMargin">
+    <number>0</number>
+   </property>
+   <property name="rightMargin">
+    <number>0</number>
+   </property>
+   <property name="bottomMargin">
+    <number>0</number>
+   </property>
    <item>
-    <widget class="VideoWidget" name="videoFeed" native="true"/>
-   </item>
-   <item alignment="Qt::AlignHCenter">
-    <widget class="QPushButton" name="takePhotoButton">
-     <property name="sizePolicy">
-      <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
-       <horstretch>0</horstretch>
-       <verstretch>0</verstretch>
-      </sizepolicy>
-     </property>
-     <property name="minimumSize">
-      <size>
-       <width>40</width>
-       <height>40</height>
-      </size>
-     </property>
-     <property name="text">
-      <string/>
-     </property>
-     <property name="icon">
-      <iconset resource="ressources.qrc">
-       <normaloff>:/images/icons/ic_photo_camera_white_24dp_2x.png</normaloff>:/images/icons/ic_photo_camera_white_24dp_2x.png</iconset>
-     </property>
-     <property name="iconSize">
-      <size>
-       <width>36</width>
-       <height>36</height>
-      </size>
-     </property>
-    </widget>
-   </item>
-   <item alignment="Qt::AlignHCenter|Qt::AlignVCenter">
-    <widget class="QLabel" name="label">
-     <property name="sizePolicy">
-      <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
-       <horstretch>0</horstretch>
-       <verstretch>0</verstretch>
-      </sizepolicy>
-     </property>
-     <property name="text">
-      <string>or</string>
-     </property>
-    </widget>
-   </item>
-   <item alignment="Qt::AlignHCenter">
-    <widget class="QPushButton" name="importButton">
-     <property name="minimumSize">
-      <size>
-       <width>90</width>
-       <height>30</height>
-      </size>
-     </property>
-     <property name="text">
-      <string>Import</string>
-     </property>
-    </widget>
+    <widget class="PhotoboothWidget" name="Photobooth" native="true"/>
    </item>
   </layout>
  </widget>
  <customwidgets>
   <customwidget>
-   <class>VideoWidget</class>
+   <class>PhotoboothWidget</class>
    <extends>QWidget</extends>
-   <header>videowidget.h</header>
+   <header>photoboothwidget.h</header>
    <container>1</container>
   </customwidget>
  </customwidgets>
- <resources>
-  <include location="ressources.qrc"/>
- </resources>
+ <resources/>
  <connections/>
 </ui>
-- 
GitLab