File indexing completed on 2024-05-12 04:46:01
0001 #include "patharrowbackground.h" 0002 0003 #include <QPainter> 0004 #include <QBrush> 0005 0006 PathArrowBackground::PathArrowBackground(QQuickItem *parent) 0007 : QQuickPaintedItem(parent) 0008 , m_color(Qt::white) 0009 , m_arrowWidth(16) 0010 { 0011 connect(this, SIGNAL(colorChanged()), this, SLOT(update())); 0012 connect(this, SIGNAL(arrowWidthChanged()), this, SLOT(update())); 0013 } 0014 0015 void PathArrowBackground::paint(QPainter *painter) 0016 { 0017 QBrush brush(m_color); 0018 0019 painter->setBrush(brush); 0020 painter->setPen(Qt::NoPen); 0021 painter->setRenderHint(QPainter::Antialiasing); 0022 0023 const QPointF topLeftPoints[3] = { 0024 QPointF(boundingRect().left() - 1, 0), 0025 QPointF(boundingRect().left() + m_arrowWidth, 0), 0026 QPointF(boundingRect().left() + m_arrowWidth, boundingRect().top() + boundingRect().height() * 0.5) 0027 }; 0028 0029 const QPointF bottomLeftPoints[3] = { 0030 QPointF(boundingRect().left() - 1, boundingRect().bottom()), 0031 QPointF(boundingRect().left() + m_arrowWidth, boundingRect().bottom()), 0032 QPointF(boundingRect().left() + m_arrowWidth, boundingRect().top() + boundingRect().height() * 0.5) 0033 }; 0034 0035 const QPointF rightPoints[3] = { 0036 QPointF(boundingRect().right() - m_arrowWidth - 1, 0), 0037 QPointF(boundingRect().right(), boundingRect().top() + boundingRect().height() * 0.5), 0038 QPointF(boundingRect().right() - m_arrowWidth - 1, boundingRect().bottom()), 0039 }; 0040 0041 painter->drawConvexPolygon(topLeftPoints, 3); 0042 painter->drawConvexPolygon(bottomLeftPoints, 3); 0043 painter->drawConvexPolygon(rightPoints, 3); 0044 0045 painter->drawRect(m_arrowWidth, 0, boundingRect().width() - m_arrowWidth * 2, boundingRect().height()); 0046 } 0047