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