VirtualBox

Changeset 43552 in vbox


Ignore:
Timestamp:
Oct 5, 2012 10:52:56 AM (12 years ago)
Author:
vboxsync
Message:

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

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

Legend:

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

    r43549 r43552  
    134134                    if (!pClickedItem->isRoot())
    135135                    {
    136                         /* Is clicked item in selection list: */
    137                         bool fIsClickedItemInSelectionList = model()->currentItems().contains(pClickedItem);
    138136                        /* Move focus to clicked item (with selection if not selected yet): */
    139                         model()->setFocusItem(pClickedItem, !fIsClickedItemInSelectionList);
     137                        model()->setCurrentItem(pClickedItem);
    140138                    }
    141139                }
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser/UIGChooserModel.cpp

    r43544 r43552  
    211211}
    212212
     213void UIGChooserModel::setCurrentItems(const QList<UIGChooserItem*> &items)
     214{
     215    /* Is there something seems to be changed? */
     216    if (m_currentItems == items)
     217        return;
     218
     219    /* Remember old current-item list: */
     220    QList<UIGChooserItem*> oldCurrentItems = m_currentItems;
     221
     222    /* Clear current current-item list: */
     223    m_currentItems.clear();
     224
     225    /* Iterate over all the passed items: */
     226    foreach (UIGChooserItem *pItem, items)
     227    {
     228        /* If navigation list contains iterated-item: */
     229        if (pItem && navigationList().contains(pItem))
     230        {
     231            /* Add that item to current: */
     232            m_currentItems << pItem;
     233        }
     234        else
     235            AssertMsgFailed(("Passed item not in navigation list!"));
     236    }
     237
     238    /* Is there something really changed? */
     239    if (oldCurrentItems == m_currentItems)
     240        return;
     241
     242    /* Update all the old items (they are no longer selected): */
     243    foreach (UIGChooserItem *pItem, oldCurrentItems)
     244        pItem->update();
     245
     246    /* Update all the new items (they are selected): */
     247    foreach (UIGChooserItem *pItem, m_currentItems)
     248        pItem->update();
     249
     250    /* Notify about selection changes: */
     251    notifyCurrentItemChanged();
     252}
     253
    213254void UIGChooserModel::setCurrentItem(UIGChooserItem *pItem)
    214255{
    215     /* If navigation list contains passed item: */
    216     if (navigationList().contains(pItem))
    217     {
    218         /* Pass focus/selection to that item: */
    219         setFocusItem(pItem, true);
    220     }
    221     else
    222         AssertMsgFailed(("Passed item not in navigation list!"));
    223 }
    224 
    225 void UIGChooserModel::setCurrentItem(int iItemIndex)
    226 {
    227     /* Make sure passed index feats the bounds: */
    228     if (iItemIndex >= 0 && iItemIndex < navigationList().size())
    229     {
    230         /* And call for other wrapper: */
    231         setCurrentItem(navigationList().at(iItemIndex));
    232     }
    233     else
    234         AssertMsgFailed(("Passed index out of bounds!"));
     256    /* Call for wrapper above: */
     257    setCurrentItems(QList<UIGChooserItem*>() << pItem);
     258    /* Move focus to current-item: */
     259    setFocusItem(currentItem());
    235260}
    236261
     
    263288    }
    264289
    265     /* Some item found? */
    266     if (pItem)
    267     {
    268         /* This item should be in navigation list: */
    269         AssertMsg(navigationList().contains(pItem),
    270                   ("Passed item is NOT in navigation list!"));
    271         /* Make this item current: */
    272         setCurrentItem(pItem);
    273     }
     290    /* Make sure found item is in navigation list: */
     291    if (!pItem || !navigationList().contains(pItem))
     292        return;
     293
     294    /* Call for wrapper above: */
     295    setCurrentItem(pItem);
    274296}
    275297
    276298void UIGChooserModel::unsetCurrentItem()
    277299{
    278     /* Clear focus/selection: */
    279     setFocusItem(0, true);
     300    /* Call for wrapper above: */
     301    setCurrentItem(0);
    280302}
    281303
    282304void UIGChooserModel::addToCurrentItems(UIGChooserItem *pItem)
    283305{
    284     AssertMsg(pItem, ("Passed item is invalid!"));
    285     m_currentItems << pItem;
    286     pItem->update();
     306    /* Call for wrapper above: */
     307    setCurrentItems(QList<UIGChooserItem*>(m_currentItems) << pItem);
    287308}
    288309
    289310void UIGChooserModel::removeFromCurrentItems(UIGChooserItem *pItem)
    290311{
    291     AssertMsg(pItem, ("Passed item is invalid!"));
    292     m_currentItems.removeAll(pItem);
    293     pItem->update();
     312    /* Prepare filtered list: */
     313    QList<UIGChooserItem*> list(m_currentItems);
     314    list.removeAll(pItem);
     315    /* Call for wrapper above: */
     316    setCurrentItems(list);
    294317}
    295318
     
    306329    /* Make sure selection item list is never empty
    307330     * if at least one item (for example 'focus') present: */
    308     if (currentItems().isEmpty() && focusItem())
    309         addToCurrentItems(focusItem());
     331    if (!currentItem() && focusItem())
     332        setCurrentItem(focusItem());
    310333    /* Notify listeners about selection change: */
    311334    emit sigSelectionChanged();
     
    350373}
    351374
    352 void UIGChooserModel::setFocusItem(UIGChooserItem *pItem, bool fWithSelection /* = false */)
     375void UIGChooserModel::setFocusItem(UIGChooserItem *pItem)
    353376{
    354377    /* Make sure real focus unset: */
    355378    clearRealFocus();
    356379
    357     /* Something changed? */
    358     if (m_pFocusItem != pItem || !pItem)
    359     {
    360         /* Remember previous focus item: */
    361         QPointer<UIGChooserItem> pPreviousFocusItem = m_pFocusItem;
    362         /* Set new focus item: */
    363         m_pFocusItem = pItem;
    364 
    365         /* Should we move selection too? */
    366         if (fWithSelection)
    367         {
    368             /* Clear selection: */
    369             clearSelectionList();
    370             /* Add focus item into selection (if any): */
    371             if (m_pFocusItem)
    372                 addToCurrentItems(m_pFocusItem);
    373             /* Notify selection changed: */
    374             notifyCurrentItemChanged();
    375         }
    376 
    377         /* Update previous focus item (if any): */
    378         if (pPreviousFocusItem)
    379         {
    380             disconnect(pPreviousFocusItem, SIGNAL(destroyed(QObject*)), this, SLOT(sltFocusItemDestroyed()));
    381             pPreviousFocusItem->update();
    382         }
    383         /* Update new focus item (if any): */
    384         if (m_pFocusItem)
    385         {
    386             connect(m_pFocusItem, SIGNAL(destroyed(QObject*)), this, SLOT(sltFocusItemDestroyed()));
    387             m_pFocusItem->update();
    388         }
    389 
    390         /* Notify focus changed: */
    391         emit sigFocusChanged(m_pFocusItem);
    392     }
     380    /* Is there something changed? */
     381    if (m_pFocusItem == pItem)
     382        return;
     383
     384    /* Remember old focus-item: */
     385    UIGChooserItem *pOldFocusItem = m_pFocusItem;
     386
     387    /* Set new focus-item: */
     388    m_pFocusItem = pItem;
     389
     390    /* Disconnect old focus-item (if any): */
     391    if (pOldFocusItem)
     392        disconnect(pOldFocusItem, SIGNAL(destroyed(QObject*)), this, SLOT(sltFocusItemDestroyed()));
     393    /* Connect new focus item (if any): */
     394    if (m_pFocusItem)
     395        connect(m_pFocusItem, SIGNAL(destroyed(QObject*)), this, SLOT(sltFocusItemDestroyed()));
     396
     397    /* Notify listeners about focus change: */
     398    emit sigFocusChanged(m_pFocusItem);
    393399}
    394400
     
    602608        updateNavigation();
    603609        updateLayout();
    604         /* Make sure focus-item present, if possible: */
    605         if (!focusItem() && currentItem())
    606             setFocusItem(currentItem());
    607610        /* Make sure current-item present, if possible: */
    608611        if (!currentItem() && !navigationList().isEmpty())
    609             setCurrentItem(0);
     612            setCurrentItem(navigationList().first());
     613        /* Make sure focus-item present, if possible: */
     614        else if (!focusItem() && currentItem())
     615            setFocusItem(currentItem());
    610616        /* Notify about current-item change: */
    611617        notifyCurrentItemChanged();
     
    672678    else
    673679    {
    674         if (root()->hasItems())
    675             setCurrentItem(root()->items().first());
     680        if (!navigationList().isEmpty())
     681            setCurrentItem(navigationList().first());
    676682        else
    677683            unsetCurrentItem();
     
    814820    updateNavigation();
    815821    updateLayout();
    816     setCurrentItem(0);
     822    setCurrentItem(navigationList().first());
    817823    saveGroupSettings();
    818824}
     
    12041210    setCurrentItem(vboxGlobal().virtualBox().GetExtraData(GUI_LastItemSelected));
    12051211    if (!currentItem() && !navigationList().isEmpty())
    1206         setCurrentItem(0);
     1212        setCurrentItem(navigationList().first());
    12071213}
    12081214
     
    15801586    updateLayout();
    15811587    if (!navigationList().isEmpty())
    1582         setCurrentItem(0);
     1588        setCurrentItem(navigationList().first());
    15831589    else
    15841590        unsetCurrentItem();
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser/UIGChooserModel.h

    r43544 r43552  
    114114    UIGChooserItem* currentItem() const;
    115115    const QList<UIGChooserItem*>& currentItems() const;
     116    void setCurrentItems(const QList<UIGChooserItem*> &items);
    116117    void setCurrentItem(UIGChooserItem *pItem);
    117     void setCurrentItem(int iItemIndex);
    118118    void setCurrentItem(const QString &strDefinition);
    119119    void unsetCurrentItem();
     
    127127    /* API: Focus-item stuff: */
    128128    UIGChooserItem* focusItem() const;
    129     void setFocusItem(UIGChooserItem *pItem, bool fWithSelection = false);
     129    void setFocusItem(UIGChooserItem *pItem);
    130130
    131131    /* API: Root-item stuff: */
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