123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- #include "DialogNewProject.h"
- #include "Common.h"
- DialogNewProject::DialogNewProject(QWidget *parent)
- : QDialog(parent)
- {
- ui.setupUi(this);
- // 对话框初始化
- initUI();
- }
- DialogNewProject::~DialogNewProject()
- {
- }
- /// <summary>
- /// 对话框初始化
- /// </summary>
- void DialogNewProject::initUI()
- {
- this->setWindowTitle(("Add New Project"));
- this->setAttribute(Qt::WA_QuitOnClose);
- this->setWindowModality(Qt::ApplicationModal);
- m_bIsEmptyProject = false;
- // 槽函数
- connect(ui.createButton, SIGNAL(clicked()), this, SLOT(onButtonCreateClicked()));
- connect(ui.cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
- // 设置固定窗体大小
- //this->setFixedSize(375, 281);
- //this->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint);
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="event"></param>
- void DialogNewProject::showEvent(QShowEvent* /*event*/)
- {
- if (m_strProjectName == "Default")
- {
- m_strProjectName = "Project 01";
- m_strProjectName = "Project_" + QDateTime::currentDateTime().toString("[yyyy-MM-dd hh-mm]");
-
- }
- ui.editProjectName->setPlaceholderText(m_strProjectName);
- ui.editProjectPath->setPlaceholderText(m_strProjectPath);
- ui.editProjectInfo->setPlaceholderText(m_strProjectInfo);
- ui.editProjectName->setText(m_strProjectName);
- ui.editProjectPath->setText(m_strProjectPath);
- ui.editProjectInfo->setText(m_strProjectInfo);
- }
- /// <summary>
- /// Create按钮
- /// </summary>
- void DialogNewProject::onButtonCreateClicked()
- {
- QString strProjectName = ui.editProjectName->text();
- QString strProjectPath = ui.editProjectPath->text();
- QString strProjectInfo = ui.editProjectInfo->toPlainText();
- if (strProjectName.isEmpty())
- {
- return;
- }
- if (strProjectPath.isEmpty())
- {
- return;
- }
- m_strProjectName = strProjectName;
- m_strProjectPath = strProjectPath;
- if (!strProjectInfo.isEmpty())
- {
- m_strProjectInfo = strProjectInfo;
- }
- m_bIsEmptyProject = ui.checkBoxEmptyProject->isChecked();
- QString strPath = m_strProjectPath + "//" + m_strProjectName + DOC_POSTFIX;
- QFileInfo FileInfo(strPath);
- //如果在目录下查询到文件,即报告,以免文件被覆盖
- if (FileInfo.exists() == true)
- {
- QString strFilePath = FileInfo.absoluteFilePath();
- qDebug() << "File:" << strFilePath << "Already Exists";
- return;
- }
-
- this->accept();
- }
- /// <summary>
- /// 设置工程文件夹
- /// </summary>
- void DialogNewProject::on_btnSetFolder_clicked()
- {
- QString runPath = QCoreApplication::applicationDirPath(); //获取exe路径
- QString dirpath = QFileDialog::getExistingDirectory(this, "选择目录", runPath, QFileDialog::ShowDirsOnly);
- if (! dirpath.isEmpty())
- {
- ui.editProjectPath->setText(dirpath);
- }
- }
|