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

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

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

◆ ~KisKSwitchLanguageDialog()

KDEPrivate::KisKSwitchLanguageDialog::~KisKSwitchLanguageDialog ( )
override

Definition at line 195 of file kswitchlanguagedialog_p.cpp.

196{
197 delete d;
198}

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

237{
238 Q_UNUSED(languageCode);
239#if 0
240 for (int i = 0, count = d->languageButtons.count(); i < count; ++i) {
241 KLanguageButton *languageButton = d->languageButtons[i];
242 if (languageButton->current() == languageCode) {
243 //update all buttons which have matching id
244 //might update buttons which were not changed, but well...
245 languageButton->setText(KLocale::global()->languageCodeToName(languageCode));
246 }
247 }
248#endif
249}
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 206 of file kswitchlanguagedialog_p.cpp.

207{
208 QObject const *signalSender = sender();
209 if (!signalSender) {
210 qCritical() << "KisKSwitchLanguageDialog::removeButtonClicked() called directly, not using signal" << Qt::endl;
211 return;
212 }
213
214 QPushButton *removeButton = const_cast<QPushButton *>(::qobject_cast<const QPushButton *>(signalSender));
215 if (!removeButton) {
216 qCritical() << "KisKSwitchLanguageDialog::removeButtonClicked() called from something else than QPushButton" << Qt::endl;
217 return;
218 }
219
220 QMap<QPushButton *, LanguageRowData>::iterator it = d->languageRows.find(removeButton);
221 if (it == d->languageRows.end()) {
222 qCritical() << "KisKSwitchLanguageDialog::removeButtonClicked called from unknown QPushButton" << Qt::endl;
223 return;
224 }
225
226 LanguageRowData languageRowData = it.value();
227
228 d->languageButtons.removeAll(languageRowData.languageButton);
229
230 languageRowData.label->deleteLater();
231 languageRowData.languageButton->deleteLater();
232 languageRowData.removeButton->deleteLater();
233 d->languageRows.erase(it);
234}
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 200 of file kswitchlanguagedialog_p.cpp.

201{
202 //adding new button with en_US as it should always be present
203 d->addLanguageButton(QStringLiteral("en_US"), d->languageButtons.isEmpty());
204}

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

◆ slotDefault

void KDEPrivate::KisKSwitchLanguageDialog::slotDefault ( )
protectedslot

Definition at line 273 of file kswitchlanguagedialog_p.cpp.

274{
275 setApplicationSpecificLanguage(QByteArray());
276 accept();
277}
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 251 of file kswitchlanguagedialog_p.cpp.

252{
253 QStringList languages;
254
255 for (int i = 0, count = d->languageButtons.count(); i < count; ++i) {
256 KLanguageButton *languageButton = d->languageButtons[i];
257 languages << languageButton->current();
258 }
259
260 if (d->applicationLanguageList() != languages) {
261 QString languageString = languages.join(QLatin1Char(':'));
262 //list is different from defaults or saved languages list
263 setApplicationSpecificLanguage(languageString.toLatin1());
264
265 QMessageBox::information(this,
266 i18nc("@title:window:", "Application Language Changed"), //caption
267 i18n("The language for this application has been changed. The change will take effect the next time the application is started."));
268 }
269
270 accept();
271}

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: