| 1 | /* |
| 2 | * Copyright (C) 2020-2022 Roy Qu (royqh1979@gmail.com) |
| 3 | * |
| 4 | * This program is free software: you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation, either version 3 of the License, or |
| 7 | * (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 16 | */ |
| 17 | #include "newclassdialog.h" |
| 18 | #include "ui_newclassdialog.h" |
| 19 | #include "../iconsmanager.h" |
| 20 | #include "../settings.h" |
| 21 | #include <QFileDialog> |
| 22 | |
| 23 | NewClassDialog::NewClassDialog(QWidget *parent) : |
| 24 | QDialog(parent), |
| 25 | ui(new Ui::NewClassDialog) |
| 26 | { |
| 27 | setWindowFlag(Qt::WindowContextHelpButtonHint,false); |
| 28 | ui->setupUi(this); |
| 29 | resize(pSettings->ui().newClassDialogWidth(),pSettings->ui().newClassDialogHeight()); |
| 30 | onUpdateIcons(); |
| 31 | connect(pIconsManager,&IconsManager::actionIconsUpdated, |
| 32 | this, &NewClassDialog::onUpdateIcons); |
| 33 | ui->txtClassName->setFocus(); |
| 34 | } |
| 35 | |
| 36 | NewClassDialog::~NewClassDialog() |
| 37 | { |
| 38 | } |
| 39 | |
| 40 | QString NewClassDialog::className() const |
| 41 | { |
| 42 | return ui->txtClassName->text(); |
| 43 | } |
| 44 | |
| 45 | QString NewClassDialog::baseClass() const |
| 46 | { |
| 47 | return ui->cbBaseClass->currentText(); |
| 48 | } |
| 49 | |
| 50 | QString NewClassDialog::() const |
| 51 | { |
| 52 | return ui->txtHeaderName->text(); |
| 53 | } |
| 54 | |
| 55 | QString NewClassDialog::sourceName() const |
| 56 | { |
| 57 | return ui->txtSourceName->text(); |
| 58 | } |
| 59 | |
| 60 | QString NewClassDialog::path() const |
| 61 | { |
| 62 | return ui->txtPath->text(); |
| 63 | } |
| 64 | |
| 65 | void NewClassDialog::setPath(const QString &location) |
| 66 | { |
| 67 | ui->txtPath->setText(location); |
| 68 | } |
| 69 | |
| 70 | void NewClassDialog::on_btnCancel_clicked() |
| 71 | { |
| 72 | this->reject(); |
| 73 | } |
| 74 | |
| 75 | void NewClassDialog::closeEvent(QCloseEvent */*event*/) |
| 76 | { |
| 77 | this->reject(); |
| 78 | } |
| 79 | |
| 80 | |
| 81 | void NewClassDialog::on_btnCreate_clicked() |
| 82 | { |
| 83 | this->accept(); |
| 84 | } |
| 85 | |
| 86 | void NewClassDialog::onUpdateIcons() |
| 87 | { |
| 88 | pIconsManager->setIcon(ui->btnBrowsePath, IconsManager::ACTION_FILE_OPEN_FOLDER); |
| 89 | } |
| 90 | |
| 91 | |
| 92 | void NewClassDialog::on_btnBrowsePath_clicked() |
| 93 | { |
| 94 | QString fileName = QFileDialog::getExistingDirectory( |
| 95 | this, |
| 96 | tr("Path" ), |
| 97 | ui->txtPath->text()); |
| 98 | ui->txtPath->setText(fileName); |
| 99 | } |
| 100 | |
| 101 | |
| 102 | void NewClassDialog::on_txtClassName_textChanged(const QString &/* arg1 */) |
| 103 | { |
| 104 | ui->txtHeaderName->setText(ui->txtClassName->text().toLower()+".h" ); |
| 105 | ui->txtSourceName->setText(ui->txtClassName->text().toLower()+".cpp" ); |
| 106 | } |
| 107 | |
| 108 | |