VirtualBox

Ignore:
Timestamp:
Apr 3, 2014 2:54:55 PM (11 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
93124
Message:

FE/Qt: Medium Manager rework/cleanup: Abstract medium-type to tab-index mapping.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/medium
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumManager.cpp

    r50964 r50966  
    749749    if (mTabWidget)
    750750    {
    751         mTabWidget->setTabIcon(TabIndex_HD, m_iconHD);
    752         mTabWidget->setTabIcon(TabIndex_CD, m_iconCD);
    753         mTabWidget->setTabIcon(TabIndex_FD, m_iconFD);
     751        mTabWidget->setTabIcon(tabIndex(UIMediumType_HardDisk), m_iconHD);
     752        mTabWidget->setTabIcon(tabIndex(UIMediumType_DVD), m_iconCD);
     753        mTabWidget->setTabIcon(tabIndex(UIMediumType_Floppy), m_iconFD);
    754754    }
    755755
     
    11611161        /* Configure tab-widget: */
    11621162        mTabWidget->setFocusPolicy(Qt::TabFocus);
    1163         mTabWidget->setTabIcon(TabIndex_HD, m_iconHD);
    1164         mTabWidget->setTabIcon(TabIndex_CD, m_iconCD);
    1165         mTabWidget->setTabIcon(TabIndex_FD, m_iconFD);
     1163        mTabWidget->setTabIcon(tabIndex(UIMediumType_HardDisk), m_iconHD);
     1164        mTabWidget->setTabIcon(tabIndex(UIMediumType_DVD), m_iconCD);
     1165        mTabWidget->setTabIcon(tabIndex(UIMediumType_Floppy), m_iconFD);
    11661166        connect(mTabWidget, SIGNAL(currentChanged(int)), this, SLOT(sltHandleCurrentTabChanged()));
    11671167        /* Focus current tree-widget: */
     
    14251425
    14261426    /* Prepare data for tab: */
    1427     int iTab = -1;
    14281427    const QIcon *pIcon = 0;
    14291428    bool *pfInaccessible = 0;
    1430     switch (pMediumItem->mediumType())
     1429    const UIMediumType mediumType = pMediumItem->mediumType();
     1430    switch (mediumType)
    14311431    {
    14321432        case UIMediumType_HardDisk:
    1433             iTab = TabIndex_HD;
    14341433            pIcon = &m_iconHD;
    14351434            pfInaccessible = &m_fInaccessibleHD;
    14361435            break;
    14371436        case UIMediumType_DVD:
    1438             iTab = TabIndex_CD;
    14391437            pIcon = &m_iconCD;
    14401438            pfInaccessible = &m_fInaccessibleCD;
    14411439            break;
    14421440        case UIMediumType_Floppy:
    1443             iTab = TabIndex_FD;
    14441441            pIcon = &m_iconFD;
    14451442            pfInaccessible = &m_fInaccessibleFD;
     
    14481445            AssertFailed();
    14491446    }
    1450     AssertReturnVoid(iTab != -1 && pIcon && pfInaccessible);
     1447    AssertReturnVoid(pIcon && pfInaccessible);
    14511448
    14521449    switch (action)
     
    14611458
    14621459            if (mTabWidget)
    1463                 mTabWidget->setTabIcon(iTab, vboxGlobal().warningIcon());
     1460                mTabWidget->setTabIcon(tabIndex(mediumType), vboxGlobal().warningIcon());
    14641461
    14651462            break;
     
    14981495            {
    14991496                if (*pfInaccessible)
    1500                     mTabWidget->setTabIcon(iTab, vboxGlobal().warningIcon());
     1497                    mTabWidget->setTabIcon(tabIndex(mediumType), vboxGlobal().warningIcon());
    15011498                else
    1502                     mTabWidget->setTabIcon(iTab, *pIcon);
     1499                    mTabWidget->setTabIcon(tabIndex(mediumType), *pIcon);
    15031500            }
    15041501
     
    17151712    if (mTabWidget)
    17161713    {
    1717         mTabWidget->setTabText(TabIndex_HD, tr("&Hard drives"));
    1718         mTabWidget->setTabText(TabIndex_CD, tr("&Optical disks"));
    1719         mTabWidget->setTabText(TabIndex_FD, tr("&Floppy disks"));
     1714        mTabWidget->setTabText(tabIndex(UIMediumType_HardDisk), tr("&Hard drives"));
     1715        mTabWidget->setTabText(tabIndex(UIMediumType_DVD), tr("&Optical disks"));
     1716        mTabWidget->setTabText(tabIndex(UIMediumType_Floppy), tr("&Floppy disks"));
    17201717    }
    17211718
     
    20362033
    20372034    /* Return current medium type: */
    2038     switch (mTabWidget->currentIndex())
    2039     {
    2040         case TabIndex_HD: return UIMediumType_HardDisk;
    2041         case TabIndex_CD: return UIMediumType_DVD;
    2042         case TabIndex_FD: return UIMediumType_Floppy;
    2043         default: AssertMsgFailed(("Unknown page type: %d\n", mTabWidget->currentIndex())); break;
    2044     }
    2045     /* Invalid by default: */
    2046     return UIMediumType_Invalid;
     2035    return mediumType(mTabWidget->currentIndex());
    20472036}
    20482037
     
    20772066    /* Re-fetch currently chosen medium-item: */
    20782067    refetchCurrentChosenMediumItem();
     2068}
     2069
     2070/* static */
     2071int UIMediumManager::tabIndex(UIMediumType type)
     2072{
     2073    /* Return tab index corresponding to known medium type: */
     2074    switch (type)
     2075    {
     2076        case UIMediumType_HardDisk: return 0;
     2077        case UIMediumType_DVD:      return 1;
     2078        case UIMediumType_Floppy:   return 2;
     2079        default: break;
     2080    }
     2081
     2082    /* -1 by default: */
     2083    return -1;
     2084}
     2085
     2086/* static */
     2087UIMediumType UIMediumManager::mediumType(int iIndex)
     2088{
     2089    /* Return medium type corresponding to known tab index: */
     2090    switch (iIndex)
     2091    {
     2092        case 0: return UIMediumType_HardDisk;
     2093        case 1: return UIMediumType_DVD;
     2094        case 2: return UIMediumType_Floppy;
     2095        default: break;
     2096    }
     2097
     2098    /* Invalid by default: */
     2099    return UIMediumType_Invalid;
    20792100}
    20802101
  • trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumManager.h

    r50960 r50966  
    4242{
    4343    Q_OBJECT;
    44 
    45     /** Tab index enumerator. */
    46     enum TabIndex { TabIndex_HD = 0, TabIndex_CD, TabIndex_FD };
    4744
    4845    /** Item action enumerator. */
     
    195192    void setCurrentItem(QTreeWidget *pTreeWidget, QTreeWidgetItem *pItem);
    196193
     194    /** Returns tab index for passed UIMediumType. */
     195    static int tabIndex(UIMediumType type);
     196    /** Returns UIMediumType for passed tab index. */
     197    static UIMediumType mediumType(int iIndex);
     198
    197199    /** Performs search for the @a pTree child which corresponds to the @a condition but not @a pException. */
    198200    static UIMediumItem* searchItem(QTreeWidget *pTree, const CheckIfSuitableBy &condition, CheckIfSuitableBy *pException = 0);
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