Changeset View
Changeset View
Standalone View
Standalone View
libs/widgets/KisPaletteModel.h
Context not available. | |||||
22 | 22 | | |||
---|---|---|---|---|---|
23 | #include <QPointer> | 23 | #include <QPointer> | ||
24 | #include <QModelIndex> | 24 | #include <QModelIndex> | ||
25 | #include <QMap> | ||||
25 | 26 | | |||
26 | #include <KoColorDisplayRendererInterface.h> | 27 | #include <KoColorDisplayRendererInterface.h> | ||
27 | 28 | | |||
Context not available. | |||||
30 | #include <QScopedPointer> | 31 | #include <QScopedPointer> | ||
31 | 32 | | |||
32 | class KoColorSet; | 33 | class KoColorSet; | ||
34 | class KisPaletteView; | ||||
33 | 35 | | |||
34 | /** | 36 | /** | ||
35 | * @brief The KisPaletteModel class | 37 | * @brief The KisPaletteModel class | ||
36 | * This, together with kis_palette_view and kis_palette_delegate forms a mvc way to access kocolorsets. | 38 | * This, together with KisPaletteView and KisPaletteDelegate forms a mvc way to access kocolorsets. | ||
39 | * A display renderer is given to this model to convert KoColor to QColor when | ||||
40 | * colors are requested | ||||
37 | */ | 41 | */ | ||
38 | class KRITAWIDGETS_EXPORT KisPaletteModel : public QAbstractTableModel | 42 | class KRITAWIDGETS_EXPORT KisPaletteModel : public QAbstractTableModel | ||
39 | { | 43 | { | ||
40 | Q_OBJECT | 44 | Q_OBJECT | ||
41 | public: | 45 | public: | ||
42 | KisPaletteModel(QObject* parent = 0); | 46 | explicit KisPaletteModel(QObject* parent = Q_NULLPTR); | ||
43 | ~KisPaletteModel() override; | 47 | ~KisPaletteModel() override; | ||
44 | 48 | | |||
45 | enum AdditionalRoles { | 49 | enum AdditionalRoles { | ||
46 | IsHeaderRole = Qt::UserRole + 1, | 50 | IsGroupNameRole = Qt::UserRole + 1, | ||
47 | ExpandCategoryRole = Qt::UserRole + 2, | 51 | CheckSlotRole, | ||
48 | RetrieveEntryRole = Qt::UserRole + 3 | 52 | GroupNameRole, | ||
53 | RowInGroupRole | ||||
49 | }; | 54 | }; | ||
50 | 55 | | |||
56 | public /* overriden methods */: // QAbstractTableModel | ||||
51 | QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; | 57 | QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; | ||
52 | int rowCount(const QModelIndex& parent = QModelIndex()) const override; | 58 | int rowCount(const QModelIndex& parent = QModelIndex()) const override; | ||
53 | int columnCount(const QModelIndex& parent = QModelIndex()) const override; | 59 | int columnCount(const QModelIndex& parent = QModelIndex()) const override; | ||
54 | Qt::ItemFlags flags(const QModelIndex& index) const override; | 60 | /** | ||
61 | * @brief index | ||||
62 | * @param row | ||||
63 | * @param column | ||||
64 | * @param parent | ||||
65 | * @return the index of for the data at row, column | ||||
66 | * if the data is a color entry, the internal pointer points to the group | ||||
67 | * the entry belongs to, and the row and column are row number and column | ||||
68 | * number inside the group. | ||||
69 | * if the data is a group, the row number and group number is Q_INFINIFY, | ||||
70 | * and the internal pointer also points to the group | ||||
71 | */ | ||||
55 | QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const override; | 72 | QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const override; | ||
56 | 73 | | |||
57 | void setColorSet(KoColorSet* colorSet); | 74 | Qt::ItemFlags flags(const QModelIndex& index) const override; | ||
58 | KoColorSet* colorSet() const; | | |||
59 | 75 | | |||
60 | /** | 76 | /** | ||
61 | * Installs a display renderer object for a palette that will | 77 | * @brief dropMimeData | ||
62 | * convert the KoColor to the displayable QColor. Default is the | 78 | * This is an overridden function that handles dropped mimedata. | ||
63 | * dumb renderer. | 79 | * right now only colorsetentries and colorsetgroups are handled. | ||
80 | * @return | ||||
64 | */ | 81 | */ | ||
65 | void setDisplayRenderer(KoColorDisplayRendererInterface *displayRenderer); | 82 | bool dropMimeData(const QMimeData *data, Qt::DropAction action, | ||
66 | 83 | int row, int column, const QModelIndex &parent) override; | |||
67 | /** | 84 | /** | ||
68 | * @brief indexFromId | 85 | * @brief mimeData | ||
69 | * convenience function to get the tableindex from the global palette color. | 86 | * gives the mimedata for a kocolorsetentry or a kocolorsetgroup. | ||
70 | * used by lazybrush. | 87 | * @param indexes | ||
71 | * @param i | 88 | * @return the mimedata for the given indices | ||
72 | * @return index in table. | | |||
73 | */ | 89 | */ | ||
74 | QModelIndex indexFromId(int i) const; | 90 | QMimeData *mimeData(const QModelIndexList &indexes) const override; | ||
91 | | ||||
92 | QStringList mimeTypes() const override; | ||||
93 | | ||||
94 | Qt::DropActions supportedDropActions() const override; | ||||
75 | /** | 95 | /** | ||
76 | * @brief idFromIndex | 96 | * @brief setData | ||
77 | * convenience function to get the global colorset entry id from the table index. | 97 | * setData is not used as KoColor is not a QVariant | ||
78 | * If you just want to use this to get the kocolorsetentry, use colorsetEntryFromIndex instead. | 98 | * use setEntry, addEntry and removeEntry instead | ||
79 | * @param index | | |||
80 | * @return | | |||
81 | */ | 99 | */ | ||
82 | int idFromIndex(const QModelIndex &index) const; | 100 | // TODO Used QVariant::setValue and QVariant.value<KoColor> to implement this | ||
101 | // bool setData(const QModelIndex &index, const QVariant &value, int role) override; | ||||
83 | 102 | | |||
103 | Q_SIGNALS: | ||||
104 | /** | ||||
105 | * @brief sigPaletteModified | ||||
106 | * emitted when palette associated with the model is modified | ||||
107 | */ | ||||
108 | void sigPaletteModified(); | ||||
84 | /** | 109 | /** | ||
85 | * @brief colorSetEntryFromIndex | 110 | * @brief sigPaletteChanged | ||
86 | * This gives the colorset entry for the given table model index. | 111 | * emitted when the palette associated with the model is made another one | ||
87 | * @param index the QModelIndex | | |||
88 | * @return the kocolorsetentry | | |||
89 | */ | 112 | */ | ||
90 | KoColorSetEntry colorSetEntryFromIndex(const QModelIndex &index) const; | 113 | void sigPaletteChanged(); | ||
91 | 114 | | |||
115 | public /* methods */: | ||||
92 | /** | 116 | /** | ||
93 | * @brief addColorSetEntry | 117 | * @brief addEntry | ||
94 | * proper function to handle adding entries. | 118 | * proper function to handle adding entries. | ||
95 | * @return whether successful. | 119 | * @return whether successful. | ||
96 | */ | 120 | */ | ||
97 | bool addColorSetEntry(KoColorSetEntry entry, QString groupName=QString()); | 121 | bool addEntry(const KisSwatch &entry, | ||
122 | const QString &groupName = KoColorSet::GLOBAL_GROUP_NAME); | ||||
123 | | ||||
124 | void setEntry(const KisSwatch &entry, const QModelIndex &index); | ||||
125 | | ||||
98 | /** | 126 | /** | ||
99 | * @brief removeEntry | 127 | * @brief removeEntry | ||
100 | * proper function to remove the colorsetentry at the given index. | 128 | * proper function to remove the colorsetentry at the given index. | ||
Context not available. | |||||
104 | * so hence the default is true. | 132 | * so hence the default is true. | ||
105 | * @return if successful | 133 | * @return if successful | ||
106 | */ | 134 | */ | ||
107 | bool removeEntry(QModelIndex index, bool keepColors=true); | 135 | bool removeEntry(const QModelIndex &index, bool keepColors=true); | ||
108 | /** | 136 | void removeGroup(const QString &groupName, bool keepColors); | ||
109 | * @brief addGroup | 137 | bool renameGroup(const QString &groupName, const QString &newName); | ||
110 | * Adds a group to the list. | 138 | void addGroup(const KisSwatchGroup &group); | ||
111 | * @param groupName | 139 | void setRowNumber(const QString &groupName, int rowCount); | ||
112 | * @return if successful | 140 | void clear(); | ||
113 | */ | | |||
114 | bool addGroup(QString groupName = QString()); | | |||
115 | 141 | | |||
116 | bool removeRows(int row, int count, const QModelIndex &parent) override; | 142 | KisSwatch getEntry(const QModelIndex &index) const; | ||
117 | 143 | | |||
118 | /** | 144 | void setPalette(KoColorSet* colorSet); | ||
119 | * @brief dropMimeData | 145 | KoColorSet* colorSet() const; | ||
120 | * This is an overridden function that handles dropped mimedata. | | |||
121 | * right now only colorsetentries and colorsetgroups are handled. | | |||
122 | * @return | | |||
123 | */ | | |||
124 | bool dropMimeData(const QMimeData *data, Qt::DropAction action, | | |||
125 | int row, int column, const QModelIndex &parent) override; | | |||
126 | /** | | |||
127 | * @brief mimeData | | |||
128 | * gives the mimedata for a kocolorsetentry or a kocolorsetgroup. | | |||
129 | * @param indexes | | |||
130 | * @return the mimedata for the given indices | | |||
131 | */ | | |||
132 | QMimeData *mimeData(const QModelIndexList &indexes) const override; | | |||
133 | | ||||
134 | QStringList mimeTypes() const override; | | |||
135 | | ||||
136 | Qt::DropActions supportedDropActions() const override; | | |||
137 | 146 | | |||
147 | QModelIndex indexForClosest(const KoColor &compare); | ||||
148 | int indexRowForInfo(const KisSwatchGroup::SwatchInfo &info); | ||||
138 | 149 | | |||
150 | public Q_SLOTS: | ||||
139 | 151 | | |||
140 | private Q_SLOTS: | 152 | private Q_SLOTS: | ||
141 | void slotDisplayConfigurationChanged(); | 153 | void slotDisplayConfigurationChanged(); | ||
154 | void slotPaletteModified(); | ||||
155 | | ||||
156 | private /* methods */: | ||||
157 | QVariant dataForGroupNameRow(const QModelIndex &idx, int role) const; | ||||
158 | QVariant dataForSwatch(const QModelIndex &idx, int role) const; | ||||
159 | int rowNumberInGroup(int rowInModel) const; | ||||
160 | int groupNameRowForRow(int rowInModel) const; | ||||
161 | int groupNameRowForName(const QString &groupName); | ||||
162 | void resetGroupNameRows(); | ||||
163 | /** | ||||
164 | * Installs a display renderer object for a palette that will | ||||
165 | * convert the KoColor to the displayable QColor. Default is the | ||||
166 | * dumb renderer. | ||||
167 | */ | ||||
168 | void setDisplayRenderer(const KoColorDisplayRendererInterface *displayRenderer); | ||||
169 | | ||||
170 | | ||||
171 | private /* member variables */: | ||||
172 | QPointer<KoColorSet> m_colorSet; | ||||
173 | QPointer<const KoColorDisplayRendererInterface> m_displayRenderer; | ||||
174 | QMap<int, QString> m_groupNameRows; | ||||
142 | 175 | | |||
143 | private: | 176 | friend class KisPaletteView; | ||
144 | KoColorSet* m_colorSet; | | |||
145 | QPointer<KoColorDisplayRendererInterface> m_displayRenderer; | | |||
146 | QModelIndex getLastEntryIndex(); | | |||
147 | }; | 177 | }; | ||
148 | 178 | | |||
149 | #endif | 179 | #endif | ||
Context not available. |