UImageView.h
Go to the documentation of this file.
1 /*
2  * ImageView.h
3  *
4  * Created on: 2012-06-20
5  * Author: mathieu
6  */
7 
8 #ifndef IMAGEVIEW_H_
9 #define IMAGEVIEW_H_
10 
11 #include "rtabmap/gui/rtabmap_gui_export.h" // DLL export/import defines
12 
13 #include <QWidget>
14 #include <QtGui/QPainter>
15 
16 class RTABMAP_GUI_EXPORT UImageView : public QWidget
17 {
18  Q_OBJECT;
19 public:
20  UImageView(QWidget * parent = 0) : QWidget(parent) {}
22  void setBackgroundBrush(const QBrush & brush) {brush_ = brush;}
23 
24 public Q_SLOTS:
25  void setImage(const QImage & image)
26  {
27  pixmap_ = QPixmap::fromImage(image);
28  this->update();
29  }
30 
31 private:
32  void computeScaleOffsets(float & scale, float & offsetX, float & offsetY)
33  {
34  scale = 1.0f;
35  offsetX = 0.0f;
36  offsetY = 0.0f;
37 
38  if(!pixmap_.isNull())
39  {
40  float w = pixmap_.width();
41  float h = pixmap_.height();
42  float widthRatio = float(this->rect().width()) / w;
43  float heightRatio = float(this->rect().height()) / h;
44 
45  if(widthRatio < heightRatio)
46  {
47  scale = widthRatio;
48  }
49  else
50  {
51  scale = heightRatio;
52  }
53 
54  w *= scale;
55  h *= scale;
56 
57  if(w < this->rect().width())
58  {
59  offsetX = (this->rect().width() - w)/2.0f;
60  }
61  if(h < this->rect().height())
62  {
63  offsetY = (this->rect().height() - h)/2.0f;
64  }
65  }
66  }
67 
68 protected:
69  virtual void paintEvent(QPaintEvent *event)
70  {
71  QPainter painter(this);
72 
73  //Draw background
74  painter.save();
75  painter.setBrush(brush_);
76  painter.drawRect(this->rect());
77  painter.restore();
78 
79  if(!pixmap_.isNull())
80  {
81  painter.save();
82  //Scale
83  float ratio, offsetX, offsetY;
84  this->computeScaleOffsets(ratio, offsetX, offsetY);
85  painter.translate(offsetX, offsetY);
86  painter.scale(ratio, ratio);
87  painter.drawPixmap(QPoint(0,0), pixmap_);
88  painter.restore();
89  }
90  }
91 
92 private:
93  QPixmap pixmap_;
94  QBrush brush_;
95 };
96 
97 
98 #endif /* IMAGEVIEW_H_ */
w
RowVector3d w
update
def update(text)
UImageView
Definition: UImageView.h:16
h
const double h
UImageView::paintEvent
virtual void paintEvent(QPaintEvent *event)
Definition: UImageView.h:69
UImageView::setBackgroundBrush
void setBackgroundBrush(const QBrush &brush)
Definition: UImageView.h:22
UImageView::pixmap_
QPixmap pixmap_
Definition: UImageView.h:93
scale
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy y set format x g set format y g set format x2 g set format y2 g set format z g set angles radians set nogrid set key title set key left top Right noreverse box linetype linewidth samplen spacing width set nolabel set noarrow set nologscale set logscale x set set pointsize set encoding default set nopolar set noparametric set set set set surface set nocontour set clabel set mapping cartesian set nohidden3d set cntrparam order set cntrparam linear set cntrparam levels auto set cntrparam points set size set set xzeroaxis lt lw set x2zeroaxis lt lw set yzeroaxis lt lw set y2zeroaxis lt lw set tics in set ticslevel set tics scale
UImageView::UImageView
UImageView(QWidget *parent=0)
Definition: UImageView.h:20
f
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
UImageView::computeScaleOffsets
void computeScaleOffsets(float &scale, float &offsetX, float &offsetY)
Definition: UImageView.h:32
UImageView::brush_
QBrush brush_
Definition: UImageView.h:94
ratio
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy y set format x g set format y g set format x2 g set format y2 g set format z g set angles radians set nogrid set key title set key left top Right noreverse box linetype linewidth samplen spacing width set nolabel set noarrow set nologscale set logscale x set set pointsize set encoding default set nopolar set noparametric set set set set surface set nocontour set clabel set mapping cartesian set nohidden3d set cntrparam order set cntrparam linear set cntrparam levels auto set cntrparam points set size ratio
float
float
UImageView::~UImageView
~UImageView()
Definition: UImageView.h:21
UImageView::setImage
void setImage(const QImage &image)
Definition: UImageView.h:25


rtabmap
Author(s): Mathieu Labbe
autogenerated on Thu Jul 25 2024 02:50:23