2021-06-14 08:01:00 +08:00
|
|
|
#include "editorcolorschemewidget.h"
|
|
|
|
#include "ui_editorcolorschemewidget.h"
|
2021-06-18 22:57:19 +08:00
|
|
|
#include "../settings.h"
|
|
|
|
#include "../colorscheme.h"
|
2021-06-20 14:30:47 +08:00
|
|
|
#include "../mainwindow.h"
|
|
|
|
|
|
|
|
#include <QAction>
|
|
|
|
#include <QMessageBox>
|
2021-06-20 14:49:38 +08:00
|
|
|
#include <QDebug>
|
2021-06-20 22:54:16 +08:00
|
|
|
#include <QInputDialog>
|
|
|
|
#include <QFileDialog>
|
2021-06-14 08:01:00 +08:00
|
|
|
|
2021-06-17 10:39:46 +08:00
|
|
|
EditorColorSchemeWidget::EditorColorSchemeWidget(const QString& name, const QString& group, QWidget *parent) :
|
|
|
|
SettingsWidget(name,group,parent),
|
2021-06-14 08:01:00 +08:00
|
|
|
ui(new Ui::EditorColorSchemeWidget)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2021-06-18 22:57:19 +08:00
|
|
|
|
2021-06-20 14:30:47 +08:00
|
|
|
mDefaultSchemeComboFont = ui->cbScheme->font();
|
|
|
|
mModifiedSchemeComboFont = mDefaultSchemeComboFont;
|
|
|
|
mModifiedSchemeComboFont.setBold(true);
|
|
|
|
int schemeCount=0;
|
2021-06-18 22:57:19 +08:00
|
|
|
for (QString schemeName: pColorManager->getSchemes()) {
|
2021-06-20 14:30:47 +08:00
|
|
|
PColorScheme scheme = pColorManager->get(schemeName);
|
|
|
|
if (!scheme)
|
|
|
|
return;
|
2021-06-18 22:57:19 +08:00
|
|
|
ui->cbScheme->addItem(schemeName);
|
2021-06-20 14:30:47 +08:00
|
|
|
if (scheme->customed())
|
|
|
|
ui->cbScheme->setItemData(schemeCount,mModifiedSchemeComboFont,Qt::FontRole);
|
|
|
|
schemeCount++;
|
2021-06-18 22:57:19 +08:00
|
|
|
}
|
2021-06-19 22:58:35 +08:00
|
|
|
ui->treeItems->setModel(&mDefinesModel);
|
|
|
|
mDefinesModel.setHorizontalHeaderLabels(QStringList());
|
|
|
|
for (QString defineName : pColorManager->getDefines()) {
|
|
|
|
addDefine(defineName, pColorManager->getDefine(defineName));
|
|
|
|
}
|
|
|
|
ui->treeItems->expandAll();
|
2021-06-20 14:30:47 +08:00
|
|
|
QModelIndex groupIndex = mDefinesModel.index(0,0);
|
|
|
|
QModelIndex index = mDefinesModel.index(0,0,groupIndex);
|
|
|
|
ui->treeItems->setCurrentIndex(index);
|
2021-06-19 22:58:35 +08:00
|
|
|
connect(ui->treeItems->selectionModel(), &QItemSelectionModel::selectionChanged,
|
|
|
|
this, &EditorColorSchemeWidget::onItemSelectionChanged);
|
2021-06-20 14:30:47 +08:00
|
|
|
connect(ui->cbScheme, QOverload<int>::of(&QComboBox::currentIndexChanged),
|
|
|
|
this, &EditorColorSchemeWidget::changeSchemeComboFont);
|
|
|
|
connect(ui->cbScheme, QOverload<int>::of(&QComboBox::currentIndexChanged),
|
|
|
|
this, &EditorColorSchemeWidget::onItemSelectionChanged);
|
2021-06-19 22:58:35 +08:00
|
|
|
connect(this, &SettingsWidget::settingsChanged,this,
|
|
|
|
&EditorColorSchemeWidget::onSettingChanged);
|
|
|
|
ui->editDemo->lines()->setText(
|
|
|
|
"#include <iostream>\n"
|
|
|
|
"#include <conio.h>\n"
|
|
|
|
"\n"
|
|
|
|
"int x=10;\n"
|
|
|
|
"\n"
|
|
|
|
"int main(int argc, char **argv)\n"
|
|
|
|
"{\n"
|
|
|
|
" int numbers[20];\n"
|
|
|
|
" float average, total; //breakpoint\n"
|
|
|
|
" for (int i = 0; i <= 19; i++)\n"
|
|
|
|
" { // active breakpoint\n"
|
|
|
|
" numbers[i] = i+x;\n"
|
|
|
|
" Total += i; // error line\n"
|
|
|
|
" }\n"
|
|
|
|
" average = total / 20; // comment\n"
|
|
|
|
" cout << \"total: \" << total << \"\nAverage: \" << average;\n"
|
|
|
|
" getch();\n"
|
|
|
|
"}\n"
|
|
|
|
);
|
|
|
|
ui->editDemo->setReadOnly(true);
|
2021-06-20 14:30:47 +08:00
|
|
|
onItemSelectionChanged();
|
2021-06-19 22:58:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditorColorSchemeWidget::addDefine(const QString& name, PColorSchemeItemDefine define)
|
|
|
|
{
|
|
|
|
QList<QStandardItem*> items = mDefinesModel.findItems(define->group());
|
|
|
|
QStandardItem* pGroupItem;
|
|
|
|
if (items.count() == 0 ) {
|
|
|
|
pGroupItem = new QStandardItem(define->group());
|
|
|
|
pGroupItem->setData("", NameRole);
|
|
|
|
mDefinesModel.appendRow(pGroupItem);
|
|
|
|
} else {
|
|
|
|
pGroupItem = items[0];
|
|
|
|
}
|
|
|
|
QStandardItem* pWidgetItem = new QStandardItem(define->displayName());
|
|
|
|
pWidgetItem->setData(name, NameRole);
|
|
|
|
pGroupItem->appendRow(pWidgetItem);
|
|
|
|
}
|
|
|
|
|
|
|
|
PColorSchemeItem EditorColorSchemeWidget::getCurrentItem()
|
|
|
|
{
|
|
|
|
QItemSelectionModel * selectionModel = ui->treeItems->selectionModel();
|
|
|
|
QString name =mDefinesModel.data(selectionModel->currentIndex(),NameRole).toString();
|
|
|
|
if (name.isEmpty())
|
|
|
|
return PColorSchemeItem();
|
|
|
|
return pColorManager->getItem(ui->cbScheme->currentText(), name);
|
2021-06-14 08:01:00 +08:00
|
|
|
}
|
|
|
|
|
2021-06-20 09:27:37 +08:00
|
|
|
PColorScheme EditorColorSchemeWidget::getCurrentScheme()
|
|
|
|
{
|
|
|
|
return pColorManager->get(ui->cbScheme->currentText());
|
|
|
|
}
|
|
|
|
|
2021-06-20 14:30:47 +08:00
|
|
|
void EditorColorSchemeWidget::connectModificationSlots()
|
|
|
|
{
|
|
|
|
connect(ui->cbBackground,&QCheckBox::stateChanged,
|
|
|
|
this, &EditorColorSchemeWidget::onBackgroundChanged);
|
|
|
|
connect(ui->colorBackground,&ColorEdit::colorChanged,
|
|
|
|
this, &EditorColorSchemeWidget::onBackgroundChanged);
|
|
|
|
connect(ui->cbForeground,&QCheckBox::stateChanged,
|
|
|
|
this, &EditorColorSchemeWidget::onForegroundChanged);
|
|
|
|
connect(ui->colorForeground,&ColorEdit::colorChanged,
|
|
|
|
this, &EditorColorSchemeWidget::onForegroundChanged);
|
|
|
|
connect(ui->cbBold,&QCheckBox::stateChanged,
|
|
|
|
this, &EditorColorSchemeWidget::onFontStyleChanged);
|
|
|
|
connect(ui->cbItalic,&QCheckBox::stateChanged,
|
|
|
|
this, &EditorColorSchemeWidget::onFontStyleChanged);
|
|
|
|
connect(ui->cbStrikeout,&QCheckBox::stateChanged,
|
|
|
|
this, &EditorColorSchemeWidget::onFontStyleChanged);
|
|
|
|
connect(ui->cbUnderlined,&QCheckBox::stateChanged,
|
|
|
|
this, &EditorColorSchemeWidget::onFontStyleChanged);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorColorSchemeWidget::disconnectModificationSlots()
|
|
|
|
{
|
|
|
|
disconnect(ui->cbBackground,&QCheckBox::stateChanged,
|
|
|
|
this, &EditorColorSchemeWidget::onBackgroundChanged);
|
|
|
|
disconnect(ui->colorBackground,&ColorEdit::colorChanged,
|
|
|
|
this, &EditorColorSchemeWidget::onBackgroundChanged);
|
|
|
|
disconnect(ui->cbForeground,&QCheckBox::stateChanged,
|
|
|
|
this, &EditorColorSchemeWidget::onForegroundChanged);
|
|
|
|
disconnect(ui->colorForeground,&ColorEdit::colorChanged,
|
|
|
|
this, &EditorColorSchemeWidget::onForegroundChanged);
|
|
|
|
disconnect(ui->cbBold,&QCheckBox::stateChanged,
|
|
|
|
this, &EditorColorSchemeWidget::onFontStyleChanged);
|
|
|
|
disconnect(ui->cbItalic,&QCheckBox::stateChanged,
|
|
|
|
this, &EditorColorSchemeWidget::onFontStyleChanged);
|
|
|
|
disconnect(ui->cbStrikeout,&QCheckBox::stateChanged,
|
|
|
|
this, &EditorColorSchemeWidget::onFontStyleChanged);
|
|
|
|
disconnect(ui->cbUnderlined,&QCheckBox::stateChanged,
|
|
|
|
this, &EditorColorSchemeWidget::onFontStyleChanged);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorColorSchemeWidget::setCurrentSchemeModified()
|
|
|
|
{
|
|
|
|
PColorScheme scheme = getCurrentScheme();
|
|
|
|
if (scheme) {
|
|
|
|
scheme->setCustomed(true);
|
|
|
|
}
|
|
|
|
if (mModifiedSchemes.contains(ui->cbScheme->currentText()))
|
|
|
|
return;
|
|
|
|
mModifiedSchemes.insert(ui->cbScheme->currentText());
|
|
|
|
ui->cbScheme->setItemData(ui->cbScheme->currentIndex(),
|
|
|
|
mModifiedSchemeComboFont,Qt::FontRole);
|
|
|
|
ui->cbScheme->setFont(mModifiedSchemeComboFont);
|
2021-06-20 22:54:16 +08:00
|
|
|
//ui->cbScheme->view()->setFont(mDefaultSchemeComboFont);
|
2021-06-20 14:30:47 +08:00
|
|
|
//we must reset the editor here, because this slot is processed after the onSettingChanged
|
|
|
|
onSettingChanged();
|
|
|
|
}
|
|
|
|
|
2021-06-14 08:01:00 +08:00
|
|
|
EditorColorSchemeWidget::~EditorColorSchemeWidget()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
2021-06-18 21:48:40 +08:00
|
|
|
|
2021-06-19 22:58:35 +08:00
|
|
|
static void setColorProp(ColorEdit* ce, QCheckBox* cb, const QColor& color) {
|
|
|
|
if (color.isValid()) {
|
|
|
|
cb->setChecked(true);
|
|
|
|
ce->setColor(color);
|
|
|
|
ce->setVisible(true);
|
|
|
|
} else {
|
|
|
|
cb->setChecked(false);
|
|
|
|
ce->setVisible(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorColorSchemeWidget::onItemSelectionChanged()
|
|
|
|
{
|
2021-06-20 14:30:47 +08:00
|
|
|
disconnectModificationSlots();
|
2021-06-19 22:58:35 +08:00
|
|
|
QItemSelectionModel * selectionModel = ui->treeItems->selectionModel();
|
|
|
|
QString name =mDefinesModel.data(selectionModel->currentIndex(),NameRole).toString();
|
|
|
|
bool found = false;
|
|
|
|
if (!name.isEmpty()) {
|
|
|
|
PColorSchemeItemDefine define = pColorManager->getDefine(name);
|
|
|
|
if (define) {
|
|
|
|
found = true;
|
|
|
|
ui->cbBackground->setEnabled(define->hasBackground());
|
|
|
|
ui->colorBackground->setEnabled(define->hasBackground());
|
|
|
|
ui->cbForeground->setEnabled(define->hasForeground());
|
|
|
|
ui->colorForeground->setEnabled(define->hasForeground());
|
|
|
|
ui->grpFontStyles->setEnabled(define->hasFontStyle());
|
|
|
|
PColorSchemeItem item = pColorManager->getItem(ui->cbScheme->currentText(), name);
|
|
|
|
if (item) {
|
|
|
|
if (define->hasBackground()) {
|
|
|
|
setColorProp(ui->colorBackground, ui->cbBackground,item->background());
|
|
|
|
} else {
|
|
|
|
setColorProp(ui->colorBackground, ui->cbBackground,QColor());
|
|
|
|
}
|
|
|
|
if (define->hasForeground()) {
|
|
|
|
setColorProp(ui->colorForeground, ui->cbForeground,item->foreground());
|
|
|
|
} else {
|
|
|
|
setColorProp(ui->colorForeground, ui->cbForeground,QColor());
|
|
|
|
}
|
|
|
|
if (define->hasFontStyle()) {
|
|
|
|
ui->cbBold->setChecked(item->bold());
|
|
|
|
ui->cbItalic->setChecked(item->italic());
|
|
|
|
ui->cbUnderlined->setChecked(item->underlined());
|
|
|
|
ui->cbStrikeout->setChecked(item->strikeout());
|
|
|
|
} else {
|
|
|
|
ui->cbBold->setChecked(false);
|
|
|
|
ui->cbItalic->setChecked(false);
|
|
|
|
ui->cbUnderlined->setChecked(false);
|
|
|
|
ui->cbStrikeout->setChecked(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-06-20 14:30:47 +08:00
|
|
|
|
2021-06-19 22:58:35 +08:00
|
|
|
ui->widgetSchemeItem->setEnabled(found);
|
2021-06-20 14:30:47 +08:00
|
|
|
connectModificationSlots();
|
2021-06-19 22:58:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditorColorSchemeWidget::onSettingChanged()
|
|
|
|
{
|
|
|
|
ui->editDemo->applyColorScheme(ui->cbScheme->currentText());
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorColorSchemeWidget::onForegroundChanged()
|
|
|
|
{
|
|
|
|
PColorSchemeItem item = getCurrentItem();
|
|
|
|
if (!item)
|
|
|
|
return;
|
2021-06-20 22:54:16 +08:00
|
|
|
ui->colorForeground->setVisible(ui->cbForeground->isChecked());
|
2021-06-19 22:58:35 +08:00
|
|
|
if (ui->cbForeground->isChecked()) {
|
|
|
|
item->setForeground(ui->colorForeground->color());
|
|
|
|
} else {
|
2021-06-20 22:54:16 +08:00
|
|
|
ui->colorForeground->setColor(QColor());
|
2021-06-19 22:58:35 +08:00
|
|
|
item->setForeground(QColor());
|
|
|
|
}
|
2021-06-20 14:30:47 +08:00
|
|
|
setCurrentSchemeModified();
|
2021-06-19 22:58:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditorColorSchemeWidget::onBackgroundChanged()
|
|
|
|
{
|
|
|
|
PColorSchemeItem item = getCurrentItem();
|
|
|
|
if (!item)
|
|
|
|
return;
|
2021-06-20 22:54:16 +08:00
|
|
|
ui->colorBackground->setVisible(ui->cbBackground->isChecked());
|
2021-06-19 22:58:35 +08:00
|
|
|
if (ui->cbBackground->isChecked()) {
|
|
|
|
item->setBackground(ui->colorBackground->color());
|
|
|
|
} else {
|
2021-06-20 22:54:16 +08:00
|
|
|
ui->colorBackground->setColor(QColor());
|
2021-06-19 22:58:35 +08:00
|
|
|
item->setBackground(QColor());
|
|
|
|
}
|
2021-06-20 14:30:47 +08:00
|
|
|
setCurrentSchemeModified();
|
2021-06-19 22:58:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditorColorSchemeWidget::onFontStyleChanged()
|
|
|
|
{
|
|
|
|
PColorSchemeItem item = getCurrentItem();
|
|
|
|
if (!item)
|
|
|
|
return;
|
|
|
|
item->setBold(ui->cbBold->isChecked());
|
|
|
|
item->setItalic(ui->cbItalic->isChecked());
|
|
|
|
item->setStrikeout(ui->cbStrikeout->isChecked());
|
|
|
|
item->setUnderlined(ui->cbUnderlined->isChecked());
|
2021-06-20 14:30:47 +08:00
|
|
|
setCurrentSchemeModified();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorColorSchemeWidget::changeSchemeComboFont()
|
|
|
|
{
|
|
|
|
QString name = ui->cbScheme->currentText();
|
|
|
|
PColorScheme scheme = pColorManager->get(name);
|
|
|
|
if (scheme && scheme->customed()) {
|
|
|
|
ui->cbScheme->setFont(mModifiedSchemeComboFont);
|
|
|
|
} else {
|
|
|
|
ui->cbScheme->setFont(mDefaultSchemeComboFont);
|
2021-06-20 09:27:37 +08:00
|
|
|
}
|
2021-06-20 22:54:16 +08:00
|
|
|
//ui->cbScheme->view()->setFont(mDefaultSchemeComboFont);
|
2021-06-19 22:58:35 +08:00
|
|
|
}
|
|
|
|
|
2021-06-18 21:48:40 +08:00
|
|
|
void EditorColorSchemeWidget::doLoad()
|
|
|
|
{
|
2021-06-20 14:30:47 +08:00
|
|
|
ui->cbScheme->setCurrentText(pSettings->editor().colorScheme());
|
2021-06-18 21:48:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditorColorSchemeWidget::doSave()
|
2021-06-20 14:30:47 +08:00
|
|
|
{
|
|
|
|
try {
|
|
|
|
for (QString name:mModifiedSchemes) {
|
|
|
|
pColorManager->saveScheme(name);
|
|
|
|
}
|
|
|
|
pSettings->editor().setColorScheme(ui->cbScheme->currentText());
|
|
|
|
pSettings->editor().save();
|
|
|
|
pMainWindow->updateEditorColorSchemes();
|
|
|
|
} catch (FileError e) {
|
2021-06-21 11:21:26 +08:00
|
|
|
QMessageBox::critical(this,tr("Error"),e.reason());
|
2021-06-20 14:30:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorColorSchemeWidget::on_actionCopy_Scheme_triggered()
|
2021-06-18 21:48:40 +08:00
|
|
|
{
|
2021-06-20 14:49:38 +08:00
|
|
|
QString newName = pColorManager->copy(ui->cbScheme->currentText());
|
|
|
|
if (newName.isEmpty())
|
|
|
|
return;
|
|
|
|
ui->cbScheme->addItem(newName);
|
|
|
|
ui->cbScheme->setCurrentText(newName);
|
2021-06-18 21:48:40 +08:00
|
|
|
}
|
2021-06-20 14:30:47 +08:00
|
|
|
|
|
|
|
void EditorColorSchemeWidget::on_btnSchemeMenu_pressed()
|
|
|
|
{
|
|
|
|
QMenu menu;
|
|
|
|
|
2021-06-20 14:49:38 +08:00
|
|
|
PColorScheme scheme = getCurrentScheme();
|
2021-06-20 14:30:47 +08:00
|
|
|
if (scheme) {
|
|
|
|
if (scheme->customed()) {
|
|
|
|
menu.addAction(ui->actionReset_Scheme);
|
|
|
|
}
|
|
|
|
if (!scheme->bundled()) {
|
|
|
|
menu.addAction(ui->actionRename_Scheme);
|
|
|
|
menu.addAction(ui->actionDelete_Scheme);
|
|
|
|
}
|
2021-06-20 22:54:16 +08:00
|
|
|
QString name = ui->cbScheme->currentText();
|
|
|
|
if (!pColorManager->exists(name+ " Copy"))
|
|
|
|
menu.addAction(ui->actionCopy_Scheme);
|
2021-06-20 14:30:47 +08:00
|
|
|
menu.addAction(ui->actionExport_Scheme);
|
|
|
|
menu.addSeparator();
|
|
|
|
}
|
|
|
|
menu.addAction(ui->actionImport_Scheme);
|
|
|
|
QPoint p;
|
|
|
|
p.setX(0);
|
|
|
|
p.setY(ui->btnSchemeMenu->height()+2);
|
2021-06-20 14:49:38 +08:00
|
|
|
menu.exec(ui->btnSchemeMenu->mapToGlobal(p));
|
2021-06-20 14:30:47 +08:00
|
|
|
}
|
2021-06-20 22:54:16 +08:00
|
|
|
|
|
|
|
void EditorColorSchemeWidget::on_actionImport_Scheme_triggered()
|
|
|
|
{
|
|
|
|
QString filename = QFileDialog::getOpenFileName(this,
|
|
|
|
tr("Open"), QString(), tr("Color Scheme Files (*.scheme)"));
|
|
|
|
if (filename.isEmpty())
|
|
|
|
return;
|
|
|
|
QFileInfo fileInfo(filename);
|
|
|
|
QString name = fileInfo.fileName();
|
|
|
|
QString suffix = EXT_COLOR_SCHEME;
|
|
|
|
if (!name.toLower().endsWith(suffix))
|
|
|
|
return;
|
|
|
|
name.remove(name.length()-suffix.length(),suffix.length());
|
|
|
|
name.replace('_',' ');
|
|
|
|
if (!pColorManager->isValidName(name)) {
|
2021-06-21 11:21:26 +08:00
|
|
|
QMessageBox::critical(this,tr("Error"),tr("'%1' is not a valid name for color scheme file."));
|
2021-06-20 22:54:16 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
PColorScheme scheme = ColorScheme::load(filename);
|
|
|
|
pColorManager->add(name, scheme);
|
|
|
|
ui->cbScheme->addItem(name);
|
|
|
|
ui->cbScheme->setCurrentText(name);
|
|
|
|
} catch (FileError e) {
|
2021-06-21 11:21:26 +08:00
|
|
|
QMessageBox::critical(this,tr("Error"),e.reason());
|
2021-06-20 22:54:16 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorColorSchemeWidget::on_actionRename_Scheme_triggered()
|
|
|
|
{
|
|
|
|
QString name = ui->cbScheme->currentText();
|
|
|
|
bool isOk;
|
|
|
|
QString newName = QInputDialog::getText(this,tr("New scheme name"),tr("New scheme name"),
|
|
|
|
QLineEdit::Normal,name,&isOk);
|
|
|
|
if (isOk) {
|
|
|
|
if (!pColorManager->isValidName(newName)) {
|
2021-06-21 11:21:26 +08:00
|
|
|
QMessageBox::critical(this,tr("Error"),tr("'%1' is not a valid scheme name!").arg(newName));
|
2021-06-20 22:54:16 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
pColorManager->rename(name,newName);
|
|
|
|
ui->cbScheme->setItemText(
|
|
|
|
ui->cbScheme->currentIndex(),
|
|
|
|
newName
|
|
|
|
);
|
|
|
|
if (mModifiedSchemes.contains(name))
|
|
|
|
mModifiedSchemes.remove(name);
|
|
|
|
mModifiedSchemes.insert(newName);
|
|
|
|
} catch(FileError e) {
|
2021-06-21 11:21:26 +08:00
|
|
|
QMessageBox::critical(this,tr("Error"),e.reason());
|
2021-06-20 22:54:16 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorColorSchemeWidget::on_actionReset_Scheme_triggered()
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
if (pColorManager->restoreToDefault(ui->cbScheme->currentText())) {
|
|
|
|
ui->cbScheme->setItemData(
|
|
|
|
ui->cbScheme->currentIndex(),
|
|
|
|
QVariant(),
|
|
|
|
Qt::FontRole);
|
|
|
|
ui->cbScheme->setFont(mDefaultSchemeComboFont);
|
|
|
|
//ui->cbScheme->view()->setFont(mDefaultSchemeComboFont);
|
|
|
|
}
|
|
|
|
} catch (FileError e) {
|
2021-06-21 11:21:26 +08:00
|
|
|
QMessageBox::critical(this,tr("Error"),e.reason());
|
2021-06-20 22:54:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorColorSchemeWidget::on_actionExport_Scheme_triggered()
|
|
|
|
{
|
|
|
|
QString filename = QFileDialog::getSaveFileName(this,
|
|
|
|
tr("Save"), QString(), tr("Color Scheme Files (*.scheme)"));
|
|
|
|
if (filename.isEmpty())
|
|
|
|
return;
|
|
|
|
try {
|
|
|
|
PColorScheme scheme = getCurrentScheme();
|
|
|
|
scheme->save(filename);
|
|
|
|
} catch (FileError e) {
|
2021-06-21 11:21:26 +08:00
|
|
|
QMessageBox::critical(this,tr("Error"),e.reason());
|
2021-06-20 22:54:16 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorColorSchemeWidget::on_actionDelete_Scheme_triggered()
|
|
|
|
{
|
|
|
|
|
|
|
|
QString name = ui->cbScheme->currentText();
|
2021-06-21 11:21:26 +08:00
|
|
|
if (QMessageBox::warning(this,tr("Confirm Delete Scheme"),
|
2021-06-20 22:54:16 +08:00
|
|
|
tr("Scheme '%1' will be deleted!<br />Do you really want to continue?")
|
|
|
|
.arg(name),
|
|
|
|
QMessageBox::Yes, QMessageBox::No)!=QMessageBox::Yes)
|
|
|
|
return;
|
|
|
|
try {
|
|
|
|
if (pColorManager->remove(name)) {
|
|
|
|
if (mModifiedSchemes.contains(name))
|
|
|
|
mModifiedSchemes.remove(name);
|
|
|
|
ui->cbScheme->removeItem(ui->cbScheme->currentIndex());
|
|
|
|
if (name == pSettings->editor().colorScheme())
|
|
|
|
doSave();
|
|
|
|
}
|
|
|
|
} catch (FileError e) {
|
2021-06-21 11:21:26 +08:00
|
|
|
QMessageBox::critical(this,tr("Error"),e.reason());
|
2021-06-20 22:54:16 +08:00
|
|
|
}
|
|
|
|
}
|