VirtualBox

Changeset 50960 in vbox


Ignore:
Timestamp:
Apr 3, 2014 11:31:10 AM (11 years ago)
Author:
vboxsync
Message:

FE/Qt: Medium Manager rework/cleanup: Prepare for .ui file absorption (part 2).

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

Legend:

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

    r50959 r50960  
    2222/* Qt includes: */
    2323#include <QLabel>
    24 #include <QProgressBar>
    2524#include <QMenuBar>
    2625#include <QHeaderView>
    2726#include <QPushButton>
     27#include <QProgressBar>
    2828
    2929/* GUI includes: */
     
    3333#include "UIMessageCenter.h"
    3434#include "UIToolBar.h"
    35 #include "QILabel.h"
    3635#include "UIIconPool.h"
    3736#include "UIMediumTypeChangeDialog.h"
     
    594593
    595594    /** Constructor on the basis of passed @a pParent. */
    596     UIEnumerationProgressBar(QWidget *pParent)
     595    UIEnumerationProgressBar(QWidget *pParent = 0)
    597596        : QWidget(pParent)
    598597    {
     
    657656    , m_iconCD(UIIconPool::iconSet(":/cd_16px.png", ":/cd_disabled_16px.png"))
    658657    , m_iconFD(UIIconPool::iconSet(":/fd_16px.png", ":/fd_disabled_16px.png"))
     658    , m_pToolBar(0)
     659    , m_pContextMenu(0)
     660    , m_pMenu(0)
     661    , m_pActionCopy(0), m_pActionModify(0)
     662    , m_pActionRemove(0), m_pActionRelease(0)
     663    , m_pActionRefresh(0)
     664    , m_pProgressBar(0)
    659665{
    660666    /* Prepare: */
     
    10461052void UIMediumManager::prepareMenuBar()
    10471053{
    1048     /* Create actions-menu for menu-bar: */
     1054    /* Create menu-bar-menu: */
    10491055    m_pMenu = menuBar()->addMenu(QString());
    10501056    {
    1051         /* Configure menu-bar menu: */
     1057        /* Configure menu-bar-menu: */
    10521058        m_pMenu->addAction(m_pActionCopy);
    10531059        m_pMenu->addAction(m_pActionModify);
     
    10981104        /* Integrate tool-bar into dialog: */
    10991105        QVBoxLayout *pMainLayout = qobject_cast<QVBoxLayout*>(centralWidget()->layout());
    1100         Assert(pMainLayout);
    11011106#if MAC_LEOPARD_STYLE
    11021107        /* Enable unified tool-bars on Mac OS X. Available on Qt >= 4.3: */
     
    11121117        pMainLayout->setSpacing(5);
    11131118        pMainLayout->setContentsMargins(5, 5, 5, 5);
    1114 #endif /* MAC_LEOPARD_STYLE */
     1119#endif /* !MAC_LEOPARD_STYLE */
    11151120    }
    11161121}
     
    11201125    /* Tab-widget created in .ui file. */
    11211126    {
     1127        /* Prepare tabs: */
     1128        for (int i = (int)UIMediumType_HardDisk; i <= (int)UIMediumType_Floppy; ++i)
     1129            prepareTab((UIMediumType)i);
    11221130        /* Configure tab-widget: */
    11231131        mTabWidget->setFocusPolicy(Qt::TabFocus);
     
    11261134        mTabWidget->setTabIcon(TabIndex_FD, m_iconFD);
    11271135        connect(mTabWidget, SIGNAL(currentChanged(int)), this, SLOT(sltHandleCurrentTabChanged()));
    1128         /* Prepare tree-widgets: */
    1129         prepareTreeWidgets();
    1130         /* Prepare information-panes: */
    1131         prepareInformationPanes();
    1132     }
    1133 }
    1134 
    1135 void UIMediumManager::prepareTreeWidgets()
    1136 {
    1137     /* Prepare tree-widget HD: */
    1138     prepareTreeWidgetHD();
    1139     /* Prepare tree-widget CD: */
    1140     prepareTreeWidgetCD();
    1141     /* Prepare tree-widget FD: */
    1142     prepareTreeWidgetFD();
    1143 
    1144     /* Focus current tree-widget: */
    1145     currentTreeWidget()->setFocus();
    1146 }
    1147 
    1148 void UIMediumManager::prepareTreeWidgetHD()
    1149 {
    1150     /* HD tree-widget created in .ui file. */
    1151     {
    1152         /* Configure HD tree-widget: */
    1153         QTreeWidget *pTreeWidget = treeWidget(UIMediumType_HardDisk);
    1154         pTreeWidget->setColumnCount(3);
     1136        /* Focus current tree-widget: */
     1137        if (currentTreeWidget())
     1138            currentTreeWidget()->setFocus();
     1139        /* Update other widgets according chosen tab: */
     1140        sltHandleCurrentTabChanged();
     1141    }
     1142}
     1143
     1144void UIMediumManager::prepareTab(UIMediumType type)
     1145{
     1146    /* Tab created in .ui file. */
     1147    {
     1148        /* Tab layout created in .ui file. */
     1149        {
     1150            /* Prepare tree-widget: */
     1151            prepareTreeWidget(type, type == UIMediumType_HardDisk ? 3 : 2);
     1152            /* Prepare information-container: */
     1153            prepareInformationContainer(type, type == UIMediumType_HardDisk ? 5 : 2);
     1154        }
     1155    }
     1156}
     1157
     1158void UIMediumManager::prepareTreeWidget(UIMediumType type, int iColumns)
     1159{
     1160    /* Tree-widget created in .ui file. */
     1161    {
     1162        /* Configure tree-widget: */
     1163        QTreeWidget *pTreeWidget = treeWidget(type);
     1164        pTreeWidget->setColumnCount(iColumns);
    11551165        pTreeWidget->sortItems(0, Qt::AscendingOrder);
    1156         pTreeWidget->header()->setResizeMode(0, QHeaderView::Fixed);
    1157         pTreeWidget->header()->setResizeMode(1, QHeaderView::ResizeToContents);
    1158         pTreeWidget->header()->setResizeMode(2, QHeaderView::ResizeToContents);
     1166        if (iColumns > 0)
     1167            pTreeWidget->header()->setResizeMode(0, QHeaderView::Fixed);
     1168        if (iColumns > 1)
     1169            pTreeWidget->header()->setResizeMode(1, QHeaderView::ResizeToContents);
     1170        if (iColumns > 2)
     1171            pTreeWidget->header()->setResizeMode(2, QHeaderView::ResizeToContents);
    11591172        pTreeWidget->header()->setStretchLastSection(false);
    11601173        pTreeWidget->setSortingEnabled(true);
     
    11721185}
    11731186
    1174 void UIMediumManager::prepareTreeWidgetCD()
    1175 {
    1176     /* CD tree-widget created in .ui file. */
    1177     {
    1178         /* Configure CD tree-widget: */
    1179         QTreeWidget *pTreeWidget = treeWidget(UIMediumType_DVD);
    1180         pTreeWidget->setColumnCount(2);
    1181         pTreeWidget->sortItems(0, Qt::AscendingOrder);
    1182         pTreeWidget->header()->setResizeMode(0, QHeaderView::Fixed);
    1183         pTreeWidget->header()->setResizeMode(1, QHeaderView::ResizeToContents);
    1184         pTreeWidget->header()->setStretchLastSection(false);
    1185         pTreeWidget->setSortingEnabled(true);
    1186         connect(pTreeWidget, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)),
    1187                 this, SLOT(sltHandleCurrentItemChanged()));
    1188         connect(pTreeWidget, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)),
    1189                 this, SLOT(sltHandleDoubleClick()));
    1190         connect(pTreeWidget, SIGNAL(customContextMenuRequested(const QPoint&)),
    1191                 this, SLOT(sltHandleContextMenuCall(const QPoint&)));
    1192         connect(pTreeWidget, SIGNAL(resized(const QSize&, const QSize&)),
    1193                 this, SLOT(sltPerformTablesAdjustment()), Qt::QueuedConnection);
    1194         connect(pTreeWidget->header(), SIGNAL(sectionResized(int, int, int)),
    1195                 this, SLOT(sltPerformTablesAdjustment()), Qt::QueuedConnection);
    1196     }
    1197 }
    1198 
    1199 void UIMediumManager::prepareTreeWidgetFD()
    1200 {
    1201     /* FD tree-widget created in .ui file. */
    1202     {
    1203         /* Configure FD tree-widget: */
    1204         QTreeWidget *pTreeWidget = treeWidget(UIMediumType_Floppy);
    1205         pTreeWidget->setColumnCount(2);
    1206         pTreeWidget->sortItems(0, Qt::AscendingOrder);
    1207         pTreeWidget->header()->setResizeMode(0, QHeaderView::Fixed);
    1208         pTreeWidget->header()->setResizeMode(1, QHeaderView::ResizeToContents);
    1209         pTreeWidget->header()->setStretchLastSection(false);
    1210         pTreeWidget->setSortingEnabled(true);
    1211         connect(pTreeWidget, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)),
    1212                 this, SLOT(sltHandleCurrentItemChanged()));
    1213         connect(pTreeWidget, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)),
    1214                 this, SLOT(sltHandleDoubleClick()));
    1215         connect(pTreeWidget, SIGNAL(customContextMenuRequested(const QPoint&)),
    1216                 this, SLOT(sltHandleContextMenuCall(const QPoint&)));
    1217         connect(pTreeWidget, SIGNAL(resized(const QSize&, const QSize&)),
    1218                 this, SLOT(sltPerformTablesAdjustment()), Qt::QueuedConnection);
    1219         connect(pTreeWidget->header(), SIGNAL(sectionResized(int, int, int)),
    1220                 this, SLOT(sltPerformTablesAdjustment()), Qt::QueuedConnection);
    1221     }
    1222 }
    1223 
    1224 void UIMediumManager::prepareInformationPanes()
     1187void UIMediumManager::prepareInformationContainer(UIMediumType, int)
    12251188{
    12261189    /* Information-panes created in .ui file. */
     
    12391202        /* Configure button-box: */
    12401203        mButtonBox->button(QDialogButtonBox::Ok)->setDefault(true);
     1204        connect(mButtonBox, SIGNAL(helpRequested()), &msgCenter(), SLOT(sltShowHelpHelpDialog()));
    12411205        connect(mButtonBox, SIGNAL(accepted()), this, SLOT(accept()));
    1242         connect(mButtonBox, SIGNAL(helpRequested()), &msgCenter(), SLOT(sltShowHelpHelpDialog()));
    12431206        /* Prepare progress-bar: */
    12441207        prepareProgressBar();
     
    12491212{
    12501213    /* Create progress-bar: */
    1251     m_pProgressBar = new UIEnumerationProgressBar(this);
     1214    m_pProgressBar = new UIEnumerationProgressBar;
    12521215    {
    12531216        /* Configure progress-bar: */
    12541217        m_pProgressBar->hide();
     1218        /* Add progress-bar into button-box layout: */
    12551219        mButtonBox->addExtraWidget(m_pProgressBar);
    12561220    }
     
    18551819}
    18561820
     1821QTreeWidget* UIMediumManager::treeWidget(UIMediumType type) const
     1822{
     1823    /* Return corresponding tree-widget for known medium types: */
     1824    switch (type)
     1825    {
     1826        case UIMediumType_HardDisk: return mTwHD;
     1827        case UIMediumType_DVD:      return mTwCD;
     1828        case UIMediumType_Floppy:   return mTwFD;
     1829        default: AssertMsgFailed(("Unknown medium type: %d\n", type)); break;
     1830    }
     1831    /* Null by default: */
     1832    return 0;
     1833}
     1834
     1835UIMediumItem* UIMediumManager::mediumItem(UIMediumType type) const
     1836{
     1837    /* Get corresponding tree-widget: */
     1838    QTreeWidget *pTreeWidget = treeWidget(type);
     1839    /* Return corresponding medium-item: */
     1840    return pTreeWidget ? toMediumItem(pTreeWidget->currentItem()) : 0;
     1841}
     1842
    18571843UIMediumType UIMediumManager::mediumType(QTreeWidget *pTreeWidget) const
    18581844{
     
    18651851    /* Invalid by default: */
    18661852    AssertFailedReturn(UIMediumType_Invalid);
    1867 }
    1868 
    1869 QTreeWidget* UIMediumManager::treeWidget(UIMediumType type) const
    1870 {
    1871     /* Return corresponding tree-widget for known medium types: */
    1872     switch (type)
    1873     {
    1874         case UIMediumType_HardDisk: return mTwHD;
    1875         case UIMediumType_DVD:      return mTwCD;
    1876         case UIMediumType_Floppy:   return mTwFD;
    1877         default: AssertMsgFailed(("Unknown medium type: %d\n", type)); break;
    1878     }
    1879     /* Null by default: */
    1880     return 0;
    1881 }
    1882 
    1883 UIMediumItem* UIMediumManager::mediumItem(UIMediumType type) const
    1884 {
    1885     /* Get corresponding tree-widget: */
    1886     QTreeWidget *pTreeWidget = treeWidget(type);
    1887     /* Return corresponding medium-item: */
    1888     return pTreeWidget ? toMediumItem(pTreeWidget->currentItem()) : 0;
    18891853}
    18901854
  • trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumManager.h

    r50959 r50960  
    118118    /** Prepare tab-widget. */
    119119    void prepareTabWidget();
    120     /** Prepare tree-widgets. */
    121     void prepareTreeWidgets();
    122     /** Prepare hard-drive tree-widget. */
    123     void prepareTreeWidgetHD();
    124     /** Prepare optical-disk tree-widget. */
    125     void prepareTreeWidgetCD();
    126     /** Prepare floppy-disk tree-widget. */
    127     void prepareTreeWidgetFD();
    128     /** Prepare information-panes. */
    129     void prepareInformationPanes();
     120    /** Prepare tab-widget's tab. */
     121    void prepareTab(UIMediumType type);
     122    /** Prepare tab-widget's tree-widget. */
     123    void prepareTreeWidget(UIMediumType type, int iColumns);
     124    /** Prepare tab-widget's information-container. */
     125    void prepareInformationContainer(UIMediumType type, int iFields);
    130126    /** Prepare button-box. */
    131127    void prepareButtonBox();
     
    181177    void deleteMediumItem(const QString &strMediumID);
    182178
    183     /** Returns medium type for passed @a pTreeWidget. */
    184     UIMediumType mediumType(QTreeWidget *pTreeWidget) const;
    185179    /** Returns tree-widget for passed medium @a type. */
    186180    QTreeWidget* treeWidget(UIMediumType type) const;
    187181    /** Returns item for passed medium @a type. */
    188182    UIMediumItem* mediumItem(UIMediumType type) const;
     183
     184    /** Returns medium type for passed @a pTreeWidget. */
     185    UIMediumType mediumType(QTreeWidget *pTreeWidget) const;
    189186
    190187    /** Returns current medium type. */
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