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 "projectoutputwidget.h" |
18 | #include "ui_projectoutputwidget.h" |
19 | #include "../mainwindow.h" |
20 | #include "../project.h" |
21 | #include "../iconsmanager.h" |
22 | #include "../systemconsts.h" |
23 | |
24 | #include <QFileDialog> |
25 | |
26 | |
27 | ProjectOutputWidget::ProjectOutputWidget(const QString &name, const QString &group, QWidget *parent) : |
28 | SettingsWidget(name,group,parent), |
29 | ui(new Ui::ProjectOutputWidget) |
30 | { |
31 | ui->setupUi(this); |
32 | } |
33 | |
34 | ProjectOutputWidget::~ProjectOutputWidget() |
35 | { |
36 | delete ui; |
37 | } |
38 | |
39 | void ProjectOutputWidget::doLoad() |
40 | { |
41 | ui->txtOutputDir->setText(pMainWindow->project()->options().exeOutput); |
42 | ui->txtObjOutputDir->setText(pMainWindow->project()->options().objectOutput); |
43 | ui->grpAutosaveCompileLog->setChecked(pMainWindow->project()->options().logOutputEnabled); |
44 | ui->txtCompileLog->setText(pMainWindow->project()->options().logOutput); |
45 | ui->grpOverrideOutput->setChecked(pMainWindow->project()->options().overrideOutput); |
46 | ui->txtOutputFilename->setText(pMainWindow->project()->options().overridenOutput); |
47 | } |
48 | |
49 | void ProjectOutputWidget::doSave() |
50 | { |
51 | pMainWindow->project()->options().exeOutput = ui->txtOutputDir->text(); |
52 | pMainWindow->project()->options().objectOutput = ui->txtObjOutputDir->text(); |
53 | pMainWindow->project()->options().logOutputEnabled = ui->grpAutosaveCompileLog->isChecked(); |
54 | pMainWindow->project()->options().logOutput = ui->txtCompileLog->text(); |
55 | pMainWindow->project()->options().overrideOutput = ui->grpOverrideOutput->isChecked(); |
56 | pMainWindow->project()->options().overridenOutput = ui->txtOutputFilename->text(); |
57 | pMainWindow->project()->saveOptions(); |
58 | } |
59 | |
60 | void ProjectOutputWidget::on_btnOutputDir_clicked() |
61 | { |
62 | QString dirName = QFileDialog::getExistingDirectory( |
63 | this, |
64 | tr("Executable output directory" ), |
65 | pMainWindow->project()->directory()); |
66 | if (!dirName.isEmpty()) |
67 | ui->txtOutputDir->setText(extractRelativePath(pMainWindow->project()->folder(),dirName)); |
68 | } |
69 | |
70 | |
71 | void ProjectOutputWidget::on_btnObjOutputDir_clicked() |
72 | { |
73 | QString dirName = QFileDialog::getExistingDirectory( |
74 | this, |
75 | tr("Object files output directory" ), |
76 | pMainWindow->project()->directory()); |
77 | if (!dirName.isEmpty()) |
78 | ui->txtObjOutputDir->setText(extractRelativePath(pMainWindow->project()->folder(),dirName)); |
79 | } |
80 | |
81 | |
82 | void ProjectOutputWidget::on_btnCompileLog_clicked() |
83 | { |
84 | QString fileName = QFileDialog::getOpenFileName( |
85 | this, |
86 | tr("Log file" ), |
87 | pMainWindow->project()->directory(), |
88 | tr("All files (%1)" ).arg(ALL_FILE_WILDCARD)); |
89 | if (!fileName.isEmpty() ) { |
90 | ui->txtCompileLog->setText(extractRelativePath(pMainWindow->project()->folder(),fileName)); |
91 | } |
92 | } |
93 | |
94 | void ProjectOutputWidget::updateIcons(const QSize &/*size*/) |
95 | { |
96 | pIconsManager->setIcon(ui->btnCompileLog, IconsManager::ACTION_FILE_OPEN_FOLDER); |
97 | pIconsManager->setIcon(ui->btnObjOutputDir, IconsManager::ACTION_FILE_OPEN_FOLDER); |
98 | pIconsManager->setIcon(ui->btnOutputDir, IconsManager::ACTION_FILE_OPEN_FOLDER); |
99 | } |
100 | |
101 | |