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 "StealthTickArrow.h" 0021 0022 #include <tikz/core/Style.h> 0023 0024 #include <QPainter> 0025 0026 #include <cmath> 0027 0028 class StealthTickArrowPrivate 0029 { 0030 public: 0031 }; 0032 0033 StealthTickArrow::StealthTickArrow(tikz::core::Style * style) 0034 : AbstractArrow(style) 0035 , d(new StealthTickArrowPrivate()) 0036 { 0037 } 0038 0039 StealthTickArrow::~StealthTickArrow() 0040 { 0041 delete d; 0042 } 0043 0044 tikz::Arrow StealthTickArrow::type() const 0045 { 0046 return tikz::Arrow::StealthTickArrow; 0047 } 0048 0049 QString StealthTickArrow::name() const 0050 { 0051 return QObject::tr("stealth'"); 0052 } 0053 0054 qreal StealthTickArrow::leftExtend() const 0055 { 0056 // see: pgfcorearrows.code.tex 0057 const qreal lineWidth = style()->penWidth().toPoint(); 0058 const qreal dima = 0.28 + 0.3 * lineWidth; 0059 const qreal dimb = 6 * dima + 0.5 * lineWidth; 0060 return -dimb; 0061 } 0062 0063 qreal StealthTickArrow::rightExtend() const 0064 { 0065 // see: pgfcorearrows.code.tex 0066 const qreal lineWidth = style()->penWidth().toPoint(); 0067 const qreal dima = 0.28 + 0.3 * lineWidth; 0068 const qreal dimb = 2 * dima + 0.5 * lineWidth; 0069 return dimb; 0070 } 0071 0072 void StealthTickArrow::draw(QPainter* painter) const 0073 { 0074 // see: pgfcorearrows.code.tex 0075 QPainterPath p = path(); 0076 painter->save(); 0077 QPen pen = painter->pen(); 0078 pen.setWidthF(style()->penWidth().toPoint()); 0079 pen.setColor(style()->penColor()); 0080 pen.setJoinStyle(Qt::RoundJoin); 0081 painter->setPen(pen); 0082 painter->setBrush(Qt::black); // TODO 0083 painter->drawPath(p); 0084 painter->restore(); 0085 } 0086 0087 QPainterPath StealthTickArrow::path() const 0088 { 0089 // see: pgfcorearrows.code.tex 0090 qreal dima = 0.28 + 0.3 * style()->penWidth().toPoint(); 0091 0092 QPainterPath path; 0093 path.moveTo(dima * QPointF(2, 0)); 0094 path.cubicTo(dima * QPointF(-0.5, 0.5), 0095 dima * QPointF(-3, 1.5), 0096 dima * QPointF(-6, 3.25)); 0097 path.cubicTo(dima * QPointF(-3, 1), 0098 dima * QPointF(-3, -1), 0099 dima * QPointF(-6, -3.25)); 0100 path.cubicTo(dima * QPointF(-3, -1.5), 0101 dima * QPointF(-0.5, -0.5), 0102 dima * QPointF(2, 0)); 0103 path.closeSubpath(); 0104 0105 return path; 0106 } 0107 0108 0109 0110 ReversedStealthTickArrow::ReversedStealthTickArrow(tikz::core::Style * style) 0111 : StealthTickArrow(style) 0112 { 0113 } 0114 0115 tikz::Arrow ReversedStealthTickArrow::type() const 0116 { 0117 return tikz::Arrow::ReversedStealthTickArrow; 0118 } 0119 0120 QString ReversedStealthTickArrow::name() const 0121 { 0122 return QObject::tr("stealth' reversed"); 0123 } 0124 0125 qreal ReversedStealthTickArrow::leftExtend() const 0126 { 0127 return -StealthTickArrow::rightExtend(); 0128 } 0129 0130 qreal ReversedStealthTickArrow::rightExtend() const 0131 { 0132 return -StealthTickArrow::leftExtend(); 0133 } 0134 0135 QPainterPath ReversedStealthTickArrow::path() const 0136 { 0137 QTransform trans; 0138 trans.scale(-1, 1); 0139 return trans.map(StealthTickArrow::path()); 0140 } 0141 // kate: indent-width 4; replace-tabs on;