File indexing completed on 2025-02-02 04:54:38

0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 // SPDX-FileCopyrightText: 2018 Kevin Ottens <ervin@kde.org>
0003 
0004 #include "strokelistitem.h"
0005 
0006 #include <QPainter>
0007 
0008 #include "sketchmodel.h"
0009 
0010 StrokeListItem::StrokeListItem(QQuickItem *parent)
0011     : QQuickPaintedItem(parent)
0012 {
0013     setAntialiasing(true);
0014     setRenderTarget(FramebufferObject);
0015 }
0016 
0017 void StrokeListItem::addStroke(const Stroke &stroke)
0018 {
0019     Q_ASSERT(m_model);
0020     Q_ASSERT(stroke.type() == m_type);
0021     m_model->addStroke(stroke);
0022     update();
0023 }
0024 
0025 void StrokeListItem::eraseArea(const QVector2D &center, float radius)
0026 {
0027     Q_ASSERT(m_model);
0028     m_model->eraseArea(m_type, center, radius);
0029     update();
0030 }
0031 
0032 void StrokeListItem::paint(QPainter *painter)
0033 {
0034     const auto strokes = m_model->strokes(m_type);
0035     for (const auto &stroke : std::as_const(strokes))
0036         m_strokepainter.render(stroke, painter);
0037 }
0038 
0039 Stroke::Type StrokeListItem::type() const
0040 {
0041     return m_type;
0042 }
0043 
0044 SketchModel *StrokeListItem::model() const
0045 {
0046     return m_model;
0047 }
0048 
0049 void StrokeListItem::setType(Stroke::Type type)
0050 {
0051     if (m_type == type)
0052         return;
0053 
0054     m_type = type;
0055     Q_EMIT typeChanged(type);
0056     update();
0057 }
0058 
0059 void StrokeListItem::setModel(SketchModel *model)
0060 {
0061     if (m_model == model)
0062         return;
0063 
0064     m_model = model;
0065     Q_EMIT modelChanged(model);
0066     update();
0067 }