1 | /* $Id: UITranslationEventListener.cpp 103920 2024-03-19 14:40:59Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UITranslationEventListener class implementation.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2023 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.virtualbox.org.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or
|
---|
13 | * modify it under the terms of the GNU General Public License
|
---|
14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
15 | * License.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful, but
|
---|
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | * General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | *
|
---|
25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
26 | */
|
---|
27 |
|
---|
28 | /* Qt includes: */
|
---|
29 | #include <QApplication>
|
---|
30 |
|
---|
31 | /* GUI includes: */
|
---|
32 | #include "UITranslationEventListener.h"
|
---|
33 | #include "UITranslator.h"
|
---|
34 |
|
---|
35 | /* static */
|
---|
36 | UITranslationEventListener *UITranslationEventListener::s_pInstance = 0;
|
---|
37 |
|
---|
38 | UITranslationEventListener *UITranslationEventListener::instance()
|
---|
39 | {
|
---|
40 | return s_pInstance;
|
---|
41 | }
|
---|
42 |
|
---|
43 | /* static */
|
---|
44 | void UITranslationEventListener::create()
|
---|
45 | {
|
---|
46 | /* Make sure instance is NOT created yet: */
|
---|
47 | if (s_pInstance)
|
---|
48 | return;
|
---|
49 |
|
---|
50 | /* Create instance: */
|
---|
51 | new UITranslationEventListener;
|
---|
52 | }
|
---|
53 |
|
---|
54 | /* static */
|
---|
55 | void UITranslationEventListener::destroy()
|
---|
56 | {
|
---|
57 | /* Make sure instance is NOT destroyed yet: */
|
---|
58 | if (!s_pInstance)
|
---|
59 | return;
|
---|
60 |
|
---|
61 | /* Destroy instance: */
|
---|
62 | delete s_pInstance;
|
---|
63 | }
|
---|
64 |
|
---|
65 |
|
---|
66 | UITranslationEventListener::UITranslationEventListener(QObject *pParent /* = 0 */)
|
---|
67 | :QObject(pParent)
|
---|
68 | {
|
---|
69 | qApp->installEventFilter(this);
|
---|
70 | s_pInstance = this;
|
---|
71 | }
|
---|
72 |
|
---|
73 | UITranslationEventListener::~UITranslationEventListener()
|
---|
74 | {
|
---|
75 | s_pInstance = 0;
|
---|
76 | }
|
---|
77 |
|
---|
78 | bool UITranslationEventListener::eventFilter(QObject *pObject, QEvent *pEvent)
|
---|
79 | {
|
---|
80 | if ( !UITranslator::isTranslationInProgress()
|
---|
81 | && pEvent->type() == QEvent::LanguageChange)
|
---|
82 | {
|
---|
83 | //&& (pObject == qApp || pObject == this))
|
---|
84 | emit sigRetranslateUI();
|
---|
85 | }
|
---|
86 | /* Call to base-class: */
|
---|
87 | return QObject::eventFilter(pObject, pEvent);
|
---|
88 | }
|
---|