1 /*  This file is part of the KDE project
2     Copyright (c) 2005 Boudewijn Rempt <boud@valdyas.org>
3 
4     This library is free software; you can redistribute it and/or
5     modify it under the terms of the GNU Lesser General Public
6     License as published by the Free Software Foundation; either
7     version 2.1 of the License, or (at your option) any later version.
8 
9     This library 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 GNU
12     Lesser General Public License for more details.
13 
14     You should have received a copy of the GNU Lesser General Public
15     License along with this library; if not, write to the Free Software
16     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
17 
18  */
19 #ifndef KOCOLORSET
20 #define KOCOLORSET
21 
22 #include <QObject>
23 #include <QColor>
24 #include <QVector>
25 
26 #include "KoResource.h"
27 #include "KoColor.h"
28 
29 struct KoColorSetEntry {
30     KoColor color;
31     QString name;
32     bool operator==(const KoColorSetEntry& rhs) const {
33         return color == rhs.color && name == rhs.name;
34     }
35 };
36 
37 /**
38  * Open Gimp, Photoshop or RIFF palette files. This is a straight port
39  * from the Gimp.
40  */
41 class PIGMENTCMS_EXPORT KoColorSet : public QObject, public KoResource
42 {
43     Q_OBJECT
44 public:
45 
46     enum PaletteType {
47         UNKNOWN = 0,
48         GPL,                // GIMP
49         RIFF_PAL,           // RIFF
50         ACT,                // Photoshop binary
51         PSP_PAL,            // PaintShop Pro
52         ACO                 // Photoshop Swatches
53     };
54 
55 
56     /**
57      * Load a color set from a file. This can be a Gimp
58      * palette, a RIFF palette or a Photoshop palette.
59      */
60     explicit KoColorSet(const QString &filename);
61 
62     /// Create an empty color set
63     KoColorSet();
64 
65     /// Explicit copy constructor (KoResource copy constructor is private)
66     KoColorSet(const KoColorSet& rhs);
67 
68     ~KoColorSet() override;
69 
70     bool load() override;
71     bool loadFromDevice(QIODevice *dev) override;
72     bool save() override;
73     bool saveToDevice(QIODevice* dev) const override;
74 
75     QString defaultFileExtension() const override;
76 
77     void setColumnCount(int columns);
78     int columnCount();
79 
80 public:
81 
82     void add(const KoColorSetEntry &);
83     void remove(const KoColorSetEntry &);
84     void removeAt(quint32 index);
85     KoColorSetEntry getColor(quint32 index);
86     qint32 nColors();
87 
88 private:
89 
90 
91     bool init();
92 
93     bool loadGpl();
94     bool loadAct();
95     bool loadRiff();
96     bool loadPsp();
97     bool loadAco();
98 
99     QByteArray m_data;
100     bool m_ownData;
101     QString m_name;
102     QString m_comment;
103     qint32 m_columns;
104     QVector<KoColorSetEntry> m_colors;
105 
106 };
107 #endif // KOCOLORSET
108 
109