Commit 6c323c6e authored by Andreas Traczyk's avatar Andreas Traczyk

wizard: fix photobooth

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