From bcf824dce2558e9a01455b284055f93a6dc35ef0 Mon Sep 17 00:00:00 2001 From: David Rosca Date: Wed, 8 Feb 2017 10:13:41 +0100 Subject: [PATCH] Preferences: Allow to reorder spellcheck languages See #2195 --- src/lib/preferences/preferences.cpp | 27 ++++++++++++++++++++------- src/lib/preferences/preferences.ui | 10 ++++++++-- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/src/lib/preferences/preferences.cpp b/src/lib/preferences/preferences.cpp index d82662308..46fa16b80 100644 --- a/src/lib/preferences/preferences.cpp +++ b/src/lib/preferences/preferences.cpp @@ -436,19 +436,29 @@ Preferences::Preferences(BrowserWindow* window) const QStringList files = dir.entryList({QSL("*.bdic")}); for (const QString &file : files) { const QString lang = file.left(file.size() - 5); - if (!ui->spellcheckLanguages->findItems(lang, Qt::MatchExactly).isEmpty()) { + const QString langName = createLanguageItem(lang); + if (!ui->spellcheckLanguages->findItems(langName, Qt::MatchExactly).isEmpty()) { continue; } QListWidgetItem *item = new QListWidgetItem; - item->setText(createLanguageItem(lang)); + item->setText(langName); item->setData(Qt::UserRole, lang); ui->spellcheckLanguages->addItem(item); - if (spellcheckLanguages.contains(lang)) { - ui->spellcheckLanguages->setCurrentItem(item, QItemSelectionModel::Select); - } } } + int topIndex = 0; + for (const QString &lang : spellcheckLanguages) { + const auto items = ui->spellcheckLanguages->findItems(createLanguageItem(lang), Qt::MatchExactly); + if (items.isEmpty()) { + continue; + } + QListWidgetItem *item = items.at(0); + ui->spellcheckLanguages->takeItem(ui->spellcheckLanguages->row(item)); + ui->spellcheckLanguages->insertItem(topIndex++, item); + ui->spellcheckLanguages->setCurrentItem(item, QItemSelectionModel::Select); + } + if (ui->spellcheckLanguages->count() == 0) { ui->spellcheckLanguages->hide(); } else { @@ -1003,8 +1013,11 @@ void Preferences::saveSettings() settings.beginGroup(QSL("SpellCheck")); settings.setValue("Enabled", ui->spellcheckEnabled->isChecked()); QStringList languages; - for (QListWidgetItem *item : ui->spellcheckLanguages->selectedItems()) { - languages.append(item->data(Qt::UserRole).toString()); + for (int i = 0; i < ui->spellcheckLanguages->count(); ++i) { + QListWidgetItem *item = ui->spellcheckLanguages->item(i); + if (item->isSelected()) { + languages.append(item->data(Qt::UserRole).toString()); + } } settings.setValue("Languages", languages); settings.endGroup(); diff --git a/src/lib/preferences/preferences.ui b/src/lib/preferences/preferences.ui index f2d3df085..4f5609f27 100644 --- a/src/lib/preferences/preferences.ui +++ b/src/lib/preferences/preferences.ui @@ -2424,8 +2424,8 @@ 0 0 - 96 - 28 + 560 + 80 @@ -2444,6 +2444,12 @@ 100 + + true + + + QAbstractItemView::InternalMove + QAbstractItemView::MultiSelection