DialogNewProject.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. #include "DialogNewProject.h"
  2. #include "Common.h"
  3. DialogNewProject::DialogNewProject(QWidget *parent)
  4. : QDialog(parent)
  5. {
  6. ui.setupUi(this);
  7. // 对话框初始化
  8. initUI();
  9. }
  10. DialogNewProject::~DialogNewProject()
  11. {
  12. }
  13. /// <summary>
  14. /// 对话框初始化
  15. /// </summary>
  16. void DialogNewProject::initUI()
  17. {
  18. this->setWindowTitle(("Add New Project"));
  19. this->setAttribute(Qt::WA_QuitOnClose);
  20. this->setWindowModality(Qt::ApplicationModal);
  21. m_bIsEmptyProject = false;
  22. // 槽函数
  23. connect(ui.createButton, SIGNAL(clicked()), this, SLOT(onButtonCreateClicked()));
  24. connect(ui.cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
  25. // 设置固定窗体大小
  26. //this->setFixedSize(375, 281);
  27. //this->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint);
  28. }
  29. /// <summary>
  30. ///
  31. /// </summary>
  32. /// <param name="event"></param>
  33. void DialogNewProject::showEvent(QShowEvent* /*event*/)
  34. {
  35. if (m_strProjectName == "Default")
  36. {
  37. m_strProjectName = "Project 01";
  38. m_strProjectName = "Project_" + QDateTime::currentDateTime().toString("[yyyy-MM-dd hh-mm]");
  39. }
  40. ui.editProjectName->setPlaceholderText(m_strProjectName);
  41. ui.editProjectPath->setPlaceholderText(m_strProjectPath);
  42. ui.editProjectInfo->setPlaceholderText(m_strProjectInfo);
  43. ui.editProjectName->setText(m_strProjectName);
  44. ui.editProjectPath->setText(m_strProjectPath);
  45. ui.editProjectInfo->setText(m_strProjectInfo);
  46. }
  47. /// <summary>
  48. /// Create按钮
  49. /// </summary>
  50. void DialogNewProject::onButtonCreateClicked()
  51. {
  52. QString strProjectName = ui.editProjectName->text();
  53. QString strProjectPath = ui.editProjectPath->text();
  54. QString strProjectInfo = ui.editProjectInfo->toPlainText();
  55. if (strProjectName.isEmpty())
  56. {
  57. return;
  58. }
  59. if (strProjectPath.isEmpty())
  60. {
  61. return;
  62. }
  63. m_strProjectName = strProjectName;
  64. m_strProjectPath = strProjectPath;
  65. if (!strProjectInfo.isEmpty())
  66. {
  67. m_strProjectInfo = strProjectInfo;
  68. }
  69. m_bIsEmptyProject = ui.checkBoxEmptyProject->isChecked();
  70. QString strPath = m_strProjectPath + "//" + m_strProjectName + DOC_POSTFIX;
  71. QFileInfo FileInfo(strPath);
  72. //如果在目录下查询到文件,即报告,以免文件被覆盖
  73. if (FileInfo.exists() == true)
  74. {
  75. QString strFilePath = FileInfo.absoluteFilePath();
  76. qDebug() << "File:" << strFilePath << "Already Exists";
  77. return;
  78. }
  79. this->accept();
  80. }
  81. /// <summary>
  82. /// 设置工程文件夹
  83. /// </summary>
  84. void DialogNewProject::on_btnSetFolder_clicked()
  85. {
  86. QString runPath = QCoreApplication::applicationDirPath(); //获取exe路径
  87. QString dirpath = QFileDialog::getExistingDirectory(this, "选择目录", runPath, QFileDialog::ShowDirsOnly);
  88. if (! dirpath.isEmpty())
  89. {
  90. ui.editProjectPath->setText(dirpath);
  91. }
  92. }