blob: e9f9523ce2f8ba1847a9274409f907e4aa6f9114 [file] [log] [blame]
Edric Milaret627500d2015-03-27 16:41:40 -04001/***************************************************************************
Anthony LĂ©onard2fde81d2017-04-17 10:06:55 -04002 * Copyright (C) 2015-2017 by Savoir-faire Linux *
Edric Milaret627500d2015-03-27 16:41:40 -04003 * 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 Milaret5f316da2015-09-28 11:57:42 -040019#pragma once
Edric Milaret627500d2015-03-27 16:41:40 -040020
21#include <QWidget>
22#include <QPainter>
Andreas Traczyk14c3e862018-12-26 14:02:30 -050023#include <QMutex>
Edric Milaret1eca0292015-06-29 12:03:36 -040024
25#include <memory>
Edric Milaret7153eed2015-06-03 15:29:03 -040026
27#include "video/renderer.h"
28#include "video/previewmanager.h"
Edric Milaret627500d2015-03-27 16:41:40 -040029
30class VideoWidget : public QWidget
31{
32 Q_OBJECT
33public:
Edric Milaret80e0b212015-10-16 10:07:43 -040034 explicit VideoWidget(QWidget* parent = 0);
Edric Milaret627500d2015-03-27 16:41:40 -040035 ~VideoWidget();
36 void paintEvent(QPaintEvent* evt);
Edric Milaret80e0b212015-10-16 10:07:43 -040037 void setPreviewDisplay(bool display);
38 void setDistantRenderer(Video::Renderer* renderer);
Edric Milaret0b7fe5d2016-01-27 11:12:43 -050039 void setIsFullPreview(bool full);
Andreas Traczyk6c323c62018-12-26 13:04:22 -050040 inline void setResetPreview(bool reset) { resetPreview_ = reset; hasFrame_=false; }
Edric Milaret25236d92016-03-28 09:40:58 -040041 void setPhotoMode(bool isPhotoMode);
42 QImage takePhoto();
Edric Milaret627500d2015-03-27 16:41:40 -040043
44public slots:
45 void previewStarted(Video::Renderer* renderer);
Edric Milaret72c406d2015-04-28 13:23:54 -040046 void previewStopped();
Edric Milaret627500d2015-03-27 16:41:40 -040047 void frameFromPreview();
Edric Milaret627500d2015-03-27 16:41:40 -040048 void frameFromDistant();
49 void renderingStopped();
Edric Milaret25236d92016-03-28 09:40:58 -040050 inline QRect& getPreviewRect(){ return previewGeometry_; }
Edric Milaret627500d2015-03-27 16:41:40 -040051
52private:
53 Video::Renderer* previewRenderer_;
54 Video::Renderer* renderer_;
Edric Milaret37157b32015-10-13 18:00:03 -040055 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 Milaret80e0b212015-10-16 10:07:43 -040062 bool isPreviewDisplayed_;
Edric Milaret0b7fe5d2016-01-27 11:12:43 -050063 bool fullPreview_;
Nicolas Jagerc7b8e4b2016-02-29 09:20:40 -050064 QRect previewGeometry_;
65 bool resetPreview_ = false;
Edric Milaret25236d92016-03-28 09:40:58 -040066 bool photoMode_ = false;
Andreas Traczyk6c323c62018-12-26 13:04:22 -050067 bool hasFrame_ = false;
Edric Milaret37157b32015-10-13 18:00:03 -040068
Edric Milareta9f937f2015-06-01 17:10:34 -040069 constexpr static int previewMargin_ = 15;
Andreas Traczyk6c323c62018-12-26 13:04:22 -050070
71private:
72 void paintBackgroundColor(QPainter* painter, QColor color);
Edric Milaret627500d2015-03-27 16:41:40 -040073};
74