| 1 | // For license of this file, see <project-root-folder>/LICENSE.md. |
| 2 | |
| 3 | #include "gui/settings/settingsgui.h" |
| 4 | |
| 5 | #include "core/feedsmodel.h" |
| 6 | #include "gui/dialogs/formmain.h" |
| 7 | #include "gui/feedmessageviewer.h" |
| 8 | #include "gui/reusable/colortoolbutton.h" |
| 9 | #include "gui/reusable/plaintoolbutton.h" |
| 10 | #include "gui/systemtrayicon.h" |
| 11 | #include "gui/tabwidget.h" |
| 12 | #include "gui/toolbars/feedstoolbar.h" |
| 13 | #include "gui/toolbars/messagestoolbar.h" |
| 14 | #include "gui/toolbars/statusbar.h" |
| 15 | #include "miscellaneous/application.h" |
| 16 | #include "miscellaneous/iconfactory.h" |
| 17 | #include "miscellaneous/settings.h" |
| 18 | |
| 19 | #include <QDropEvent> |
| 20 | #include <QMetaEnum> |
| 21 | #include <QMetaObject> |
| 22 | #include <QStyleFactory> |
| 23 | |
| 24 | SettingsGui::SettingsGui(Settings* settings, QWidget* parent) |
| 25 | : SettingsPanel(settings, parent), m_ui(new Ui::SettingsGui) { |
| 26 | m_ui->setupUi(this); |
| 27 | m_ui->m_editorMessagesToolbar->activeItemsWidget()->viewport()->installEventFilter(this); |
| 28 | m_ui->m_editorFeedsToolbar->activeItemsWidget()->viewport()->installEventFilter(this); |
| 29 | m_ui->m_editorMessagesToolbar->availableItemsWidget()->viewport()->installEventFilter(this); |
| 30 | m_ui->m_editorFeedsToolbar->availableItemsWidget()->viewport()->installEventFilter(this); |
| 31 | m_ui->m_treeSkins->setColumnCount(4); |
| 32 | m_ui->m_treeSkins->setHeaderHidden(false); |
| 33 | m_ui->m_treeSkins->setHeaderLabels({tr("Name"), tr("Author"), tr("Forced style"), tr("Forced skin colors")}); |
| 34 | |
| 35 | m_ui->m_tabUi->setTabVisible(m_ui->m_tabUi->indexOf(m_ui->m_tabTaskBar), |
| 36 | #if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)) || defined(Q_OS_WIN) |
| 37 | true); |
| 38 | #else |
| 39 | false); |
| 40 | #endif |
| 41 | |
| 42 | m_ui->m_helpCustomSkinColors->setHelpText(tr("You can override some colors defined by your skin here. " |
| 43 | "Some colors are used dynamically throughout the application."), |
| 44 | false); |
| 45 | |
| 46 | // Setup skins. |
| 47 | m_ui->m_treeSkins->header()->setSectionResizeMode(0, QHeaderView::ResizeMode::ResizeToContents); |
| 48 | m_ui->m_treeSkins->header()->setSectionResizeMode(1, QHeaderView::ResizeMode::ResizeToContents); |
| 49 | m_ui->m_treeSkins->header()->setSectionResizeMode(2, QHeaderView::ResizeMode::ResizeToContents); |
| 50 | m_ui->m_treeSkins->header()->setSectionResizeMode(3, QHeaderView::ResizeMode::ResizeToContents); |
| 51 | |
| 52 | connect(m_ui->m_checkFontAntialiasing, &QCheckBox::toggled, this, &SettingsGui::requireRestart); |
| 53 | connect(m_ui->m_checkFontAntialiasing, &QCheckBox::toggled, this, &SettingsGui::dirtifySettings); |
| 54 | |
| 55 | connect(m_ui->m_cmbStyles, |
| 56 | static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), |
| 57 | this, |
| 58 | &SettingsGui::updateSkinOptions); |
| 59 | |
| 60 | connect(m_ui->m_checkMonochromeIcons, |
| 61 | &QCheckBox::toggled, |
| 62 | m_ui->m_checkColoredIconsWhenArticles, |
| 63 | &QCheckBox::setEnabled); |
| 64 | connect(m_ui->m_cmbIconTheme, |
| 65 | static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), |
| 66 | this, |
| 67 | &SettingsGui::requireRestart); |
| 68 | connect(m_ui->m_cmbIconTheme, |
| 69 | static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), |
| 70 | this, |
| 71 | &SettingsGui::dirtifySettings); |
| 72 | connect(m_ui->m_treeSkins, &QTreeWidget::currentItemChanged, this, &SettingsGui::dirtifySettings); |
| 73 | connect(m_ui->m_treeSkins, &QTreeWidget::currentItemChanged, this, &SettingsGui::updateSkinOptions); |
| 74 | connect(m_ui->m_grpTray, &QGroupBox::toggled, this, &SettingsGui::dirtifySettings); |
| 75 | connect(m_ui->m_checkHidden, &QCheckBox::toggled, this, &SettingsGui::dirtifySettings); |
| 76 | connect(m_ui->m_checkForceAlternativePalette, &QCheckBox::toggled, this, &SettingsGui::dirtifySettings); |
| 77 | connect(m_ui->m_checkForceAlternativePalette, &QCheckBox::toggled, this, &SettingsGui::requireRestart); |
| 78 | connect(m_ui->m_checkMonochromeIcons, &QCheckBox::toggled, this, &SettingsGui::dirtifySettings); |
| 79 | connect(m_ui->m_checkMonochromeIcons, &QCheckBox::toggled, this, &SettingsGui::requireRestart); |
| 80 | connect(m_ui->m_checkColoredIconsWhenArticles, &QCheckBox::toggled, this, &SettingsGui::dirtifySettings); |
| 81 | connect(m_ui->m_checkColoredIconsWhenArticles, &QCheckBox::toggled, this, &SettingsGui::requireRestart); |
| 82 | connect(m_ui->m_checkCountUnreadMessages, &QCheckBox::toggled, this, &SettingsGui::dirtifySettings); |
| 83 | connect(m_ui->m_checkHideWhenMinimized, &QCheckBox::toggled, this, &SettingsGui::dirtifySettings); |
| 84 | connect(m_ui->m_checkHideTabBarIfOneTabVisible, &QCheckBox::toggled, this, &SettingsGui::dirtifySettings); |
| 85 | connect(m_ui->m_checkCloseTabsDoubleClick, &QCheckBox::toggled, this, &SettingsGui::dirtifySettings); |
| 86 | connect(m_ui->m_checkCloseTabsMiddleClick, &QCheckBox::toggled, this, &SettingsGui::dirtifySettings); |
| 87 | connect(m_ui->m_checkNewTabDoubleClick, &QCheckBox::toggled, this, &SettingsGui::dirtifySettings); |
| 88 | connect(m_ui->m_grbCloseTabs, &QGroupBox::toggled, this, &SettingsGui::dirtifySettings); |
| 89 | connect(m_ui->m_cmbToolbarButtonStyle, |
| 90 | static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), |
| 91 | this, |
| 92 | &SettingsGui::dirtifySettings); |
| 93 | connect(m_ui->m_editorFeedsToolbar, &ToolBarEditor::setupChanged, this, &SettingsGui::dirtifySettings); |
| 94 | connect(m_ui->m_editorMessagesToolbar, &ToolBarEditor::setupChanged, this, &SettingsGui::dirtifySettings); |
| 95 | connect(m_ui->m_editorStatusbar, &ToolBarEditor::setupChanged, this, &SettingsGui::dirtifySettings); |
| 96 | connect(m_ui->m_editorStatusbar, &ToolBarEditor::setupChanged, this, &SettingsGui::requireRestart); |
| 97 | connect(m_ui->m_cmbStyles, |
| 98 | static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), |
| 99 | this, |
| 100 | &SettingsGui::dirtifySettings); |
| 101 | connect(m_ui->m_cmbSelectToolBar, |
| 102 | static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), |
| 103 | m_ui->m_stackedToolbars, |
| 104 | &QStackedWidget::setCurrentIndex); |
| 105 | connect(m_ui->m_gbCustomSkinColors, &QGroupBox::toggled, this, &SettingsGui::dirtifySettings); |
| 106 | connect(m_ui->m_spinToolbarIconSize, |
| 107 | QOverload<int>::of(&QSpinBox::valueChanged), |
| 108 | this, |
| 109 | &SettingsGui::dirtifySettings); |
| 110 | connect(m_ui->m_displayUnreadMessageCountOnTaskBar, &QCheckBox::toggled, this, &SettingsGui::dirtifySettings); |
| 111 | |
| 112 | connect(m_ui->m_spinToolbarIconSize, QOverload<int>::of(&QSpinBox::valueChanged), this, [=](int value) { |
| 113 | if (value <= 0) { |
| 114 | m_ui->m_spinToolbarIconSize->setSuffix(tr(" = default icon size")); |
| 115 | } |
| 116 | else { |
| 117 | m_ui->m_spinToolbarIconSize->setSuffix(QSL(" px")); |
| 118 | } |
| 119 | }); |
| 120 | } |
| 121 | |
| 122 | SettingsGui::~SettingsGui() { |
| 123 | delete m_ui; |
| 124 | } |
| 125 | |
| 126 | QIcon SettingsGui::icon() const { |
| 127 | return qApp->icons()->fromTheme(QSL("draw-freehand"), QSL("draw-star")); |
| 128 | } |
| 129 | |
| 130 | bool SettingsGui::eventFilter(QObject* obj, QEvent* e) { |
| 131 | Q_UNUSED(obj) |
| 132 | |
| 133 | if (e->type() == QEvent::Type::Drop) { |
| 134 | auto* drop_event = static_cast<QDropEvent*>(e); |
| 135 | |
| 136 | #if QT_VERSION_MAJOR == 6 |
| 137 | if (drop_event->modifiers() != |
| 138 | #else |
| 139 | if (drop_event->keyboardModifiers() != |
| 140 | #endif |
| 141 | Qt::KeyboardModifier::NoModifier) { |
| 142 | drop_event->setDropAction(Qt::DropAction::MoveAction); |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | return false; |
| 147 | } |
| 148 | |
| 149 | void SettingsGui::updateSkinOptions() { |
| 150 | auto* it = m_ui->m_treeSkins->currentItem(); |
| 151 | |
| 152 | if (it == nullptr) { |
| 153 | return; |
| 154 | } |
| 155 | |
| 156 | const Skin skin = it->data(0, Qt::ItemDataRole::UserRole).value<Skin>(); |
| 157 | const bool skin_has_palette_or_css = !skin.m_stylePalette.isEmpty() || !skin.m_rawData.isEmpty(); |
| 158 | const bool skin_forces_palette = skin.m_forcedSkinColors; |
| 159 | const bool skin_forces_style = !skin.m_forcedStyles.isEmpty(); |
| 160 | |
| 161 | m_ui->m_cmbStyles->setEnabled(!qApp->skins()->styleIsFrozen() && !skin_forces_style); |
| 162 | m_ui->m_checkForceAlternativePalette->setEnabled(skin_has_palette_or_css && !skin_forces_palette); |
| 163 | } |
| 164 | |
| 165 | void SettingsGui::loadSettings() { |
| 166 | onBeginLoadSettings(); |
| 167 | |
| 168 | m_ui->m_checkFontAntialiasing->setChecked(settings()->value(GROUP(GUI), SETTING(GUI::FontAntialiasing)).toBool()); |
| 169 | |
| 170 | // Load settings of tray icon. |
| 171 | m_ui->m_grpTray->setChecked(settings()->value(GROUP(GUI), SETTING(GUI::UseTrayIcon)).toBool()); |
| 172 | |
| 173 | if (!SystemTrayIcon::isSystemTrayAreaAvailable()) { |
| 174 | m_ui->m_grpTray->setTitle(m_ui->m_grpTray->title() + QL1C(' ') + |
| 175 | tr("(Your OS does not support tray icons at the moment.)")); |
| 176 | m_ui->m_grpTray->setEnabled(false); |
| 177 | } |
| 178 | |
| 179 | m_ui->m_checkHidden->setChecked(settings()->value(GROUP(GUI), SETTING(GUI::MainWindowStartsHidden)).toBool()); |
| 180 | m_ui->m_checkHideWhenMinimized |
| 181 | ->setChecked(settings()->value(GROUP(GUI), SETTING(GUI::HideMainWindowWhenMinimized)).toBool()); |
| 182 | |
| 183 | // Load settings of icon theme. |
| 184 | const QString current_theme = qApp->icons()->currentIconTheme(); |
| 185 | auto icons = qApp->icons()->installedIconThemes(); |
| 186 | |
| 187 | for (const QString& icon_theme_name : std::as_const(icons)) { |
| 188 | if (icon_theme_name == QSL(APP_NO_THEME)) { |
| 189 | // Add just "no theme" on other systems. |
| 190 | //: Label for disabling icon theme. |
| 191 | #if defined(Q_OS_UNIX) && !defined(Q_OS_MACOS) |
| 192 | m_ui->m_cmbIconTheme->addItem(tr("system icon theme"), APP_NO_THEME); |
| 193 | #else |
| 194 | m_ui->m_cmbIconTheme->addItem(tr("no icon theme"), APP_NO_THEME); |
| 195 | #endif |
| 196 | } |
| 197 | else { |
| 198 | m_ui->m_cmbIconTheme->addItem(icon_theme_name, icon_theme_name); |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | m_ui->m_checkMonochromeIcons->setChecked(settings()->value(GROUP(GUI), SETTING(GUI::MonochromeTrayIcon)).toBool()); |
| 203 | m_ui->m_checkColoredIconsWhenArticles |
| 204 | ->setChecked(settings()->value(GROUP(GUI), SETTING(GUI::ColoredBusyTrayIcon)).toBool()); |
| 205 | m_ui->m_checkCountUnreadMessages |
| 206 | ->setChecked(settings()->value(GROUP(GUI), SETTING(GUI::UnreadNumbersInTrayIcon)).toBool()); |
| 207 | |
| 208 | #if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)) || defined(Q_OS_WIN) |
| 209 | m_ui->m_displayUnreadMessageCountOnTaskBar |
| 210 | ->setChecked(settings()->value(GROUP(GUI), SETTING(GUI::UnreadNumbersOnTaskBar)).toBool()); |
| 211 | #endif |
| 212 | |
| 213 | // Mark active icon theme. |
| 214 | if (current_theme == QL1S(APP_NO_THEME)) { |
| 215 | // Because "no icon theme" lies at the index 0. |
| 216 | m_ui->m_cmbIconTheme->setCurrentIndex(0); |
| 217 | } |
| 218 | else { |
| 219 | m_ui->m_cmbIconTheme->setCurrentText(current_theme); |
| 220 | } |
| 221 | |
| 222 | // Load styles. |
| 223 | auto styles = QStyleFactory::keys(); |
| 224 | |
| 225 | m_ui->m_cmbStyles->addItem( |
| 226 | #if defined(Q_OS_UNIX) && !defined(Q_OS_MACOS) |
| 227 | tr("system style"), |
| 228 | #else |
| 229 | tr("default style"), |
| 230 | #endif |
| 231 | APP_NO_THEME); |
| 232 | |
| 233 | for (const QString& style_name : std::as_const(styles)) { |
| 234 | m_ui->m_cmbStyles->addItem(style_name, style_name); |
| 235 | } |
| 236 | |
| 237 | int item_style = m_ui->m_cmbStyles->findData(qApp->skins()->currentStyle(), |
| 238 | Qt::ItemDataRole::UserRole, |
| 239 | Qt::MatchFlag::MatchFixedString); |
| 240 | |
| 241 | if (item_style >= 0) { |
| 242 | m_ui->m_cmbStyles->setCurrentIndex(item_style); |
| 243 | } |
| 244 | |
| 245 | m_ui->m_checkForceAlternativePalette |
| 246 | ->setChecked(settings()->value(GROUP(GUI), SETTING(GUI::ForcedSkinColors)).toBool()); |
| 247 | |
| 248 | // Load skin. |
| 249 | const QString selected_skin = qApp->skins()->selectedSkinName(); |
| 250 | auto skins = qApp->skins()->installedSkins(); |
| 251 | |
| 252 | for (const Skin& skin : std::as_const(skins)) { |
| 253 | QTreeWidgetItem* new_item = |
| 254 | new QTreeWidgetItem({skin.m_visibleName, |
| 255 | skin.m_author, |
| 256 | skin.m_forcedStyles.isEmpty() ? QString() : skin.m_forcedStyles.join(QSL(", ")), |
| 257 | QString()}); |
| 258 | |
| 259 | new_item->setToolTip(0, |
| 260 | tr("%1\n\n" |
| 261 | "Version: %2\n" |
| 262 | "Description: %3") |
| 263 | .arg(skin.m_visibleName, |
| 264 | skin.m_version, |
| 265 | skin.m_description.isEmpty() ? QSL("-") : skin.m_description)); |
| 266 | |
| 267 | for (int i = 1; i < m_ui->m_treeSkins->columnCount(); i++) { |
| 268 | new_item->setToolTip(i, new_item->toolTip(0)); |
| 269 | } |
| 270 | |
| 271 | if (skin.m_forcedStyles.isEmpty()) { |
| 272 | new_item->setIcon(2, qApp->icons()->fromTheme(QSL("dialog-cancel"), QSL("gtk-cancel"))); |
| 273 | } |
| 274 | |
| 275 | new_item->setIcon(3, |
| 276 | skin.m_forcedSkinColors ? qApp->icons()->fromTheme(QSL("dialog-yes"), QSL("dialog-ok")) |
| 277 | : qApp->icons()->fromTheme(QSL("dialog-cancel"), QSL("gtk-cancel"))); |
| 278 | |
| 279 | new_item->setData(0, Qt::UserRole, QVariant::fromValue(skin)); |
| 280 | |
| 281 | // Add this skin and mark it as active if its active now. |
| 282 | m_ui->m_treeSkins->addTopLevelItem(new_item); |
| 283 | |
| 284 | if (skin.m_baseName == selected_skin) { |
| 285 | m_ui->m_treeSkins->setCurrentItem(new_item); |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | if (m_ui->m_treeSkins->currentItem() == nullptr && m_ui->m_treeSkins->topLevelItemCount() > 0) { |
| 290 | // Currently active skin is NOT available, select another one as selected |
| 291 | // if possible. |
| 292 | m_ui->m_treeSkins->setCurrentItem(m_ui->m_treeSkins->topLevelItem(0)); |
| 293 | } |
| 294 | |
| 295 | // Load tab settings. |
| 296 | m_ui->m_checkCloseTabsMiddleClick |
| 297 | ->setChecked(settings()->value(GROUP(GUI), SETTING(GUI::TabCloseMiddleClick)).toBool()); |
| 298 | m_ui->m_checkCloseTabsDoubleClick |
| 299 | ->setChecked(settings()->value(GROUP(GUI), SETTING(GUI::TabCloseDoubleClick)).toBool()); |
| 300 | m_ui->m_checkNewTabDoubleClick->setChecked(settings()->value(GROUP(GUI), SETTING(GUI::TabNewDoubleClick)).toBool()); |
| 301 | m_ui->m_checkHideTabBarIfOneTabVisible |
| 302 | ->setChecked(settings()->value(GROUP(GUI), SETTING(GUI::HideTabBarIfOnlyOneTab)).toBool()); |
| 303 | |
| 304 | // Load toolbar button style. |
| 305 | m_ui->m_spinToolbarIconSize->setValue(settings()->value(GROUP(GUI), SETTING(GUI::ToolbarIconSize)).toInt()); |
| 306 | m_ui->m_cmbToolbarButtonStyle->addItem(tr("Icon only"), Qt::ToolButtonStyle::ToolButtonIconOnly); |
| 307 | m_ui->m_cmbToolbarButtonStyle->addItem(tr("Text only"), Qt::ToolButtonStyle::ToolButtonTextOnly); |
| 308 | m_ui->m_cmbToolbarButtonStyle->addItem(tr("Text beside icon"), Qt::ToolButtonStyle::ToolButtonTextBesideIcon); |
| 309 | m_ui->m_cmbToolbarButtonStyle->addItem(tr("Text under icon"), Qt::ToolButtonStyle::ToolButtonTextUnderIcon); |
| 310 | m_ui->m_cmbToolbarButtonStyle->addItem(tr("Follow OS style"), Qt::ToolButtonStyle::ToolButtonFollowStyle); |
| 311 | m_ui->m_cmbToolbarButtonStyle |
| 312 | ->setCurrentIndex(m_ui->m_cmbToolbarButtonStyle |
| 313 | ->findData(settings()->value(GROUP(GUI), SETTING(GUI::ToolbarStyle)).toInt())); |
| 314 | |
| 315 | // Load toolbars. |
| 316 | m_ui->m_editorFeedsToolbar->loadFromToolBar(qApp->mainForm()->tabWidget()->feedMessageViewer()->feedsToolBar()); |
| 317 | m_ui->m_editorMessagesToolbar->loadFromToolBar(qApp->mainForm()->tabWidget()->feedMessageViewer()->messagesToolBar()); |
| 318 | m_ui->m_editorStatusbar->loadFromToolBar(qApp->mainForm()->statusBar()); |
| 319 | |
| 320 | // Load custom colors. |
| 321 | m_ui->m_gbCustomSkinColors |
| 322 | ->setChecked(settings()->value(GROUP(CustomSkinColors), SETTING(CustomSkinColors::Enabled)).toBool()); |
| 323 | |
| 324 | const QMetaObject& mo = SkinEnums::staticMetaObject; |
| 325 | QMetaEnum enumer = mo.enumerator(mo.indexOfEnumerator(QSL("PaletteColors").toLocal8Bit().constData())); |
| 326 | |
| 327 | for (int i = 0, row = 0; i < enumer.keyCount(); i++, row++) { |
| 328 | SkinEnums::PaletteColors pal = SkinEnums::PaletteColors(enumer.value(i)); |
| 329 | |
| 330 | auto* clr_btn = new ColorToolButton(this); |
| 331 | auto* rst_btn = new PlainToolButton(this); |
| 332 | |
| 333 | rst_btn->setToolTip(tr("Fetch color from activated skin")); |
| 334 | rst_btn->setIcon(qApp->icons()->fromTheme(QSL("edit-reset"))); |
| 335 | |
| 336 | QColor clr = settings()->value(GROUP(CustomSkinColors), enumer.key(i)).toString(); |
| 337 | |
| 338 | if (!clr.isValid()) { |
| 339 | clr = qApp->skins()->colorForModel(pal).value<QColor>(); |
| 340 | } |
| 341 | |
| 342 | rst_btn->setObjectName(QString::number(enumer.value(i))); |
| 343 | |
| 344 | connect(rst_btn, &PlainToolButton::clicked, this, &SettingsGui::resetCustomSkinColor); |
| 345 | connect(clr_btn, &ColorToolButton::colorChanged, this, &SettingsGui::dirtifySettings); |
| 346 | |
| 347 | clr_btn->setObjectName(QString::number(enumer.value(i))); |
| 348 | clr_btn->setColor(clr); |
| 349 | |
| 350 | auto* lay = new QHBoxLayout(); |
| 351 | |
| 352 | lay->addWidget(clr_btn); |
| 353 | lay->addWidget(rst_btn); |
| 354 | |
| 355 | m_ui->m_layoutCustomColors |
| 356 | ->setWidget(row, |
| 357 | QFormLayout::ItemRole::LabelRole, |
| 358 | new QLabel(TextFactory:: |
| 359 | capitalizeFirstLetter(SkinEnums:: |
| 360 | palleteColorText(SkinEnums::PaletteColors(enumer.value(i)))), |
| 361 | this)); |
| 362 | m_ui->m_layoutCustomColors->setLayout(row, QFormLayout::ItemRole::FieldRole, lay); |
| 363 | } |
| 364 | |
| 365 | onEndLoadSettings(); |
| 366 | } |
| 367 | |
| 368 | void SettingsGui::resetCustomSkinColor() { |
| 369 | auto* clr_btn = m_ui->m_gbCustomSkinColors->findChild<ColorToolButton*>(sender()->objectName()); |
| 370 | SkinEnums::PaletteColors pal = SkinEnums::PaletteColors(sender()->objectName().toInt()); |
| 371 | |
| 372 | clr_btn->setColor(qApp->skins()->colorForModel(pal, true).value<QColor>()); |
| 373 | } |
| 374 | |
| 375 | void SettingsGui::saveSettings() { |
| 376 | onBeginSaveSettings(); |
| 377 | |
| 378 | settings()->setValue(GROUP(GUI), GUI::FontAntialiasing, m_ui->m_checkFontAntialiasing->isChecked()); |
| 379 | |
| 380 | // Save custom skin colors. |
| 381 | settings()->setValue(GROUP(CustomSkinColors), CustomSkinColors::Enabled, m_ui->m_gbCustomSkinColors->isChecked()); |
| 382 | |
| 383 | const QMetaObject& mo = SkinEnums::staticMetaObject; |
| 384 | QMetaEnum enumer = mo.enumerator(mo.indexOfEnumerator(QSL("PaletteColors").toLocal8Bit().constData())); |
| 385 | auto children = m_ui->m_gbCustomSkinColors->findChildren<ColorToolButton*>(); |
| 386 | |
| 387 | for (const ColorToolButton* clr : children) { |
| 388 | settings()->setValue(GROUP(CustomSkinColors), enumer.valueToKey(clr->objectName().toInt()), clr->color().name()); |
| 389 | } |
| 390 | |
| 391 | // Save toolbar. |
| 392 | settings()->setValue(GROUP(GUI), GUI::ToolbarIconSize, m_ui->m_spinToolbarIconSize->value()); |
| 393 | settings()->setValue(GROUP(GUI), |
| 394 | GUI::ToolbarStyle, |
| 395 | m_ui->m_cmbToolbarButtonStyle->itemData(m_ui->m_cmbToolbarButtonStyle->currentIndex())); |
| 396 | |
| 397 | // Save tray icon. |
| 398 | if (SystemTrayIcon::isSystemTrayAreaAvailable()) { |
| 399 | settings()->setValue(GROUP(GUI), GUI::UseTrayIcon, m_ui->m_grpTray->isChecked()); |
| 400 | |
| 401 | if (m_ui->m_grpTray->isChecked()) { |
| 402 | qApp->showTrayIcon(); |
| 403 | } |
| 404 | else { |
| 405 | qApp->deleteTrayIcon(); |
| 406 | } |
| 407 | } |
| 408 | settings()->setValue(GROUP(GUI), GUI::MonochromeTrayIcon, m_ui->m_checkMonochromeIcons->isChecked()); |
| 409 | settings()->setValue(GROUP(GUI), GUI::ColoredBusyTrayIcon, m_ui->m_checkColoredIconsWhenArticles->isChecked()); |
| 410 | settings()->setValue(GROUP(GUI), GUI::UnreadNumbersInTrayIcon, m_ui->m_checkCountUnreadMessages->isChecked()); |
| 411 | settings()->setValue(GROUP(GUI), GUI::MainWindowStartsHidden, m_ui->m_checkHidden->isChecked()); |
| 412 | settings()->setValue(GROUP(GUI), GUI::HideMainWindowWhenMinimized, m_ui->m_checkHideWhenMinimized->isChecked()); |
| 413 | |
| 414 | #if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)) || defined(Q_OS_WIN) |
| 415 | settings()->setValue(GROUP(GUI), |
| 416 | GUI::UnreadNumbersOnTaskBar, |
| 417 | m_ui->m_displayUnreadMessageCountOnTaskBar->isChecked()); |
| 418 | #endif |
| 419 | |
| 420 | // Make sure that number of unread messages is shown in tray icon as requested. |
| 421 | qApp->feedReader()->feedsModel()->notifyWithCounts(); |
| 422 | |
| 423 | // Save selected icon theme. |
| 424 | QString selected_icon_theme = m_ui->m_cmbIconTheme->itemData(m_ui->m_cmbIconTheme->currentIndex()).toString(); |
| 425 | QString original_icon_theme = qApp->icons()->currentIconTheme(); |
| 426 | |
| 427 | qApp->icons()->setCurrentIconTheme(selected_icon_theme); |
| 428 | |
| 429 | // Check if icon theme was changed. |
| 430 | if (selected_icon_theme != original_icon_theme) { |
| 431 | requireRestart(); |
| 432 | } |
| 433 | |
| 434 | // Save and activate new skin. |
| 435 | if (!m_ui->m_treeSkins->selectedItems().isEmpty()) { |
| 436 | const Skin active_skin = m_ui->m_treeSkins->currentItem()->data(0, Qt::ItemDataRole::UserRole).value<Skin>(); |
| 437 | |
| 438 | if (qApp->skins()->selectedSkinName() != active_skin.m_baseName) { |
| 439 | qApp->skins()->setCurrentSkinName(active_skin.m_baseName); |
| 440 | requireRestart(); |
| 441 | } |
| 442 | } |
| 443 | |
| 444 | // Set new style. |
| 445 | if (m_ui->m_cmbStyles->currentIndex() >= 0 && m_ui->m_cmbStyles->isEnabled()) { |
| 446 | const QString new_style = m_ui->m_cmbStyles->currentData().toString(); |
| 447 | const QString old_style = qApp->settings()->value(GROUP(GUI), SETTING(GUI::Style)).toString(); |
| 448 | |
| 449 | if (old_style != new_style) { |
| 450 | requireRestart(); |
| 451 | } |
| 452 | |
| 453 | qApp->settings()->setValue(GROUP(GUI), GUI::Style, new_style); |
| 454 | } |
| 455 | |
| 456 | if (m_ui->m_checkForceAlternativePalette->isEnabled()) { |
| 457 | settings()->setValue(GROUP(GUI), GUI::ForcedSkinColors, m_ui->m_checkForceAlternativePalette->isChecked()); |
| 458 | } |
| 459 | |
| 460 | // Save tab settings. |
| 461 | settings()->setValue(GROUP(GUI), GUI::TabCloseMiddleClick, m_ui->m_checkCloseTabsMiddleClick->isChecked()); |
| 462 | settings()->setValue(GROUP(GUI), GUI::TabCloseDoubleClick, m_ui->m_checkCloseTabsDoubleClick->isChecked()); |
| 463 | settings()->setValue(GROUP(GUI), GUI::TabNewDoubleClick, m_ui->m_checkNewTabDoubleClick->isChecked()); |
| 464 | settings()->setValue(GROUP(GUI), GUI::HideTabBarIfOnlyOneTab, m_ui->m_checkHideTabBarIfOneTabVisible->isChecked()); |
| 465 | |
| 466 | m_ui->m_editorFeedsToolbar->saveToolBar(); |
| 467 | m_ui->m_editorMessagesToolbar->saveToolBar(); |
| 468 | m_ui->m_editorStatusbar->saveToolBar(); |
| 469 | |
| 470 | qApp->mainForm()->tabWidget()->updateAppearance(); |
| 471 | qApp->mainForm()->tabWidget()->checkCornerButtonVisibility(); |
| 472 | |
| 473 | qApp->mainForm()->tabWidget()->feedMessageViewer()->normalizeToolbarHeights(); |
| 474 | qApp->mainForm()->tabWidget()->feedMessageViewer()->refreshVisualProperties(); |
| 475 | |
| 476 | qApp->feedReader()->feedsModel()->reloadWholeLayout(); |
| 477 | qApp->feedReader()->messagesModel()->setupIcons(); |
| 478 | qApp->feedReader()->messagesModel()->reloadWholeLayout(); |
| 479 | |
| 480 | onEndSaveSettings(); |
| 481 | } |