#include "CreateProjWidget.h" #include #include #include #include #include #include #include #include #include CreateProjWidget::CreateProjWidget(QWidget *parent) : QDialog(parent) { initWindow(); initWidgets(); resetInputs(); initLayout(); connectSignalsAndSlots(); } CreateProjWidget::Mode CreateProjWidget::mode() const { return m_mode; } void CreateProjWidget::setMode(CreateProjWidget::Mode mode) { m_mode = mode; switch (mode) { case Create: { setWindowTitle("创建项目"); m_confirm->setText("创建"); break; } case Update: { setWindowTitle("修改项目"); m_confirm->setText("保存"); break; } case Info: { setWindowTitle("项目信息"); break; } } bool c = (mode == Create); bool cu = (mode == Update || mode == Create); bool i = (mode == Info); m_task->setEnabled(cu); m_time->setEnabled(c); m_purpose->setReadOnly(!cu); m_unit->setEnabled(cu); m_crew->setEnabled(cu); m_rank->setEnabled(cu); m_note->setReadOnly(!cu); m_proj->setEnabled(cu); m_type1->setEnabled(c); m_type2->setEnabled(c); m_type3->setEnabled(c); m_edit->setVisible(i); m_confirm->setVisible(cu); m_cancel->setVisible(cu); } void CreateProjWidget::resetInputs() { m_task->clear(); m_time->setDateTime(QDateTime::currentDateTime()); m_purpose->clear(); m_unit->clear(); m_crew->clear(); m_rank->clear(); m_note->clear(); m_proj->clear(); m_type1->setChecked(false); m_type2->setChecked(false); m_type3->setChecked(false); } ProjectInfo *CreateProjWidget::projInfo() const { return m_projInfo; } ProjectInfo CreateProjWidget::editedProjInfo() const { ProjectInfo proj; proj.taskName = m_task->text(); proj.estimateTime = QString::number(m_time->dateTime().toTime_t()); proj.estimateObjective = m_purpose->toPlainText(); proj.estimateDept = m_unit->text(); proj.estimatePerson = m_crew->text(); proj.positionalTitles = m_rank->text(); proj.remark = m_note->toPlainText(); proj.projectName = m_proj->text(); ProjectManager::EvalTypes t; t |= (m_type1->isChecked() ? ProjectManager::DemandEval : ProjectManager::None); t |= (m_type2->isChecked() ? ProjectManager::OptimalEval : ProjectManager::None); t |= (m_type3->isChecked() ? ProjectManager::EfficiencyEval : ProjectManager::None); if (t != ProjectManager::None) { proj.estimateType = QString::number(t); } return proj; } void CreateProjWidget::setProjectInfo(ProjectInfo *info) { m_projInfo = info; m_task->setText(info->taskName); QDateTime time = QDateTime::fromTime_t(info->estimateTime.toUInt()); m_time->setDateTime(time); m_purpose->setText(info->estimateObjective); m_unit->setText(info->estimateDept); m_crew->setText(info->estimatePerson); m_rank->setText(info->positionalTitles); m_note->setText(info->remark); m_proj->setText(info->projectName); ProjectManager::EvalTypes types = ProjectManager::evalTypes(*info); m_type1->setChecked((types & ProjectManager::DemandEval) == ProjectManager::DemandEval); m_type2->setChecked((types & ProjectManager::OptimalEval) == ProjectManager::OptimalEval); m_type3->setChecked((types & ProjectManager::EfficiencyEval) == ProjectManager::EfficiencyEval); } void CreateProjWidget::initWindow() { setWindowTitle("新建工程"); // setWindowFlags(Qt::Window); // setWindowFlag(Qt::WindowMinMaxButtonsHint, false); setModal(true); setWindowFlags(Qt::Dialog); setWindowFlag(Qt::WindowContextHelpButtonHint, false); setFixedSize(460, 700); } void CreateProjWidget::initWidgets() { m_summary = new QLabel(this); m_summary->setText("项目概要:"); m_task = new LineEdit(this); m_task->setPlaceholderText("任务名称"); m_time = new DateTimeEdit(this); m_purpose = new TextEdit(this); m_purpose->setPlaceholderText("评估目的"); m_unit = new LineEdit(this); m_unit->setPlaceholderText("评估单位"); m_crew = new LineEdit(this); m_crew->setPlaceholderText("评估人员"); m_rank = new LineEdit(this); m_rank->setPlaceholderText("职称"); m_note = new TextEdit(this); m_note->setPlaceholderText("备注"); m_note->setFontPointSize(10); m_taskLabel = new QLabel(this); m_taskLabel->setText("任务名称:"); m_timeLabel = new QLabel(this); m_timeLabel->setText("评估时间:"); m_purposeLabel = new QLabel(this); m_purposeLabel->setText("评估目的:"); m_unitLabel = new QLabel(this); m_unitLabel->setText("评估单位:"); m_crewLabel = new QLabel(this); m_crewLabel->setText("评估人员:"); m_rankLabel = new QLabel(this); m_rankLabel->setText("职称:"); m_noteLabel = new QLabel(this); m_noteLabel->setText("备注:"); m_separator = new QWidget(this); m_separator->setFixedHeight(1); m_separator->setStyleSheet("background-color:#dddddd"); m_projLabel = new QLabel(this); m_projLabel->setText("项目名称:"); m_proj = new LineEdit(this); m_proj->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_edit = new PushButton("修改", this); m_confirm = new PushButton("创建", this); m_cancel = new PushButton("取消", this); } void CreateProjWidget::initLayout() { int minEditWidth = 300; // 总体布局 m_layout = new QVBoxLayout(this); m_layout->setContentsMargins(20, 20, 20, 20); m_layout->addWidget(m_summary); m_summaryLayout = new QGridLayout(); 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_task->setFixedWidth(minEditWidth); m_time->setFixedWidth(minEditWidth); m_purpose->setFixedWidth(minEditWidth); m_unit->setFixedWidth(minEditWidth); m_crew->setFixedWidth(minEditWidth); m_rank->setFixedWidth(minEditWidth); m_note->setFixedWidth(minEditWidth); m_purposeLabel->setContentsMargins(0, 10, 0, 10); m_noteLabel->setContentsMargins(0, 10, 0, 10); m_summaryLayout->setMargin(10); m_summaryLayout->addWidget(m_taskLabel, 1, 0, 1, 1, Qt::AlignRight); m_summaryLayout->addWidget(m_timeLabel, 2, 0, 1, 1, Qt::AlignRight); m_summaryLayout->addWidget(m_unitLabel, 3, 0, 1, 1, Qt::AlignRight); m_summaryLayout->addWidget(m_crewLabel, 4, 0, 1, 1, Qt::AlignRight); m_summaryLayout->addWidget(m_rankLabel, 5, 0, 1, 1, Qt::AlignRight); m_summaryLayout->addWidget(m_purposeLabel, 6, 0, 1, 1, Qt::AlignRight | Qt::AlignTop); m_summaryLayout->addWidget(m_noteLabel, 7, 0, 1, 1, Qt::AlignRight | Qt::AlignTop); m_summaryLayout->addWidget(m_task, 1, 1, 1, 1, Qt::AlignLeft); m_summaryLayout->addWidget(m_time, 2, 1, 1, 1, Qt::AlignLeft); m_summaryLayout->addWidget(m_unit, 3, 1, 1, 1, Qt::AlignLeft); m_summaryLayout->addWidget(m_crew, 4, 1, 1, 1, Qt::AlignLeft); m_summaryLayout->addWidget(m_rank, 5, 1, 1, 1, Qt::AlignLeft); m_summaryLayout->addWidget(m_purpose, 6, 1, 1, 1, Qt::AlignLeft); m_summaryLayout->addWidget(m_note, 7, 1, 1, 1, Qt::AlignLeft); // 项目信息布局 m_projLayout->setMargin(10); m_proj->setFixedWidth(minEditWidth); m_projLayout->addWidget(m_projLabel, 0, 0, 1, 1, Qt::AlignLeft); m_projLayout->addWidget(m_proj, 0, 1, 1, 1, Qt::AlignLeft); m_projLayout->addWidget(new QWidget(this), 1, 1, 1, 1, Qt::AlignLeft); m_projLayout->addWidget(m_typeLabel, 4, 0, 1, 1, Qt::AlignLeft); m_projLayout->addWidget(m_type1, 4, 1, 1, 1, Qt::AlignLeft); m_projLayout->addWidget(m_type2, 5, 1, 1, 1, Qt::AlignLeft); m_projLayout->addWidget(m_type3, 6, 1, 1, 1, Qt::AlignLeft); // 按钮布局 m_btnLayout->addStretch(); m_btnLayout->addWidget(m_edit); m_btnLayout->addWidget(m_confirm); m_btnLayout->addWidget(m_cancel); } void CreateProjWidget::connectSignalsAndSlots() { connect(m_task, &LineEdit::textChanged, this, &CreateProjWidget::slotTextChanged); connect(m_purpose, &TextEdit::textChanged, this, &CreateProjWidget::slotTextChanged); connect(m_unit, &LineEdit::textChanged, this, &CreateProjWidget::slotTextChanged); connect(m_crew, &LineEdit::textChanged, this, &CreateProjWidget::slotTextChanged); connect(m_rank, &LineEdit::textChanged, this, &CreateProjWidget::slotTextChanged); connect(m_note, &TextEdit::textChanged, this, &CreateProjWidget::slotTextChanged); connect(m_proj, &LineEdit::textChanged, this, &CreateProjWidget::slotTextChanged); connect(m_type1, &CheckBox::stateChanged, this, &CreateProjWidget::slotCheckBoxChanged); connect(m_type2, &CheckBox::stateChanged, this, &CreateProjWidget::slotCheckBoxChanged); connect(m_type3, &CheckBox::stateChanged, this, &CreateProjWidget::slotCheckBoxChanged); connect(m_edit, &PushButton::clicked, this, &CreateProjWidget::slotEditClicked); connect(m_confirm, &PushButton::clicked, this, &CreateProjWidget::slotConfirmClicked); connect(m_cancel, &PushButton::clicked, this, &CreateProjWidget::slotCancelClicked); } void CreateProjWidget::slotTextChanged() { LineEdit *lineEdit = dynamic_cast(sender()); if (lineEdit) { lineEdit->setText(lineEdit->text().trimmed()); } } void CreateProjWidget::slotCheckBoxChanged() { } void CreateProjWidget::slotEditClicked() { setMode(Update); } void CreateProjWidget::slotConfirmClicked() { ProjectInfo p = editedProjInfo(); qDebug() << __FUNCTION__ << p.taskName << p.estimateTime << p.estimateObjective << p.estimateDept << p.estimatePerson << p.positionalTitles << p.remark << p.projectName << p.estimateType; emit signalConfirm(); } void CreateProjWidget::slotCancelClicked() { if (m_mode == Update) { setMode(Info); setProjectInfo(m_projInfo); } else { close(); } }