QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
QGCImageProvider.cc
Go to the documentation of this file.
1#include "QGCImageProvider.h"
2
3#include <QtGui/QPainter>
4#include <QtGui/QFont>
5
7 : QQuickImageProvider(QQmlImageProviderBase::ImageType::Image)
8 , _dummy(320, 240, QImage::Format_RGBA8888)
9{
10 // qCDebug(ImageProtocolManagerLog) << Q_FUNC_INFO << this;
11
12 // Dummy temporary image until something comes along
13 _dummy.fill(Qt::black);
14 QPainter painter(&_dummy);
15 QFont f = painter.font();
16 f.setPixelSize(20);
17 painter.setFont(f);
18 painter.setPen(Qt::white);
19 painter.drawText(QRectF(0, 0, _dummy.width(), _dummy.height()), Qt::AlignCenter, QStringLiteral("Waiting..."));
20 _images[0] = _dummy;
21}
22
24{
25 // qCDebug(ImageProtocolManagerLog) << Q_FUNC_INFO << this;
26}
27
28QImage QGCImageProvider::requestImage(const QString &id, QSize *size, const QSize &requestedSize)
29{
30 Q_UNUSED(requestedSize);
31
32 if (id.isEmpty()) {
33 return _dummy;
34 }
35
36 if (!id.contains("/")) {
37 return _dummy;
38 }
39
40 const QStringList url = id.split('/', Qt::SkipEmptyParts);
41 if (url.size() != 2) {
42 return _dummy;
43 }
44
45 bool ok = false;
46 const quint32 vehicleId = url[0].toUInt(&ok);
47 if (!ok) {
48 return _dummy;
49 }
50
51 const uint8_t index [[maybe_unused]] = url[1].toUInt(&ok);
52 if (!ok) {
53 return _dummy;
54 }
55
56 if (!_images.contains(vehicleId)) {
57 return _dummy;
58 }
59
60 const QImage image = _images[vehicleId];
61 // image->scaled(requestedSize);
62 *size = image.size();
63
64 return image;
65}
QImage requestImage(const QString &id, QSize *size, const QSize &requestedSize) final