blob: ded23f4eb903f905f6aa38638dd7e0d4a567bf8a [file] [log] [blame]
Olivier SOLDANO3dad1752017-07-13 14:08:53 -04001/***************************************************************************
2 * Copyright (C) 2015-2017 by Savoir-faire Linux *
3 * Author: Olivier Soldano <olivier.soldano@savoirfairelinux.com> *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 3 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
17 **************************************************************************/
18
19#include "photoboothwidget.h"
20#include "ui_photoboothwidget.h"
21
22#include <QFileDialog>
23#include <QStandardPaths>
24
25#include "video/previewmanager.h"
26
27PhotoboothWidget::PhotoboothWidget(QWidget *parent) :
28 QWidget(parent),
29 fileName_(QStandardPaths::standardLocations(QStandardPaths::TempLocation).first()
30 + QStringLiteral("profile.png")),
31 ui(new Ui::PhotoboothWidget)
32{
33 ui->setupUi(this);
34 ui->videoFeed->setIsFullPreview(true);
35 ui->videoFeed->setPhotoMode(true);
Olivier SOLDANO3dad1752017-07-13 14:08:53 -040036}
37
38PhotoboothWidget::~PhotoboothWidget()
39{
40 Video::PreviewManager::instance().stopPreview();
41 delete ui;
42}
43
44void PhotoboothWidget::startBooth()
45{
Olivier SOLDANO3dad1752017-07-13 14:08:53 -040046 Video::PreviewManager::instance().stopPreview();
Olivier SOLDANO3dad1752017-07-13 14:08:53 -040047 Video::PreviewManager::instance().startPreview();
48 ui->videoFeed->show();
49}
50
51void PhotoboothWidget::stopBooth()
52{
53 Video::PreviewManager::instance().stopPreview();
54 hide();
55}
56
57void
58PhotoboothWidget::on_importButton_clicked()
59{
60 fileName_ = QFileDialog::getOpenFileName(this, tr("Choose File"),
61 "",
62 tr("Files (*)"));
63 if (fileName_.isEmpty())
64 fileName_ = QStandardPaths::standardLocations(
65 QStandardPaths::TempLocation).first()
66 + QStringLiteral("profile.png");
67 else {
68 Video::PreviewManager::instance().stopPreview();
69 }
70 emit photoTaken(fileName_);
71}
72
73void
74PhotoboothWidget::on_takePhotoButton_clicked()
75{
76 auto photo = ui->videoFeed->takePhoto();
77 Video::PreviewManager::instance().stopPreview();
78 photo.save(fileName_);
79 emit photoTaken(fileName_);
80}