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

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/transform.hpp"
0012 #include "model/property/sub_object_property.hpp"
0013 #include "utils/range.hpp"
0014 
0015 namespace glaxnimate::model {
0016 
0017 
0018 class Group : public StaticOverrides<Group, ShapeElement>
0019 {
0020     GLAXNIMATE_OBJECT(Group)
0021 
0022 public:
0023     GLAXNIMATE_PROPERTY_LIST(ShapeElement, shapes)
0024     GLAXNIMATE_SUBOBJECT(Transform, transform)
0025     GLAXNIMATE_ANIMATABLE(float, opacity, 1, &Group::opacity_changed, 0, 1, false, PropertyTraits::Percent)
0026     GLAXNIMATE_PROPERTY(bool, auto_orient, false, &Group::on_transform_matrix_changed, {}, PropertyTraits::Visual|PropertyTraits::Hidden)
0027 
0028 public:
0029     Group(Document* document);
0030 
0031     int docnode_child_count() const override { return shapes.size(); }
0032     DocumentNode* docnode_child(int index) const override { return shapes[index]; }
0033     int docnode_child_index(DocumentNode* obj) const override { return shapes.index_of(static_cast<ShapeElement*>(obj)); }
0034 
0035     static QIcon static_tree_icon()
0036     {
0037         return QIcon::fromTheme("object-group");
0038     }
0039 
0040     static QString static_type_name_human()
0041     {
0042         return i18n("Group");
0043     }
0044 
0045     void add_shapes(model::FrameTime t, math::bezier::MultiBezier & bez, const QTransform& transform) const override;
0046 
0047     QRectF local_bounding_rect(FrameTime t) const override;
0048 
0049     QTransform local_transform_matrix(model::FrameTime t) const override;
0050 
0051     QPainterPath to_clip(model::FrameTime t) const override;
0052 
0053     std::unique_ptr<ShapeElement> to_path() const override;
0054 
0055 Q_SIGNALS:
0056     void opacity_changed(float op);
0057 
0058 protected:
0059     QPainterPath to_painter_path_impl(model::FrameTime t) const override;
0060     void on_paint(QPainter*, FrameTime, PaintMode, model::Modifier*) const override;
0061     void on_graphics_changed() override;
0062     void on_composition_changed(model::Composition* old_comp, model::Composition* new_comp) override;
0063 
0064 private Q_SLOTS:
0065     void on_transform_matrix_changed();
0066 };
0067 
0068 } // namespace glaxnimate::model