2
This source file is part of Konsole, a terminal emulator.
4
Copyright 2007-2008 by Robert Knight <robertknight@gmail.com>
6
This program is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2 of the License, or
9
(at your option) any later version.
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
GNU General Public License for more details.
16
You should have received a copy of the GNU General Public License
17
along with this program; if not, write to the Free Software
18
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
34
#include "CharacterColor.h"
43
* Represents a color scheme for a terminal display.
45
* The color scheme includes the palette of colors used to draw the text and character backgrounds
46
* in the display and the opacity level of the display background.
52
* Constructs a new color scheme which is initialised to the default color set
56
ColorScheme(const ColorScheme& other);
59
/** Sets the descriptive name of the color scheme. */
60
void setDescription(const QString& description);
61
/** Returns the descriptive name of the color scheme. */
62
QString description() const;
64
/** Sets the name of the color scheme */
65
void setName(const QString& name);
66
/** Returns the name of the color scheme */
70
// Implemented upstream - in user apps
71
/** Reads the color scheme from the specified configuration source */
72
void read(KConfig& config);
73
/** Writes the color scheme to the specified configuration source */
74
void write(KConfig& config) const;
76
void read(const QString & filename);
78
/** Sets a single entry within the color palette. */
79
void setColorTableEntry(int index , const ColorEntry& entry);
82
* Copies the color entries which form the palette for this color scheme
83
* into @p table. @p table should be an array with TABLE_COLORS entries.
85
* @param table Array into which the color entries for this color scheme
87
* @param randomSeed Color schemes may allow certain colors in their
88
* palette to be randomized. The seed is used to pick the random color.
90
void getColorTable(ColorEntry* table, uint randomSeed = 0) const;
93
* Retrieves a single color entry from the table.
97
ColorEntry colorEntry(int index , uint randomSeed = 0) const;
100
* Convenience method. Returns the
101
* foreground color for this scheme,
102
* this is the primary color used to draw the
103
* text in this scheme.
105
QColor foregroundColor() const;
107
* Convenience method. Returns the background color for
108
* this scheme, this is the primary color used to
109
* draw the terminal background in this scheme.
111
QColor backgroundColor() const;
114
* Returns true if this color scheme has a dark background.
115
* The background color is said to be dark if it has a value of less than 127
116
* in the HSV color space.
118
bool hasDarkBackground() const;
121
* Sets the opacity level of the display background. @p opacity ranges
122
* between 0 (completely transparent background) and 1 (completely
123
* opaque background).
127
* TODO: More documentation
129
void setOpacity(qreal opacity);
131
* Returns the opacity level for this color scheme, see setOpacity()
132
* TODO: More documentation
134
qreal opacity() const;
137
* Enables randomization of the background color. This will cause
138
* the palette returned by getColorTable() and colorEntry() to
139
* be adjusted depending on the value of the random seed argument
142
void setRandomizedBackgroundColor(bool randomize);
144
/** Returns true if the background color is randomized. */
145
bool randomizedBackgroundColor() const;
147
static QString colorNameForIndex(int index);
148
static QString translatedColorNameForIndex(int index);
151
// specifies how much a particular color can be randomized by
152
class RandomizationRange
155
RandomizationRange() : hue(0) , saturation(0) , value(0) {}
159
return ( hue == 0 && saturation == 0 && value == 0 );
167
// returns the active color table. if none has been set specifically,
168
// this is the default color table.
169
const ColorEntry* colorTable() const;
172
// implemented upstream - user apps
173
// reads a single colour entry from a KConfig source
174
// and sets the palette entry at 'index' to the entry read.
175
void readColorEntry(KConfig& config , int index);
176
// writes a single colour entry to a KConfig source
177
void writeColorEntry(KConfig& config , const QString& colorName, const ColorEntry& entry,const RandomizationRange& range) const;
179
void readColorEntry(QSettings *s, int index);
181
// sets the amount of randomization allowed for a particular color
182
// in the palette. creates the randomization table if
183
// it does not already exist
184
void setRandomizationRange( int index , quint16 hue , quint8 saturation , quint8 value );
186
QString _description;
189
ColorEntry* _table; // pointer to custom color table or 0 if the default
190
// color scheme is being used
193
static const quint16 MAX_HUE = 340;
195
RandomizationRange* _randomTable; // pointer to randomization table or 0
196
// if no colors in the color scheme support
199
static const char* const colorNames[TABLE_COLORS];
200
static const char* const translatedColorNames[TABLE_COLORS];
202
static const ColorEntry defaultTable[]; // table of default color entries
206
* A color scheme which uses colors from the standard KDE color palette.
208
* This is designed primarily for the benefit of users who are using specially
211
* TODO Implement and make it the default on systems with specialized KDE
214
class AccessibleColorScheme : public ColorScheme
217
AccessibleColorScheme();
221
* Reads a color scheme stored in the .schema format used in the KDE 3 incarnation
224
* Only the basic essentials ( title and color palette entries ) are currently
225
* supported. Additional options such as background image and background
226
* blend colors are ignored.
228
class KDE3ColorSchemeReader
232
* Constructs a new reader which reads from the specified device.
233
* The device should be open in read-only mode.
235
KDE3ColorSchemeReader( QIODevice* device );
238
* Reads and parses the contents of the .schema file from the input
239
* device and returns the ColorScheme defined within it.
241
* Returns a null pointer if an error occurs whilst parsing
242
* the contents of the file.
247
// reads a line from the file specifying a colour palette entry
248
// format is: color [index] [red] [green] [blue] [transparent] [bold]
249
bool readColorLine(const QString& line , ColorScheme* scheme);
250
bool readTitleLine(const QString& line , ColorScheme* scheme);
256
* Manages the color schemes available for use by terminal displays.
259
class ColorSchemeManager
264
* Constructs a new ColorSchemeManager and loads the list
265
* of available color schemes.
267
* The color schemes themselves are not loaded until they are first
268
* requested via a call to findColorScheme()
270
ColorSchemeManager();
272
* Destroys the ColorSchemeManager and saves any modified color schemes to disk.
274
~ColorSchemeManager();
277
* Returns the default color scheme for Konsole
279
const ColorScheme* defaultColorScheme() const;
282
* Returns the color scheme with the given name or 0 if no
283
* scheme with that name exists. If @p name is empty, the
284
* default color scheme is returned.
286
* The first time that a color scheme with a particular name is
287
* requested, the configuration information is loaded from disk.
289
const ColorScheme* findColorScheme(const QString& name);
293
* Adds a new color scheme to the manager. If @p scheme has the same name as
294
* an existing color scheme, it replaces the existing scheme.
296
* TODO - Ensure the old color scheme gets deleted
298
void addColorScheme(ColorScheme* scheme);
301
* Deletes a color scheme. Returns true on successful deletion or false otherwise.
303
bool deleteColorScheme(const QString& name);
306
* Returns a list of the all the available color schemes.
307
* This may be slow when first called because all of the color
308
* scheme resources on disk must be located, read and parsed.
310
* Subsequent calls will be inexpensive.
312
QList<const ColorScheme*> allColorSchemes();
314
/** Returns the global color scheme manager instance. */
315
static ColorSchemeManager* instance();
317
/** @brief Loads a custom color scheme under given \em path.
319
* The \em path may refer to either KDE 4 .colorscheme or KDE 3
322
* The loaded color scheme is available under the name equal to
323
* the base name of the \em path via the allColorSchemes() and
324
* findColorScheme() methods after this call if loaded successfully.
326
* @param[in] path The path to KDE 4 .colorscheme or KDE 3 .schema.
327
* @return Whether the color scheme is loaded successfully.
329
bool loadCustomColorScheme(const QString& path);
331
// loads a color scheme from a KDE 4+ .colorscheme file
332
bool loadColorScheme(const QString& path);
333
// loads a color scheme from a KDE 3 .schema file
334
bool loadKDE3ColorScheme(const QString& path);
335
// returns a list of paths of color schemes in the KDE 4+ .colorscheme file format
336
QList<QString> listColorSchemes();
337
// returns a list of paths of color schemes in the .schema file format
339
QList<QString> listKDE3ColorSchemes();
340
// loads all of the color schemes
341
void loadAllColorSchemes();
342
// finds the path of a color scheme
343
QString findColorSchemePath(const QString& name) const;
345
QHash<QString,const ColorScheme*> _colorSchemes;
346
QSet<ColorScheme*> _modifiedSchemes;
350
static const ColorScheme _defaultColorScheme;
352
static ColorSchemeManager * theColorSchemeManager;
357
Q_DECLARE_METATYPE(const Konsole::ColorScheme*)
359
#endif //COLORSCHEME_H