#include "VRichRingItem.h" VRichRingItem::VRichRingItem(double xc, double yc, double r, double projX, double projY, double lineWidth, double hitSize) { fCenterX = xc; fCenterY = yc; setPos(fCenterX, fCenterY); fRadius = r; fProjX = projX; fProjY = projY; fLineWidth = lineWidth; fHitSize = hitSize; fVisibleStyle = false; SetVisibleStyle(false); setAcceptsHoverEvents ( true ); } QRectF VRichRingItem::boundingRect() const { double adjust = 0.5; return QRectF(-fRadius - adjust, -fRadius - adjust, 2.*(fRadius + adjust), 2.*(fRadius + adjust)); } void VRichRingItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) { ///Draw ring QRectF rect(-fRadius,-fRadius, 2 * fRadius, 2 * fRadius); painter->setPen( QPen(Qt::darkRed, fLineWidth, fPenStyle) ); painter->drawEllipse(rect); if (fProjX != 0. && fProjY != 0.){ ///Draw Line between Ring center and projection QLineF line(fProjX - fCenterX, fProjY - fCenterY, fCenterX - fCenterX, fCenterY - fCenterY); painter->setPen(QPen(Qt::darkCyan, fLineWidth, fPenStyle)); painter->drawLine(line); ///Draw Projection painter->setPen( QPen(Qt::magenta, 0.01, fPenStyle) ); painter->setBrush( QBrush(Qt::magenta, fBrushStyle) ); rect.setRect(fProjX - fCenterX - fHitSize/2., fProjY - fCenterY- fHitSize/2., fHitSize, fHitSize); painter->drawEllipse(rect); } ///Draw Hits for (unsigned int iHit = 0; iHit < fHitsAr.size(); iHit++){ rect.setRect(fHitsAr[iHit].first - fCenterX- fHitSize/2., fHitsAr[iHit].second - fCenterY - fHitSize/2., fHitSize, fHitSize); painter->setPen(QPen(Qt::darkBlue, 0.5, fPenStyle)); painter->setBrush(QBrush(Qt::darkBlue, fBrushStyle) ); painter->drawEllipse(rect); } } void VRichRingItem::AddHit(double x, double y) { QPair pair; pair.first = x; pair.second = y; fHitsAr.push_back(pair); } void VRichRingItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) { QGraphicsItem::mouseDoubleClickEvent(event); //setVisible(true); qDebug() << "mouseDoubleClickEvent"; } void VRichRingItem::mouseMoveEvent(QGraphicsSceneMouseEvent* event) { QGraphicsItem::mouseMoveEvent(event); /// setVisible(true); qDebug() << "RichRingItem mouse move Event"; } void VRichRingItem::mousePressEvent(QGraphicsSceneMouseEvent* event) { QGraphicsItem::mousePressEvent(event); qDebug() << "mouse Press Event"; } bool VRichRingItem::sceneEvent(QEvent* event) { if (event->type() == QEvent::GraphicsSceneHoverEnter){ // qDebug() << rand()<< "hover Enter event"; SetVisibleStyle(true); } if (event->type() == QEvent::GraphicsSceneHoverLeave){ // qDebug() << rand()<< "hover leave event"; SetVisibleStyle(false); } // if (event->type() == QEvent::GraphicsSceneMousePress){ // SetVisibleStyle(!fVisibleStyle); // } //if ( ((QGraphicsSceneMouseEvent*)event)->button() != Qt::LeftButton){ // qDebug() << rand()<< "lalala"; //} // if (event->type() == QEvent::GraphicsSceneMouseMove){ // qDebug() << rand()<< "mouse move event"; // } return true; } void VRichRingItem::SetVisibleStyle(bool isVisible) { fVisibleStyle = isVisible; if(isVisible){ fPenStyle = Qt::SolidLine; fBrushStyle = Qt::SolidPattern; }else { fPenStyle = Qt::NoPen; fBrushStyle = Qt::NoBrush; } update(); }