VirtualBox

Changeset 77992 in vbox for trunk


Ignore:
Timestamp:
Apr 3, 2019 2:35:45 PM (6 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9432: Moving QIWithRetranslateUI templates onto eventFilter basis; changeEvent handler was too global for our needs and that caused even local LanguageChange events to call for whole app retranslation sequence.

File:
1 edited

Legend:

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

    r77568 r77992  
    4040
    4141    /** Constructs translatable widget passing @a pParent to the base-class. */
    42     QIWithRetranslateUI(QWidget *pParent = 0) : Base(pParent) {}
     42    QIWithRetranslateUI(QWidget *pParent = 0) : Base(pParent)
     43    {
     44        qApp->installEventFilter(this);
     45    }
    4346
    4447protected:
    4548
    46     /** Handles standard Qt change @a pEvent. */
    47     virtual void changeEvent(QEvent *pEvent)
     49    /** Pre-handles standard Qt @a pEvent for passed @a pObject. */
     50    virtual bool eventFilter(QObject *pObject, QEvent *pEvent)
    4851    {
     52        /* Handle LanguageChange events for qApp or this object: */
     53        if (pObject == qApp || pObject == this)
     54        {
     55            switch (pEvent->type())
     56            {
     57                case QEvent::LanguageChange: retranslateUi(); break;
     58                default: break;
     59            }
     60        }
    4961        /* Call to base-class: */
    50         Base::changeEvent(pEvent);
    51         /* Handle LanguageChange events: */
    52         switch (pEvent->type())
    53         {
    54             case QEvent::LanguageChange:
    55             {
    56                 retranslateUi();
    57                 pEvent->accept();
    58                 break;
    59             }
    60             default:
    61                 break;
    62         }
     62        return Base::eventFilter(pObject, pEvent);
    6363    }
    6464
     
    8484
    8585    /** Constructs translatable widget passing @a pParent and @a fFlags to the base-class. */
    86     QIWithRetranslateUI2(QWidget *pParent = 0, Qt::WindowFlags fFlags = 0) : Base(pParent, fFlags) {}
     86    QIWithRetranslateUI2(QWidget *pParent = 0, Qt::WindowFlags fFlags = 0) : Base(pParent, fFlags)
     87    {
     88        qApp->installEventFilter(this);
     89    }
    8790
    8891protected:
    8992
    90     /** Handles standard Qt change @a pEvent. */
    91     virtual void changeEvent(QEvent *pEvent)
     93    /** Pre-handles standard Qt @a pEvent for passed @a pObject. */
     94    virtual bool eventFilter(QObject *pObject, QEvent *pEvent)
    9295    {
     96        /* Handle LanguageChange events for qApp or this object: */
     97        if (pObject == qApp || pObject == this)
     98        {
     99            switch (pEvent->type())
     100            {
     101                case QEvent::LanguageChange: retranslateUi(); break;
     102                default: break;
     103            }
     104        }
    93105        /* Call to base-class: */
    94         Base::changeEvent(pEvent);
    95         /* Handle LanguageChange events: */
    96         switch (pEvent->type())
    97         {
    98             case QEvent::LanguageChange:
    99             {
    100                 retranslateUi();
    101                 pEvent->accept();
    102                 break;
    103             }
    104             default:
    105                 break;
    106         }
     106        return Base::eventFilter(pObject, pEvent);
    107107    }
    108108
     
    130130    virtual bool eventFilter(QObject *pObject, QEvent *pEvent)
    131131    {
    132         /* Handle LanguageChange events for qApp only: */
    133         if (pObject == qApp)
     132        /* Handle LanguageChange events for qApp or this object: */
     133        if (pObject == qApp || pObject == this)
    134134        {
    135135            switch (pEvent->type())
     
    175175    virtual bool eventFilter(QObject *pObject, QEvent *pEvent)
    176176    {
    177         /* Handle LanguageChange events: */
    178         switch (pEvent->type())
     177        /* Handle LanguageChange events for qApp or this object: */
     178        if (pObject == qApp || pObject == this)
    179179        {
    180             case QEvent::LanguageChange: retranslateUi(); break;
    181             default: break;
     180            /* Handle LanguageChange events: */
     181            switch (pEvent->type())
     182            {
     183                case QEvent::LanguageChange: retranslateUi(); break;
     184                default: break;
     185            }
    182186        }
    183187        /* Call to base-class: */
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