You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
229 lines
6.1 KiB
229 lines
6.1 KiB
15 years ago
|
/* 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
|
||
|
|
||
15 years ago
|
#include <tqcolor.h>
|
||
|
#include <tqptrlist.h>
|
||
|
#include <tqstring.h>
|
||
|
#include <tqstringlist.h>
|
||
15 years ago
|
#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.
|
||
|
*
|
||
15 years ago
|
* This class is totally unrelated to TQPalette.
|
||
15 years ago
|
*
|
||
|
* @author Waldo Bastian (bastian@kde.org)
|
||
|
**/
|
||
|
class KDECORE_EXPORT KPalette
|
||
|
{
|
||
|
public:
|
||
|
/**
|
||
|
* Query which KDE palettes are installed.
|
||
|
*
|
||
|
* @return A list with a palette names.
|
||
|
*/
|
||
15 years ago
|
static TQStringList getPaletteList();
|
||
15 years ago
|
|
||
|
/**
|
||
|
* 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()
|
||
|
**/
|
||
15 years ago
|
KPalette(const TQString &name=TQString::null);
|
||
15 years ago
|
|
||
|
/**
|
||
|
* 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.
|
||
|
**/
|
||
15 years ago
|
TQString description() const
|
||
15 years ago
|
{ return mDesc; }
|
||
|
|
||
|
/**
|
||
|
* Set the description of the palette.
|
||
|
* @param desc the new description
|
||
|
**/
|
||
15 years ago
|
void setDescription(const TQString &desc)
|
||
15 years ago
|
{ mDesc = desc; }
|
||
|
|
||
|
/**
|
||
|
* Get the name of the palette.
|
||
|
* @return the name of the palette
|
||
|
**/
|
||
15 years ago
|
TQString name() const
|
||
15 years ago
|
{ return mName; }
|
||
|
|
||
|
/**
|
||
|
* Set the name of the palette.
|
||
|
* @param name the name of the palette
|
||
|
**/
|
||
15 years ago
|
void setName(const TQString &name)
|
||
15 years ago
|
{ 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.
|
||
|
**/
|
||
15 years ago
|
TQColor color(int index);
|
||
15 years ago
|
|
||
|
/**
|
||
|
* Find index by @p color.
|
||
14 years ago
|
* @param color the color to find
|
||
15 years ago
|
* @return The index of the color in the palette or -1 if the
|
||
|
* color is not found.
|
||
|
**/
|
||
15 years ago
|
int findColor(const TQColor &color) const;
|
||
15 years ago
|
|
||
|
/**
|
||
|
* 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.
|
||
|
**/
|
||
15 years ago
|
TQString colorName(int index);
|
||
15 years ago
|
|
||
|
/**
|
||
|
* 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.
|
||
|
**/
|
||
15 years ago
|
TQString colorName(const TQColor &color)
|
||
15 years ago
|
{ 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.
|
||
|
**/
|
||
15 years ago
|
int addColor(const TQColor &newColor,
|
||
|
const TQString &newColorName = TQString::null);
|
||
15 years ago
|
|
||
|
/**
|
||
|
* 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,
|
||
15 years ago
|
const TQColor &newColor,
|
||
|
const TQString &newColorName = TQString::null);
|
||
15 years ago
|
|
||
|
/**
|
||
|
* 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.
|
||
|
**/
|
||
15 years ago
|
int changeColor(const TQColor &oldColor,
|
||
|
const TQColor &newColor,
|
||
|
const TQString &newColorName = TQString::null)
|
||
15 years ago
|
{ return changeColor( findColor(oldColor), newColor, newColorName); }
|
||
|
|
||
|
private:
|
||
15 years ago
|
typedef struct { TQColor color; TQString name; } kolor;
|
||
|
TQPtrList<kolor> mKolorList;
|
||
15 years ago
|
|
||
15 years ago
|
TQString mName;
|
||
|
TQString mDesc;
|
||
15 years ago
|
Editable mEditable;
|
||
|
|
||
|
KPalettePrivate *d;
|
||
|
};
|
||
|
|
||
|
|
||
|
#endif // KDELIBS_KPALETTE_H
|
||
|
|