CreateProjView.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. #include "CreateProjView.h"
  2. #include <Widgets/LineEdit.h>
  3. #include <Widgets/Button.h>
  4. #include <Widgets/CheckBox.h>
  5. #include <QGridLayout>
  6. #include <QLabel>
  7. #include <QDebug>
  8. CreateProjView::CreateProjView(QWidget *parent) : QWidget(parent)
  9. {
  10. initWindow();
  11. initialize();
  12. initLayout();
  13. connectSignalsAndSlots();
  14. }
  15. const QString CreateProjView::projName() const
  16. {
  17. return m_nameLineEdit->text();
  18. }
  19. bool CreateProjView::importanceSelected() const
  20. {
  21. return m_importanceCheckBox->isChecked();
  22. }
  23. bool CreateProjView::schemeSelected() const
  24. {
  25. return m_schemeCheckBox->isChecked();
  26. }
  27. void CreateProjView::clearInputs()
  28. {
  29. m_nameLineEdit->clear();
  30. m_importanceCheckBox->setChecked(false);
  31. m_schemeCheckBox->setChecked(false);
  32. }
  33. void CreateProjView::initWindow()
  34. {
  35. setWindowTitle("新建工程");
  36. setWindowFlags(Qt::Window);
  37. setWindowFlag(Qt::WindowMinMaxButtonsHint, false);
  38. resize(400, 200);
  39. }
  40. void CreateProjView::initialize()
  41. {
  42. m_gridLayout = new QGridLayout(this);
  43. m_nameLabel = new QLabel(this);
  44. m_nameLabel->setText("工程名:");
  45. m_typeLabel = new QLabel(this);
  46. m_typeLabel->setText("类型(多选):");
  47. m_nameLineEdit = new LineEdit(this);
  48. m_nameLineEdit->setPlaceholderText("请输入工程名");
  49. m_nameLineEdit->setMaximumWidth(500);
  50. m_nameLineEdit->setMinimumWidth(300);
  51. m_importanceCheckBox = new CheckBox("能力与技术重要度评估", this);
  52. m_schemeCheckBox = new CheckBox("技术方案评估", this);
  53. m_createButton = new PushButton("创建", this);
  54. m_createButton->setEnabled(false);
  55. m_cancelButton = new PushButton("取消", this);
  56. }
  57. void CreateProjView::initLayout()
  58. {
  59. m_gridLayout->setAlignment(Qt::AlignTop | Qt::AlignLeft);
  60. m_gridLayout->setContentsMargins(50, 20, 50, 20);
  61. m_gridLayout->addWidget(m_nameLabel, 0, 0, 1, 1, Qt::AlignRight);
  62. m_gridLayout->addWidget(m_nameLineEdit, 0, 1, 1, 5, Qt::AlignLeft);
  63. m_gridLayout->addWidget(new QWidget(this), 1, 1, 4, 1, Qt::AlignLeft);
  64. m_gridLayout->addWidget(m_typeLabel, 4, 0, 1, 1, Qt::AlignRight);
  65. m_gridLayout->addWidget(m_importanceCheckBox, 4, 1, 1, 5, Qt::AlignLeft);
  66. m_gridLayout->addWidget(m_schemeCheckBox, 5, 1, 1, 5, Qt::AlignLeft);
  67. m_gridLayout->addWidget(new QWidget(this), 6, 1, 4, 1, Qt::AlignLeft);
  68. m_gridLayout->addWidget(m_createButton, 10, 4, 1, 1, Qt::AlignLeft);
  69. m_gridLayout->addWidget(m_cancelButton, 10, 5, 1, 1, Qt::AlignLeft);
  70. }
  71. void CreateProjView::connectSignalsAndSlots()
  72. {
  73. connect(m_nameLineEdit, &LineEdit::textChanged, this, &CreateProjView::slotTextChanged);
  74. connect(m_importanceCheckBox, &CheckBox::stateChanged, this, &CreateProjView::slotCheckBoxChanged);
  75. connect(m_schemeCheckBox, &CheckBox::stateChanged, this, &CreateProjView::slotCheckBoxChanged);
  76. connect(m_createButton, &PushButton::clicked, this, &CreateProjView::slotCreateClicked);
  77. connect(m_cancelButton, &PushButton::clicked, this, &CreateProjView::slotCancelClicked);
  78. }
  79. void CreateProjView::updateCreateButtonState()
  80. {
  81. bool nameValid = m_nameLineEdit->text().length() > 0;
  82. bool typeValid = m_importanceCheckBox->isChecked() || m_schemeCheckBox->isChecked();
  83. m_createButton->setEnabled(nameValid && typeValid);
  84. }
  85. void CreateProjView::slotTextChanged(const QString &text)
  86. {
  87. m_nameLineEdit->setText(text.trimmed());
  88. updateCreateButtonState();
  89. }
  90. void CreateProjView::slotCheckBoxChanged(int)
  91. {
  92. updateCreateButtonState();
  93. }
  94. void CreateProjView::slotCreateClicked()
  95. {
  96. emit signalCreate();
  97. close();
  98. }
  99. void CreateProjView::slotCancelClicked()
  100. {
  101. close();
  102. }