File indexing completed on 2025-02-02 04:11:04
0001 /* 0002 * SPDX-FileCopyrightText: 2019-2023 Mattia Basaglia <dev@dragon.best> 0003 * 0004 * SPDX-License-Identifier: GPL-3.0-or-later 0005 */ 0006 0007 #include "composition.hpp" 0008 #include "model/document.hpp" 0009 #include "model/assets/assets.hpp" 0010 #include "command/object_list_commands.hpp" 0011 #include <QPainter> 0012 0013 using namespace glaxnimate; 0014 0015 GLAXNIMATE_OBJECT_IMPL(glaxnimate::model::Composition) 0016 0017 QIcon glaxnimate::model::Composition::tree_icon() const 0018 { 0019 return QIcon::fromTheme("video-x-generic"); 0020 } 0021 0022 QString glaxnimate::model::Composition::type_name_human() const 0023 { 0024 return i18n("Composition"); 0025 } 0026 0027 bool glaxnimate::model::Composition::remove_if_unused(bool clean_lists) 0028 { 0029 if ( clean_lists && users().empty() ) 0030 { 0031 document()->push_command(new command::RemoveObject( 0032 this, 0033 &document()->assets()->compositions->values 0034 )); 0035 return true; 0036 } 0037 return false; 0038 } 0039 0040 glaxnimate::model::DocumentNode * glaxnimate::model::Composition::docnode_parent() const 0041 { 0042 return document()->assets()->compositions.get(); 0043 } 0044 0045 0046 int glaxnimate::model::Composition::docnode_child_index(glaxnimate::model::DocumentNode* dn) const 0047 { 0048 return shapes.index_of(static_cast<ShapeElement*>(dn)); 0049 } 0050 0051 QRectF glaxnimate::model::Composition::local_bounding_rect(FrameTime) const 0052 { 0053 return rect(); 0054 } 0055 0056 QImage glaxnimate::model::Composition::render_image(float time, QSize image_size, const QColor& background) const 0057 { 0058 QSizeF real_size = size(); 0059 if ( !image_size.isValid() ) 0060 image_size = real_size.toSize(); 0061 QImage image(image_size, QImage::Format_RGBA8888); 0062 if ( !background.isValid() ) 0063 image.fill(Qt::transparent); 0064 else 0065 image.fill(background); 0066 0067 QPainter painter(&image); 0068 painter.setRenderHint(QPainter::Antialiasing); 0069 painter.scale( 0070 image_size.width() / real_size.width(), 0071 image_size.height() / real_size.height() 0072 ); 0073 paint(&painter, time, VisualNode::Render); 0074 0075 return image; 0076 } 0077 0078 QImage glaxnimate::model::Composition::render_image() const 0079 { 0080 return render_image(document()->current_time(), size()); 0081 }