Warning, file /graphics/glaxnimate/src/core/model/document.hpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

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 
0010 #include <QDir>
0011 #include <QUndoStack>
0012 
0013 #include "io/options.hpp"
0014 #include "model/comp_graph.hpp"
0015 #include "model/document_node.hpp"
0016 
0017 namespace glaxnimate::model {
0018 
0019 class Assets;
0020 struct PendingAsset;
0021 class Composition;
0022 
0023 class Document : public QObject
0024 {
0025     Q_OBJECT
0026 
0027     Q_PROPERTY(QString filename READ filename)
0028     Q_PROPERTY(double current_time READ current_time WRITE set_current_time NOTIFY current_time_changed)
0029     Q_PROPERTY(bool record_to_keyframe READ record_to_keyframe WRITE set_record_to_keyframe NOTIFY record_to_keyframe_changed)
0030     Q_PROPERTY(Object* assets READ assets_obj)
0031     Q_PROPERTY(QVariantMap metadata READ metadata WRITE set_metadata)
0032 
0033 public:
0034     struct DocumentInfo
0035     {
0036         QString author;
0037         QString description;
0038         QStringList keywords;
0039 
0040         bool empty() const
0041         {
0042             return author.isEmpty() && description.isEmpty() && keywords.empty();
0043         }
0044     };
0045 
0046     explicit Document(const QString& filename = {});
0047     ~Document();
0048 
0049     QString filename() const;
0050     QUuid uuid() const;
0051 
0052     QVariantMap& metadata();
0053     void set_metadata(const QVariantMap& meta);
0054 
0055     DocumentInfo& info();
0056 
0057     Composition* current_comp();
0058     void set_current_comp(Composition* comp);
0059 
0060     QUndoStack& undo_stack();
0061 
0062     const io::Options& io_options() const;
0063 
0064     void set_io_options(const io::Options& opt);
0065 
0066     Q_INVOKABLE glaxnimate::model::DocumentNode* find_by_uuid(const QUuid& n) const;
0067     Q_INVOKABLE glaxnimate::model::DocumentNode* find_by_name(const QString& name) const;
0068     Q_INVOKABLE QVariantList find_by_type_name(const QString& type_name) const;
0069 
0070     Q_INVOKABLE bool undo();
0071     Q_INVOKABLE bool redo();
0072 
0073     void push_command(QUndoCommand* cmd);
0074 
0075     FrameTime current_time() const;
0076     void set_current_time(FrameTime t);
0077 
0078     /**
0079      * \brief Whether animated values should add keyframes when their value changes
0080      */
0081     bool record_to_keyframe() const;
0082     void set_record_to_keyframe(bool r);
0083 
0084     Q_INVOKABLE QString get_best_name(glaxnimate::model::DocumentNode* node, const QString& suggestion={}) const;
0085     Q_INVOKABLE void set_best_name(glaxnimate::model::DocumentNode* node, const QString& suggestion={}) const;
0086 
0087     model::Assets* assets() const;
0088 
0089     model::CompGraph& comp_graph();
0090 
0091     void stretch_time(qreal multiplier);
0092 
0093     int add_pending_asset(const QString& name, const QUrl& url);
0094     int add_pending_asset(const QString& name, const QByteArray& data);
0095     int add_pending_asset(const model::PendingAsset& asset);
0096     std::vector<model::PendingAsset> pending_assets();
0097     void mark_asset_loaded(int pending_id);
0098     void clear_pending_assets();
0099 
0100 
0101 Q_SIGNALS:
0102     void filename_changed(const QString& n);
0103     void current_time_changed(FrameTime t);
0104     void record_to_keyframe_changed(bool r);
0105     void graphics_invalidated();
0106 
0107 private:
0108     Object* assets_obj() const;
0109     void decrease_node_name(const QString& old_name);
0110     void increase_node_name(const QString& new_name);
0111 
0112 private:
0113     class Private;
0114     friend DocumentNode;
0115     std::unique_ptr<Private> d;
0116 };
0117 
0118 } // namespace glaxnimate::model