File indexing completed on 2024-05-26 04:38:37

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 "AbstractArrow.h"
0021 
0022 #include <tikz/core/Style.h>
0023 
0024 #include <QObject>
0025 #include <QPainterPathStroker>
0026 
0027 class AbstractArrowPrivate
0028 {
0029     public:
0030         tikz::core::Style* style;
0031 };
0032 
0033 AbstractArrow::AbstractArrow(tikz::core::Style* style)
0034     : d(new AbstractArrowPrivate())
0035 {
0036     d->style = style;
0037 }
0038 
0039 AbstractArrow::~AbstractArrow()
0040 {
0041     delete d;
0042 }
0043 
0044 tikz::core::Style* AbstractArrow::style() const
0045 {
0046     return d->style;
0047 }
0048 
0049 tikz::Arrow AbstractArrow::type() const
0050 {
0051     return tikz::Arrow::NoArrow;
0052 }
0053 
0054 QString AbstractArrow::name() const
0055 {
0056     return QObject::tr("none");
0057 }
0058 
0059 qreal AbstractArrow::leftExtend() const
0060 {
0061     return 0.0;
0062 }
0063 
0064 qreal AbstractArrow::rightExtend() const
0065 {
0066     return 0.0;
0067 }
0068 
0069 void AbstractArrow::draw(QPainter* painter) const
0070 {
0071     Q_UNUSED(painter);
0072 }
0073 
0074 QPainterPath AbstractArrow::path() const
0075 {
0076     return QPainterPath();
0077 }
0078 
0079 QPainterPath AbstractArrow::contour(qreal width) const
0080 {
0081     QPainterPath arrowPath = path();
0082 
0083     // if path is empty, return immediately
0084     if (arrowPath.isEmpty()) {
0085         return QPainterPath();
0086     }
0087 
0088     QPainterPathStroker stroker;
0089     stroker.setJoinStyle(Qt::RoundJoin);
0090     stroker.setCapStyle(Qt::RoundCap);
0091     stroker.setWidth(width + style()->penWidth().toPoint());
0092 
0093     return stroker.createStroke(arrowPath);
0094 }
0095 
0096 #include "ToArrow.h"
0097 #include "StealthArrow.h"
0098 #include "LatexArrow.h"
0099 #include "PipeArrow.h"
0100 #include "StealthTickArrow.h"
0101 
0102 AbstractArrow *createArrow(tikz::Arrow type, tikz::core::Style* style)
0103 {
0104     switch (type) {
0105         case tikz::Arrow::NoArrow: return new AbstractArrow(style);
0106         case tikz::Arrow::ToArrow: return new ToArrow(style);
0107         case tikz::Arrow::ReversedToArrow: return new ReversedToArrow(style);
0108         case tikz::Arrow::StealthArrow: return new StealthArrow(style);
0109         case tikz::Arrow::ReversedStealthArrow: return new ReversedStealthArrow(style);
0110         case tikz::Arrow::LatexArrow: return new LatexArrow(style);
0111         case tikz::Arrow::ReversedLatexArrow: return new ReversedLatexArrow(style);
0112         case tikz::Arrow::PipeArrow: return new PipeArrow(style);
0113         case tikz::Arrow::StealthTickArrow: return new StealthTickArrow(style);
0114         case tikz::Arrow::ReversedStealthTickArrow: return new ReversedStealthTickArrow(style);
0115         default: break;
0116     }
0117     return new AbstractArrow(style);
0118 }
0119 
0120 // kate: indent-width 4; replace-tabs on;