blob: 826144f6d1d5cd2b9982c2b29ef6e35f90c609d7 [file] [log] [blame]
Edric Milaret25236d92016-03-28 09:40:58 -04001/***************************************************************************
2 * Copyright (C) 2016 by Savoir-faire Linux *
3 * Author: Edric Ladent Milaret <edric.ladent-milaret@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 "photoboothdialog.h"
20#include "ui_photoboothdialog.h"
21
22#include <QFileDialog>
Edric Milaret28a86b72016-05-06 12:13:25 -040023#include <QStandardPaths>
Edric Milaret25236d92016-03-28 09:40:58 -040024
25#include "video/previewmanager.h"
26
27PhotoBoothDialog::PhotoBoothDialog(QWidget* parent) :
28 QDialog(parent),
Edric Milaret28a86b72016-05-06 12:13:25 -040029 fileName_(QStandardPaths::standardLocations(QStandardPaths::TempLocation).first()
30 + QStringLiteral("profile.png")),
Edric Milaret25236d92016-03-28 09:40:58 -040031 ui(new Ui::PhotoBoothDialog)
32{
33 ui->setupUi(this);
34
35 Qt::WindowFlags flags = windowFlags();
36 flags = flags & (~Qt::WindowContextHelpButtonHint);
37 setWindowFlags(flags);
38
39 ui->videoFeed->setIsFullPreview(true);
40 ui->videoFeed->setPhotoMode(true);
41 Video::PreviewManager::instance().startPreview();
42}
43
44PhotoBoothDialog::~PhotoBoothDialog()
45{
46 delete ui;
47}
48
49void
50PhotoBoothDialog::closeEvent(QCloseEvent* event)
51{
52 Q_UNUSED(event)
53 Video::PreviewManager::instance().stopPreview();
54}
55
56void
57PhotoBoothDialog::on_importButton_clicked()
58{
59 fileName_ = QFileDialog::getOpenFileName(this, tr("Choose File"),
60 "",
61 tr("Files (*)"));
62 if (fileName_.isEmpty())
Edric Milaret28a86b72016-05-06 12:13:25 -040063 fileName_ = QStandardPaths::standardLocations(
64 QStandardPaths::TempLocation).first()
65 + QStringLiteral("profile.png");
Edric Milaret25236d92016-03-28 09:40:58 -040066 else {
67 Video::PreviewManager::instance().stopPreview();
68 accept();
69 }
70}
71
72void
73PhotoBoothDialog::on_takePhotoButton_clicked()
74{
75 auto photo = ui->videoFeed->takePhoto();
76 Video::PreviewManager::instance().stopPreview();
77 photo.save(fileName_);
78 accept();
79}