Skip to content
Snippets Groups Projects
Commit 30ac2c75 authored by Olivier SOLDANO's avatar Olivier SOLDANO Committed by Anthony Léonard
Browse files

replace photoboothdialog code


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: default avatarAnthony Léonard <anthony.leonard@savoirfairelinux.com>
parent 2742f555
No related branches found
No related tags found
No related merge requests found
...@@ -432,7 +432,7 @@ ConfigurationWidget::on_avatarButton_clicked() ...@@ -432,7 +432,7 @@ ConfigurationWidget::on_avatarButton_clicked()
PhotoBoothDialog dlg; PhotoBoothDialog dlg;
dlg.exec(); dlg.exec();
if (dlg.result() == QDialog::Accepted) { 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); auto avatar = image.scaled(100, 100, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);
ProfileModel::instance().selectedProfile()->person()->setPhoto(avatar); ProfileModel::instance().selectedProfile()->person()->setPhoto(avatar);
ProfileModel::instance().selectedProfile()->save(); ProfileModel::instance().selectedProfile()->save();
......
...@@ -26,54 +26,18 @@ ...@@ -26,54 +26,18 @@
PhotoBoothDialog::PhotoBoothDialog(QWidget* parent) : PhotoBoothDialog::PhotoBoothDialog(QWidget* parent) :
QDialog(parent), QDialog(parent),
fileName_(QStandardPaths::standardLocations(QStandardPaths::TempLocation).first()
+ QStringLiteral("profile.png")),
ui(new Ui::PhotoBoothDialog) ui(new Ui::PhotoBoothDialog)
{ {
ui->setupUi(this); ui->setupUi(this);
setWindowFlags(windowFlags() & (~Qt::WindowContextHelpButtonHint));
Qt::WindowFlags flags = windowFlags(); connect(ui->Photobooth, &PhotoboothWidget::photoTaken, [this](QString fileName){
flags = flags & (~Qt::WindowContextHelpButtonHint); fileName_ = fileName;
setWindowFlags(flags);
ui->videoFeed->setIsFullPreview(true);
ui->videoFeed->setPhotoMode(true);
Video::PreviewManager::instance().startPreview();
}
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(); accept();
} }
);
} }
void PhotoBoothDialog::~PhotoBoothDialog()
PhotoBoothDialog::on_takePhotoButton_clicked()
{ {
auto photo = ui->videoFeed->takePhoto(); delete ui;
Video::PreviewManager::instance().stopPreview();
photo.save(fileName_);
accept();
} }
...@@ -31,17 +31,9 @@ class PhotoBoothDialog : public QDialog ...@@ -31,17 +31,9 @@ class PhotoBoothDialog : public QDialog
public: public:
explicit PhotoBoothDialog(QWidget* parent = 0); explicit PhotoBoothDialog(QWidget* parent = 0);
~PhotoBoothDialog(); ~PhotoBoothDialog();
public: QString& getOutputFileName() { return fileName_;}
QString fileName_;
protected:
void closeEvent(QCloseEvent* event);
//UI SLOTS
private slots:
void on_importButton_clicked();
void on_takePhotoButton_clicked();
private: private:
Ui::PhotoBoothDialog* ui; Ui::PhotoBoothDialog* ui;
QString fileName_;
}; };
...@@ -13,77 +13,32 @@ ...@@ -13,77 +13,32 @@
<property name="windowTitle"> <property name="windowTitle">
<string>Photobooth</string> <string>Photobooth</string>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout" stretch="1,0,0,0"> <layout class="QVBoxLayout" name="verticalLayout" stretch="0">
<item> <property name="leftMargin">
<widget class="VideoWidget" name="videoFeed" native="true"/> <number>0</number>
</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>
<property name="icon"> <property name="topMargin">
<iconset resource="ressources.qrc"> <number>0</number>
<normaloff>:/images/icons/ic_photo_camera_white_24dp_2x.png</normaloff>:/images/icons/ic_photo_camera_white_24dp_2x.png</iconset>
</property> </property>
<property name="iconSize"> <property name="rightMargin">
<size> <number>0</number>
<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>
<property name="text"> <property name="bottomMargin">
<string>or</string> <number>0</number>
</property> </property>
</widget> <item>
</item> <widget class="PhotoboothWidget" name="Photobooth" native="true"/>
<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>
</item> </item>
</layout> </layout>
</widget> </widget>
<customwidgets> <customwidgets>
<customwidget> <customwidget>
<class>VideoWidget</class> <class>PhotoboothWidget</class>
<extends>QWidget</extends> <extends>QWidget</extends>
<header>videowidget.h</header> <header>photoboothwidget.h</header>
<container>1</container> <container>1</container>
</customwidget> </customwidget>
</customwidgets> </customwidgets>
<resources> <resources/>
<include location="ressources.qrc"/>
</resources>
<connections/> <connections/>
</ui> </ui>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment