VirtualBox

Changeset 71354 in vbox


Ignore:
Timestamp:
Mar 15, 2018 2:27:38 PM (7 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9049: A bit of refactoring and cleanup for QIWithRetranslateUI templates.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/QIWithRetranslateUI.h

    r69500 r71354  
    55
    66/*
    7  * Copyright (C) 2008-2017 Oracle Corporation
     7 * Copyright (C) 2008-2018 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    1616 */
    1717
    18 #ifndef __QIWithRetranslateUI_h
    19 #define __QIWithRetranslateUI_h
     18#ifndef ___QIWithRetranslateUI_h___
     19#define ___QIWithRetranslateUI_h___
    2020
    21 /* Global includes */
     21/* Qt includes: */
    2222#include <QApplication>
    2323#include <QEvent>
     24#include <QGraphicsWidget>
    2425#include <QObject>
    25 #include <QGraphicsWidget>
     26#include <QWidget>
    2627
     28
     29/** Template for automatic language translations of underlying QWidget. */
    2730template <class Base>
    28 class QIWithRetranslateUI: public Base
     31class QIWithRetranslateUI : public Base
    2932{
    3033public:
    3134
     35    /** Constructs translatable widget passing @a pParent to the base-class. */
    3236    QIWithRetranslateUI(QWidget *pParent = 0) : Base(pParent) {}
    3337
    3438protected:
    3539
     40    /** Handles standard Qt change @a pEvent. */
    3641    virtual void changeEvent(QEvent *pEvent)
    3742    {
    38         Base::changeEvent (pEvent);
     43        /* Call to base-class: */
     44        Base::changeEvent(pEvent);
     45        /* Handle LanguageChange events: */
    3946        switch (pEvent->type())
    4047        {
     
    5057    }
    5158
     59    /** Handles translation event. */
    5260    virtual void retranslateUi() = 0;
    5361};
    5462
     63
     64/** Template for automatic language translations of underlying QWidget with certain flags. */
    5565template <class Base>
    56 class QIWithRetranslateUI2: public Base
     66class QIWithRetranslateUI2 : public Base
    5767{
    5868public:
    5969
     70    /** Constructs translatable widget passing @a pParent and @a fFlags to the base-class. */
    6071    QIWithRetranslateUI2(QWidget *pParent = 0, Qt::WindowFlags fFlags = 0) : Base(pParent, fFlags) {}
    6172
    6273protected:
    6374
     75    /** Handles standard Qt change @a pEvent. */
    6476    virtual void changeEvent(QEvent *pEvent)
    6577    {
    66         Base::changeEvent (pEvent);
     78        /* Call to base-class: */
     79        Base::changeEvent(pEvent);
     80        /* Handle LanguageChange events: */
    6781        switch (pEvent->type())
    6882        {
     
    7892    }
    7993
     94    /** Handles translation event. */
    8095    virtual void retranslateUi() = 0;
    8196};
    8297
     98
     99/** Template for automatic language translations of underlying QObject. */
    83100template <class Base>
    84 class QIWithRetranslateUI3: public Base
     101class QIWithRetranslateUI3 : public Base
    85102{
    86103public:
    87104
     105    /** Constructs translatable widget passing @a pParent to the base-class. */
    88106    QIWithRetranslateUI3(QObject *pParent = 0)
    89107        : Base(pParent)
     
    94112protected:
    95113
     114    /** Pre-handles standard Qt @a pEvent for passed @a pObject. */
    96115    virtual bool eventFilter(QObject *pObject, QEvent *pEvent)
    97116    {
    98         /* Handle events for qApp only: */
     117        /* Handle LanguageChange events for qApp only: */
    99118        if (pObject == qApp)
    100119        {
     
    109128    }
    110129
     130    /** Handles translation event. */
    111131    virtual void retranslateUi() = 0;
    112132};
    113133
     134
     135/** Template for automatic language translations of underlying QGraphicsWidget. */
    114136template <class Base>
    115 class QIWithRetranslateUI4: public Base
     137class QIWithRetranslateUI4 : public Base
    116138{
    117139public:
    118140
     141    /** Constructs translatable widget passing @a pParent to the base-class. */
    119142    QIWithRetranslateUI4(QGraphicsWidget *pParent = 0)
    120143        : Base(pParent)
     
    125148protected:
    126149
     150    /** Pre-handles standard Qt @a pEvent for passed @a pObject. */
    127151    virtual bool eventFilter(QObject *pObject, QEvent *pEvent)
    128152    {
     153        /* Handle LanguageChange events: */
    129154        switch (pEvent->type())
    130155        {
    131             case QEvent::LanguageChange:
    132             {
    133                 retranslateUi();
    134                 break;
    135             }
    136             default:
    137                 break;
     156            case QEvent::LanguageChange: retranslateUi(); break;
     157            default: break;
    138158        }
     159        /* Call to base-class: */
    139160        return Base::eventFilter(pObject, pEvent);
    140161    }
    141162
     163    /** Handles translation event. */
    142164    virtual void retranslateUi() = 0;
    143165};
    144166
    145 #endif /* __QIWithRetranslateUI_h */
    146167
     168#endif /* !___QIWithRetranslateUI_h___ */
     169
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette