VirtualBox

Changeset 43539 in vbox


Ignore:
Timestamp:
Oct 4, 2012 12:41:57 PM (12 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
81140
Message:

FE/Qt: VM group feature UI: Current-item handling cleanup (part 2).

Location:
trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser/UIGChooserHandlerKeyboard.cpp

    r43054 r43539  
    116116                    model()->setFocusItem(pPreviousItem);
    117117                    /* Calculate positions: */
    118                     UIGChooserItem *pFirstItem = model()->selectionList().first();
     118                    UIGChooserItem *pFirstItem = model()->currentItem();
    119119                    int iFirstPosition = model()->navigationList().indexOf(pFirstItem);
    120120                    int iPreviousPosition = model()->navigationList().indexOf(pPreviousItem);
     
    124124                    if (iFirstPosition <= iPreviousPosition)
    125125                        for (int i = iFirstPosition; i <= iPreviousPosition; ++i)
    126                             model()->addToSelectionList(model()->navigationList().at(i));
     126                            model()->addToCurrentItems(model()->navigationList().at(i));
    127127                    else
    128128                        for (int i = iFirstPosition; i >= iPreviousPosition; --i)
    129                             model()->addToSelectionList(model()->navigationList().at(i));
     129                            model()->addToCurrentItems(model()->navigationList().at(i));
    130130                    /* Notify selection changed: */
    131                     model()->notifySelectionChanged();
     131                    model()->notifyCurrentItemChanged();
    132132                    /* Filter-out this event: */
    133133                    return true;
     
    160160                    /* Move selection to 'previous' item: */
    161161                    model()->clearSelectionList();
    162                     model()->addToSelectionList(pPreviousItem);
     162                    model()->addToCurrentItems(pPreviousItem);
    163163                    /* Notify selection changed: */
    164                     model()->notifySelectionChanged();
     164                    model()->notifyCurrentItemChanged();
    165165                    /* Filter-out this event: */
    166166                    return true;
     
    232232                    model()->setFocusItem(pNextItem);
    233233                    /* Calculate positions: */
    234                     UIGChooserItem *pFirstItem = model()->selectionList().first();
     234                    UIGChooserItem *pFirstItem = model()->currentItem();
    235235                    int iFirstPosition = model()->navigationList().indexOf(pFirstItem);
    236236                    int iNextPosition = model()->navigationList().indexOf(pNextItem);
     
    240240                    if (iFirstPosition <= iNextPosition)
    241241                        for (int i = iFirstPosition; i <= iNextPosition; ++i)
    242                             model()->addToSelectionList(model()->navigationList().at(i));
     242                            model()->addToCurrentItems(model()->navigationList().at(i));
    243243                    else
    244244                        for (int i = iFirstPosition; i >= iNextPosition; --i)
    245                             model()->addToSelectionList(model()->navigationList().at(i));
     245                            model()->addToCurrentItems(model()->navigationList().at(i));
    246246                    /* Notify selection changed: */
    247                     model()->notifySelectionChanged();
     247                    model()->notifyCurrentItemChanged();
    248248                    /* Filter-out this event: */
    249249                    return true;
     
    276276                    /* Move selection to 'next' item: */
    277277                    model()->clearSelectionList();
    278                     model()->addToSelectionList(pNextItem);
     278                    model()->addToCurrentItems(pNextItem);
    279279                    /* Notify selection changed: */
    280                     model()->notifySelectionChanged();
     280                    model()->notifyCurrentItemChanged();
    281281                    /* Filter-out this event: */
    282282                    return true;
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser/UIGChooserHandlerMouse.cpp

    r43154 r43539  
    7575                {
    7676                    /* Old selection list: */
    77                     QList<UIGChooserItem*> oldSelectionList = model()->selectionList();
     77                    QList<UIGChooserItem*> oldSelectionList = model()->currentItems();
    7878                    /* Move focus to clicked item: */
    7979                    model()->setFocusItem(pClickedItem);
     
    8282                    {
    8383                        /* Calculate positions: */
    84                         UIGChooserItem *pFirstItem = model()->selectionList().first();
     84                        UIGChooserItem *pFirstItem = model()->currentItem();
    8585                        int iFirstPosition = model()->navigationList().indexOf(pFirstItem);
    8686                        int iClickedPosition = model()->navigationList().indexOf(pClickedItem);
     
    9090                        if (iFirstPosition <= iClickedPosition)
    9191                            for (int i = iFirstPosition; i <= iClickedPosition; ++i)
    92                                 model()->addToSelectionList(model()->navigationList().at(i));
     92                                model()->addToCurrentItems(model()->navigationList().at(i));
    9393                        else
    9494                            for (int i = iFirstPosition; i >= iClickedPosition; --i)
    95                                 model()->addToSelectionList(model()->navigationList().at(i));
     95                                model()->addToCurrentItems(model()->navigationList().at(i));
    9696                    }
    9797                    /* Was 'control' modifier pressed? */
     
    9999                    {
    100100                        /* Select clicked item, inverting if necessary: */
    101                         if (model()->selectionList().contains(pClickedItem))
    102                             model()->removeFromSelectionList(pClickedItem);
     101                        if (model()->currentItems().contains(pClickedItem))
     102                            model()->removeFromCurrentItems(pClickedItem);
    103103                        else
    104                             model()->addToSelectionList(pClickedItem);
     104                            model()->addToCurrentItems(pClickedItem);
    105105                    }
    106106                    /* Was no modifiers pressed? */
     
    109109                        /* Move selection to clicked item: */
    110110                        model()->clearSelectionList();
    111                         model()->addToSelectionList(pClickedItem);
     111                        model()->addToCurrentItems(pClickedItem);
    112112                    }
    113113                    /* Selection list changed?: */
    114                     if (oldSelectionList != model()->selectionList())
    115                         model()->notifySelectionChanged();
     114                    if (oldSelectionList != model()->currentItems())
     115                        model()->notifyCurrentItemChanged();
    116116                }
    117117                break;
     
    135135                    {
    136136                        /* Is clicked item in selection list: */
    137                         bool fIsClickedItemInSelectionList = contains(model()->selectionList(), pClickedItem);
     137                        bool fIsClickedItemInSelectionList = contains(model()->currentItems(), pClickedItem);
    138138                        /* Move focus to clicked item (with selection if not selected yet): */
    139139                        model()->setFocusItem(pClickedItem, !fIsClickedItemInSelectionList);
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser/UIGChooserItemGroup.cpp

    r43505 r43539  
    169169    }
    170170    /* If that item is NOT focused, but selected: */
    171     else if (model()->selectionList().contains(this))
     171    else if (model()->currentItems().contains(this))
    172172    {
    173173        /* Remove item from the selection list: */
    174         model()->removeFromSelectionList(this);
     174        model()->removeFromCurrentItems(this);
    175175    }
    176176    /* Remove item from the navigation list: */
     
    12071207    QPalette pal = palette();
    12081208    QColor windowColor = pal.color(QPalette::Active,
    1209                                    model()->selectionList().contains(this) ?
     1209                                   model()->currentItems().contains(this) ?
    12101210                                   QPalette::Highlight : QPalette::Window);
    12111211
     
    13331333
    13341334    /* Update palette: */
    1335     if (model()->selectionList().contains(this))
     1335    if (model()->currentItems().contains(this))
    13361336    {
    13371337        QPalette pal = palette();
     
    13411341    /* Update buttons: */
    13421342    if (m_pToggleButton)
    1343         m_pToggleButton->setParentSelected(model()->selectionList().contains(this));
     1343        m_pToggleButton->setParentSelected(model()->currentItems().contains(this));
    13441344    if (m_pEnterButton)
    1345         m_pEnterButton->setParentSelected(model()->selectionList().contains(this));
     1345        m_pEnterButton->setParentSelected(model()->currentItems().contains(this));
    13461346    if (m_pExitButton)
    1347         m_pExitButton->setParentSelected(model()->selectionList().contains(this));
     1347        m_pExitButton->setParentSelected(model()->currentItems().contains(this));
    13481348
    13491349    /* Paint name: */
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser/UIGChooserItemMachine.cpp

    r43447 r43539  
    116116    }
    117117    /* If that item is NOT focused, but selected: */
    118     else if (model()->selectionList().contains(this))
     118    else if (model()->currentItems().contains(this))
    119119    {
    120120        /* Remove item from the selection list: */
    121         model()->removeFromSelectionList(this);
     121        model()->removeFromCurrentItems(this);
    122122    }
    123123    /* Remove item from the navigation list: */
     
    595595
    596596    /* Selection background: */
    597     if (model()->selectionList().contains(this))
     597    if (model()->currentItems().contains(this))
    598598    {
    599599        /* Prepare color: */
     
    622622    {
    623623        /* Window color: */
    624         QColor base = pal.color(QPalette::Active, model()->selectionList().contains(this) ?
     624        QColor base = pal.color(QPalette::Active, model()->currentItems().contains(this) ?
    625625                                QPalette::Highlight : QPalette::Window);
    626626        QLinearGradient dragTokenGradient;
     
    650650{
    651651    /* Only chosen and/or hovered item should have a frame: */
    652     if (!model()->selectionList().contains(this) && !isHovered())
     652    if (!model()->currentItems().contains(this) && !isHovered())
    653653        return;
    654654
     
    657657    QPalette pal = palette();
    658658    QColor hc = pal.color(QPalette::Active, QPalette::Highlight);
    659     if (model()->selectionList().contains(this))
     659    if (model()->currentItems().contains(this))
    660660        hc = hc.darker(strokeDarkness());
    661661    pPainter->setPen(hc);
     
    680680
    681681    /* Update palette: */
    682     if (model()->selectionList().contains(this))
     682    if (model()->currentItems().contains(this))
    683683    {
    684684        QPalette pal = palette();
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser/UIGChooserModel.cpp

    r43536 r43539  
    189189{
    190190    /* Search for the first selected machine: */
    191     return searchCurrentItem(selectionList());
     191    return searchCurrentItem(currentItems());
    192192}
    193193
     
    199199
    200200    /* Get first selected item: */
    201     UIGChooserItem *pSelectedItem = selectionList().isEmpty() ? 0 : selectionList().first();
     201    UIGChooserItem *pSelectedItem = currentItem();
    202202    /* Item exists? */
    203203    if (pSelectedItem)
     
    220220{
    221221    /* Populate list of selected machines: */
    222     QList<UIVMItem*> currentItemList;
    223     enumerateCurrentItems(selectionList(), currentItemList);
    224     return currentItemList;
    225 }
    226 
    227 const QList<UIGChooserItem*>& UIGChooserModel::selectionList() const
    228 {
    229     return m_selectionList;
     222    QList<UIVMItem*> currentMachineItemList;
     223    enumerateCurrentItems(currentItems(), currentMachineItemList);
     224    return currentMachineItemList;
     225}
     226
     227UIGChooserItem* UIGChooserModel::currentItem() const
     228{
     229    /* Return first of current items, if any: */
     230    return currentItems().isEmpty() ? 0 : currentItems().first();
     231}
     232
     233const QList<UIGChooserItem*>& UIGChooserModel::currentItems() const
     234{
     235    return m_currentItems;
    230236}
    231237
     
    309315}
    310316
    311 void UIGChooserModel::addToSelectionList(UIGChooserItem *pItem)
     317void UIGChooserModel::addToCurrentItems(UIGChooserItem *pItem)
    312318{
    313319    AssertMsg(pItem, ("Passed item is invalid!"));
    314     m_selectionList << pItem;
     320    m_currentItems << pItem;
    315321    pItem->update();
    316322}
    317323
    318 void UIGChooserModel::removeFromSelectionList(UIGChooserItem *pItem)
     324void UIGChooserModel::removeFromCurrentItems(UIGChooserItem *pItem)
    319325{
    320326    AssertMsg(pItem, ("Passed item is invalid!"));
    321     m_selectionList.removeAll(pItem);
     327    m_currentItems.removeAll(pItem);
    322328    pItem->update();
    323329}
     
    325331void UIGChooserModel::clearSelectionList()
    326332{
    327     QList<UIGChooserItem*> oldSelectedList = m_selectionList;
    328     m_selectionList.clear();
    329     foreach (UIGChooserItem *pItem, oldSelectedList)
     333    QList<UIGChooserItem*> oldCurrentItems = m_currentItems;
     334    m_currentItems.clear();
     335    foreach (UIGChooserItem *pItem, oldCurrentItems)
    330336        pItem->update();
    331337}
    332338
    333 void UIGChooserModel::notifySelectionChanged()
     339void UIGChooserModel::notifyCurrentItemChanged()
    334340{
    335341    /* Make sure selection item list is never empty
    336342     * if at least one item (for example 'focus') present: */
    337     if (selectionList().isEmpty() && focusItem())
    338         addToSelectionList(focusItem());
     343    if (currentItems().isEmpty() && focusItem())
     344        addToCurrentItems(focusItem());
    339345    /* Notify listeners about selection change: */
    340346    emit sigSelectionChanged();
     
    348354bool UIGChooserModel::isSingleGroupSelected() const
    349355{
    350     return selectionList().size() == 1 &&
    351            selectionList().first()->type() == UIGChooserItemType_Group;
     356    return currentItems().size() == 1 &&
     357           currentItem()->type() == UIGChooserItemType_Group;
    352358}
    353359
     
    355361{
    356362    /* Make sure at least on item selected: */
    357     if (selectionList().isEmpty())
     363    if (currentItems().isEmpty())
    358364        return false;
    359365
    360366    /* Determine the parent group of the first item: */
    361     UIGChooserItem *pFirstParent = selectionList().first()->parentItem();
     367    UIGChooserItem *pFirstParent = currentItem()->parentItem();
    362368
    363369    /* Make sure this parent is not main root item: */
     
    365371        return false;
    366372
    367     /* Enumerate selected set: */
    368     QSet<UIGChooserItem*> selectedSet;
    369     foreach (UIGChooserItem *pSelectedItem, selectionList())
    370         selectedSet << pSelectedItem;
     373    /* Enumerate current-item set: */
     374    QSet<UIGChooserItem*> currentItemSet;
     375    foreach (UIGChooserItem *pCurrentItem, currentItems())
     376        currentItemSet << pCurrentItem;
    371377
    372378    /* Enumerate first parent children set: */
    373     QSet<UIGChooserItem*> firstParentSet;
    374     foreach (UIGChooserItem *pSelectedItem, pFirstParent->items())
    375         firstParentSet << pSelectedItem;
     379    QSet<UIGChooserItem*> firstParentItemSet;
     380    foreach (UIGChooserItem *pFirstParentItem, pFirstParent->items())
     381        firstParentItemSet << pFirstParentItem;
    376382
    377383    /* Check if both sets contains the same: */
    378     return selectedSet == firstParentSet;
     384    return currentItemSet == firstParentItemSet;
    379385}
    380386
     
    404410            /* Add focus item into selection (if any): */
    405411            if (m_pFocusItem)
    406                 addToSelectionList(m_pFocusItem);
     412                addToCurrentItems(m_pFocusItem);
    407413            /* Notify selection changed: */
    408             notifySelectionChanged();
     414            notifyCurrentItemChanged();
    409415        }
    410416
     
    711717    QStringList busyGroupNames;
    712718    QStringList busyMachineNames;
    713     QList<UIGChooserItem*> selectedItems = selectionList();
     719    QList<UIGChooserItem*> selectedItems = currentItems();
    714720    foreach (UIGChooserItem *pItem, selectedItems)
    715721    {
     
    762768
    763769    /* Start editing group name: */
    764     selectionList().first()->startEditing();
     770    currentItem()->startEditing();
    765771}
    766772
     
    768774{
    769775    if (isSingleGroupSelected())
    770         sortItems(selectionList().first());
     776        sortItems(currentItem());
    771777}
    772778
     
    851857    UIGChooserItem *pGroup = 0;
    852858    if (isSingleGroupSelected())
    853         pGroup = selectionList().first();
    854     else if (!selectionList().isEmpty())
    855         pGroup = selectionList().first()->parentItem();
     859        pGroup = currentItem();
     860    else if (!currentItems().isEmpty())
     861        pGroup = currentItem()->parentItem();
    856862    QString strGroupName;
    857863    if (pGroup)
     
    888894void UIGChooserModel::sltSortParentGroup()
    889895{
    890     if (!selectionList().isEmpty())
    891         sortItems(selectionList().first()->parentItem());
     896    if (!currentItems().isEmpty())
     897        sortItems(currentItem()->parentItem());
    892898}
    893899
     
    896902    /* Gather list of chosen inaccessible VMs: */
    897903    QList<UIGChooserItem*> inaccessibleItems;
    898     enumerateInaccessibleItems(selectionList(), inaccessibleItems);
     904    enumerateInaccessibleItems(currentItems(), inaccessibleItems);
    899905
    900906    /* For each inaccessible item: */
     
    928934{
    929935    /* Enumerate all the selected machine items: */
    930     QList<UIGChooserItem*> selectedMachineItemList = gatherMachineItems(selectionList());
     936    QList<UIGChooserItem*> selectedMachineItemList = gatherMachineItems(currentItems());
    931937    /* Enumerate all the existing machine items: */
    932938    QList<UIGChooserItem*> existingMachineItemList = gatherMachineItems(mainRoot()->items());
     
    16031609    updateNavigation();
    16041610    updateLayout();
    1605     if (mainRoot()->hasItems())
     1611    if (!navigationList().isEmpty())
    16061612        setCurrentItem(0);
    16071613    else
     
    16791685                            return false;
    16801686                        /* Is this group item only the one selected? */
    1681                         if (selectionList().contains(pGroupItem) && selectionList().size() == 1)
     1687                        if (currentItems().contains(pGroupItem) && currentItems().size() == 1)
    16821688                        {
    16831689                            /* Group context menu in that case: */
     
    17011707        {
    17021708            /* Get first selected item: */
    1703             if (UIGChooserItem *pItem = selectionList().first())
     1709            if (UIGChooserItem *pItem = currentItem())
    17041710            {
    17051711                /* If this item of known type? */
     
    17091715                    {
    17101716                        /* Is this group item only the one selected? */
    1711                         if (selectionList().size() == 1)
     1717                        if (currentItems().size() == 1)
    17121718                        {
    17131719                            /* Group context menu in that case: */
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser/UIGChooserModel.h

    r43536 r43539  
    113113    QString currentItemDefinition() const;
    114114    QList<UIVMItem*> currentMachineItems() const;
    115     const QList<UIGChooserItem*>& selectionList() const;
     115    UIGChooserItem* currentItem() const;
     116    const QList<UIGChooserItem*>& currentItems() const;
    116117    void setCurrentItem(int iItemIndex);
    117118    void setCurrentItem(UIGChooserItem *pItem);
    118119    void setCurrentItemDefinition(const QString &strDefinition);
    119120    void unsetCurrentItem();
    120     void addToSelectionList(UIGChooserItem *pItem);
    121     void removeFromSelectionList(UIGChooserItem *pItem);
     121    void addToCurrentItems(UIGChooserItem *pItem);
     122    void removeFromCurrentItems(UIGChooserItem *pItem);
    122123    void clearSelectionList();
    123     void notifySelectionChanged();
     124    void notifyCurrentItemChanged();
    124125    void activate();
    125126    bool isSingleGroupSelected() const;
     
    302303    QMap<QString, QStringList> m_groups;
    303304    QList<UIGChooserItem*> m_navigationList;
    304     QList<UIGChooserItem*> m_selectionList;
     305    QList<UIGChooserItem*> m_currentItems;
    305306    UIGChooserHandlerMouse *m_pMouseHandler;
    306307    UIGChooserHandlerKeyboard *m_pKeyboardHandler;
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