2021-12-26 23:18:28 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2020-2022 Roy Qu (royqh1979@gmail.com)
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2021-09-14 14:05:43 +08:00
|
|
|
#include "projectgeneralwidget.h"
|
|
|
|
#include "ui_projectgeneralwidget.h"
|
|
|
|
#include "../project.h"
|
|
|
|
#include "../mainwindow.h"
|
2021-09-14 23:56:08 +08:00
|
|
|
#include "settings.h"
|
|
|
|
#include "../systemconsts.h"
|
2021-12-23 09:11:58 +08:00
|
|
|
#include "../iconsmanager.h"
|
2021-09-14 14:05:43 +08:00
|
|
|
|
2021-09-14 23:56:08 +08:00
|
|
|
#include <QFileDialog>
|
2021-09-14 14:05:43 +08:00
|
|
|
#include <QIcon>
|
2022-03-17 17:07:28 +08:00
|
|
|
#include <QImageWriter>
|
|
|
|
#include <QImageWriter>
|
2021-09-15 12:19:09 +08:00
|
|
|
#include <QMessageBox>
|
2021-09-14 14:05:43 +08:00
|
|
|
#include <QTextCodec>
|
|
|
|
|
|
|
|
ProjectGeneralWidget::ProjectGeneralWidget(const QString &name, const QString &group, QWidget *parent) :
|
|
|
|
SettingsWidget(name,group,parent),
|
|
|
|
ui(new Ui::ProjectGeneralWidget)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
ProjectGeneralWidget::~ProjectGeneralWidget()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
2021-09-15 07:53:35 +08:00
|
|
|
void ProjectGeneralWidget::refreshIcon()
|
|
|
|
{
|
|
|
|
QPixmap icon(mIconPath);
|
2022-01-13 16:47:48 +08:00
|
|
|
ui->lbIcon->setPixmap(icon);
|
2021-09-15 07:53:35 +08:00
|
|
|
}
|
|
|
|
|
2021-09-14 14:05:43 +08:00
|
|
|
void ProjectGeneralWidget::doLoad()
|
|
|
|
{
|
|
|
|
std::shared_ptr<Project> project = pMainWindow->project();
|
|
|
|
if (!project)
|
|
|
|
return;
|
|
|
|
ui->txtName->setText(project->name());
|
|
|
|
ui->txtFileName->setText(project->filename());
|
|
|
|
ui->txtOutputFile->setText(project->executable());
|
|
|
|
|
|
|
|
int srcCount=0,headerCount=0,resCount=0,otherCount=0, totalCount=0;
|
|
|
|
foreach (const PProjectUnit& unit, project->units()) {
|
|
|
|
switch(getFileType(unit->fileName())) {
|
|
|
|
case FileType::CSource:
|
|
|
|
case FileType::CppSource:
|
|
|
|
srcCount++;
|
|
|
|
break;
|
|
|
|
case FileType::CppHeader:
|
|
|
|
case FileType::CHeader:
|
|
|
|
headerCount++;
|
|
|
|
break;
|
|
|
|
case FileType::WindowsResourceSource:
|
|
|
|
resCount++;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
otherCount++;
|
|
|
|
}
|
|
|
|
totalCount++;
|
|
|
|
}
|
|
|
|
ui->lblFiles->setText(tr("%1 files [ %2 sources, %3 headers, %4 resources, %5 other files ]")
|
|
|
|
.arg(totalCount).arg(srcCount).arg(headerCount)
|
|
|
|
.arg(resCount).arg(otherCount));
|
|
|
|
|
|
|
|
ui->cbDefaultEncoding->setCurrentText(project->options().encoding);
|
|
|
|
|
|
|
|
ui->lstType->setCurrentRow( static_cast<int>(project->options().type));
|
|
|
|
|
2022-02-01 16:17:28 +08:00
|
|
|
ui->cbDefaultCpp->setChecked(project->options().isCpp);
|
2021-09-14 14:05:43 +08:00
|
|
|
ui->cbSupportXPTheme->setChecked(project->options().supportXPThemes);
|
|
|
|
mIconPath = project->options().icon;
|
2021-09-15 07:53:35 +08:00
|
|
|
QPixmap icon(mIconPath);
|
|
|
|
refreshIcon();
|
2021-09-14 14:05:43 +08:00
|
|
|
}
|
2021-09-14 17:33:47 +08:00
|
|
|
|
|
|
|
void ProjectGeneralWidget::doSave()
|
|
|
|
{
|
|
|
|
std::shared_ptr<Project> project = pMainWindow->project();
|
|
|
|
if (!project)
|
|
|
|
return;
|
|
|
|
project->setName(ui->txtName->text().trimmed());
|
|
|
|
|
|
|
|
project->options().encoding = ui->cbDefaultEncoding->currentText();
|
|
|
|
|
|
|
|
int row = std::max(0,ui->lstType->currentRow());
|
|
|
|
project->options().type = static_cast<ProjectType>(row);
|
|
|
|
|
2022-02-01 16:17:28 +08:00
|
|
|
project->options().isCpp = ui->cbDefaultCpp->isChecked();
|
2021-09-14 17:33:47 +08:00
|
|
|
project->options().supportXPThemes = ui->cbSupportXPTheme->isChecked();
|
2022-08-08 10:45:35 +08:00
|
|
|
qDebug()<<"iconpath"<<mIconPath;
|
2021-09-15 07:53:35 +08:00
|
|
|
if (mIconPath.isEmpty()
|
2022-07-24 11:19:11 +08:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5,15,0)
|
2022-08-08 10:45:35 +08:00
|
|
|
|| ui->lbIcon->pixmap(Qt::ReturnByValue).isNull()) {
|
2022-07-04 11:39:06 +08:00
|
|
|
#else
|
2022-01-13 16:47:48 +08:00
|
|
|
|| !ui->lbIcon->pixmap() || ui->lbIcon->pixmap()->isNull()) {
|
2022-07-04 11:39:06 +08:00
|
|
|
#endif
|
2021-09-15 07:53:35 +08:00
|
|
|
project->options().icon = "";
|
|
|
|
} else {
|
2022-04-25 21:48:04 +08:00
|
|
|
QString iconPath = QFileInfo(project->filename()).absoluteDir().absoluteFilePath("app.ico");
|
2022-01-13 16:47:48 +08:00
|
|
|
if (iconPath!=mIconPath) {
|
|
|
|
if (QFile(iconPath).exists()) {
|
|
|
|
if (!QFile::remove(iconPath)) {
|
|
|
|
QMessageBox::critical(this,
|
|
|
|
tr("Can't remove old icon file"),
|
|
|
|
tr("Can't remove old icon file '%1'")
|
|
|
|
.arg(iconPath),
|
|
|
|
QMessageBox::Ok);
|
|
|
|
}
|
2021-09-15 12:19:09 +08:00
|
|
|
}
|
2022-03-18 19:14:19 +08:00
|
|
|
if (!mIconPath.endsWith(".ico",PATH_SENSITIVITY) && QImageWriter::supportedImageFormats().contains("ico")) {
|
2022-07-24 11:19:11 +08:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5,15,0)
|
2022-07-04 11:39:06 +08:00
|
|
|
ui->lbIcon->pixmap(Qt::ReturnByValue).save(iconPath,"ico");
|
|
|
|
#else
|
2022-03-17 17:07:28 +08:00
|
|
|
ui->lbIcon->pixmap()->save(iconPath,"ico");
|
2022-07-04 11:39:06 +08:00
|
|
|
#endif
|
2022-03-17 17:07:28 +08:00
|
|
|
} else
|
2022-08-08 10:45:35 +08:00
|
|
|
copyFile(mIconPath, iconPath,true);
|
2022-01-13 16:47:48 +08:00
|
|
|
project->options().icon = iconPath;
|
|
|
|
mIconPath = iconPath;
|
|
|
|
refreshIcon();
|
2021-09-15 12:19:09 +08:00
|
|
|
}
|
2021-09-15 07:53:35 +08:00
|
|
|
}
|
|
|
|
|
2021-09-14 17:33:47 +08:00
|
|
|
project->saveOptions();
|
|
|
|
}
|
2021-09-14 23:56:08 +08:00
|
|
|
|
|
|
|
void ProjectGeneralWidget::on_btnBrowse_clicked()
|
|
|
|
{
|
|
|
|
QString fileName = QFileDialog::getOpenFileName(this,
|
|
|
|
tr("Select icon file"),
|
2021-12-26 15:08:54 +08:00
|
|
|
pSettings->dirs().appDir(),
|
2022-01-13 16:47:48 +08:00
|
|
|
tr("Image Files (*.ico *.png *.jpg)"));
|
2021-09-14 23:56:08 +08:00
|
|
|
if (!fileName.isEmpty()) {
|
|
|
|
mIconPath = fileName;
|
2021-09-15 07:53:35 +08:00
|
|
|
refreshIcon();
|
2021-09-15 12:19:09 +08:00
|
|
|
setSettingsChanged();
|
2021-09-14 23:56:08 +08:00
|
|
|
}
|
|
|
|
ui->btnRemove->setEnabled(!mIconPath.isEmpty());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ProjectGeneralWidget::on_btnRemove_clicked()
|
|
|
|
{
|
|
|
|
mIconPath = "";
|
2022-01-13 16:47:48 +08:00
|
|
|
ui->lbIcon->setPixmap(QPixmap());
|
2021-09-14 23:56:08 +08:00
|
|
|
ui->btnRemove->setEnabled(!mIconPath.isEmpty());
|
2021-09-15 12:19:09 +08:00
|
|
|
setSettingsChanged();
|
2021-09-14 23:56:08 +08:00
|
|
|
}
|
|
|
|
|
2021-09-15 11:23:42 +08:00
|
|
|
void ProjectGeneralWidget::init()
|
|
|
|
{
|
|
|
|
ui->cbDefaultEncoding->clear();
|
|
|
|
ui->cbDefaultEncoding->addItems(pSystemConsts->codecNames());
|
2021-09-15 12:19:09 +08:00
|
|
|
SettingsWidget::init();
|
2021-09-15 11:23:42 +08:00
|
|
|
}
|
|
|
|
|
2021-12-23 09:11:58 +08:00
|
|
|
void ProjectGeneralWidget::updateIcons(const QSize &)
|
|
|
|
{
|
|
|
|
pIconsManager->setIcon(ui->btnBrowse,IconsManager::ACTION_FILE_OPEN_FOLDER);
|
|
|
|
pIconsManager->setIcon(ui->btnRemove, IconsManager::ACTION_MISC_CROSS);
|
|
|
|
}
|
|
|
|
|