File indexing completed on 2025-02-02 04:11:08

0001 /*
0002  * SPDX-FileCopyrightText: 2019-2023 Mattia Basaglia <dev@dragon.best>
0003  *
0004  * SPDX-License-Identifier: GPL-3.0-or-later
0005  */
0006 
0007 #pragma once
0008 
0009 #include <set>
0010 
0011 #include <QBrush>
0012 #include <QPainter>
0013 
0014 #include "styler.hpp"
0015 #include "model/animation/animatable.hpp"
0016 
0017 namespace glaxnimate::model {
0018 
0019 class Stroke : public StaticOverrides<Stroke, Styler>
0020 {
0021     GLAXNIMATE_OBJECT(Stroke)
0022 
0023 public:
0024     enum Cap
0025     {
0026         ButtCap = Qt::FlatCap,
0027         RoundCap = Qt::RoundCap,
0028         SquareCap = Qt::SquareCap,
0029     };
0030 
0031     enum Join
0032     {
0033         MiterJoin = Qt::MiterJoin,
0034         RoundJoin = Qt::RoundJoin,
0035         BevelJoin = Qt::BevelJoin,
0036     };
0037 
0038 private:
0039     Q_ENUM(Cap);
0040     Q_ENUM(Join);
0041 
0042     GLAXNIMATE_ANIMATABLE(float, width, 1, {}, 0)
0043     GLAXNIMATE_PROPERTY(Cap, cap, RoundCap, nullptr, nullptr, PropertyTraits::Visual)
0044     GLAXNIMATE_PROPERTY(Join, join, RoundJoin, nullptr, nullptr, PropertyTraits::Visual)
0045     GLAXNIMATE_PROPERTY(float, miter_limit, 0, nullptr, nullptr, PropertyTraits::Visual)
0046 
0047 public:
0048     using Ctor::Ctor;
0049 
0050     QRectF local_bounding_rect(FrameTime t) const override
0051     {
0052         if ( !visible.get() )
0053             return {};
0054         qreal half_width = width.get_at(t) / 2;
0055         return collect_shapes(t, {}).bounding_box().adjusted(
0056             -half_width, -half_width, half_width, half_width
0057         );
0058     }
0059 
0060 
0061     static QIcon static_tree_icon()
0062     {
0063         return QIcon::fromTheme("format-stroke-color");
0064     }
0065 
0066     static QString static_type_name_human()
0067     {
0068         return i18n("Stroke");
0069     }
0070 
0071     void set_pen_style(const QPen& p);
0072     void set_pen_style_undoable(const QPen& p);
0073 
0074 
0075 protected:
0076     QPainterPath to_painter_path_impl(FrameTime t) const override;
0077     void on_paint(QPainter* p, FrameTime t, PaintMode, model::Modifier* modifier) const override;
0078 };
0079 
0080 } // namespace glaxnimate::model
0081