VirtualBox

Changeset 85661 in vbox


Ignore:
Timestamp:
Aug 10, 2020 12:04:07 PM (5 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
139788
Message:

FE/Qt: bugref:9609: Cleanup for action-pool stuff: Lots of code reordering.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/globals
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIActionPool.cpp

    r85642 r85661  
    23082308}
    23092309
    2310 UIActionPool::UIActionPool(UIActionPoolType enmType, bool fTemporary /* = false */)
    2311     : m_enmType(enmType)
    2312     , m_fTemporary(fTemporary)
    2313 {
    2314 }
    2315 
    23162310UIActionPoolManager *UIActionPool::toManager()
    23172311{
     
    23222316{
    23232317    return qobject_cast<UIActionPoolRuntime*>(this);
     2318}
     2319
     2320UIAction *UIActionPool::action(int iIndex) const
     2321{
     2322    AssertReturn(m_pool.contains(iIndex), 0);
     2323    return m_pool.value(iIndex);
     2324}
     2325
     2326QList<UIAction*> UIActionPool::actions() const
     2327{
     2328    return m_pool.values();
    23242329}
    23252330
     
    23862391    m_restrictedActionsMenuHelp[enmLevel] = enmRestriction;
    23872392    m_invalidations << UIActionIndex_Menu_Help;
     2393}
     2394
     2395bool UIActionPool::processHotKey(const QKeySequence &key)
     2396{
     2397    /* Iterate through the whole list of keys: */
     2398    foreach (const int &iKey, m_pool.keys())
     2399    {
     2400        /* Get current action: */
     2401        UIAction *pAction = m_pool.value(iKey);
     2402        /* Skip menus/separators: */
     2403        if (pAction->type() == UIActionType_Menu)
     2404            continue;
     2405        /* Get the hot-key of the current action: */
     2406        const QString strHotKey = gShortcutPool->shortcut(this, pAction).primaryToPortableText();
     2407        if (pAction->isEnabled() && pAction->isAllowed() && !strHotKey.isEmpty())
     2408        {
     2409            if (key.matches(QKeySequence(strHotKey)) == QKeySequence::ExactMatch)
     2410            {
     2411                /* We asynchronously post a special event instead of calling
     2412                 * pAction->trigger() directly, to let key presses and
     2413                 * releases be processed correctly by Qt first.
     2414                 * Note: we assume that nobody will delete the menu item
     2415                 * corresponding to the key sequence, so that the pointer to
     2416                 * menu data posted along with the event will remain valid in
     2417                 * the event handler, at least until the main window is closed. */
     2418                QApplication::postEvent(this, new ActivateActionEvent(pAction));
     2419                return true;
     2420            }
     2421        }
     2422    }
     2423    return false;
    23882424}
    23892425
     
    24222458#endif /* VBOX_WS_MAC */
    24232459
    2424 void UIActionPool::prepare()
    2425 {
    2426     /* Prepare pool: */
    2427     preparePool();
    2428     /* Prepare connections: */
    2429     prepareConnections();
    2430     /* Update configuration: */
    2431     updateConfiguration();
    2432     /* Update shortcuts: */
    2433     updateShortcuts();
     2460UIActionPool::UIActionPool(UIActionPoolType enmType, bool fTemporary /* = false */)
     2461    : m_enmType(enmType)
     2462    , m_fTemporary(fTemporary)
     2463{
    24342464}
    24352465
     
    25292559    m_invalidations.unite(m_menuUpdateHandlers.keys().toSet());
    25302560
    2531     /* Retranslate finally: */
     2561    /* Apply language settings: */
    25322562    retranslateUi();
    25332563}
     
    25662596}
    25672597
     2598void UIActionPool::cleanupConnections()
     2599{
     2600    /* Nothing for now.. */
     2601}
     2602
    25682603void UIActionPool::cleanupPool()
    25692604{
    25702605    qDeleteAll(m_groupPool);
    25712606    qDeleteAll(m_pool);
    2572 }
    2573 
    2574 void UIActionPool::cleanup()
    2575 {
    2576     /* Cleanup pool: */
    2577     cleanupPool();
    2578 }
    2579 
    2580 void UIActionPool::updateShortcuts()
    2581 {
    2582     gShortcutPool->applyShortcuts(this);
    2583 }
    2584 
    2585 bool UIActionPool::processHotKey(const QKeySequence &key)
    2586 {
    2587     /* Iterate through the whole list of keys: */
    2588     foreach (const int &iKey, m_pool.keys())
    2589     {
    2590         /* Get current action: */
    2591         UIAction *pAction = m_pool.value(iKey);
    2592         /* Skip menus/separators: */
    2593         if (pAction->type() == UIActionType_Menu)
    2594             continue;
    2595         /* Get the hot-key of the current action: */
    2596         const QString strHotKey = gShortcutPool->shortcut(this, pAction).primaryToPortableText();
    2597         if (pAction->isEnabled() && pAction->isAllowed() && !strHotKey.isEmpty())
    2598         {
    2599             if (key.matches(QKeySequence(strHotKey)) == QKeySequence::ExactMatch)
    2600             {
    2601                 /* We asynchronously post a special event instead of calling
    2602                  * pAction->trigger() directly, to let key presses and
    2603                  * releases be processed correctly by Qt first.
    2604                  * Note: we assume that nobody will delete the menu item
    2605                  * corresponding to the key sequence, so that the pointer to
    2606                  * menu data posted along with the event will remain valid in
    2607                  * the event handler, at least until the main window is closed. */
    2608                 QApplication::postEvent(this, new ActivateActionEvent(pAction));
    2609                 return true;
    2610             }
    2611         }
    2612     }
    2613     return false;
    26142607}
    26152608
     
    26432636        && m_menuUpdateHandlers.contains(iIndex))
    26442637        (this->*(m_menuUpdateHandlers.value(iIndex).ptf))();
     2638}
     2639
     2640void UIActionPool::updateShortcuts()
     2641{
     2642    gShortcutPool->applyShortcuts(this);
     2643}
     2644
     2645bool UIActionPool::event(QEvent *pEvent)
     2646{
     2647    /* Depending on event-type: */
     2648    switch ((UIEventType)pEvent->type())
     2649    {
     2650        case ActivateActionEventType:
     2651        {
     2652            /* Process specific event: */
     2653            ActivateActionEvent *pActionEvent = static_cast<ActivateActionEvent*>(pEvent);
     2654            pActionEvent->action()->trigger();
     2655            pEvent->accept();
     2656            return true;
     2657        }
     2658        default:
     2659            break;
     2660    }
     2661    /* Pass to the base-class: */
     2662    return QObject::event(pEvent);
     2663}
     2664
     2665void UIActionPool::retranslateUi()
     2666{
     2667    /* Translate all the actions: */
     2668    foreach (const int iActionPoolKey, m_pool.keys())
     2669        m_pool[iActionPoolKey]->retranslateUi();
     2670    /* Update shortcuts: */
     2671    updateShortcuts();
     2672}
     2673
     2674bool UIActionPool::addAction(UIMenu *pMenu, UIAction *pAction, bool fReallyAdd /* = true */)
     2675{
     2676    /* Check if action is allowed: */
     2677    const bool fIsActionAllowed = pAction->isAllowed();
     2678
     2679#ifdef VBOX_WS_MAC
     2680    /* Check if menu is consumable: */
     2681    const bool fIsMenuConsumable = pMenu->isConsumable();
     2682    /* Check if menu is NOT yet consumed: */
     2683    const bool fIsMenuConsumed = pMenu->isConsumed();
     2684#endif
     2685
     2686    /* Make this action visible
     2687     * depending on clearance state. */
     2688    pAction->setVisible(fIsActionAllowed);
     2689
     2690#ifdef VBOX_WS_MAC
     2691    /* If menu is consumable: */
     2692    if (fIsMenuConsumable)
     2693    {
     2694        /* Add action only if menu was not yet consumed: */
     2695        if (!fIsMenuConsumed)
     2696            pMenu->addAction(pAction);
     2697    }
     2698    /* If menu is NOT consumable: */
     2699    else
     2700#endif
     2701    {
     2702        /* Add action only if is allowed: */
     2703        if (fIsActionAllowed && fReallyAdd)
     2704            pMenu->addAction(pAction);
     2705    }
     2706
     2707    /* Return if action is allowed: */
     2708    return fIsActionAllowed;
     2709}
     2710
     2711bool UIActionPool::addMenu(QList<QMenu*> &menuList, UIAction *pAction, bool fReallyAdd /* = true */)
     2712{
     2713    /* Check if action is allowed: */
     2714    const bool fIsActionAllowed = pAction->isAllowed();
     2715
     2716    /* Get action's menu: */
     2717    UIMenu *pMenu = pAction->menu();
     2718
     2719#ifdef VBOX_WS_MAC
     2720    /* Check if menu is consumable: */
     2721    const bool fIsMenuConsumable = pMenu->isConsumable();
     2722    /* Check if menu is NOT yet consumed: */
     2723    const bool fIsMenuConsumed = pMenu->isConsumed();
     2724#endif
     2725
     2726    /* Make this action visible
     2727     * depending on clearance state. */
     2728    pAction->setVisible(   fIsActionAllowed
     2729#ifdef VBOX_WS_MAC
     2730                        && !fIsMenuConsumable
     2731#endif
     2732                        );
     2733
     2734#ifdef VBOX_WS_MAC
     2735    /* If menu is consumable: */
     2736    if (fIsMenuConsumable)
     2737    {
     2738        /* Add action's menu only if menu was not yet consumed: */
     2739        if (!fIsMenuConsumed)
     2740            menuList << pMenu;
     2741    }
     2742    /* If menu is NOT consumable: */
     2743    else
     2744#endif
     2745    {
     2746        /* Add action only if is allowed: */
     2747        if (fIsActionAllowed && fReallyAdd)
     2748            menuList << pMenu;
     2749    }
     2750
     2751    /* Return if action is allowed: */
     2752    return fIsActionAllowed;
    26452753}
    26462754
     
    28902998}
    28912999
    2892 void UIActionPool::retranslateUi()
    2893 {
    2894     /* Translate all the actions: */
    2895     foreach (const int iActionPoolKey, m_pool.keys())
    2896         m_pool[iActionPoolKey]->retranslateUi();
     3000void UIActionPool::prepare()
     3001{
     3002    /* Prepare pool: */
     3003    preparePool();
     3004    /* Prepare connections: */
     3005    prepareConnections();
     3006
     3007    /* Update configuration: */
     3008    updateConfiguration();
    28973009    /* Update shortcuts: */
    28983010    updateShortcuts();
    28993011}
    29003012
    2901 bool UIActionPool::event(QEvent *pEvent)
    2902 {
    2903     /* Depending on event-type: */
    2904     switch ((UIEventType)pEvent->type())
    2905     {
    2906         case ActivateActionEventType:
    2907         {
    2908             /* Process specific event: */
    2909             ActivateActionEvent *pActionEvent = static_cast<ActivateActionEvent*>(pEvent);
    2910             pActionEvent->action()->trigger();
    2911             pEvent->accept();
    2912             return true;
    2913         }
    2914         default:
    2915             break;
    2916     }
    2917     /* Pass to the base-class: */
    2918     return QObject::event(pEvent);
    2919 }
    2920 
    2921 bool UIActionPool::addAction(UIMenu *pMenu, UIAction *pAction, bool fReallyAdd /* = true */)
    2922 {
    2923     /* Check if action is allowed: */
    2924     const bool fIsActionAllowed = pAction->isAllowed();
    2925 
    2926 #ifdef VBOX_WS_MAC
    2927     /* Check if menu is consumable: */
    2928     const bool fIsMenuConsumable = pMenu->isConsumable();
    2929     /* Check if menu is NOT yet consumed: */
    2930     const bool fIsMenuConsumed = pMenu->isConsumed();
    2931 #endif
    2932 
    2933     /* Make this action visible
    2934      * depending on clearance state. */
    2935     pAction->setVisible(fIsActionAllowed);
    2936 
    2937 #ifdef VBOX_WS_MAC
    2938     /* If menu is consumable: */
    2939     if (fIsMenuConsumable)
    2940     {
    2941         /* Add action only if menu was not yet consumed: */
    2942         if (!fIsMenuConsumed)
    2943             pMenu->addAction(pAction);
    2944     }
    2945     /* If menu is NOT consumable: */
    2946     else
    2947 #endif
    2948     {
    2949         /* Add action only if is allowed: */
    2950         if (fIsActionAllowed && fReallyAdd)
    2951             pMenu->addAction(pAction);
    2952     }
    2953 
    2954     /* Return if action is allowed: */
    2955     return fIsActionAllowed;
    2956 }
    2957 
    2958 bool UIActionPool::addMenu(QList<QMenu*> &menuList, UIAction *pAction, bool fReallyAdd /* = true */)
    2959 {
    2960     /* Check if action is allowed: */
    2961     const bool fIsActionAllowed = pAction->isAllowed();
    2962 
    2963     /* Get action's menu: */
    2964     UIMenu *pMenu = pAction->menu();
    2965 
    2966 #ifdef VBOX_WS_MAC
    2967     /* Check if menu is consumable: */
    2968     const bool fIsMenuConsumable = pMenu->isConsumable();
    2969     /* Check if menu is NOT yet consumed: */
    2970     const bool fIsMenuConsumed = pMenu->isConsumed();
    2971 #endif
    2972 
    2973     /* Make this action visible
    2974      * depending on clearance state. */
    2975     pAction->setVisible(   fIsActionAllowed
    2976 #ifdef VBOX_WS_MAC
    2977                         && !fIsMenuConsumable
    2978 #endif
    2979                         );
    2980 
    2981 #ifdef VBOX_WS_MAC
    2982     /* If menu is consumable: */
    2983     if (fIsMenuConsumable)
    2984     {
    2985         /* Add action's menu only if menu was not yet consumed: */
    2986         if (!fIsMenuConsumed)
    2987             menuList << pMenu;
    2988     }
    2989     /* If menu is NOT consumable: */
    2990     else
    2991 #endif
    2992     {
    2993         /* Add action only if is allowed: */
    2994         if (fIsActionAllowed && fReallyAdd)
    2995             menuList << pMenu;
    2996     }
    2997 
    2998     /* Return if action is allowed: */
    2999     return fIsActionAllowed;
     3013void UIActionPool::cleanup()
     3014{
     3015    /* Cleanup connections: */
     3016    cleanupConnections();
     3017    /* Cleanup pool: */
     3018    cleanupPool();
    30003019}
    30013020
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIActionPool.h

    r85642 r85661  
    476476    /** Returns action-pool type. */
    477477    UIActionPoolType type() const { return m_enmType; }
     478    /** Returns whether this action-pool is temporary. */
     479    bool isTemporary() const { return m_fTemporary; }
    478480
    479481    /** Returns the action for the passed @a iIndex. */
    480     UIAction *action(int iIndex) const { return m_pool.value(iIndex); }
     482    UIAction *action(int iIndex) const;
    481483    /** Returns all the actions action-pool contains. */
    482     QList<UIAction*> actions() const { return m_pool.values(); }
     484    QList<UIAction*> actions() const;
    483485
    484486    /** Returns the action group for the passed @a iIndex.
     
    516518    /** Defines whether shortcuts of menu actions with specified @a iIndex should be visible. */
    517519    virtual void setShortcutsVisible(int iIndex, bool fVisible) { Q_UNUSED(iIndex); Q_UNUSED(fVisible); }
    518 
    519520    /** Returns extra-data ID to save keyboard shortcuts under. */
    520521    virtual QString shortcutsExtraDataID() const = 0;
     
    540541    UIActionPool(UIActionPoolType enmType, bool fTemporary = false);
    541542
    542     /** Prepares all. */
    543     void prepare();
    544543    /** Prepares pool. */
    545544    virtual void preparePool();
     
    547546    virtual void prepareConnections();
    548547    /** Cleanups connections. */
    549     virtual void cleanupConnections() {}
     548    virtual void cleanupConnections();
    550549    /** Cleanups pool. */
    551550    virtual void cleanupPool();
    552     /** Cleanups all. */
    553     void cleanup();
    554551
    555552    /** Updates configuration. */
     
    560557    /** Updates menus. */
    561558    virtual void updateMenus() = 0;
    562     /** Updates 'Application' menu. */
    563     virtual void updateMenuApplication();
    564 #ifdef VBOX_WS_MAC
    565     /** Mac OS X: Updates 'Window' menu. */
    566     virtual void updateMenuWindow();
    567 #endif
    568     /** Updates 'Help' menu. */
    569     virtual void updateMenuHelp();
    570     /** Updates 'Log Viewer Window' menu. */
    571     virtual void updateMenuLogViewerWindow();
    572     /** Updates 'Log Viewer' menu. */
    573     virtual void updateMenuLogViewer();
    574     /** Updates 'Log Viewer' @a pMenu. */
    575     virtual void updateMenuLogViewerWrapper(UIMenu *pMenu);
    576     /** Updates 'Performance Monitor' menu. */
    577     virtual void updateMenuPerformanceMonitor();
    578     /** Updates 'File Manager' menu. */
    579     virtual void updateMenuFileManager();
    580     /** Updates 'File Manager' @a pMenu. */
    581     virtual void updateMenuFileManagerWrapper(UIMenu *pMenu);
    582559
    583560    /** Updates shortcuts. */
    584561    virtual void updateShortcuts();
    585562
     563    /** Handles any Qt @a pEvent */
     564    virtual bool event(QEvent *pEvent) /* override */;
     565
    586566    /** Handles translation event. */
    587567    virtual void retranslateUi() /* override */;
    588 
    589     /** Handles any Qt @a pEvent */
    590     virtual bool event(QEvent *pEvent) /* override */;
    591568
    592569    /** Adds action into corresponding menu. */
     
    595572    bool addMenu(QList<QMenu*> &menuList, UIAction *pAction, bool fReallyAdd = true);
    596573
    597     /** Holds the action-pool type. */
    598     const UIActionPoolType  m_enmType;
    599     /** Holds whether this action-pool is temporary. */
    600     const bool              m_fTemporary;
     574    /** Updates 'Application' menu. */
     575    void updateMenuApplication();
     576#ifdef VBOX_WS_MAC
     577    /** Mac OS X: Updates 'Window' menu. */
     578    void updateMenuWindow();
     579#endif
     580    /** Updates 'Help' menu. */
     581    void updateMenuHelp();
     582    /** Updates 'Log Viewer Window' menu. */
     583    void updateMenuLogViewerWindow();
     584    /** Updates 'Log Viewer' menu. */
     585    void updateMenuLogViewer();
     586    /** Updates 'Log Viewer' @a pMenu. */
     587    void updateMenuLogViewerWrapper(UIMenu *pMenu);
     588    /** Updates 'Performance Monitor' menu. */
     589    void updateMenuPerformanceMonitor();
     590    /** Updates 'File Manager' menu. */
     591    void updateMenuFileManager();
     592    /** Updates 'File Manager' @a pMenu. */
     593    void updateMenuFileManagerWrapper(UIMenu *pMenu);
    601594
    602595    /** Holds the map of actions. */
     
    623616    /** Holds restricted action types of the Help menu. */
    624617    QMap<UIActionRestrictionLevel, UIExtraDataMetaDefs::MenuHelpActionType>         m_restrictedActionsMenuHelp;
     618
     619private:
     620
     621    /** Prepares all. */
     622    void prepare();
     623    /** Cleanups all. */
     624    void cleanup();
     625
     626    /** Holds the action-pool type. */
     627    const UIActionPoolType  m_enmType;
     628    /** Holds whether this action-pool is temporary. */
     629    const bool              m_fTemporary;
    625630};
    626631
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIActionPoolManager.cpp

    r85644 r85661  
    42254225    UIActionPool::updateShortcuts();
    42264226    /* Create temporary Runtime UI pool to do the same: */
    4227     if (!m_fTemporary)
     4227    if (!isTemporary())
    42284228        UIActionPool::createTemporary(UIActionPoolType_Runtime);
    42294229}
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIActionPoolRuntime.cpp

    r85599 r85661  
    43614361    UIActionPool::updateShortcuts();
    43624362    /* Create temporary Manager UI pool to do the same: */
    4363     if (!m_fTemporary)
     4363    if (!isTemporary())
    43644364        UIActionPool::createTemporary(UIActionPoolType_Manager);
    43654365}
Note: See TracChangeset for help on using the changeset viewer.

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