VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/globals/QIWithRetranslateUI.h@ 43138

Last change on this file since 43138 was 30194, checked in by vboxsync, 14 years ago

FE/Qt: 5052: Runtime language switching should now translate all QIWithRetranslateUI3 derived objects.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.6 KB
RevLine 
[25177]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/*
[28800]9 * Copyright (C) 2008-2010 Oracle Corporation
[25177]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
[26636]23/* Global includes */
[30194]24#include <QApplication>
25#include <QEvent>
[25177]26#include <QObject>
27
28template <class Base>
29class QIWithRetranslateUI: public Base
30{
31public:
32
[26636]33 QIWithRetranslateUI(QWidget *pParent = 0) : Base(pParent) {}
[25177]34
35protected:
36
[26636]37 virtual void changeEvent(QEvent *pEvent)
[25177]38 {
[26636]39 Base::changeEvent (pEvent);
40 switch (pEvent->type())
[25177]41 {
42 case QEvent::LanguageChange:
43 {
44 retranslateUi();
[26636]45 pEvent->accept();
[25177]46 break;
47 }
[26502]48 default:
[25177]49 break;
50 }
51 }
52
53 virtual void retranslateUi() = 0;
54};
55
56template <class Base>
57class QIWithRetranslateUI2: public Base
58{
59public:
60
[26636]61 QIWithRetranslateUI2(QWidget *pParent = 0, Qt::WindowFlags fFlags = 0) : Base(pParent, fFlags) {}
[26502]62
[25177]63protected:
64
[26636]65 virtual void changeEvent(QEvent *pEvent)
[25177]66 {
[26636]67 Base::changeEvent (pEvent);
68 switch (pEvent->type())
[25177]69 {
70 case QEvent::LanguageChange:
71 {
72 retranslateUi();
[26636]73 pEvent->accept();
[25177]74 break;
75 }
[26502]76 default:
[25177]77 break;
78 }
79 }
80
81 virtual void retranslateUi() = 0;
82};
83
[26636]84template <class Base>
85class QIWithRetranslateUI3: public Base
86{
87public:
88
[30194]89 QIWithRetranslateUI3(QObject *pParent = 0)
90 : Base(pParent)
91 {
92 qApp->installEventFilter(this);
93 }
[26636]94
95protected:
96
[30194]97 virtual bool eventFilter(QObject *pObject, QEvent *pEvent)
[26636]98 {
99 switch (pEvent->type())
100 {
101 case QEvent::LanguageChange:
102 {
103 retranslateUi();
104 break;
105 }
106 default:
107 break;
108 }
[30194]109 return Base::eventFilter(pObject, pEvent);
[26636]110 }
111
112 virtual void retranslateUi() = 0;
113};
114
[25177]115#endif /* __QIWithRetranslateUI_h */
[26714]116
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use