VirtualBox

Changeset 101392 in vbox for trunk/src


Ignore:
Timestamp:
Oct 9, 2023 10:12:12 AM (19 months ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
159413
Message:

FE/Qt: bugref:10513: UISettingsSelector: Lots of cleanup for selector of tree-widget type.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified trunk/src/VBox/Frontends/VirtualBox/src/settings/UISettingsSelector.cpp

    r101391 r101392  
    321321{
    322322    QWidget *pResult = 0;
    323     if (pPage != 0)
    324     {
     323    if (pPage)
     324    {
     325        /* Adjust page a bit: */
     326        pPage->setContentsMargins(0, 0, 0, 0);
     327        if (pPage->layout())
     328            pPage->layout()->setContentsMargins(0, 0, 0, 0);
     329        pResult = pPage;
     330
     331        /* Add selector-item object: */
    325332        const QIcon icon = UIIconPool::iconSet(strMediumIcon);
    326 
    327333        UISelectorItem *pItem = new UISelectorItem(icon, iID, strLink, pPage, iParentID);
    328         m_list.append(pItem);
    329 
    330         QTreeWidgetItem *pTwItem = new QITreeWidgetItem(m_pTreeWidget, QStringList() << QString("")
    331                                                                                      << idToString(iID)
    332                                                                                      << strLink);
    333         pTwItem->setIcon(TreeWidgetSection_Category, pItem->icon());
    334         pPage->setContentsMargins(0, 0, 0, 0);
    335         pPage->layout()->setContentsMargins(0, 0, 0, 0);
    336         pResult = pPage;
     334        if (pItem)
     335            m_list.append(pItem);
     336
     337        /* Add tree-widget item: */
     338        QITreeWidgetItem *pTwItem = new QITreeWidgetItem(m_pTreeWidget, QStringList() << QString("")
     339                                                                                      << idToString(iID)
     340                                                                                      << strLink);
     341        if (pTwItem)
     342            pTwItem->setIcon(TreeWidgetSection_Category, pItem->icon());
    337343    }
    338344    return pResult;
     
    341347void UISettingsSelectorTreeWidget::setItemText(int iID, const QString &strText)
    342348{
     349    /* Call to base-class: */
    343350    UISettingsSelector::setItemText(iID, strText);
     351
     352    /* Look for the tree-widget item to assign the text: */
    344353    QTreeWidgetItem *pItem = findItem(m_pTreeWidget, idToString(iID), TreeWidgetSection_Id);
    345354    if (pItem)
     
    380389{
    381390    /* Get recommended size hint: */
    382     const QStyle *pStyle = QApplication::style();
    383     const int iIconMetric = pStyle->pixelMetric(QStyle::PM_SmallIconSize);
    384     int iItemWidth = static_cast<QAbstractItemView*>(m_pTreeWidget)->sizeHintForColumn(TreeWidgetSection_Category);
    385     int iItemHeight = qMax((int)(iIconMetric * 1.5) /* icon height */,
    386                            m_pTreeWidget->fontMetrics().height() /* text height */);
    387     /* Add some margin to every item in the tree: */
    388     iItemHeight += 4 /* margin itself */ * 2 /* margin count */;
     391    const int iIconMetric = QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize);
     392    const int iItemWidth = static_cast<QAbstractItemView*>(m_pTreeWidget)->sizeHintForColumn(TreeWidgetSection_Category);
     393    const int iItemHeight = qMax((int)(iIconMetric * 1.5) /* icon height */,
     394                                 m_pTreeWidget->fontMetrics().height() /* text height */)
     395                          + 4 /* margin itself */ * 2 /* margin count */;
     396
    389397    /* Set final size hint for items: */
    390398    m_pTreeWidget->setSizeHintForItems(QSize(iItemWidth , iItemHeight));
     
    392400    /* Adjust selector width/height: */
    393401    m_pTreeWidget->setFixedWidth(iItemWidth + 2 * m_pTreeWidget->frameWidth());
    394     m_pTreeWidget->setMinimumHeight(m_pTreeWidget->topLevelItemCount() * iItemHeight +
    395                                     1 /* margin itself */ * 2 /* margin count */);
     402    m_pTreeWidget->setMinimumHeight(  m_pTreeWidget->topLevelItemCount() * iItemHeight
     403                                    + 1 /* margin itself */ * 2 /* margin count */);
    396404
    397405    /* Sort selector by the id column: */
     
    402410}
    403411
    404 void UISettingsSelectorTreeWidget::sltSettingsGroupChanged(QTreeWidgetItem *pItem,
    405                                                          QTreeWidgetItem * /* pPrevItem */)
     412void UISettingsSelectorTreeWidget::sltSettingsGroupChanged(QTreeWidgetItem *pItem, QTreeWidgetItem * /* pPrevItem */)
    406413{
    407414    if (pItem)
     
    443450QString UISettingsSelectorTreeWidget::pagePath(const QString &strMatch) const
    444451{
    445     const QTreeWidgetItem *pTreeItem =
    446         findItem(m_pTreeWidget,
    447                  strMatch,
    448                  TreeWidgetSection_Id);
     452    const QTreeWidgetItem *pTreeItem = findItem(m_pTreeWidget, strMatch, TreeWidgetSection_Id);
    449453    return path(pTreeItem);
    450454}
    451455
    452 QTreeWidgetItem *UISettingsSelectorTreeWidget::findItem(QTreeWidget *pView,
    453                                                         const QString &strMatch,
    454                                                         int iColumn) const
    455 {
    456     QList<QTreeWidgetItem*> list =
    457         pView->findItems(strMatch, Qt::MatchExactly, iColumn);
    458 
    459     return list.count() ? list[0] : 0;
     456QTreeWidgetItem *UISettingsSelectorTreeWidget::findItem(QTreeWidget *pView, const QString &strMatch, int iColumn) const
     457{
     458    const QList<QTreeWidgetItem*> list = pView->findItems(strMatch, Qt::MatchExactly, iColumn);
     459    return list.count() ? list.first() : 0;
    460460}
    461461
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