VirtualBox

Changeset 86005 in vbox for trunk/src


Ignore:
Timestamp:
Sep 2, 2020 3:46:14 PM (4 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9812: Global preferences: Prepare cascade cleanup for Extension page.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/global/UIGlobalSettingsExtension.cpp

    r85973 r86005  
    1818/* Qt includes: */
    1919#include <QHeaderView>
    20 #include <QGridLayout>
    2120#include <QMenu>
     21#include <QVBoxLayout>
    2222#ifdef VBOX_WS_WIN
    2323# include <QTextStream>
     
    173173
    174174UIGlobalSettingsExtension::UIGlobalSettingsExtension()
    175     : m_pActionAdd(0), m_pActionRemove(0)
    176     , m_pCache(0)
    177     , m_pPackagesTree(0)
    178     , m_pEntensionLabel(0)
    179     , m_pPackagesToolbar(0)
     175    : m_pCache(0)
     176    , m_pLabelSeparator(0)
     177    , m_pLayoutPackages(0)
     178    , m_pTreeWidget(0)
     179    , m_pToolbar(0)
     180    , m_pActionAdd(0)
     181    , m_pActionRemove(0)
    180182{
    181183    /* Prepare: */
     
    224226    /* Load old extension data from the cache: */
    225227    foreach (const UIDataSettingsGlobalExtensionItem &item, oldExtensionData.m_items)
    226         new UIExtensionPackageItem(m_pPackagesTree, item);
     228        new UIExtensionPackageItem(m_pTreeWidget, item);
    227229    /* If at least one item present: */
    228     if (m_pPackagesTree->topLevelItemCount())
    229         m_pPackagesTree->setCurrentItem(m_pPackagesTree->topLevelItem(0));
     230    if (m_pTreeWidget->topLevelItemCount())
     231        m_pTreeWidget->setCurrentItem(m_pTreeWidget->topLevelItem(0));
    230232    /* Update action's availability: */
    231     sltHandleCurrentItemChange(m_pPackagesTree->currentItem());
     233    sltHandleCurrentItemChange(m_pTreeWidget->currentItem());
    232234}
    233235
     
    250252void UIGlobalSettingsExtension::retranslateUi()
    251253{
    252     m_pEntensionLabel->setText(tr("&Extension Packages"));
    253     QTreeWidgetItem *pTreeWidgetItem = m_pPackagesTree->headerItem();
     254    m_pLabelSeparator->setText(tr("&Extension Packages"));
     255    QTreeWidgetItem *pTreeWidgetItem = m_pTreeWidget->headerItem();
    254256    if (pTreeWidgetItem)
    255257    {
     
    258260        pTreeWidgetItem->setText(0, tr("Active"));
    259261    }
    260     m_pPackagesTree->setWhatsThis(tr("Lists all installed packages."));
     262    m_pTreeWidget->setWhatsThis(tr("Lists all installed packages."));
    261263
    262264    /* Translate actions: */
     
    280282{
    281283    QMenu menu;
    282     if (m_pPackagesTree->itemAt(position))
     284    if (m_pTreeWidget->itemAt(position))
    283285    {
    284286        menu.addAction(m_pActionAdd);
     
    289291        menu.addAction(m_pActionAdd);
    290292    }
    291     menu.exec(m_pPackagesTree->viewport()->mapToGlobal(position));
     293    menu.exec(m_pTreeWidget->viewport()->mapToGlobal(position));
    292294}
    293295
     
    337339
    338340            /* Remove it from the tree: */
    339             const int cItems = m_pPackagesTree->topLevelItemCount();
     341            const int cItems = m_pTreeWidget->topLevelItemCount();
    340342            for (int i = 0; i < cItems; i++)
    341343            {
    342                 UIExtensionPackageItem *pItem = static_cast<UIExtensionPackageItem*>(m_pPackagesTree->topLevelItem(i));
     344                UIExtensionPackageItem *pItem = static_cast<UIExtensionPackageItem*>(m_pTreeWidget->topLevelItem(i));
    343345                if (!strExtPackName.compare(pItem->name(), Qt::CaseInsensitive))
    344346                {
     
    357359                m_pCache->data().m_items << item;
    358360
    359                 UIExtensionPackageItem *pItem = new UIExtensionPackageItem(m_pPackagesTree, m_pCache->data().m_items.last());
    360                 m_pPackagesTree->setCurrentItem(pItem);
    361                 m_pPackagesTree->sortByColumn(1, Qt::AscendingOrder);
     361                UIExtensionPackageItem *pItem = new UIExtensionPackageItem(m_pTreeWidget, m_pCache->data().m_items.last());
     362                m_pTreeWidget->setCurrentItem(pItem);
     363                m_pTreeWidget->sortByColumn(1, Qt::AscendingOrder);
    362364            }
    363365        }
     
    368370{
    369371    /* Get current item: */
    370     UIExtensionPackageItem *pItem = m_pPackagesTree &&
    371                                     m_pPackagesTree->currentItem() ?
    372                                     static_cast<UIExtensionPackageItem*>(m_pPackagesTree->currentItem()) : 0;
     372    UIExtensionPackageItem *pItem = m_pTreeWidget &&
     373                                    m_pTreeWidget->currentItem() ?
     374                                    static_cast<UIExtensionPackageItem*>(m_pTreeWidget->currentItem()) : 0;
    373375
    374376    /* Uninstall chosen package: */
     
    422424void UIGlobalSettingsExtension::prepare()
    423425{
    424     prepareWidgets();
    425 
    426426    /* Prepare cache: */
    427427    m_pCache = new UISettingsCacheGlobalExtension;
    428428    AssertPtrReturnVoid(m_pCache);
    429429
    430     /* Layout created in the .ui file. */
    431     {
    432         /* Tree-widget created in the .ui file. */
    433         AssertPtrReturnVoid(m_pPackagesTree);
    434         {
    435             /* Configure tree-widget: */
    436             m_pPackagesTree->header()->setStretchLastSection(false);
    437             m_pPackagesTree->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
    438             m_pPackagesTree->header()->setSectionResizeMode(1, QHeaderView::Stretch);
    439             m_pPackagesTree->header()->setSectionResizeMode(2, QHeaderView::ResizeToContents);
    440             m_pPackagesTree->setContextMenuPolicy(Qt::CustomContextMenu);
    441             connect(m_pPackagesTree, &QITreeWidget::currentItemChanged,
    442                     this, &UIGlobalSettingsExtension::sltHandleCurrentItemChange);
    443             connect(m_pPackagesTree, &QITreeWidget::customContextMenuRequested,
    444                     this, &UIGlobalSettingsExtension::sltHandleContextMenuRequest);
    445         }
    446 
    447         /* Tool-bar created in the .ui file. */
    448         AssertPtrReturnVoid(m_pPackagesToolbar);
    449         {
    450             /* Configure toolbar: */
    451             const int iIconMetric = QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize);
    452             m_pPackagesToolbar->setOrientation(Qt::Vertical);
    453             m_pPackagesToolbar->setIconSize(QSize(iIconMetric, iIconMetric));
    454 
    455             /* Create 'Add Package' action: */
    456             m_pActionAdd = m_pPackagesToolbar->addAction(UIIconPool::iconSet(":/extension_pack_install_16px.png",
    457                                                                              ":/extension_pack_install_disabled_16px.png"),
    458                                                          QString(), this, SLOT(sltAddPackage()));
    459 
    460             /* Create 'Remove Package' action: */
    461             m_pActionRemove = m_pPackagesToolbar->addAction(UIIconPool::iconSet(":/extension_pack_uninstall_16px.png",
    462                                                                                 ":/extension_pack_uninstall_disabled_16px.png"),
    463                                                             QString(), this, SLOT(sltRemovePackage()));
    464         }
    465     }
     430    /* Prepare everything: */
     431    prepareWidgets();
     432    prepareConnections();
    466433
    467434    /* Apply language settings: */
     
    471438void UIGlobalSettingsExtension::prepareWidgets()
    472439{
    473     if (objectName().isEmpty())
    474         setObjectName(QStringLiteral("UIGlobalSettingsExtension"));
    475     QGridLayout *pMainLayout = new QGridLayout(this);
    476     pMainLayout->setContentsMargins(0, 0, 0, 0);
    477     pMainLayout->setObjectName(QStringLiteral("pMainLayout"));
    478     m_pEntensionLabel = new QILabelSeparator();
    479     m_pEntensionLabel->setObjectName(QStringLiteral("m_pEntensionLabel"));
    480     pMainLayout->addWidget(m_pEntensionLabel, 0, 0, 1, 1);
    481 
    482     QWidget *pExtensionPackContainer = new QWidget();
    483     pExtensionPackContainer->setObjectName(QStringLiteral("pExtensionPackContainer"));
    484     QHBoxLayout *pLayout1 = new QHBoxLayout(pExtensionPackContainer);
    485     pLayout1->setSpacing(3);
    486     pLayout1->setContentsMargins(0, 0, 0, 0);
    487     pLayout1->setObjectName(QStringLiteral("pLayout1"));
    488     m_pPackagesTree = new QITreeWidget(pExtensionPackContainer);
    489     m_pPackagesTree->setObjectName(QStringLiteral("m_pPackagesTree"));
    490     m_pPackagesTree->setColumnCount(3);
    491     QSizePolicy sizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
    492     sizePolicy.setHorizontalStretch(0);
    493     sizePolicy.setVerticalStretch(0);
    494     sizePolicy.setHeightForWidth(m_pPackagesTree->sizePolicy().hasHeightForWidth());
    495     m_pPackagesTree->setSizePolicy(sizePolicy);
    496     m_pPackagesTree->setMinimumSize(QSize(0, 150));
    497     m_pPackagesTree->setRootIsDecorated(false);
    498     pLayout1->addWidget(m_pPackagesTree);
    499 
    500     m_pPackagesToolbar = new UIToolBar(pExtensionPackContainer);
    501     m_pPackagesToolbar->setObjectName(QStringLiteral("m_pPackagesToolbar"));
    502     pLayout1->addWidget(m_pPackagesToolbar);
    503 
    504     pMainLayout->addWidget(pExtensionPackContainer, 1, 0, 1, 1);
    505     m_pEntensionLabel->setBuddy(m_pPackagesTree);
     440    /* Prepare main layout: */
     441    QVBoxLayout *pLayoutMain = new QVBoxLayout(this);
     442    if (pLayoutMain)
     443    {
     444        pLayoutMain->setContentsMargins(0, 0, 0, 0);
     445
     446        /* Prepare separator: */
     447        m_pLabelSeparator = new QILabelSeparator(this);
     448        if (m_pLabelSeparator)
     449            pLayoutMain->addWidget(m_pLabelSeparator);
     450
     451        /* Prepare packages layout: */
     452        m_pLayoutPackages = new QHBoxLayout;
     453        if (m_pLayoutPackages)
     454        {
     455            m_pLayoutPackages->setSpacing(3);
     456
     457            /* Prepare tree-widget: */
     458            prepareTreeWidget();
     459            /* Prepare toolbar: */
     460            prepareToolbar();
     461
     462            pLayoutMain->addLayout(m_pLayoutPackages);
     463        }
     464    }
     465}
     466
     467void UIGlobalSettingsExtension::prepareTreeWidget()
     468{
     469    /* Prepare tree-widget: */
     470    m_pTreeWidget = new QITreeWidget(this);
     471    if (m_pTreeWidget)
     472    {
     473        if (m_pLabelSeparator)
     474            m_pLabelSeparator->setBuddy(m_pTreeWidget);
     475        m_pTreeWidget->setColumnCount(3);
     476        m_pTreeWidget->setRootIsDecorated(false);
     477        m_pTreeWidget->header()->setStretchLastSection(false);
     478        m_pTreeWidget->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
     479        m_pTreeWidget->header()->setSectionResizeMode(1, QHeaderView::Stretch);
     480        m_pTreeWidget->header()->setSectionResizeMode(2, QHeaderView::ResizeToContents);
     481        m_pTreeWidget->setContextMenuPolicy(Qt::CustomContextMenu);
     482
     483        m_pLayoutPackages->addWidget(m_pTreeWidget);
     484    }
     485}
     486
     487void UIGlobalSettingsExtension::prepareToolbar()
     488{
     489    /* Prepare toolbar: */
     490    m_pToolbar = new UIToolBar(this);
     491    if (m_pToolbar)
     492    {
     493        /* Configure toolbar: */
     494        const int iIconMetric = QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize);
     495        m_pToolbar->setIconSize(QSize(iIconMetric, iIconMetric));
     496        m_pToolbar->setOrientation(Qt::Vertical);
     497
     498        /* Prepare 'Add Package' action: */
     499        m_pActionAdd = m_pToolbar->addAction(UIIconPool::iconSet(":/extension_pack_install_16px.png",
     500                                                                 ":/extension_pack_install_disabled_16px.png"),
     501                                             QString(), this, SLOT(sltAddPackage()));
     502
     503        /* Prepare 'Remove Package' action: */
     504        m_pActionRemove = m_pToolbar->addAction(UIIconPool::iconSet(":/extension_pack_uninstall_16px.png",
     505                                                                    ":/extension_pack_uninstall_disabled_16px.png"),
     506                                                QString(), this, SLOT(sltRemovePackage()));
     507
     508        m_pLayoutPackages->addWidget(m_pToolbar);
     509    }
     510}
     511
     512void UIGlobalSettingsExtension::prepareConnections()
     513{
     514    connect(m_pTreeWidget, &QITreeWidget::currentItemChanged,
     515            this, &UIGlobalSettingsExtension::sltHandleCurrentItemChange);
     516    connect(m_pTreeWidget, &QITreeWidget::customContextMenuRequested,
     517            this, &UIGlobalSettingsExtension::sltHandleContextMenuRequest);
    506518}
    507519
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/global/UIGlobalSettingsExtension.h

    r85822 r86005  
    2626
    2727/* Forward declarations: */
     28class QHBoxLayout;
    2829class QITreeWidget;
    2930class QTreeWidgetItem;
     
    8384    /** Prepares widgets. */
    8485    void prepareWidgets();
     86    /** Prepares tree-widget. */
     87    void prepareTreeWidget();
     88    /** Prepares toolbar. */
     89    void prepareToolbar();
     90    /** Prepares connections. */
     91    void prepareConnections();
    8592    /** Cleanups all. */
    8693    void cleanup();
     
    8996    void loadData(const CExtPack &package, UIDataSettingsGlobalExtensionItem &item) const;
    9097
    91     /** Holds the Add action instance. */
    92     QAction *m_pActionAdd;
    93     /** Holds the Remove action instance. */
    94     QAction *m_pActionRemove;
    95 
    9698    /** Holds the page data cache instance. */
    9799    UISettingsCacheGlobalExtension *m_pCache;
     100
    98101    /** @name Widgets
    99102     * @{ */
    100        QITreeWidget *m_pPackagesTree;
    101        QILabelSeparator *m_pEntensionLabel;
    102        UIToolBar *m_pPackagesToolbar;
     103        /** Holds the separator label instance. */
     104        QILabelSeparator *m_pLabelSeparator;
     105        /** Holds the packages layout instance. */
     106        QHBoxLayout      *m_pLayoutPackages;
     107        /** Holds the tree-widget instance. */
     108        QITreeWidget     *m_pTreeWidget;
     109        /** Holds the toolbar instance. */
     110        UIToolBar        *m_pToolbar;
     111        /** Holds the Add action instance. */
     112        QAction          *m_pActionAdd;
     113        /** Holds the Remove action instance. */
     114        QAction          *m_pActionRemove;
    103115    /** @} */
    104116};
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