ICF 3.1.1.10
Technical documentation of ICF Libraries
TVisualChangesHandlerWrap.h
Go to the documentation of this file.
1/********************************************************************************
2** This file is part of the ICF Framework. Copyright (C) Witold Gantzke & Kirill Lepskiy
3** ICF Framework may be used under the terms of the LGPL License v. 2.1 by the Free Software Foundation.
4********************************************************************************/
5
6#pragma once
7
8
9// Qt includes
10#include <QtCore/QObject>
11#include <QtCore/QCoreApplication>
12
13
14namespace ibase
15{
16
17
18template <class Base>
19class TVisualChangesHandlerWrap: public Base
20{
21public:
22 typedef Base BaseClass;
23
24 template<typename... Args>
26
30 virtual void EnableVisualChangesHandler(bool enableLocalization = true);
31
32protected:
33 // Methods signaling visual changes
34 virtual void OnLanguageChanged();
35 virtual void OnDesignSchemaChanged();
36
37private:
38 class EventFilter: public QObject
39 {
40 public:
41 typedef QObject BaseClass;
42
43 explicit EventFilter(TVisualChangesHandlerWrap& parent);
44
45 protected:
46 // reimplemented (QObject)
47 bool eventFilter(QObject* sourcePtr, QEvent* eventPtr);
48
49 private:
51 };
52
53 EventFilter m_eventFilter;
54 bool m_isFilterInstalled;
55};
56
57
58// public methods of class TVisualChangesHandlerWrap
59
60template <class Base>
61template<typename... Args>
63: BaseClass(args...),
64 m_eventFilter(*this),
65 m_isFilterInstalled(false)
66{
67}
68
69
70template <class Base>
72{
73 QCoreApplication* applicationPtr = QCoreApplication::instance();
74 if (applicationPtr != nullptr){
75 if (enableLocalization){
76 if (!m_isFilterInstalled){
77 applicationPtr->installEventFilter(&m_eventFilter);
78
79 m_isFilterInstalled = true;
80 }
81 }
82 else{
83 if (m_isFilterInstalled){
84 applicationPtr->removeEventFilter(&m_eventFilter);
85
86 m_isFilterInstalled = false;
87 }
88 }
89 }
90}
91
92
93// protected methods
94
95template <class Base>
99
100
101template <class Base>
105
106
107// public methods of the embedded class EventFilter
108
109template <class Base>
111: m_parent(parent)
112{
113}
114
115
116// protected methods of the embedded class EventFilter
117
118// reimplemented (QObject)
119
120template <class Base>
121bool TVisualChangesHandlerWrap<Base>::EventFilter::eventFilter(QObject* sourcePtr, QEvent* eventPtr)
122{
123 if (sourcePtr == QCoreApplication::instance()){
124 switch (eventPtr->type()){
125 case QEvent::QEvent::ApplicationPaletteChange:
126 m_parent.OnDesignSchemaChanged();
127 break;
128
129 case QEvent::QEvent::LanguageChange:
130 m_parent.OnLanguageChanged();
131 break;
132
133 default:
134 break;
135 }
136 }
137
138 return BaseClass::eventFilter(sourcePtr, eventPtr);
139}
140
141
142} // namespace ibase
143
144
virtual void EnableVisualChangesHandler(bool enableLocalization=true)
If enabled, listen to the language change event from the application context.
Base class for component implementation.
This namespace contains standard classes based on Qt.

© Witold Gantzke and Kirill Lepskiy