Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 1 | /*************************************************************************** |
Anthony LĂ©onard | 2fde81d | 2017-04-17 10:06:55 -0400 | [diff] [blame] | 2 | * Copyright (C) 2015-2017 by Savoir-faire Linux * |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 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 | |
Edric Milaret | 5f316da | 2015-09-28 11:57:42 -0400 | [diff] [blame] | 19 | #pragma once |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 20 | |
| 21 | #include <QWidget> |
| 22 | #include <QPainter> |
Andreas Traczyk | 14c3e86 | 2018-12-26 14:02:30 -0500 | [diff] [blame] | 23 | #include <QMutex> |
Edric Milaret | 1eca029 | 2015-06-29 12:03:36 -0400 | [diff] [blame] | 24 | |
| 25 | #include <memory> |
Edric Milaret | 7153eed | 2015-06-03 15:29:03 -0400 | [diff] [blame] | 26 | |
| 27 | #include "video/renderer.h" |
| 28 | #include "video/previewmanager.h" |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 29 | |
| 30 | class VideoWidget : public QWidget |
| 31 | { |
| 32 | Q_OBJECT |
| 33 | public: |
Edric Milaret | 80e0b21 | 2015-10-16 10:07:43 -0400 | [diff] [blame] | 34 | explicit VideoWidget(QWidget* parent = 0); |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 35 | ~VideoWidget(); |
| 36 | void paintEvent(QPaintEvent* evt); |
Edric Milaret | 80e0b21 | 2015-10-16 10:07:43 -0400 | [diff] [blame] | 37 | void setPreviewDisplay(bool display); |
| 38 | void setDistantRenderer(Video::Renderer* renderer); |
Edric Milaret | 0b7fe5d | 2016-01-27 11:12:43 -0500 | [diff] [blame] | 39 | void setIsFullPreview(bool full); |
Andreas Traczyk | 6c323c6 | 2018-12-26 13:04:22 -0500 | [diff] [blame] | 40 | inline void setResetPreview(bool reset) { resetPreview_ = reset; hasFrame_=false; } |
Edric Milaret | 25236d9 | 2016-03-28 09:40:58 -0400 | [diff] [blame] | 41 | void setPhotoMode(bool isPhotoMode); |
| 42 | QImage takePhoto(); |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 43 | |
| 44 | public slots: |
| 45 | void previewStarted(Video::Renderer* renderer); |
Edric Milaret | 72c406d | 2015-04-28 13:23:54 -0400 | [diff] [blame] | 46 | void previewStopped(); |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 47 | void frameFromPreview(); |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 48 | void frameFromDistant(); |
| 49 | void renderingStopped(); |
Edric Milaret | 25236d9 | 2016-03-28 09:40:58 -0400 | [diff] [blame] | 50 | inline QRect& getPreviewRect(){ return previewGeometry_; } |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 51 | |
| 52 | private: |
| 53 | Video::Renderer* previewRenderer_; |
| 54 | Video::Renderer* renderer_; |
Edric Milaret | 37157b3 | 2015-10-13 18:00:03 -0400 | [diff] [blame] | 55 | Video::Frame currentPreviewFrame_; |
| 56 | Video::Frame currentDistantFrame_; |
| 57 | QMutex mutex_; |
| 58 | std::unique_ptr<QImage> distantImage_; |
| 59 | std::unique_ptr<QImage> previewImage_; |
| 60 | std::vector<uint8_t> frameDistant_; |
| 61 | std::vector<uint8_t> framePreview_; |
Edric Milaret | 80e0b21 | 2015-10-16 10:07:43 -0400 | [diff] [blame] | 62 | bool isPreviewDisplayed_; |
Edric Milaret | 0b7fe5d | 2016-01-27 11:12:43 -0500 | [diff] [blame] | 63 | bool fullPreview_; |
Nicolas Jager | c7b8e4b | 2016-02-29 09:20:40 -0500 | [diff] [blame] | 64 | QRect previewGeometry_; |
| 65 | bool resetPreview_ = false; |
Edric Milaret | 25236d9 | 2016-03-28 09:40:58 -0400 | [diff] [blame] | 66 | bool photoMode_ = false; |
Andreas Traczyk | 6c323c6 | 2018-12-26 13:04:22 -0500 | [diff] [blame] | 67 | bool hasFrame_ = false; |
Edric Milaret | 37157b3 | 2015-10-13 18:00:03 -0400 | [diff] [blame] | 68 | |
Edric Milaret | a9f937f | 2015-06-01 17:10:34 -0400 | [diff] [blame] | 69 | constexpr static int previewMargin_ = 15; |
Andreas Traczyk | 6c323c6 | 2018-12-26 13:04:22 -0500 | [diff] [blame] | 70 | |
| 71 | private: |
| 72 | void paintBackgroundColor(QPainter* painter, QColor color); |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 73 | }; |
| 74 | |