File indexing completed on 2024-05-12 05:40:26

0001 #include "nodeitem.h"
0002 
0003 #include "geometry/boxnode.h"
0004 
0005 #define RADIUS 10.f
0006 
0007 NodeItem::NodeItem(QQuickItem* parent) : QQuickItem(parent)
0008 {
0009     setFlag(QQuickItem::ItemHasContents, true);
0010     setAcceptedMouseButtons(static_cast<Qt::MouseButtons>(Qt::AllButtons));
0011     setFlag(ItemAcceptsInputMethod, true);
0012 }
0013 
0014 QString NodeItem::text()
0015 {
0016     return m_text;
0017 }
0018 
0019 void NodeItem::setText(const QString& text)
0020 {
0021     if(text == m_text)
0022         return;
0023     m_text= text;
0024     emit textChanged();
0025 }
0026 QColor NodeItem::color() const
0027 {
0028     return m_color;
0029 }
0030 void NodeItem::setColor(const QColor& color)
0031 {
0032     if(color == m_color)
0033         return;
0034     m_color= color;
0035     emit colorChanged();
0036 }
0037 QPointF NodeItem::position() const
0038 {
0039     return m_position;
0040 }
0041 void NodeItem::setPosition(const QPointF& position)
0042 {
0043     if(position == m_position)
0044         return;
0045     m_position= position;
0046     emit positionChanged();
0047 }
0048 
0049 QSGNode* NodeItem::updatePaintNode(QSGNode* node, UpdatePaintNodeData*)
0050 {
0051     BoxNode* boxNode= static_cast<BoxNode*>(node);
0052     if(nullptr == boxNode)
0053     {
0054         boxNode= new BoxNode();
0055         boxNode->setColor(m_color);
0056         // auto pos= boundingRect().topLeft();
0057         qDebug() << boundingRect() << m_color;
0058 
0059         boxNode->update(boundingRect() /**/, RADIUS);
0060     }
0061     return boxNode;
0062 }
0063 
0064 void NodeItem::mousePressEvent(QMouseEvent* event)
0065 {
0066     QQuickItem::mousePressEvent(event);
0067 }
0068 void NodeItem::mouseMoveEvent(QMouseEvent* event)
0069 {
0070     QQuickItem::mouseMoveEvent(event);
0071 }