diff --git a/configurationwidget.cpp b/configurationwidget.cpp index 745dab30e53a60d570153398b2c5dd0ed87646e7..4a9e1e6529bf156c25ce68a49a38d56fdfb1283d 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 6a804f38ed560c5129972137b91af3d84ab76c66..5ea809157c5b9fce3c148053f88d18fc4cd39d6d 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 9330f97af88355585eb1b35298fa5f3f8e72cc29..ac16f10d2bf6718e4ba335a57994a5a0b45718a1 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 8c98b5577499a717d963568e53593f537ed4b032..748b015b16377ee1060b12ecc37ac6419507b457 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>