Skip to content
Snippets Groups Projects
Commit 6c323c6e authored by Andreas Traczyk's avatar Andreas Traczyk
Browse files

wizard: fix photobooth

- use new lrc profile editing
- add camera/file reset
 
Change-Id: I6b877a1b9ef8639c9ab3294ecf735e4366e98006
parent 0f996355
No related branches found
No related tags found
No related merge requests found
...@@ -136,6 +136,14 @@ public: ...@@ -136,6 +136,14 @@ public:
.index(getCurrentAccountIndex()), AccountListModel::Role::Picture).value<QPixmap>(); .index(getCurrentAccountIndex()), AccountListModel::Role::Picture).value<QPixmap>();
}; };
static void setCurrAccAvatar(const QPixmap& avatarPixmap) {
QByteArray ba;
QBuffer bu(&ba);
bu.open(QIODevice::WriteOnly);
avatarPixmap.save(&bu, "PNG");
instance().editableAccountModel()->setAvatar(getCurrAccId(), ba.toBase64().toStdString());
};
static void setCurrAccAvatar(const std::string& avatar) { static void setCurrAccAvatar(const std::string& avatar) {
instance().editableAccountModel()->setAvatar(getCurrAccId(), avatar); instance().editableAccountModel()->setAvatar(getCurrAccId(), avatar);
}; };
......
...@@ -27,10 +27,6 @@ ...@@ -27,10 +27,6 @@
#include <QFileDialog> #include <QFileDialog>
#include <QBitmap> #include <QBitmap>
#include "accountmodel.h"
#include "account.h"
#include "profilemodel.h"
#include "profile.h"
#include "namedirectory.h" #include "namedirectory.h"
#include "utils.h" #include "utils.h"
...@@ -52,8 +48,6 @@ NewWizardWidget::NewWizardWidget(WizardMode wizardMode, AccountInfo* toBeMigrate ...@@ -52,8 +48,6 @@ NewWizardWidget::NewWizardWidget(WizardMode wizardMode, AccountInfo* toBeMigrate
ui->welcomeLogo->setPixmap(logo.scaledToHeight(100, Qt::SmoothTransformation)); ui->welcomeLogo->setPixmap(logo.scaledToHeight(100, Qt::SmoothTransformation));
ui->welcomeLogo->setAlignment(Qt::AlignHCenter); ui->welcomeLogo->setAlignment(Qt::AlignHCenter);
ui->fullNameEdit->setText(Utils::GetCurrentUserName());
creationSpinnerMovie_ = new QMovie(":/images/jami_eclipse_spinner.gif"); creationSpinnerMovie_ = new QMovie(":/images/jami_eclipse_spinner.gif");
ui->spinnerLabel->setMovie(creationSpinnerMovie_); ui->spinnerLabel->setMovie(creationSpinnerMovie_);
creationSpinnerMovie_->start(); creationSpinnerMovie_->start();
...@@ -100,14 +94,6 @@ NewWizardWidget::NewWizardWidget(WizardMode wizardMode, AccountInfo* toBeMigrate ...@@ -100,14 +94,6 @@ NewWizardWidget::NewWizardWidget(WizardMode wizardMode, AccountInfo* toBeMigrate
validateWizardProgression(); validateWizardProgression();
}); });
connect(ui->setAvatarWidget, &PhotoboothWidget::photoTaken,
this, &NewWizardWidget::on_photoTaken);
connect(ui->setAvatarWidget, &PhotoboothWidget::photoReady,
[this] {
ui->setAvatarWidget->startBooth();
});
ui->containerWidget->setVisible(false); ui->containerWidget->setVisible(false);
} }
...@@ -175,12 +161,6 @@ NewWizardWidget::processWizardInformations() ...@@ -175,12 +161,6 @@ NewWizardWidget::processWizardInformations()
Utils::CreateStartupLink(); Utils::CreateStartupLink();
} }
void
NewWizardWidget::on_photoTaken(QString fileName)
{
ui->setAvatarWidget->stopBooth();
}
void void
NewWizardWidget::on_existingPushButton_clicked() NewWizardWidget::on_existingPushButton_clicked()
{ {
...@@ -210,6 +190,7 @@ void NewWizardWidget::changePage(QWidget* toPage) ...@@ -210,6 +190,7 @@ void NewWizardWidget::changePage(QWidget* toPage)
ui->confirmPasswordEdit->clear(); ui->confirmPasswordEdit->clear();
ui->signUpCheckbox->setChecked(true); ui->signUpCheckbox->setChecked(true);
ui->usernameEdit->setEnabled(true); ui->usernameEdit->setEnabled(true);
ui->fullNameEdit->setText(Utils::GetCurrentUserName());
setNavBarVisibility(true); setNavBarVisibility(true);
updateCustomUI(); updateCustomUI();
registeredNameFoundConnection_ = connect( registeredNameFoundConnection_ = connect(
......
...@@ -21,9 +21,6 @@ ...@@ -21,9 +21,6 @@
#include <QLabel> #include <QLabel>
#include <QtConcurrent/QtConcurrent> #include <QtConcurrent/QtConcurrent>
#include "account.h"
#include "person.h"
#include "lrcinstance.h" #include "lrcinstance.h"
#include "navwidget.h" #include "navwidget.h"
...@@ -72,7 +69,6 @@ private slots: ...@@ -72,7 +69,6 @@ private slots:
const std::string& name); const std::string& name);
void handle_nameRegistrationEnded(NameDirectory::RegisterNameStatus status, const QString& name); void handle_nameRegistrationEnded(NameDirectory::RegisterNameStatus status, const QString& name);
void timeoutNameLookupTimer(); void timeoutNameLookupTimer();
void on_photoTaken(QString fileName);
void on_signUpCheckbox_toggled(bool checked); void on_signUpCheckbox_toggled(bool checked);
private: private:
......
...@@ -21,25 +21,39 @@ ...@@ -21,25 +21,39 @@
#include <QFileDialog> #include <QFileDialog>
#include <QStandardPaths> #include <QStandardPaths>
#include <QGraphicsOpacityEffect>
#include <QtConcurrent/QtConcurrent>
#include "video/previewmanager.h" #include "video/previewmanager.h"
#include "profilemodel.h"
#include "profile.h"
#include "account.h"
#include "person.h"
#include "utils.h" #include "utils.h"
#include "lrcinstance.h"
PhotoboothWidget::PhotoboothWidget(QWidget *parent) : PhotoboothWidget::PhotoboothWidget(QWidget *parent) :
QWidget(parent), QWidget(parent),
fileName_(QStandardPaths::standardLocations(QStandardPaths::TempLocation).first() fileName_(""),
+ QStringLiteral("profile.png")),
ui(new Ui::PhotoboothWidget) ui(new Ui::PhotoboothWidget)
{ {
ui->setupUi(this); ui->setupUi(this);
ui->videoFeed->setIsFullPreview(true); ui->videoFeed->setIsFullPreview(true);
ui->videoFeed->setPhotoMode(true); ui->videoFeed->setPhotoMode(true);
flashOverlay_ = new QLabel(this);
flashOverlay_->setStyleSheet("background-color:#fff");
flashOverlay_->hide();
QGraphicsOpacityEffect *effect = new QGraphicsOpacityEffect(this);
flashOverlay_->setGraphicsEffect(effect);
flashAnimation_ = new QPropertyAnimation(this);
flashAnimation_->setTargetObject(effect);
flashAnimation_->setPropertyName("opacity");
flashAnimation_->setDuration(600);
flashAnimation_->setStartValue(1);
flashAnimation_->setEndValue(0);
flashAnimation_->setEasingCurve(QEasingCurve::OutCubic);
takePhotoState_ = true;
ui->takePhotoButton->setIcon(QPixmap(":/images/icons/baseline-camera_alt-24px.svg"));
} }
PhotoboothWidget::~PhotoboothWidget() PhotoboothWidget::~PhotoboothWidget()
...@@ -50,11 +64,13 @@ PhotoboothWidget::~PhotoboothWidget() ...@@ -50,11 +64,13 @@ PhotoboothWidget::~PhotoboothWidget()
void PhotoboothWidget::startBooth() void PhotoboothWidget::startBooth()
{ {
ui->videoFeed->setResetPreview(true);
Video::PreviewManager::instance().stopPreview(); Video::PreviewManager::instance().stopPreview();
Video::PreviewManager::instance().startPreview(); Video::PreviewManager::instance().startPreview();
ui->videoFeed->show(); ui->videoFeed->show();
ui->avatarLabel->hide(); ui->avatarLabel->hide();
takePhotoState_ = true; takePhotoState_ = true;
ui->takePhotoButton->setIcon(QPixmap(":/images/icons/baseline-camera_alt-24px.svg"));
} }
void PhotoboothWidget::stopBooth() void PhotoboothWidget::stopBooth()
...@@ -63,43 +79,57 @@ void PhotoboothWidget::stopBooth() ...@@ -63,43 +79,57 @@ void PhotoboothWidget::stopBooth()
ui->videoFeed->hide(); ui->videoFeed->hide();
ui->avatarLabel->show(); ui->avatarLabel->show();
takePhotoState_ = false; takePhotoState_ = false;
ui->takePhotoButton->setIcon(QPixmap(":/images/icons/baseline-refresh-24px.svg"));
} }
void void
PhotoboothWidget::on_importButton_clicked() PhotoboothWidget::on_importButton_clicked()
{ {
Video::PreviewManager::instance().stopPreview();
auto picturesDir = QStandardPaths::standardLocations(QStandardPaths::PicturesLocation).first();
fileName_ = QFileDialog::getOpenFileName(this, tr("Choose File"), fileName_ = QFileDialog::getOpenFileName(this, tr("Choose File"),
"", picturesDir,
tr("Files (*)")); tr("Image Files (*.jpg, *.jpeg, *png)"));
if (fileName_.isEmpty()) { if (fileName_.isEmpty()) {
fileName_ = QStandardPaths::standardLocations( Video::PreviewManager::instance().startPreview();
QStandardPaths::TempLocation).first() return;
+ QStringLiteral("profile.png");
} else {
Video::PreviewManager::instance().stopPreview();
} }
Video::PreviewManager::instance().stopPreview();
auto image = QImage(fileName_); auto image = QImage(fileName_);
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); auto avatarPixmap = QPixmap::fromImage(Utils::getCirclePhoto(avatar, ui->avatarLabel->width()));
ui->avatarLabel->setPixmap(QPixmap::fromImage(Utils::getCirclePhoto(avatar, ui->avatarLabel->width()))); LRCInstance::setCurrAccAvatar(avatarPixmap);
emit photoTaken(fileName_); ui->avatarLabel->setPixmap(avatarPixmap);
stopBooth();
} }
void void
PhotoboothWidget::on_takePhotoButton_clicked() PhotoboothWidget::on_takePhotoButton_clicked()
{ {
if (!takePhotoState_) { if (!takePhotoState_) {
takePhotoState_ = true; startBooth();
ui->takePhotoButton->setIcon(QPixmap(":/images/icons/baseline-camera_alt-24px.svg")); return;
emit photoReady();
} else { } else {
auto photo = ui->videoFeed->takePhoto(); auto videoRect = ui->videoFeed->rect();
QPoint avatarLabelPos = ui->videoFeed->mapTo(this, videoRect.topLeft());
flashOverlay_->setGeometry(
avatarLabelPos.x(),
avatarLabelPos.y(),
videoRect.width(),
videoRect.height()
);
flashOverlay_->show();
flashAnimation_->start(QPropertyAnimation::KeepWhenStopped);
QtConcurrent::run(
[=] {
Video::PreviewManager::instance().stopPreview(); Video::PreviewManager::instance().stopPreview();
photo.save(fileName_); auto photo = ui->videoFeed->takePhoto();
auto avatar = photo.scaled(100, 100, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation); auto avatar = photo.scaled(100, 100, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);
ProfileModel::instance().selectedProfile()->person()->setPhoto(avatar); auto avatarPixmap = QPixmap::fromImage(Utils::getCirclePhoto(avatar, ui->avatarLabel->width()));
ui->avatarLabel->setPixmap(QPixmap::fromImage(Utils::getCirclePhoto(avatar, ui->avatarLabel->width()))); LRCInstance::setCurrAccAvatar(avatarPixmap);
ui->takePhotoButton->setIcon(QPixmap(":/images/icons/baseline-refresh-24px.svg")); ui->avatarLabel->setPixmap(avatarPixmap);
emit photoTaken(fileName_); stopBooth();
});
} }
} }
...@@ -20,6 +20,8 @@ ...@@ -20,6 +20,8 @@
#define PHOTOBOOTHWIDGET_H #define PHOTOBOOTHWIDGET_H
#include <QWidget> #include <QWidget>
#include <QLabel>
#include <QPropertyAnimation>
namespace Ui { namespace Ui {
class PhotoboothWidget; class PhotoboothWidget;
...@@ -43,11 +45,14 @@ private: ...@@ -43,11 +45,14 @@ private:
QString fileName_; QString fileName_;
Ui::PhotoboothWidget *ui; Ui::PhotoboothWidget *ui;
QLabel* flashOverlay_;
QPropertyAnimation *flashAnimation_;
bool takePhotoState_; bool takePhotoState_;
signals: signals:
void photoTaken(QString fileName); void photoTaken(QString fileName);
void photoReady();
}; };
#endif // PHOTOBOOTHWIDGET_H #endif // PHOTOBOOTHWIDGET_H
...@@ -105,8 +105,8 @@ VideoWidget::paintEvent(QPaintEvent* evt) { ...@@ -105,8 +105,8 @@ VideoWidget::paintEvent(QPaintEvent* evt) {
painter.drawImage(QRect(xDiff,yDiff,scaledDistant.width(),scaledDistant.height()), scaledDistant); painter.drawImage(QRect(xDiff,yDiff,scaledDistant.width(),scaledDistant.height()), scaledDistant);
} }
} }
if (previewRenderer_ && isPreviewDisplayed_) { if ((previewRenderer_ && isPreviewDisplayed_) || (photoMode_ && hasFrame_)) {
{ if (previewRenderer_) {
QMutexLocker lock(&mutex_); QMutexLocker lock(&mutex_);
if (currentPreviewFrame_.storage.size() != 0 if (currentPreviewFrame_.storage.size() != 0
&& currentPreviewFrame_.storage.size() == && currentPreviewFrame_.storage.size() ==
...@@ -116,6 +116,7 @@ VideoWidget::paintEvent(QPaintEvent* evt) { ...@@ -116,6 +116,7 @@ VideoWidget::paintEvent(QPaintEvent* evt) {
previewRenderer_->size().width(), previewRenderer_->size().width(),
previewRenderer_->size().height(), previewRenderer_->size().height(),
QImage::Format_ARGB32_Premultiplied)); QImage::Format_ARGB32_Premultiplied));
hasFrame_ = true;
} }
} }
...@@ -149,10 +150,23 @@ VideoWidget::paintEvent(QPaintEvent* evt) { ...@@ -149,10 +150,23 @@ VideoWidget::paintEvent(QPaintEvent* evt) {
painter.drawImage(previewGeometry_, scaledPreview); painter.drawImage(previewGeometry_, scaledPreview);
} }
} else if (photoMode_) {
paintBackgroundColor(&painter, Qt::black);
} }
painter.end(); painter.end();
} }
void
VideoWidget::paintBackgroundColor(QPainter* painter, QColor color)
{
QImage black(1, 1, QImage::Format_ARGB32);
black.fill(color);
QImage scaledPreview = Utils::getCirclePhoto(black, height());
previewGeometry_.setWidth(scaledPreview.width());
previewGeometry_.setHeight(scaledPreview.height());
painter->drawImage(previewGeometry_, scaledPreview);
}
void void
VideoWidget::setDistantRenderer(Video::Renderer* renderer) { VideoWidget::setDistantRenderer(Video::Renderer* renderer) {
if (not renderer) if (not renderer)
......
...@@ -37,7 +37,7 @@ public: ...@@ -37,7 +37,7 @@ public:
void setPreviewDisplay(bool display); void setPreviewDisplay(bool display);
void setDistantRenderer(Video::Renderer* renderer); void setDistantRenderer(Video::Renderer* renderer);
void setIsFullPreview(bool full); void setIsFullPreview(bool full);
inline void setResetPreview(bool reset){ resetPreview_ = reset; } inline void setResetPreview(bool reset) { resetPreview_ = reset; hasFrame_=false; }
void setPhotoMode(bool isPhotoMode); void setPhotoMode(bool isPhotoMode);
QImage takePhoto(); QImage takePhoto();
...@@ -64,7 +64,11 @@ private: ...@@ -64,7 +64,11 @@ private:
QRect previewGeometry_; QRect previewGeometry_;
bool resetPreview_ = false; bool resetPreview_ = false;
bool photoMode_ = false; bool photoMode_ = false;
bool hasFrame_ = false;
constexpr static int previewMargin_ = 15; constexpr static int previewMargin_ = 15;
private:
void paintBackgroundColor(QPainter* painter, QColor color);
}; };
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment