ImageDisplay.hh
Go to the documentation of this file.
1/*
2 * Copyright (C) 2017 Open Source Robotics Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16*/
17
18#ifndef GZ_GUI_PLUGINS_IMAGEDISPLAY_HH_
19#define GZ_GUI_PLUGINS_IMAGEDISPLAY_HH_
20
21#include <QImage>
22#include <QString>
23#include <QStringList>
24#include <QQuickImageProvider>
25
26#include <gz/msgs/image.pb.h>
27
28#ifndef _WIN32
29# define ImageDisplay_EXPORTS_API __attribute__ ((visibility ("default")))
30#else
31# if (defined(ImageDisplay_EXPORTS))
32# define ImageDisplay_EXPORTS_API __declspec(dllexport)
33# else
34# define ImageDisplay_EXPORTS_API __declspec(dllimport)
35# endif
36#endif
37
38#include "gz/gui/Plugin.hh"
39
40#include <gz/utils/ImplPtr.hh>
41
42namespace gz::gui::plugins
43{
44 class ImageProvider : public QQuickImageProvider
45 {
46 public: ImageProvider()
47 : QQuickImageProvider(QQuickImageProvider::Image)
48 {
49 }
50
51 public: QImage requestImage(const QString &, QSize *,
52 const QSize &) override
53 {
54 if (!this->img.isNull())
55 {
56 // Must return a copy
57 return this->img;
58 }
59
60 // Placeholder in case we have no image yet
61 QImage i(400, 400, QImage::Format_RGB888);
62 i.fill(QColor(128, 128, 128, 100));
63 return i;
64 }
65
66 public: void SetImage(const QImage &_image)
67 {
68 this->img = _image;
69 }
70
71 private: QImage img;
72 };
73
82 {
83 Q_OBJECT
84
86 Q_PROPERTY(
87 QStringList topicList
88 READ TopicList
89 WRITE SetTopicList
90 NOTIFY TopicListChanged
91 )
92
93
94 public: ImageDisplay();
95
97 public: virtual ~ImageDisplay();
98
99 // Documentation inherited
100 public: virtual void LoadConfig(const tinyxml2::XMLElement *_pluginElem);
101
103 public slots: void OnRefresh();
104
106 public slots: void OnTopic(const QString _topic);
107
111 public: Q_INVOKABLE QStringList TopicList() const;
112
116 public: Q_INVOKABLE void SetTopicList(const QStringList &_topicList);
117
120 public: Q_INVOKABLE void RegisterImageProvider(const QString &_uniqueName);
121
123 public: Q_INVOKABLE QString ImageProviderName();
124
126 signals: void TopicListChanged();
127
129 signals: void newImage();
130
131 private slots: void ProcessImage();
132
135 private: void OnImageMsg(const gz::msgs::Image &_msg);
136
139 GZ_UTILS_UNIQUE_IMPL_PTR(dataPtr)
140 };
141} // namespace gz::gui::plugins
142
143#endif // GZ_GUI_PLUGINS_IMAGEDISPLAY_HH_