/* * QtColorSchemeComboBox.h * * Created on: 2013-5-27 * Author: long */ #ifndef QtColorSchemeComboBox_H_ #define QtColorSchemeComboBox_H_ #include "qtpropertybrowser.h" // #include "PaiColorPub.h" #include "qtComboBox.h" #include const QString gOrignizationName="PI PlatForm"; const QString gSchemeNumKey="Scheme Color Number"; const QString gOneSchemeNameKey="Custom "; const QString gOneSchemeControlColorNumKey="Control colornum"; const QString gOneSchemeColorKey="color"; #define PAITOTALCOLOR_MIN 2 // 最小总颜色数目 #define PAITOTALCOLOR_MAX 65 // 最大总颜色数目 #define SECTIONVIEW_NUM 255 struct Qt_ColorItem { QRgb color; // 颜色值 float fromValue; // 对应的振幅开始值 float toValue; // 对应的振幅的结束值 char strComments[64]; // 描述信息 }; class QtColorItem { public: QtColorItem() { color=QColor(0,0,0); fromValue=toValue=0; strComments=""; } QtColorItem(const QColor &color,float value=0) { this->color=color; this->fromValue=this->toValue=value; strComments=""; } QtColorItem(const QtColorItem &other) { color=other.color; fromValue=other.fromValue; toValue=other.toValue; strComments=other.strComments; } QtColorItem & operator=(const QtColorItem &other) { color=other.color; fromValue=other.fromValue; toValue=other.toValue; strComments=other.strComments; return *this; } QColor color; // 颜色值 float fromValue; // 对应的振幅开始值 float toValue; // 对应的振幅的结束值 QString strComments; // 描述信息 }; /** * @class QtSchemeColor * @brief 描述一种颜色方案 */ struct QtScheme_Color { char schemeName[64]; int size; struct Qt_ColorItem colorList[256]; bool isDirty; bool isCustom; int currentIndex; // 当前编辑的位置 }; class QtSchemeColor { public: QtSchemeColor() { schemeName=""; colorList.clear(); isDirty=isCustom=false; currentIndex=0; } QtSchemeColor(const QtSchemeColor &other) { schemeName=other.schemeName; colorList=other.colorList; isDirty=other.isDirty; isCustom=other.isCustom; currentIndex=other.currentIndex; } QtSchemeColor & operator=(const QtSchemeColor &other) { schemeName=other.schemeName; colorList=other.colorList; isDirty=other.isDirty; isCustom=other.isCustom; currentIndex=other.currentIndex; return *this; } QString schemeName; QVector colorList; bool isDirty; bool isCustom; int currentIndex; // 当前编辑的位置 }; class QTPROPERTYBROWSER_EXPORT QtColorTableData { public: enum { MAXCUSTOM_SCHEME=12 // 允许的最大颜色自定义方案 }; /** * @brief 构造函数 * @param moduleName 模块名称 * @param inopSystemColor是否将读取的缺省颜色插值为65中 */ QtColorTableData(const QString &moduleName,bool inopSystemColor) { m_isSettingSysColor=false; m_systemShcemeNum=0; m_flMinVal=-1000; m_flMaxVal=1000; m_modulName=moduleName; m_polatationSystemColor=inopSystemColor; LoadScheme(); } static QtColorTableData* getInstance(); /** * @brief 加载已经存在的颜色方案 */ bool LoadScheme(bool IsReLoad=false); /* * @brief 获取颜色方案列表 * @warning 下一部准备实现不同模块的系统保留和自定义方案 */ QList &GetSchemeList() { return m_colorSchemeList; } /** * @brief 改变当前颜色方案的颜色数 */ bool ChangeColorNum(int colorNum); /** * @brief 获取当前颜色方案的RGB值 * @param colornum 需要返回的颜色数目,如果为0按照实际的颜色数目返回 */ QList GetRgb(int colornum=0) const; void ChangeDataRange(QtSchemeColor *scheme); void ReadSettings(); /* * @brief 设置当前的颜色方案序号 * */ void SetCurrentSchemeIndex(int nIndex); /** * @brief 获取当前的颜色方案 */ QtSchemeColor* CurrentScheme() { if(m_currentSchemIndex==-1) return NULL; return &m_colorSchemeList[m_currentSchemIndex]; } private: void FreeColorScheme(); // 是否设置系统缺省颜色 bool m_isSettingSysColor; // 当前所有的颜色方案,包括系统方案,自定义方案 QList m_colorSchemeList; // 备份的颜色方案 QList m_systemSchemeList; QString m_modulName; // 用于保存参数的组织和模块名 int m_currentSchemIndex; // 当前正在使用的颜色方案 int m_systemShcemeNum; // 系统缺省的颜色方案数目 bool m_polatationSystemColor; // 设置数据的最小和最大范围 float m_flMinVal,m_flMaxVal; QSharedMemory m_SharedMemory; }; class QTPROPERTYBROWSER_EXPORT QtColorSchemeComboBox:public QtComboBox { public: QtColorSchemeComboBox(QWidget *parent=0); virtual ~QtColorSchemeComboBox(); void setSchemeColor(const QList &schemeList); void ShowText(bool showText=true); private: QPixmap getColorLabelPixmap(const QVector &colorList,int colorNumber); void freeColorScheme(); private: bool m_isShowText; QList m_colorSchemeList; }; #endif /* QtColorSchemeComboBox_H_ */