source: calamares/trunk/fuentes/src/libcalamares/utils/Retranslator.cpp @ 7538

Last change on this file since 7538 was 7538, checked in by kbut, 13 months ago

sync with github

File size: 1.8 KB
Line 
1/* === This file is part of Calamares - <https://github.com/calamares> ===
2 *
3 *   Copyright 2014, Teo Mrnjavac <teo@kde.org>
4 *
5 *   Calamares is free software: you can redistribute it and/or modify
6 *   it under the terms of the GNU General Public License as published by
7 *   the Free Software Foundation, either version 3 of the License, or
8 *   (at your option) any later version.
9 *
10 *   Calamares is distributed in the hope that it will be useful,
11 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
12 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 *   GNU General Public License for more details.
14 *
15 *   You should have received a copy of the GNU General Public License
16 *   along with Calamares. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#include "Retranslator.h"
20
21#include <QEvent>
22
23
24namespace CalamaresUtils {
25
26
27void
28Retranslator::attachRetranslator( QObject* parent,
29                                  std::function< void ( void ) > retranslateFunc )
30{
31    Retranslator* r = nullptr;
32    for ( QObject* child : parent->children() )
33    {
34        r = qobject_cast< Retranslator* >( child );
35        if ( r )
36            break;
37    }
38
39    if ( !r )
40        r = new Retranslator( parent );
41
42    r->m_retranslateFuncList.append( retranslateFunc );
43    retranslateFunc();
44}
45
46
47Retranslator::Retranslator( QObject* parent )
48    : QObject( parent )
49{
50    parent->installEventFilter( this );
51}
52
53
54bool
55Retranslator::eventFilter( QObject* obj, QEvent* e )
56{
57    if ( obj == parent() )
58    {
59        if ( e->type() == QEvent::LanguageChange )
60        {
61            foreach ( std::function< void() > func, m_retranslateFuncList )
62                func();
63        }
64    }
65    // pass the event on to the base
66    return QObject::eventFilter( obj, e );
67}
68
69
70} // namespace CalamaresUtils
Note: See TracBrowser for help on using the repository browser.