Changeset 85661 in vbox
- Timestamp:
- Aug 10, 2020 12:04:07 PM (5 years ago)
- svn:sync-xref-src-repo-rev:
- 139788
- 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 2308 2308 } 2309 2309 2310 UIActionPool::UIActionPool(UIActionPoolType enmType, bool fTemporary /* = false */)2311 : m_enmType(enmType)2312 , m_fTemporary(fTemporary)2313 {2314 }2315 2316 2310 UIActionPoolManager *UIActionPool::toManager() 2317 2311 { … … 2322 2316 { 2323 2317 return qobject_cast<UIActionPoolRuntime*>(this); 2318 } 2319 2320 UIAction *UIActionPool::action(int iIndex) const 2321 { 2322 AssertReturn(m_pool.contains(iIndex), 0); 2323 return m_pool.value(iIndex); 2324 } 2325 2326 QList<UIAction*> UIActionPool::actions() const 2327 { 2328 return m_pool.values(); 2324 2329 } 2325 2330 … … 2386 2391 m_restrictedActionsMenuHelp[enmLevel] = enmRestriction; 2387 2392 m_invalidations << UIActionIndex_Menu_Help; 2393 } 2394 2395 bool 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; 2388 2424 } 2389 2425 … … 2422 2458 #endif /* VBOX_WS_MAC */ 2423 2459 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(); 2460 UIActionPool::UIActionPool(UIActionPoolType enmType, bool fTemporary /* = false */) 2461 : m_enmType(enmType) 2462 , m_fTemporary(fTemporary) 2463 { 2434 2464 } 2435 2465 … … 2529 2559 m_invalidations.unite(m_menuUpdateHandlers.keys().toSet()); 2530 2560 2531 /* Retranslate finally: */2561 /* Apply language settings: */ 2532 2562 retranslateUi(); 2533 2563 } … … 2566 2596 } 2567 2597 2598 void UIActionPool::cleanupConnections() 2599 { 2600 /* Nothing for now.. */ 2601 } 2602 2568 2603 void UIActionPool::cleanupPool() 2569 2604 { 2570 2605 qDeleteAll(m_groupPool); 2571 2606 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 calling2602 * pAction->trigger() directly, to let key presses and2603 * releases be processed correctly by Qt first.2604 * Note: we assume that nobody will delete the menu item2605 * corresponding to the key sequence, so that the pointer to2606 * menu data posted along with the event will remain valid in2607 * 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;2614 2607 } 2615 2608 … … 2643 2636 && m_menuUpdateHandlers.contains(iIndex)) 2644 2637 (this->*(m_menuUpdateHandlers.value(iIndex).ptf))(); 2638 } 2639 2640 void UIActionPool::updateShortcuts() 2641 { 2642 gShortcutPool->applyShortcuts(this); 2643 } 2644 2645 bool 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 2665 void 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 2674 bool 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 2711 bool 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; 2645 2753 } 2646 2754 … … 2890 2998 } 2891 2999 2892 void UIActionPool::retranslateUi() 2893 { 2894 /* Translate all the actions: */ 2895 foreach (const int iActionPoolKey, m_pool.keys()) 2896 m_pool[iActionPoolKey]->retranslateUi(); 3000 void UIActionPool::prepare() 3001 { 3002 /* Prepare pool: */ 3003 preparePool(); 3004 /* Prepare connections: */ 3005 prepareConnections(); 3006 3007 /* Update configuration: */ 3008 updateConfiguration(); 2897 3009 /* Update shortcuts: */ 2898 3010 updateShortcuts(); 2899 3011 } 2900 3012 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; 3013 void UIActionPool::cleanup() 3014 { 3015 /* Cleanup connections: */ 3016 cleanupConnections(); 3017 /* Cleanup pool: */ 3018 cleanupPool(); 3000 3019 } 3001 3020 -
trunk/src/VBox/Frontends/VirtualBox/src/globals/UIActionPool.h
r85642 r85661 476 476 /** Returns action-pool type. */ 477 477 UIActionPoolType type() const { return m_enmType; } 478 /** Returns whether this action-pool is temporary. */ 479 bool isTemporary() const { return m_fTemporary; } 478 480 479 481 /** 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; 481 483 /** Returns all the actions action-pool contains. */ 482 QList<UIAction*> actions() const { return m_pool.values(); }484 QList<UIAction*> actions() const; 483 485 484 486 /** Returns the action group for the passed @a iIndex. … … 516 518 /** Defines whether shortcuts of menu actions with specified @a iIndex should be visible. */ 517 519 virtual void setShortcutsVisible(int iIndex, bool fVisible) { Q_UNUSED(iIndex); Q_UNUSED(fVisible); } 518 519 520 /** Returns extra-data ID to save keyboard shortcuts under. */ 520 521 virtual QString shortcutsExtraDataID() const = 0; … … 540 541 UIActionPool(UIActionPoolType enmType, bool fTemporary = false); 541 542 542 /** Prepares all. */543 void prepare();544 543 /** Prepares pool. */ 545 544 virtual void preparePool(); … … 547 546 virtual void prepareConnections(); 548 547 /** Cleanups connections. */ 549 virtual void cleanupConnections() {}548 virtual void cleanupConnections(); 550 549 /** Cleanups pool. */ 551 550 virtual void cleanupPool(); 552 /** Cleanups all. */553 void cleanup();554 551 555 552 /** Updates configuration. */ … … 560 557 /** Updates menus. */ 561 558 virtual void updateMenus() = 0; 562 /** Updates 'Application' menu. */563 virtual void updateMenuApplication();564 #ifdef VBOX_WS_MAC565 /** Mac OS X: Updates 'Window' menu. */566 virtual void updateMenuWindow();567 #endif568 /** 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);582 559 583 560 /** Updates shortcuts. */ 584 561 virtual void updateShortcuts(); 585 562 563 /** Handles any Qt @a pEvent */ 564 virtual bool event(QEvent *pEvent) /* override */; 565 586 566 /** Handles translation event. */ 587 567 virtual void retranslateUi() /* override */; 588 589 /** Handles any Qt @a pEvent */590 virtual bool event(QEvent *pEvent) /* override */;591 568 592 569 /** Adds action into corresponding menu. */ … … 595 572 bool addMenu(QList<QMenu*> &menuList, UIAction *pAction, bool fReallyAdd = true); 596 573 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); 601 594 602 595 /** Holds the map of actions. */ … … 623 616 /** Holds restricted action types of the Help menu. */ 624 617 QMap<UIActionRestrictionLevel, UIExtraDataMetaDefs::MenuHelpActionType> m_restrictedActionsMenuHelp; 618 619 private: 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; 625 630 }; 626 631 -
trunk/src/VBox/Frontends/VirtualBox/src/globals/UIActionPoolManager.cpp
r85644 r85661 4225 4225 UIActionPool::updateShortcuts(); 4226 4226 /* Create temporary Runtime UI pool to do the same: */ 4227 if (! m_fTemporary)4227 if (!isTemporary()) 4228 4228 UIActionPool::createTemporary(UIActionPoolType_Runtime); 4229 4229 } -
trunk/src/VBox/Frontends/VirtualBox/src/globals/UIActionPoolRuntime.cpp
r85599 r85661 4361 4361 UIActionPool::updateShortcuts(); 4362 4362 /* Create temporary Manager UI pool to do the same: */ 4363 if (! m_fTemporary)4363 if (!isTemporary()) 4364 4364 UIActionPool::createTemporary(UIActionPoolType_Manager); 4365 4365 }
Note:
See TracChangeset
for help on using the changeset viewer.