VirtualBox

Changeset 50967 in vbox for trunk/src/VBox/Frontends


Ignore:
Timestamp:
Apr 3, 2014 3:17:29 PM (11 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
93125
Message:

FE/Qt: Medium Manager rework/cleanup: Abstract information-container content (labels/fields) 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

    r50966 r50967  
    12161216}
    12171217
    1218 void UIMediumManager::prepareInformationContainer(UIMediumType, int)
     1218void UIMediumManager::prepareInformationContainer(UIMediumType type, int iFields)
    12191219{
    12201220    /* Information-panes created in .ui file. */
    12211221    {
    12221222        /* Configure information-panes: */
    1223         QList<QILabel*> panes = findChildren<QILabel*>();
    1224         foreach (QILabel *pPane, panes)
    1225             pPane->setFullSizeSelection(true);
     1223        for (int i = 0; i < iFields; ++i)
     1224        {
     1225            QILabel *pField = infoField(type, i);
     1226            if (pField)
     1227                pField->setFullSizeSelection(true);
     1228        }
    12261229    }
    12271230}
     
    15351538    {
    15361539        /* Just clear information panes: */
    1537         if (m_pTypePane)
    1538             m_pTypePane->clear();
    1539         if (m_pLocationPane)
    1540             m_pLocationPane->clear();
    1541         if (m_pFormatPane)
    1542             m_pFormatPane->clear();
    1543         if (m_pDetailsPane)
    1544             m_pDetailsPane->clear();
    1545         if (m_pUsagePane)
    1546             m_pUsagePane->clear();
     1540        for (int i = 0; i < 5; ++i)
     1541            infoField(UIMediumType_HardDisk, i)->clear();
    15471542    }
    15481543    /* If current item is set: */
     
    15541549                           formatPaneText(QApplication::translate("VBoxMediaManagerDlg", "<i>Not&nbsp;Attached</i>"), false) :
    15551550                           formatPaneText(pCurrentItem->usage());
    1556         if (m_pTypePane)
    1557             m_pTypePane->setText(pCurrentItem->hardDiskType());
    1558         if (m_pLocationPane)
    1559             m_pLocationPane->setText(formatPaneText(pCurrentItem->location(), true, "end"));
    1560         if (m_pFormatPane)
    1561             m_pFormatPane->setText(pCurrentItem->hardDiskFormat());
    1562         if (m_pDetailsPane)
    1563             m_pDetailsPane->setText(strDetails);
    1564         if (m_pUsagePane)
    1565             m_pUsagePane->setText(strUsage);
     1551        if (infoField(UIMediumType_HardDisk, 0))
     1552            infoField(UIMediumType_HardDisk, 0)->setText(pCurrentItem->hardDiskType());
     1553        if (infoField(UIMediumType_HardDisk, 1))
     1554            infoField(UIMediumType_HardDisk, 1)->setText(formatPaneText(pCurrentItem->location(), true, "end"));
     1555        if (infoField(UIMediumType_HardDisk, 2))
     1556            infoField(UIMediumType_HardDisk, 2)->setText(pCurrentItem->hardDiskFormat());
     1557        if (infoField(UIMediumType_HardDisk, 3))
     1558            infoField(UIMediumType_HardDisk, 3)->setText(strDetails);
     1559        if (infoField(UIMediumType_HardDisk, 4))
     1560            infoField(UIMediumType_HardDisk, 4)->setText(strUsage);
    15661561    }
    15671562
    15681563    /* Enable/disable information-panes container: */
    1569     if (mHDContainer)
    1570         mHDContainer->setEnabled(pCurrentItem);
     1564    if (infoContainer(UIMediumType_HardDisk))
     1565        infoContainer(UIMediumType_HardDisk)->setEnabled(pCurrentItem);
    15711566}
    15721567
     
    15801575    {
    15811576        /* Just clear information panes: */
    1582         if (mIpCD1)
    1583             mIpCD1->clear();
    1584         if (mIpCD2)
    1585             mIpCD2->clear();
     1577        for (int i = 0; i < 2; ++i)
     1578            infoField(UIMediumType_DVD, i)->clear();
    15861579    }
    15871580    /* If current item is set: */
     
    15921585                           formatPaneText(QApplication::translate("VBoxMediaManagerDlg", "<i>Not&nbsp;Attached</i>"), false) :
    15931586                           formatPaneText(pCurrentItem->usage());
    1594         if (mIpCD1)
    1595             mIpCD1->setText(formatPaneText(pCurrentItem->location(), true, "end"));
    1596         if (mIpCD2)
    1597             mIpCD2->setText(strUsage);
     1587        if (infoField(UIMediumType_DVD, 0))
     1588            infoField(UIMediumType_DVD, 0)->setText(formatPaneText(pCurrentItem->location(), true, "end"));
     1589        if (infoField(UIMediumType_DVD, 1))
     1590            infoField(UIMediumType_DVD, 1)->setText(strUsage);
    15981591    }
    15991592
    16001593    /* Enable/disable information-panes container: */
    1601     if (mCDContainer)
    1602         mCDContainer->setEnabled(pCurrentItem);
     1594    if (infoContainer(UIMediumType_DVD))
     1595        infoContainer(UIMediumType_DVD)->setEnabled(pCurrentItem);
    16031596}
    16041597
     
    16121605    {
    16131606        /* Just clear information panes: */
    1614         if (mIpFD1)
    1615             mIpFD1->clear();
    1616         if (mIpFD2)
    1617             mIpFD2->clear();
     1607        for (int i = 0; i < 2; ++i)
     1608            infoField(UIMediumType_Floppy, i)->clear();
    16181609    }
    16191610    /* If current item is set: */
     
    16241615                           formatPaneText(QApplication::translate("VBoxMediaManagerDlg", "<i>Not&nbsp;Attached</i>"), false) :
    16251616                           formatPaneText(pCurrentItem->usage());
    1626         if (mIpFD1)
    1627             mIpFD1->setText(formatPaneText(pCurrentItem->location(), true, "end"));
    1628         if (mIpFD2)
    1629             mIpFD2->setText(strUsage);
     1617        if (infoField(UIMediumType_Floppy, 0))
     1618            infoField(UIMediumType_Floppy, 0)->setText(formatPaneText(pCurrentItem->location(), true, "end"));
     1619        if (infoField(UIMediumType_Floppy, 1))
     1620            infoField(UIMediumType_Floppy, 1)->setText(strUsage);
    16301621    }
    16311622
    16321623    /* Enable/disable information-panes container: */
    1633     if (mFDContainer)
    1634         mFDContainer->setEnabled(pCurrentItem);
     1624    if (infoContainer(UIMediumType_Floppy))
     1625        infoContainer(UIMediumType_Floppy)->setEnabled(pCurrentItem);
    16351626}
    16361627
     
    17271718
    17281719    /* Translate HD information-labels: */
    1729     if (m_pTypeLabel)
    1730         m_pTypeLabel->setText(QApplication::translate("VBoxMediaManagerDlg", "Type:"));
    1731     if (m_pLocationLabel)
    1732         m_pLocationLabel->setText(QApplication::translate("VBoxMediaManagerDlg", "Location:"));
    1733     if (m_pFormatLabel)
    1734         m_pFormatLabel->setText(QApplication::translate("VBoxMediaManagerDlg", "Format:"));
    1735     if (m_pDetailsLabel)
    1736         m_pDetailsLabel->setText(QApplication::translate("VBoxMediaManagerDlg", "Storage details:"));
    1737     if (m_pUsageLabel)
    1738         m_pUsageLabel->setText(QApplication::translate("VBoxMediaManagerDlg", "Attached to:"));
     1720    if (infoLabel(UIMediumType_HardDisk, 0))
     1721        infoLabel(UIMediumType_HardDisk, 0)->setText(QApplication::translate("VBoxMediaManagerDlg", "Type:"));
     1722    if (infoLabel(UIMediumType_HardDisk, 1))
     1723        infoLabel(UIMediumType_HardDisk, 1)->setText(QApplication::translate("VBoxMediaManagerDlg", "Location:"));
     1724    if (infoLabel(UIMediumType_HardDisk, 2))
     1725        infoLabel(UIMediumType_HardDisk, 2)->setText(QApplication::translate("VBoxMediaManagerDlg", "Format:"));
     1726    if (infoLabel(UIMediumType_HardDisk, 3))
     1727        infoLabel(UIMediumType_HardDisk, 3)->setText(QApplication::translate("VBoxMediaManagerDlg", "Storage details:"));
     1728    if (infoLabel(UIMediumType_HardDisk, 4))
     1729        infoLabel(UIMediumType_HardDisk, 4)->setText(QApplication::translate("VBoxMediaManagerDlg", "Attached to:"));
    17391730
    17401731    /* Translate CD tree-widget: */
     
    17471738
    17481739    /* Translate CD information-labels: */
    1749     if (mLbCD1)
    1750         mLbCD1->setText(QApplication::translate("VBoxMediaManagerDlg", "Location:"));
    1751     if (mLbCD2)
    1752         mLbCD2->setText(QApplication::translate("VBoxMediaManagerDlg", "Attached to:"));
     1740    if (infoLabel(UIMediumType_DVD, 0))
     1741        infoLabel(UIMediumType_DVD, 0)->setText(QApplication::translate("VBoxMediaManagerDlg", "Location:"));
     1742    if (infoLabel(UIMediumType_DVD, 1))
     1743        infoLabel(UIMediumType_DVD, 1)->setText(QApplication::translate("VBoxMediaManagerDlg", "Attached to:"));
    17531744
    17541745    /* Translate FD tree-widget: */
     
    17611752
    17621753    /* Translate FD information-labels: */
    1763     if (mLbFD1)
    1764         mLbFD1->setText(QApplication::translate("VBoxMediaManagerDlg", "Location:"));
    1765     if (mLbFD2)
    1766         mLbFD2->setText(QApplication::translate("VBoxMediaManagerDlg", "Attached to:"));
     1754    if (infoLabel(UIMediumType_Floppy, 0))
     1755        infoLabel(UIMediumType_Floppy, 0)->setText(QApplication::translate("VBoxMediaManagerDlg", "Location:"));
     1756    if (infoLabel(UIMediumType_Floppy, 1))
     1757        infoLabel(UIMediumType_Floppy, 1)->setText(QApplication::translate("VBoxMediaManagerDlg", "Attached to:"));
    17671758
    17681759    /* Translate progress-bar: */
     
    20142005}
    20152006
     2007QFrame* UIMediumManager::infoContainer(UIMediumType type) const
     2008{
     2009    /* Return corresponding tree-widget for known medium types: */
     2010    switch (type)
     2011    {
     2012        case UIMediumType_HardDisk: return mHDContainer;
     2013        case UIMediumType_DVD:      return mCDContainer;
     2014        case UIMediumType_Floppy:   return mFDContainer;
     2015        default: AssertMsgFailed(("Unknown medium type: %d\n", type)); break;
     2016    }
     2017    /* Null by default: */
     2018    return 0;
     2019}
     2020
     2021QLabel* UIMediumManager::infoLabel(UIMediumType type, int iLabelIndex) const
     2022{
     2023    /* Return corresponding tree-widget for known medium types: */
     2024    switch (type)
     2025    {
     2026        case UIMediumType_HardDisk:
     2027        {
     2028            switch (iLabelIndex)
     2029            {
     2030                case 0: return m_pTypeLabel;
     2031                case 1: return m_pLocationLabel;
     2032                case 2: return m_pFormatLabel;
     2033                case 3: return m_pDetailsLabel;
     2034                case 4: return m_pUsageLabel;
     2035                default: AssertMsgFailed(("Label index out of bounds: %d\n", iLabelIndex)); break;
     2036            }
     2037            break;
     2038        }
     2039        case UIMediumType_DVD:
     2040        {
     2041            switch (iLabelIndex)
     2042            {
     2043                case 0: return mLbCD1;
     2044                case 1: return mLbCD2;
     2045                default: AssertMsgFailed(("Label index out of bounds: %d\n", iLabelIndex)); break;
     2046            }
     2047            break;
     2048        }
     2049        case UIMediumType_Floppy:
     2050        {
     2051            switch (iLabelIndex)
     2052            {
     2053                case 0: return mLbFD1;
     2054                case 1: return mLbFD2;
     2055                default: AssertMsgFailed(("Label index out of bounds: %d\n", iLabelIndex)); break;
     2056            }
     2057            break;
     2058        }
     2059        default: AssertMsgFailed(("Unknown medium type: %d\n", type)); break;
     2060    }
     2061    /* Null by default: */
     2062    return 0;
     2063}
     2064
     2065QILabel* UIMediumManager::infoField(UIMediumType type, int iFieldIndex) const
     2066{
     2067    /* Return corresponding tree-widget for known medium types: */
     2068    switch (type)
     2069    {
     2070        case UIMediumType_HardDisk:
     2071        {
     2072            switch (iFieldIndex)
     2073            {
     2074                case 0: return m_pTypePane;
     2075                case 1: return m_pLocationPane;
     2076                case 2: return m_pFormatPane;
     2077                case 3: return m_pDetailsPane;
     2078                case 4: return m_pUsagePane;
     2079                default: AssertMsgFailed(("Field index out of bounds: %d\n", iFieldIndex)); break;
     2080            }
     2081            break;
     2082        }
     2083        case UIMediumType_DVD:
     2084        {
     2085            switch (iFieldIndex)
     2086            {
     2087                case 0: return mIpCD1;
     2088                case 1: return mIpCD2;
     2089                default: AssertMsgFailed(("Field index out of bounds: %d\n", iFieldIndex)); break;
     2090            }
     2091            break;
     2092        }
     2093        case UIMediumType_Floppy:
     2094        {
     2095            switch (iFieldIndex)
     2096            {
     2097                case 0: return mIpFD1;
     2098                case 1: return mIpFD2;
     2099                default: AssertMsgFailed(("Field index out of bounds: %d\n", iFieldIndex)); break;
     2100            }
     2101            break;
     2102        }
     2103        default: AssertMsgFailed(("Unknown medium type: %d\n", type)); break;
     2104    }
     2105    /* Null by default: */
     2106    return 0;
     2107}
     2108
    20162109UIMediumType UIMediumManager::mediumType(QTreeWidget *pTreeWidget) const
    20172110{
  • trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumManager.h

    r50966 r50967  
    178178    /** Returns item for passed medium @a type. */
    179179    UIMediumItem* mediumItem(UIMediumType type) const;
     180    /** Returns information-container for passed medium @a type. */
     181    QFrame* infoContainer(UIMediumType type) const;
     182    /** Returns information-label for passed medium @a type and @a iLabelIndex. */
     183    QLabel* infoLabel(UIMediumType type, int iLabelIndex) const;
     184    /** Returns information-field for passed medium @a type and @a iFieldIndex. */
     185    QILabel* infoField(UIMediumType type, int iFieldIndex) const;
    180186
    181187    /** Returns medium type for passed @a pTreeWidget. */
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