• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

Konsole

ColorScheme.h

Go to the documentation of this file.
00001 /*
00002     This source file is part of Konsole, a terminal emulator.
00003 
00004     Copyright 2007-2008 by Robert Knight <robertknight@gmail.com>
00005 
00006     This program is free software; you can redistribute it and/or modify
00007     it under the terms of the GNU General Public License as published by
00008     the Free Software Foundation; either version 2 of the License, or
00009     (at your option) any later version.
00010 
00011     This program is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014     GNU General Public License for more details.
00015 
00016     You should have received a copy of the GNU General Public License
00017     along with this program; if not, write to the Free Software
00018     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00019     02110-1301  USA.
00020 */
00021 
00022 #ifndef COLORSCHEME_H
00023 #define COLORSCHEME_H
00024 
00025 // Qt
00026 #include <QtCore/QHash>
00027 #include <QtCore/QList>
00028 #include <QtCore/QMetaType>
00029 #include <QtCore/QIODevice>
00030 #include <QtCore/QSet>
00031 
00032 // Konsole
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     // specifies how much a particular color can be randomized by
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     // returns the active color table.  if none has been set specifically,
00163     // this is the default color table.
00164     const ColorEntry* colorTable() const;
00165 
00166     // reads a single colour entry from a KConfig source
00167     // and sets the palette entry at 'index' to the entry read.
00168     void readColorEntry(KConfig& config , int index); 
00169     // writes a single colour entry to a KConfig source
00170     void writeColorEntry(KConfig& config , const QString& colorName, const ColorEntry& entry,const RandomizationRange& range) const;
00171 
00172     // sets the amount of randomization allowed for a particular color 
00173     // in the palette.  creates the randomization table if 
00174     // it does not already exist
00175     void setRandomizationRange( int index , quint16 hue , quint8 saturation , quint8 value );
00176 
00177     QString _description;
00178     QString _name;
00179     qreal _opacity;
00180     ColorEntry* _table; // pointer to custom color table or 0 if the default
00181                         // color scheme is being used
00182 
00183 
00184     static const quint16 MAX_HUE = 340;
00185 
00186     RandomizationRange* _randomTable;   // pointer to randomization table or 0
00187                                         // if no colors in the color scheme support
00188                                         // randomization
00189 
00190     static const char* colorNames[TABLE_COLORS];
00191     static const char* translatedColorNames[TABLE_COLORS];
00192 
00193     static const ColorEntry defaultTable[]; // table of default color entries
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     // reads a line from the file specifying a colour palette entry
00239     // format is: color [index] [red] [green] [blue] [transparent] [bold]
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     // loads a color scheme from a KDE 4+ .colorscheme file
00309     bool loadColorScheme(const QString& path);
00310     // loads a color scheme from a KDE 3 .schema file
00311     bool loadKDE3ColorScheme(const QString& path);
00312     // returns a list of paths of color schemes in the KDE 4+ .colorscheme file format
00313     QList<QString> listColorSchemes();
00314     // returns a list of paths of color schemes in the .schema file format
00315     // used in KDE 3
00316     QList<QString> listKDE3ColorSchemes();
00317     // loads all of the color schemes
00318     void loadAllColorSchemes();
00319     // finds the path of a color scheme
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

Konsole

Skip menu "Konsole"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  • Konsole
  • Libraries
  •   libkonq
Generated for API Reference by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal