VirtualBox

Ignore:
Timestamp:
Aug 31, 2020 2:50:13 PM (4 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9812: VM settings: Prepare cascade cleanup for Shared Folders page.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/settings/machine
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsSF.cpp

    r85645 r85959  
    279279
    280280UIMachineSettingsSF::UIMachineSettingsSF()
    281     : m_pActionAdd(0), m_pActionEdit(0), m_pActionRemove(0)
    282     , m_pCache(0)
    283     , m_pFoldersTreeWidget(0)
    284     , m_pNameSeparator(0)
    285     , m_pFoldersToolBar(0)
    286 {
    287     /* Prepare: */
     281    : m_pCache(0)
     282    , m_pLabelSeparator(0)
     283    , m_pLayoutTree(0)
     284    , m_pTreeWidget(0)
     285    , m_pToolBar(0)
     286    , m_pActionAdd(0)
     287    , m_pActionEdit(0)
     288    , m_pActionRemove(0)
     289{
    288290    prepare();
    289291}
     
    363365{
    364366    /* Clear list initially: */
    365     m_pFoldersTreeWidget->clear();
     367    m_pTreeWidget->clear();
    366368
    367369    /* Update root items visibility: */
     
    373375
    374376    /* Choose first folder as current: */
    375     m_pFoldersTreeWidget->setCurrentItem(m_pFoldersTreeWidget->topLevelItem(0));
    376     sltHandleCurrentItemChange(m_pFoldersTreeWidget->currentItem());
     377    m_pTreeWidget->setCurrentItem(m_pTreeWidget->topLevelItem(0));
     378    sltHandleCurrentItemChange(m_pTreeWidget->currentItem());
    377379
    378380    /* Polish page finally: */
     
    386388
    387389    /* For each folder type: */
    388     QTreeWidgetItem *pMainRootItem = m_pFoldersTreeWidget->invisibleRootItem();
     390    QTreeWidgetItem *pMainRootItem = m_pTreeWidget->invisibleRootItem();
    389391    for (int iFolderTypeIndex = 0; iFolderTypeIndex < pMainRootItem->childCount(); ++iFolderTypeIndex)
    390392    {
     
    417419}
    418420
    419 
    420421void UIMachineSettingsSF::retranslateUi()
    421422{
    422     m_pNameSeparator->setText(tr("Shared &Folders"));
    423     QTreeWidgetItem *pQTreeWidgetItem = m_pFoldersTreeWidget->headerItem();
     423    m_pLabelSeparator->setText(tr("Shared &Folders"));
     424    QTreeWidgetItem *pQTreeWidgetItem = m_pTreeWidget->headerItem();
    424425    pQTreeWidgetItem->setText(4, tr("At"));
    425426    pQTreeWidgetItem->setText(3, tr("Auto Mount"));
     
    428429    pQTreeWidgetItem->setText(0, tr("Name"));
    429430#ifndef QT_NO_WHATSTHIS
    430     m_pFoldersTreeWidget->setWhatsThis(tr("Lists all shared folders accessible to this machine. Use 'net use x: \\\\vboxsvr\\share' to access a shared folder named <i>share</i> from a DOS-like OS, or 'mount -t vboxsf share mount_point' to access it from a Linux OS. This feature requires Guest Additions."));
     431    m_pTreeWidget->setWhatsThis(tr("Lists all shared folders accessible to this machine. Use 'net use x: \\\\vboxsvr\\share' to access a shared folder named <i>share</i> from a DOS-like OS, or 'mount -t vboxsf share mount_point' to access it from a Linux OS. This feature requires Guest Additions."));
    431432#endif // QT_NO_WHATSTHIS
    432433
     
    448449{
    449450    /* Polish shared folders page availability: */
    450     m_pNameSeparator->setEnabled(isMachineInValidMode());
    451     m_pFoldersToolBar->setEnabled(isMachineInValidMode());
    452     m_pFoldersToolBar->setEnabled(isMachineInValidMode());
     451    m_pLabelSeparator->setEnabled(isMachineInValidMode());
     452    m_pToolBar->setEnabled(isMachineInValidMode());
     453    m_pToolBar->setEnabled(isMachineInValidMode());
    453454
    454455    /* Update root items visibility: */
     
    462463
    463464    /* Connect header-resize signal just before widget is shown after all the items properly loaded and initialized: */
    464     connect(m_pFoldersTreeWidget->header(), &QHeaderView::sectionResized, this, &UIMachineSettingsSF::sltAdjustTreeFields);
     465    connect(m_pTreeWidget->header(), &QHeaderView::sectionResized, this, &UIMachineSettingsSF::sltAdjustTreeFields);
    465466
    466467    /* Adjusting size after all pending show events are processed: */
     
    503504
    504505        /* Sort tree-widget before adjusting: */
    505         m_pFoldersTreeWidget->sortItems(0, Qt::AscendingOrder);
     506        m_pTreeWidget->sortItems(0, Qt::AscendingOrder);
    506507        /* Adjust tree-widget finally: */
    507508        sltAdjustTree();
     
    512513{
    513514    /* Check current folder item: */
    514     SFTreeViewItem *pItem = static_cast<SFTreeViewItem*>(m_pFoldersTreeWidget->currentItem());
     515    SFTreeViewItem *pItem = static_cast<SFTreeViewItem*>(m_pTreeWidget->currentItem());
    515516    AssertPtrReturnVoid(pItem);
    516517    AssertPtrReturnVoid(pItem->parentItem());
     
    555556
    556557            /* Update tree-widget: */
    557             m_pFoldersTreeWidget->scrollToItem(pItem);
    558             m_pFoldersTreeWidget->setCurrentItem(pItem);
     558            m_pTreeWidget->scrollToItem(pItem);
     559            m_pTreeWidget->setCurrentItem(pItem);
    559560            sltHandleCurrentItemChange(pItem);
    560561        }
    561562
    562563        /* Sort tree-widget before adjusting: */
    563         m_pFoldersTreeWidget->sortItems(0, Qt::AscendingOrder);
     564        m_pTreeWidget->sortItems(0, Qt::AscendingOrder);
    564565        /* Adjust tree-widget finally: */
    565566        sltAdjustTree();
     
    570571{
    571572    /* Check current folder item: */
    572     QTreeWidgetItem *pItem = m_pFoldersTreeWidget->currentItem();
     573    QTreeWidgetItem *pItem = m_pTreeWidget->currentItem();
    573574    AssertPtrReturnVoid(pItem);
    574575
     
    601602{
    602603    QMenu menu;
    603     QTreeWidgetItem *pItem = m_pFoldersTreeWidget->itemAt(position);
    604     if (m_pFoldersTreeWidget->isEnabled() && pItem && pItem->flags() & Qt::ItemIsSelectable)
     604    QTreeWidgetItem *pItem = m_pTreeWidget->itemAt(position);
     605    if (m_pTreeWidget->isEnabled() && pItem && pItem->flags() & Qt::ItemIsSelectable)
    605606    {
    606607        menu.addAction(m_pActionEdit);
     
    612613    }
    613614    if (!menu.isEmpty())
    614         menu.exec(m_pFoldersTreeWidget->viewport()->mapToGlobal(position));
     615        menu.exec(m_pTreeWidget->viewport()->mapToGlobal(position));
    615616}
    616617
     
    628629     * 4 = Auto mount point
    629630     */
    630     QAbstractItemView *pItemView = m_pFoldersTreeWidget;
    631     QHeaderView *pItemHeader = m_pFoldersTreeWidget->header();
    632     const int iTotal = m_pFoldersTreeWidget->viewport()->width();
     631    QAbstractItemView *pItemView = m_pTreeWidget;
     632    QHeaderView *pItemHeader = m_pTreeWidget->header();
     633    const int iTotal = m_pTreeWidget->viewport()->width();
    633634
    634635    const int mw0 = qMax(pItemView->sizeHintForColumn(0), pItemHeader->sectionSizeHint(0));
     
    668669    }
    669670#endif
    670     m_pFoldersTreeWidget->setColumnWidth(0, w0);
    671     m_pFoldersTreeWidget->setColumnWidth(1, w1);
    672     m_pFoldersTreeWidget->setColumnWidth(2, w2);
    673     m_pFoldersTreeWidget->setColumnWidth(3, w3);
    674     m_pFoldersTreeWidget->setColumnWidth(4, w4);
     671    m_pTreeWidget->setColumnWidth(0, w0);
     672    m_pTreeWidget->setColumnWidth(1, w1);
     673    m_pTreeWidget->setColumnWidth(2, w2);
     674    m_pTreeWidget->setColumnWidth(3, w3);
     675    m_pTreeWidget->setColumnWidth(4, w4);
    675676}
    676677
    677678void UIMachineSettingsSF::sltAdjustTreeFields()
    678679{
    679     QTreeWidgetItem *pMainRoot = m_pFoldersTreeWidget->invisibleRootItem();
     680    QTreeWidgetItem *pMainRoot = m_pTreeWidget->invisibleRootItem();
    680681    for (int i = 0; i < pMainRoot->childCount(); ++i)
    681682    {
     
    690691}
    691692
    692 void UIMachineSettingsSF::prepareWidgets()
    693 {
    694     if (objectName().isEmpty())
    695         setObjectName(QStringLiteral("UIMachineSettingsSF"));
    696     resize(300, 220);
    697     QVBoxLayout *pMainLayout = new QVBoxLayout(this);
    698     pMainLayout->setObjectName(QStringLiteral("pMainLayout"));
    699     pMainLayout->setContentsMargins(0, 0, 0, 0);
    700     m_pNameSeparator = new QILabelSeparator(this);
    701     m_pNameSeparator->setObjectName(QStringLiteral("m_pNameSeparator"));
    702 
    703     pMainLayout->addWidget(m_pNameSeparator);
    704 
    705     QWidget *m_pFoldersTreeWidgetContainer = new QWidget(this);
    706     m_pFoldersTreeWidgetContainer->setObjectName(QStringLiteral("m_pFoldersTreeWidgetContainer"));
    707     QHBoxLayout *pFoldersLayout = new QHBoxLayout(m_pFoldersTreeWidgetContainer);
    708     pFoldersLayout->setSpacing(3);
    709     pFoldersLayout->setObjectName(QStringLiteral("pFoldersLayout"));
    710     pFoldersLayout->setContentsMargins(0, 0, 0, 0);
    711     m_pFoldersTreeWidget = new QITreeWidget(m_pFoldersTreeWidgetContainer);
    712     m_pFoldersTreeWidget->setObjectName(QStringLiteral("m_pFoldersTreeWidget"));
    713     m_pFoldersTreeWidget->setMinimumSize(QSize(0, 200));
    714     m_pFoldersTreeWidget->setContextMenuPolicy(Qt::CustomContextMenu);
    715     m_pFoldersTreeWidget->setUniformRowHeights(true);
    716     m_pFoldersTreeWidget->setAllColumnsShowFocus(true);
    717 
    718     pFoldersLayout->addWidget(m_pFoldersTreeWidget);
    719 
    720     m_pFoldersToolBar = new UIToolBar(m_pFoldersTreeWidgetContainer);
    721     m_pFoldersToolBar->setObjectName(QStringLiteral("m_pFoldersToolBar"));
    722 
    723     pFoldersLayout->addWidget(m_pFoldersToolBar);
    724     pMainLayout->addWidget(m_pFoldersTreeWidgetContainer);
    725     m_pNameSeparator->setBuddy(m_pFoldersTreeWidget);
    726 }
    727 
    728693void UIMachineSettingsSF::prepare()
    729694{
    730     prepareWidgets();
    731 
    732695    /* Prepare cache: */
    733696    m_pCache = new UISettingsCacheSharedFolders;
    734697    AssertPtrReturnVoid(m_pCache);
    735698
    736     /* Layout created in the .ui file. */
    737     {
    738         /* Prepare shared folders tree: */
    739         prepareFoldersTree();
    740         /* Prepare shared folders toolbar: */
    741         prepareFoldersToolbar();
    742         /* Prepare connections: */
    743         prepareConnections();
    744     }
     699    /* Prepare everything: */
     700    prepareWidgets();
     701    prepareConnections();
    745702
    746703    /* Apply language settings: */
     
    748705}
    749706
    750 void UIMachineSettingsSF::prepareFoldersTree()
    751 {
    752     /* Shared Folders tree-widget created in the .ui file. */
    753     AssertPtrReturnVoid(m_pFoldersTreeWidget);
    754     {
    755         /* Configure tree-widget: */
    756         m_pFoldersTreeWidget->header()->setSectionsMovable(false);
    757     }
    758 }
    759 
    760 void UIMachineSettingsSF::prepareFoldersToolbar()
    761 {
    762     /* Shared Folders toolbar created in the .ui file. */
    763     AssertPtrReturnVoid(m_pFoldersToolBar);
    764     {
    765         /* Configure toolbar: */
     707void UIMachineSettingsSF::prepareWidgets()
     708{
     709    /* Prepare main layout: */
     710    QVBoxLayout *pLayoutMain = new QVBoxLayout(this);
     711    if (pLayoutMain)
     712    {
     713        pLayoutMain->setContentsMargins(0, 0, 0, 0);
     714
     715        /* Prepare separator: */
     716        m_pLabelSeparator = new QILabelSeparator(this);
     717        if (m_pLabelSeparator)
     718            pLayoutMain->addWidget(m_pLabelSeparator);
     719
     720        /* Prepare view layout: */
     721        m_pLayoutTree = new QHBoxLayout;
     722        if (m_pLayoutTree)
     723        {
     724            m_pLayoutTree->setContentsMargins(0, 0, 0, 0);
     725            m_pLayoutTree->setSpacing(3);
     726
     727            /* Prepare tree-widget: */
     728            prepareTreeWidget();
     729            /* Prepare toolbar: */
     730            prepareToolbar();
     731
     732            pLayoutMain->addLayout(m_pLayoutTree);
     733        }
     734    }
     735}
     736
     737void UIMachineSettingsSF::prepareTreeWidget()
     738{
     739    /* Prepare shared folders tree-widget: */
     740    m_pTreeWidget = new QITreeWidget(this);
     741    if (m_pTreeWidget)
     742    {
     743        if (m_pLabelSeparator)
     744            m_pLabelSeparator->setBuddy(m_pTreeWidget);
     745        m_pTreeWidget->header()->setSectionsMovable(false);
     746        m_pTreeWidget->setMinimumSize(QSize(0, 200));
     747        m_pTreeWidget->setContextMenuPolicy(Qt::CustomContextMenu);
     748        m_pTreeWidget->setUniformRowHeights(true);
     749        m_pTreeWidget->setAllColumnsShowFocus(true);
     750
     751        m_pLayoutTree->addWidget(m_pTreeWidget);
     752    }
     753}
     754
     755void UIMachineSettingsSF::prepareToolbar()
     756{
     757    /* Prepare shared folders toolbar: */
     758    m_pToolBar = new UIToolBar(this);
     759    if (m_pToolBar)
     760    {
    766761        const int iIconMetric = QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize);
    767         m_pFoldersToolBar->setIconSize(QSize(iIconMetric, iIconMetric));
    768         m_pFoldersToolBar->setOrientation(Qt::Vertical);
    769 
    770         /* Create 'Add Shared Folder' action: */
    771         m_pActionAdd = m_pFoldersToolBar->addAction(UIIconPool::iconSet(":/sf_add_16px.png",
     762        m_pToolBar->setIconSize(QSize(iIconMetric, iIconMetric));
     763        m_pToolBar->setOrientation(Qt::Vertical);
     764
     765        /* Prepare 'Add Shared Folder' action: */
     766        m_pActionAdd = m_pToolBar->addAction(UIIconPool::iconSet(":/sf_add_16px.png",
    772767                                                                        ":/sf_add_disabled_16px.png"),
    773768                                                    QString(), this, SLOT(sltAddFolder()));
    774         AssertPtrReturnVoid(m_pActionAdd);
    775         {
    776             /* Configure action: */
     769        if (m_pActionAdd)
    777770            m_pActionAdd->setShortcuts(QList<QKeySequence>() << QKeySequence("Ins") << QKeySequence("Ctrl+N"));
    778         }
    779 
    780         /* Create 'Edit Shared Folder' action: */
    781         m_pActionEdit = m_pFoldersToolBar->addAction(UIIconPool::iconSet(":/sf_edit_16px.png",
     771
     772        /* Prepare 'Edit Shared Folder' action: */
     773        m_pActionEdit = m_pToolBar->addAction(UIIconPool::iconSet(":/sf_edit_16px.png",
    782774                                                                         ":/sf_edit_disabled_16px.png"),
    783775                                                     QString(), this, SLOT(sltEditFolder()));
    784         AssertPtrReturnVoid(m_pActionEdit);
    785         {
    786             /* Configure action: */
     776        if (m_pActionEdit)
    787777            m_pActionEdit->setShortcuts(QList<QKeySequence>() << QKeySequence("Space") << QKeySequence("F2"));
    788         }
    789 
    790         /* Create 'Remove Shared Folder' action: */
    791         m_pActionRemove = m_pFoldersToolBar->addAction(UIIconPool::iconSet(":/sf_remove_16px.png",
     778
     779        /* Prepare 'Remove Shared Folder' action: */
     780        m_pActionRemove = m_pToolBar->addAction(UIIconPool::iconSet(":/sf_remove_16px.png",
    792781                                                                           ":/sf_remove_disabled_16px.png"),
    793782                                                       QString(), this, SLOT(sltRemoveFolder()));
    794         AssertPtrReturnVoid(m_pActionRemove);
    795         {
    796             /* Configure action: */
     783        if (m_pActionRemove)
    797784            m_pActionRemove->setShortcuts(QList<QKeySequence>() << QKeySequence("Del") << QKeySequence("Ctrl+R"));
    798         }
     785
     786        m_pLayoutTree->addWidget(m_pToolBar);
    799787    }
    800788}
     
    803791{
    804792    /* Configure tree-widget connections: */
    805     connect(m_pFoldersTreeWidget, &QITreeWidget::currentItemChanged,
     793    connect(m_pTreeWidget, &QITreeWidget::currentItemChanged,
    806794            this, &UIMachineSettingsSF::sltHandleCurrentItemChange);
    807     connect(m_pFoldersTreeWidget, &QITreeWidget::itemDoubleClicked,
     795    connect(m_pTreeWidget, &QITreeWidget::itemDoubleClicked,
    808796            this, &UIMachineSettingsSF::sltHandleDoubleClick);
    809     connect(m_pFoldersTreeWidget, &QITreeWidget::customContextMenuRequested,
     797    connect(m_pTreeWidget, &QITreeWidget::customContextMenuRequested,
    810798            this, &UIMachineSettingsSF::sltHandleContextMenuRequest);
    811799}
     
    822810    /* Search for the corresponding root item among all the top-level items: */
    823811    SFTreeViewItem *pRootItem = 0;
    824     QTreeWidgetItem *pMainRootItem = m_pFoldersTreeWidget->invisibleRootItem();
     812    QTreeWidgetItem *pMainRootItem = m_pTreeWidget->invisibleRootItem();
    825813    for (int iFolderTypeIndex = 0; iFolderTypeIndex < pMainRootItem->childCount(); ++iFolderTypeIndex)
    826814    {
     
    844832    /* Make the used names list: */
    845833    QStringList list;
    846     QTreeWidgetItemIterator it(m_pFoldersTreeWidget);
     834    QTreeWidgetItemIterator it(m_pTreeWidget);
    847835    while (*it)
    848836    {
     
    887875    {
    888876        /* Create new shared folder type item: */
    889         pRootItem = new SFTreeViewItem(m_pFoldersTreeWidget, SFTreeViewItem::FormatType_EllipsisEnd);
     877        pRootItem = new SFTreeViewItem(m_pTreeWidget, SFTreeViewItem::FormatType_EllipsisEnd);
    890878        AssertPtrReturnVoid(pRootItem);
    891879        {
     
    925913        if (fChoose)
    926914        {
    927             m_pFoldersTreeWidget->scrollToItem(pItem);
    928             m_pFoldersTreeWidget->setCurrentItem(pItem);
     915            m_pTreeWidget->scrollToItem(pItem);
     916            m_pTreeWidget->setCurrentItem(pItem);
    929917            sltHandleCurrentItemChange(pItem);
    930918        }
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsSF.h

    r85643 r85959  
    2929
    3030/* Forward declarations: */
     31class QHBoxLayout;
    3132class QTreeWidgetItem;
    3233class QITreeWidget;
     
    112113    /** Prepares Widgets. */
    113114    void prepareWidgets();
    114     /** Prepares shared folders tree. */
    115     void prepareFoldersTree();
     115    /** Prepares shared folders tree-wdget. */
     116    void prepareTreeWidget();
    116117    /** Prepares shared folders toolbar. */
    117     void prepareFoldersToolbar();
     118    void prepareToolbar();
    118119    /** Prepares connections. */
    119120    void prepareConnections();
     
    150151    bool createSharedFolder(const UISettingsCacheSharedFolder &folderCache);
    151152
    152     /** Holds the Add action instance. */
    153     QAction *m_pActionAdd;
    154     /** Holds the Edit action instance. */
    155     QAction *m_pActionEdit;
    156     /** Holds the Remove action instance. */
    157     QAction *m_pActionRemove;
    158 
    159153    /** Holds the page data cache instance. */
    160154    UISettingsCacheSharedFolders *m_pCache;
     
    162156    /** @name Widgets
    163157      * @{ */
    164         QITreeWidget *m_pFoldersTreeWidget;
    165         QILabelSeparator *m_pNameSeparator;
    166         UIToolBar *m_pFoldersToolBar;
     158        /** Holds the widget separator instance. */
     159        QILabelSeparator *m_pLabelSeparator;
     160        /** Holds the tree layout instance. */
     161        QHBoxLayout      *m_pLayoutTree;
     162        /** Holds the tree-widget instance. */
     163        QITreeWidget     *m_pTreeWidget;
     164        /** Holds the toolbar instance. */
     165        UIToolBar        *m_pToolBar;
     166        /** Holds the Add action instance. */
     167        QAction          *m_pActionAdd;
     168        /** Holds the Edit action instance. */
     169        QAction          *m_pActionEdit;
     170        /** Holds the Remove action instance. */
     171        QAction          *m_pActionRemove;
    167172    /** @} */
    168173};
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