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 "projectmakefilewidget.h"
18#include "ui_projectmakefilewidget.h"
19#include "compilersetdirectorieswidget.h"
20#include "../mainwindow.h"
21#include "../project.h"
22#include "../widgets/custommakefileinfodialog.h"
23#include "../iconsmanager.h"
24#include "../systemconsts.h"
25
26#include <QFileDialog>
27
28ProjectMakefileWidget::ProjectMakefileWidget(const QString &name, const QString &group, QWidget *parent) :
29 SettingsWidget(name,group,parent),
30 ui(new Ui::ProjectMakefileWidget)
31{
32 ui->setupUi(this);
33
34 mIncludesDirWidget = new CompilerSetDirectoriesWidget(this);
35 ui->verticalLayout->addWidget(mIncludesDirWidget);
36}
37
38ProjectMakefileWidget::~ProjectMakefileWidget()
39{
40 delete ui;
41}
42
43void ProjectMakefileWidget::doLoad()
44{
45 ui->grpCustomMakefile->setChecked(pMainWindow->project()->options().useCustomMakefile);
46 ui->txtCustomMakefile->setText(pMainWindow->project()->options().customMakefile);
47 mIncludesDirWidget->setDirList(pMainWindow->project()->options().makeIncludes);
48}
49
50void ProjectMakefileWidget::doSave()
51{
52 pMainWindow->project()->options().useCustomMakefile = ui->grpCustomMakefile->isChecked();
53 pMainWindow->project()->options().customMakefile = ui->txtCustomMakefile->text();
54 pMainWindow->project()->options().makeIncludes = mIncludesDirWidget->dirList();
55 pMainWindow->project()->saveOptions();
56
57}
58
59void ProjectMakefileWidget::on_btnBrowse_clicked()
60{
61 QString fileName = QFileDialog::getOpenFileName(
62 this,
63 tr("Custom makefile"),
64 pMainWindow->project()->directory(),
65 tr("All files (%1)").arg(ALL_FILE_WILDCARD));
66 if (!fileName.isEmpty() && QFileInfo(fileName).exists()) {
67 ui->txtCustomMakefile->setText(fileName);
68 }
69}
70
71
72void ProjectMakefileWidget::updateIcons(const QSize &)
73{
74 pIconsManager->setIcon(ui->btnBrowse, IconsManager::ACTION_FILE_OPEN_FOLDER);
75 pIconsManager->setIcon(ui->btnInfo, IconsManager::ACTION_MISC_HELP);
76}
77
78
79void ProjectMakefileWidget::on_btnInfo_clicked()
80{
81 CustomMakefileInfoDialog dialog(this);
82 dialog.exec();
83}
84
85