Gazebo Gui

API Reference

8.3.0
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 <algorithm>
22 #include <memory>
23 #include <QQuickImageProvider>
24 
25 #include <gz/msgs/image.pb.h>
26 
27 #ifndef _WIN32
28 # define ImageDisplay_EXPORTS_API
29 #else
30 # if (defined(ImageDisplay_EXPORTS))
31 # define ImageDisplay_EXPORTS_API __declspec(dllexport)
32 # else
33 # define ImageDisplay_EXPORTS_API __declspec(dllimport)
34 # endif
35 #endif
36 
37 #include "gz/gui/Plugin.hh"
38 
39 namespace gz::gui::plugins
40 {
41  class ImageDisplayPrivate;
42 
43  class ImageProvider : public QQuickImageProvider
44  {
45  public: ImageProvider()
46  : QQuickImageProvider(QQuickImageProvider::Image)
47  {
48  }
49 
50  public: QImage requestImage(const QString &, QSize *,
51  const QSize &) override
52  {
53  if (!this->img.isNull())
54  {
55  // Must return a copy
56  QImage copy(this->img);
57  return copy;
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 
81  class ImageDisplay_EXPORTS_API ImageDisplay : public Plugin
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 
119  signals: void TopicListChanged();
120 
122  signals: void newImage();
123 
125  private slots: void ProcessImage();
126 
129  private: void OnImageMsg(const gz::msgs::Image &_msg);
130 
133  private: std::unique_ptr<ImageDisplayPrivate> dataPtr;
134  };
135 } // namespace gz::gui::plugins
136 
137 #endif // GZ_GUI_PLUGINS_IMAGEDISPLAY_HH_