File indexing completed on 2024-05-12 16:01:53
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 communicate 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 oriName 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 &oriName) const; 0053 /** 0054 * @brief oldNameFromNewName 0055 * @param newName the current name of a group 0056 * @return the name of the group at the creation of the instance 0057 */ 0058 QString oldNameFromNewName(const QString &newName) const; 0059 /** 0060 * @brief duplicateExistsFilename 0061 * @param filename the name of the file 0062 * @param global if this filename is going to be used for a global palette 0063 * @return true if the a palette in the resource system that has filename 0064 * name already exists else false 0065 */ 0066 bool duplicateExistsFilename(const QString &filename, bool global) const; 0067 QString relativePathFromSaveLocation() const; 0068 0069 void rename(const QString &newName); 0070 void changeFilename(const QString &newName); 0071 void changeColCount(int); 0072 0073 /** 0074 * @brief addGroup 0075 * @return new group's name if change accepted, empty string if cancelled 0076 */ 0077 QString addGroup(); 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 * @brief renameGroup 0086 * @param oldName 0087 * @return new name if change accepted, empty string if cancelled 0088 */ 0089 QString renameGroup(const QString &oldName); 0090 void changeGroupRowCount(const QString &name, int newRowCount); 0091 void setStorageLocation(QString location); 0092 0093 void setEntry(const KoColor &color, const QModelIndex &index); 0094 void removeEntry(const QModelIndex &index); 0095 void modifyEntry(const QModelIndex &index); 0096 void addEntry(const KoColor &color); 0097 0098 bool isModified() const; 0099 0100 /** 0101 * @brief getModifiedGroup 0102 * @param originalName name of the group at the creation of the instance 0103 * @return the modified group 0104 */ 0105 const KisSwatchGroup &getModifiedGroup(const QString &originalName) const; 0106 0107 /** 0108 * @brief updatePalette 0109 * MUST be called to make the changes into the resource server 0110 */ 0111 void updatePalette(); 0112 0113 /** 0114 * @brief savePalette 0115 * 0116 */ 0117 void saveNewPaletteVersion(); 0118 0119 private Q_SLOTS: 0120 void slotGroupNameChanged(const QString &newName); 0121 void slotPaletteChanged(); 0122 void slotSetDocumentModified(); 0123 0124 private: 0125 QString newGroupName() const; 0126 bool duplicateExistsGroupName(const QString &name) const; 0127 bool duplicateExistsOriginalGroupName(const QString &name) const; 0128 QString filenameFromPath(const QString &path) const; 0129 0130 private: 0131 struct Private; 0132 QScopedPointer<Private> m_d; 0133 }; 0134 0135 #endif // KISPALETTEMANAGER_H