25 #include <tqtextstream.h> 26 #include <kstandarddirs.h> 28 #include <ksavefile.h> 29 #include <kstringhandler.h> 31 template class TQPtrList<KPalette::kolor>;
36 TQStringList paletteList;
39 int strip = strlen(
"colors/");
40 for(TQStringList::Iterator it = paletteList.begin();
41 it != paletteList.end();
44 (*it) = (*it).mid(strip);
53 mKolorList.setAutoDelete(
true);
54 if (mName.isEmpty())
return;
56 TQString filename = locate(
"config",
"colors/"+mName);
57 if (filename.isEmpty())
return;
59 TQFile paletteFile(filename);
60 if (!paletteFile.exists())
return;
61 if (!paletteFile.open(IO_ReadOnly))
return;
63 uint maxLength = 1024;
68 if (paletteFile.readLine(line, maxLength) == -1)
return;
69 if (line.find(
" Palette") == -1)
return;
71 while( paletteFile.readLine(line, maxLength) != -1)
77 line = line.stripWhiteSpace();
86 line = line.stripWhiteSpace();
87 if (line.isEmpty())
continue;
90 if (sscanf(line.ascii(),
"%d %d %d%n", &red, &green, &blue, &pos) >= 3)
92 if (red > 255) red = 255;
94 if (green > 255) green = 255;
95 if (green < 0) green = 0;
96 if (blue > 255) blue = 255;
97 if (blue < 0) blue = 0;
98 kolor *node =
new kolor();
99 node->color.setRgb(red, green, blue);
100 node->name = line.mid(pos).stripWhiteSpace();
101 if (node->name.isNull()) node->name =
"";
102 mKolorList.append( node );
109 : mName(p.mName), mDesc(p.mDesc), mEditable(p.mEditable)
111 mKolorList.setAutoDelete(
true);
115 TQPtrList<kolor> *nonConstList = (TQPtrList<kolor> *) &p.mKolorList;
116 for(kolor *node = nonConstList->first(); node; node = nonConstList->next())
118 mKolorList.append(
new kolor(*node));
130 TQString filename = locateLocal(
"config",
"colors/"+mName);
132 if (sf.
status() != 0)
return false;
137 description =
"#"+TQStringList::split(
"\n", description,
true).join(
"\n#");
139 (*str) <<
"KDE RGB Palette\n";
140 (*str) << description <<
"\n";
143 TQPtrList<kolor> *nonConstList = (TQPtrList<kolor> *) (&mKolorList);
144 for(kolor *node = nonConstList->first(); node; node = nonConstList->next())
147 node->color.rgb(&r, &g, &b);
148 (*str) << r <<
" " << g <<
" " << b <<
" " << node->name <<
"\n";
157 if (&p ==
this)
return *
this;
162 TQPtrList<kolor> *nonConstList = (TQPtrList<kolor> *) &p.mKolorList;
163 for(kolor *node = nonConstList->first(); node; node = nonConstList->next())
165 mKolorList.append(
new kolor(*node));
169 mEditable = p.mEditable;
176 if ((index < 0) || (index >=
nrColors()))
179 kolor *node = mKolorList.at(index);
190 TQPtrListIterator<kolor> it( mKolorList );
191 for (index = 0; it.current(); ++it, ++index)
193 if (it.current()->color ==
color)
202 if ((index < 0) || (index >=
nrColors()))
203 return TQString::null;
205 kolor *node = mKolorList.at(index);
207 return TQString::null;
215 kolor *node =
new kolor();
216 node->color = newColor;
217 node->name = newColorName;
218 mKolorList.append( node );
224 const TQColor &newColor,
225 const TQString &newColorName)
227 if ((index < 0) || (index >=
nrColors()))
230 kolor *node = mKolorList.at(index);
234 node->color = newColor;
235 node->name = newColorName;
TQTextStream * textStream()
A TQTextStream* open for writing to the file.
int findColor(const TQColor &color) const
Find index by color.
Class for handling Palettes.
KPalette(const TQString &name=TQString::null)
KPalette constructor.
virtual ~KPalette()
KPalette destructor.
The KSaveFile class has been made to write out changes to an existing file atomically.
int status() const
Returns the status of the file based on errno.
TQString description() const
Get the description of the palette.
bool close()
Closes the file and makes the changes definitive.
static KStandardDirs * dirs()
Returns the application standard dirs object.
TQColor color(int index)
Find color by index.
bool save()
Save the palette.
TQString name() const
Get the name of the palette.
int nrColors() const
Return the number of colors in the palette.
TQString colorName(int index)
Find color name by index.
int changeColor(int index, const TQColor &newColor, const TQString &newColorName=TQString::null)
Change a color.
static TQStringList getPaletteList()
Query which KDE palettes are installed.
KPalette & operator=(const KPalette &)
KPalette assignment operator.
TQStringList findAllResources(const char *type, const TQString &filter=TQString::null, bool recursive=false, bool unique=false) const
Tries to find all resources with the specified type.
int addColor(const TQColor &newColor, const TQString &newColorName=TQString::null)
Add a color.