void Wire::rebuild(const QPointF& s, const QPointF& e)
{
//QList<QLineF*> m_lines is member variable
if(!m_lines.isEmpty())
{
qDeleteAll(m_lines);
m_lines.clear();
}
if(st.x() == en.x() || st.y() == en.y())
{
m_lines.
append(new QLineF(st,en
));
prepareGeometryChange();
return;
}
m_lines.
append(new QLineF(st,inter
));
m_lines.
append(new QLineF(inter,en
));
prepareGeometryChange();
}
QRectF Wire
::rectForLine(const QLineF
& line
) const {
qreal x = qMin(line.p1().x() , line.p2().x());
qreal y = qMin(line.p1().y() , line.p2().y());
qreal w = qAbs(line.p1().x() - line.p2().x());
if(w < 1.0)
w = 1.0;
qreal h = qAbs(line.p1().y() - line.p2().y());
if(h < 1.0)
h = 1.0;
}
QRectF Wire
::boundingRect() const {
foreach
(QLineF* line, m_lines
) rect |= rectForLine(*line);
return rect.adjusted(-1.0,-1.0,1.0,1.0);
}
{
if(m_lines.isEmpty())
return path;
foreach
(QLineF *line, m_lines
) path.addRect(rectForLine(*line));
return path;
}
void Wire::rebuild(const QPointF& s, const QPointF& e)
{
//QList<QLineF*> m_lines is member variable
if(!m_lines.isEmpty())
{
qDeleteAll(m_lines);
m_lines.clear();
}
QPointF st = mapFromScene(s);
QPointF en = mapFromScene(e);
if(st.x() == en.x() || st.y() == en.y())
{
m_lines.append(new QLineF(st,en));
prepareGeometryChange();
return;
}
QPointF inter = QPointF(st.x(),en.y());
m_lines.append(new QLineF(st,inter));
m_lines.append(new QLineF(inter,en));
prepareGeometryChange();
}
QRectF Wire::rectForLine(const QLineF& line) const
{
qreal x = qMin(line.p1().x() , line.p2().x());
qreal y = qMin(line.p1().y() , line.p2().y());
qreal w = qAbs(line.p1().x() - line.p2().x());
if(w < 1.0)
w = 1.0;
qreal h = qAbs(line.p1().y() - line.p2().y());
if(h < 1.0)
h = 1.0;
return QRectF(x,y,w,h);
}
QRectF Wire::boundingRect() const
{
QRectF rect(0.0,0.0,0.0,0.0);
foreach(QLineF* line, m_lines)
rect |= rectForLine(*line);
return rect.adjusted(-1.0,-1.0,1.0,1.0);
}
QPainterPath Wire::shape() const
{
QPainterPath path;
if(m_lines.isEmpty())
return path;
foreach(QLineF *line, m_lines)
path.addRect(rectForLine(*line));
return path;
}
To copy to clipboard, switch view to plain text mode
Bookmarks