Konsole
ColorScheme.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef COLORSCHEME_H
00023 #define COLORSCHEME_H
00024
00025
00026 #include <QtCore/QHash>
00027 #include <QtCore/QList>
00028 #include <QtCore/QMetaType>
00029 #include <QtCore/QIODevice>
00030 #include <QtCore/QSet>
00031
00032
00033 #include "CharacterColor.h"
00034
00035 class QIODevice;
00036 class KConfig;
00037
00038 namespace Konsole
00039 {
00040
00047 class ColorScheme
00048 {
00049 public:
00054 ColorScheme();
00055 ColorScheme(const ColorScheme& other);
00056 ~ColorScheme();
00057
00059 void setDescription(const QString& description);
00061 QString description() const;
00062
00064 void setName(const QString& name);
00066 QString name() const;
00067
00069 void read(KConfig& config);
00071 void write(KConfig& config) const;
00072
00074 void setColorTableEntry(int index , const ColorEntry& entry);
00075
00085 void getColorTable(ColorEntry* table, uint randomSeed = 0) const;
00086
00092 ColorEntry colorEntry(int index , uint randomSeed = 0) const;
00093
00100 QColor foregroundColor() const;
00106 QColor backgroundColor() const;
00107
00113 bool hasDarkBackground() const;
00114
00124 void setOpacity(qreal opacity);
00129 qreal opacity() const;
00130
00137 void setRandomizedBackgroundColor(bool randomize);
00138
00140 bool randomizedBackgroundColor() const;
00141
00142 static QString colorNameForIndex(int index);
00143 static QString translatedColorNameForIndex(int index);
00144
00145 private:
00146
00147 class RandomizationRange
00148 {
00149 public:
00150 RandomizationRange() : hue(0) , saturation(0) , value(0) {}
00151
00152 bool isNull() const
00153 {
00154 return ( hue == 0 && saturation == 0 && value == 0 );
00155 }
00156
00157 quint16 hue;
00158 quint8 saturation;
00159 quint8 value;
00160 };
00161
00162
00163
00164 const ColorEntry* colorTable() const;
00165
00166
00167
00168 void readColorEntry(KConfig& config , int index);
00169
00170 void writeColorEntry(KConfig& config , const QString& colorName, const ColorEntry& entry,const RandomizationRange& range) const;
00171
00172
00173
00174
00175 void setRandomizationRange( int index , quint16 hue , quint8 saturation , quint8 value );
00176
00177 QString _description;
00178 QString _name;
00179 qreal _opacity;
00180 ColorEntry* _table;
00181
00182
00183
00184 static const quint16 MAX_HUE = 340;
00185
00186 RandomizationRange* _randomTable;
00187
00188
00189
00190 static const char* colorNames[TABLE_COLORS];
00191 static const char* translatedColorNames[TABLE_COLORS];
00192
00193 static const ColorEntry defaultTable[];
00194 };
00195
00205 class AccessibleColorScheme : public ColorScheme
00206 {
00207 public:
00208 AccessibleColorScheme();
00209 };
00210
00219 class KDE3ColorSchemeReader
00220 {
00221 public:
00226 KDE3ColorSchemeReader( QIODevice* device );
00227
00235 ColorScheme* read();
00236
00237 private:
00238
00239
00240 bool readColorLine(const QString& line , ColorScheme* scheme);
00241 bool readTitleLine(const QString& line , ColorScheme* scheme);
00242
00243 QIODevice* _device;
00244 };
00245
00250 class ColorSchemeManager
00251 {
00252 public:
00253
00261 ColorSchemeManager();
00265 ~ColorSchemeManager();
00266
00270 const ColorScheme* defaultColorScheme() const;
00271
00280 const ColorScheme* findColorScheme(const QString& name);
00281
00288 void addColorScheme(ColorScheme* scheme);
00289
00293 bool deleteColorScheme(const QString& name);
00294
00302 QList<const ColorScheme*> allColorSchemes();
00303
00305 static ColorSchemeManager* instance();
00306
00307 private:
00308
00309 bool loadColorScheme(const QString& path);
00310
00311 bool loadKDE3ColorScheme(const QString& path);
00312
00313 QList<QString> listColorSchemes();
00314
00315
00316 QList<QString> listKDE3ColorSchemes();
00317
00318 void loadAllColorSchemes();
00319
00320 QString findColorSchemePath(const QString& name) const;
00321
00322 QHash<QString,const ColorScheme*> _colorSchemes;
00323 QSet<ColorScheme*> _modifiedSchemes;
00324
00325 bool _haveLoadedAll;
00326
00327 static const ColorScheme _defaultColorScheme;
00328 };
00329
00330 }
00331
00332 Q_DECLARE_METATYPE(const Konsole::ColorScheme*)
00333
00334 #endif //COLORSCHEME_H