File indexing completed on 2024-04-14 04:46:06
0001 /* 0002 SPDX-FileCopyrightText: 2012 Till Theato <root@ttill.de> 0003 SPDX-FileCopyrightText: 2014 Jean-Baptiste Mardelle <jb@kdenlive.org> 0004 This file is part of Kdenlive. See www.kdenlive.org. 0005 0006 SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0007 */ 0008 0009 #pragma once 0010 0011 #include "abstractmodel/treeitem.hpp" 0012 #include "undohelper.hpp" 0013 0014 #include <QDateTime> 0015 #include <QIcon> 0016 #include <QObject> 0017 #include <QReadWriteLock> 0018 0019 class ProjectClip; 0020 class ProjectFolder; 0021 class Bin; 0022 class QDomElement; 0023 class QDomDocument; 0024 class ProjectItemModel; 0025 0026 /** 0027 * @class AbstractProjectItem 0028 * @brief Base class for all project items (clips, folders, ...). 0029 * 0030 * Project items are stored in a tree like structure ... 0031 */ 0032 class AbstractProjectItem : public QObject, public TreeItem 0033 { 0034 Q_OBJECT 0035 0036 public: 0037 enum PROJECTITEMTYPE { FolderItem, ClipItem, SubClipItem }; 0038 0039 /** 0040 * @brief Constructor. 0041 * @param type is the type of the bin item 0042 * @param id is the binId 0043 * @param model is the ptr to the item model 0044 * @param isRoot is true if this is the topmost folder 0045 */ 0046 AbstractProjectItem(PROJECTITEMTYPE type, QString id, const std::shared_ptr<ProjectItemModel> &model, bool isRoot = false); 0047 0048 bool operator==(const std::shared_ptr<AbstractProjectItem> &projectItem) const; 0049 0050 /** @brief Returns a pointer to the parent item (or NULL). */ 0051 std::shared_ptr<AbstractProjectItem> parent() const; 0052 0053 /** @brief Returns the type of this item (folder, clip, subclip, etc). */ 0054 PROJECTITEMTYPE itemType() const; 0055 0056 /** @brief Used to search for a clip with a specific id. */ 0057 virtual std::shared_ptr<ProjectClip> clip(const QString &id) = 0; 0058 /** @brief Used to search for a folder with a specific id. */ 0059 virtual std::shared_ptr<ProjectFolder> folder(const QString &id) = 0; 0060 virtual std::shared_ptr<ProjectClip> clipAt(int ix) = 0; 0061 /** @brief Recursively disable/enable bin effects. */ 0062 virtual void setBinEffectsEnabled(bool enabled) = 0; 0063 /** @brief Returns true if item has both audio and video enabled. */ 0064 virtual bool hasAudioAndVideo() const = 0; 0065 0066 /** @brief This function executes what should be done when the item is deleted 0067 but without deleting effectively. 0068 For example, the item will deregister itself from the model and delete the 0069 clips from the timeline. 0070 However, the object is NOT actually deleted, and the tree structure is preserved. 0071 @param Undo,Redo are the lambdas accumulating the update. 0072 */ 0073 virtual bool selfSoftDelete(Fun &undo, Fun &redo); 0074 virtual Fun getAudio_lambda(); 0075 /** @brief Returns the clip's id. */ 0076 const QString &clipId() const; 0077 virtual QPoint zone() const; 0078 0079 // TODO refac : these ref counting are probably deprecated by smart ptrs 0080 /** @brief Set current usage count. */ 0081 void setRefCount(uint count, uint totalCount); 0082 /** @brief Returns clip's current usage count in timeline. */ 0083 uint refCount() const; 0084 /** @brief Increase usage count. */ 0085 void addRef(); 0086 /** @brief Decrease usage count. */ 0087 void removeRef(); 0088 0089 enum DataType { 0090 // display name of item 0091 DataName = Qt::DisplayRole, 0092 // image thumbnail 0093 DataThumbnail = Qt::DecorationRole, 0094 // Tooltip text,usually full path 0095 ClipToolTip = Qt::ToolTipRole, 0096 // unique id of the project clip / folder 0097 DataId = Qt::UserRole, 0098 // creation date 0099 DataDate, 0100 // Description for item (user editable) 0101 DataDescription, 0102 // Number of occurrences used in timeline 0103 UsageCount, 0104 AudioUsed, 0105 VideoUsed, 0106 // Empty if clip has no effect, icon otherwise 0107 IconOverlay, 0108 // item type (clip, subclip, folder) 0109 ItemTypeRole, 0110 // Duration of the clip as displayabe string 0111 DataDuration, 0112 // Tag of the clip as colors 0113 DataTag, 0114 // Rating of the clip (0-5) 0115 DataRating, 0116 // Duration of the clip in frames 0117 ParentDuration, 0118 // Inpoint of the subclip (0 for clips) 0119 DataInPoint, 0120 // Outpoint of the subclip (0 for clips) 0121 DataOutPoint, 0122 // Current progress of the job 0123 JobProgress, 0124 // error message if job crashes (not fully implemented) 0125 JobSuccess, 0126 JobStatus, 0127 // Item status (ready or not, missing, waiting, ...) 0128 ClipStatus, 0129 ClipType, 0130 ClipHasAudioAndVideo, 0131 // Item is the folder containing sequences 0132 SequenceFolder 0133 }; 0134 0135 virtual void setClipStatus(FileStatus::ClipStatus status); 0136 FileStatus::ClipStatus clipStatus() const; 0137 bool statusReady() const; 0138 0139 /** @brief Returns the data that describes this item. 0140 * @param type type of data to return 0141 * 0142 * This function is necessary for interaction with ProjectItemModel. 0143 */ 0144 virtual const QVariant getData(DataType type) const; 0145 /** 0146 * @brief Returns the item icon. 0147 */ 0148 const QIcon icon() const; 0149 0150 /** 0151 * @brief Returns the amount of different types of data this item supports. 0152 * 0153 * This base class supports only DataName and DataDescription, so the return value is always 2. 0154 * This function is necessary for interaction with ProjectItemModel. 0155 */ 0156 virtual int supportedDataCount() const; 0157 0158 /** @brief Returns the (displayable) name of this item. */ 0159 QString name() const; 0160 /** @brief Sets a new (displayable) name. */ 0161 virtual void setName(const QString &name); 0162 0163 /** @brief Returns the (displayable) description of this item. */ 0164 QString description() const; 0165 /** @brief Sets a new description. */ 0166 virtual void setDescription(const QString &description); 0167 0168 virtual QDomElement toXml(QDomDocument &document, bool includeMeta = false, bool includeProfile = true) = 0; 0169 virtual QString getToolTip() const = 0; 0170 virtual bool rename(const QString &name, int column) = 0; 0171 0172 /** @brief Return the bin id of the last parent that this element got, even if this 0173 parent has already been destroyed. 0174 Return the empty string if the element was parentless */ 0175 QString lastParentId() const; 0176 0177 /** @brief This is an overload of TreeItem::updateParent that tracks the id of the id of the parent */ 0178 void updateParent(std::shared_ptr<TreeItem> newParent) override; 0179 0180 /** @brief Returns a ptr to the enclosing dir, and nullptr if none is found. 0181 @param strict if set to false, the enclosing dir of a dir is itself, otherwise we try to find a "true" parent 0182 */ 0183 std::shared_ptr<AbstractProjectItem> getEnclosingFolder(bool strict = false); 0184 0185 /** @brief Returns true if a clip corresponding to this bin is inserted in a timeline. 0186 Note that this function does not account for children, use TreeItem::accumulate if you want to get that information as well. 0187 */ 0188 virtual bool isIncludedInTimeline() { return false; } 0189 virtual ClipType::ProducerType clipType() const = 0; 0190 uint rating() const; 0191 virtual void setRating(uint rating); 0192 const QString &tags() const; 0193 void setTags(const QString &tags); 0194 0195 Q_SIGNALS: 0196 void childAdded(AbstractProjectItem *child); 0197 void aboutToRemoveChild(AbstractProjectItem *child); 0198 0199 protected: 0200 QString m_name; 0201 QString m_description; 0202 QIcon m_thumbnail; 0203 QString m_duration; 0204 int m_parentDuration; 0205 int m_inPoint; 0206 int m_outPoint; 0207 QDateTime m_date; 0208 QString m_binId; 0209 uint m_totalUsage; 0210 uint m_currentSequenceUsage; 0211 uint m_AudioUsage; 0212 uint m_VideoUsage; 0213 QString m_usageText; 0214 uint m_rating; 0215 QString m_tags; 0216 FileStatus::ClipStatus m_clipStatus; 0217 0218 PROJECTITEMTYPE m_itemType; 0219 0220 QString m_lastParentId; 0221 0222 /** @brief Returns a rounded border pixmap from the @param source pixmap. */ 0223 QPixmap roundedPixmap(const QPixmap &source); 0224 /** @brief This is a lock that ensures safety in case of concurrent access */ 0225 mutable QReadWriteLock m_lock; 0226 0227 private: 0228 bool m_isCurrent; 0229 };