Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "rtabmap/gui/KeypointItem.h"
00029
00030 #include <QtGui/QPen>
00031 #include <QtGui/QBrush>
00032 #include <QGraphicsScene>
00033 #include "rtabmap/utilite/ULogger.h"
00034
00035 namespace rtabmap {
00036
00037 KeypointItem::KeypointItem(int id, const cv::KeyPoint & kpt, float depth, const QColor & color, QGraphicsItem * parent) :
00038 QGraphicsEllipseItem(kpt.pt.x-(kpt.size==0?3.0f:kpt.size)/2.0f, kpt.pt.y-(kpt.size==0?3.0f:kpt.size)/2.0f, kpt.size==0?3.0f:kpt.size, kpt.size==0?3.0f:kpt.size, parent),
00039 _id(id),
00040 _kpt(kpt),
00041 _placeHolder(0),
00042 _depth(depth)
00043 {
00044 this->setColor(color);
00045 this->setAcceptHoverEvents(true);
00046 this->setFlag(QGraphicsItem::ItemIsFocusable, true);
00047 _width = pen().width();
00048 }
00049
00050 KeypointItem::~KeypointItem()
00051 {
00052 if(_placeHolder)
00053 {
00054 delete _placeHolder;
00055 }
00056 }
00057
00058 void KeypointItem::setColor(const QColor & color)
00059 {
00060 this->setPen(QPen(color));
00061 this->setBrush(QBrush(color));
00062 }
00063
00064 void KeypointItem::showDescription()
00065 {
00066 if(!_placeHolder)
00067 {
00068 _placeHolder = new QGraphicsRectItem (this);
00069 _placeHolder->setVisible(false);
00070 _placeHolder->setBrush(QBrush(QColor ( 0, 0, 0, 170 )));
00071 QGraphicsTextItem * text = new QGraphicsTextItem(_placeHolder);
00072 text->setDefaultTextColor(this->pen().color().rgb());
00073 if(_depth <= 0)
00074 {
00075 text->setPlainText(QString( "Id = %1\n"
00076 "Dir = %3\n"
00077 "Hessian = %4\n"
00078 "X = %5\n"
00079 "Y = %6\n"
00080 "Size = %7\n"
00081 "Octave = %8").arg(_id).arg(_kpt.angle).arg(_kpt.response).arg(_kpt.pt.x).arg(_kpt.pt.y).arg(_kpt.size).arg(_kpt.octave));
00082 }
00083 else
00084 {
00085 text->setPlainText(QString( "Id = %1\n"
00086 "Dir = %3\n"
00087 "Hessian = %4\n"
00088 "X = %5\n"
00089 "Y = %6\n"
00090 "Size = %7\n"
00091 "Octave = %8\n"
00092 "Depth = %9 m").arg(_id).arg(_kpt.angle).arg(_kpt.response).arg(_kpt.pt.x).arg(_kpt.pt.y).arg(_kpt.size).arg(_kpt.octave).arg(_depth));
00093 }
00094 _placeHolder->setRect(text->boundingRect());
00095 }
00096
00097
00098 if(_placeHolder->parentItem())
00099 {
00100 _placeHolder->setParentItem(0);
00101 }
00102 QPen pen = this->pen();
00103 this->setPen(QPen(pen.color(), _width+2));
00104 _placeHolder->setZValue(this->zValue()+1);
00105 _placeHolder->setPos(this->mapFromScene(0,0));
00106 _placeHolder->setVisible(true);
00107 }
00108
00109 void KeypointItem::hideDescription()
00110 {
00111 if(_placeHolder)
00112 {
00113 _placeHolder->setVisible(false);
00114 }
00115 this->setPen(QPen(pen().color(), _width));
00116 }
00117
00118 void KeypointItem::hoverEnterEvent ( QGraphicsSceneHoverEvent * event )
00119 {
00120 QGraphicsScene * scene = this->scene();
00121 if(scene && scene->focusItem() == 0)
00122 {
00123 this->showDescription();
00124 }
00125 else
00126 {
00127 this->setPen(QPen(pen().color(), _width+2));
00128 }
00129 QGraphicsEllipseItem::hoverEnterEvent(event);
00130 }
00131
00132 void KeypointItem::hoverLeaveEvent ( QGraphicsSceneHoverEvent * event )
00133 {
00134 if(!this->hasFocus())
00135 {
00136 this->hideDescription();
00137 }
00138 QGraphicsEllipseItem::hoverEnterEvent(event);
00139 }
00140
00141 void KeypointItem::focusInEvent ( QFocusEvent * event )
00142 {
00143 this->showDescription();
00144 QGraphicsEllipseItem::focusInEvent(event);
00145 }
00146
00147 void KeypointItem::focusOutEvent ( QFocusEvent * event )
00148 {
00149 this->hideDescription();
00150 QGraphicsEllipseItem::focusOutEvent(event);
00151 }
00152
00153 }