Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame^] | 1 | /* |
| 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 | |
| 24 | DistantRenderer::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 | |
| 45 | DistantRenderer::~DistantRenderer() {} |
| 46 | |
| 47 | void |
| 48 | DistantRenderer::setRendererId(const QString &id) |
| 49 | { |
| 50 | distantRenderId_ = id; |
| 51 | update(QRect(0, 0, width(), height())); |
| 52 | } |
| 53 | |
| 54 | void |
| 55 | DistantRenderer::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 | } |