summaryrefslogtreecommitdiffstats
path: root/kdecore/kpalette.h
blob: a7dd5e946caf57f97110ab8d810e0e9f139028a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
/* This file is part of the KDE libraries
    Copyright (C) 1999 Waldo Bastian (bastian@kde.org)

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; version 
    2 of the License.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
    Boston, MA 02110-1301, USA.
*/
//-----------------------------------------------------------------------------
// KDE color palette.

#ifndef KDELIBS_KPALETTE_H
#define KDELIBS_KPALETTE_H

#include <tqcolor.h>
#include <tqptrlist.h>
#include <tqstring.h>
#include <tqstringlist.h>
#include "kdelibs_export.h"

class KPalettePrivate;

/**
 * Class for handling Palettes.
 *
 * This class makes it easy to handle palettes.
 * A palette is a set of colors. This class can read
 * and write palettes from and to a file.
 *
 * This class uses the "GIMP" palette file format.
 *
 * This class is totally unrelated to TQPalette.
 *
 * @author Waldo Bastian (bastian@kde.org)
 **/
class KDECORE_EXPORT KPalette
{
public:
   /**
    * Query which KDE palettes are installed.
    *
    * @return A list with a palette names.
    */
   static TQStringList getPaletteList();

   /**
    * KPalette constructor. Creates a KPalette from a file
    * the filename is derived from the name.
    * @param name The name of palette as returned by getPaletteList()
    **/
   KPalette(const TQString &name=TQString::null);

   /**
    * KPalette copy constructor.
    **/
   KPalette(const KPalette &);

   /**
    * KPalette destructor.
    **/
   virtual ~KPalette();
   
   /**
    * KPalette assignment operator
    **/
   KPalette& operator=( const KPalette &);

   /**
    * Save the palette
    *
    * @return 'true' if successful
    **/
   bool save();

   /**
    * Get the description of the palette.
    * @return the description of the palette.
    **/
   TQString description() const
   	{ return mDesc; }

   /**   	
    * Set the description of the palette.
    * @param desc the new description
    **/
   void setDescription(const TQString &desc)
   	{ mDesc = desc; }
   
   /**
    * Get the name of the palette. 
    * @return the name of the palette
    **/
   TQString name() const
   	{ return mName; }

   /**
    * Set the name of the palette.
    * @param name the name of the palette
    **/
   void setName(const TQString &name)
   	{ mName = name; }

   /**
    * Used to specify whether a palette may be edited.
    * @see editable()
    * @see setEditable()
    */
   enum Editable { Yes, ///< Palette may be edited 
		   No,  ///< Palette may not be edited
		   Ask  ///< Ask user before editing
   };
  
   /**
    * Returns whether the palette may be edited.
    * @return the state of the palette
    **/
   Editable editable() const
   	{ return mEditable; }

   /**
    * Change whether the palette may be edited.
    * @param editable the state of the palette
    **/
   void setEditable(Editable editable)
   	{ mEditable = editable; }
   
   /**
    * Return the number of colors in the palette.
    * @return the number of colors
    **/
   int nrColors() const
   	{ return (int) mKolorList.count(); }

   /**
    * Find color by index.
    * @param index the index of the desired color
    * @return The @p index -th color of the palette, null if not found.
    **/
   TQColor color(int index);
   
   /**
    * Find index by @p color.
    * @param color the color to tqfind
    * @return The index of the color in the palette or -1 if the
    * color is not found.
    **/
   int findColor(const TQColor &color) const;

   /**
    * Find color name by @p index.
    * @param index the index of the color
    * @return The name of the @p index -th color.
    * Note that not all palettes have named the colors. Null is
    * returned if the color does not exist or has no name.
    **/
   TQString colorName(int index);
   
   /**
    * Find color name by @p color.
    * @return The name of color according to this palette.
    * Note that not all palettes have named the colors.
    * Note also that each palette can give the same color
    * a different name.
    **/
   TQString colorName(const TQColor &color)
   	{ return colorName( findColor(color)); }
   
   /**
    * Add a color.
    * @param newColor The color to add.
    * @param newColorName The name of the color, null to remove 
    *                     the name.
    * @return The index of the added color.
    **/
   int addColor(const TQColor &newColor, 
                const TQString &newColorName = TQString::null);

   /**
    * Change a color.
    * @param index Index of the color to change
    * @param newColor The new color.
    * @param newColorName The new color name, null to remove 
    *                     the name.
    * @return The index of the new color or -1 if the color couldn't
    * be changed.
    **/
   int changeColor(int index, 
                   const TQColor &newColor, 
                   const TQString &newColorName = TQString::null);
 
   /**
    * Change a color.
    * @param oldColor The original color
    * @param newColor The new color.
    * @param newColorName The new color name, null to remove 
    *                     the name.
    * @return The index of the new color or -1 if the color couldn't
    * be changed.
    **/
   int changeColor(const TQColor &oldColor, 
                   const TQColor &newColor, 
                   const TQString &newColorName = TQString::null)
   	{ return changeColor( findColor(oldColor), newColor, newColorName); }

private:   
   typedef struct { TQColor color; TQString name; } kolor;
   TQPtrList<kolor> mKolorList;
   
   TQString mName;
   TQString mDesc;
   Editable mEditable;

   KPalettePrivate *d;
};


#endif		// KDELIBS_KPALETTE_H