#include "CUI.h" #include #include #include #include #include #include #include #include #include #include #include /** * @brief CUI::CUI 构造函数 * @param conf 配置信息 */ CUI::CUI(CUIConfig *conf) { this->conf = conf; this->conf->printConfig(); buildUI(); } /** * @brief CUI::buildUI 创建组件 */ void CUI::buildUI() { QString type = conf->property["type"]; if(type == "") return; // qDebug()<<"start_build"; if(type == "Widget") { // qDebug()<<"build widget"; uiWidget = new CUIWidget(conf,subCUI); } if(type == "GroupBox") { uiGroupBox = new CUIGroupBox(conf,subCUI); } if(type == "LineEdit") { uiLineEdit = new CUILineEdit(conf,subCUI); } if(type == "TabWidget") { uiTabWidget = new CUITabWidget(conf,subCUI); } if(type == "ComboBox"){ uiComboBox = new CUIComboBox(conf,subCUI); } if(type == "PushButton"){ uiPushButton = new CUIPushButton(conf,subCUI); } if(type == "CheckBox"){ uiCheckBox = new CUICheckBox(conf,subCUI); } if(type == "RadioButton"){ uiRadioButton = new CUIRadioButton(conf,subCUI); } if(type == "ButtonBox"){ uiButtonBox = new CUIButtonBox(conf,subCUI); } } /** * @brief CUI::check 对管理的组件进行检查 */ void CUI::check() { } /** * @brief CUI::getUI 返回组件 * @return QWidget,组件 */ QWidget *CUI::getUI() { if(conf->property["type"] == "Widget"){ return uiWidget; } if(conf->property["type"] == "GroupBox"){ return uiGroupBox; } if(conf->property["type"] == "LineEdit"){ return uiLineEdit; } if(conf->property["type"] == "TabWidget"){ return uiTabWidget; } if(conf->property["type"] == "ComboBox"){ return uiComboBox; } if(conf->property["type"] == "Item"){ return NULL; } if(conf->property["type"] == "PushButton"){ return uiPushButton; } if(conf->property["type"] == "CheckBox"){ return uiCheckBox; } if(conf->property["type"] == "ButtonBox"){ return uiButtonBox; } if(conf->property["type"] == "RadioButton"){ return uiRadioButton; } return NULL; } /** * @brief CUI::getProperty 获取该配置的某一项 * @param key * @return val */ QString CUI::getProperty(QString s) { return conf->property[s]; } /** * @brief CUI::autoArrangeWidgets 自动整理组件 */ void CUI::autoArrangeWidgets() { qint32 labelMaxWidth = INT_MIN; labelMaxWidth = getMaxLabelWidth(); setLabelWidth(labelMaxWidth); } /** * @brief CUI::getMaxLabelWidth 根据类型,获取组件的宽度 * @return 宽度 */ qint32 CUI::getMaxLabelWidth() { qint32 res = INT_MIN; if(conf->property["type"] == "LineEdit"){ res = uiLineEdit->getLabelWidth(); } else if(conf->property["type"] == "ComboBox"){ res = uiComboBox->getLabelWidth(); }else{ for(auto &ui:subCUI){ res = qMax(res,ui->getMaxLabelWidth()); } } return res; } void CUI::setLabelWidth(qint32 width) { if(conf->property["type"] == "LineEdit"){ uiLineEdit->setLabelWidth(width); } else if(conf->property["type"] == "ComboBox"){ uiComboBox->setLabelWidth(width); }else{ for(auto &ui:subCUI){ ui->setLabelWidth(width); } } }