1 /* 2 SPDX-FileCopyrightText: 2012 Till Theato <root@ttill.de> 3 SPDX-FileCopyrightText: 2014 Jean-Baptiste Mardelle <jb@kdenlive.org> 4 This file is part of Kdenlive. See www.kdenlive.org. 5 6 SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 7 */ 8 9 #ifndef ABSTRACTPROJECTITEM_H 10 #define ABSTRACTPROJECTITEM_H 11 12 #include "abstractmodel/treeitem.hpp" 13 #include "undohelper.hpp" 14 15 #include <QDateTime> 16 #include <QIcon> 17 #include <QObject> 18 #include <QReadWriteLock> 19 20 class ProjectClip; 21 class ProjectFolder; 22 class Bin; 23 class QDomElement; 24 class QDomDocument; 25 class ProjectItemModel; 26 27 /** 28 * @class AbstractProjectItem 29 * @brief Base class for all project items (clips, folders, ...). 30 * 31 * Project items are stored in a tree like structure ... 32 */ 33 class AbstractProjectItem : public QObject, public TreeItem 34 { 35 Q_OBJECT 36 37 public: 38 enum PROJECTITEMTYPE { FolderItem, ClipItem, SubClipItem }; 39 40 /** 41 * @brief Constructor. 42 * @param type is the type of the bin item 43 * @param id is the binId 44 * @param model is the ptr to the item model 45 * @param isRoot is true if this is the topmost folder 46 */ 47 AbstractProjectItem(PROJECTITEMTYPE type, QString id, const std::shared_ptr<ProjectItemModel> &model, bool isRoot = false); 48 49 bool operator==(const std::shared_ptr<AbstractProjectItem> &projectItem) const; 50 51 /** @brief Returns a pointer to the parent item (or NULL). */ 52 std::shared_ptr<AbstractProjectItem> parent() const; 53 54 /** @brief Returns the type of this item (folder, clip, subclip, etc). */ 55 PROJECTITEMTYPE itemType() const; 56 57 /** @brief Used to search for a clip with a specific id. */ 58 virtual std::shared_ptr<ProjectClip> clip(const QString &id) = 0; 59 /** @brief Used to search for a folder with a specific id. */ 60 virtual std::shared_ptr<ProjectFolder> folder(const QString &id) = 0; 61 virtual std::shared_ptr<ProjectClip> clipAt(int ix) = 0; 62 /** @brief Recursively disable/enable bin effects. */ 63 virtual void setBinEffectsEnabled(bool enabled) = 0; 64 /** @brief Returns true if item has both audio and video enabled. */ 65 virtual bool hasAudioAndVideo() const = 0; 66 67 /** @brief This function executes what should be done when the item is deleted 68 but without deleting effectively. 69 For example, the item will deregister itself from the model and delete the 70 clips from the timeline. 71 However, the object is NOT actually deleted, and the tree structure is preserved. 72 @param Undo,Redo are the lambdas accumulating the update. 73 */ 74 virtual bool selfSoftDelete(Fun &undo, Fun &redo); 75 virtual Fun getAudio_lambda(); 76 /** @brief Returns the clip's id. */ 77 const QString &clipId() const; 78 virtual QPoint zone() const; 79 80 // TODO refac : these ref counting are probably deprecated by smart ptrs 81 /** @brief Set current usage count. */ 82 void setRefCount(uint count, uint audioCount); 83 /** @brief Returns clip's current usage count in timeline. */ 84 uint refCount() const; 85 /** @brief Increase usage count. */ 86 void addRef(bool isAudio); 87 /** @brief Decrease usage count. */ 88 void removeRef(bool isAudio); 89 90 enum DataType { 91 // display name of item 92 DataName = Qt::DisplayRole, 93 // image thumbnail 94 DataThumbnail = Qt::DecorationRole, 95 // Tooltip text,usually full path 96 ClipToolTip = Qt::ToolTipRole, 97 // unique id of the project clip / folder 98 DataId = Qt::UserRole, 99 // creation date 100 DataDate, 101 // Description for item (user editable) 102 DataDescription, 103 // Number of occurrences used in timeline 104 UsageCount, 105 AudioUsageCount, 106 // Empty if clip has no effect, icon otherwise 107 IconOverlay, 108 // item type (clip, subclip, folder) 109 ItemTypeRole, 110 // Duration of the clip as displayabe string 111 DataDuration, 112 // Tag of the clip as colors 113 DataTag, 114 // Rating of the clip (0-5) 115 DataRating, 116 // Duration of the clip in frames 117 ParentDuration, 118 // Inpoint of the subclip (0 for clips) 119 DataInPoint, 120 // Outpoint of the subclip (0 for clips) 121 DataOutPoint, 122 // Current progress of the job 123 JobProgress, 124 // error message if job crashes (not fully implemented) 125 JobSuccess, 126 JobStatus, 127 // Item status (ready or not, missing, waiting, ...) 128 ClipStatus, 129 ClipType, 130 ClipHasAudioAndVideo 131 }; 132 133 virtual void setClipStatus(FileStatus::ClipStatus status); 134 FileStatus::ClipStatus clipStatus() const; 135 bool statusReady() const; 136 137 /** @brief Returns the data that describes this item. 138 * @param type type of data to return 139 * 140 * This function is necessary for interaction with ProjectItemModel. 141 */ 142 virtual QVariant getData(DataType type) const; 143 144 /** 145 * @brief Returns the amount of different types of data this item supports. 146 * 147 * This base class supports only DataName and DataDescription, so the return value is always 2. 148 * This function is necessary for interaction with ProjectItemModel. 149 */ 150 virtual int supportedDataCount() const; 151 152 /** @brief Returns the (displayable) name of this item. */ 153 QString name() const; 154 /** @brief Sets a new (displayable) name. */ 155 virtual void setName(const QString &name); 156 157 /** @brief Returns the (displayable) description of this item. */ 158 QString description() const; 159 /** @brief Sets a new description. */ 160 virtual void setDescription(const QString &description); 161 162 virtual QDomElement toXml(QDomDocument &document, bool includeMeta = false, bool includeProfile = true) = 0; 163 virtual QString getToolTip() const = 0; 164 virtual bool rename(const QString &name, int column) = 0; 165 166 /** @brief Return the bin id of the last parent that this element got, even if this 167 parent has already been destroyed. 168 Return the empty string if the element was parentless */ 169 QString lastParentId() const; 170 171 /** @brief This is an overload of TreeItem::updateParent that tracks the id of the id of the parent */ 172 void updateParent(std::shared_ptr<TreeItem> newParent) override; 173 174 /** @brief Returns a ptr to the enclosing dir, and nullptr if none is found. 175 @param strict if set to false, the enclosing dir of a dir is itself, otherwise we try to find a "true" parent 176 */ 177 std::shared_ptr<AbstractProjectItem> getEnclosingFolder(bool strict = false); 178 179 /** @brief Returns true if a clip corresponding to this bin is inserted in a timeline. 180 Note that this function does not account for children, use TreeItem::accumulate if you want to get that information as well. 181 */ isIncludedInTimeline()182 virtual bool isIncludedInTimeline() { return false; } 183 virtual ClipType::ProducerType clipType() const = 0; 184 uint rating() const; 185 virtual void setRating(uint rating); 186 const QString &tags() const; 187 void setTags(const QString tags); 188 189 signals: 190 void childAdded(AbstractProjectItem *child); 191 void aboutToRemoveChild(AbstractProjectItem *child); 192 193 protected: 194 QString m_name; 195 QString m_description; 196 QIcon m_thumbnail; 197 QString m_duration; 198 int m_parentDuration; 199 int m_inPoint; 200 int m_outPoint; 201 QDateTime m_date; 202 QString m_binId; 203 uint m_usage; 204 uint m_AudioUsage; 205 uint m_rating; 206 QString m_tags; 207 FileStatus::ClipStatus m_clipStatus; 208 209 PROJECTITEMTYPE m_itemType; 210 211 QString m_lastParentId; 212 213 /** @brief Returns a rounded border pixmap from the @param source pixmap. */ 214 QPixmap roundedPixmap(const QPixmap &source); 215 /** @brief This is a lock that ensures safety in case of concurrent access */ 216 mutable QReadWriteLock m_lock; 217 218 private: 219 bool m_isCurrent; 220 }; 221 222 #endif 223