#include "T_CreateNewReportWidget.h" #include #include #include #include #include #include "ElaPushButton.h" #include "ElaLineEdit.h" #include "ElaComboBox.h" #include "ElaScrollPageArea.h" #include "ElaImageCard.h" #include "ElaStatusBar.h" #include "ElaText.h" #include "GenerateReportBase.h" #include "MainWindow.h" #include "CreateNewReport.h" using namespace std; T_CreateNewReportWidget::T_CreateNewReportWidget(QWidget* parent) : ElaWidget(parent) { setWindowTitle("新建报告"); setWindowIcon(QIcon(":/include/Image/Moon.jpg")); //setStyleSheet("QWidget { qproperty - windowTitleFontSize: 14px; }"); this->setIsFixedSize(true); setWindowModality(Qt::ApplicationModal); setWindowButtonFlags(ElaAppBarType::CloseButtonHint); //总布局(纵) QVBoxLayout* mainLayout = new QVBoxLayout(this); //第一行布局(横) QHBoxLayout* firstRowLayout = new QHBoxLayout; //第二行布局(横) QHBoxLayout* secondRowLayout = new QHBoxLayout; //第三行布局(横) QHBoxLayout* thirdRowLayout = new QHBoxLayout; //第一行内容:报告名称设置 ElaText* reportNameText = new ElaText("报告名称", this); reportNameText->setWordWrap(false); reportNameText->setTextPixelSize(14); //ElaLineEdit* _nameEdit = new ElaLineEdit(this); //_nameEdit->setPlaceholderText("搜索图标"); _nameEdit->setFixedSize(300,32); _nameEdit->setAlignment(Qt::AlignLeft); //_nameEdit->setStyleSheet("QLineEdit::placeholder { color: red; }");//yr-设置未生效 firstRowLayout->addWidget(reportNameText); firstRowLayout->addWidget(_nameEdit); firstRowLayout->setAlignment(Qt::AlignLeft); firstRowLayout->setSpacing(0); //第二行内容:模板调用 ElaText* templateCallText = new ElaText("模板调用", this); templateCallText->setWordWrap(false); templateCallText->setTextPixelSize(14); ElaComboBox* _templateCallComboBox = new ElaComboBox(this); QStringList _templateCallComboList { "无", //"模板1", }; _templateCallComboBox->setFixedWidth(310); _templateCallComboBox->addItems(_templateCallComboList); secondRowLayout->addWidget(templateCallText); secondRowLayout->addWidget(_templateCallComboBox); secondRowLayout->setAlignment(Qt::AlignLeft); secondRowLayout->setSpacing(2); //第三行内容:确定、取消按钮 ElaPushButton* cancelButton = new ElaPushButton("取消", this); cancelButton->setFixedWidth(80); ElaPushButton* confirmButton = new ElaPushButton("确定", this); confirmButton->setFixedWidth(80); thirdRowLayout->addWidget(cancelButton); thirdRowLayout->addWidget(confirmButton); thirdRowLayout->setAlignment(Qt::AlignRight); thirdRowLayout->setSpacing(2); //总体布局 //mainLayout->setContentsMargins(0, 0, 0, 0); mainLayout->addLayout(firstRowLayout); mainLayout->addLayout(secondRowLayout); mainLayout->addLayout(thirdRowLayout); //mainLayout->setSpacing(20); //接口 connect(_nameEdit, &ElaLineEdit::textEdited, this, &T_CreateNewReportWidget::slot_onNameEditTextEdit); connect(_nameEdit, &ElaLineEdit::focusIn, this, &T_CreateNewReportWidget::slot_onNameEditTextEdit); connect(cancelButton, &ElaPushButton::clicked, this, &T_CreateNewReportWidget::slot_cancelButtonClicked); connect(confirmButton, &ElaPushButton::clicked, this, &T_CreateNewReportWidget::slot_confirmButtonClicked); } T_CreateNewReportWidget::~T_CreateNewReportWidget() { } void T_CreateNewReportWidget::slot_onNameEditTextEdit(const QString& nameText) { setErrorMessagePrompt(QString("")); //yr-还需添加自定义规则判断 m_reportName = nameText; } void T_CreateNewReportWidget::slot_cancelButtonClicked() { //关闭窗口 ElaWidget::close(); } void T_CreateNewReportWidget::slot_confirmButtonClicked() { if (m_reportName.isEmpty()) { setErrorMessagePrompt(QString("报告名称不能为空!")); return; } else { GenerateReportBaseInstance->setCurrentReportName(m_reportName); //关闭窗口 ElaWidget::close(); GenerateReport::CreateNewReport tes; tes.accept(); } } void T_CreateNewReportWidget::setErrorMessagePrompt(QString errorMessage) { _nameEdit->setPlaceholderText(errorMessage); }