Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qsyntheticvideoscene.cpp
Go to the documentation of this file.
1// Copyright (C) 2026 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
5
6#include <QtGui/qpainter.h>
7
9
10using namespace Qt::StringLiterals;
11
12// The map is sent over D-Bus, so it may only contain types QtDBus can marshal --
13// QSize, QRect and QColor are not among them. Everything is flattened to ints and
14// colour names.
16{
17 return QVariantMap{
18 { u"frameWidth"_s, frameSize.width() },
19 { u"frameHeight"_s, frameSize.height() },
20 { u"patternX"_s, patternRect.x() },
21 { u"patternY"_s, patternRect.y() },
22 { u"patternWidth"_s, patternRect.width() },
23 { u"patternHeight"_s, patternRect.height() },
24 { u"backgroundColor"_s, backgroundColor.name(QColor::HexArgb) },
25 { u"firstColor"_s, firstColor.name(QColor::HexArgb) },
26 { u"secondColor"_s, secondColor.name(QColor::HexArgb) },
27 { u"animated"_s, animated },
28 { u"scale"_s, scale },
29 };
30}
31
32SyntheticVideoScene SyntheticVideoScene::fromVariantMap(const QVariantMap &map)
33{
34 const auto intOr = [&](const QString &key, int fallback) {
35 const auto it = map.find(key);
36 return it == map.end() ? fallback : it->toInt();
37 };
38 const auto colorOr = [&](const QString &key, QColor fallback) {
39 const auto it = map.find(key);
40 if (it == map.end())
41 return fallback;
42 const QColor color(it->toString());
43 return color.isValid() ? color : fallback;
44 };
45
47 scene.frameSize = QSize(intOr(u"frameWidth"_s, scene.frameSize.width()),
48 intOr(u"frameHeight"_s, scene.frameSize.height()));
49 scene.patternRect = QRect(intOr(u"patternX"_s, scene.patternRect.x()),
50 intOr(u"patternY"_s, scene.patternRect.y()),
51 intOr(u"patternWidth"_s, scene.patternRect.width()),
52 intOr(u"patternHeight"_s, scene.patternRect.height()));
53 scene.backgroundColor = colorOr(u"backgroundColor"_s, scene.backgroundColor);
54 scene.firstColor = colorOr(u"firstColor"_s, scene.firstColor);
55 scene.secondColor = colorOr(u"secondColor"_s, scene.secondColor);
56 if (const auto it = map.find(u"animated"_s); it != map.end())
57 scene.animated = it->toBool();
58 if (const auto it = map.find(u"scale"_s); it != map.end())
59 scene.scale = it->toReal();
60 return scene;
61}
62
63void paintSyntheticVideoScene(QPainter &painter, const SyntheticVideoScene &scene, unsigned tick)
64{
65 QColor first = scene.firstColor;
66 QColor second = scene.secondColor;
67 if (scene.animated && (tick & 1u))
68 std::swap(first, second);
69
70 painter.fillRect(QRect(QPoint(0, 0), scene.frameSize), scene.backgroundColor);
71 painter.fillRect(scene.patternRect, first);
72 painter.fillRect(scene.insetRect(), second);
73}
74
76{
77 QImage image(scene.frameSize, QImage::Format_RGB32);
78 QPainter painter(&image);
79 paintSyntheticVideoScene(painter, scene, tick);
80 return image;
81}
82
83QT_END_NAMESPACE
friend class QPainter
Combined button and popup list for selecting options.
void paintSyntheticVideoScene(QPainter &painter, const SyntheticVideoScene &scene, unsigned tick)
QImage renderSyntheticVideoScene(const SyntheticVideoScene &scene, unsigned tick)
QVariantMap toVariantMap() const