26 #include <QtGui/QPainter>
30 #include <KLocalizedString>
31 #include <KConfigGroup>
35 const int FGCOLOR_INDEX = 0;
36 const int BGCOLOR_INDEX = 1;
39 using namespace Konsole;
68 const char*
const ColorScheme::colorNames[
TABLE_COLORS] = {
90 const char*
const ColorScheme::translatedColorNames[
TABLE_COLORS] = {
91 I18N_NOOP2(
"@item:intable palette",
"Foreground"),
92 I18N_NOOP2(
"@item:intable palette",
"Background"),
93 I18N_NOOP2(
"@item:intable palette",
"Color 1"),
94 I18N_NOOP2(
"@item:intable palette",
"Color 2"),
95 I18N_NOOP2(
"@item:intable palette",
"Color 3"),
96 I18N_NOOP2(
"@item:intable palette",
"Color 4"),
97 I18N_NOOP2(
"@item:intable palette",
"Color 5"),
98 I18N_NOOP2(
"@item:intable palette",
"Color 6"),
99 I18N_NOOP2(
"@item:intable palette",
"Color 7"),
100 I18N_NOOP2(
"@item:intable palette",
"Color 8"),
101 I18N_NOOP2(
"@item:intable palette",
"Foreground (Intense)"),
102 I18N_NOOP2(
"@item:intable palette",
"Background (Intense)"),
103 I18N_NOOP2(
"@item:intable palette",
"Color 1 (Intense)"),
104 I18N_NOOP2(
"@item:intable palette",
"Color 2 (Intense)"),
105 I18N_NOOP2(
"@item:intable palette",
"Color 3 (Intense)"),
106 I18N_NOOP2(
"@item:intable palette",
"Color 4 (Intense)"),
107 I18N_NOOP2(
"@item:intable palette",
"Color 5 (Intense)"),
108 I18N_NOOP2(
"@item:intable palette",
"Color 6 (Intense)"),
109 I18N_NOOP2(
"@item:intable palette",
"Color 7 (Intense)"),
110 I18N_NOOP2(
"@item:intable palette",
"Color 8 (Intense)")
117 return QString(colorNames[index]);
124 return i18nc(
"@item:intable palette", translatedColorNames[index]);
138 , _opacity(other._opacity)
139 , _wallpaper(other._wallpaper)
144 if (other._table != 0) {
149 if (other._randomTable != 0) {
151 const RandomizationRange& range = other._randomTable[i];
152 setRandomizationRange(i, range.hue, range.saturation, range.value);
159 delete[] _randomTable;
164 _description = aDescription;
191 _table[index] = entry;
202 if (randomSeed != 0 &&
204 !_randomTable[index].isNull()) {
205 const RandomizationRange& range = _randomTable[index];
207 int hueDifference = range.hue ? (qrand() % range.hue) - range.hue / 2 : 0;
208 int saturationDifference = range.saturation ? (qrand() % range.saturation) - range.saturation / 2 : 0;
209 int valueDifference = range.value ? (qrand() % range.value) - range.value / 2 : 0;
211 QColor& color = entry.
color;
213 int newHue = qAbs((color.hue() + hueDifference) % MAX_HUE);
214 int newValue = qMin(qAbs(color.value() + valueDifference) , 255);
215 int newSaturation = qMin(qAbs(color.saturation() + saturationDifference) , 255);
217 color.setHsv(newHue, newSaturation, newValue);
229 return _randomTable == 0 ?
false : !_randomTable[BGCOLOR_INDEX].isNull();
238 setRandomizationRange(BGCOLOR_INDEX , MAX_HUE , 255 , 0);
241 setRandomizationRange(BGCOLOR_INDEX , 0 , 0 , 0);
245 void ColorScheme::setRandomizationRange(
int index , quint16 hue , quint8 saturation ,
248 Q_ASSERT(hue <= MAX_HUE);
251 if (_randomTable == 0)
254 _randomTable[index].hue = hue;
255 _randomTable[index].value = value;
256 _randomTable[index].saturation = saturation;
259 const ColorEntry* ColorScheme::colorTable()
const
268 return colorTable()[FGCOLOR_INDEX].
color;
272 return colorTable()[BGCOLOR_INDEX].
color;
291 KConfigGroup configGroup = config.group(
"General");
293 const QString schemeDescription = configGroup.readEntry(
"Description", I18N_NOOP(
"Un-named Color Scheme"));
295 _description = i18n(schemeDescription.toUtf8());
296 _opacity = configGroup.readEntry(
"Opacity", qreal(1.0));
297 setWallpaper(configGroup.readEntry(
"Wallpaper", QString()));
300 readColorEntry(config, i);
304 void ColorScheme::readColorEntry(
const KConfig& config ,
int index)
310 entry.
color = configGroup.readEntry(
"Color", QColor());
314 const quint16 hue = configGroup.readEntry(
"MaxRandomHue", 0);
315 const quint8 value = configGroup.readEntry(
"MaxRandomValue", 0);
316 const quint8 saturation = configGroup.readEntry(
"MaxRandomSaturation", 0);
318 if (hue != 0 || value != 0 || saturation != 0)
319 setRandomizationRange(index , hue , saturation , value);
324 KConfigGroup configGroup = config.group(
"General");
326 configGroup.writeEntry(
"Description", _description);
327 configGroup.writeEntry(
"Opacity", _opacity);
328 configGroup.writeEntry(
"Wallpaper", _wallpaper->path());
331 writeColorEntry(config, i);
335 void ColorScheme::writeColorEntry(KConfig& config ,
int index)
const
339 const ColorEntry& entry = colorTable()[index];
341 configGroup.writeEntry(
"Color", entry.
color);
344 if (configGroup.hasKey(
"Transparent")) {
345 configGroup.deleteEntry(
"Transparent");
347 if (configGroup.hasKey(
"Transparency")) {
348 configGroup.deleteEntry(
"Transparency");
350 if (configGroup.hasKey(
"Bold")) {
351 configGroup.deleteEntry(
"Bold");
354 RandomizationRange random = _randomTable != 0 ? _randomTable[index] : RandomizationRange();
358 if (!random.isNull() || configGroup.hasKey(
"MaxRandomHue")) {
359 configGroup.writeEntry(
"MaxRandomHue", static_cast<int>(random.hue));
360 configGroup.writeEntry(
"MaxRandomValue", static_cast<int>(random.value));
361 configGroup.writeEntry(
"MaxRandomSaturation", static_cast<int>(random.saturation));
393 _picture =
new QPixmap();
395 if (_picture->isNull())
396 _picture->load(_path);
401 return _path.isEmpty();
406 if (!_picture || _picture->isNull())
409 painter.drawTiledPixmap(rect, *_picture, rect.topLeft());
static QString translatedColorNameForIndex(int index)
ColorScheme()
Constructs a new color scheme which is initialized to the default color set for Konsole.
bool hasDarkBackground() const
Returns true if this color scheme has a dark background.
This class holds the wallpaper pixmap associated with a color scheme.
void getColorTable(ColorEntry *table, uint randomSeed=0) const
Copies the color entries which form the palette for this color scheme into table. ...
void setRandomizedBackgroundColor(bool randomize)
Enables randomization of the background color.
void write(KConfig &config) const
Writes the color scheme to the specified configuration source.
void setOpacity(qreal opacity)
Sets the opacity level of the display background.
ColorEntry colorEntry(int index, uint randomSeed=0) const
Retrieves a single color entry from the table.
qreal opacity() const
Returns the opacity level for this color scheme, see setOpacity() TODO: More documentation.
bool randomizedBackgroundColor() const
Returns true if the background color is randomized.
An entry in a terminal display's color palette.
KSharedPtr< ColorSchemeWallpaper > Ptr
ColorSchemeWallpaper(const QString &path)
void setColorTableEntry(int index, const ColorEntry &entry)
Sets a single entry within the color palette.
QString description() const
Returns the descriptive name of the color scheme.
void setDescription(const QString &description)
Sets the descriptive name of the color scheme.
void setName(const QString &name)
Sets the name of the color scheme.
void setWallpaper(const QString &path)
static const ColorEntry defaultTable[]
static QString colorNameForIndex(int index)
QString name() const
Returns the name of the color scheme.
QColor color
The color value of this entry for display.
QColor backgroundColor() const
Convenience method.
QColor foregroundColor() const
Convenience method.
Represents a color scheme for a terminal display.
bool draw(QPainter &painter, const QRect &rect)
Returns true if wallpaper available and drawn.
ColorSchemeWallpaper::Ptr wallpaper() const
void read(const KConfig &config)
Reads the color scheme from the specified configuration source.