ACF $AcfVersion:0$
TLocalizableWrap.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-2.1-or-later OR GPL-2.0-or-later OR GPL-3.0-or-later OR LicenseRef-ACF-Commercial
2#pragma once
3
4
5// Qt includes
6#include <QtCore/QObject>
7#include <QtCore/QCoreApplication>
8
9
10namespace ibase
11{
12
13
14template <class Base>
15class TLocalizableWrap: public Base
16{
17public:
18 typedef Base BaseClass;
19
21
25 virtual void EnableLocalization(bool enableLocalization = true);
26
27protected:
28 // abstract methods
29 virtual void OnLanguageChanged() = 0;
30
31private:
32 class LanguageChangeEventFilter: public QObject
33 {
34 public:
35 typedef QObject BaseClass;
36
37 explicit LanguageChangeEventFilter(TLocalizableWrap& parent);
38
39 protected:
40 // reimplemented (QObject)
41 virtual bool eventFilter(QObject* sourcePtr, QEvent* eventPtr) override;
42
43 private:
44 TLocalizableWrap& m_parent;
45 };
46
47 LanguageChangeEventFilter m_languageChangeEventFilter;
48};
49
50
51// public methods of class TLocalizableWrap
52
53template <class Base>
55 :m_languageChangeEventFilter(*this)
56{
57}
58
59
60template <class Base>
61void TLocalizableWrap<Base>::EnableLocalization(bool enableLocalization)
62{
63 QCoreApplication* applicationPtr = QCoreApplication::instance();
64 if (applicationPtr != NULL){
65 if (enableLocalization){
66 applicationPtr->installEventFilter(&m_languageChangeEventFilter);
67 }
68 else{
69 applicationPtr->removeEventFilter(&m_languageChangeEventFilter);
70 }
71 }
72}
73
74
75// public methods of the embedded class LanguageChangeEventFilter
76
77template <class Base>
79 :m_parent(parent)
80{
81}
82
83
84// protected methods of the embedded class LanguageChangeEventFilter
85
86// reimplemented (QObject)
87
88template <class Base>
89bool TLocalizableWrap<Base>::LanguageChangeEventFilter::eventFilter(QObject* sourcePtr, QEvent* eventPtr)
90{
91 if ((eventPtr->type() == QEvent::LanguageChange) && (sourcePtr == QCoreApplication::instance())){
92 m_parent.OnLanguageChanged();
93 }
94
95 return BaseClass::eventFilter(sourcePtr, eventPtr);
96}
97
98
99} // namespace ibase
100
101
102
virtual void EnableLocalization(bool enableLocalization=true)
If enabled, listen to the language change event from the application context.
virtual void OnLanguageChanged()=0
#define NULL
Definition istd.h:74
This namespace contains basic implementations of standard primitives on the component level.