blob: 023442b34b011c72f3b7ff0df45366230c57f38e [file] [log] [blame]
Sébastien Blin1f915762020-08-03 13:27:42 -04001/*
2 * Copyright (C) 2019-2020 by Savoir-faire Linux
3 * Author: Andreas Traczyk <andreas.traczyk@savoirfairelinux.com>
4 * Author: Mingrui Zhang <mingrui.zhang@savoirfairelinux.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include "distantrenderer.h"
21
22#include "lrcinstance.h"
23
24DistantRenderer::DistantRenderer(QQuickItem *parent)
25 : QQuickPaintedItem(parent)
26{
27 setAntialiasing(true);
28 setFillColor(Qt::black);
29 setRenderTarget(QQuickPaintedItem::FramebufferObject);
30 setPerformanceHint(QQuickPaintedItem::FastFBOResizing);
31
32 connect(LRCInstance::renderer(), &RenderManager::distantFrameUpdated, [this](const QString &id) {
33 if (distantRenderId_ == id)
34 update(QRect(0, 0, width(), height()));
35 });
36
37 connect(LRCInstance::renderer(),
38 &RenderManager::distantRenderingStopped,
39 [this](const QString &id) {
40 if (distantRenderId_ == id)
41 update(QRect(0, 0, width(), height()));
42 });
43}
44
45DistantRenderer::~DistantRenderer() {}
46
47void
48DistantRenderer::setRendererId(const QString &id)
49{
50 distantRenderId_ = id;
51 update(QRect(0, 0, width(), height()));
52}
53
54void
55DistantRenderer::paint(QPainter *painter)
56{
57 auto distantImage = LRCInstance::renderer()->getFrame(distantRenderId_);
58 if (distantImage) {
59 auto scaledDistant = distantImage->scaled(size().toSize(), Qt::KeepAspectRatio);
60 auto xDiff = (width() - scaledDistant.width()) / 2;
61 auto yDiff = (height() - scaledDistant.height()) / 2;
62 painter->drawImage(QRect(xDiff, yDiff, scaledDistant.width(), scaledDistant.height()),
63 scaledDistant);
64 }
65}