File indexing completed on 2024-05-05 05:53:44
0001 /* 0002 This source file is part of Konsole, a terminal emulator. 0003 0004 SPDX-FileCopyrightText: 2007-2008 Robert Knight <robertknight@gmail.com> 0005 0006 SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 0009 #ifndef COLORSCHEME_H 0010 #define COLORSCHEME_H 0011 0012 // Qt 0013 #include <QMetaType> 0014 #include <QSharedData> 0015 0016 // C++ 0017 #include <memory> 0018 0019 // Konsole 0020 #include "ColorSchemeWallpaper.h" 0021 0022 #include <KLazyLocalizedString> 0023 0024 class KConfig; 0025 class QPixmap; 0026 class QPainter; 0027 0028 namespace Konsole 0029 { 0030 class RandomizationRange; 0031 /** 0032 * Represents a color scheme for a terminal display. 0033 * 0034 * The color scheme includes the palette of colors used to draw the text and character backgrounds 0035 * in the display and the opacity level of the display background. 0036 */ 0037 class ColorScheme 0038 { 0039 public: 0040 /** 0041 * Constructs a new color scheme which is initialized to the default color set 0042 * for Konsole. 0043 */ 0044 ColorScheme(); 0045 ColorScheme(const ColorScheme &other); 0046 ColorScheme &operator=(const ColorScheme &other) = delete; 0047 ~ColorScheme(); 0048 0049 /** Sets the descriptive name of the color scheme. */ 0050 void setDescription(const QString &description); 0051 /** Returns the descriptive name of the color scheme. */ 0052 QString description() const; 0053 0054 /** Sets the name of the color scheme */ 0055 void setName(const QString &name); 0056 /** Returns the name of the color scheme */ 0057 QString name() const; 0058 0059 /** Reads the color scheme from the specified configuration source */ 0060 void read(const KConfig &config); 0061 /** Writes the color scheme to the specified configuration source */ 0062 void write(KConfig &config) const; 0063 0064 /** Sets a single entry within the color palette. */ 0065 void setColorTableEntry(int index, const QColor &entry); 0066 0067 /** 0068 * Copies the color entries which form the palette for this color scheme 0069 * into @p table. @p table should be an array with TABLE_COLORS entries. 0070 * 0071 * @param table Array into which the color entries for this color scheme 0072 * are copied. 0073 * @param randomSeed Color schemes may allow certain colors in their 0074 * palette to be randomized. The seed is used to pick the random color. 0075 */ 0076 void getColorTable(QColor *table, uint randomSeed = 0) const; 0077 0078 /** 0079 * Retrieves a single color entry from the table. 0080 * 0081 * See getColorTable() 0082 */ 0083 QColor colorEntry(int index, uint randomSeed = 0) const; 0084 0085 /** 0086 * Convenience method. Returns the 0087 * foreground color for this scheme, 0088 * this is the primary color used to draw the 0089 * text in this scheme. 0090 */ 0091 QColor foregroundColor() const; 0092 /** 0093 * Convenience method. Returns the background color for 0094 * this scheme, this is the primary color used to 0095 * draw the terminal background in this scheme. 0096 */ 0097 QColor backgroundColor() const; 0098 0099 /** 0100 * Returns true if this color scheme has a dark background. 0101 * The background color is said to be dark if it has a lightness 0102 * of less than 50% in the HSLuv color space. 0103 */ 0104 bool hasDarkBackground() const; 0105 0106 /** 0107 * Sets the opacity level of the display background. @p opacity ranges 0108 * between 0 (completely transparent background) and 1 (completely 0109 * opaque background). 0110 * 0111 * Defaults to 1. 0112 * 0113 * TODO: More documentation 0114 */ 0115 void setOpacity(qreal opacity); 0116 /** 0117 * Returns the opacity level for this color scheme, see setOpacity() 0118 * TODO: More documentation 0119 */ 0120 qreal opacity() const; 0121 0122 /** 0123 * Enables blur behind the transparent window 0124 * 0125 * Defaults to false. 0126 */ 0127 void setBlur(bool blur); 0128 /** 0129 * Returns whether blur is enabled for this color scheme, see setBlur() 0130 */ 0131 bool blur() const; 0132 0133 void setWallpaper(const QString &path, 0134 const ColorSchemeWallpaper::FillStyle style, 0135 const QPointF &anchor, 0136 const qreal &opacity, 0137 const ColorSchemeWallpaper::FlipType flipType); 0138 0139 void setWallpaper(const QString &path, const QString &style, const QPointF &anchor, const qreal &opacity, const QString &flipType); 0140 0141 ColorSchemeWallpaper::Ptr wallpaper() const; 0142 0143 /** 0144 * Enables colors randomization. This will cause the palette 0145 * returned by getColorTable() and colorEntry() to be adjusted 0146 * depending on the parameters of color randomization and the 0147 * random seed parameter passed to them. 0148 */ 0149 void setColorRandomization(bool randomize); 0150 0151 /** Returns true if color randomization is enabled. */ 0152 bool isColorRandomizationEnabled() const; 0153 0154 static const QColor defaultTable[]; // table of default color entries 0155 0156 static QString colorNameForIndex(int index); 0157 static QString translatedColorNameForIndex(int index); 0158 0159 private: 0160 // returns the active color table. if none has been set specifically, 0161 // this is the default color table. 0162 const QColor *colorTable() const; 0163 0164 // reads a single color entry from a KConfig source 0165 // and sets the palette entry at 'index' to the entry read. 0166 void readColorEntry(const KConfig &config, int index); 0167 // writes a single color entry to a KConfig source 0168 void writeColorEntry(KConfig &config, int index) const; 0169 0170 // sets the amount of randomization allowed for a particular color 0171 // in the palette. creates the randomization table if 0172 // it does not already exist 0173 void setRandomizationRange(int index, double hue, double saturation, double lightness); 0174 0175 QString _description; 0176 QString _name; 0177 0178 // pointer to custom color table, or 0 if the default color table is 0179 // being used 0180 QColor *_table; 0181 0182 // pointer to randomization table, or 0 if no colors in the color 0183 // scheme support randomization 0184 RandomizationRange *_randomTable; 0185 0186 qreal _opacity; 0187 0188 // enables blur behind the terminal window 0189 bool _blur; 0190 0191 bool _colorRandomization; 0192 0193 ColorSchemeWallpaper::Ptr _wallpaper; 0194 0195 static const char *const colorNames[TABLE_COLORS]; 0196 static const KLazyLocalizedString translatedColorNames[TABLE_COLORS]; 0197 }; 0198 } 0199 0200 Q_DECLARE_METATYPE(std::shared_ptr<const Konsole::ColorScheme>) 0201 0202 #endif // COLORSCHEME_H