Commit 30ac2c75 authored by Olivier SOLDANO's avatar Olivier SOLDANO Committed by Anthony Léonard

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
......@@ -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();
......
......@@ -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();
}
......@@ -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_;
};
......@@ -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>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment