itom 1.3.0
|
00001 /* ******************************************************************** 00002 itom software 00003 URL: http://www.uni-stuttgart.de/ito 00004 Copyright (C) 2013, Institut für Technische Optik (ITO), 00005 Universität Stuttgart, Germany 00006 00007 This file is part of itom. 00008 00009 itom is free software; you can redistribute it and/or modify it 00010 under the terms of the GNU Library General Public Licence as published by 00011 the Free Software Foundation; either version 2 of the Licence, or (at 00012 your option) any later version. 00013 00014 itom is distributed in the hope that it will be useful, but 00015 WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library 00017 General Public Licence for more details. 00018 00019 You should have received a copy of the GNU Library General Public License 00020 along with itom. If not, see <http://www.gnu.org/licenses/>. 00021 *********************************************************************** */ 00022 00023 #ifndef PALETTEORGANIZER_H 00024 #define PALETTEORGANIZER_H 00025 00026 #include "../../common/sharedStructures.h" 00027 #include "../../common/sharedStructuresGraphics.h" 00028 00029 #include <qhash.h> 00030 00031 namespace ito 00032 { 00033 00034 class ItomPaletteBase 00035 { 00036 public: 00037 00038 ItomPaletteBase():m_name(""), m_type(0), m_inverseColorOne(), m_inverseColorTwo() {m_colorStops.clear();}; 00039 ItomPaletteBase(const QString name, const char type): m_name(name), m_type(type), m_inverseColorOne(), m_inverseColorTwo() {m_colorStops.clear();}; 00040 ItomPaletteBase(const QString name, const char type, QColor start, QColor stop): m_name(name), m_type(type), m_inverseColorOne(), m_inverseColorTwo() 00041 { 00042 m_colorStops.clear(); 00043 m_colorStops.append(QPair<double, QColor>(0.0, start)); 00044 m_colorStops.append(QPair<double, QColor>(1.0, stop)); 00045 }; 00046 00047 ItomPaletteBase(const ItomPaletteBase & scr) 00048 { 00049 m_inverseColorOne = scr.m_inverseColorOne; 00050 m_inverseColorTwo = scr.m_inverseColorTwo; 00051 m_name = scr.m_name; 00052 m_type = scr.m_type; 00053 m_colorStops.clear(); 00054 m_colorStops = scr.m_colorStops; 00055 m_paletteStucture = scr.m_paletteStucture; 00056 } 00057 00058 ~ItomPaletteBase() {m_colorStops.clear(); m_paletteStucture.colorStops.clear(); m_paletteStucture.colorVector256.clear();}; 00059 /* 00060 enum tPalette{ 00061 NoType = 0x00, 00062 GrayPalette = 0x01, 00063 RGBPalette = 0x02, 00064 FCPalette = 0x04, 00065 indexPalette = 0x08, 00066 LinearPalette = 0x10, 00067 ReadOnlyPalette = 0x20, 00068 }; 00069 */ 00070 QString getName() const {return m_name;}; 00071 inline int getSize() const {return m_colorStops.size();}; 00072 inline int getType() const {return m_type;}; 00073 00074 double getPosFirst() const {return m_colorStops[0].first;}; 00075 double getPosLast() const {return m_colorStops[m_colorStops.size()-1].first;}; 00076 double getPos(unsigned int color) const; 00077 00078 bool setInversColorOne(const QColor color); 00079 QColor getInversColorOne() const {return m_inverseColorOne;}; 00080 bool setInversColorTwo(const QColor color); 00081 QColor getInversColorTwo() const {return m_inverseColorTwo;}; 00082 00083 QColor getColorFirst() const {return m_colorStops[0].second;}; 00084 QColor getColorLast() const {return m_colorStops[m_colorStops.size()-1].second;}; 00085 QColor getColor(unsigned int color) const; 00086 00087 void update(const bool updateInverseColors); 00088 ItomPalette getPalette(); 00089 00090 inline void setWriteProtection() { m_type = m_type | ito::tPaletteReadOnly; return;}; 00091 bool insertColorStop( double pos, const QColor color ); 00092 void calculateInverseColors(QColor &inv1, QColor &inv2); 00093 //QColor getColor(double pos) const; 00094 00095 QVector<ito::uint32> get256Colors() const; 00096 00097 protected: 00098 inline void removeWriteProtection() { m_type = m_type & !ito::tPaletteReadOnly; return;}; 00099 00100 private: 00101 QString m_name; 00102 char m_type; 00103 00104 ItomPalette m_paletteStucture; 00105 00106 QColor m_inverseColorTwo; 00107 QColor m_inverseColorOne; 00108 00109 QVector<QPair<double, QColor> > m_colorStops; 00110 00111 int findUpper( double pos ) const; 00112 00113 public slots: 00114 00115 private slots: 00116 00117 signals: 00118 00119 }; 00120 00121 class PaletteOrganizer : public QObject 00122 { 00123 Q_OBJECT 00124 00125 public: 00126 00127 PaletteOrganizer(); 00128 ~PaletteOrganizer(){}; 00129 00130 protected: 00131 00132 00133 private: 00134 00135 QList<QString> restrictedKeyWords; 00136 QList<ItomPaletteBase> m_colorBars; 00137 QHash<QString,int> m_colorBarLookUp; 00138 00139 ItomPaletteBase noPalette; 00140 00141 public slots: 00142 ItomPaletteBase getColorBar(const int index) const; 00143 ItomPaletteBase getNextColorBar(const int curindex, const int type = ito::tPaletteNoType) const; 00144 int getColorBarIndex(const QString name, bool *found = NULL) const; 00145 ItomPaletteBase getColorBar(const QString name, bool *found = NULL) const; 00146 QList<QString> getColorBarList(const int type = ito::tPaletteNoType) const; 00147 int numberOfColorBars() const {return m_colorBars.length();}; 00148 00149 private slots: 00150 00151 signals: 00152 00153 }; 00154 } //namespace íto 00155 #endif