diff --git a/qt/OpenRGBDialog/OpenRGBDialog.cpp b/qt/OpenRGBDialog/OpenRGBDialog.cpp index 9ea23df5..b6cad235 100644 --- a/qt/OpenRGBDialog/OpenRGBDialog.cpp +++ b/qt/OpenRGBDialog/OpenRGBDialog.cpp @@ -711,7 +711,7 @@ void OpenRGBDialog::AddPluginsPage() /*-----------------------------------------------------*\ | Create the tab label | \*-----------------------------------------------------*/ - TabLabel* PluginTabLabel = new TabLabel(OpenRGBFont::extension, tr("Plugins"), (char *)"Plugins", (char *)context); + TabLabel* PluginTabLabel = new TabLabel(OpenRGBFont::extension, (char *)"Plugins", (char *)context, true); ui->SettingsTabBar->tabBar()->setTabButton(ui->SettingsTabBar->tabBar()->count() - 1, QTabBar::LeftSide, PluginTabLabel); } @@ -728,7 +728,7 @@ void OpenRGBDialog::AddSoftwareInfoPage() /*-----------------------------------------------------*\ | Create the tab label | \*-----------------------------------------------------*/ - TabLabel* SoftwareTabLabel = new TabLabel(OpenRGBFont::info, tr("About OpenRGB"), (char *)"About OpenRGB", (char *)context); + TabLabel* SoftwareTabLabel = new TabLabel(OpenRGBFont::info, (char *)"About OpenRGB", (char *)context, true); ui->InformationTabBar->tabBar()->setTabButton(ui->InformationTabBar->tabBar()->count() - 1, QTabBar::LeftSide, SoftwareTabLabel); } @@ -745,7 +745,7 @@ void OpenRGBDialog::AddSupportedDevicesPage() /*-----------------------------------------------------*\ | Create the tab label | \*-----------------------------------------------------*/ - TabLabel* SupportedTabLabel = new TabLabel(OpenRGBFont::controller, tr("Supported Devices"), (char *)"Supported Devices", (char *)context); + TabLabel* SupportedTabLabel = new TabLabel(OpenRGBFont::controller, (char *)"Supported Devices", (char *)context, true); ui->SettingsTabBar->tabBar()->setTabButton(ui->SettingsTabBar->tabBar()->count() - 1, QTabBar::LeftSide, SupportedTabLabel); } @@ -762,7 +762,7 @@ void OpenRGBDialog::AddSettingsPage() /*-----------------------------------------------------*\ | Create the tab label | \*-----------------------------------------------------*/ - TabLabel* SettingsTabLabel = new TabLabel(OpenRGBFont::options, tr("General Settings"), (char *)"General Settings", (char *)context); + TabLabel* SettingsTabLabel = new TabLabel(OpenRGBFont::options, (char *)"General Settings", (char *)context, true); ui->SettingsTabBar->tabBar()->setTabButton(ui->SettingsTabBar->tabBar()->count() - 1, QTabBar::LeftSide, SettingsTabLabel); @@ -785,7 +785,7 @@ void OpenRGBDialog::AddManualDevicesSettingsPage() /*-----------------------------------------------------*\ | Create the tab label | \*-----------------------------------------------------*/ - TabLabel* SettingsTabLabel = new TabLabel(OpenRGBFont::bulb, tr("Manually Added Devices"), (char *)"Manually Added Devices", (char *)context); + TabLabel* SettingsTabLabel = new TabLabel(OpenRGBFont::bulb, (char *)"Manually Added Devices", (char *)context, true); ui->SettingsTabBar->tabBar()->setTabButton(ui->SettingsTabBar->tabBar()->count() - 1, QTabBar::LeftSide, SettingsTabLabel); } @@ -795,7 +795,7 @@ void OpenRGBDialog::AddPlugin(OpenRGBPluginEntry* plugin) /*-----------------------------------------------------*\ | Create the tab label | \*-----------------------------------------------------*/ - TabLabel* PluginTabLabel = new TabLabel(OpenRGBFont::extension, QString::fromStdString(plugin->info.Label), (char *)plugin->info.Label.c_str(), (char *)context); + TabLabel* PluginTabLabel = new TabLabel(OpenRGBFont::extension, (char *)plugin->info.Label.c_str(), (char *)context, false); /*-----------------------------------------------------*\ | Place plugin as its own top level tab | @@ -948,7 +948,7 @@ void OpenRGBDialog::AddI2CToolsPage() /*-----------------------------------------------------*\ | Create the tab label | \*-----------------------------------------------------*/ - TabLabel* SMBusToolsTabLabel = new TabLabel(OpenRGBFont::toolbox, tr("SMBus Tools"), (char *)"SMBus Tools", (char *)context); + TabLabel* SMBusToolsTabLabel = new TabLabel(OpenRGBFont::toolbox, (char *)"SMBus Tools", (char *)context, true); ui->InformationTabBar->tabBar()->setTabButton(ui->InformationTabBar->tabBar()->count() - 1, QTabBar::LeftSide, SMBusToolsTabLabel); } @@ -1062,7 +1062,7 @@ void OpenRGBDialog::UpdateDevicesList() /*---------------------------------------------*\ | Create the tab label | \*---------------------------------------------*/ - TabLabel* NewTabLabel = new TabLabel(GetIcon(controllers[controller_idx]->type), QString::fromStdString(controllers[controller_idx]->GetName()), (char *)controllers[controller_idx]->GetName().c_str(), (char *)context); + TabLabel* NewTabLabel = new TabLabel(GetIcon(controllers[controller_idx]->type), (char *)controllers[controller_idx]->GetName().c_str(), (char *)context, false); ui->DevicesTabBar->tabBar()->setTabButton(ui->DevicesTabBar->count() - 1, QTabBar::LeftSide, NewTabLabel); ui->DevicesTabBar->tabBar()->setTabToolTip(ui->DevicesTabBar->count() - 1, QString::fromStdString(controllers[controller_idx]->GetName())); @@ -1115,7 +1115,7 @@ void OpenRGBDialog::UpdateDevicesList() /*---------------------------------------------*\ | Create the tab label | \*---------------------------------------------*/ - TabLabel* NewTabLabel = new TabLabel(GetIcon(controllers[controller_idx]->type), QString::fromStdString(controllers[controller_idx]->GetName()), (char *)controllers[controller_idx]->GetName().c_str(), (char *)context); + TabLabel* NewTabLabel = new TabLabel(GetIcon(controllers[controller_idx]->type), (char *)controllers[controller_idx]->GetName().c_str(), (char *)context, false); ui->InformationTabBar->tabBar()->setTabButton(ui->InformationTabBar->count() - 1, QTabBar::LeftSide, NewTabLabel); ui->InformationTabBar->tabBar()->setTabToolTip(ui->InformationTabBar->count() - 1, QString::fromStdString(controllers[controller_idx]->GetName())); @@ -1815,7 +1815,7 @@ void OpenRGBDialog::AddConsolePage() /*-----------------------------------------------------*\ | Create the tab label | \*-----------------------------------------------------*/ - TabLabel* ConsoleTabLabel = new TabLabel(OpenRGBFont::terminal, tr("Log Console"), (char *)"Log Console", (char *)context); + TabLabel* ConsoleTabLabel = new TabLabel(OpenRGBFont::terminal, (char *)"Log Console", (char *)context, true); ui->InformationTabBar->tabBar()->setTabButton(ui->InformationTabBar->tabBar()->count() - 1, QTabBar::LeftSide, ConsoleTabLabel); } diff --git a/qt/TabLabel.cpp b/qt/TabLabel.cpp index db3ee18b..fabd8663 100644 --- a/qt/TabLabel.cpp +++ b/qt/TabLabel.cpp @@ -12,7 +12,7 @@ #include "OpenRGBFont.h" #include "ui_TabLabel.h" -TabLabel::TabLabel(int icon, QString name, char* original, char* context) : +TabLabel::TabLabel(int icon, char* label, char* context, bool translatable) : QWidget(nullptr), ui(new Ui::TabLabel) { @@ -24,10 +24,11 @@ TabLabel::TabLabel(int icon, QString name, char* original, char* context) : ui->icon->setFont(font); ui->icon->setText(OpenRGBFont::icon(icon)); - ui->name->setText(name); + this->translatable = translatable; + this->label = label; + this->context = context; - label = original; - ctxt = context; + UpdateLabel(true); } TabLabel::~TabLabel() @@ -39,14 +40,29 @@ void TabLabel::changeEvent(QEvent *event) { if(event->type() == QEvent::LanguageChange) { - /*-----------------------------------------------------*\ - | Storing the base string in label | - | enables switching between multiple languages | - | The context needs to be stored as the translation | - | file requires the originating context | - \*-----------------------------------------------------*/ - QApplication* app = static_cast(QApplication::instance()); - - ui->name->setText(app->translate(ctxt, label)); + UpdateLabel(false); + } +} + +void TabLabel::UpdateLabel(bool in_constructor) +{ + if(translatable) + { + /*-------------------------------------------------*\ + | Storing the base string in label | + | enables switching between multiple languages | + | The context needs to be stored as the translation | + | file requires the originating context | + \*-------------------------------------------------*/ + QApplication* app = static_cast(QApplication::instance()); + ui->name->setText(app->translate(context, label)); + } + else if(in_constructor) + { + /*-------------------------------------------------*\ + | Must only be called during constructor if not | + | translatable as label buffer may not exist | + \*-------------------------------------------------*/ + ui->name->setText(label); } } diff --git a/qt/TabLabel.h b/qt/TabLabel.h index 2311d50c..6da2048a 100644 --- a/qt/TabLabel.h +++ b/qt/TabLabel.h @@ -21,13 +21,16 @@ class TabLabel : public QWidget Q_OBJECT public: - TabLabel(int icon, QString name, char* original, char* context); + TabLabel(int icon, char* label, char* context, bool translatable); ~TabLabel(); private: - Ui::TabLabel *ui; - char* label; - char* ctxt; + Ui::TabLabel* ui; + char* label; + char* context; + bool translatable; + + void UpdateLabel(bool in_constructor); private slots: void changeEvent(QEvent *event);