Commit f5dd84b3 authored by roangel's avatar roangel
Browse files

Added markers and some other details, like measures are now real, 1m per grid unit,...

parent 21e623d0
......@@ -179,6 +179,7 @@ set(MY_LIB_SOURCES # compilation of sources
${MY_LIB_PATH_SRC}/myGraphicsScene.cpp
${MY_LIB_PATH_SRC}/myGraphicsView.cpp
${MY_LIB_PATH_SRC}/tablePiece.cpp
${MY_LIB_PATH_SRC}/marker.cpp
)
......
......@@ -24,7 +24,8 @@ SOURCES += \
src/myGraphicsRectItem.cpp \
src/myGraphicsScene.cpp \
src/myGraphicsView.cpp \
src/tablePiece.cpp
src/tablePiece.cpp \
src/marker.cpp
HEADERS += \
include/cornergrabber.h \
......@@ -34,7 +35,9 @@ HEADERS += \
include/myGraphicsRectItem.h \
include/myGraphicsScene.h \
include/myGraphicsView.h \
include/tablePiece.h
include/tablePiece.h \
include/globalDefinitions.h \
include/marker.h
FORMS += \
src/mainguiwindow.ui
#ifndef GLOBAL_DEFINITIONS_H
#define GLOBAL_DEFINITIONS_H
#define TO_METERS 100
#define TO_CENTIMETERS 1
#define TO_MILIMETERS 0.1
#endif
......@@ -7,7 +7,6 @@
#include <QGridLayout>
#include <QGraphicsRectItem>
#ifdef CATKIN_MAKE
#include "ros/callback_queue.h"
#include "ros/ros.h"
......@@ -15,6 +14,10 @@
#include "ui_mainguiwindow.h"
#include "myGraphicsScene.h"
#include "globalDefinitions.h"
#include "marker.h" // temporal, just to check
namespace Ui {
class MainGUIWindow;
......@@ -94,7 +97,6 @@ private:
Ui::MainGUIWindow *ui;
myGraphicsScene* scene;
void _init();
#ifdef CATKIN_MAKE
......
#ifndef MARKER_H
#define MARKER_H
#include "globalDefinitions.h"
#include <QGraphicsEllipseItem>
#define MARKER_DIAMETER 20 * TO_MILIMETERS
#define HIGHLIGHT_DIAMETER 20
#define HIGHLIGHT_WIDTH 5
class Marker : public QGraphicsEllipseItem
{
public:
explicit Marker(qreal x, qreal y, QGraphicsItem *parent = 0);
void setHighlighted(void);
void clearHighlighted(void);
bool getHighlighted(void);
private:
qreal _diameter;
qreal _x;
qreal _y;
bool _highlighted;
QGraphicsEllipseItem* _highlight_circle;
qreal _highlight_diameter;
qreal _x_highlight;
qreal _y_highlight;
};
#endif
......@@ -8,6 +8,8 @@
#include "crazyFlyZone.h"
#include "tablePiece.h"
#include "marker.h"
class QGraphicsSceneMouseEvent;
class QPointF;
class QColor;
......@@ -35,6 +37,10 @@ public:
QRectF getRectFCrazyFlyZone(int index);
// Y axis in QGraphicsView is inverted wrt normal axis. This functions map from one way to the other
QPointF mapFromWorldToScene(QPointF point);
QPointF mapFromSceneToWorld(QPointF point);
enum {mode_table, mode_crazyfly_zones, mode_locked};
void removeTable();
......@@ -78,6 +84,8 @@ private:
QPointF* p1;
QPointF* p2;
Marker* marker;
bool startedRect;
int mode;
bool grid_enable;
......
#include "crazyFlyZone.h"
#include "globalDefinitions.h"
crazyFlyZone::crazyFlyZone(const QRectF & rect, int index, QGraphicsItem * parent)
: myGraphicsRectItem(rect, parent)
......@@ -17,14 +18,14 @@ void crazyFlyZone::setLabel(QString string)
{
label = new QGraphicsSimpleTextItem(string, this);
label->setFlag(QGraphicsItem::ItemIgnoresTransformations);
label->setFont(QFont("Arial", 18, QFont::Bold, true));
label->setFont(QFont("Arial", 16, QFont::Bold, true));
setLabelPosition();
}
void crazyFlyZone::setLabelPosition()
{
qreal x_offset = 10;
qreal y_offset = 5;
qreal x_offset = 0.1 * TO_METERS;
qreal y_offset = 0.05 * TO_METERS;
label->setPos(this->rect().topLeft().x() + x_offset,this->rect().topLeft().y() + y_offset);
}
......
......@@ -48,10 +48,14 @@ void MainGUIWindow::set_tabs(int n)
void MainGUIWindow::_init()
{
ui->graphicsView->setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
scene = new myGraphicsScene(ui->frame_drawing);
scene->setSceneRect(QRectF(QPointF(-1400, 1400), QSizeF(1400, 1400)));
scene->setSceneRect(-100 * TO_METERS, -100 * TO_METERS, 200 * TO_METERS, 200 * TO_METERS);
// Marker* marker = new Marker(0, 0);
// scene->addItem(marker);
ui->graphicsView->setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
ui->graphicsView->setScene(scene);
QObject::connect(ui->tabWidget, SIGNAL(tabCloseRequested(int)), scene, SLOT(removeCrazyFlyZone(int)));
......
#include "marker.h"
#include <QPen>
#include <QBrush>
Marker::Marker(qreal x, qreal y, QGraphicsItem * parent)
: QGraphicsEllipseItem(parent)
{
_highlighted = false;
_highlight_diameter = HIGHLIGHT_DIAMETER;
_x_highlight = x - _highlight_diameter/2;
_y_highlight = y -_highlight_diameter/2;
_diameter = MARKER_DIAMETER; // x and y are top left coordinates
_x = x - _diameter/2;
_y = y - _diameter/2;
this->setRect(QRectF(_x, _y, _diameter, _diameter));
this->setPen(Qt::NoPen);
this->setBrush(QColor(255, 0, 0));
this->setZValue(10); // max z value, should always be seen
setHighlighted();
}
void Marker::setHighlighted(void)
{
prepareGeometryChange();
_highlight_circle = new QGraphicsEllipseItem();
_highlight_circle->setRect(QRectF(_x_highlight, _y_highlight, _highlight_diameter, _highlight_diameter));
_highlight_circle->setPen(QPen(QBrush(Qt::black), HIGHLIGHT_WIDTH));
_highlight_circle->setParentItem(this);
_highlight_circle->setFlag(QGraphicsItem::ItemIgnoresTransformations);
_highlighted = true;
}
void Marker::clearHighlighted(void)
{
prepareGeometryChange();
_highlighted = false;
}
bool Marker::getHighlighted(void)
{
return _highlighted;
}
#include "myGraphicsScene.h"
#include "globalDefinitions.h"
#include <QGraphicsSceneMouseEvent>
#include <QRect>
......@@ -14,6 +15,9 @@ myGraphicsScene::myGraphicsScene(QObject *parent)
tmp_rect = 0;
startedRect = false;
setGrid(true);
marker = new Marker(0, 0);
this->addItem(marker);
}
......@@ -95,6 +99,7 @@ void myGraphicsScene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)
{
if (mouseEvent->button() != Qt::LeftButton)
return;
qDebug("Mouse Position in world coord: %d, %d", (int)mapFromSceneToWorld((mouseEvent->scenePos()).toPoint()).x(), (int)mapFromSceneToWorld((mouseEvent->scenePos()).toPoint()).y());
if(Qt::ControlModifier == QApplication::keyboardModifiers())
{
switch(mode)
......@@ -322,7 +327,7 @@ void myGraphicsScene::drawBackground(QPainter *painter, const QRectF &rect)
if(grid_enable)
{
const int gridSize = 25;
const int gridSize = 1 * TO_METERS;
qreal left = int(rect.left()) - (int(rect.left()) % gridSize);
qreal top = int(rect.top()) - (int(rect.top()) % gridSize);
......@@ -398,3 +403,16 @@ void myGraphicsScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent)
QGraphicsScene::mouseReleaseEvent(mouseEvent);
}
QPointF myGraphicsScene::mapFromWorldToScene(QPointF point)
{
QPointF new_point(point.x(), -1 * point.y());
return new_point;
}
QPointF myGraphicsScene::mapFromSceneToWorld(QPointF point)
{
QPointF new_point(point.x(), -1 * point.y());
return new_point;
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment