55#include " autoupdaterwindow.h"
66#include " mainwindow.h"
77#include " qtutils.h"
8- #include " scmversion/scmversion.h"
98#include " settingswindow.h"
109#include " settingwidgetbinder.h"
1110
11+ #include " scmversion/scmversion.h"
12+
13+ #include " common/string_util.h"
14+
15+ #include < ranges>
16+
1217#include " moc_interfacesettingswidget.cpp"
1318
1419const char * InterfaceSettingsWidget::THEME_NAMES[] = {
@@ -90,8 +95,47 @@ InterfaceSettingsWidget::InterfaceSettingsWidget(SettingsWindow* dialog, QWidget
9095 connect (m_ui.language , QOverload<int >::of (&QComboBox::currentIndexChanged), this ,
9196 &InterfaceSettingsWidget::onLanguageChanged);
9297
98+ // Annoyingly, have to match theme and language properties otherwise the sizes do not match.
99+ m_ui.theme ->setMinimumContentsLength (m_ui.language ->minimumContentsLength ());
100+ m_ui.theme ->setSizeAdjustPolicy (m_ui.language ->sizeAdjustPolicy ());
101+
102+ if (AutoUpdaterWindow::isSupported ())
103+ {
104+ SettingWidgetBinder::BindWidgetToBoolSetting (sif, m_ui.autoUpdateEnabled , " AutoUpdater" , " CheckAtStartup" , true );
105+ m_ui.autoUpdateTag ->addItems (AutoUpdaterWindow::getTagList ());
106+ SettingWidgetBinder::BindWidgetToStringSetting (sif, m_ui.autoUpdateTag , " AutoUpdater" , " UpdateTag" ,
107+ AutoUpdaterWindow::getDefaultTag ());
108+ connect (m_ui.checkForUpdates , &QPushButton::clicked, this , []() { g_main_window->checkForUpdates (true ); });
109+ }
110+ else
111+ {
112+ m_ui.autoUpdateTag ->addItem (tr (" Unavailable" ));
113+ m_ui.autoUpdateEnabled ->setEnabled (false );
114+ m_ui.autoUpdateTag ->setEnabled (false );
115+ m_ui.checkForUpdates ->setEnabled (false );
116+ m_ui.updatesGroup ->setEnabled (false );
117+ }
118+
93119 m_ui.autoUpdateCurrentVersion ->setText (tr (" %1 (%2)" ).arg (g_scm_version_str).arg (g_scm_date_str));
94120 }
121+ else
122+ {
123+ delete m_ui.appearanceGroup ;
124+ m_ui.appearanceGroup = nullptr ;
125+ m_ui.languageLabel = nullptr ;
126+ m_ui.language = nullptr ;
127+ m_ui.themeLabel = nullptr ;
128+ m_ui.theme = nullptr ;
129+
130+ delete m_ui.updatesGroup ;
131+ m_ui.autoUpdateTagLabel = nullptr ;
132+ m_ui.autoUpdateTag = nullptr ;
133+ m_ui.autoUpdateCurrentVersionLabel = nullptr ;
134+ m_ui.autoUpdateCurrentVersion = nullptr ;
135+ m_ui.autoUpdateCheckLayout = nullptr ;
136+ m_ui.autoUpdateEnabled = nullptr ;
137+ m_ui.checkForUpdates = nullptr ;
138+ }
95139
96140 onRenderToSeparateWindowChanged ();
97141
@@ -135,23 +179,6 @@ InterfaceSettingsWidget::InterfaceSettingsWidget(SettingsWindow* dialog, QWidget
135179
136180 if (!m_dialog->isPerGameSettings ())
137181 {
138- if (AutoUpdaterWindow::isSupported ())
139- {
140- SettingWidgetBinder::BindWidgetToBoolSetting (sif, m_ui.autoUpdateEnabled , " AutoUpdater" , " CheckAtStartup" , true );
141- m_ui.autoUpdateTag ->addItems (AutoUpdaterWindow::getTagList ());
142- SettingWidgetBinder::BindWidgetToStringSetting (sif, m_ui.autoUpdateTag , " AutoUpdater" , " UpdateTag" ,
143- AutoUpdaterWindow::getDefaultTag ());
144- connect (m_ui.checkForUpdates , &QPushButton::clicked, this , []() { g_main_window->checkForUpdates (true ); });
145- }
146- else
147- {
148- m_ui.autoUpdateTag ->addItem (tr (" Unavailable" ));
149- m_ui.autoUpdateEnabled ->setEnabled (false );
150- m_ui.autoUpdateTag ->setEnabled (false );
151- m_ui.checkForUpdates ->setEnabled (false );
152- m_ui.updatesGroup ->setEnabled (false );
153- }
154-
155182 dialog->registerWidgetHelp (m_ui.language , tr (" Language" ), tr (" System Language" ),
156183 tr (" Selects the language for the application. Please note that not all parts of the "
157184 " application may be translated for a given language." ));
@@ -178,31 +205,27 @@ InterfaceSettingsWidget::InterfaceSettingsWidget(SettingsWindow* dialog, QWidget
178205 tr (" Automatically checks for updates to the program on startup. Updates can be deferred "
179206 " until later or skipped entirely." ));
180207 }
181- else
182- {
183- delete m_ui.appearanceGroup ;
184- m_ui.appearanceGroup = nullptr ;
185- m_ui.languageLabel = nullptr ;
186- m_ui.language = nullptr ;
187- m_ui.themeLabel = nullptr ;
188- m_ui.theme = nullptr ;
189-
190- delete m_ui.updatesGroup ;
191- m_ui.autoUpdateTagLabel = nullptr ;
192- m_ui.autoUpdateTag = nullptr ;
193- m_ui.autoUpdateCurrentVersionLabel = nullptr ;
194- m_ui.autoUpdateCurrentVersion = nullptr ;
195- m_ui.autoUpdateCheckLayout = nullptr ;
196- m_ui.autoUpdateEnabled = nullptr ;
197- m_ui.checkForUpdates = nullptr ;
198- }
199208}
200209
201210InterfaceSettingsWidget::~InterfaceSettingsWidget () = default ;
202211
203212void InterfaceSettingsWidget::populateLanguageDropdown (QComboBox* cb)
204213{
205- for (const auto & [language, code] : Host::GetAvailableLanguageList ())
214+ const auto language_list = Host::GetAvailableLanguageList ();
215+
216+ // Instantiating the fonts used for languages takes ~170ms on my machine, so we do this to avoid a delay in opening
217+ // the window. It effectively just shifts the delay to opening the dropdown instead, but most users are going to be
218+ // changing the language less frequently than opening the settings window.
219+ cb->setMinimumContentsLength (static_cast <int >(std::ranges::max (
220+ std::views::transform (language_list, [](const auto & it) { return StringUtil::GetUTF8CharacterCount (it.first ); }))));
221+ cb->setSizeAdjustPolicy (QComboBox::AdjustToMinimumContentsLengthWithIcon);
222+ if (QListView* const view = qobject_cast<QListView*>(cb->view ()))
223+ {
224+ view->setUniformItemSizes (true );
225+ view->setLayoutMode (QListView::Batched);
226+ }
227+
228+ for (const auto & [language, code] : language_list)
206229 {
207230 cb->addItem (QtUtils::GetIconForTranslationLanguage (code), QString::fromUtf8 (Host::GetLanguageName (code)),
208231 QString::fromLatin1 (code));
0 commit comments