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 119 of file kswitchlanguagedialog_p.cpp.

Constructor & Destructor Documentation

◆ KisKSwitchLanguageDialogPrivate()

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

Definition at line 300 of file kswitchlanguagedialog_p.cpp.

302 : p(parent)
303{
304 //NOTE: do NOT use "p" in constructor, it is not fully constructed
305}

Member Function Documentation

◆ addLanguageButton()

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

Adds one button with language to widget.

Definition at line 411 of file kswitchlanguagedialog_p.cpp.

412{
413 QString labelText = primaryLanguage ? i18n("Primary language:") : i18n("Fallback language:");
414
415 KLanguageButton *languageButton = new KLanguageButton(p);
416
417 fillApplicationLanguages(languageButton);
418
419 languageButton->setCurrentItem(languageCode);
420
421 QObject::connect(
422 languageButton,
423 SIGNAL(activated(QString)),
424 p,
425 SLOT(languageOnButtonChanged(QString))
426 );
427
428 LanguageRowData languageRowData;
429 QPushButton *removeButton = 0;
430
431 if (!primaryLanguage) {
432 removeButton = new QPushButton(i18n("Remove"), p);
433
434 QObject::connect(
435 removeButton,
436 SIGNAL(clicked()),
437 p,
438 SLOT(removeButtonClicked())
439 );
440 }
441
442 languageButton->setToolTip(primaryLanguage
443 ? i18n("This is the main application language which will be used first, before any other languages.")
444 : i18n("This is the language which will be used if any previous languages do not contain a proper translation."));
445
446 int numRows = languagesLayout->rowCount();
447
448 QLabel *languageLabel = new QLabel(labelText, p);
449 languagesLayout->addWidget(languageLabel, numRows + 1, 1, Qt::AlignLeft);
450 languagesLayout->addWidget(languageButton, numRows + 1, 2, Qt::AlignLeft);
451
452 if (!primaryLanguage) {
453 languagesLayout->addWidget(removeButton, numRows + 1, 3, Qt::AlignLeft);
454 languageRowData.setRowWidgets(languageLabel, languageButton, removeButton);
455 removeButton->show();
456 }
457
458 languageRows.insert(removeButton, languageRowData);
459
460 languageButtons.append(languageButton);
461 languageButton->show();
462 languageLabel->show();
463}
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 374 of file kswitchlanguagedialog_p.cpp.

375{
376 QStringList languagesList;
377
378 QByteArray languageCode = getApplicationSpecificLanguage();
379 if (!languageCode.isEmpty()) {
380 languagesList = QString::fromLatin1(languageCode).split(QLatin1Char(':'));
381 }
382 if (languagesList.isEmpty()) {
383 QLocale l;
384 languagesList = l.uiLanguages();
385
386 // We get en-US here but we use en_US
387 for (int i = 0; i < languagesList.count(); ++i) {
388 languagesList[i].replace(QLatin1String("-"), QLatin1String("_"));
389 }
390 }
391
392 for (int i = 0; i < languagesList.count();) {
393 QString languageCode = languagesList[i];
394 if (!KLocalizedString::isApplicationTranslatedInto(languageCode)) {
395 if (stripCountryCode(&languageCode)) {
396 if (KLocalizedString::isApplicationTranslatedInto(languageCode)) {
397 languagesList[i] = languageCode;
398 ++i;
399 continue;
400 }
401 }
402 languagesList.removeAt(i);
403 } else {
404 ++i;
405 }
406 }
407
408 return languagesList;
409}
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 317 of file kswitchlanguagedialog_p.cpp.

318{
319 QLocale defaultLocale;
320 QLocale cLocale(QLocale::C);
321 QLocale::setDefault(cLocale);
322 QSet<QString> insertedLanguages;
323
324 const QList<QLocale> allLocales = QLocale::matchingLocales(QLocale::AnyLanguage, QLocale::AnyScript, QLocale::AnyCountry);
325 Q_FOREACH (const QLocale &l, allLocales) {
326 QString languageCode = l.name();
327 if (l != cLocale) {
328 const QString nativeName = l.nativeLanguageName();
329 // For some languages the native name might be empty.
330 // In this case use the non native language name as fallback.
331 // See: QTBUG-51323
332 const QString languageName = nativeName.isEmpty() ? QLocale::languageToString(l.language()) : nativeName;
333 if (!insertedLanguages.contains(languageCode) && KLocalizedString::isApplicationTranslatedInto(languageCode)) {
334 QString displayName;
335 // Check if languageCode contains a territory name.
336 // For en and en_GB their native names already contain "American"
337 // and "British", so no need to append the territory name.
338 // Same applies for zh_CN and zh_TW, however we will need to
339 // disambiguate between zh_TW and zh_HK if it is eventually
340 // added.
341#if QT_VERSION < QT_VERSION_CHECK(6, 2, 0)
342 if (l.language() != QLocale::English && l.language() != QLocale::Chinese && languageCode.contains('_')) {
343 QString territoryName = l.nativeCountryName();
344 // Fallback just in case.
345 if (territoryName.isEmpty()) {
346 territoryName = QLocale::countryToString(l.country());
347#else
348 if (l.language() != QLocale::English && l.language() != QLocale::Chinese && languageCode.contains('_')) {
349 QString territoryName = l.nativeTerritoryName();
350 // Fallback just in case.
351 if (territoryName.isEmpty()) {
352 territoryName = QLocale::territoryToString(l.territory());
353#endif
354 }
355 // Append the territory name for disambiguation.
356 displayName = languageName % " (" % territoryName % ")";
357 } else {
358 displayName = languageName;
359 }
360 button->insertLanguage(languageCode, displayName);
361 insertedLanguages << languageCode;
362 } else if (stripCountryCode(&languageCode)) {
363 if (!insertedLanguages.contains(languageCode) && KLocalizedString::isApplicationTranslatedInto(languageCode)) {
364 button->insertLanguage(languageCode, languageName);
365 insertedLanguages << languageCode;
366 }
367 }
368 }
369 }
370
371 QLocale::setDefault(defaultLocale);
372}
QString button(const QWheelEvent &ev)

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

Member Data Documentation

◆ languageButtons

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

Definition at line 142 of file kswitchlanguagedialog_p.cpp.

◆ languageRows

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

Definition at line 141 of file kswitchlanguagedialog_p.cpp.

◆ languagesLayout

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

Definition at line 143 of file kswitchlanguagedialog_p.cpp.

143{nullptr};

◆ p

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

Definition at line 124 of file kswitchlanguagedialog_p.cpp.

124{nullptr}; //parent class

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