Add function for assigning a settings category name with retranslation

The function is still experimental as there's likely a better way to
implement this.
This commit is contained in:
Martchus 2023-07-02 23:54:14 +02:00
parent f69ffec06c
commit 0392b27b97
2 changed files with 18 additions and 0 deletions

View File

@ -155,6 +155,21 @@ void SettingsDialog::showCategory(OptionCategory *category)
updateTabWidget();
}
/*!
* \brief Allows to set the \a categories display name so that it is retranslated as needed.
* \remarks
* - The specified \a translator is supposed to return the display name to assign to \a category for the current
* locale. The \a translator is called immediately for the initial assignment and on language change events.
* - This function is experimental and might change or be removed completely in the next minor release.
*/
void SettingsDialog::translateCategory(OptionCategory *category, const std::function<QString ()> &translator)
{
category->setDisplayName(translator());
connect(this, &SettingsDialog::retranslationRequired, category, [category, translator = std::move(translator)] {
category->setDisplayName(translator());
});
}
/*!
* \brief Enables *single-category mode* to show only the specified \a
* singleCategory.
@ -339,6 +354,7 @@ bool SettingsDialog::event(QEvent *event)
break;
case QEvent::LanguageChange:
m_ui->retranslateUi(this);
emit retranslationRequired();
break;
default:;
}

View File

@ -31,6 +31,7 @@ public:
OptionCategory *category(int categoryIndex) const;
OptionPage *page(int categoryIndex, int pageIndex) const;
void showCategory(OptionCategory *category);
void translateCategory(OptionCategory *category, const std::function<QString()> &translator);
void setSingleCategory(OptionCategory *singleCategory);
QWidget *cornerWidget(Qt::Corner corner = Qt::TopRightCorner) const;
void setCornerWidget(QWidget *widget, Qt::Corner corner = Qt::TopRightCorner);
@ -44,6 +45,7 @@ public Q_SLOTS:
Q_SIGNALS:
void applied();
void resetted();
void retranslationRequired();
protected:
bool event(QEvent *event) override;