1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 18:56:34 +01:00

Preferences: Allow to reorder spellcheck languages

See #2195
This commit is contained in:
David Rosca 2017-02-08 10:13:41 +01:00
parent 6e2d8d8fe7
commit bcf824dce2
2 changed files with 28 additions and 9 deletions

View File

@ -436,18 +436,28 @@ Preferences::Preferences(BrowserWindow* window)
const QStringList files = dir.entryList({QSL("*.bdic")}); const QStringList files = dir.entryList({QSL("*.bdic")});
for (const QString &file : files) { for (const QString &file : files) {
const QString lang = file.left(file.size() - 5); 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; continue;
} }
QListWidgetItem *item = new QListWidgetItem; QListWidgetItem *item = new QListWidgetItem;
item->setText(createLanguageItem(lang)); item->setText(langName);
item->setData(Qt::UserRole, lang); item->setData(Qt::UserRole, lang);
ui->spellcheckLanguages->addItem(item); ui->spellcheckLanguages->addItem(item);
if (spellcheckLanguages.contains(lang)) { }
}
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); ui->spellcheckLanguages->setCurrentItem(item, QItemSelectionModel::Select);
} }
}
}
if (ui->spellcheckLanguages->count() == 0) { if (ui->spellcheckLanguages->count() == 0) {
ui->spellcheckLanguages->hide(); ui->spellcheckLanguages->hide();
@ -1003,9 +1013,12 @@ void Preferences::saveSettings()
settings.beginGroup(QSL("SpellCheck")); settings.beginGroup(QSL("SpellCheck"));
settings.setValue("Enabled", ui->spellcheckEnabled->isChecked()); settings.setValue("Enabled", ui->spellcheckEnabled->isChecked());
QStringList languages; QStringList languages;
for (QListWidgetItem *item : ui->spellcheckLanguages->selectedItems()) { 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()); languages.append(item->data(Qt::UserRole).toString());
} }
}
settings.setValue("Languages", languages); settings.setValue("Languages", languages);
settings.endGroup(); settings.endGroup();
#endif #endif

View File

@ -2424,8 +2424,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>96</width> <width>560</width>
<height>28</height> <height>80</height>
</rect> </rect>
</property> </property>
<layout class="QHBoxLayout" name="horizontalLayout_14"> <layout class="QHBoxLayout" name="horizontalLayout_14">
@ -2444,6 +2444,12 @@
<height>100</height> <height>100</height>
</size> </size>
</property> </property>
<property name="dragEnabled">
<bool>true</bool>
</property>
<property name="dragDropMode">
<enum>QAbstractItemView::InternalMove</enum>
</property>
<property name="selectionMode"> <property name="selectionMode">
<enum>QAbstractItemView::MultiSelection</enum> <enum>QAbstractItemView::MultiSelection</enum>
</property> </property>