Perceptual Color

settranslation.cpp
1// SPDX-FileCopyrightText: Lukas Sommer <sommerluk@gmail.com>
2// SPDX-License-Identifier: BSD-2-Clause OR MIT
3
4// Own headers
5// First the interface, which forces the header to be self-contained.
6#include "settranslation.h"
7
8#include "initializetranslation.h"
9#include <optional>
10#include <qcoreapplication.h>
11#include <qdebug.h>
12#include <qglobal.h>
13#include <qthread.h>
14
15#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
16#include <qlist.h>
17#endif
18
19namespace PerceptualColor
20{
21
22/** @brief Set the translation for the whole library.
23 *
24 * After calling this function, all objects of this library that are created
25 * from now on are translated according to translation that was set.
26 *
27 * Objects that were yet existing when calling are <em>not always</em>
28 * automatically updated: When calling this function, Qt sends
29 * a <tt>QEvent::LanguageChange</tt> event only to top-level widgets,
30 * and these will get updated then. You can send the event yourself
31 * to non-top-level widgets to update those widgets also. Note that
32 * also @ref RgbColorSpaceFactory generates objects that might have
33 * localized properties; these objects do not support translation
34 * updates.
35 *
36 * If you create objects that use translations <em>before</em> a translation
37 * has been set explicitly, than automatically an environment-dependant
38 * translation is loaded.
39 *
40 * You might call this function again after a change of
41 * <tt>QLocale()</tt> to change the translation. Also, call this
42 * function again after destroying the <tt>QCoreApplication</tt>
43 * object and creating a new one.
44 *
45 * It is safe to call this function multiple times.
46 *
47 * @pre There exists exactly <em>one</em> instance of <tt>QCoreApplication</tt>
48 * to which the parameter points. This function is called from the same thread
49 * in which the <tt>QCoreApplication</tt> instance lives.
50 *
51 * @param instance A pointer to the <tt>QCoreApplication</tt> instance for
52 * which the initialization will be done.
53 * @param newUiLanguages List of translations, ordered by priority,
54 * most important ones first, like in <tt>QLocale::uiLanguages()</tt>. */
55void setTranslation(QCoreApplication *instance, const QStringList &newUiLanguages)
56{
57 // Check of pre-conditions
58 // The mutex lowers the risk when using QCoreApplication::instance()
59 // and QThread::currentThread(), which are not explicitly documented
60 // as thread-safe.
61 if (instance == nullptr) {
62 qWarning() //
63 << __func__ //
64 << "must not be called without a QCoreApplication object.";
65 return;
66 }
68 qWarning() //
69 << __func__ //
70 << "must not be called by any other thread "
71 "except the QCoreApplication thread.";
72 return;
73 }
74
75 initializeTranslation(instance, std::optional<QStringList>(newUiLanguages));
76}
77
78} // namespace PerceptualColor
The namespace of this library.
void setTranslation(QCoreApplication *instance, const QStringList &newUiLanguages)
Set the translation for the whole library.
QCoreApplication * instance()
QThread * currentThread()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:00:47 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.