1 /*  This file is part of the KDE project
2     Copyright (c) 2005 Boudewijn Rempt <boud@valdyas.org>
3     Copyright (c) 2016 L. E. Segovia <amy@amyspark.me>
4     Copyright (c) 2018 Michael Zhou <simerixh@gmail.com>
5 
6     This library is free software; you can redistribute it and/or
7     modify it under the terms of the GNU Lesser General Public
8     License as published by the Free Software Foundation; either
9     version 2.1 of the License, or (at your option) any later version.
10 
11     This library is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14     Lesser General Public License for more details.
15 
16     You should have received a copy of the GNU Lesser General Public
17     License along with this library; if not, write to the Free Software
18     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
19 
20  */
21 
22 #ifndef KISSWATCHGROUP_H
23 #define KISSWATCHGROUP_H
24 
25 #include "KisSwatch.h"
26 
27 #include "kritapigment_export.h"
28 
29 #include <QVector>
30 #include <QList>
31 #include <QMap>
32 #include <QScopedPointer>
33 
34 /**
35  * @brief The KisSwatchGroup class stores a matrix of color swatches
36  * swatches can accessed using (x, y) coordinates.
37  * x is the column number from left to right and y is the row number from top
38  * to bottom.
39  * Both x and y start at 0
40  * there could be empty entries, so the checkEntry(int, int) method must used
41  * whenever you want to get an entry from the matrix
42  */
43 class KRITAPIGMENT_EXPORT KisSwatchGroup
44 {
45 public /* struct */:
46     struct SwatchInfo {
47         QString group;
48         KisSwatch swatch;
49         int row;
50         int column;
51     };
52 
53 public:
54     KisSwatchGroup();
55     ~KisSwatchGroup();
56     KisSwatchGroup(const KisSwatchGroup &rhs);
57     KisSwatchGroup &operator =(const KisSwatchGroup &rhs);
58 
59 public /* methods */:
60     void setName(const QString &name);
61     QString name() const;
62 
63     void setColumnCount(int columnCount);
64     int columnCount() const;
65 
66     void setRowCount(int newRowCount);
67     int rowCount() const;
68 
69     int colorCount() const;
70 
71     /**
72      * @brief getColors
73      * @return the list of colors in this SwatchGroup, in no specific order.
74      */
75     QList<SwatchInfo> infoList() const;
76 
77     /**
78      * @brief checkEntry
79      * checks if position @p column and @p row has a valid entry
80      * both @p column and @p row start from 0
81      * @param column
82      * @param row
83      * @return true if there is a valid entry at position (column, row)
84      */
85     bool checkEntry(int column, int row) const;
86     /**
87      * @brief setEntry
88      * sets the entry at position (@p column, @p row) to be @p e
89      * @param e
90      * @param column
91      * @param row
92      */
93     void setEntry(const KisSwatch &e, int column, int row);
94     /**
95      * @brief getEntry
96      * used to get the swatch entry at position (@p column, @p row)
97      * there is an assertion to make sure that this position isn't empty,
98      * so checkEntry(int, int) must be used before this method to ensure
99      * a valid entry can be found
100      * @param column
101      * @param row
102      * @return the swatch entry at position (column, row)
103      */
104     KisSwatch getEntry(int column, int row) const;
105     /**
106      * @brief removeEntry
107      * removes the entry at position (@p column, @p row)
108      * @param column
109      * @param row
110      * @return true if these is an entry at (column, row)
111      */
112     bool removeEntry(int column, int row);
113     /**
114      * @brief addEntry
115      * adds the entry e to the right of the rightmost entry in the last row
116      * if the rightmost entry in the last row is in the right most column,
117      * add e to the leftmost column of a new row
118      *
119      * when column is set to 0, resize number of columns to default
120      * @param e
121      */
122     void addEntry(const KisSwatch &e);
123 
124     void clear();
125 
126 private /* member variables */:
127     struct Private;
128     QScopedPointer<Private> d;
129 };
130 
131 #endif // KISSWATCHGROUP_H
132