30 #include <QMouseEvent> 33 #include <QInputDialog> 43 setAttribute(Qt::WA_StaticContents);
48 menu_ =
new QMenu(tr(
""),
this);
59 QActionGroup * group =
new QActionGroup(
this);
84 map_.height() == modifiedMap.rows);
85 UASSERT(modifiedMap.type() == CV_8UC1);
86 for(
int j=0; j<
map_.height(); ++j)
88 for(
int i=0; i<
map_.width(); ++i)
90 modifiedMap.at<
unsigned char>(j,i) = qRed(
map_.pixel(i, j));
111 if (event->button() == Qt::LeftButton) {
112 float scale, offsetX, offsetY;
114 lastPoint_.setX((event->pos().x()-offsetX)/scale);
115 lastPoint_.setY((event->pos().y()-offsetY)/scale);
123 if ((event->buttons() & Qt::LeftButton) &&
scribbling_)
125 float scale, offsetX, offsetY;
128 to.setX((event->pos().x()-offsetX)/scale);
129 to.setY((event->pos().y()-offsetY)/scale);
136 if (event->button() == Qt::LeftButton &&
scribbling_) {
137 float scale, offsetX, offsetY;
140 to.setX((event->pos().x()-offsetX)/scale);
141 to.setY((event->pos().y()-offsetY)/scale);
155 float w =
map_.width();
156 float h =
map_.height();
157 float widthRatio = float(targetRect.width()) / w;
158 float heightRatio = float(targetRect.height()) / h;
161 if(widthRatio < heightRatio)
175 if(w < targetRect.width())
177 offsetX = (targetRect.width() - w)/2.0
f;
179 if(h < targetRect.height())
181 offsetY = (targetRect.height() - h)/2.0
f;
190 float ratio, offsetX, offsetY;
192 QPainter painter(
this);
194 painter.translate(offsetX, offsetY);
195 painter.scale(ratio, ratio);
196 painter.drawImage(QPoint(0,0),
map_);
201 QWidget::resizeEvent(event);
206 QAction * action =
menu_->exec(e->globalPos());
210 int width = QInputDialog::getInt(
this, tr(
"Set Pen Width"), tr(
"Width:"),
penWidth(), 1, 99, 1, &ok);
224 QPainter painter(&
map_);
234 color.setRgb(178,178,178);
238 color.setRgb(89,89,89);
240 painter.setPen(QPen(color,
myPenWidth_, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
cv::Mat getModifiedMap() const
EditMapArea(QWidget *parent=0)
GLM_FUNC_DECL genType e()
void setMap(const cv::Mat &map)
void drawLineTo(const QPoint &endPoint)
virtual void contextMenuEvent(QContextMenuEvent *e)
#define UASSERT(condition)
QImage uCvMat2QImage(const cv::Mat &image, bool isBgr=true, uCvQtDepthColorMap colorMap=uCvQtDepthWhiteToBlack)
void setPenWidth(int newWidth)
virtual void paintEvent(QPaintEvent *event)
void computeScaleOffsets(const QRect &targetRect, float &scale, float &offsetX, float &offsetY) const
virtual void mousePressEvent(QMouseEvent *event)
virtual void mouseMoveEvent(QMouseEvent *event)
ULogger class and convenient macros.
virtual void resizeEvent(QResizeEvent *event)
virtual void mouseReleaseEvent(QMouseEvent *event)