From c9e162cf8a4409b046dd433d42229a03e3d13c07 Mon Sep 17 00:00:00 2001 From: Prince Gupta Date: Sun, 12 Jan 2020 16:44:58 +0530 Subject: [PATCH] Reorganize UI theme selection --- src/gui/advancedsettings.cpp | 12 ----- src/gui/advancedsettings.h | 4 +- src/gui/optionsdialog.cpp | 63 +++++++++--------------- src/gui/optionsdialog.h | 2 - src/gui/optionsdialog.ui | 92 +++++++++++++++++++----------------- 5 files changed, 71 insertions(+), 102 deletions(-) diff --git a/src/gui/advancedsettings.cpp b/src/gui/advancedsettings.cpp index 22defdc40..e796e7a88 100644 --- a/src/gui/advancedsettings.cpp +++ b/src/gui/advancedsettings.cpp @@ -82,10 +82,6 @@ enum AdvSettingsRows DOWNLOAD_TRACKER_FAVICON, SAVE_PATH_HISTORY_LENGTH, ENABLE_SPEED_WIDGET, -#if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)) - USE_ICON_THEME, -#endif - // libtorrent section LIBTORRENT_HEADER, ASYNC_IO_THREADS, @@ -252,10 +248,6 @@ void AdvancedSettings::saveAdvancedSettings() // Seed choking algorithm session->setSeedChokingAlgorithm(static_cast(m_comboBoxSeedChokingAlgorithm.currentIndex())); - // Icon theme -#if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)) - pref->useSystemIconTheme(m_checkBoxUseIconTheme.isChecked()); -#endif pref->setConfirmTorrentRecheck(m_checkBoxConfirmTorrentRecheck.isChecked()); pref->setConfirmRemoveAllTags(m_checkBoxConfirmRemoveAllTags.isChecked()); @@ -561,10 +553,6 @@ void AdvancedSettings::loadAdvancedSettings() addRow(SEED_CHOKING_ALGORITHM, (tr("Upload choking algorithm") + ' ' + makeLink("https://www.libtorrent.org/reference-Settings.html#seed_choking_algorithm", "(?)")) , &m_comboBoxSeedChokingAlgorithm); -#if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)) - m_checkBoxUseIconTheme.setChecked(pref->useSystemIconTheme()); - addRow(USE_ICON_THEME, tr("Use system icon theme"), &m_checkBoxUseIconTheme); -#endif // Torrent recheck confirmation m_checkBoxConfirmTorrentRecheck.setChecked(pref->confirmTorrentRecheck()); addRow(CONFIRM_RECHECK_TORRENT, tr("Confirm torrent recheck"), &m_checkBoxConfirmTorrentRecheck); diff --git a/src/gui/advancedsettings.h b/src/gui/advancedsettings.h index 1122b58b9..204e3838a 100644 --- a/src/gui/advancedsettings.h +++ b/src/gui/advancedsettings.h @@ -69,9 +69,7 @@ private: QLineEdit m_lineEditAnnounceIP; // OS dependent settings -#if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)) - QCheckBox m_checkBoxUseIconTheme; -#elif defined(Q_OS_WIN) +#if defined(Q_OS_WIN) QComboBox m_comboBoxOSMemoryPriority; #endif }; diff --git a/src/gui/optionsdialog.cpp b/src/gui/optionsdialog.cpp index 95cb6c604..22184d369 100644 --- a/src/gui/optionsdialog.cpp +++ b/src/gui/optionsdialog.cpp @@ -175,7 +175,17 @@ OptionsDialog::OptionsDialog(QWidget *parent) // Languages supported initializeLanguageCombo(); - initializeThemeCombo(); + m_ui->checkUseCustomTheme->setChecked(Preferences::instance()->useCustomUITheme()); + m_ui->customThemeFilePath->setSelectedPath(Preferences::instance()->customUIThemePath()); + m_ui->customThemeFilePath->setMode(FileSystemPathEdit::Mode::FileOpen); + m_ui->customThemeFilePath->setDialogCaption(tr("Select qBittorrent UI Theme file")); + m_ui->customThemeFilePath->setFileNameFilter(tr("qBittorrent UI Theme file (*.qbtheme)")); + +#if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)) + m_ui->checkUseSystemIcon->setChecked(Preferences::instance()->useSystemIconTheme()); +#else + m_ui->checkUseSystemIcon->setVisible(false); +#endif // Load week days (scheduler) m_ui->comboBoxScheduleDays->addItems(translatedWeekdayNames()); @@ -218,7 +228,11 @@ OptionsDialog::OptionsDialog(QWidget *parent) // Apply button is activated when a value is changed // Behavior tab connect(m_ui->comboI18n, qComboBoxCurrentIndexChanged, this, &ThisType::enableApplyButton); - connect(m_ui->comboTheme, qComboBoxCurrentIndexChanged, this, &ThisType::enableApplyButton); + connect(m_ui->checkUseCustomTheme, &QGroupBox::toggled, this, &ThisType::enableApplyButton); + connect(m_ui->customThemeFilePath, &FileSystemPathEdit::selectedPathChanged, this, &ThisType::enableApplyButton); +#if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)) + connect(m_ui->checkUseSystemIcon, &QAbstractButton::toggled, this, &ThisType::enableApplyButton); +#endif connect(m_ui->confirmDeletion, &QAbstractButton::toggled, this, &ThisType::enableApplyButton); connect(m_ui->checkAltRowColors, &QAbstractButton::toggled, this, &ThisType::enableApplyButton); connect(m_ui->checkHideZero, &QAbstractButton::toggled, this, &ThisType::enableApplyButton); @@ -496,38 +510,6 @@ void OptionsDialog::initializeLanguageCombo() } } -void OptionsDialog::initializeThemeCombo() -{ - m_ui->comboTheme->addItem(tr("Default")); - const QString customUIThemePath = Preferences::instance()->customUIThemePath(); - if (!customUIThemePath.isEmpty()) - m_ui->comboTheme->addItem(Utils::Fs::toNativePath(customUIThemePath)); - m_ui->comboTheme->insertSeparator(m_ui->comboTheme->count()); - m_ui->comboTheme->addItem(tr("Select...")); - m_ui->comboTheme->setCurrentIndex(Preferences::instance()->useCustomUITheme() ? 1 : 0); - - connect(m_ui->comboTheme, qOverload(&QComboBox::currentIndexChanged), this, [this](const int index) - { - if (index != (m_ui->comboTheme->count() - 1)) - return; - - m_uiThemeFilePath = QFileDialog::getOpenFileName(this, tr("Select qBittorrent theme file"), {}, tr("qBittorrent Theme File (*.qbtheme)")); - m_ui->comboTheme->blockSignals(true); - if (!m_uiThemeFilePath.isEmpty()) { - if (m_ui->comboTheme->count() == 3) - m_ui->comboTheme->insertItem(1, Utils::Fs::toNativePath(m_uiThemeFilePath)); - else - m_ui->comboTheme->setItemText(1, Utils::Fs::toNativePath(m_uiThemeFilePath)); - m_ui->comboTheme->setCurrentIndex(1); - } - else { - // don't leave "Select..." as current text - m_ui->comboTheme->setCurrentIndex(Preferences::instance()->useCustomUITheme() ? 1 : 0); - } - m_ui->comboTheme->blockSignals(false); - }); -} - // Main destructor OptionsDialog::~OptionsDialog() { @@ -599,13 +581,12 @@ void OptionsDialog::saveOptions() // Behavior preferences pref->setLocale(locale); - if (!m_uiThemeFilePath.isEmpty() - && (m_ui->comboTheme->currentIndex() == 1)) { - // only change if current selection is still new m_uiThemeFilePath - pref->setCustomUIThemePath(m_uiThemeFilePath); - m_uiThemeFilePath.clear(); - } - pref->setUseCustomUITheme(m_ui->comboTheme->currentIndex() == 1); + pref->setUseCustomUITheme(m_ui->checkUseCustomTheme->isChecked()); + pref->setCustomUIThemePath(m_ui->customThemeFilePath->selectedPath()); + +#if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)) + pref->useSystemIconTheme(m_ui->checkUseSystemIcon->isChecked()); +#endif pref->setConfirmTorrentDeletion(m_ui->confirmDeletion->isChecked()); pref->setAlternatingRowColors(m_ui->checkAltRowColors->isChecked()); diff --git a/src/gui/optionsdialog.h b/src/gui/optionsdialog.h index 14fc61c07..167083430 100644 --- a/src/gui/optionsdialog.h +++ b/src/gui/optionsdialog.h @@ -117,7 +117,6 @@ private: void saveOptions(); void loadOptions(); void initializeLanguageCombo(); - void initializeThemeCombo(); static QString languageToLocalizedString(const QLocale &locale); // General options QString getLocale() const; @@ -184,7 +183,6 @@ private: AdvancedSettings *m_advancedSettings; QList m_addedScanDirs; QList m_removedScanDirs; - QString m_uiThemeFilePath; }; #endif // OPTIONSDIALOG_H diff --git a/src/gui/optionsdialog.ui b/src/gui/optionsdialog.ui index 3ede266bf..892dbc31e 100644 --- a/src/gui/optionsdialog.ui +++ b/src/gui/optionsdialog.ui @@ -133,45 +133,29 @@ Interface - - - - Language: - - - - - - - - 0 - 0 - - - - QComboBox::AdjustToContents - - - 0 - - - - - - - - true - - - - (Requires restart) + + + + Use custom UI Theme - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + true + + + + + UI Theme file: + + + + + + + - + Qt::Horizontal @@ -185,27 +169,44 @@ - + - Theme: + Language: + + + + + + + Use system icon theme - + + + + 0 + 0 + + + + QComboBox::AdjustToContents + + + 0 + + - - + + true - (Requires restart) - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + Changing Interface settings requires application restart @@ -3244,6 +3245,9 @@ Use ';' to split multiple entries. Can use wildcard '*'. tabOption comboI18n + checkUseSystemIcon + checkUseCustomTheme + customThemeFilePath checkStartPaused spinPort checkUPnP