| 1 | /* |
| 2 | * Copyright (C) 2020-2022 Roy Qu (royqh1979@gmail.com) |
| 3 | * |
| 4 | * This program is free software: you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation, either version 3 of the License, or |
| 7 | * (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 16 | */ |
| 17 | #include "editorclipboardwidget.h" |
| 18 | #include "ui_editorclipboardwidget.h" |
| 19 | #include "../settings.h" |
| 20 | #include "../mainwindow.h" |
| 21 | #include "../colorscheme.h" |
| 22 | |
| 23 | EditorClipboardWidget::EditorClipboardWidget(const QString& name, const QString& group, QWidget *parent) : |
| 24 | SettingsWidget(name,group,parent), |
| 25 | ui(new Ui::EditorClipboardWidget) |
| 26 | { |
| 27 | ui->setupUi(this); |
| 28 | ui->cbCopyWithFormatAs->addItem("None" ); |
| 29 | #ifdef Q_OS_WIN |
| 30 | ui->cbCopyWithFormatAs->addItem("HTML" ); |
| 31 | #endif |
| 32 | |
| 33 | for (QString name: pColorManager->getSchemes()) { |
| 34 | ui->cbHTMLColorScheme->addItem(name); |
| 35 | ui->cbRTFColorScheme->addItem(name); |
| 36 | } |
| 37 | connect(ui->chkCopyRTFUseEditorColor, |
| 38 | &QCheckBox::stateChanged, |
| 39 | this, |
| 40 | &EditorClipboardWidget::onUseSchemeChanged); |
| 41 | connect(ui->chkCopyHTMLUseEditorColor, |
| 42 | &QCheckBox::stateChanged, |
| 43 | this, |
| 44 | &EditorClipboardWidget::onUseSchemeChanged); |
| 45 | } |
| 46 | |
| 47 | EditorClipboardWidget::~EditorClipboardWidget() |
| 48 | { |
| 49 | delete ui; |
| 50 | } |
| 51 | |
| 52 | void EditorClipboardWidget::onUseSchemeChanged() |
| 53 | { |
| 54 | ui->cbRTFColorScheme->setEnabled(!ui->chkCopyRTFUseEditorColor->isChecked()); |
| 55 | ui->cbHTMLColorScheme->setEnabled(!ui->chkCopyHTMLUseEditorColor->isChecked()); |
| 56 | } |
| 57 | |
| 58 | void EditorClipboardWidget::doLoad() |
| 59 | { |
| 60 | //pSettings->editor().load(); |
| 61 | //copy |
| 62 | QString mCopyHTMLColorScheme; |
| 63 | |
| 64 | ui->grpCopySizeLimit->setChecked(pSettings->editor().copySizeLimit()); |
| 65 | ui->spinCopyCharLimits->setValue(pSettings->editor().copyCharLimits()); |
| 66 | ui->spinCopyLineLimits->setValue(pSettings->editor().copyLineLimits()); |
| 67 | ui->cbCopyWithFormatAs->setCurrentIndex(std::max(0,std::min(ui->cbCopyWithFormatAs->count(), |
| 68 | pSettings->editor().copyWithFormatAs())) ); |
| 69 | ui->chkCopyRTFUseBackground->setChecked(pSettings->editor().copyRTFUseBackground()); |
| 70 | ui->chkCopyRTFUseEditorColor->setChecked(pSettings->editor().copyRTFUseEditorColor()); |
| 71 | ui->cbRTFColorScheme->setCurrentText(pSettings->editor().copyRTFColorScheme()); |
| 72 | ui->chkCopyHTMLUseBackground->setChecked(pSettings->editor().copyHTMLUseBackground()); |
| 73 | ui->chkCopyHTMLUseEditorColor->setChecked(pSettings->editor().copyHTMLUseEditorColor()); |
| 74 | ui->cbHTMLColorScheme->setCurrentText(pSettings->editor().copyHTMLColorScheme()); |
| 75 | onUseSchemeChanged(); |
| 76 | } |
| 77 | |
| 78 | void EditorClipboardWidget::doSave() |
| 79 | { |
| 80 | //copy |
| 81 | pSettings->editor().setCopySizeLimit(ui->grpCopySizeLimit->isChecked()); |
| 82 | pSettings->editor().setCopyCharLimits(ui->spinCopyCharLimits->value()); |
| 83 | pSettings->editor().setCopyLineLimits(ui->spinCopyLineLimits->value()); |
| 84 | pSettings->editor().setCopyWithFormatAs(ui->cbCopyWithFormatAs->currentIndex()); |
| 85 | |
| 86 | pSettings->editor().setCopyRTFUseBackground(ui->chkCopyRTFUseBackground->isChecked()); |
| 87 | pSettings->editor().setCopyRTFUseEditorColor(ui->chkCopyRTFUseEditorColor->isChecked()); |
| 88 | pSettings->editor().setCopyRTFColorScheme(ui->cbRTFColorScheme->currentText()); |
| 89 | |
| 90 | pSettings->editor().setCopyHTMLUseBackground(ui->chkCopyHTMLUseBackground->isChecked()); |
| 91 | pSettings->editor().setCopyHTMLUseEditorColor(ui->chkCopyHTMLUseEditorColor->isChecked()); |
| 92 | pSettings->editor().setCopyHTMLColorScheme(ui->cbHTMLColorScheme->currentText()); |
| 93 | |
| 94 | pSettings->editor().save(); |
| 95 | pMainWindow->updateEditorSettings(); |
| 96 | } |
| 97 | |