VirtualBox

Changeset 77844 in vbox


Ignore:
Timestamp:
Mar 22, 2019 10:41:16 AM (6 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9241: VirtualBox Manager: Chooser pane: Restore lost shift item functionality.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserHandlerKeyboard.cpp

    r77752 r77844  
    2323#include "UIChooserModel.h"
    2424#include "UIChooserItemGroup.h"
     25#include "UIChooserItemMachine.h"
     26#include "UIChooserNodeGroup.h"
     27#include "UIChooserNodeMachine.h"
    2528
    2629
     
    327330}
    328331
    329 void UIChooserHandlerKeyboard::shift(UIItemShiftDirection direction, UIItemShiftSize size) const
    330 {
    331     Q_UNUSED(direction);
    332     Q_UNUSED(size);
    333     /// @todo implement item shifting
    334 
    335 #if 0
    336     /* Get focus-item and his parent: */
    337     UIChooserItem *pFocusItem = model()->focusItem();
    338     UIChooserItem *pParentItem = pFocusItem->parentItem();
    339     /* Get the list of focus-item neighbours: */
    340     UIChooserItemType type = (UIChooserItemType)pFocusItem->type();
    341     QList<UIChooserItem*> items = pParentItem->items(type);
    342     /* Get focus-item position: */
    343     int iFocusPosition = items.indexOf(pFocusItem);
    344 
    345     /* Depending on direction: */
    346     switch (direction)
     332void UIChooserHandlerKeyboard::shift(UIItemShiftDirection enmDirection, UIItemShiftType enmShiftType) const
     333{
     334    /* Get focus-node and its parent: */
     335    UIChooserNode *pFocusNode = model()->focusItem()->node();
     336    UIChooserNode *pParentNode = pFocusNode->parentNode();
     337    /* Get focus-node position: */
     338    const int iFocusNodePosition = pFocusNode->position();
     339
     340    /* Calculate new position: */
     341    int iNewFocusNodePosition = -1;
     342    switch (enmDirection)
    347343    {
    348344        case UIItemShiftDirection_Up:
    349345        {
    350             /* Is focus-item shiftable? */
    351             if (iFocusPosition == 0)
    352                 return;
    353             /* Shift item: */
    354             switch (size)
    355             {
    356                 case UIItemShiftSize_Item: items.move(iFocusPosition, iFocusPosition - 1); break;
    357                 case UIItemShiftSize_Full: items.move(iFocusPosition, 0); break;
    358                 default: break;
    359             }
     346            if (iFocusNodePosition > 0)
     347                switch (enmShiftType)
     348                {
     349                    case UIItemShiftSize_Item: iNewFocusNodePosition = iFocusNodePosition - 1; break;
     350                    case UIItemShiftSize_Full: iNewFocusNodePosition = 0; break;
     351                    default: break;
     352                }
    360353            break;
    361354        }
    362355        case UIItemShiftDirection_Down:
    363356        {
    364             /* Is focus-item shiftable? */
    365             if (iFocusPosition == items.size() - 1)
    366                 return;
    367             /* Shift item: */
    368             switch (size)
    369             {
    370                 case UIItemShiftSize_Item: items.move(iFocusPosition, iFocusPosition + 1); break;
    371                 case UIItemShiftSize_Full: items.move(iFocusPosition, items.size() - 1); break;
    372                 default: break;
    373             }
     357            if (iFocusNodePosition < pParentNode->nodes(pFocusNode->type()).size() - 1)
     358                switch (enmShiftType)
     359                {
     360                    case UIItemShiftSize_Item: iNewFocusNodePosition = iFocusNodePosition + 2; break;
     361                    case UIItemShiftSize_Full: iNewFocusNodePosition = pParentNode->nodes(pFocusNode->type()).size();  break;
     362                    default: break;
     363                }
    374364            break;
    375365        }
     
    377367            break;
    378368    }
    379 
    380     /* Reassign items: */
    381     pParentItem->setItems(items, type);
     369    /* Filter out invalid requests: */
     370    if (iNewFocusNodePosition == -1)
     371        return;
     372
     373    /* Create shifted node/item: */
     374    UIChooserItem *pShiftedItem = 0;
     375    switch (pFocusNode->type())
     376    {
     377        case UIChooserItemType_Group:
     378        {
     379            UIChooserNodeGroup *pNewNode = new UIChooserNodeGroup(pParentNode, pFocusNode->toGroupNode(), iNewFocusNodePosition);
     380            pShiftedItem = new UIChooserItemGroup(pParentNode->item(), pNewNode);
     381            break;
     382        }
     383        case UIChooserItemType_Machine:
     384        {
     385            UIChooserNodeMachine *pNewNode = new UIChooserNodeMachine(pParentNode, pFocusNode->toMachineNode(), iNewFocusNodePosition);
     386            pShiftedItem = new UIChooserItemMachine(pParentNode->item(), pNewNode);
     387            break;
     388        }
     389        default:
     390            break;
     391    }
     392
     393    /* Delete old node/item: */
     394    delete pFocusNode;
     395
    382396    /* Update model: */
     397    model()->wipeOutEmptyGroups();
    383398    model()->updateNavigation();
    384399    model()->updateLayout();
    385 #endif
    386 }
     400    model()->setCurrentItem(pShiftedItem);
     401    model()->saveGroupSettings();
     402}
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserHandlerKeyboard.h

    r76581 r77844  
    4444};
    4545
    46 /* Item shift size: */
    47 enum UIItemShiftSize
     46/** Item shift types. */
     47enum UIItemShiftType
    4848{
    4949    UIItemShiftSize_Item,
     
    7474
    7575    /* Helper: Item shift delegate: */
    76     void shift(UIItemShiftDirection direction, UIItemShiftSize size) const;
     76    void shift(UIItemShiftDirection enmDirection, UIItemShiftType enmShiftType) const;
    7777
    7878    /* Variables: */
    7979    UIChooserModel *m_pModel;
    80     QMap<int, UIItemShiftSize> m_shiftMap;
     80    QMap<int, UIItemShiftType> m_shiftMap;
    8181};
    8282
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