logplus/qtpropertybrowser/qtColorSchemeComboBox.h

234 lines
5.6 KiB
C
Raw Permalink Normal View History

/*
* 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 <QSharedMemory>
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<QtColorItem> 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<QtSchemeColor > &GetSchemeList()
{
return m_colorSchemeList;
}
/**
* @brief
*/
bool ChangeColorNum(int colorNum);
/**
* @brief RGB值
* @param colornum 0
*/
QList<QRgb> 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<QtSchemeColor> m_colorSchemeList;
// 备份的颜色方案
QList<QtSchemeColor> 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<QtSchemeColor > &schemeList);
void ShowText(bool showText=true);
private:
QPixmap getColorLabelPixmap(const QVector<QtColorItem> &colorList,int colorNumber);
void freeColorScheme();
private:
bool m_isShowText;
QList<QtSchemeColor > m_colorSchemeList;
};
#endif /* QtColorSchemeComboBox_H_ */