2021-04-17 23:17:22 +08:00
|
|
|
#include "settingsdialog.h"
|
|
|
|
#include "ui_settingsdialog.h"
|
|
|
|
#include "settingswidget.h"
|
|
|
|
#include "compilersetoptionwidget.h"
|
2021-06-07 11:02:03 +08:00
|
|
|
#include "editorgeneralwidget.h"
|
2021-06-08 21:41:42 +08:00
|
|
|
#include "editorfontwidget.h"
|
2021-06-12 22:36:23 +08:00
|
|
|
#include "editorclipboardwidget.h"
|
2021-06-17 10:39:46 +08:00
|
|
|
#include "editorcolorschemewidget.h"
|
2021-08-30 16:59:08 +08:00
|
|
|
#include "editorcodecompletionwidget.h"
|
2021-06-25 12:40:11 +08:00
|
|
|
#include "editorsyntaxcheckwidget.h"
|
2021-06-21 16:25:21 +08:00
|
|
|
#include "editorsymbolcompletionwidget.h"
|
2021-08-30 22:05:45 +08:00
|
|
|
#include "editorautosavewidget.h"
|
2021-08-30 18:36:44 +08:00
|
|
|
#include "editormiscwidget.h"
|
2021-06-18 21:48:40 +08:00
|
|
|
#include "environmentappearencewidget.h"
|
2021-07-01 19:44:38 +08:00
|
|
|
#include "executorgeneralwidget.h"
|
2021-08-01 23:24:37 +08:00
|
|
|
#include "debuggeneralwidget.h"
|
2021-04-17 23:17:22 +08:00
|
|
|
#include <QDebug>
|
2021-04-18 00:08:01 +08:00
|
|
|
#include <QMessageBox>
|
2021-06-18 21:48:40 +08:00
|
|
|
#include <QModelIndex>
|
2021-04-17 23:17:22 +08:00
|
|
|
|
|
|
|
SettingsDialog::SettingsDialog(QWidget *parent) :
|
|
|
|
QDialog(parent),
|
|
|
|
ui(new Ui::SettingsDialog)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
|
|
|
ui->widgetsView->setModel(&model);
|
|
|
|
|
|
|
|
model.setHorizontalHeaderLabels(QStringList());
|
|
|
|
|
|
|
|
ui->btnApply->setEnabled(false);
|
|
|
|
|
2021-06-18 21:48:40 +08:00
|
|
|
pEnvironmentAppearenceWidget = new EnvironmentAppearenceWidget(tr("Appearence"),tr("Environment"));
|
|
|
|
pEnvironmentAppearenceWidget->init();
|
|
|
|
addWidget(pEnvironmentAppearenceWidget);
|
|
|
|
|
2021-04-17 23:17:22 +08:00
|
|
|
pCompilerSetOptionWidget = new CompilerSetOptionWidget(tr("Compiler Set"),tr("Compiler"));
|
|
|
|
pCompilerSetOptionWidget->init();
|
|
|
|
addWidget(pCompilerSetOptionWidget);
|
2021-06-07 11:02:03 +08:00
|
|
|
|
|
|
|
pEditorGeneralWidget = new EditorGeneralWidget(tr("General"),tr("Editor"));
|
|
|
|
pEditorGeneralWidget->init();
|
|
|
|
addWidget(pEditorGeneralWidget);
|
2021-06-08 21:41:42 +08:00
|
|
|
|
|
|
|
pEditorFontWidget = new EditorFontWidget(tr("Font"),tr("Editor"));
|
|
|
|
pEditorFontWidget->init();
|
|
|
|
addWidget(pEditorFontWidget);
|
2021-06-12 22:36:23 +08:00
|
|
|
|
|
|
|
pEditorClipboardWidget = new EditorClipboardWidget(tr("Copy & Export"),tr("Editor"));
|
|
|
|
pEditorClipboardWidget->init();
|
|
|
|
addWidget(pEditorClipboardWidget);
|
2021-06-17 10:39:46 +08:00
|
|
|
|
|
|
|
pEditorColorSchemeWidget = new EditorColorSchemeWidget(tr("Color"),tr("Editor"));
|
|
|
|
pEditorColorSchemeWidget->init();
|
|
|
|
addWidget(pEditorColorSchemeWidget);
|
2021-06-18 21:48:40 +08:00
|
|
|
|
2021-08-30 16:59:08 +08:00
|
|
|
pEditorCodeCompletionWidget = new EditorCodeCompletionWidget(tr("Code Completion"),tr("Editor"));
|
|
|
|
pEditorCodeCompletionWidget->init();
|
|
|
|
addWidget(pEditorCodeCompletionWidget);
|
|
|
|
|
2021-06-21 16:25:21 +08:00
|
|
|
pEditorSymbolCompletionWidget = new EditorSymbolCompletionWidget(tr("Symbol Completion"),tr("Editor"));
|
|
|
|
pEditorSymbolCompletionWidget->init();
|
|
|
|
addWidget(pEditorSymbolCompletionWidget);
|
2021-06-18 21:48:40 +08:00
|
|
|
|
2021-06-25 12:40:11 +08:00
|
|
|
pEditorSyntaxCheckWidget = new EditorSyntaxCheckWidget(tr("Auto Syntax Checking"),tr("Editor"));
|
|
|
|
pEditorSyntaxCheckWidget->init();
|
|
|
|
addWidget(pEditorSyntaxCheckWidget);
|
|
|
|
|
2021-08-30 22:05:45 +08:00
|
|
|
pEditorAutoSaveWidget = new EditorAutoSaveWidget(tr("Auto save"),tr("Editor"));
|
|
|
|
pEditorAutoSaveWidget->init();
|
|
|
|
addWidget(pEditorAutoSaveWidget);
|
|
|
|
|
2021-08-30 18:36:44 +08:00
|
|
|
pEditorMiscWidget = new EditorMiscWidget(tr("Misc"),tr("Editor"));
|
|
|
|
pEditorMiscWidget->init();
|
|
|
|
addWidget(pEditorMiscWidget);
|
|
|
|
|
2021-06-25 12:40:11 +08:00
|
|
|
|
2021-07-01 19:44:38 +08:00
|
|
|
pExecutorGeneralWidget = new ExecutorGeneralWidget(tr("General"),tr("Program Runner"));
|
|
|
|
pExecutorGeneralWidget->init();
|
|
|
|
addWidget(pExecutorGeneralWidget);
|
|
|
|
|
2021-08-01 23:24:37 +08:00
|
|
|
pDebugGeneralWidget = new DebugGeneralWidget(tr("General"),tr("Debugger"));
|
|
|
|
pDebugGeneralWidget->init();
|
|
|
|
addWidget(pDebugGeneralWidget);
|
|
|
|
|
2021-06-18 21:48:40 +08:00
|
|
|
ui->widgetsView->expandAll();
|
|
|
|
//select the first widget of the first group
|
|
|
|
auto groupIndex = ui->widgetsView->model()->index(0,0);
|
|
|
|
auto widgetIndex = ui->widgetsView->model()->index(0,0, groupIndex);
|
|
|
|
ui->widgetsView->selectionModel()->setCurrentIndex(
|
|
|
|
widgetIndex,
|
|
|
|
QItemSelectionModel::Select
|
|
|
|
);
|
|
|
|
on_widgetsView_clicked(widgetIndex);
|
2021-04-17 23:17:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
SettingsDialog::~SettingsDialog()
|
|
|
|
{
|
|
|
|
for (SettingsWidget* p:mSettingWidgets) {
|
|
|
|
p->setParent(nullptr);
|
|
|
|
delete p;
|
|
|
|
}
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SettingsDialog::addWidget(SettingsWidget *pWidget)
|
|
|
|
{
|
|
|
|
QList<QStandardItem*> 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) {
|
2021-04-18 00:08:01 +08:00
|
|
|
saveCurrentPageSettings(true);
|
2021-04-17 23:17:22 +08:00
|
|
|
SettingsWidget* pWidget = mSettingWidgets[i];
|
2021-06-07 11:02:03 +08:00
|
|
|
if (ui->scrollArea->widget()!=nullptr) {
|
|
|
|
QWidget* w = ui->scrollArea->takeWidget();
|
|
|
|
w->setParent(nullptr);
|
|
|
|
}
|
2021-04-17 23:17:22 +08:00
|
|
|
ui->scrollArea->setWidget(pWidget);
|
|
|
|
ui->lblWidgetCaption->setText(QString("%1 > %2").arg(pWidget->group()).arg(pWidget->name()));
|
|
|
|
|
|
|
|
ui->btnApply->setEnabled(false);
|
2021-08-30 22:48:59 +08:00
|
|
|
} else if (model.hasChildren(index)) {
|
|
|
|
ui->widgetsView->expand(index);
|
|
|
|
QModelIndex childIndex = this->model.index(0,0,index);
|
|
|
|
emit ui->widgetsView->clicked(childIndex);
|
2021-04-17 23:17:22 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SettingsDialog::widget_settings_changed(bool value)
|
|
|
|
{
|
|
|
|
ui->btnApply->setEnabled(value);
|
|
|
|
}
|
2021-04-18 00:08:01 +08:00
|
|
|
|
|
|
|
void SettingsDialog::on_btnCancle_pressed()
|
|
|
|
{
|
|
|
|
this->close();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SettingsDialog::on_btnApply_pressed()
|
|
|
|
{
|
|
|
|
saveCurrentPageSettings(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SettingsDialog::on_btnOk_pressed()
|
|
|
|
{
|
|
|
|
saveCurrentPageSettings(false);
|
|
|
|
this->close();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SettingsDialog::saveCurrentPageSettings(bool confirm)
|
|
|
|
{
|
2021-04-18 11:25:40 +08:00
|
|
|
if (ui->scrollArea->widget()==ui->scrollAreaWidgetContents)
|
2021-04-18 00:08:01 +08:00
|
|
|
return;
|
|
|
|
SettingsWidget* pWidget = (SettingsWidget*) ui->scrollArea->widget();
|
|
|
|
if (!pWidget->isSettingsChanged())
|
|
|
|
return;
|
|
|
|
if (confirm) {
|
2021-06-21 11:21:26 +08:00
|
|
|
if (QMessageBox::warning(this,tr("Save Changes"),
|
2021-04-18 00:08:01 +08:00
|
|
|
tr("There are changes in the settings, do you want to save them before swtich to other page?"),
|
|
|
|
QMessageBox::Yes, QMessageBox::No)!=QMessageBox::Yes) {
|
2021-04-18 11:25:40 +08:00
|
|
|
return;
|
|
|
|
}
|
2021-04-18 00:08:01 +08:00
|
|
|
}
|
|
|
|
pWidget->save();
|
|
|
|
}
|