You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
178 lines
4.0 KiB
C++
178 lines
4.0 KiB
C++
#include "CUI.h"
|
|
|
|
#include<CUIConfig.h>
|
|
#include<CUIWidget.h>
|
|
#include<CUIGroupBox.h>
|
|
#include<CUILineEdit.h>
|
|
#include<CUITabWidget.h>
|
|
#include<CUIComboBox.h>
|
|
#include<CUIPushButton.h>
|
|
#include<CUICheckBox.h>
|
|
#include<CUIRadioButton.h>
|
|
#include<QDebug>
|
|
#include<CUIButtonBox.h>
|
|
#include<QVBoxLayout>
|
|
|
|
/**
|
|
* @brief CUI::CUI 构造函数
|
|
* @param conf 配置信息
|
|
*/
|
|
CUI::CUI(QWidget *parent, CUIConfig *conf): QWidget(parent)
|
|
{
|
|
this->conf = conf;
|
|
// this->conf->printConfig();
|
|
qDebug() << "----------------------";
|
|
buildUI();
|
|
}
|
|
|
|
/**
|
|
* @brief CUI::buildUI 创建组件
|
|
*/
|
|
void CUI::buildUI()
|
|
{
|
|
QWidget* widget = nullptr;
|
|
QString type = conf->getPropertyValue("type");
|
|
if(type == "") {
|
|
return;
|
|
}
|
|
if(type == "Widget") {
|
|
widget = new CUIWidget(conf, subCUI);
|
|
} else if(type == "GroupBox") {
|
|
widget = new CUIGroupBox(conf, subCUI);
|
|
} else if(type == "LineEdit") {
|
|
widget = new CUILineEdit(conf, subCUI);
|
|
} else if(type == "TabWidget") {
|
|
widget = new CUITabWidget(conf, subCUI);
|
|
} else if(type == "ComboBox") {
|
|
widget = new CUIComboBox(conf, subCUI);
|
|
} else if(type == "PushButton") {
|
|
widget = new CUIPushButton(conf, subCUI);
|
|
} else if(type == "CheckBox") {
|
|
widget = new CUICheckBox(conf, subCUI);
|
|
} else if(type == "RadioButton") {
|
|
widget = new CUIRadioButton(conf, subCUI);
|
|
} else if(type == "ButtonBox") {
|
|
widget = new CUIButtonBox(conf, subCUI);
|
|
}
|
|
if (widget) {
|
|
qDebug() << "----------- ui widget is not null";
|
|
QVBoxLayout *layout = new QVBoxLayout;
|
|
layout->addWidget(widget);
|
|
this->setLayout(layout);
|
|
// QSpacerItem* spacer = new QSpacerItem(5000,5000,QSizePolicy::Maximum,QSizePolicy::Maximum);
|
|
// layout->addItem(spacer);
|
|
|
|
} else {
|
|
qDebug() << "----------- ui widget is null";
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @brief CUI::check 对管理的组件进行检查
|
|
*/
|
|
void CUI::check()
|
|
{
|
|
}
|
|
|
|
/**
|
|
* @brief CUI::getUI 返回组件
|
|
* @return QWidget,组件
|
|
*/
|
|
QWidget *CUI::getUI()
|
|
{
|
|
QString type = conf->getPropertyValue("type");
|
|
if(type == "Item") {
|
|
return NULL;
|
|
} else {
|
|
return this;
|
|
}
|
|
return NULL;
|
|
if(type == "Widget") {
|
|
return uiWidget;
|
|
}
|
|
if(type == "GroupBox") {
|
|
return uiGroupBox;
|
|
}
|
|
if(type == "LineEdit") {
|
|
return uiLineEdit;
|
|
}
|
|
if(type == "TabWidget") {
|
|
return uiTabWidget;
|
|
}
|
|
if(type == "ComboBox") {
|
|
return uiComboBox;
|
|
}
|
|
if(type == "Item") {
|
|
return NULL;
|
|
}
|
|
if(type == "PushButton") {
|
|
return uiPushButton;
|
|
}
|
|
if(type == "CheckBox") {
|
|
return uiCheckBox;
|
|
}
|
|
if(type == "ButtonBox") {
|
|
return uiButtonBox;
|
|
}
|
|
if(type == "RadioButton") {
|
|
return uiRadioButton;
|
|
}
|
|
return NULL;
|
|
}
|
|
|
|
/**
|
|
* @brief CUI::getProperty 获取该配置的某一项
|
|
* @param key
|
|
* @return val
|
|
*/
|
|
QString CUI::getProperty(QString s)
|
|
{
|
|
// return conf->property[s];
|
|
return conf->getPropertyValue(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;
|
|
QString type = conf->getPropertyValue("type");
|
|
if(type == "LineEdit") {
|
|
res = uiLineEdit->getLabelWidth();
|
|
} else if(type == "ComboBox") {
|
|
res = uiComboBox->getLabelWidth();
|
|
} else {
|
|
for(auto &ui : subCUI) {
|
|
res = qMax(res, ui->getMaxLabelWidth());
|
|
}
|
|
}
|
|
return res;
|
|
}
|
|
|
|
void CUI::setLabelWidth(qint32 width)
|
|
{
|
|
QString type = conf->getPropertyValue("type");
|
|
if(type == "LineEdit") {
|
|
uiLineEdit->setLabelWidth(width);
|
|
} else if(type == "ComboBox") {
|
|
uiComboBox->setLabelWidth(width);
|
|
} else {
|
|
for(auto &ui : subCUI) {
|
|
ui->setLabelWidth(width);
|
|
}
|
|
}
|
|
}
|
|
|