| 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 "editorgeneralwidget.h" |
| 18 | #include "ui_editorgeneralwidget.h" |
| 19 | #include "../settings.h" |
| 20 | #include "../mainwindow.h" |
| 21 | |
| 22 | #include <QStandardItemModel> |
| 23 | |
| 24 | EditorGeneralWidget::EditorGeneralWidget(const QString& name, const QString& group, QWidget *parent) : |
| 25 | SettingsWidget(name,group,parent), |
| 26 | ui(new Ui::editorgeneralwidget) |
| 27 | { |
| 28 | ui->setupUi(this); |
| 29 | QStringList caretTypes; |
| 30 | caretTypes.append(tr("Vertical Line" )); |
| 31 | caretTypes.append(tr("Horizontal Line" )); |
| 32 | caretTypes.append(tr("Half Block" )); |
| 33 | caretTypes.append(tr("Block" )); |
| 34 | ui->cbCaretForInsert->addItems(caretTypes); |
| 35 | ui->cbCaretForOverwrite->addItems(caretTypes); |
| 36 | } |
| 37 | |
| 38 | EditorGeneralWidget::~EditorGeneralWidget() |
| 39 | { |
| 40 | delete ui; |
| 41 | } |
| 42 | |
| 43 | static void setCaretTypeIndex(QComboBox* combo, QSynedit::EditCaretType caretType) { |
| 44 | int t = static_cast<int>(caretType); |
| 45 | combo->setCurrentIndex(t); |
| 46 | } |
| 47 | |
| 48 | static QSynedit::EditCaretType getCaretTypeIndex(QComboBox* combo) { |
| 49 | if (combo->currentIndex()<0) |
| 50 | return QSynedit::EditCaretType::ctVerticalLine; |
| 51 | return static_cast<QSynedit::EditCaretType>(combo->currentIndex()); |
| 52 | } |
| 53 | void EditorGeneralWidget::doLoad() |
| 54 | { |
| 55 | pSettings->editor().load(); |
| 56 | //indents |
| 57 | ui->chkAutoIndent->setChecked(pSettings->editor().autoIndent()); |
| 58 | ui->chkTabToSpaces->setChecked(pSettings->editor().tabToSpaces()); |
| 59 | ui->spTabWidth->setValue(pSettings->editor().tabWidth()); |
| 60 | ui->chkShowIndentLines->setChecked(pSettings->editor().showIndentLines()); |
| 61 | ui->colorIndentLine->setColor(pSettings->editor().indentLineColor()); |
| 62 | ui->chkFillIndents->setChecked(pSettings->editor().fillIndents()); |
| 63 | //carets |
| 64 | ui->chkEnhanceHome->setChecked(pSettings->editor().enhanceHomeKey()); |
| 65 | ui->chkEnhanceEndKey->setChecked(pSettings->editor().enhanceEndKey()); |
| 66 | ui->chkKeepCaretX->setChecked(pSettings->editor().keepCaretX()); |
| 67 | setCaretTypeIndex(ui->cbCaretForInsert,pSettings->editor().caretForInsert()); |
| 68 | setCaretTypeIndex(ui->cbCaretForOverwrite,pSettings->editor().caretForOverwrite()); |
| 69 | ui->chkCaretUseTextColor->setChecked(pSettings->editor().caretUseTextColor()); |
| 70 | ui->colorCaret->setColor(pSettings->editor().caretColor()); |
| 71 | //highlight |
| 72 | ui->chkHighlightCurrentWord->setChecked(pSettings->editor().highlightCurrentWord()); |
| 73 | ui->chkHighlightMatchingBraces->setChecked(pSettings->editor().highlightMathingBraces()); |
| 74 | //scrolls; |
| 75 | ui->chkAutoHideScrollBars->setChecked(pSettings->editor().autoHideScrollbar()); |
| 76 | ui->chkScrollPastEOF->setChecked(pSettings->editor().scrollPastEof()); |
| 77 | ui->chkScrollPastEOL->setChecked(pSettings->editor().scrollPastEol()); |
| 78 | ui->chkScrollHalfPage->setChecked(pSettings->editor().halfPageScroll()); |
| 79 | ui->chkScrollByOneLess->setChecked(pSettings->editor().scrollByOneLess()); |
| 80 | ui->spinMouseWheelScrollSpeed->setValue(pSettings->editor().mouseWheelScrollSpeed()); |
| 81 | ui->spinMouseSelectionScrollSpeed->setValue(pSettings->editor().mouseSelectionScrollSpeed()); |
| 82 | |
| 83 | //right margin line; |
| 84 | ui->grpRightEdge->setChecked(pSettings->editor().showRightEdgeLine()); |
| 85 | ui->spRightEdge->setValue(pSettings->editor().rightEdgeWidth()); |
| 86 | ui->colorRightEdgeLine->setColor(pSettings->editor().rightEdgeLineColor()); |
| 87 | } |
| 88 | |
| 89 | void EditorGeneralWidget::doSave() |
| 90 | { |
| 91 | //indents |
| 92 | pSettings->editor().setAutoIndent(ui->chkAutoIndent->isChecked()); |
| 93 | pSettings->editor().setTabToSpaces(ui->chkTabToSpaces->isChecked()); |
| 94 | pSettings->editor().setTabWidth(ui->spTabWidth->value()); |
| 95 | pSettings->editor().setShowIndentLines(ui->chkShowIndentLines->isChecked()); |
| 96 | pSettings->editor().setIndentLineColor(ui->colorIndentLine->color()); |
| 97 | pSettings->editor().setFillIndents(ui->chkFillIndents->isChecked()); |
| 98 | |
| 99 | //carets |
| 100 | pSettings->editor().setEnhanceHomeKey(ui->chkEnhanceHome->isChecked()); |
| 101 | pSettings->editor().setEnhanceEndKey(ui->chkEnhanceEndKey->isChecked()); |
| 102 | pSettings->editor().setKeepCaretX(ui->chkKeepCaretX->isChecked()); |
| 103 | pSettings->editor().setCaretForInsert(getCaretTypeIndex(ui->cbCaretForInsert)); |
| 104 | pSettings->editor().setCaretForOverwrite(getCaretTypeIndex(ui->cbCaretForOverwrite)); |
| 105 | pSettings->editor().setCaretUseTextColor(ui->chkCaretUseTextColor->isChecked()); |
| 106 | pSettings->editor().setCaretColor(ui->colorCaret->color()); |
| 107 | //highlight |
| 108 | pSettings->editor().setHighlightCurrentWord(ui->chkHighlightCurrentWord->isChecked()); |
| 109 | pSettings->editor().setHighlightMathingBraces(ui->chkHighlightMatchingBraces->isChecked()); |
| 110 | |
| 111 | //scrolls; |
| 112 | pSettings->editor().setAutoHideScrollbar(ui->chkAutoHideScrollBars->isChecked()); |
| 113 | pSettings->editor().setScrollPastEof(ui->chkScrollPastEOF->isChecked()); |
| 114 | pSettings->editor().setScrollPastEol(ui->chkScrollPastEOL->isChecked()); |
| 115 | pSettings->editor().setScrollByOneLess(ui->chkScrollByOneLess->isChecked()); |
| 116 | pSettings->editor().setHalfPageScroll(ui->chkScrollHalfPage->isChecked()); |
| 117 | pSettings->editor().setMouseWheelScrollSpeed(ui->spinMouseWheelScrollSpeed->value()); |
| 118 | pSettings->editor().setMouseSelectionScrollSpeed(ui->spinMouseSelectionScrollSpeed->value()); |
| 119 | |
| 120 | //right margin line; |
| 121 | pSettings->editor().setShowRightEdgeLine(ui->grpRightEdge->isChecked()); |
| 122 | pSettings->editor().setRightEdgeWidth(ui->spRightEdge->value()); |
| 123 | pSettings->editor().setRightEdgeLineColor(ui->colorRightEdgeLine->color()); |
| 124 | pSettings->editor().save(); |
| 125 | pMainWindow->updateEditorSettings(); |
| 126 | } |
| 127 | |
| 128 | void EditorGeneralWidget::on_chkCaretUseTextColor_stateChanged(int ) |
| 129 | { |
| 130 | ui->lbCaretColor->setVisible(!ui->chkCaretUseTextColor->isChecked()); |
| 131 | ui->colorCaret->setVisible(!ui->chkCaretUseTextColor->isChecked()); |
| 132 | } |
| 133 | |
| 134 | |
| 135 | void EditorGeneralWidget::on_chkShowIndentLines_stateChanged(int) |
| 136 | { |
| 137 | ui->lbIndentLineColor->setVisible(ui->chkShowIndentLines->isChecked()); |
| 138 | ui->colorIndentLine->setVisible(ui->chkShowIndentLines->isChecked()); |
| 139 | } |
| 140 | |
| 141 | |