diff --git a/src/mkvtoolnix-gui/chapter_editor/chapter_model.cpp b/src/mkvtoolnix-gui/chapter_editor/chapter_model.cpp index 240840fc8..0cc648711 100644 --- a/src/mkvtoolnix-gui/chapter_editor/chapter_model.cpp +++ b/src/mkvtoolnix-gui/chapter_editor/chapter_model.cpp @@ -181,8 +181,10 @@ ChapterModel::chapterNameForLanguage(KaxChapterAtom &chapter, if (!kDisplay) continue; - auto actualLanguage = FindChildValue(kDisplay, "eng"s); - if (language.empty() || (language == actualLanguage)) + auto actualLanguage = mtx::chapters::get_language_from_display(*kDisplay, "eng"s); + if ( language.empty() + || (language == actualLanguage.get_language()) + || (language == actualLanguage.get_iso639_2_code())) return Q(FindChildValue(kDisplay)); } diff --git a/src/mkvtoolnix-gui/chapter_editor/name_model.cpp b/src/mkvtoolnix-gui/chapter_editor/name_model.cpp index d60a9b1d7..203ec32d8 100644 --- a/src/mkvtoolnix-gui/chapter_editor/name_model.cpp +++ b/src/mkvtoolnix-gui/chapter_editor/name_model.cpp @@ -1,5 +1,6 @@ #include "common/common_pch.h" +#include "common/chapters/chapters.h" #include "common/ebml.h" #include "common/qt.h" #include "mkvtoolnix-gui/app.h" @@ -49,7 +50,7 @@ NameModel::setRowText(QList const &rowItems) { auto &display = *displayFromItem(rowItems[0]); rowItems[0]->setText(Q(GetChildValue(display))); - rowItems[1]->setText(App::descriptionFromIso639_2LanguageCode(Q(FindChildValue(display, "eng"s)))); + rowItems[1]->setText(Q(mtx::chapters::get_language_from_display(display, "eng"s).format_long())); rowItems[2]->setText(App::descriptionFromTopLevelDomainCountryCode(Q(FindChildValue(display, ""s)))); } @@ -82,7 +83,7 @@ NameModel::addNew() { auto display = new KaxChapterDisplay; GetChild(display).SetValueUTF8(Y("")); - GetChild(display).SetValue(to_utf8(cfg.m_defaultChapterLanguage)); + mtx::chapters::set_languages_in_display(*display, to_utf8(cfg.m_defaultChapterLanguage)); GetChild(display).SetValue(to_utf8(cfg.m_defaultChapterCountry)); m_chapter->PushElement(*display); diff --git a/src/mkvtoolnix-gui/chapter_editor/tab.cpp b/src/mkvtoolnix-gui/chapter_editor/tab.cpp index fbd9651d6..8c9976b08 100644 --- a/src/mkvtoolnix-gui/chapter_editor/tab.cpp +++ b/src/mkvtoolnix-gui/chapter_editor/tab.cpp @@ -115,16 +115,15 @@ Tab::setupUi() { p->ui->cbChNameCountry->view()->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); - p->ui->cbChNameLanguage->setup(); + p->ui->ldwChNameLanguage->enableClearingLanguage(true); p->ui->cbChNameCountry->setup(true); p->nameWidgets << p->ui->pbChRemoveName << p->ui->lChName << p->ui->leChName - << p->ui->lChNameLanguage << p->ui->cbChNameLanguage + << p->ui->lChNameLanguage << p->ui->ldwChNameLanguage << p->ui->lChNameCountry << p->ui->cbChNameCountry; Util::fixScrollAreaBackground(p->ui->scrollArea); - Util::fixComboBoxViewWidth(*p->ui->cbChNameLanguage); Util::fixComboBoxViewWidth(*p->ui->cbChNameCountry); Util::HeaderViewManager::create(*p->ui->elements, "ChapterEditor::Elements") .setDefaultSizes({ { Q("editionChapter"), 200 }, { Q("start"), 130 }, { Q("end"), 130 } }); Util::HeaderViewManager::create(*p->ui->tvChNames, "ChapterEditor::ChapterNames").setDefaultSizes({ { Q("name"), 200 }, { Q("language"), 150 } }); @@ -149,7 +148,7 @@ Tab::setupUi() { connect(p->ui->elements->selectionModel(), &QItemSelectionModel::selectionChanged, this, &Tab::chapterSelectionChanged); connect(p->ui->tvChNames->selectionModel(), &QItemSelectionModel::selectionChanged, this, &Tab::nameSelectionChanged); connect(p->ui->leChName, &QLineEdit::textEdited, this, &Tab::chapterNameEdited); - connect(p->ui->cbChNameLanguage, static_cast(&QComboBox::currentIndexChanged), this, &Tab::chapterNameLanguageChanged); + connect(p->ui->ldwChNameLanguage, &Util::LanguageDisplayWidget::languageChanged, this, &Tab::chapterNameLanguageChanged); connect(p->ui->cbChNameCountry, static_cast(&QComboBox::currentIndexChanged), this, &Tab::chapterNameCountryChanged); connect(p->ui->pbChAddName, &QPushButton::clicked, this, &Tab::addChapterName); connect(p->ui->pbChRemoveName, &QPushButton::clicked, this, &Tab::removeChapterName); @@ -168,7 +167,6 @@ Tab::setupUi() { connect(p->generateSubChaptersAction, &QAction::triggered, this, &Tab::generateSubChapters); connect(p->renumberSubChaptersAction, &QAction::triggered, this, &Tab::renumberSubChapters); - connect(mw, &MainWindow::preferencesChanged, p->ui->cbChNameLanguage, &Util::ComboBoxBase::reInitialize); connect(mw, &MainWindow::preferencesChanged, p->ui->cbChNameCountry, &Util::ComboBoxBase::reInitialize); for (auto &lineEdit : findChildren()) { @@ -1124,12 +1122,11 @@ Tab::setNameControlsFromStorage(QModelIndex const &idx) { if (!display) return false; - auto language = Q(FindChildValue(display, "eng"s)); + auto language = mtx::chapters::get_language_from_display(*display, "eng"s); p->ui->leChName->setText(Q(GetChildValue(display))); - p->ui->cbChNameLanguage->setAdditionalItems(usedNameLanguages()) - .reInitializeIfNecessary() - .setCurrentByData(language); + p->ui->ldwChNameLanguage->setAdditionalLanguages(usedNameLanguages()); + p->ui->ldwChNameLanguage->setLanguage(language); p->ui->cbChNameCountry->setAdditionalItems(usedNameCountryCodes()) .reInitializeIfNecessary() .setCurrentByData(Q(FindChildValue(display))); @@ -1182,14 +1179,11 @@ Tab::chapterNameEdited(QString const &text) { } void -Tab::chapterNameLanguageChanged(int index) { +Tab::chapterNameLanguageChanged(mtx::bcp47::language_c const &language) { auto p = p_func(); - if (0 > index) - return; - - withSelectedName([p, index](QModelIndex const &idx, KaxChapterDisplay &display) { - GetChild(display).SetValue(to_utf8(p->ui->cbChNameLanguage->itemData(index).toString())); + withSelectedName([p, &language](QModelIndex const &idx, KaxChapterDisplay &display) { + mtx::chapters::set_languages_in_display(display, language); p->nameModel->updateRow(idx.row()); }); } @@ -1306,7 +1300,7 @@ Tab::createEmptyChapter(int64_t startTime, if (!name.isEmpty()) { auto &display = GetChild(*chapter); GetChild(display).SetValue(to_wide(name)); - GetChild(display).SetValue(to_utf8(language ? *language : cfg.m_defaultChapterLanguage)); + mtx::chapters::set_languages_in_display(display, to_utf8(language ? *language : cfg.m_defaultChapterLanguage)); if ((country && !country->isEmpty()) || !cfg.m_defaultChapterCountry.isEmpty()) GetChild(display).SetValue(to_utf8((country && !country->isEmpty()) ? *country : cfg.m_defaultChapterCountry)); } @@ -1503,7 +1497,7 @@ Tab::setLanguages(QStandardItem *item, for (auto const &element : *chapter) { auto kDisplay = dynamic_cast(element); if (kDisplay) - GetChild(*kDisplay).SetValue(to_utf8(language)); + mtx::chapters::set_languages_in_display(*kDisplay, to_utf8(language)); } for (auto row = 0, numRows = item->rowCount(); row < numRows; ++row) @@ -1785,9 +1779,10 @@ Tab::changeChapterName(QModelIndex const &parentIdx, if (!kDisplay) continue; - auto language = FindChildValue(kDisplay, "eng"s); + auto language = mtx::chapters::get_language_from_display(*kDisplay, "eng"s); if ( (RenumberSubChaptersParametersDialog::NameMatch::All == nameMatchingMode) - || (Q(language) == languageOfNamesToReplace)) + || (Q(language.get_language()) == languageOfNamesToReplace) + || (Q(language.get_iso639_2_code()) == languageOfNamesToReplace)) GetChild(*kDisplay).SetValue(name); } @@ -2122,8 +2117,7 @@ Tab::usedNameLanguages(QStandardItem *rootItem) { if (!kDisplay) continue; - auto kLanguage = FindChild(*kDisplay); - names << (kLanguage ? Q(*kLanguage) : Q("eng")); + names << Q(mtx::chapters::get_language_from_display(*kDisplay, "eng"s).format()); } for (int row = 0, numRows = currentItem->rowCount(); row < numRows; ++row) diff --git a/src/mkvtoolnix-gui/chapter_editor/tab.h b/src/mkvtoolnix-gui/chapter_editor/tab.h index a8730e034..3e84880f4 100644 --- a/src/mkvtoolnix-gui/chapter_editor/tab.h +++ b/src/mkvtoolnix-gui/chapter_editor/tab.h @@ -18,6 +18,10 @@ namespace libebml { class EbmlBinary; } +namespace mtx::bcp47 { +class language_c; +} + namespace mtx::bluray::mpls { struct chapter_t; } @@ -113,7 +117,7 @@ public Q_SLOTS: virtual void nameSelectionChanged(QItemSelection const &selected, QItemSelection const &deselected); virtual void chapterNameEdited(QString const &text); - virtual void chapterNameLanguageChanged(int index); + virtual void chapterNameLanguageChanged(mtx::bcp47::language_c const &language); virtual void chapterNameCountryChanged(int index); virtual void addChapterName(); virtual void removeChapterName(); diff --git a/src/mkvtoolnix-gui/forms/chapter_editor/tab.ui b/src/mkvtoolnix-gui/forms/chapter_editor/tab.ui index 41912bff6..dc9df5d6e 100644 --- a/src/mkvtoolnix-gui/forms/chapter_editor/tab.ui +++ b/src/mkvtoolnix-gui/forms/chapter_editor/tab.ui @@ -466,15 +466,12 @@ - &Language: - - - cbChNameLanguage + Language: - + @@ -535,9 +532,9 @@
mkvtoolnix-gui/util/elide_label.h
- mtx::gui::Util::LanguageComboBox - QComboBox -
mkvtoolnix-gui/util/language_combo_box.h
+ mtx::gui::Util::LanguageDisplayWidget + QForm +
mkvtoolnix-gui/util/language_display_widget.h
mtx::gui::Util::CountryComboBox @@ -564,7 +561,7 @@ pbChAddName pbChRemoveName leChName - cbChNameLanguage + ldwChNameLanguage cbChNameCountry