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 "LatexArrow.h"
0021 
0022 #include <tikz/core/Style.h>
0023 
0024 #include <QPainter>
0025 
0026 #include <cmath>
0027 
0028 class LatexArrowPrivate
0029 {
0030     public:
0031 };
0032 
0033 LatexArrow::LatexArrow(tikz::core::Style * style)
0034     : AbstractArrow(style)
0035     , d(new LatexArrowPrivate())
0036 {
0037 }
0038 
0039 LatexArrow::~LatexArrow()
0040 {
0041     delete d;
0042 }
0043 
0044 tikz::Arrow LatexArrow::type() const
0045 {
0046     return tikz::Arrow::LatexArrow;
0047 }
0048 
0049 QString LatexArrow::name() const
0050 {
0051     return QObject::tr("latex");
0052 }
0053 
0054 qreal LatexArrow::leftExtend() const
0055 {
0056     // see: pgfcorearrows.code.tex
0057     tikz::Value dima(0.28);
0058     tikz::Value dimb = style()->penWidth();
0059     if (style()->innerLineWidth() > 0.0) {
0060         dimb = 0.6 * dimb - 0.4 * style()->innerLineWidth();
0061     }
0062     dima += 0.3 * dimb;
0063     return -1 * dima.toPoint();
0064 }
0065 
0066 qreal LatexArrow::rightExtend() const
0067 {
0068     // see: pgfcorearrows.code.tex
0069     tikz::Value dima(0.28);
0070     tikz::Value dimb = style()->penWidth();
0071         if (style()->innerLineWidth() > 0.0) {
0072         dimb = 0.6 * dimb - 0.4 * style()->innerLineWidth();
0073     }
0074     dima += 0.3 * dimb;
0075     return 9 * dima.toPoint();
0076 }
0077 
0078 void LatexArrow::draw(QPainter* painter) const
0079 {
0080     // see: pgfcorearrows.code.tex
0081     QPainterPath p = path();
0082     painter->save();
0083 
0084     painter->fillPath(p, style()->penColor());
0085     painter->restore();
0086 }
0087 
0088 QPainterPath LatexArrow::path() const
0089 {
0090     // see: pgfcorearrows.code.tex
0091     qreal dima = tikz::Value(0.28).toPoint();
0092     qreal dimb = style()->penWidth().toPoint();
0093     if (style()->innerLineWidth() > 0.0) {
0094         dimb = 0.6 * dimb - 0.4 * style()->innerLineWidth().toPoint();
0095     }
0096     dima += 0.3 * dimb;
0097 
0098     QPainterPath path;
0099     path.moveTo(dima * QPointF(9,  0));
0100     path.cubicTo(dima * QPointF(6.3333, 0.5),
0101                  dima * QPointF(2, 2),
0102                  dima * QPointF(-1, 3.75));
0103     path.lineTo(dima * QPointF(-1, -3.75));
0104     path.cubicTo(dima * QPointF(2, -2),
0105                  dima * QPointF(6.3333, -0.5),
0106                  dima * QPointF(9, 0));
0107     path.closeSubpath();
0108 
0109     return path;
0110 }
0111 
0112 QPainterPath LatexArrow::contour(qreal width) const
0113 {
0114     QPainterPathStroker stroker;
0115     stroker.setJoinStyle(Qt::RoundJoin);
0116     stroker.setCapStyle(Qt::RoundCap);
0117     stroker.setWidth(width);
0118 
0119     return stroker.createStroke(path());
0120 }
0121 
0122 
0123 
0124 ReversedLatexArrow::ReversedLatexArrow(tikz::core::Style * style)
0125     : LatexArrow(style)
0126 {
0127 }
0128 
0129 tikz::Arrow ReversedLatexArrow::type() const
0130 {
0131     return tikz::Arrow::ReversedLatexArrow;
0132 }
0133 
0134 QString ReversedLatexArrow::name() const
0135 {
0136     return QObject::tr("latex reversed");
0137 }
0138 
0139 qreal ReversedLatexArrow::leftExtend() const
0140 {
0141     return -LatexArrow::rightExtend();
0142 }
0143 
0144 qreal ReversedLatexArrow::rightExtend() const
0145 {
0146     return -LatexArrow::leftExtend();
0147 }
0148 
0149 QPainterPath ReversedLatexArrow::path() const
0150 {
0151     QTransform trans;
0152     trans.scale(-1, 1);
0153     return trans.map(LatexArrow::path());
0154 }
0155 
0156 // kate: indent-width 4; replace-tabs on;