blob: 537f544399ce96425c527ecdded15d1cdf5b0222 [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);
36 startBooth();
37}
38
39PhotoboothWidget::~PhotoboothWidget()
40{
41 Video::PreviewManager::instance().stopPreview();
42 delete ui;
43}
44
45void PhotoboothWidget::startBooth()
46{
47 // // // //
48 // stop (or start before) to give Preview manager some time to start
49 // TODO go modify the daemon to ensure starting upon calling videomanager::startCamera
50 Video::PreviewManager::instance().stopPreview();
51 // // // //
52
53 Video::PreviewManager::instance().startPreview();
54 ui->videoFeed->show();
55}
56
57void PhotoboothWidget::stopBooth()
58{
59 Video::PreviewManager::instance().stopPreview();
60 hide();
61}
62
63void
64PhotoboothWidget::on_importButton_clicked()
65{
66 fileName_ = QFileDialog::getOpenFileName(this, tr("Choose File"),
67 "",
68 tr("Files (*)"));
69 if (fileName_.isEmpty())
70 fileName_ = QStandardPaths::standardLocations(
71 QStandardPaths::TempLocation).first()
72 + QStringLiteral("profile.png");
73 else {
74 Video::PreviewManager::instance().stopPreview();
75 }
76 emit photoTaken(fileName_);
77}
78
79void
80PhotoboothWidget::on_takePhotoButton_clicked()
81{
82 auto photo = ui->videoFeed->takePhoto();
83 Video::PreviewManager::instance().stopPreview();
84 photo.save(fileName_);
85 emit photoTaken(fileName_);
86}