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 "projectcompileparamaterswidget.h"
18#include "ui_projectcompileparamaterswidget.h"
19#include "../mainwindow.h"
20#include "../project.h"
21#include "../iconsmanager.h"
22
23#include <QFileDialog>
24
25ProjectCompileParamatersWidget::ProjectCompileParamatersWidget(const QString &name, const QString &group, QWidget *parent) :
26 SettingsWidget(name,group,parent),
27 ui(new Ui::ProjectCompileParamatersWidget)
28{
29 ui->setupUi(this);
30}
31
32ProjectCompileParamatersWidget::~ProjectCompileParamatersWidget()
33{
34 delete ui;
35}
36
37void ProjectCompileParamatersWidget::doLoad()
38{
39 ui->txtCCompiler->setPlainText(pMainWindow->project()->options().compilerCmd);
40 ui->txtCPPCompiler->setPlainText(pMainWindow->project()->options().cppCompilerCmd);
41 ui->txtLinker->setPlainText(pMainWindow->project()->options().linkerCmd);
42}
43
44void ProjectCompileParamatersWidget::doSave()
45{
46 pMainWindow->project()->options().compilerCmd = ui->txtCCompiler->toPlainText();
47 pMainWindow->project()->options().cppCompilerCmd = ui->txtCPPCompiler->toPlainText();
48 pMainWindow->project()->options().linkerCmd = ui->txtLinker->toPlainText();
49 pMainWindow->project()->saveOptions();
50}
51
52void ProjectCompileParamatersWidget::on_btnChooseLib_clicked()
53{
54#ifdef Q_OS_WIN
55 QString filter = tr("Library Files")+" (*.a *.lib *.o)";
56#else
57 QString filter = tr("Library Files")+" (*.a *.o)";
58#endif
59
60 QStringList files = QFileDialog::getOpenFileNames(
61 this,
62 tr("Add Library Files"),
63 QDir::currentPath(),
64 filter
65 );
66 if (!files.isEmpty()) {
67 foreach (const QString& file,files) {
68 ui->txtLinker->appendPlainText(" "+genMakePath1(file));
69 }
70 }
71}
72
73void ProjectCompileParamatersWidget::updateIcons(const QSize &/*size*/)
74{
75 pIconsManager->setIcon(ui->btnChooseLib, IconsManager::ACTION_MISC_FOLDER);
76}
77
78