Krita Source Code Documentation
Loading...
Searching...
No Matches
KDEPrivate::KisKSwitchLanguageDialogPrivate Class Reference

Public Member Functions

void addLanguageButton (const QString &languageCode, bool primaryLanguage)
 
QStringList applicationLanguageList ()
 
void fillApplicationLanguages (KLanguageButton *button)
 
 KisKSwitchLanguageDialogPrivate (KisKSwitchLanguageDialog *parent)
 

Public Attributes

QList< KLanguageButton * > languageButtons
 
QMap< QPushButton *, LanguageRowDatalanguageRows
 
QGridLayout * languagesLayout {nullptr}
 
KisKSwitchLanguageDialogp {nullptr}
 

Detailed Description

Definition at line 106 of file kswitchlanguagedialog_p.cpp.

Constructor & Destructor Documentation

◆ KisKSwitchLanguageDialogPrivate()

KDEPrivate::KisKSwitchLanguageDialogPrivate::KisKSwitchLanguageDialogPrivate ( KisKSwitchLanguageDialog * parent)

Definition at line 281 of file kswitchlanguagedialog_p.cpp.

283 : p(parent)
284{
285 //NOTE: do NOT use "p" in constructor, it is not fully constructed
286}

Member Function Documentation

◆ addLanguageButton()

void KDEPrivate::KisKSwitchLanguageDialogPrivate::addLanguageButton ( const QString & languageCode,
bool primaryLanguage )

Adds one button with language to widget.

Definition at line 384 of file kswitchlanguagedialog_p.cpp.

385{
386 QString labelText = primaryLanguage ? i18n("Primary language:") : i18n("Fallback language:");
387
388 KLanguageButton *languageButton = new KLanguageButton(p);
389
390 fillApplicationLanguages(languageButton);
391
392 languageButton->setCurrentItem(languageCode);
393
394 QObject::connect(
395 languageButton,
396 SIGNAL(activated(QString)),
397 p,
398 SLOT(languageOnButtonChanged(QString))
399 );
400
401 LanguageRowData languageRowData;
402 QPushButton *removeButton = 0;
403
404 if (!primaryLanguage) {
405 removeButton = new QPushButton(i18n("Remove"), p);
406
407 QObject::connect(
408 removeButton,
409 SIGNAL(clicked()),
410 p,
411 SLOT(removeButtonClicked())
412 );
413 }
414
415 languageButton->setToolTip(primaryLanguage
416 ? i18n("This is the main application language which will be used first, before any other languages.")
417 : i18n("This is the language which will be used if any previous languages do not contain a proper translation."));
418
419 int numRows = languagesLayout->rowCount();
420
421 QLabel *languageLabel = new QLabel(labelText, p);
422 languagesLayout->addWidget(languageLabel, numRows + 1, 1, Qt::AlignLeft);
423 languagesLayout->addWidget(languageButton, numRows + 1, 2, Qt::AlignLeft);
424
425 if (!primaryLanguage) {
426 languagesLayout->addWidget(removeButton, numRows + 1, 3, Qt::AlignLeft);
427 languageRowData.setRowWidgets(languageLabel, languageButton, removeButton);
428 removeButton->show();
429 }
430
431 languageRows.insert(removeButton, languageRowData);
432
433 languageButtons.append(languageButton);
434 languageButton->show();
435 languageLabel->show();
436}
QMap< QPushButton *, LanguageRowData > languageRows
void setCurrentItem(const QString &languageCode)

References fillApplicationLanguages(), languageButtons, languageRows, languagesLayout, p, KLanguageButton::setCurrentItem(), and KDEPrivate::LanguageRowData::setRowWidgets().

◆ applicationLanguageList()

QStringList KDEPrivate::KisKSwitchLanguageDialogPrivate::applicationLanguageList ( )

Returns list of languages chosen for application or default languages is they are not set.

Definition at line 347 of file kswitchlanguagedialog_p.cpp.

348{
349 QStringList languagesList;
350
351 QByteArray languageCode = getApplicationSpecificLanguage();
352 if (!languageCode.isEmpty()) {
353 languagesList = QString::fromLatin1(languageCode).split(QLatin1Char(':'));
354 }
355 if (languagesList.isEmpty()) {
356 QLocale l;
357 languagesList = l.uiLanguages();
358
359 // We get en-US here but we use en_US
360 for (int i = 0; i < languagesList.count(); ++i) {
361 languagesList[i].replace(QLatin1String("-"), QLatin1String("_"));
362 }
363 }
364
365 for (int i = 0; i < languagesList.count();) {
366 QString languageCode = languagesList[i];
367 if (!KLocalizedString::isApplicationTranslatedInto(languageCode)) {
368 if (stripCountryCode(&languageCode)) {
369 if (KLocalizedString::isApplicationTranslatedInto(languageCode)) {
370 languagesList[i] = languageCode;
371 ++i;
372 continue;
373 }
374 }
375 languagesList.removeAt(i);
376 } else {
377 ++i;
378 }
379 }
380
381 return languagesList;
382}
static QByteArray getApplicationSpecificLanguage(const QByteArray &defaultCode=QByteArray())
static bool stripCountryCode(QString *languageCode)

References getApplicationSpecificLanguage(), and KDEPrivate::stripCountryCode().

◆ fillApplicationLanguages()

void KDEPrivate::KisKSwitchLanguageDialogPrivate::fillApplicationLanguages ( KLanguageButton * button)

Fills language button with names of languages for which given application has translation.

Definition at line 298 of file kswitchlanguagedialog_p.cpp.

299{
300 QLocale defaultLocale;
301 QLocale cLocale(QLocale::C);
302 QLocale::setDefault(cLocale);
303 QSet<QString> insertedLanguages;
304
305 const QList<QLocale> allLocales = QLocale::matchingLocales(QLocale::AnyLanguage, QLocale::AnyScript, QLocale::AnyCountry);
306 Q_FOREACH (const QLocale &l, allLocales) {
307 QString languageCode = l.name();
308 if (l != cLocale) {
309 const QString nativeName = l.nativeLanguageName();
310 // For some languages the native name might be empty.
311 // In this case use the non native language name as fallback.
312 // See: QTBUG-51323
313 const QString languageName = nativeName.isEmpty() ? QLocale::languageToString(l.language()) : nativeName;
314 if (!insertedLanguages.contains(languageCode) && KLocalizedString::isApplicationTranslatedInto(languageCode)) {
315 QString displayName;
316 // Check if languageCode contains a country name.
317 // For en and en_GB their native names already contain "American"
318 // and "British", so no need to append the country name.
319 // Same applies for zh_CN and zh_TW, however we will need to
320 // disambiguate between zh_TW and zh_HK if it is eventually
321 // added.
322 if (l.language() != QLocale::English && l.language() != QLocale::Chinese && languageCode.contains('_')) {
323 QString countryName = l.nativeCountryName();
324 // Fallback just in case.
325 if (countryName.isEmpty()) {
326 countryName = QLocale::countryToString(l.country());
327 }
328 // Append the country name for disambiguation.
329 displayName = languageName % " (" % countryName % ")";
330 } else {
331 displayName = languageName;
332 }
333 button->insertLanguage(languageCode, displayName);
334 insertedLanguages << languageCode;
335 } else if (stripCountryCode(&languageCode)) {
336 if (!insertedLanguages.contains(languageCode) && KLocalizedString::isApplicationTranslatedInto(languageCode)) {
337 button->insertLanguage(languageCode, languageName);
338 insertedLanguages << languageCode;
339 }
340 }
341 }
342 }
343
344 QLocale::setDefault(defaultLocale);
345}
QString button(const QWheelEvent &ev)

References button(), and KDEPrivate::stripCountryCode().

Member Data Documentation

◆ languageButtons

QList<KLanguageButton *> KDEPrivate::KisKSwitchLanguageDialogPrivate::languageButtons

Definition at line 129 of file kswitchlanguagedialog_p.cpp.

◆ languageRows

QMap<QPushButton *, LanguageRowData> KDEPrivate::KisKSwitchLanguageDialogPrivate::languageRows

Definition at line 128 of file kswitchlanguagedialog_p.cpp.

◆ languagesLayout

QGridLayout* KDEPrivate::KisKSwitchLanguageDialogPrivate::languagesLayout {nullptr}

Definition at line 130 of file kswitchlanguagedialog_p.cpp.

130{nullptr};

◆ p

KisKSwitchLanguageDialog* KDEPrivate::KisKSwitchLanguageDialogPrivate::p {nullptr}

Definition at line 111 of file kswitchlanguagedialog_p.cpp.

111{nullptr}; //parent class

The documentation for this class was generated from the following file: