File indexing completed on 2024-12-22 04:17:59
0001 /******************************************************************************* 0002 * * 0003 * copyright : (C) 2010 C. Barth Netterfield <netterfield@astro.utoronto.ca> * 0004 * * 0005 * This program is free software; you can redistribute it and/or modify * 0006 * it under the terms of the GNU General Public License as published by * 0007 * the Free Software Foundation; either version 2 of the License, or * 0008 * (at your option) any later version. * 0009 * * 0010 *******************************************************************************/ 0011 0012 #ifndef PALETTE_H 0013 #define PALETTE_H 0014 0015 #include <QColor> 0016 #include <QHash> 0017 #include "kstmath_export.h" 0018 0019 namespace Kst { 0020 0021 typedef QHash<int, QColor> PaletteData; 0022 0023 const unsigned int maxColorTableSize = 2048; 0024 0025 const QString DefaultPalette("Kst Grayscale"); 0026 class KSTMATH_EXPORT Palette 0027 { 0028 public: 0029 /** 0030 * @returns string list of avalible palettes 0031 */ 0032 static QStringList getPaletteList(); 0033 0034 Palette(); 0035 explicit Palette(const QString &paletteName); 0036 0037 virtual ~Palette(); 0038 0039 void changePaletteName(const QString &paletteName); 0040 QString paletteName() const {return _paletteName;} 0041 int colorCount() const {return _count;} 0042 0043 /** 0044 * Returns the color corresponding to colorId. 0045 * It truncates to max or min _color if colorId is out 0046 * of bounds, so bounds checking is not necessary in the 0047 * calling function. 0048 * @returns the QColor 0049 */ 0050 QColor color(const int colorId) const{ 0051 if (colorId<0) { 0052 return _colors[0]; 0053 } else if (colorId>=_count) { 0054 return _colors[_count-1]; 0055 } else { 0056 return _colors[colorId]; 0057 } 0058 } 0059 /** 0060 * Returns the rgb value for the color corresponding to colorId. 0061 * It truncates to max or min _rgb if colorId is out 0062 * of bounds, so bounds checking is not necessary in the 0063 * calling function. 0064 * @returns the QColor.rgb(). 0065 */ 0066 QRgb rgb(const int colorId) const{ 0067 if (colorId<0) { 0068 return _rgb[0] | 0xff000000; 0069 } else if (colorId>=_count) { 0070 return _rgb[_count-1] | 0xff000000; 0071 } else { 0072 return _rgb[colorId] | 0xff000000; 0073 } 0074 } 0075 0076 private: 0077 QColor *_colors; 0078 QRgb *_rgb; 0079 QString _paletteName; 0080 int _count; 0081 }; 0082 0083 } 0084 #endif 0085 0086 // vim: ts=2 sw=2 et