File indexing completed on 2024-05-12 16:30:46
0001 /* This file is part of the KDE project 0002 * Copyright (C) 2008 Jan Hambrecht <jaham@gmx.net> 0003 * 0004 * This library is free software; you can redistribute it and/or 0005 * modify it under the terms of the GNU Library General Public 0006 * License as published by the Free Software Foundation; either 0007 * version 2 of the License, or (at your option) any later version. 0008 * 0009 * This library is distributed in the hope that it will be useful, 0010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 * Library General Public License for more details. 0013 * 0014 * You should have received a copy of the GNU Library General Public License 0015 * along with this library; see the file COPYING.LIB. If not, write to 0016 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 * Boston, MA 02110-1301, USA. 0018 */ 0019 0020 #include "KarbonOutlinePaintingStrategy.h" 0021 0022 #include <KoShapeManager.h> 0023 #include <KoShape.h> 0024 #include <KoShapeStroke.h> 0025 0026 #include <QPen> 0027 #include <QPainter> 0028 #include <QPainterPath> 0029 0030 class OutlineStroke : public KoShapeStroke { 0031 public: 0032 OutlineStroke() 0033 : m_pen(Qt::black) { 0034 } 0035 0036 using KoShapeStroke::paint; 0037 0038 void paint(KoShape *shape, QPainter &painter, const KoViewConverter &converter) override 0039 { 0040 KoShape::applyConversion(painter, converter); 0041 painter.strokePath(shape->outline(), m_pen); 0042 } 0043 0044 private: 0045 QPen m_pen; 0046 }; 0047 0048 KarbonOutlinePaintingStrategy::KarbonOutlinePaintingStrategy(KoShapeManager * shapeManager) 0049 : KoShapeManagerPaintingStrategy(shapeManager), m_stroke(new OutlineStroke()) 0050 { 0051 Q_ASSERT(shapeManager); 0052 shapeManager->setPaintingStrategy(this); 0053 } 0054 0055 KarbonOutlinePaintingStrategy::~KarbonOutlinePaintingStrategy() 0056 { 0057 delete m_stroke; 0058 } 0059 0060 void KarbonOutlinePaintingStrategy::paint(KoShape * shape, QPainter &painter, const KoViewConverter &converter, KoShapePaintingContext &/*paintContext*/) 0061 { 0062 painter.save(); 0063 painter.setTransform(shape->absoluteTransformation(&converter) * painter.transform()); 0064 0065 m_stroke->paint(shape, painter, converter); 0066 0067 painter.restore(); 0068 }