1 | /** @file
|
---|
2 | *
|
---|
3 | * VBox frontends: Qt GUI ("VirtualBox"):
|
---|
4 | * Declarations of utility classes and functions
|
---|
5 | * VirtualBox Qt extensions: QIWithRetranslateUI class declaration
|
---|
6 | */
|
---|
7 |
|
---|
8 | /*
|
---|
9 | * Copyright (C) 2008-2010 Oracle Corporation
|
---|
10 | *
|
---|
11 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
12 | * available from http://www.virtualbox.org. This file is free software;
|
---|
13 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
14 | * General Public License (GPL) as published by the Free Software
|
---|
15 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
16 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
17 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
18 | */
|
---|
19 |
|
---|
20 | #ifndef __QIWithRetranslateUI_h
|
---|
21 | #define __QIWithRetranslateUI_h
|
---|
22 |
|
---|
23 | /* Global includes */
|
---|
24 | #include <QApplication>
|
---|
25 | #include <QEvent>
|
---|
26 | #include <QObject>
|
---|
27 | #include <QGraphicsWidget>
|
---|
28 |
|
---|
29 | template <class Base>
|
---|
30 | class QIWithRetranslateUI: public Base
|
---|
31 | {
|
---|
32 | public:
|
---|
33 |
|
---|
34 | QIWithRetranslateUI(QWidget *pParent = 0) : Base(pParent) {}
|
---|
35 |
|
---|
36 | protected:
|
---|
37 |
|
---|
38 | virtual void changeEvent(QEvent *pEvent)
|
---|
39 | {
|
---|
40 | Base::changeEvent (pEvent);
|
---|
41 | switch (pEvent->type())
|
---|
42 | {
|
---|
43 | case QEvent::LanguageChange:
|
---|
44 | {
|
---|
45 | retranslateUi();
|
---|
46 | pEvent->accept();
|
---|
47 | break;
|
---|
48 | }
|
---|
49 | default:
|
---|
50 | break;
|
---|
51 | }
|
---|
52 | }
|
---|
53 |
|
---|
54 | virtual void retranslateUi() = 0;
|
---|
55 | };
|
---|
56 |
|
---|
57 | template <class Base>
|
---|
58 | class QIWithRetranslateUI2: public Base
|
---|
59 | {
|
---|
60 | public:
|
---|
61 |
|
---|
62 | QIWithRetranslateUI2(QWidget *pParent = 0, Qt::WindowFlags fFlags = 0) : Base(pParent, fFlags) {}
|
---|
63 |
|
---|
64 | protected:
|
---|
65 |
|
---|
66 | virtual void changeEvent(QEvent *pEvent)
|
---|
67 | {
|
---|
68 | Base::changeEvent (pEvent);
|
---|
69 | switch (pEvent->type())
|
---|
70 | {
|
---|
71 | case QEvent::LanguageChange:
|
---|
72 | {
|
---|
73 | retranslateUi();
|
---|
74 | pEvent->accept();
|
---|
75 | break;
|
---|
76 | }
|
---|
77 | default:
|
---|
78 | break;
|
---|
79 | }
|
---|
80 | }
|
---|
81 |
|
---|
82 | virtual void retranslateUi() = 0;
|
---|
83 | };
|
---|
84 |
|
---|
85 | template <class Base>
|
---|
86 | class QIWithRetranslateUI3: public Base
|
---|
87 | {
|
---|
88 | public:
|
---|
89 |
|
---|
90 | QIWithRetranslateUI3(QObject *pParent = 0)
|
---|
91 | : Base(pParent)
|
---|
92 | {
|
---|
93 | qApp->installEventFilter(this);
|
---|
94 | }
|
---|
95 |
|
---|
96 | protected:
|
---|
97 |
|
---|
98 | virtual bool eventFilter(QObject *pObject, QEvent *pEvent)
|
---|
99 | {
|
---|
100 | switch (pEvent->type())
|
---|
101 | {
|
---|
102 | case QEvent::LanguageChange:
|
---|
103 | {
|
---|
104 | retranslateUi();
|
---|
105 | break;
|
---|
106 | }
|
---|
107 | default:
|
---|
108 | break;
|
---|
109 | }
|
---|
110 | return Base::eventFilter(pObject, pEvent);
|
---|
111 | }
|
---|
112 |
|
---|
113 | virtual void retranslateUi() = 0;
|
---|
114 | };
|
---|
115 |
|
---|
116 | template <class Base>
|
---|
117 | class QIWithRetranslateUI4: public Base
|
---|
118 | {
|
---|
119 | public:
|
---|
120 |
|
---|
121 | QIWithRetranslateUI4(QGraphicsWidget *pParent = 0)
|
---|
122 | : Base(pParent)
|
---|
123 | {
|
---|
124 | qApp->installEventFilter(this);
|
---|
125 | }
|
---|
126 |
|
---|
127 | protected:
|
---|
128 |
|
---|
129 | virtual bool eventFilter(QObject *pObject, QEvent *pEvent)
|
---|
130 | {
|
---|
131 | switch (pEvent->type())
|
---|
132 | {
|
---|
133 | case QEvent::LanguageChange:
|
---|
134 | {
|
---|
135 | retranslateUi();
|
---|
136 | break;
|
---|
137 | }
|
---|
138 | default:
|
---|
139 | break;
|
---|
140 | }
|
---|
141 | return Base::eventFilter(pObject, pEvent);
|
---|
142 | }
|
---|
143 |
|
---|
144 | virtual void retranslateUi() = 0;
|
---|
145 | };
|
---|
146 |
|
---|
147 | #endif /* __QIWithRetranslateUI_h */
|
---|
148 |
|
---|