00001 #ifndef COLORTABLE_H 00002 #define COLORTABLE_H 00003 /* ============================================================================ 00004 'colortable.h' defines a pair of classes used to maintain the color tables 00005 required by the application. 00006 00007 Written by Nicholas Phillips. 00008 QT4 adaption and Black/White color table by Michael R. Greason, ADNET, 00009 27 August 2007. 00010 ============================================================================ */ 00011 /* 00012 Fetch header files. 00013 */ 00014 #include <QString> 00015 #include <QColor> 00016 #include <QPixmap> 00017 #include <vector> 00018 /* ============================================================================ 00019 'ColorTable' maintains a single color table. Each element represents one 00020 usable color; it may be accessed either by indexing it directly or by supplying 00021 a value from 0--1. 00022 00023 The color tables currently supported are staticly defined in 00024 'define_colortable.h'. 00025 00026 TBD: 00027 - Allow the setting of color tables from image files. 00028 - Return a pixmap of the color table. 00029 ============================================================================ */ 00030 class ColorTable 00031 { 00032 public: 00033 ColorTable(); 00034 ColorTable(int id); 00035 QColor operator[](unsigned int ind) const; 00036 QColor operator[](float v) const; 00037 QColor operator()(float v) const; 00038 int getSize (void) const; 00039 QString getName() const; 00040 QPixmap getPixmap(); 00041 protected: 00042 QString name; 00043 unsigned int ncols; 00044 std::vector<QColor> table; 00045 private: 00046 void define_table (float intab[][3]); 00047 }; 00048 /* ---------------------------------------------------------------------------- 00049 'getName' returns the name of the color table. 00050 00051 Arguments: 00052 None. 00053 00054 Returned: 00055 name - The name of the table. 00056 00057 Written by Michael R. Greason, ADNET, 27 August 2007. 00058 ---------------------------------------------------------------------------- */ 00059 inline QString ColorTable::getName() const 00060 { 00061 return name; 00062 } 00063 /* ---------------------------------------------------------------------------- 00064 'getSize' returns the size of the color table. 00065 00066 Arguments: 00067 None. 00068 00069 Returned: 00070 size - The number of elements in the table. 00071 00072 Written by Michael R. Greason, ADNET, 27 August 2007. 00073 ---------------------------------------------------------------------------- */ 00074 inline int ColorTable::getSize(void) const 00075 { 00076 return ncols; 00077 } 00078 /* ---------------------------------------------------------------------------- 00079 'operator[]' returns the indexed element in the table. 00080 00081 Arguments: 00082 ind - The index; it is forced to fall in bounds. 00083 00084 Returned: 00085 col - The desired color. 00086 00087 Written by Michael R. Greason, ADNET, 27 August 2007. 00088 ---------------------------------------------------------------------------- */ 00089 inline QColor ColorTable::operator[](unsigned int ind) const 00090 { 00091 return table[(ind >= ncols) ? (ncols - 1) : ind]; 00092 } 00093 /* ---------------------------------------------------------------------------- 00094 'operator()' returns the indexed element in the table. 00095 00096 Arguments: 00097 v - The 'index'; this is a value between 0 and 1 identifying the 00098 desired color as a fractional position in the table. 00099 00100 Returned: 00101 col - The desired color. 00102 00103 Written by Michael R. Greason, ADNET, 27 August 2007. 00104 ---------------------------------------------------------------------------- */ 00105 inline QColor ColorTable::operator()(float v) const 00106 { 00107 return operator[](v); 00108 } 00109 /* ============================================================================ 00110 'ColorTableList' maintains a vector of color tables. 00111 ============================================================================ */ 00112 class ColorTableList : public std::vector<ColorTable *> 00113 { 00114 public: 00115 ColorTableList (void); 00116 ~ColorTableList(); 00117 bool set(); 00118 }; 00119 00120 #endif