File indexing completed on 2024-05-12 15:56:09

0001 /*
0002  *  SPDX-FileCopyrightText: 2005 Bart Coppens <kde@bartcoppens.be>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #include "kis_boundary.h"
0008 #include <QPainter>
0009 #include <QPainterPath>
0010 #include <QPen>
0011 
0012 #include "KoColorSpace.h"
0013 #include "kis_fixed_paint_device.h"
0014 #include "kis_outline_generator.h"
0015 
0016 struct KisBoundary::Private {
0017     KisFixedPaintDeviceSP m_device;
0018     QVector<QPolygon> m_boundary;
0019     QPainterPath path;
0020 };
0021 
0022 KisBoundary::KisBoundary(KisFixedPaintDeviceSP dev) : d(new Private)
0023 {
0024     d->m_device = dev;
0025 }
0026 
0027 KisBoundary::~KisBoundary()
0028 {
0029     delete d;
0030 }
0031 
0032 void KisBoundary::generateBoundary()
0033 {
0034     if (!d->m_device)
0035         return;
0036 
0037     KisOutlineGenerator generator(d->m_device->colorSpace(), OPACITY_TRANSPARENT_U8);
0038     generator.setSimpleOutline(true);
0039     d->m_boundary = generator.outline(d->m_device->data(), 0, 0, d->m_device->bounds().width(), d->m_device->bounds().height());
0040 
0041     d->path = QPainterPath();
0042     Q_FOREACH (const QPolygon & polygon, d->m_boundary) {
0043         d->path.addPolygon(polygon);
0044         d->path.closeSubpath();
0045     }
0046 
0047 }
0048 
0049 void KisBoundary::paint(QPainter& painter) const
0050 {
0051     QPen pen;
0052     pen.setWidth(0);
0053     pen.setBrush(Qt::black);
0054     painter.setPen(pen);
0055 
0056     Q_FOREACH (const QPolygon & polygon, d->m_boundary) {
0057         painter.drawPolygon(polygon);
0058     }
0059 }
0060 
0061 QPainterPath KisBoundary::path() const
0062 {
0063     return d->path;
0064 }
0065