File indexing completed on 2024-04-28 08:44:49
0001 /* 0002 Kdenlive TitleClip Pattern 0003 SPDX-FileCopyrightText: 2020 RafaĆ Lalik <rafallalik@gmail.com> 0004 0005 SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0006 */ 0007 0008 #pragma once 0009 0010 #include <QAbstractListModel> 0011 #include <QSize> 0012 0013 class QGraphicsItem; 0014 class QGraphicsPixmapItem; 0015 0016 /** 0017 * @todo write docs 0018 */ 0019 class PatternsModel : public QAbstractListModel 0020 { 0021 public: 0022 /** 0023 * Default constructor 0024 */ 0025 explicit PatternsModel(QObject *parent = nullptr); 0026 0027 QVariant data(const QModelIndex& index, int role) const override; 0028 int rowCount(const QModelIndex& parent) const override; 0029 0030 /** 0031 * @brief Change size of the image to be displayed in the list 0032 * @param size tile size 0033 */ 0034 virtual void setTileSize(const QSize & size) { m_tileSize = size; } 0035 0036 /** 0037 * @brief Set background for the list tiles. Should be called with TitleWidget::m_frameImage as parameter. 0038 * @param pxm background pixmap 0039 */ 0040 virtual void setBackgroundPixmap(QGraphicsPixmapItem * pxm) { bkg = pxm; } 0041 0042 /** 0043 * @brief Add new xml pattern to the model 0044 * @param pattern the xml from TitleWidget::xml() containing items. 0045 */ 0046 virtual void addScene(const QString & pattern); 0047 0048 /** 0049 * @brief Serialize all patterns 0050 * @return byte QByteArray 0051 */ 0052 virtual QByteArray serialize(); 0053 /** 0054 * @brief Deserialize byte array with patterns 0055 * @param data data 0056 */ 0057 virtual void deserialize(const QByteArray & data); 0058 0059 /** 0060 * @brief Return number of modification. Counter is incremented after each addScene() and removeScene() call. Is cleared after serialize() and deserialize() is called. 0061 * @return number of modifications 0062 */ 0063 int getModifiedCounter() const { return modified_counter; } 0064 0065 /** 0066 * @brief Repaint all scenes. Useful when e.g. background was changed. 0067 */ 0068 virtual void repaintScenes(); 0069 0070 private: 0071 /** 0072 * @brief paint scene for given pattern 0073 * @param pattern xml pattern 0074 * @return rendered pixmap 0075 */ 0076 virtual QPixmap paintScene(const QString & pattern); 0077 0078 public Q_SLOTS: 0079 /** 0080 * @brief Remove scene. 0081 * @param index scene index 0082 */ 0083 virtual void removeScene(const QModelIndex & index); 0084 0085 /** 0086 * @brief Remove all scenes 0087 */ 0088 virtual void removeAll(); 0089 0090 private: 0091 QVector<QString> patterns; 0092 QVector<QPixmap> pixmaps; 0093 QGraphicsPixmapItem * bkg{nullptr}; 0094 int modified_counter{0}; 0095 0096 QSize m_tileSize{QSize(16,9)}; 0097 };