summaryrefslogtreecommitdiffstats
path: root/kcoloredit/palette.h
blob: a363ada4b2bc479b53c2503d4e3b32ef805434ab (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
/***************************************************************************
                          palette.h  -  description
                             -------------------
    begin                : Sat Jul 8 2000
    copyright            : (C) 2000 by Artur Rataj
    email                : art@zeus.polsl.gliwice.pl
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef PALETTE_H
#define PALETTE_H

#include <tqstring.h>
#include <tqtextstream.h>
#include <tqfile.h>

#include "color.h"

/**This class holds a palette.
  *@author Artur Rataj
  */
class Palette {
public:
	/** Constructs an empty palette */
	Palette();
	/** The copy constructor */
	Palette(const Palette& palette);
	~Palette();
	/** @return A list of KDE palettes */
	static TQStringList kdePalettes();
	/** sets palette name */
	void setName(const TQString& name);
	/** @return palette name */
	const TQString& name() const;
	/** inserts a color at a given position */
	void insert(const int index, Color* const color);
	/** appends a color */
	void append(Color* const color);
	/** removes a color at index */
	void remove(const int index);
	/** @return the number of colors */
	int length() const;
	/** @return color at index */
	Color* color(const int index);
	/** @return a copy of palette at index, of length length */
	Palette copy(const int index, const int length);
	/** cuts a palette at index, of length length
	 *  @return a palette that has been cut out
	 */
	Palette cut(const int index, const int length);
	/** pastes a palette at index */
	void paste(const int index, Palette& palette);
	/** Loads a palette from a text stream
	 *  @return whether the load was succesfull
	 */
	bool load(TQTextStream& stream, bool loadName = true);
	/** Loads a palette from a file.
	 *  If loadName is true, palette name is expected.
	 *  @return whether the load was succesfull
	 */
	bool load(const TQString& fileName);
	/** Saves a palette into a text stream.
	 *  If file is given, it is checked for IO errors.
	 *  If saveName is true, palette name is saved.
	 *  @return whether save was succesfull
	 */
	bool save(TQTextStream& stream, const TQFile* file = 0, bool saveName = true);
	/** Saves a palette to a file
	 *  @return whether save was succesfull
	 */
	bool save(const TQString& fileName);
	/** Deletes contents of the palette */
	void deleteContents();
	/** @return A possible error description from the last unsuccessfull
	 *  IO operation
	 */
	const TQString& errorString() const;

private:
	/** The palette name */
	TQString m_name;

private:
	/** Initialization method called by constructors */
	void init();

protected:
	/** A list of palette colors */
	TQPtrList<Color> colors;
	/** An IO error description */
	TQString m_errorString;
};

#endif