RedPanda-CPP/RedPandaIDE/settingsdialog/editorclipboardwidget.cpp

90 lines
3.5 KiB
C++
Raw Normal View History

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/>.
*/
#include "editorclipboardwidget.h"
#include "ui_editorclipboardwidget.h"
#include "../settings.h"
#include "../mainwindow.h"
2021-06-20 22:54:16 +08:00
#include "../colorscheme.h"
EditorClipboardWidget::EditorClipboardWidget(const QString& name, const QString& group, QWidget *parent) :
SettingsWidget(name,group,parent),
ui(new Ui::EditorClipboardWidget)
{
ui->setupUi(this);
ui->cbCopyWithFormatAs->addItem("None");
2021-12-25 23:46:12 +08:00
#ifdef Q_OS_WIN
ui->cbCopyWithFormatAs->addItem("HTML");
2021-12-25 23:46:12 +08:00
#endif
2021-06-20 22:54:16 +08:00
for (QString name: pColorManager->getSchemes()) {
ui->cbHTMLColorScheme->addItem(name);
ui->cbRTFColorScheme->addItem(name);
}
connect(ui->chkCopyRTFUseEditorColor,
&QCheckBox::stateChanged,
this,
&EditorClipboardWidget::onUseSchemeChanged);
connect(ui->chkCopyHTMLUseEditorColor,
&QCheckBox::stateChanged,
this,
&EditorClipboardWidget::onUseSchemeChanged);
}
EditorClipboardWidget::~EditorClipboardWidget()
{
delete ui;
}
2021-06-20 22:54:16 +08:00
void EditorClipboardWidget::onUseSchemeChanged()
{
ui->cbRTFColorScheme->setEnabled(!ui->chkCopyRTFUseEditorColor->isChecked());
ui->cbHTMLColorScheme->setEnabled(!ui->chkCopyHTMLUseEditorColor->isChecked());
}
void EditorClipboardWidget::doLoad()
{
//pSettings->editor().load();
//copy
2021-06-20 14:30:47 +08:00
QString mCopyHTMLColorScheme;
ui->cbCopyWithFormatAs->setCurrentIndex(std::max(0,std::min(ui->cbCopyWithFormatAs->count(),
pSettings->editor().copyWithFormatAs())) );
ui->chkCopyRTFUseBackground->setChecked(pSettings->editor().copyRTFUseBackground());
ui->chkCopyRTFUseEditorColor->setChecked(pSettings->editor().copyRTFUseEditorColor());
ui->cbRTFColorScheme->setCurrentText(pSettings->editor().copyRTFColorScheme());
ui->chkCopyHTMLUseBackground->setChecked(pSettings->editor().copyHTMLUseBackground());
ui->chkCopyHTMLUseEditorColor->setChecked(pSettings->editor().copyHTMLUseEditorColor());
ui->cbHTMLColorScheme->setCurrentText(pSettings->editor().copyHTMLColorScheme());
2021-06-20 22:54:16 +08:00
onUseSchemeChanged();
}
void EditorClipboardWidget::doSave()
{
//copy
pSettings->editor().setCopyWithFormatAs(ui->cbCopyWithFormatAs->currentIndex());
pSettings->editor().setCopyRTFUseBackground(ui->chkCopyRTFUseBackground->isChecked());
pSettings->editor().setCopyRTFUseEditorColor(ui->chkCopyRTFUseEditorColor->isChecked());
2021-06-20 22:54:16 +08:00
pSettings->editor().setCopyRTFColorScheme(ui->cbRTFColorScheme->currentText());
pSettings->editor().setCopyHTMLUseBackground(ui->chkCopyHTMLUseBackground->isChecked());
pSettings->editor().setCopyHTMLUseEditorColor(ui->chkCopyHTMLUseEditorColor->isChecked());
2021-06-20 22:54:16 +08:00
pSettings->editor().setCopyHTMLColorScheme(ui->cbHTMLColorScheme->currentText());
pSettings->editor().save();
pMainWindow->updateEditorSettings();
}