Newer
Older
/***************************************************************
QGVCore
Copyright (c) 2014, Bergont Nicolas, All rights reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
***************************************************************/
Joachim Langenbach
committed
#include <QGVCore.h>
Joachim Langenbach
committed
#include <QGVGraphPrivate.h>
#include <QGVEdgePrivate.h>
QGVEdge::QGVEdge(QGVEdgePrivate *edge, QGVScene *scene) : _scene(scene), _edge(edge)
Joachim Langenbach
committed
delete _edge;
return _path.boundingRect() | _head_arrow.boundingRect() | _tail_arrow.boundingRect() | _label_rect;
}
QPainterPath QGVEdge::shape() const
{
QPainterPathStroker ps;
ps.setCapStyle(_pen.capStyle());
ps.setWidth(_pen.widthF() + 10);
ps.setJoinStyle(_pen.joinStyle());
ps.setMiterLimit(_pen.miterLimit());
return ps.createStroke(_path);
}
void QGVEdge::setLabel(const QString &label)
{
setAttribute("xlabel", label);
}
void QGVEdge::paint(QPainter * painter, const QStyleOptionGraphicsItem *, QWidget *)
{
QPen tpen(_pen);
tpen.setColor(_pen.color().darker(120));
tpen.setStyle(Qt::DotLine);
painter->setPen(tpen);
}
/*
QRectF pp = _path.controlPointRect();
if(pp.width() < pp.height())
{
painter->save();
painter->translate(_label_rect.topLeft());
painter->rotate(90);
painter->drawText(QRectF(QPointF(0, -_label_rect.width()), _label_rect.size()), Qt::AlignCenter, _label);
painter->restore();
}
else
*/
painter->drawText(_label_rect, Qt::AlignCenter, _label);
// painter->setBrush(QBrush(_pen.color(), Qt::SolidPattern));
painter->drawPolygon(_head_arrow);
painter->drawPolygon(_tail_arrow);
painter->restore();
}
void QGVEdge::setAttribute(const QString &name, const QString &value)
{
char empty[] = "";
agsafeset(_edge->edge(), name.toLocal8Bit().data(), value.toLocal8Bit().data(), empty);
QString QGVEdge::getAttribute(const QString &name) const
{
Joachim Langenbach
committed
char* value = agget(_edge->edge(), name.toLocal8Bit().data());
if(value)
return value;
return QString();
}
Joachim Langenbach
committed
qreal gheight = QGVCore::graphHeight(_scene->_graph->graph());
Joachim Langenbach
committed
const splines* spl = ED_spl(_edge->edge());
if((spl->list != 0) && (spl->list->size%3 == 1))
{
if(spl->list->sflag)
{
_tail_arrow = toArrow(QLineF(QGVCore::toPoint(spl->list->list[0], gheight), QGVCore::toPoint(spl->list->sp, gheight)));
{
_head_arrow = toArrow(QLineF(QGVCore::toPoint(spl->list->list[spl->list->size-1], gheight), QGVCore::toPoint(spl->list->ep, gheight)));
}
}
_pen.setWidth(QGVCore::toPenWidth(getAttribute("penwidth")));
_pen.setColor(QGVCore::toColor(getAttribute("color")));
_pen.setStyle(QGVCore::toPenStyle(getAttribute("style")));
Joachim Langenbach
committed
textlabel_t *xlabel = ED_xlabel(_edge->edge());
if(xlabel)
{
_label = xlabel->text;
_label_rect.setSize(QSize(xlabel->dimen.x, xlabel->dimen.y));
Joachim Langenbach
committed
_label_rect.moveCenter(QGVCore::toPoint(xlabel->pos, QGVCore::graphHeight(_scene->_graph->graph())));
QPolygonF QGVEdge::toArrow(const QLineF &line) const
{
QLineF n = line.normalVector();
QPointF o(n.dx() / 3.0, n.dy() / 3.0);
//Only support normal arrow type
QPolygonF polygon;
polygon.append(line.p1() + o);
polygon.append(line.p2());
polygon.append(line.p1() - o);