Changeset View
Changeset View
Standalone View
Standalone View
libs/ui/KisPaletteEditor.h
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright (c) 2018 Michael Zhou <simeirxh@gmail.com> | ||||
3 | * | ||||
4 | * This program is free software; you can redistribute it and/or modify | ||||
5 | * it under the terms of the GNU General Public License as published by | ||||
6 | * the Free Software Foundation; either version 2 of the License, or | ||||
7 | * (at your option) any later version. | ||||
8 | * | ||||
9 | * This program is distributed in the hope that it will be useful, | ||||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
12 | * GNU General Public License for more details. | ||||
13 | * | ||||
14 | * You should have received a copy of the GNU General Public License | ||||
15 | * along with this program; if not, write to the Free Software | ||||
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||||
17 | */ | ||||
18 | | ||||
19 | #ifndef KISPALETTEMANAGER_H | ||||
20 | #define KISPALETTEMANAGER_H | ||||
21 | | ||||
22 | #include <QObject> | ||||
23 | #include <QScopedPointer> | ||||
24 | #include <KisSwatch.h> | ||||
25 | | ||||
26 | #include <kritaui_export.h> | ||||
27 | | ||||
28 | class KoColorSet; | ||||
29 | class KisPaletteModel; | ||||
30 | class KisViewManager; | ||||
31 | class KisSwatchGroup; | ||||
32 | class KisViewManager; | ||||
33 | | ||||
34 | /** | ||||
35 | * @brief The PaletteEditor class | ||||
36 | * this class manipulates a KisPaletteModel using GUI elements and communicate | ||||
37 | * with KisDocument | ||||
38 | * | ||||
39 | * Changes made in this class won't be done to the palette if the palette is | ||||
40 | * read only (not editable, isEditable() == false) | ||||
41 | */ | ||||
42 | class KRITAUI_EXPORT KisPaletteEditor : public QObject | ||||
43 | { | ||||
44 | Q_OBJECT | ||||
45 | public: | ||||
46 | struct PaletteInfo; | ||||
47 | | ||||
48 | public: | ||||
49 | explicit KisPaletteEditor(QObject *parent = Q_NULLPTR); | ||||
50 | ~KisPaletteEditor(); | ||||
51 | | ||||
52 | void setPaletteModel(KisPaletteModel *model); | ||||
53 | void setView(KisViewManager *view); | ||||
54 | | ||||
55 | void addPalette(); | ||||
56 | void importPalette(); | ||||
57 | void removePalette(KoColorSet *); | ||||
58 | | ||||
59 | /** | ||||
60 | * @brief rowNumberOfGroup | ||||
61 | * @param oriName the original name of a group at the creation of the instance | ||||
62 | * @return newest row number of the group | ||||
63 | */ | ||||
64 | int rowNumberOfGroup(const QString &oriName) const; | ||||
65 | /** | ||||
66 | * @brief oldNameFromNewName | ||||
67 | * @param newName the current name of a group | ||||
68 | * @return the name of the group at the creation of the instance | ||||
69 | */ | ||||
70 | QString oldNameFromNewName(const QString &newName) const; | ||||
71 | /** | ||||
72 | * @brief duplicateExistsFilename | ||||
73 | * @param name | ||||
74 | * @param global if this filename is going to be used for a global palette | ||||
75 | * @return true if the a palette in the resource system that has filename | ||||
76 | * name already exists else false | ||||
77 | */ | ||||
78 | bool duplicateExistsFilename(const QString &filename, bool global) const; | ||||
79 | QString relativePathFromSaveLocation() const; | ||||
80 | | ||||
81 | void rename(const QString &newName); | ||||
82 | void changeFilename(const QString &newName); | ||||
83 | void changeColCount(int); | ||||
84 | | ||||
85 | /** | ||||
86 | * @brief addGroup | ||||
87 | * @param name original group name | ||||
88 | * @param rowNumber | ||||
89 | * @return new group's name if change accpeted, empty string if cancelled | ||||
90 | */ | ||||
91 | QString addGroup(); | ||||
92 | /** | ||||
93 | * @brief removeGroup | ||||
94 | * @param name original group name | ||||
95 | * @return true if change accepted, false if cancelled | ||||
96 | */ | ||||
97 | bool removeGroup(const QString &name); | ||||
98 | /** | ||||
99 | * @brief renameGroup | ||||
100 | * @param oldName | ||||
101 | * @return new name if change accpeted, empty string if cancelled | ||||
102 | */ | ||||
103 | QString renameGroup(const QString &oldName); | ||||
104 | void changeGroupRowCount(const QString &name, int newRowCount); | ||||
105 | void setGlobal(bool); | ||||
106 | void setReadOnly(bool); | ||||
107 | | ||||
108 | void setEntry(const KoColor &color, const QModelIndex &index); | ||||
109 | void removeEntry(const QModelIndex &index); | ||||
110 | void modifyEntry(const QModelIndex &index); | ||||
111 | void addEntry(const KoColor &color); | ||||
112 | | ||||
113 | bool isModified() const; | ||||
114 | | ||||
115 | /** | ||||
116 | * @brief getModifiedGroup | ||||
117 | * @param originalName name of the group at the creation of the instance | ||||
118 | * @return the modified group | ||||
119 | */ | ||||
120 | const KisSwatchGroup &getModifiedGroup(const QString &originalName) const; | ||||
121 | | ||||
122 | /** | ||||
123 | * @brief updatePalette | ||||
124 | * MUST be called to make the changes into the resource server | ||||
125 | */ | ||||
126 | void updatePalette(); | ||||
127 | | ||||
128 | private Q_SLOTS: | ||||
129 | void slotGroupNameChanged(const QString &newName); | ||||
130 | void slotPaletteChanged(); | ||||
131 | void slotPolluteDoc(); | ||||
132 | | ||||
133 | private: | ||||
134 | QString newPaletteFileName(bool isGlobal); | ||||
135 | QString newGroupName() const; | ||||
136 | void setNonGlobal(); | ||||
137 | void setGlobal(); | ||||
138 | bool duplicateExistsGroupName(const QString &name) const; | ||||
139 | bool duplicateExistsOriginalGroupName(const QString &name) const; | ||||
140 | void uploadPaletteList() const; | ||||
141 | QString filenameFromPath(const QString &path) const; | ||||
142 | | ||||
143 | private: | ||||
144 | struct Private; | ||||
145 | QScopedPointer<Private> m_d; | ||||
146 | }; | ||||
147 | | ||||
148 | #endif // KISPALETTEMANAGER_H |