itom 2.0.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/sharedStructuresQt.h" 00028 #include "../../common/sharedStructuresGraphics.h" 00029 00030 #include <qhash.h> 00031 #include <qsharedpointer.h> 00032 namespace ito 00033 { 00034 00035 class ItomPaletteBase 00036 { 00037 public: 00038 00039 ItomPaletteBase():m_name(""), m_type(0), m_inverseColorOne(), m_inverseColorTwo(), m_invalidColor() {m_colorStops.clear();}; 00040 ItomPaletteBase(const QString name, const char type): m_name(name), m_type(type), m_inverseColorOne(), m_inverseColorTwo(), m_invalidColor() {m_colorStops.clear();}; 00041 ItomPaletteBase(const QString name, const char type, QColor start, QColor stop): m_name(name), m_type(type), m_inverseColorOne(), m_inverseColorTwo() , m_invalidColor() 00042 { 00043 m_colorStops.clear(); 00044 m_colorStops.append(QPair<double, QColor>(0.0, start)); 00045 m_colorStops.append(QPair<double, QColor>(1.0, stop)); 00046 }; 00047 00048 ItomPaletteBase(const ItomPaletteBase & scr) 00049 { 00050 m_invalidColor = scr.m_invalidColor; 00051 m_inverseColorOne = scr.m_inverseColorOne; 00052 m_inverseColorTwo = scr.m_inverseColorTwo; 00053 m_name = scr.m_name; 00054 m_type = scr.m_type; 00055 m_colorStops.clear(); 00056 m_colorStops = scr.m_colorStops; 00057 m_paletteStucture = scr.m_paletteStucture; 00058 } 00059 00060 ~ItomPaletteBase() {m_colorStops.clear(); m_paletteStucture.colorStops.clear(); m_paletteStucture.colorVector256.clear();}; 00061 /* 00062 enum tPalette{ 00063 NoType = 0x00, 00064 GrayPalette = 0x01, 00065 RGBPalette = 0x02, 00066 FCPalette = 0x04, 00067 indexPalette = 0x08, 00068 LinearPalette = 0x10, 00069 ReadOnlyPalette = 0x20, 00070 }; 00071 */ 00072 QString getName() const {return m_name;}; 00073 inline int getSize() const {return m_colorStops.size();}; 00074 inline int getType() const {return m_type;}; 00075 00076 double getPosFirst() const {return m_colorStops[0].first;}; 00077 double getPosLast() const {return m_colorStops[m_colorStops.size()-1].first;}; 00078 double getPos(unsigned int color) const; 00079 00080 bool setInversColorOne(const QColor color); 00081 QColor getInversColorOne() const {return m_inverseColorOne;}; 00082 bool setInversColorTwo(const QColor color); 00083 QColor getInversColorTwo() const {return m_inverseColorTwo;}; 00084 00085 bool setInvalidColor(const QColor color); 00086 QColor getInvalidColor() const; 00087 00088 QColor getColorFirst() const {return m_colorStops[0].second;}; 00089 QColor getColorLast() const {return m_colorStops[m_colorStops.size()-1].second;}; 00090 QColor getColor(unsigned int color) const; 00091 00092 void update(const bool updateInverseColors); 00093 ItomPalette getPalette(); 00094 00095 inline void setWriteProtection() { m_type = m_type | ito::tPaletteReadOnly; return;}; 00096 bool insertColorStop( double pos, const QColor color ); 00097 void calculateInverseColors(QColor &inv1, QColor &inv2); 00098 //QColor getColor(double pos) const; 00099 00100 QVector<ito::uint32> get256Colors(bool includeAlpha = false) const; 00101 00102 protected: 00103 inline void removeWriteProtection() { m_type = m_type & !ito::tPaletteReadOnly; return;}; 00104 00105 private: 00106 QString m_name; 00107 char m_type; 00108 00109 ItomPalette m_paletteStucture; 00110 00111 QColor m_inverseColorTwo; 00112 QColor m_inverseColorOne; 00113 QColor m_invalidColor; 00114 QVector<QPair<double, QColor> > m_colorStops; 00115 00116 int findUpper( double pos ) const; 00117 00118 public slots: 00119 00120 private slots: 00121 00122 signals: 00123 00124 }; 00125 00126 class PaletteOrganizer : public QObject 00127 { 00128 Q_OBJECT 00129 00130 public: 00131 00132 PaletteOrganizer(); 00133 ~PaletteOrganizer(){}; 00134 00135 protected: 00136 00137 00138 private: 00139 00140 QList<QString> restrictedKeyWords; 00141 QList<ItomPaletteBase> m_colorBars; 00142 QHash<QString,int> m_colorBarLookUp; 00143 00144 ItomPaletteBase noPalette; 00145 00146 public slots: 00147 ItomPaletteBase getColorBar(const int index) const; 00148 ItomPaletteBase getNextColorBar(const int curindex, const int type = ito::tPaletteNoType) const; 00149 int getColorBarIndex(const QString name, bool *found = NULL) const; 00150 ItomPaletteBase getColorBar(const QString name, bool *found = NULL) const; 00151 QList<QString> getColorBarList(const int type = ito::tPaletteNoType) const; 00152 int numberOfColorBars() const {return m_colorBars.length();}; 00153 00154 ito::RetVal setColorBarThreaded(QString name, ito::ItomPaletteBase newPalette, ItomSharedSemaphore *waitCond = NULL); 00155 ito::RetVal getColorBarThreaded(QString name, QSharedPointer<ito::ItomPaletteBase> palette, ItomSharedSemaphore *waitCond = NULL); 00156 ito::RetVal getColorBarListThreaded(int types, QSharedPointer<QStringList> palettes, ItomSharedSemaphore *waitCond = NULL); 00157 private slots: 00158 00159 signals: 00160 00161 }; 00162 } //namespace íto 00163 #endif