kdecore Library API Documentation

KPalette Class Reference

Class for handling Palettes. More...

#include <kpalette.h>

Collaboration diagram for KPalette:

Collaboration graph
[legend]
List of all members.

Public Types

enum  Editable { Yes, No, Ask }
 Used to specify whether a palette may be edited. More...


Public Member Functions

 KPalette (const QString &name=QString::null)
 KPalette constructor.

 KPalette (const KPalette &)
 KPalette copy constructor.

virtual ~KPalette ()
 KPalette destructor.

KPaletteoperator= (const KPalette &)
 KPalette assignment operator.

bool save ()
 Save the palette.

QString description () const
 Get the description of the palette.

void setDescription (const QString &desc)
 Set the description of the palette.

QString name () const
 Get the name of the palette.

void setName (const QString &name)
 Set the name of the palette.

Editable editable () const
 Returns whether the palette may be edited.

void setEditable (Editable editable)
 Change whether the palette may be edited.

int nrColors () const
 Return the number of colors in the palette.

QColor color (int index)
 Find color by index.

int findColor (const QColor &color) const
 Find index by color.

QString colorName (int index)
 Find color name by index.

QString colorName (const QColor &color)
 Find color name by color.

int addColor (const QColor &newColor, const QString &newColorName=QString::null)
 Add a color.

int changeColor (int index, const QColor &newColor, const QString &newColorName=QString::null)
 Change a color.

int changeColor (const QColor &oldColor, const QColor &newColor, const QString &newColorName=QString::null)
 Change a color.


Static Public Member Functions

QStringList getPaletteList ()
 Query which KDE palettes are installed.


Detailed Description

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 QPalette.

Author:
Waldo Bastian (bastian@kde.org)
Version:
Id
kpalette.h,v 1.8 2002/09/19 19:39:49 tjansen Exp

Definition at line 46 of file kpalette.h.


Member Enumeration Documentation

enum KPalette::Editable
 

Used to specify whether a palette may be edited.

See also:
editable()

setEditable()

Enumeration values:
Yes  Palette may be edited.
No  Palette may not be edited.
Ask  Ask user before editing.

Definition at line 118 of file kpalette.h.

Referenced by editable().


Constructor & Destructor Documentation

KPalette::KPalette const QString name = QString::null  ) 
 

KPalette constructor.

Creates a KPalette from a file the filename is derived from the name.

Parameters:
name The name of palette as returned by getPaletteList()

Definition at line 50 of file kpalette.cpp.

References QPtrList< kolor >::append(), QString::ascii(), QFile::exists(), QString::find(), QString::isEmpty(), QString::mid(), KStdAction::name(), QFile::open(), QFile::readLine(), QPtrList< kolor >::setAutoDelete(), and QString::stripWhiteSpace().

KPalette::KPalette const KPalette  ) 
 

KPalette copy constructor.

Definition at line 112 of file kpalette.cpp.

References QPtrList< kolor >::append(), QPtrList::first(), QPtrList::next(), and QPtrList< kolor >::setAutoDelete().

KPalette::~KPalette  )  [virtual]
 

KPalette destructor.

Definition at line 126 of file kpalette.cpp.


Member Function Documentation

QStringList KPalette::getPaletteList  )  [static]
 

Query which KDE palettes are installed.

Returns:
A list with a palette names.

Definition at line 34 of file kpalette.cpp.

References KGlobal::dirs(), and KStandardDirs::findAllResources().

KPalette & KPalette::operator= const KPalette  ) 
 

KPalette assignment operator.

Definition at line 159 of file kpalette.cpp.

References QPtrList< kolor >::append(), QPtrList< kolor >::clear(), QPtrList::first(), mDesc, mEditable, mKolorList, mName, and QPtrList::next().

bool KPalette::save  ) 
 

Save the palette.

Returns:
'true' if successful

Definition at line 132 of file kpalette.cpp.

References KSaveFile::close(), KStdAccel::description(), description(), QPtrList::first(), QPtrList::next(), QStringList::split(), KSaveFile::status(), QString::stripWhiteSpace(), and KSaveFile::textStream().

QString KPalette::description  )  const [inline]
 

Get the description of the palette.

Returns:
the description of the palette.

Definition at line 89 of file kpalette.h.

Referenced by save().

void KPalette::setDescription const QString desc  )  [inline]
 

Set the description of the palette.

Parameters:
desc the new description

Definition at line 96 of file kpalette.h.

QString KPalette::name  )  const [inline]
 

Get the name of the palette.

Returns:
the name of the palette

Definition at line 103 of file kpalette.h.

void KPalette::setName const QString name  )  [inline]
 

Set the name of the palette.

Parameters:
name the name of the palette

Definition at line 110 of file kpalette.h.

References KStdAction::name().

Editable KPalette::editable  )  const [inline]
 

Returns whether the palette may be edited.

Returns:
the state of the palette

Definition at line 127 of file kpalette.h.

References Editable.

void KPalette::setEditable Editable  editable  )  [inline]
 

Change whether the palette may be edited.

Parameters:
editable the state of the palette

Definition at line 134 of file kpalette.h.

int KPalette::nrColors  )  const [inline]
 

Return the number of colors in the palette.

Returns:
the number of colors

Definition at line 141 of file kpalette.h.

References QPtrList< kolor >::count().

Referenced by addColor(), changeColor(), color(), and colorName().

QColor KPalette::color int  index  ) 
 

Find color by index.

Parameters:
index the index of the desired color
Returns:
The index -th color of the palette, null if not found.

Definition at line 178 of file kpalette.cpp.

References QPtrList< kolor >::at(), and nrColors().

int KPalette::findColor const QColor color  )  const
 

Find index by color.

Parameters:
color the color to find
Returns:
The index of the color in the palette or -1 if the color is not found.

Definition at line 191 of file kpalette.cpp.

References QPtrListIterator::current().

Referenced by changeColor(), and colorName().

QString KPalette::colorName int  index  ) 
 

Find color name by index.

Parameters:
the index of the color
Returns:
The name of the 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.

Definition at line 204 of file kpalette.cpp.

References QPtrList< kolor >::at(), and nrColors().

Referenced by colorName().

QString KPalette::colorName const QColor color  )  [inline]
 

Find color name by color.

Returns:
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.

Definition at line 175 of file kpalette.h.

References colorName(), and findColor().

int KPalette::addColor const QColor newColor,
const QString newColorName = QString::null
 

Add a color.

Parameters:
newColor The color to add.
newColorName The name of the color, null to remove the name.
Returns:
The index of the added color.

Definition at line 217 of file kpalette.cpp.

References QPtrList< kolor >::append(), QColor::name(), and nrColors().

int KPalette::changeColor int  index,
const QColor newColor,
const QString newColorName = QString::null
 

Change a color.

Parameters:
index Index of the color to change
newColor The new color.
newColorName The new color name, null to remove the name.
Returns:
The index of the new color or -1 if the color couldn't be changed.

Definition at line 227 of file kpalette.cpp.

References QPtrList< kolor >::at(), QColor::name(), and nrColors().

Referenced by changeColor().

int KPalette::changeColor const QColor oldColor,
const QColor newColor,
const QString newColorName = QString::null
[inline]
 

Change a color.

Parameters:
oldColor The original color
newColor The new color.
newColorName The new color name, null to remove the name.
Returns:
The index of the new color or -1 if the color couldn't be changed.

Definition at line 210 of file kpalette.h.

References changeColor(), and findColor().


The documentation for this class was generated from the following files:
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 12:50:27 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001