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 | * @return true if the a palette in the resource system that has filename | ||||
75 | * name already exists else false | ||||
76 | */ | ||||
77 | bool duplicateExistsFilename(const QString &name) const; | ||||
78 | | ||||
79 | void rename(const QString &newName); | ||||
80 | void changeFilename(const QString &newName); | ||||
81 | void changeColCount(int); | ||||
82 | | ||||
83 | /** | ||||
84 | * @brief addGroup | ||||
85 | * @param name original group name | ||||
86 | * @param rowNumber | ||||
87 | * @return new group's name if change accpeted, empty string if cancelled | ||||
88 | */ | ||||
89 | QString addGroup(); | ||||
90 | /** | ||||
91 | * @brief removeGroup | ||||
92 | * @param name original group name | ||||
93 | * @return true if change accepted, false if cancelled | ||||
94 | */ | ||||
95 | bool removeGroup(const QString &name); | ||||
96 | /** | ||||
97 | * @brief renameGroup | ||||
98 | * @param oldName | ||||
99 | * @return new name if change accpeted, empty string if cancelled | ||||
100 | */ | ||||
101 | QString renameGroup(const QString &oldName); | ||||
102 | void changeGroupRowCount(const QString &name, int newRowCount); | ||||
103 | void setGlobal(bool); | ||||
104 | void setReadOnly(bool); | ||||
105 | | ||||
106 | void setEntry(const KoColor &color, const QModelIndex &index); | ||||
107 | void removeEntry(const QModelIndex &index); | ||||
108 | void modifyEntry(const QModelIndex &index); | ||||
109 | void addEntry(const KoColor &color); | ||||
110 | | ||||
111 | bool isModified() const; | ||||
112 | | ||||
113 | /** | ||||
114 | * @brief getModifiedGroup | ||||
115 | * @param originalName name of the group at the creation of the instance | ||||
116 | * @return the modified group | ||||
117 | */ | ||||
118 | const KisSwatchGroup &getModifiedGroup(const QString &originalName) const; | ||||
119 | | ||||
120 | /** | ||||
121 | * @brief updatePalette | ||||
122 | * MUST be called to make the changes into the resource server | ||||
123 | */ | ||||
124 | void updatePalette(); | ||||
125 | | ||||
126 | private Q_SLOTS: | ||||
127 | void slotGroupNameChanged(const QString &newName); | ||||
128 | void slotPaletteChanged(); | ||||
129 | | ||||
130 | private: | ||||
131 | QString newPaletteFileName(); | ||||
132 | QString newGroupName() const; | ||||
133 | void setNonGlobal(); | ||||
134 | void setGlobal(); | ||||
135 | bool duplicateExistsGroupName(const QString &name) const; | ||||
136 | bool duplicateExistsOriginalGroupName(const QString &name) const; | ||||
137 | void uploadPaletteList() const; | ||||
138 | QString filenameFromPath(const QString &path); | ||||
139 | | ||||
140 | private: | ||||
141 | struct Private; | ||||
142 | QScopedPointer<Private> m_d; | ||||
143 | void submitNonGlobalModificationToDoc(); | ||||
144 | }; | ||||
145 | | ||||
146 | #endif // KISPALETTEMANAGER_H |