diff --git a/RedPandaIDE/settingsdialog/compilersetdirectorieswidget.cpp b/RedPandaIDE/settingsdialog/compilersetdirectorieswidget.cpp new file mode 100644 index 00000000..f72386da --- /dev/null +++ b/RedPandaIDE/settingsdialog/compilersetdirectorieswidget.cpp @@ -0,0 +1,36 @@ +#include "compilersetdirectorieswidget.h" +#include "ui_compilersetdirectorieswidget.h" + +#include + +CompilerSetDirectoriesWidget::CompilerSetDirectoriesWidget(QWidget *parent) : + QWidget(parent), + ui(new Ui::CompilerSetDirectoriesWidget) +{ + ui->setupUi(this); + + mModel = new CompilerSetDirectoriesWidget::ListModel(); + ui->listView->setModel(mModel); +} + +CompilerSetDirectoriesWidget::~CompilerSetDirectoriesWidget() +{ + delete ui; +} + +void CompilerSetDirectoriesWidget::setDirList(const QStringList &list) +{ + mModel->setStringList(list); +} + +QStringList CompilerSetDirectoriesWidget::dirList() const +{ + return mModel->stringList(); +} + +Qt::ItemFlags CompilerSetDirectoriesWidget::ListModel::flags(const QModelIndex &index) const +{ + if (index.isValid()) { + return Qt::ItemIsEnabled | Qt::ItemIsDragEnabled | Qt::ItemIsEditable | Qt::ItemIsSelectable; + } +} diff --git a/RedPandaIDE/settingsdialog/compilersetdirectorieswidget.h b/RedPandaIDE/settingsdialog/compilersetdirectorieswidget.h new file mode 100644 index 00000000..4491bcb7 --- /dev/null +++ b/RedPandaIDE/settingsdialog/compilersetdirectorieswidget.h @@ -0,0 +1,32 @@ +#ifndef COMPILERSETDIRECTORIESWIDGET_H +#define COMPILERSETDIRECTORIESWIDGET_H + +#include +#include + +namespace Ui { +class CompilerSetDirectoriesWidget; +} + + +class CompilerSetDirectoriesWidget : public QWidget +{ + Q_OBJECT + class ListModel: public QStringListModel { + public: + Qt::ItemFlags flags(const QModelIndex &index) const; + }; + +public: + explicit CompilerSetDirectoriesWidget(QWidget *parent = nullptr); + ~CompilerSetDirectoriesWidget(); + + void setDirList(const QStringList& list); + QStringList dirList() const; + +private: + Ui::CompilerSetDirectoriesWidget *ui; + ListModel* mModel; +}; + +#endif // COMPILERSETDIRECTORIESWIDGET_H diff --git a/RedPandaIDE/settingsdialog/compilersetdirectorieswidget.ui b/RedPandaIDE/settingsdialog/compilersetdirectorieswidget.ui new file mode 100644 index 00000000..c2603fa3 --- /dev/null +++ b/RedPandaIDE/settingsdialog/compilersetdirectorieswidget.ui @@ -0,0 +1,119 @@ + + + CompilerSetDirectoriesWidget + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + + QFrame::NoFrame + + + QFrame::Plain + + + + + + Add + + + Add + + + + :/icons/images/newlook24/002-add.png + + + + true + + + + + + + Delete + + + Delete + + + + :/icons/images/newlook24/008-close.png + + + + true + + + + + + + Remove Invalid + + + Remove Invalid + + + + :/icons/images/newlook24/007-bughlp.png + + + + Qt::ToolButtonIconOnly + + + true + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + true + + + true + + + QAbstractItemView::InternalMove + + + Qt::MoveAction + + + + + + + + diff --git a/RedPandaIDE/settingsdialog/compilersetoptionwidget.cpp b/RedPandaIDE/settingsdialog/compilersetoptionwidget.cpp new file mode 100644 index 00000000..df00604f --- /dev/null +++ b/RedPandaIDE/settingsdialog/compilersetoptionwidget.cpp @@ -0,0 +1,187 @@ +#include "compilersetoptionwidget.h" +#include "ui_compilersetoptionwidget.h" +#include "../settings.h" +#include "../mainwindow.h" +#include "compilersetdirectorieswidget.h" +#include +#include "../utils.h" +#include +#include +#include + +CompilerSetOptionWidget::CompilerSetOptionWidget(const QString& name, const QString& group, QWidget* parent) : + SettingsWidget(name,group,parent), + ui(new Ui::CompilerSetOptionWidget) +{ + ui->setupUi(this); + + mBinDirWidget = new CompilerSetDirectoriesWidget(); + ui->dirTabs->addTab(mBinDirWidget,QObject::tr("Binaries")); + mLibDirWidget = new CompilerSetDirectoriesWidget(); + ui->dirTabs->addTab(mLibDirWidget,QObject::tr("Libraries")); + mCIncludeDirWidget = new CompilerSetDirectoriesWidget(); + ui->dirTabs->addTab(mCIncludeDirWidget,QObject::tr("C Includes")); + mCppIncludeDirWidget = new CompilerSetDirectoriesWidget(); + ui->dirTabs->addTab(mCppIncludeDirWidget,QObject::tr("C++ Includes")); + + connect(ui->chkUseCustomCompilerParams, &QCheckBox::stateChanged, + ui->txtCustomCompileParams, &QPlainTextEdit::setEnabled); + connect(ui->chkUseCustomLinkParams, &QCheckBox::stateChanged, + ui->txtCustomLinkParams, &QPlainTextEdit::setEnabled); +} + +CompilerSetOptionWidget::~CompilerSetOptionWidget() +{ + delete ui; +} + +void resetOptionTabs(Settings::PCompilerSet pSet,QTabWidget* pTab) +{ + while (pTab->count()>0) { + QWidget* p=pTab->widget(0); + if (p!=nullptr) { + pTab->removeTab(0); + p->setParent(nullptr); + delete p; + } + } + + for (PCompilerOption pOption: pSet->options()) { + QWidget* pWidget = nullptr; + for (int i=0;icount();i++) { + if (pOption->section == pTab->tabText(i)) { + pWidget = pTab->widget(i); + break; + } + } + if (pWidget == nullptr) { + pWidget = new QWidget(); + pTab->addTab(pWidget,pOption->section); + pWidget->setLayout(new QGridLayout()); + } + QGridLayout *pLayout = (QGridLayout*)pWidget->layout(); + int row = pLayout->rowCount(); + pLayout->addWidget(new QLabel(pOption->name),row,0); + QComboBox* pCombo = new QComboBox(); + if (pOption->choices.count()>0) { + for (int i=0;ichoices.count();i++) { + QString choice = pOption->choices[i]; + QStringList valueName=choice.split("="); + if (valueName.length()<2) { + pCombo->addItem(""); + } else { + pCombo->addItem(valueName[0]); + } + } + } else { + pCombo->addItem(QObject::tr("No")); + pCombo->addItem(QObject::tr("Yes")); + } + pCombo->setCurrentIndex(pOption->value); + pLayout->addWidget(pCombo,row,1); + } + for (int i=0;icount();i++) { + QWidget* pWidget = pTab->widget(i); + QGridLayout *pLayout = (QGridLayout*)pWidget->layout(); + int row = pLayout->rowCount(); + QSpacerItem* horizontalSpacer = new QSpacerItem(10, 100, QSizePolicy::Minimum, QSizePolicy::Expanding); + pLayout->addItem(horizontalSpacer,row,0); + } +} + +static void loadCompilerSetSettings(Settings::PCompilerSet pSet, Ui::CompilerSetOptionWidget* ui) { + ui->chkUseCustomCompilerParams->setChecked(pSet->useCustomCompileParams()); + ui->txtCustomCompileParams->setPlainText(pSet->customCompileParams()); + ui->txtCustomCompileParams->setEnabled(pSet->useCustomCompileParams()); + ui->chkUseCustomLinkParams->setChecked(pSet->useCustomLinkParams()); + ui->txtCustomLinkParams->setPlainText(pSet->customLinkParams()); + ui->txtCustomLinkParams->setEnabled(pSet->useCustomLinkParams()); + ui->chkStaticLink->setChecked(pSet->staticLink()); + ui->chkAutoAddCharset->setChecked(pSet->autoAddCharsetParams()); + + //rest tabs in the options widget + resetOptionTabs(pSet,ui->optionTabs); + + ui->txtCCompiler->setText(pSet->CCompiler()); + ui->txtCppCompiler->setText(pSet->cppCompiler()); + ui->txtMake->setText(pSet->make()); + ui->txtDebugger->setText(pSet->debugger()); + ui->txtResourceCompiler->setText(pSet->resourceCompiler()); + ui->txtProfiler->setText(pSet->profiler()); +} + +void CompilerSetOptionWidget::doLoad() +{ + ui->cbCompilerSet->clear(); + int index=pSettings->compilerSets().defaultIndex(); + for (int i=0;icompilerSets().list().size();i++) { + ui->cbCompilerSet->addItem(pSettings->compilerSets().list()[i]->name()); + } + ui->cbCompilerSet->setCurrentIndex(index); + + //reloadCurrentCompilerSet(); +} + +void CompilerSetOptionWidget::doSave() +{ + pSettings->compilerSets().saveSets(); +} + +void CompilerSetOptionWidget::on_cbCompilerSet_currentIndexChanged(int index) +{ + if (index<0) + return; + pSettings->compilerSets().setDefaultIndex(index); + reloadCurrentCompilerSet(); +} + +void CompilerSetOptionWidget::reloadCurrentCompilerSet() +{ + Settings::PCompilerSet pSet = pSettings->compilerSets().defaultSet(); + loadCompilerSetSettings(pSet, ui); + + mBinDirWidget->setDirList(pSet->binDirs()); + mLibDirWidget->setDirList(pSet->libDirs()); + mCIncludeDirWidget->setDirList(pSet->CIncludeDirs()); + mCppIncludeDirWidget->setDirList(pSet->CppIncludeDirs()); + + connectInputs(); +} + +void CompilerSetOptionWidget::on_btnFindCompilers_pressed() +{ + if (QMessageBox::warning(this,tr("Confirm"), + tr("Red Panda C++ will clear current compiler list and search" + " for compilers in the following locations:\n '%1'\n'%2'\nAre you really want to continue?") + .arg(includeTrailingPathDelimiter(pSettings->dirs().app()) + "MinGW32") + .arg(includeTrailingPathDelimiter(pSettings->dirs().app()) + "MinGW64"), + QMessageBox::Ok | QMessageBox::Cancel) != QMessageBox::Ok ) + return; + pSettings->compilerSets().clearSets(); + pSettings->compilerSets().findSets(); + doLoad(); +} + +void CompilerSetOptionWidget::on_btnAddBlankCompilerSet_pressed() +{ + QString name = QInputDialog::getText(this,tr("Compiler Set Name"),tr("Name")); + pSettings->compilerSets().addSet(); + pSettings->compilerSets().setDefaultIndex(pSettings->compilerSets().list().size()-1); + pSettings->compilerSets().defaultSet()->setName(name); + doLoad(); +} + +void CompilerSetOptionWidget::on_btnAddCompilerSetByFolder_pressed() +{ + QString folder = QFileDialog::getExistingDirectory(this, tr("Compiler Set Folder")); + pSettings->compilerSets().addSets(folder); + doLoad(); +} + +void CompilerSetOptionWidget::on_btnRenameCompilerSet_pressed() +{ + QString name = QInputDialog::getText(this,tr("Compiler Set Name"),tr("New name")); + if (!name.isEmpty()) + pSettings->compilerSets().defaultSet()->setName(name); + doLoad(); +} diff --git a/RedPandaIDE/settingsdialog/compilersetoptionwidget.h b/RedPandaIDE/settingsdialog/compilersetoptionwidget.h new file mode 100644 index 00000000..5f961150 --- /dev/null +++ b/RedPandaIDE/settingsdialog/compilersetoptionwidget.h @@ -0,0 +1,43 @@ +#ifndef COMPILERSETOPTIONWIDGET_H +#define COMPILERSETOPTIONWIDGET_H + +#include +#include "settingswidget.h" + +namespace Ui { +class CompilerSetOptionWidget; +} + +class CompilerSetDirectoriesWidget; +class CompilerSetOptionWidget : public SettingsWidget +{ + Q_OBJECT + +public: + explicit CompilerSetOptionWidget(const QString& name, const QString& group, QWidget *parent = nullptr); + ~CompilerSetOptionWidget(); + +private: + Ui::CompilerSetOptionWidget *ui; + CompilerSetDirectoriesWidget* mBinDirWidget; + CompilerSetDirectoriesWidget* mCIncludeDirWidget; + CompilerSetDirectoriesWidget* mCppIncludeDirWidget; + CompilerSetDirectoriesWidget* mLibDirWidget; + + + // SettingsWidget interface +protected: + void doLoad() override; + void doSave() override; +private: + void reloadCurrentCompilerSet(); + +private slots: + void on_cbCompilerSet_currentIndexChanged(int index); + void on_btnFindCompilers_pressed(); + void on_btnAddBlankCompilerSet_pressed(); + void on_btnAddCompilerSetByFolder_pressed(); + void on_btnRenameCompilerSet_pressed(); +}; + +#endif // COMPILERSETOPTIONWIDGET_H diff --git a/RedPandaIDE/settingsdialog/compilersetoptionwidget.ui b/RedPandaIDE/settingsdialog/compilersetoptionwidget.ui new file mode 100644 index 00000000..a8946716 --- /dev/null +++ b/RedPandaIDE/settingsdialog/compilersetoptionwidget.ui @@ -0,0 +1,400 @@ + + + CompilerSetOptionWidget + + + + 0 + 0 + 823 + 607 + + + + Form + + + + + + Compiler set to config + + + false + + + false + + + + + + + + + ... + + + + :/icons/images/newlook24/087-update.png + + + + + + + + ... + + + + :/icons/images/newlook24/050-newsrc.png + + + + + + + + ... + + + + :/icons/images/newlook24/053-open.png + + + + + + + + ... + + + + :/icons/images/newlook24/062-redo.png + + + + + + + + ... + + + + :/icons/images/newlook24/008-close.png + + + + + + + + + + + 0 + + + false + + + + General + + + + + + Add the following arguments when calling the compiler + + + + + + + + + + Add the following arguments when calling the linker + + + + + + + + + + Statically Link + + + + + + + Add Charset arguments when calling the compiler + + + + + + + + Settings + + + + 2 + + + 2 + + + 2 + + + 2 + + + + + true + + + + + + + + Directories + + + + 2 + + + 2 + + + 2 + + + 2 + + + + + -1 + + + true + + + + + + + + Programs + + + + + + + 0 + 0 + + + + TextLabel + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + Resource Compiler(windres) + + + + + + + + + + C++ Compiler(g++) + + + + + + + Choose C++ Compiler + + + ... + + + + :/icons/images/newlook24/053-open.png + + + + + + + + Choose C Compiler + + + ... + + + + :/icons/images/newlook24/053-open.png + + + + + + + + + + + C Compiler(gcc) + + + + + + + Debugger(gdb) + + + + + + + Profiler(gprof) + + + + + + + make + + + + + + + + + + + + + + + + + + + Choose make + + + ... + + + + :/icons/images/newlook24/053-open.png + + + + + + + + Choose Debugger + + + ... + + + + :/icons/images/newlook24/053-open.png + + + + + + + + Choose Resource Compiler + + + ... + + + + :/icons/images/newlook24/053-open.png + + + + + + + + Choose Profiler + + + ... + + + + :/icons/images/newlook24/053-open.png + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + + diff --git a/RedPandaIDE/settingsdialog/settingsdialog.cpp b/RedPandaIDE/settingsdialog/settingsdialog.cpp new file mode 100644 index 00000000..ea4804eb --- /dev/null +++ b/RedPandaIDE/settingsdialog/settingsdialog.cpp @@ -0,0 +1,75 @@ +#include "settingsdialog.h" +#include "ui_settingsdialog.h" +#include "settingswidget.h" +#include "compilersetoptionwidget.h" +#include + +SettingsDialog::SettingsDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::SettingsDialog) +{ + ui->setupUi(this); + + ui->widgetsView->setModel(&model); + + model.setHorizontalHeaderLabels(QStringList()); + + ui->btnApply->setEnabled(false); + + pCompilerSetOptionWidget = new CompilerSetOptionWidget(tr("Compiler Set"),tr("Compiler")); + pCompilerSetOptionWidget->init(); + + addWidget(pCompilerSetOptionWidget); +} + +SettingsDialog::~SettingsDialog() +{ + for (SettingsWidget* p:mSettingWidgets) { + p->setParent(nullptr); + delete p; + } + delete ui; +} + +void SettingsDialog::addWidget(SettingsWidget *pWidget) +{ + QList items = model.findItems(pWidget->group()); + QStandardItem* pGroupItem; + if (items.count() == 0 ) { + pGroupItem = new QStandardItem(pWidget->group()); + pGroupItem->setData(-1, GetWidgetIndexRole); + model.appendRow(pGroupItem); + } else { + pGroupItem = items[0]; + } + mSettingWidgets.append(pWidget); + QStandardItem* pWidgetItem = new QStandardItem(pWidget->name()); + pWidgetItem->setData(mSettingWidgets.count()-1, GetWidgetIndexRole); + pGroupItem->appendRow(pWidgetItem); + connect(pWidget, &SettingsWidget::settingsChanged, + this , &SettingsDialog::widget_settings_changed); +} + + +void SettingsDialog::on_widgetsView_clicked(const QModelIndex &index) +{ + if (!index.isValid()) + return; + int i = index.data(GetWidgetIndexRole).toInt(); + if (i>=0) { + if (ui->scrollArea->widget()!=ui->scrollAreaWidgetContents) { + //todo save change + + } + SettingsWidget* pWidget = mSettingWidgets[i]; + ui->scrollArea->setWidget(pWidget); + ui->lblWidgetCaption->setText(QString("%1 > %2").arg(pWidget->group()).arg(pWidget->name())); + + ui->btnApply->setEnabled(false); + } +} + +void SettingsDialog::widget_settings_changed(bool value) +{ + ui->btnApply->setEnabled(value); +} diff --git a/RedPandaIDE/settingsdialog/settingsdialog.h b/RedPandaIDE/settingsdialog/settingsdialog.h new file mode 100644 index 00000000..715fe084 --- /dev/null +++ b/RedPandaIDE/settingsdialog/settingsdialog.h @@ -0,0 +1,40 @@ +#ifndef SETTINGSDIALOG_H +#define SETTINGSDIALOG_H + +#include +#include +#include + +class SettingsWidget; +namespace Ui { +class SettingsDialog; +} + +class CompilerSetOptionWidget; +class PCompilerSet; +class SettingsWidget; +class SettingsDialog : public QDialog +{ + Q_OBJECT + +public: + enum { + GetWidgetIndexRole = Qt::UserRole + 1 + }; + explicit SettingsDialog(QWidget *parent = nullptr); + ~SettingsDialog(); + + void addWidget(SettingsWidget* pWidget); +private slots: + void widget_settings_changed(bool value); + void on_widgetsView_clicked(const QModelIndex &index); + +private: + Ui::SettingsDialog *ui; + QList mSettingWidgets; + QStandardItemModel model; + + CompilerSetOptionWidget* pCompilerSetOptionWidget; +}; + +#endif // SETTINGSDIALOG_H diff --git a/RedPandaIDE/settingsdialog/settingsdialog.ui b/RedPandaIDE/settingsdialog/settingsdialog.ui new file mode 100644 index 00000000..09fbe619 --- /dev/null +++ b/RedPandaIDE/settingsdialog/settingsdialog.ui @@ -0,0 +1,185 @@ + + + SettingsDialog + + + + 0 + 0 + 977 + 622 + + + + Options + + + + 2 + + + 2 + + + 2 + + + 2 + + + + + Qt::Horizontal + + + 10 + + + + + 0 + 0 + + + + QFrame::NoFrame + + + QFrame::Plain + + + + 0 + + + + + QAbstractItemView::NoEditTriggers + + + false + + + + + + + + + 1 + 0 + + + + QFrame::NoFrame + + + QFrame::Raised + + + + 0 + + + + + + 0 + 0 + + + + TextLabel + + + + + + + true + + + + + 0 + 0 + 683 + 535 + + + + + + + + + + 0 + 0 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 2 + + + 2 + + + 2 + + + 2 + + + + + Qt::Horizontal + + + + 192 + 20 + + + + + + + + OK + + + + + + + Apply + + + + + + + Cancle + + + + + + + + + + + + + + +