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
6QGCImageProvider::QGCImageProvider(QQmlImageProviderBase::ImageType imageType)
7 : QQuickImageProvider(imageType)
8 , _dummy(320, 240, QImage::Format_RGBA8888)
9{
10 // qCDebug(ImageProtocolManagerLog) << Q_FUNC_INFO << this;
11
12 Q_ASSERT(imageType == QQmlImageProviderBase::ImageType::Image);
13
14 // Dummy temporary image until something comes along
15 _dummy.fill(Qt::black);
16 QPainter painter(&_dummy);
17 QFont f = painter.font();
18 f.setPixelSize(20);
19 painter.setFont(f);
20 painter.setPen(Qt::white);
21 painter.drawText(QRectF(0, 0, _dummy.width(), _dummy.height()), Qt::AlignCenter, QStringLiteral("Waiting..."));
22 _images[0] = _dummy;
23}
24
26{
27 // qCDebug(ImageProtocolManagerLog) << Q_FUNC_INFO << this;
28}
29
30QImage QGCImageProvider::requestImage(const QString &id, QSize *size, const QSize &requestedSize)
31{
32 Q_UNUSED(requestedSize);
33
34 if (id.isEmpty()) {
35 return _dummy;
36 }
37
38 if (!id.contains("/")) {
39 return _dummy;
40 }
41
42 const QStringList url = id.split('/', Qt::SkipEmptyParts);
43 if (url.size() != 2) {
44 return _dummy;
45 }
46
47 bool ok = false;
48 const uint8_t vehicleId = url[0].toUInt(&ok);
49 if (!ok) {
50 return _dummy;
51 }
52
53 const uint8_t index [[maybe_unused]] = url[1].toUInt(&ok);
54 if (!ok) {
55 return _dummy;
56 }
57
58 if (!_images.contains(vehicleId)) {
59 return _dummy;
60 }
61
62 const QImage image = _images[vehicleId];
63 // image->scaled(requestedSize);
64 *size = image.size();
65
66 return image;
67}
QImage requestImage(const QString &id, QSize *size, const QSize &requestedSize) final
QGCImageProvider(QQmlImageProviderBase::ImageType type=QQmlImageProviderBase::ImageType::Image)