#include "DialogNewProject.h"
#include "Common.h"
DialogNewProject::DialogNewProject(QWidget *parent)
: QDialog(parent)
{
ui.setupUi(this);
// 对话框初始化
initUI();
}
DialogNewProject::~DialogNewProject()
{
}
///
/// 对话框初始化
///
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);
}
///
///
///
///
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);
}
///
/// Create按钮
///
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();
}
///
/// 设置工程文件夹
///
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);
}
}