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