| 1 | #include "PreferencesDialog.h" |
| 2 | #include "Settings.h" |
| 3 | #include <QListWidgetItem> |
| 4 | #include <QFontDialog> |
| 5 | #include <QColorDialog> |
| 6 | |
| 7 | PreferencesDialog::PreferencesDialog(QWidget* parent) |
| 8 | : QDialog(parent) |
| 9 | { |
| 10 | setupUi(this); |
| 11 | |
| 12 | connect(listFonts, &QListWidget::currentRowChanged, |
| 13 | this, &PreferencesDialog::fontSelectionChange); |
| 14 | connect(rbUseAppFont, &QRadioButton::toggled, |
| 15 | this, &PreferencesDialog::fontTypeChanged); |
| 16 | connect(rbUseFixedFont, &QRadioButton::toggled, |
| 17 | this, &PreferencesDialog::fontTypeChanged); |
| 18 | connect(rbUseCustomFont, &QRadioButton::toggled, |
| 19 | this, &PreferencesDialog::fontTypeChanged); |
| 20 | connect(btnSelectFont, &QPushButton::clicked, |
| 21 | this, &PreferencesDialog::fontSelectCustom); |
| 22 | connect(btnFontColor, &QPushButton::clicked, |
| 23 | this, &PreferencesDialog::fontSelectColor); |
| 24 | |
| 25 | initConfig(); |
| 26 | initFontList(); |
| 27 | listFonts->setCurrentRow(0); |
| 28 | } |
| 29 | |
| 30 | /* |
| 31 | * Config settings |
| 32 | */ |
| 33 | void PreferencesDialog::initConfig() |
| 34 | { |
| 35 | Settings& s = Settings::get(); |
| 36 | int status1 = s.autoReloadSymbols() ? Qt::Checked : Qt::Unchecked; |
| 37 | cbAutoReloadSymbols->setChecked(status1); |
| 38 | connect(cbAutoReloadSymbols, &QCheckBox::stateChanged, |
| 39 | this, &PreferencesDialog::autoReloadSymbols); |
| 40 | |
| 41 | int status2 = s.preserveLostSymbols() ? Qt::Checked : Qt::Unchecked; |
| 42 | cbPreserveLostSymbols->setChecked(status2); |
| 43 | connect(cbPreserveLostSymbols, &QCheckBox::stateChanged, |
| 44 | this, &PreferencesDialog::preserveLostSymbols); |
| 45 | |
| 46 | int status3 = s.preserveBreakpointSymbol() ? Qt::Checked : Qt::Unchecked; |
| 47 | cbPreserveBreakpointSymbol->setChecked(status3); |
| 48 | connect(cbPreserveBreakpointSymbol, &QCheckBox::stateChanged, |
| 49 | this, &PreferencesDialog::preserveBreakpointSymbol); |
| 50 | } |
| 51 | /* |
| 52 | * Font settings |
| 53 | */ |
| 54 | void PreferencesDialog::initFontList() |
| 55 | { |
| 56 | Settings& s = Settings::get(); |
| 57 | listFonts->clear(); |
| 58 | for (int f = Settings::APP_FONT; f < Settings::FONT_END; ++f) { |
| 59 | new QListWidgetItem(s.fontName((Settings::DebuggerFont)f), listFonts); |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | void PreferencesDialog::fontSelectionChange(int row) |
| 64 | { |
| 65 | updating = true; |
| 66 | if (row == 0) { |
| 67 | rbUseAppFont->setText(tr("Use system font")); |
| 68 | } else { |
| 69 | rbUseAppFont->setText(tr("Use application font")); |
| 70 | } |
| 71 | |
| 72 | rbUseAppFont->setEnabled(row >= 0); |
| 73 | rbUseFixedFont->setEnabled(row > 1); |
| 74 | rbUseCustomFont->setEnabled(row >= 0); |
| 75 | |
| 76 | switch (Settings::get().fontType((Settings::DebuggerFont)row)) { |
| 77 | case Settings::APPLICATION_DEFAULT: |
| 78 | rbUseAppFont->setChecked(true); |
| 79 | break; |
| 80 | case Settings::FIXED_DEFAULT: |
| 81 | rbUseFixedFont->setChecked(true); |
| 82 | break; |
| 83 | case Settings::CUSTOM: |
| 84 | rbUseCustomFont->setChecked(true); |
| 85 | break; |
| 86 | } |
| 87 | |
| 88 | lblPreview->setFont(Settings::get().font ((Settings::DebuggerFont)row)); |
| 89 | setFontPreviewColor(Settings::get().fontColor((Settings::DebuggerFont)row)); |
| 90 | btnSelectFont->setEnabled(rbUseCustomFont->isChecked()); |
| 91 | btnFontColor->setEnabled(row > 1); |
| 92 | updating = false; |
| 93 | } |
| 94 | |
| 95 | void PreferencesDialog::fontTypeChanged(bool state) |
| 96 | { |
| 97 | if (!state || updating) return; |
| 98 | |
| 99 | auto f = (Settings::DebuggerFont)(listFonts->currentRow()); |
| 100 | Settings& s = Settings::get(); |
| 101 | |
| 102 | if (rbUseAppFont->isChecked()) { |
| 103 | s.setFontType(f, Settings::APPLICATION_DEFAULT); |
| 104 | } else if (rbUseFixedFont->isChecked()) { |
| 105 | s.setFontType(f, Settings::FIXED_DEFAULT); |
| 106 | } else { |
| 107 | s.setFontType(f, Settings::CUSTOM); |
| 108 | } |
| 109 | lblPreview->setFont(s.font(f)); |
| 110 | btnSelectFont->setEnabled(rbUseCustomFont->isChecked()); |
| 111 | } |
| 112 | |
| 113 | void PreferencesDialog::fontSelectCustom() |
| 114 | { |
| 115 | bool ok; |
| 116 | auto f = (Settings::DebuggerFont)(listFonts->currentRow()); |
| 117 | QFont newFont = QFontDialog::getFont(&ok, Settings::get().font(f)); |
| 118 | if (ok) { |
| 119 | lblPreview->setFont(newFont); |
| 120 | Settings::get().setFont(f, newFont); |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | void PreferencesDialog::fontSelectColor() |
| 125 | { |
| 126 | auto f = (Settings::DebuggerFont)(listFonts->currentRow()); |
| 127 | QColor newColor = QColorDialog::getColor(Settings::get().fontColor(f), this); |
| 128 | if (newColor.isValid()) { |
| 129 | Settings::get().setFontColor(f, newColor); |
| 130 | setFontPreviewColor(newColor); |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | void PreferencesDialog::autoReloadSymbols(int state) |
| 135 | { |
| 136 | Settings::get().setAutoReloadSymbols(state == Qt::Checked); |
| 137 | } |
| 138 | |
| 139 | void PreferencesDialog::preserveLostSymbols(int state) |
| 140 | { |
| 141 | Settings::get().setPreserveLostSymbols(state == Qt::Checked); |
| 142 | } |
| 143 | |
| 144 | void PreferencesDialog::preserveBreakpointSymbol(int state) |
| 145 | { |
| 146 | Settings::get().setPreserveBreakpointSymbol(state == Qt::Checked); |
| 147 | } |
| 148 | |
| 149 | void PreferencesDialog::setFontPreviewColor(const QColor& c) |
| 150 | { |
| 151 | if (listFonts->currentRow() > 1) { |
| 152 | QPalette pal = lblPreview->palette(); |
| 153 | pal.setColor(QPalette::WindowText, c); |
| 154 | lblPreview->setPalette(pal); |
| 155 | } else { |
| 156 | lblPreview->setPalette(QPalette()); |
| 157 | } |
| 158 | } |