File indexing completed on 2025-12-07 04:19:10

0001 /* This file is part of the KDE project
0002  * SPDX-FileCopyrightText: 2012 Dan Leinir Turthra Jensen <admin@leinir.dk>
0003  *
0004  * SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #ifndef LAYERMODEL_H
0008 #define LAYERMODEL_H
0009 
0010 #include <QAbstractListModel>
0011 #include <QImage>
0012 #include <kis_types.h>
0013 
0014 class LayerModel : public QAbstractListModel
0015 {
0016     Q_OBJECT
0017     Q_PROPERTY(QObject* view READ view WRITE setView NOTIFY viewChanged)
0018     Q_PROPERTY(QObject* engine READ engine WRITE setEngine NOTIFY engineChanged)
0019     // This might seem a slightly odd position, but think of it as the thumbnail of all the currently visible layers merged down
0020     Q_PROPERTY(QString fullImageThumbUrl READ fullImageThumbUrl NOTIFY viewChanged);
0021 
0022     Q_PROPERTY(int count READ rowCount NOTIFY countChanged);
0023 
0024     Q_PROPERTY(QString activeName READ activeName WRITE setActiveName NOTIFY activeNameChanged);
0025     Q_PROPERTY(QString activeType READ activeType NOTIFY activeTypeChanged);
0026     Q_PROPERTY(int activeCompositeOp READ activeCompositeOp WRITE setActiveCompositeOp NOTIFY activeCompositeOpChanged);
0027     Q_PROPERTY(int activeOpacity READ activeOpacity WRITE setActiveOpacity NOTIFY activeOpacityChanged);
0028     Q_PROPERTY(bool activeVisible READ activeVisible WRITE setActiveVisible NOTIFY activeVisibleChanged);
0029     Q_PROPERTY(bool activeLocked READ activeLocked WRITE setActiveLocked NOTIFY activeLockedChanged);
0030     Q_PROPERTY(bool activeRChannelActive READ activeRChannelActive WRITE setActiveRChannelActive NOTIFY activeRChannelActiveChanged);
0031     Q_PROPERTY(bool activeGChannelActive READ activeGChannelActive WRITE setActiveGChannelActive NOTIFY activeGChannelActiveChanged);
0032     Q_PROPERTY(bool activeBChannelActive READ activeBChannelActive WRITE setActiveBChannelActive NOTIFY activeBChannelActiveChanged);
0033     Q_PROPERTY(bool activeAChannelActive READ activeAChannelActive WRITE setActiveAChannelActive NOTIFY activeAChannelActiveChanged);
0034     Q_PROPERTY(QObject* activeFilterConfig READ activeFilterConfig WRITE setActiveFilterConfig NOTIFY activeFilterConfigChanged);
0035 public:
0036     enum LayerRoles {
0037         IconRole = Qt::UserRole + 1,
0038         NameRole,
0039         ActiveLayerRole,
0040         OpacityRole,
0041         PercentOpacityRole,
0042         VisibleRole,
0043         LockedRole,
0044         CompositeDetailsRole,
0045         FilterRole,
0046         ChildCountRole,
0047         DeepChildCountRole,
0048         DepthRole,
0049         PreviousItemDepthRole,
0050         NextItemDepthRole,
0051         CanMoveLeftRole,
0052         CanMoveRightRole,
0053         CanMoveUpRole,
0054         CanMoveDownRole
0055     };
0056     explicit LayerModel(QObject *parent = nullptr);
0057     ~LayerModel() override;
0058     QHash<int, QByteArray> roleNames() const override;
0059     QObject* view() const;
0060     void setView(QObject* newView);
0061     QObject* engine() const;
0062     void setEngine(QObject* newEngine);
0063     QString fullImageThumbUrl() const;
0064 
0065     QVariant data(const QModelIndex &index,
0066                   int role = Qt::DisplayRole) const override;
0067     Q_INVOKABLE int
0068     rowCount(const QModelIndex &parent = QModelIndex()) const override;
0069     QVariant headerData(int section,
0070                         Qt::Orientation orientation,
0071                         int role = Qt::DisplayRole) const override;
0072 
0073     Q_INVOKABLE void setActive(int index);
0074     Q_INVOKABLE void moveUp();
0075     Q_INVOKABLE void moveDown();
0076     Q_INVOKABLE void moveLeft();
0077     Q_INVOKABLE void moveRight();
0078     void emitActiveChanges();
0079     Q_INVOKABLE void setOpacity(int index, float newOpacity);
0080     Q_INVOKABLE void setVisible(int index, bool newVisible);
0081     Q_INVOKABLE void setLocked(int index, bool newLocked);
0082     QImage layerThumbnail(QString layerID) const;
0083     Q_INVOKABLE void clear();
0084     Q_INVOKABLE void clone();
0085 
0086     Q_INVOKABLE void deleteCurrentLayer();
0087     Q_INVOKABLE void deleteLayer(int index);
0088     Q_INVOKABLE void addLayer(int layerType);
0089 
0090     QString activeName() const;
0091     void setActiveName(QString newName);
0092     QString activeType() const;
0093     int activeCompositeOp() const;
0094     void setActiveCompositeOp(int newOp);
0095     int activeOpacity() const;
0096     void setActiveOpacity(int newOpacity);
0097     bool activeVisible() const;
0098     void setActiveVisible(bool newVisible);
0099     bool activeLocked() const;
0100     void setActiveLocked(bool newLocked);
0101     bool activeRChannelActive() const;
0102     void setActiveRChannelActive(bool newActive);
0103     bool activeGChannelActive() const;
0104     void setActiveGChannelActive(bool newActive);
0105     bool activeBChannelActive() const;
0106     void setActiveBChannelActive(bool newActive);
0107     bool activeAChannelActive() const;
0108     void setActiveAChannelActive(bool newActive);
0109     QObject* activeFilterConfig() const;
0110     void setActiveFilterConfig(QObject* newConfig);
0111 Q_SIGNALS:
0112     void viewChanged();
0113     void engineChanged();
0114     void countChanged();
0115 
0116     void activeNameChanged();
0117     void activeTypeChanged();
0118     void activeCompositeOpChanged();
0119     void activeOpacityChanged();
0120     void activeVisibleChanged();
0121     void activeLockedChanged();
0122     void activeRChannelActiveChanged();
0123     void activeGChannelActiveChanged();
0124     void activeBChannelActiveChanged();
0125     void activeAChannelActiveChanged();
0126     void activeFilterConfigChanged();
0127 
0128 private Q_SLOTS:
0129     void source_rowsAboutToBeInserted(QModelIndex, int, int);
0130     void source_rowsAboutToBeRemoved(QModelIndex, int, int);
0131     void source_rowsInserted(QModelIndex, int, int);
0132     void source_rowsRemoved(QModelIndex, int, int);
0133     void source_dataChanged(QModelIndex, QModelIndex);
0134     void source_modelReset();
0135     void currentNodeChanged(KisNodeSP newActiveNode);
0136     void notifyImageDeleted();
0137     void nodeChanged(KisNodeSP node);
0138     void imageChanged();
0139     void imageHasChanged();
0140     void aboutToRemoveNode(KisNodeSP node);
0141     void updateActiveLayerWithNewFilterConfig();
0142 
0143 private:
0144     class Private;
0145     Private* d;
0146 };
0147 
0148 #endif // LAYERMODEL_H