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 "shape.hpp"
0010 
0011 #include "model/assets/assets.hpp"
0012 #include "model/property/reference_property.hpp"
0013 
0014 namespace glaxnimate::model {
0015 
0016 /**
0017  * \brief Base class for elements that add a style
0018  */
0019 class Styler : public ShapeOperator
0020 {
0021     Q_OBJECT
0022 
0023     GLAXNIMATE_ANIMATABLE(QColor, color, QColor())
0024     GLAXNIMATE_ANIMATABLE(float, opacity, 1, {}, 0, 1, false, PropertyTraits::Percent)
0025     GLAXNIMATE_PROPERTY_REFERENCE(BrushStyle, use, &Styler::valid_uses, &Styler::is_valid_use, &Styler::on_use_changed)
0026 
0027 public:
0028     using ShapeOperator::ShapeOperator;
0029 
0030     void add_shapes(FrameTime, math::bezier::MultiBezier&, const QTransform&) const override {}
0031 
0032 protected:
0033     QBrush brush(FrameTime t) const;
0034 
0035 private:
0036     std::vector<DocumentNode*> valid_uses() const;
0037 
0038     bool is_valid_use(DocumentNode* node) const;
0039 
0040     void on_use_changed(BrushStyle* new_use, BrushStyle* old_use);
0041 
0042     void on_update_style();
0043 
0044 Q_SIGNALS:
0045     void use_changed(BrushStyle* new_use);
0046     void use_changed_from(BrushStyle* old_use, BrushStyle* new_use);
0047 };
0048 
0049 } // namespace glaxnimate::model