rock_widget_collection  0.1
ImageView.h
Go to the documentation of this file.
1 
5 #ifndef IMAGE_VIEW_H
6 #define IMAGE_VIEW_H
7 
8 #include <QtGui>
9 #include <QtCore>
10 
11 #include <base/samples/Frame.hpp>
12 #include <base/samples/DistanceImage.hpp>
13 #include <frame_helper/FrameQImageConverter.h>
14 #include "rock_widget_collection/progress_indicator/ProgressIndicator.h"
15 
16 #include "GraphicsPointsItem.h"
17 
18 //TODO NOT ALL OBJECTS GET DELETED AFTER DECONSTRUCTION
19 
47 class ImageView : public QWidget
48 {
49  Q_OBJECT
50  Q_CLASSINFO("Author", "Allan Conquest")
51 
52 
60 
66 
69 
78 
79  Q_PROPERTY(bool rgb_swapped READ getRgbSwapped WRITE setRgbSwapped)
80  Q_PROPERTY(bool invert_color READ getInvertColor WRITE setInvertColor)
81 
82 #ifdef USE_GST
83  /* Properties for use with GStreamer. That means in particluar that any of
84  * the following properties is unimportant if useGst is set to false. */
85 
90  Q_PROPERTY(QString pipelineDescription READ getPipelineDescription WRITE setPipelineDescription)
91 
92 
98  Q_PROPERTY(bool useGl READ getUseGl WRITE setUseGl)
99 #endif
100 
101 public:
102  ImageView(QWidget *parent = 0);
103  virtual ~ImageView();
104 
111  {
116  };
117  Q_ENUMS(TextLocation)
118 
119  QSize sizeHint() const;
120 
121 public slots:
122  const QColor& getBackgroundColor() const;
123  void setBackgroundColor(const QColor & color);
124  bool useProgressIndicator();
125  void setUseProgressIndicator(bool use);
127  void setSmoothTransformation(bool smooth);
128  const int getProgressIndicatorTimeout() const;
129  void setProgressIndicatorTimeout(int timeout);
130 
131  void setInvertColor(bool invert);
132  bool getInvertColor(){return invert_color;};
133  void setRgbSwapped(bool swapped);
134  bool getRgbSwapped(){return rgb_swapped;};
135 
136 #ifdef USE_GST
137  const QString getPipelineDescription() const;
138  void setPipelineDescription(QString descr);
139  bool getUseGl();
140  void setUseGl(bool use_gl);
141 #endif
142 
143  /* Overlays */
144 
154  void addCircle(QPointF &center, double radius, QColor &color, int width, bool persistent = 0);
155 
165  void addLine(QLineF &line, QColor &color, int width, bool persistent = 0);
166 
176  void addPolygon(QPolygonF &polygon, QColor &color, int width, bool persistent = 0);
177 
194  void addPoints(const QList<int> points_x,QList<int> points_y, QColor &color, int width, bool persistent=0);
195 
211  void addText(QString text, /*TextLocation*/ int location, QColor color = QColor(Qt::black), bool persistent = 0);
212 
217  void clearOverlays(bool clear_persistent_items = 0);
218 
224  void rotate(int deg);
225 
235  void saveImage(QString path = QString(), bool overlay = 0);
236 
237  /* Other slots */
238 
244  void setFrame(const base::samples::DistanceImage &frame);
245  void setFrame(const base::samples::frame::Frame &frame);
246  void setImage(const QImage &image);
247  void setRawImage(const QString &mode, int pixel_size, int width, int height,const char* pbuffer, const int size);
248  void refresh();
249  void processImage();
250 
254  void update2();
255 
259  int getHeight() const;
260 
264  int getWidth() const;
265 
266 
267 
268 signals:
269 
276  void clickedImage(const QPoint &point);
277 
278 protected:
279  void resizeEvent(QResizeEvent *event);
280  void contextMenuEvent ( QContextMenuEvent * event );
281  bool eventFilter(QObject *obj, QEvent *event);
282 
283 private slots:
284  void displayContextMenu(QPoint screenPos);
285  void rotate_clockwise();
286  void save_image();
287  void save_image_overlay();
288  void startProgressIndicator();
289 
290 private:
291  void addDrawItem(QGraphicsScene *scene, QGraphicsItem *item, bool persistent = 0);
292  void setItemPositions();
293  void setupContextMenu();
294 
295  QColor bgColor;
299  bool rgb_swapped;
300  bool invert_color;
301  QString last_path;
302 #ifdef USE_GST
303  QString pipelineDescription;
304  bool use_gl;
305 #endif
306 
307  QGraphicsView *imageView;
308  QGraphicsProxyWidget *imageViewProxy;
309  QGraphicsScene *imageScene;
310  QGraphicsView *fixedOverlayView;
311  QGraphicsScene *fixedOverlayScene;
312  QGraphicsWidget *overlayWidget;
313  QGraphicsGridLayout *overlay_grid;
314  QMap<int, QLabel*> overlayMap;
315  QGraphicsPixmapItem *imageItem;
316  QImage image;
317 
318  QList<QGraphicsItem*> persistentDrawItems;
319  QList<QGraphicsItem*> volatileDrawItems;
320 
321  QSize imageSize;
322 
323  frame_helper::FrameQImageConverter frame_converter;
324 
325  ProgressIndicator progress_indicator;
326  QTimer progress_indicator_timer;
327 
328  /* Menus and actions */
329  QMenu context_menu;
330  QAction rotate_image_clockwise_act;
331  QAction save_image_act;
332  QAction save_image_overlay_act;
333  QAction activate_progress_indicator_act;
334  QAction rgb_swapped_act;
335  QAction invert_color_act;
336 };
337 
338 #endif /* IMAGE_VIEW_H */
void setRawImage(const QString &mode, int pixel_size, int width, int height, const char *pbuffer, const int size)
Definition: ImageView.cc:493
void addText(QString text, int location, QColor color=QColor(Qt::black), bool persistent=0)
Draws text overlay.
Definition: ImageView.cc:312
void saveImage(QString path=QString(), bool overlay=0)
Saves current image to file.
Definition: ImageView.cc:423
void setRgbSwapped(bool swapped)
Definition: ImageView.cc:697
void addPoints(const QList< int > points_x, QList< int > points_y, QColor &color, int width, bool persistent=0)
Draws points overlay (2D point cloud).
Definition: ImageView.cc:280
const int getProgressIndicatorTimeout() const
Definition: ImageView.cc:224
bool getRgbSwapped()
Definition: ImageView.h:134
void setUseProgressIndicator(bool use)
Definition: ImageView.cc:193
void setImage(const QImage &image)
Definition: ImageView.cc:500
void addCircle(QPointF &center, double radius, QColor &color, int width, bool persistent=0)
Draws circle overlay.
Definition: ImageView.cc:257
bool useProgressIndicator()
Definition: ImageView.cc:187
virtual ~ImageView()
Definition: ImageView.cc:167
ImageView(QWidget *parent=0)
Definition: ImageView.cc:24
QColor backgroundColor
The widget&#39;s background color.
Definition: ImageView.h:59
void setBackgroundColor(const QColor &color)
Definition: ImageView.cc:181
void addPolygon(QPolygonF &polygon, QColor &color, int width, bool persistent=0)
Draws polygon overlay.
Definition: ImageView.cc:299
const QColor & getBackgroundColor() const
Definition: ImageView.cc:176
bool useSmoothTransformation()
Definition: ImageView.cc:210
void clickedImage(const QPoint &point)
Mouse click coordinates in image.
bool eventFilter(QObject *obj, QEvent *event)
Definition: ImageView.cc:596
bool invert_color
Definition: ImageView.h:80
void refresh()
Definition: ImageView.cc:515
The ProgressIndicator class lets an application display a progress indicator to show that a lengthy t...
bool use_progress_indicator
Display progress indicator widget if no frames have being received for a defined time.
Definition: ImageView.h:65
void setInvertColor(bool invert)
Definition: ImageView.cc:689
void setFrame(const base::samples::DistanceImage &frame)
Frame input.
Definition: ImageView.cc:467
void setSmoothTransformation(bool smooth)
Definition: ImageView.cc:215
int getWidth() const
returns the real width of the underlaying widget
Definition: ImageView.cc:684
TextLocation
Text overlay alignment specification.
Definition: ImageView.h:110
void update2()
Wrapper for QWidget::update(). This is due to some QtRuby limitations.
Definition: ImageView.cc:667
bool getInvertColor()
Definition: ImageView.h:132
bool use_smooth_transformation
Usage of antialiasing techniques during image transformation.
Definition: ImageView.h:77
Image viewer with optional text and geometry overlay functionality.
Definition: ImageView.h:47
void setProgressIndicatorTimeout(int timeout)
Definition: ImageView.cc:229
QSize sizeHint() const
Definition: ImageView.cc:171
void contextMenuEvent(QContextMenuEvent *event)
Definition: ImageView.cc:591
void rotate(int deg)
Rotates image display.
Definition: ImageView.cc:416
void clearOverlays(bool clear_persistent_items=0)
Removes overlays.
Definition: ImageView.cc:401
void resizeEvent(QResizeEvent *event)
Definition: ImageView.cc:567
void addLine(QLineF &line, QColor &color, int width, bool persistent=0)
Draws line overlay.
Definition: ImageView.cc:269
void processImage()
Definition: ImageView.cc:507
int progress_indicator_timeout
The time without frame update in ms after which the progress indicator gets started.
Definition: ImageView.h:68
int getHeight() const
returns the real height of the underlaying widget
Definition: ImageView.cc:679
bool rgb_swapped
Definition: ImageView.h:79