CreateProjWidget.cpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. #include "CreateProjWidget.h"
  2. #include <dbService/ClassSet.h>
  3. #include <Widgets/LineEdit.h>
  4. #include <Widgets/Button.h>
  5. #include <Widgets/CheckBox.h>
  6. #include <Widgets/SpinBox.h>
  7. #include <QGridLayout>
  8. #include <QLabel>
  9. #include <QDebug>
  10. CreateProjWidget::CreateProjWidget(QWidget *parent) : QDialog(parent)
  11. {
  12. initWindow();
  13. initWidgets();
  14. initLayout();
  15. connectSignalsAndSlots();
  16. }
  17. const QString CreateProjWidget::projName() const
  18. {
  19. return m_name->text();
  20. }
  21. void CreateProjWidget::clearInputs()
  22. {
  23. m_name->clear();
  24. m_type1->setChecked(false);
  25. m_type2->setChecked(false);
  26. m_type3->setChecked(false);
  27. }
  28. void CreateProjWidget::initWindow()
  29. {
  30. setWindowTitle("新建工程");
  31. // setWindowFlags(Qt::Window);
  32. // setWindowFlag(Qt::WindowMinMaxButtonsHint, false);
  33. setModal(true);
  34. setWindowFlags(Qt::Dialog);
  35. setWindowFlag(Qt::WindowContextHelpButtonHint, false);
  36. resize(400, 600);
  37. }
  38. void CreateProjWidget::initWidgets()
  39. {
  40. m_summary = new QLabel(this);
  41. m_summary->setText("项目概要:");
  42. m_taskName = new LineEdit(this);
  43. m_taskName->setPlaceholderText("任务名称");
  44. m_evalTime = new DateTimeEdit(this);
  45. m_evalTime->setDateTime(QDateTime::currentDateTime());
  46. m_evalPurpose = new LineEdit(this);
  47. m_evalPurpose->setPlaceholderText("评估目的");
  48. m_evalUnit = new LineEdit(this);
  49. m_evalUnit->setPlaceholderText("评估单位");
  50. m_evalCrew = new LineEdit(this);
  51. m_evalCrew->setPlaceholderText("评估人员");
  52. m_rank = new LineEdit(this);
  53. m_rank->setPlaceholderText("职称");
  54. m_note = new TextEdit(this);
  55. m_note->setPlaceholderText("备注");
  56. m_separator = new QWidget(this);
  57. m_separator->setFixedHeight(1);
  58. m_separator->setStyleSheet("background-color:#dddddd");
  59. m_nameLabel = new QLabel(this);
  60. m_nameLabel->setText("项目名称:");
  61. m_name = new LineEdit(this);
  62. m_name->setPlaceholderText("请输入项目名称");
  63. m_typeLabel = new QLabel(this);
  64. m_typeLabel->setText("评估类型:");
  65. m_type1 = new CheckBox(EngineerInfo::nameOfEvalType(EngineerInfo::Requirements), this);
  66. m_type2 = new CheckBox(EngineerInfo::nameOfEvalType(EngineerInfo::SchemeOptimization), this);
  67. m_type3 = new CheckBox(EngineerInfo::nameOfEvalType(EngineerInfo::OverallEfficiency), this);
  68. m_confirm = new PushButton("创建", this);
  69. m_cancel = new PushButton("取消", this);
  70. }
  71. void CreateProjWidget::initLayout()
  72. {
  73. // 总体布局
  74. m_layout = new QVBoxLayout(this);
  75. m_layout->setContentsMargins(50, 20, 50, 20);
  76. m_summaryLayout = new QVBoxLayout();
  77. m_layout->addLayout(m_summaryLayout);
  78. m_layout->addWidget(m_separator);
  79. m_projLayout = new QGridLayout();
  80. m_layout->addLayout(m_projLayout);
  81. m_btnLayout = new QHBoxLayout();
  82. m_layout->addLayout(m_btnLayout);
  83. // 项目概要布局
  84. m_summaryLayout->addWidget(m_summary);
  85. m_summaryLayout->addWidget(m_taskName);
  86. m_summaryLayout->addWidget(m_evalTime);
  87. m_summaryLayout->addWidget(m_evalPurpose);
  88. m_summaryLayout->addWidget(m_evalUnit);
  89. m_summaryLayout->addWidget(m_evalCrew);
  90. m_summaryLayout->addWidget(m_rank);
  91. m_summaryLayout->addWidget(m_note);
  92. // 项目信息布局
  93. m_projLayout->addWidget(m_nameLabel, 0, 0, 1, 1, Qt::AlignLeft);
  94. m_projLayout->addWidget(m_name, 0, 1, 1, 5, Qt::AlignLeft);
  95. m_projLayout->addWidget(new QWidget(this), 1, 1, 4, 1, Qt::AlignLeft);
  96. m_projLayout->addWidget(m_typeLabel, 4, 0, 1, 1, Qt::AlignLeft);
  97. m_projLayout->addWidget(m_type1, 4, 1, 1, 5, Qt::AlignLeft);
  98. m_projLayout->addWidget(m_type2, 5, 1, 1, 5, Qt::AlignLeft);
  99. m_projLayout->addWidget(m_type3, 6, 1, 1, 5, Qt::AlignLeft);
  100. // 按钮布局
  101. m_btnLayout->addStretch();
  102. m_btnLayout->addWidget(m_confirm);
  103. m_btnLayout->addWidget(m_cancel);
  104. }
  105. void CreateProjWidget::connectSignalsAndSlots()
  106. {
  107. connect(m_name, &LineEdit::textChanged, this, &CreateProjWidget::slotProjNameChanged);
  108. connect(m_confirm, &PushButton::clicked, this, &CreateProjWidget::slotCreateClicked);
  109. connect(m_cancel, &PushButton::clicked, this, &CreateProjWidget::slotCancelClicked);
  110. }
  111. void CreateProjWidget::updateCreateButtonState()
  112. {
  113. bool summaryValid;
  114. bool nameValid;
  115. bool typeValid;
  116. m_confirm->setEnabled(summaryValid && nameValid && typeValid);
  117. }
  118. void CreateProjWidget::slotProjNameChanged(const QString &text)
  119. {
  120. m_name->setText(text.trimmed());
  121. updateCreateButtonState();
  122. }
  123. void CreateProjWidget::slotCreateClicked()
  124. {
  125. emit signalCreate();
  126. close();
  127. }
  128. void CreateProjWidget::slotCancelClicked()
  129. {
  130. close();
  131. }