File indexing completed on 2024-05-19 04:29:17

0001 /*
0002  *  SPDX-FileCopyrightText: 2018 Michael Zhou <simeirxh@gmail.com>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #ifndef KISPALETTEMANAGER_H
0008 #define KISPALETTEMANAGER_H
0009 
0010 #include <QObject>
0011 #include <QScopedPointer>
0012 #include <KisSwatch.h>
0013 
0014 #include <kritaui_export.h>
0015 
0016 class KoColorSet;
0017 class KisPaletteModel;
0018 class KisViewManager;
0019 class KisSwatchGroup;
0020 class KisViewManager;
0021 
0022 /**
0023  * @brief The PaletteEditor class
0024  * this class manipulates a KisPaletteModel using GUI elements and communicates
0025  * with KisDocument
0026  *
0027  * Changes made in this class won't be done to the palette if the palette is
0028  * read only (not editable, isEditable() == false)
0029  */
0030 class KRITAUI_EXPORT KisPaletteEditor : public QObject
0031 {
0032     Q_OBJECT
0033 public:
0034     struct PaletteInfo;
0035 
0036 public:
0037     explicit KisPaletteEditor(QObject *parent = 0);
0038     ~KisPaletteEditor();
0039 
0040     void setPaletteModel(KisPaletteModel *model);
0041     void setView(KisViewManager *view);
0042 
0043     KoColorSetSP addPalette();
0044     KoColorSetSP importPalette();
0045     void removePalette(KoColorSetSP );
0046 
0047     /**
0048      * @brief rowNumberOfGroup
0049      * @param originalName the original name of a group at the creation of the instance
0050      * @return newest row number of the group
0051      */
0052     int rowNumberOfGroup(const QString &originalName) const;
0053 
0054     /**
0055      * @brief oldNameFromNewName
0056      * @param newName the current name of a group
0057      * @return the name of the group at the creation of the instance
0058      */
0059     QString oldNameFromNewName(const QString &newName) const;
0060 
0061     /**
0062      * @brief rename
0063      * @param newName
0064      */
0065     void rename(const QString &newName);
0066 
0067     /**
0068      * @brief changeColumnCount
0069      */
0070     void changeColumnCount(int);
0071 
0072     /**
0073      * @brief addGroup
0074      * @return new group's name if change accepted, empty string if cancelled
0075      */
0076     QString addGroup();
0077 
0078     /**
0079      * @brief removeGroup
0080      * @param name original group name
0081      * @return true if change accepted, false if cancelled
0082      */
0083     bool removeGroup(const QString &name);
0084 
0085     /**
0086      * @brief renameGroup
0087      * @param oldName
0088      * @return new name if change accepted, empty string if cancelled
0089      */
0090     QString renameGroup(const QString &oldName);
0091 
0092     void changeGroupRowCount(const QString &name, int newRowCount);
0093 
0094     void setStorageLocation(QString location);
0095 
0096     void setEntry(const KoColor &color, const QModelIndex &index);
0097 
0098     void removeEntry(const QModelIndex &index);
0099 
0100     void modifyEntry(const QModelIndex &index);
0101 
0102     void addEntry(const KoColor &color);
0103 
0104     bool isModified() const;
0105 
0106     /**
0107      * @brief updatePalette
0108      * MUST be called to make the changes into the resource server
0109      */
0110     void updatePalette();
0111 
0112     /**
0113      * @brief saveNewPaletteVersion
0114      */
0115     void saveNewPaletteVersion();
0116 
0117 private Q_SLOTS:
0118     void slotGroupNameChanged(const QString &newName);
0119     void slotPaletteChanged();
0120     void slotSetDocumentModified();
0121 
0122 private:
0123     QString newGroupName() const;
0124     bool duplicateExistsGroupName(const QString &name) const;
0125     bool duplicateExistsOriginalGroupName(const QString &name) const;
0126     QString filenameFromPath(const QString &path) const;
0127 
0128 private:
0129     struct Private;
0130     QScopedPointer<Private> m_d;
0131 };
0132 
0133 #endif // KISPALETTEMANAGER_H