#include "CreateProjWidget.h" #include #include #include #include #include #include #include #include CreateProjWidget::CreateProjWidget(QWidget *parent) : QDialog(parent) { initWindow(); initWidgets(); initLayout(); connectSignalsAndSlots(); } const QString CreateProjWidget::projName() const { return m_name->text(); } void CreateProjWidget::clearInputs() { m_name->clear(); m_type1->setChecked(false); m_type2->setChecked(false); m_type3->setChecked(false); } void CreateProjWidget::initWindow() { setWindowTitle("新建工程"); // setWindowFlags(Qt::Window); // setWindowFlag(Qt::WindowMinMaxButtonsHint, false); setModal(true); setWindowFlags(Qt::Dialog); setWindowFlag(Qt::WindowContextHelpButtonHint, false); resize(400, 600); } void CreateProjWidget::initWidgets() { m_summary = new QLabel(this); m_summary->setText("项目概要:"); m_taskName = new LineEdit(this); m_taskName->setPlaceholderText("任务名称"); m_evalTime = new DateTimeEdit(this); m_evalTime->setDateTime(QDateTime::currentDateTime()); m_evalPurpose = new LineEdit(this); m_evalPurpose->setPlaceholderText("评估目的"); m_evalUnit = new LineEdit(this); m_evalUnit->setPlaceholderText("评估单位"); m_evalCrew = new LineEdit(this); m_evalCrew->setPlaceholderText("评估人员"); m_rank = new LineEdit(this); m_rank->setPlaceholderText("职称"); m_note = new TextEdit(this); m_note->setPlaceholderText("备注"); m_separator = new QWidget(this); m_separator->setFixedHeight(1); m_separator->setStyleSheet("background-color:#dddddd"); m_nameLabel = new QLabel(this); m_nameLabel->setText("项目名称:"); m_name = new LineEdit(this); m_name->setPlaceholderText("请输入项目名称"); m_typeLabel = new QLabel(this); m_typeLabel->setText("评估类型:"); m_type1 = new CheckBox(EngineerInfo::nameOfEvalType(EngineerInfo::Requirements), this); m_type2 = new CheckBox(EngineerInfo::nameOfEvalType(EngineerInfo::SchemeOptimization), this); m_type3 = new CheckBox(EngineerInfo::nameOfEvalType(EngineerInfo::OverallEfficiency), this); m_confirm = new PushButton("创建", this); m_cancel = new PushButton("取消", this); } void CreateProjWidget::initLayout() { // 总体布局 m_layout = new QVBoxLayout(this); m_layout->setContentsMargins(50, 20, 50, 20); m_summaryLayout = new QVBoxLayout(); m_layout->addLayout(m_summaryLayout); m_layout->addWidget(m_separator); m_projLayout = new QGridLayout(); m_layout->addLayout(m_projLayout); m_btnLayout = new QHBoxLayout(); m_layout->addLayout(m_btnLayout); // 项目概要布局 m_summaryLayout->addWidget(m_summary); m_summaryLayout->addWidget(m_taskName); m_summaryLayout->addWidget(m_evalTime); m_summaryLayout->addWidget(m_evalPurpose); m_summaryLayout->addWidget(m_evalUnit); m_summaryLayout->addWidget(m_evalCrew); m_summaryLayout->addWidget(m_rank); m_summaryLayout->addWidget(m_note); // 项目信息布局 m_projLayout->addWidget(m_nameLabel, 0, 0, 1, 1, Qt::AlignLeft); m_projLayout->addWidget(m_name, 0, 1, 1, 5, Qt::AlignLeft); m_projLayout->addWidget(new QWidget(this), 1, 1, 4, 1, Qt::AlignLeft); m_projLayout->addWidget(m_typeLabel, 4, 0, 1, 1, Qt::AlignLeft); m_projLayout->addWidget(m_type1, 4, 1, 1, 5, Qt::AlignLeft); m_projLayout->addWidget(m_type2, 5, 1, 1, 5, Qt::AlignLeft); m_projLayout->addWidget(m_type3, 6, 1, 1, 5, Qt::AlignLeft); // 按钮布局 m_btnLayout->addStretch(); m_btnLayout->addWidget(m_confirm); m_btnLayout->addWidget(m_cancel); } void CreateProjWidget::connectSignalsAndSlots() { connect(m_name, &LineEdit::textChanged, this, &CreateProjWidget::slotProjNameChanged); connect(m_confirm, &PushButton::clicked, this, &CreateProjWidget::slotCreateClicked); connect(m_cancel, &PushButton::clicked, this, &CreateProjWidget::slotCancelClicked); } void CreateProjWidget::updateCreateButtonState() { bool summaryValid; bool nameValid; bool typeValid; m_confirm->setEnabled(summaryValid && nameValid && typeValid); } void CreateProjWidget::slotProjNameChanged(const QString &text) { m_name->setText(text.trimmed()); updateCreateButtonState(); } void CreateProjWidget::slotCreateClicked() { emit signalCreate(); close(); } void CreateProjWidget::slotCancelClicked() { close(); }