File indexing completed on 2024-05-19 04:36:33

0001 /* This file is part of the TikZKit project.
0002  *
0003  * Copyright (C) 2013 Dominik Haumann <dhaumann@kde.org>
0004  *
0005  * This library is free software; you can redistribute it and/or modify
0006  * it under the terms of the GNU Library General Public License as published
0007  * by the Free Software Foundation, either version 2 of the License, or
0008  * (at your option) any later version.
0009  *
0010  * This library is distributed in the hope that it will be useful,
0011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013  * GNU Library General Public License for more details.
0014  *
0015  * You should have received a copy of the GNU Library General Public License
0016  * along with this library; see the file COPYING.LIB.  If not, see
0017  * <http://www.gnu.org/licenses/>.
0018  */
0019 
0020 #include "PipeArrow.h"
0021 
0022 #include <tikz/core/Style.h>
0023 
0024 #include <QPainter>
0025 
0026 #include <cmath>
0027 
0028 class PipeArrowPrivate
0029 {
0030     public:
0031 };
0032 
0033 PipeArrow::PipeArrow(tikz::core::Style * style)
0034     : AbstractArrow(style)
0035     , d(new PipeArrowPrivate())
0036 {
0037 }
0038 
0039 PipeArrow::~PipeArrow()
0040 {
0041     delete d;
0042 }
0043 
0044 tikz::Arrow PipeArrow::type() const
0045 {
0046     return tikz::Arrow::PipeArrow;
0047 }
0048 
0049 QString PipeArrow::name() const
0050 {
0051     return QObject::tr("|");
0052 }
0053 
0054 qreal PipeArrow::leftExtend() const
0055 {
0056     // see: pgfcorearrows.code.tex
0057     return -0.25 * style()->penWidth().toPoint();
0058 }
0059 
0060 qreal PipeArrow::rightExtend() const
0061 {
0062     // see: pgfcorearrows.code.tex
0063     return 0.75 * style()->penWidth().toPoint();
0064 }
0065 
0066 void PipeArrow::draw(QPainter* painter) const
0067 {
0068     // see: pgfcorearrows.code.tex
0069     QPainterPath p = path();
0070     painter->save();
0071     QPen pen = painter->pen();
0072     pen.setWidthF(style()->penWidth().toPoint());
0073     pen.setColor(style()->penColor());
0074     pen.setCapStyle(Qt::SquareCap);
0075     painter->setPen(pen);
0076     painter->setBrush(Qt::NoBrush);
0077     painter->drawPath(p);
0078     painter->restore();
0079 }
0080 
0081 QPainterPath PipeArrow::path() const
0082 {
0083     // see: pgfcorearrows.code.tex
0084     const qreal lineWidth = style()->penWidth().toPoint();
0085     const qreal dima = 2 + 1.5 * lineWidth;
0086     QPainterPath path;
0087     path.moveTo(QPointF(0.25 * lineWidth, -dima));
0088     path.lineTo(QPointF(0.25 * lineWidth,  dima));
0089 
0090     return path;
0091 }
0092 
0093 QPainterPath PipeArrow::contour(qreal width) const
0094 {
0095     QPainterPathStroker stroker;
0096     stroker.setJoinStyle(Qt::RoundJoin);
0097     stroker.setCapStyle(Qt::SquareCap);
0098     stroker.setWidth(width + style()->penWidth().toPoint());
0099 
0100     return stroker.createStroke(path());
0101 }
0102 
0103 
0104 // kate: indent-width 4; replace-tabs on;