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

Standard "switch application language" dialog box. More...

#include <kswitchlanguagedialog_p.h>

+ Inheritance diagram for KDEPrivate::KisKSwitchLanguageDialog:

Public Member Functions

 KisKSwitchLanguageDialog (QWidget *parent=nullptr)
 
 ~KisKSwitchLanguageDialog () override
 

Protected Slots

virtual void languageOnButtonChanged (const QString &)
 
virtual void removeButtonClicked ()
 
virtual void slotAddLanguageButton ()
 
void slotDefault ()
 
virtual void slotOk ()
 

Private Attributes

KisKSwitchLanguageDialogPrivate *const d
 

Friends

class KisKSwitchLanguageDialogPrivate
 

Detailed Description

Standard "switch application language" dialog box.

This class provides "switch application language" dialog box that is used in KisKHelpMenu

Author
Krzysztof Lichota (licho.nosp@m.ta@m.nosp@m.imuw..nosp@m.edu..nosp@m.pl)

Definition at line 29 of file kswitchlanguagedialog_p.h.

Constructor & Destructor Documentation

◆ KisKSwitchLanguageDialog()

KDEPrivate::KisKSwitchLanguageDialog::KisKSwitchLanguageDialog ( QWidget * parent = nullptr)

Constructor. Creates a fully featured "Switch application language" dialog box. Note that this dialog is made modeless in the KisKHelpMenu class so the users may expect a modeless dialog.

Parameters
parentThe parent of the dialog box. You should use the toplevel window so that the dialog becomes centered.

Definition at line 148 of file kswitchlanguagedialog_p.cpp.

149 : QDialog(parent),
151{
152 setWindowTitle(i18n("Switch Application Language"));
153
154 QVBoxLayout *topLayout = new QVBoxLayout(this);
155
156 QLabel *label = new QLabel(i18n("Please choose the language which should be used for this application:"), this);
157 topLayout->addWidget(label);
158
159 QHBoxLayout *languageHorizontalLayout = new QHBoxLayout();
160 topLayout->addLayout(languageHorizontalLayout);
161
162 d->languagesLayout = new QGridLayout();
163 languageHorizontalLayout->addLayout(d->languagesLayout);
164 languageHorizontalLayout->addStretch();
165
166 const QStringList defaultLanguages = d->applicationLanguageList();
167
168 int count = defaultLanguages.count();
169 if (!ALLOW_FALLBACK_LANGUAGES && count > 1) {
170 count = 1;
171 }
172
173 for (int i = 0; i < count; ++i) {
174 QString language = defaultLanguages[i];
175 bool primaryLanguage = (i == 0);
176 d->addLanguageButton(language, primaryLanguage);
177 }
178
179 if (!count) {
180 QLocale l;
181 d->addLanguageButton(l.name(), true);
182 }
183
185 QHBoxLayout *addButtonHorizontalLayout = new QHBoxLayout();
186 topLayout->addLayout(addButtonHorizontalLayout);
187
188 QPushButton *addLangButton = new QPushButton(i18n("Add Fallback Language"), this);
189 addLangButton->setToolTip(i18n("Adds one more language which will be used if other translations do not contain a proper translation."));
190 connect(addLangButton, SIGNAL(clicked()), this, SLOT(slotAddLanguageButton()));
191 addButtonHorizontalLayout->addWidget(addLangButton);
192 addButtonHorizontalLayout->addStretch();
193 }
194
195 topLayout->addStretch(10);
196
197 QDialogButtonBox *buttonBox = new QDialogButtonBox(this);
198 buttonBox->setStandardButtons(QDialogButtonBox::Ok
199 | QDialogButtonBox::Cancel
200 | QDialogButtonBox::RestoreDefaults);
201 KGuiItem::assign(buttonBox->button(QDialogButtonBox::Ok), KStandardGuiItem::ok());
202 KGuiItem::assign(buttonBox->button(QDialogButtonBox::Cancel), KStandardGuiItem::cancel());
203 KGuiItem::assign(buttonBox->button(QDialogButtonBox::RestoreDefaults), KStandardGuiItem::defaults());
204
205 topLayout->addWidget(buttonBox);
206
207 connect(buttonBox, SIGNAL(accepted()), this, SLOT(slotOk()));
208 connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
209 connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
210 connect(buttonBox->button(QDialogButtonBox::RestoreDefaults), SIGNAL(clicked()),
211 this, SLOT(slotDefault()));
212}
void addLanguageButton(const QString &languageCode, bool primaryLanguage)
KisKSwitchLanguageDialogPrivate *const d
static constexpr bool ALLOW_FALLBACK_LANGUAGES

References KDEPrivate::KisKSwitchLanguageDialogPrivate::addLanguageButton(), ALLOW_FALLBACK_LANGUAGES, KDEPrivate::KisKSwitchLanguageDialogPrivate::applicationLanguageList(), d, KDEPrivate::KisKSwitchLanguageDialogPrivate::languagesLayout, slotAddLanguageButton(), slotDefault(), and slotOk().

◆ ~KisKSwitchLanguageDialog()

KDEPrivate::KisKSwitchLanguageDialog::~KisKSwitchLanguageDialog ( )
override

Definition at line 214 of file kswitchlanguagedialog_p.cpp.

215{
216 delete d;
217}

References d.

Member Function Documentation

◆ languageOnButtonChanged

void KDEPrivate::KisKSwitchLanguageDialog::languageOnButtonChanged ( const QString & languageCode)
protectedvirtualslot

Called when one of language buttons changes state.

Definition at line 255 of file kswitchlanguagedialog_p.cpp.

256{
257 Q_UNUSED(languageCode);
258#if 0
259 for (int i = 0, count = d->languageButtons.count(); i < count; ++i) {
260 KLanguageButton *languageButton = d->languageButtons[i];
261 if (languageButton->current() == languageCode) {
262 //update all buttons which have matching id
263 //might update buttons which were not changed, but well...
264 languageButton->setText(KLocale::global()->languageCodeToName(languageCode));
265 }
266 }
267#endif
268}
QString current() const
void setText(const QString &text)

References KLanguageButton::current(), d, KDEPrivate::KisKSwitchLanguageDialogPrivate::languageButtons, and KLanguageButton::setText().

◆ removeButtonClicked

void KDEPrivate::KisKSwitchLanguageDialog::removeButtonClicked ( )
protectedvirtualslot

Called when "Remove" language button is clicked.

Definition at line 225 of file kswitchlanguagedialog_p.cpp.

226{
227 QObject const *signalSender = sender();
228 if (!signalSender) {
229 qCritical() << "KisKSwitchLanguageDialog::removeButtonClicked() called directly, not using signal" << Qt::endl;
230 return;
231 }
232
233 QPushButton *removeButton = const_cast<QPushButton *>(::qobject_cast<const QPushButton *>(signalSender));
234 if (!removeButton) {
235 qCritical() << "KisKSwitchLanguageDialog::removeButtonClicked() called from something else than QPushButton" << Qt::endl;
236 return;
237 }
238
239 QMap<QPushButton *, LanguageRowData>::iterator it = d->languageRows.find(removeButton);
240 if (it == d->languageRows.end()) {
241 qCritical() << "KisKSwitchLanguageDialog::removeButtonClicked called from unknown QPushButton" << Qt::endl;
242 return;
243 }
244
245 LanguageRowData languageRowData = it.value();
246
247 d->languageButtons.removeAll(languageRowData.languageButton);
248
249 languageRowData.label->deleteLater();
250 languageRowData.languageButton->deleteLater();
251 languageRowData.removeButton->deleteLater();
252 d->languageRows.erase(it);
253}
QMap< QPushButton *, LanguageRowData > languageRows

References d, KDEPrivate::LanguageRowData::label, KDEPrivate::LanguageRowData::languageButton, KDEPrivate::KisKSwitchLanguageDialogPrivate::languageButtons, KDEPrivate::KisKSwitchLanguageDialogPrivate::languageRows, and KDEPrivate::LanguageRowData::removeButton.

◆ slotAddLanguageButton

void KDEPrivate::KisKSwitchLanguageDialog::slotAddLanguageButton ( )
protectedvirtualslot

Called to add one language button to dialog.

Definition at line 219 of file kswitchlanguagedialog_p.cpp.

220{
221 //adding new button with en_US as it should always be present
222 d->addLanguageButton(QStringLiteral("en_US"), d->languageButtons.isEmpty());
223}

References KDEPrivate::KisKSwitchLanguageDialogPrivate::addLanguageButton(), d, and KDEPrivate::KisKSwitchLanguageDialogPrivate::languageButtons.

◆ slotDefault

void KDEPrivate::KisKSwitchLanguageDialog::slotDefault ( )
protectedslot

Definition at line 292 of file kswitchlanguagedialog_p.cpp.

293{
294 setApplicationSpecificLanguage(QByteArray());
295 accept();
296}
static void setApplicationSpecificLanguage(const QByteArray &languageCode)

References setApplicationSpecificLanguage().

◆ slotOk

void KDEPrivate::KisKSwitchLanguageDialog::slotOk ( )
protectedvirtualslot

Activated when the Ok button has been clicked.

Definition at line 270 of file kswitchlanguagedialog_p.cpp.

271{
272 QStringList languages;
273
274 for (int i = 0, count = d->languageButtons.count(); i < count; ++i) {
275 KLanguageButton *languageButton = d->languageButtons[i];
276 languages << languageButton->current();
277 }
278
279 if (d->applicationLanguageList() != languages) {
280 QString languageString = languages.join(QLatin1Char(':'));
281 //list is different from defaults or saved languages list
282 setApplicationSpecificLanguage(languageString.toLatin1());
283
284 QMessageBox::information(this,
285 i18nc("@title:window:", "Application Language Changed"), //caption
286 i18n("The language for this application has been changed. The change will take effect the next time the application is started."));
287 }
288
289 accept();
290}

References KDEPrivate::KisKSwitchLanguageDialogPrivate::applicationLanguageList(), KLanguageButton::current(), d, KDEPrivate::KisKSwitchLanguageDialogPrivate::languageButtons, and setApplicationSpecificLanguage().

Friends And Related Symbol Documentation

◆ KisKSwitchLanguageDialogPrivate

friend class KisKSwitchLanguageDialogPrivate
friend

Definition at line 71 of file kswitchlanguagedialog_p.h.

Member Data Documentation

◆ d

KisKSwitchLanguageDialogPrivate* const KDEPrivate::KisKSwitchLanguageDialog::d
private

Definition at line 69 of file kswitchlanguagedialog_p.h.


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