Edric Milaret | 25236d9 | 2016-03-28 09:40:58 -0400 | [diff] [blame] | 1 | /*************************************************************************** |
| 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 Milaret | 28a86b7 | 2016-05-06 12:13:25 -0400 | [diff] [blame] | 23 | #include <QStandardPaths> |
Edric Milaret | 25236d9 | 2016-03-28 09:40:58 -0400 | [diff] [blame] | 24 | |
| 25 | #include "video/previewmanager.h" |
| 26 | |
| 27 | PhotoBoothDialog::PhotoBoothDialog(QWidget* parent) : |
| 28 | QDialog(parent), |
Edric Milaret | 28a86b7 | 2016-05-06 12:13:25 -0400 | [diff] [blame] | 29 | fileName_(QStandardPaths::standardLocations(QStandardPaths::TempLocation).first() |
| 30 | + QStringLiteral("profile.png")), |
Edric Milaret | 25236d9 | 2016-03-28 09:40:58 -0400 | [diff] [blame] | 31 | 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 | |
| 44 | PhotoBoothDialog::~PhotoBoothDialog() |
| 45 | { |
| 46 | delete ui; |
| 47 | } |
| 48 | |
| 49 | void |
| 50 | PhotoBoothDialog::closeEvent(QCloseEvent* event) |
| 51 | { |
| 52 | Q_UNUSED(event) |
| 53 | Video::PreviewManager::instance().stopPreview(); |
| 54 | } |
| 55 | |
| 56 | void |
| 57 | PhotoBoothDialog::on_importButton_clicked() |
| 58 | { |
| 59 | fileName_ = QFileDialog::getOpenFileName(this, tr("Choose File"), |
| 60 | "", |
| 61 | tr("Files (*)")); |
| 62 | if (fileName_.isEmpty()) |
Edric Milaret | 28a86b7 | 2016-05-06 12:13:25 -0400 | [diff] [blame] | 63 | fileName_ = QStandardPaths::standardLocations( |
| 64 | QStandardPaths::TempLocation).first() |
| 65 | + QStringLiteral("profile.png"); |
Edric Milaret | 25236d9 | 2016-03-28 09:40:58 -0400 | [diff] [blame] | 66 | else { |
| 67 | Video::PreviewManager::instance().stopPreview(); |
| 68 | accept(); |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | void |
| 73 | PhotoBoothDialog::on_takePhotoButton_clicked() |
| 74 | { |
| 75 | auto photo = ui->videoFeed->takePhoto(); |
| 76 | Video::PreviewManager::instance().stopPreview(); |
| 77 | photo.save(fileName_); |
| 78 | accept(); |
| 79 | } |