diff --git a/GUI/coregui/mainwindow/mainwindow.cpp b/GUI/coregui/mainwindow/mainwindow.cpp index d9bf9f635e99c321abb0ab54bb35c88fa24d7e66..4e2e905c142ccdc85bbcc253f50dbc0bc7a619ef 100644 --- a/GUI/coregui/mainwindow/mainwindow.cpp +++ b/GUI/coregui/mainwindow/mainwindow.cpp @@ -93,11 +93,6 @@ void MainWindow::newProject() void MainWindow::openProject() { - QString fileName = QFileDialog::getOpenFileName(this); -// std::cout << "XXX openProject() " << std::endl; -// QString directory = QFileDialog::getExistingDirectory(this, -// "AAA", -// "/home/pospelov",); } diff --git a/GUI/coregui/mainwindow/newprojectdialog.cpp b/GUI/coregui/mainwindow/newprojectdialog.cpp index e2e7f77eb420da4ff0cab044f90567456c9d779c..e1a7e0186983b94713600ac5bd22dc79fc9e2b72 100644 --- a/GUI/coregui/mainwindow/newprojectdialog.cpp +++ b/GUI/coregui/mainwindow/newprojectdialog.cpp @@ -14,37 +14,49 @@ NewProjectDialog::NewProjectDialog(QWidget *parent) : QDialog(parent) +// , m_nameLabel(0) + , m_projectNameEdit(0) +// , m_parentDirLabel(0) + , m_parentDirEdit(0) + , m_browseButton(0) + , m_warningLabel(0) + , m_cancelButton(0) + , m_createButton(0) + , m_valid_projectName(true) + , m_valid_parentDir(true) + { setMinimumSize(480, 280); setWindowTitle("New project"); + QLabel *nameLabel = new QLabel(tr("Project name:")); + m_projectNameEdit = new QLineEdit; + m_projectNameEdit->setText("Untitled"); + connect(m_projectNameEdit, SIGNAL(textEdited(QString)), this, SLOT(checkIfProjectNameIsValid(QString))); + nameLabel->setBuddy(m_projectNameEdit); - - m_nameLabel = new QLabel(tr("Project name:")); - m_nameEdit = new QLineEdit; - m_nameLabel->setBuddy(m_nameEdit); - - m_createinLabel = new QLabel(tr("Create in:")); - m_createinEdit = new QLineEdit; - m_createinEdit->setText(QDir::homePath()); - m_createinLabel->setBuddy(m_createinEdit); + QLabel *parentDirLabel = new QLabel(tr("Create in:")); + m_parentDirEdit = new QLineEdit; + m_parentDirEdit->setText(QDir::homePath()); + connect(m_parentDirEdit, SIGNAL(textEdited(QString)), this, SLOT(checkIfParentDirIsValid(QString))); + parentDirLabel->setBuddy(m_parentDirEdit); m_browseButton = new QPushButton(tr("Browse")); connect(m_browseButton, SIGNAL(clicked()), this, SLOT(setDirectory())); + m_warningLabel = new QLabel(); + m_createButton = new QPushButton(tr("Create")); m_cancelButton = new QPushButton(tr("Cancel")); - -// m_statusBar = new QStatusBar; - + connect(m_cancelButton, SIGNAL(clicked()), this, SLOT(close())); QGroupBox *projectGroup = new QGroupBox(tr("Project name and location")); QGridLayout *layout = new QGridLayout; - layout->addWidget(m_nameLabel, 0, 0); - layout->addWidget(m_nameEdit, 0, 1); - layout->addWidget(m_createinLabel, 1, 0); - layout->addWidget(m_createinEdit, 1, 1); + layout->addWidget(nameLabel, 0, 0); + layout->addWidget(m_projectNameEdit, 0, 1); + layout->addWidget(parentDirLabel, 1, 0); + layout->addWidget(m_parentDirEdit, 1, 1); layout->addWidget(m_browseButton,1,2); projectGroup->setLayout(layout); @@ -53,46 +65,97 @@ NewProjectDialog::NewProjectDialog(QWidget *parent) buttonsLayout->addStretch(1); buttonsLayout->addWidget(m_createButton); buttonsLayout->addWidget(m_cancelButton); -// buttonsLayout->setMargin(0); -// buttonsLayout->setSpacing(0); -// layout->addLayout(buttonsLayout); - QVBoxLayout *mainLayout = new QVBoxLayout; mainLayout->addWidget(projectGroup); + mainLayout->addWidget(m_warningLabel); mainLayout->addStretch(); mainLayout->addLayout(buttonsLayout); -// mainLayout->addWidget(m_statusBar); setLayout(mainLayout); +} + +void NewProjectDialog::setDirectory() +{ + QString dirname = QFileDialog::getExistingDirectory(this, + "AAA", + "/home/pospelov", + QFileDialog::DontResolveSymlinks | QFileDialog::ShowDirsOnly); + if (!dirname.isEmpty()) { + checkIfParentDirIsValid(dirname); + } } -void NewProjectDialog::setDirectory() +void NewProjectDialog::checkIfParentDirIsValid(const QString &dirname) { + if(QFile::exists(dirname)) { + setValidParentDir(true); + m_parentDirEdit->setText(dirname); + } else { + setValidParentDir(false); + } + updateWarningStatus(); -// QFileDialog::Options options = QFileDialog::DontResolveSymlinks | QFileDialog::ShowDirsOnly; +} - std::cout << "XXX " << m_createinEdit->text().toStdString() << std::endl; - QString directory = QFileDialog::getExistingDirectory(this, - "AAA", - "/home/pospelov", - QFileDialog::DontResolveSymlinks | QFileDialog::ShowDirsOnly); +void NewProjectDialog::checkIfProjectNameIsValid(const QString &projectName) +{ - std::cout << "XXX 2.1" << m_createinEdit->text().toStdString(); + QDir projectDir = getParentDirName() + "/" + projectName; + if(projectDir.exists()) { + setValidProjectName(false); + } else { + setValidProjectName(true); + } + updateWarningStatus(); +} - if (!directory.isEmpty()) - m_createinEdit->setText(directory); + +void NewProjectDialog::setValidProjectName(bool status) +{ + m_valid_projectName = status; + QPalette palette; + if(m_valid_projectName) { + palette.setColor(QPalette::Text, Qt::black); + } else { + palette.setColor(QPalette::Text,Qt::darkRed); + } + m_projectNameEdit->setPalette(palette); +} +void NewProjectDialog::setValidParentDir(bool status) +{ + m_valid_parentDir = status; + QPalette palette; + if(m_valid_parentDir) { + palette.setColor(QPalette::Text, Qt::black); + } else { + palette.setColor(QPalette::Text,Qt::darkRed); + } + m_parentDirEdit->setPalette(palette); } +void NewProjectDialog::updateWarningStatus() +{ + if(m_valid_parentDir && m_valid_projectName) { + m_createButton->setEnabled(true); + m_warningLabel->setText(""); + } else if(!m_valid_parentDir ) { + m_createButton->setEnabled(false); + m_warningLabel->setText("<font color='darkRed'> The path '"+getParentDirName()+"' does not exist. </font>"); + } else if(!m_valid_projectName ) { + m_createButton->setEnabled(false); + m_warningLabel->setText("<font color='darkRed'> The directory '"+getProjectName()+"' already exists. </font>"); + } +} diff --git a/GUI/coregui/mainwindow/newprojectdialog.h b/GUI/coregui/mainwindow/newprojectdialog.h index b05576ae1447cf87fda47d25d2608fd1f3732639..85c3387d1479b952b5e61f4ea768010ae7e3e5d0 100644 --- a/GUI/coregui/mainwindow/newprojectdialog.h +++ b/GUI/coregui/mainwindow/newprojectdialog.h @@ -2,11 +2,13 @@ #define NEWPROJECTDIALOG_H #include <QDialog> +#include <QString> +#include <QLineEdit> class QLabel; -class QLineEdit; class QPushButton; class QStatusBar; +class QPalette; //! new project dialog window @@ -18,15 +20,29 @@ public: private slots: void setDirectory(); + void checkIfParentDirIsValid(const QString &dirname); + void checkIfProjectNameIsValid(const QString &projectName); + + QString getProjectName() { return m_projectNameEdit->text(); } + QString getParentDirName() { return m_parentDirEdit->text(); } private: - QLabel *m_nameLabel; - QLineEdit *m_nameEdit; - QLabel *m_createinLabel; - QLineEdit *m_createinEdit; + void setValidProjectName(bool status); + void setValidParentDir(bool status); + void updateWarningStatus(); + +// QLabel *m_nameLabel; + QLineEdit *m_projectNameEdit; +// QLabel *m_parentDirLabel; + QLineEdit *m_parentDirEdit; QPushButton *m_browseButton; + QLabel *m_warningLabel; QPushButton *m_cancelButton; QPushButton *m_createButton; + + bool m_valid_projectName; + bool m_valid_parentDir; + };