VirtualBox

Ignore:
Timestamp:
Sep 2, 2020 10:06:55 AM (4 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9812: Global preferences: Prepare cascade cleanup for Language 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/UIGlobalSettingsLanguage.cpp

    r85822 r85990  
    200200    : m_fPolished(false)
    201201    , m_pCache(0)
    202     , m_pLanguageTree(0)
    203     , m_pLanguageLabel(0)
    204     , m_pLanguageInfo(0)
     202    , m_pTreeWidget(0)
     203    , m_pLabelSeparator(0)
     204    , m_pLabelInfo(0)
    205205{
    206206    /* Prepare: */
     
    250250
    251251    /* Gather new language data: */
    252     QTreeWidgetItem *pCurrentItem = m_pLanguageTree->currentItem();
     252    QTreeWidgetItem *pCurrentItem = m_pTreeWidget->currentItem();
    253253    Assert(pCurrentItem);
    254254    if (pCurrentItem)
     
    273273void UIGlobalSettingsLanguage::retranslateUi()
    274274{
    275     m_pLanguageLabel->setText(tr("&Interface Languages"));
    276     QTreeWidgetItem *pTreeWidgetItem = m_pLanguageTree->headerItem();
     275    m_pLabelSeparator->setText(tr("&Interface Languages"));
     276    QTreeWidgetItem *pTreeWidgetItem = m_pTreeWidget->headerItem();
    277277    if (pTreeWidgetItem)
    278278    {
     
    282282        pTreeWidgetItem->setText(0, tr("Name"));
    283283    }
    284     m_pLanguageTree->setWhatsThis(tr("Lists all available user interface "
     284    m_pTreeWidget->setWhatsThis(tr("Lists all available user interface "
    285285                                     "languages. The effective language is written in <b>bold</b>. "
    286286                                     "Select <i>Default</i> to reset to the system default language."));
     
    307307{
    308308    /* Remember current info-label width: */
    309     m_pLanguageInfo->setMinimumTextWidth(m_pLanguageInfo->width());
     309    m_pLabelInfo->setMinimumTextWidth(m_pLabelInfo->width());
    310310}
    311311
     
    317317        if (pLanguageItem->isBuiltIn())
    318318        {
    319             const QRect rect = m_pLanguageTree->visualItemRect(pLanguageItem);
    320             pPainter->setPen(m_pLanguageTree->palette().color(QPalette::Mid));
     319            const QRect rect = m_pTreeWidget->visualItemRect(pLanguageItem);
     320            pPainter->setPen(m_pTreeWidget->palette().color(QPalette::Mid));
    321321            pPainter->drawLine(rect.x(), rect.y() + rect.height() - 1,
    322322                               rect.x() + rect.width(), rect.y() + rect.height() - 1);
     
    333333    const bool fEnabled = !pCurrentItem->text (1).isNull();
    334334
    335     m_pLanguageInfo->setEnabled(fEnabled);
    336     m_pLanguageInfo->setText(QString("<table>"
     335    m_pLabelInfo->setEnabled(fEnabled);
     336    m_pLabelInfo->setText(QString("<table>"
    337337                             "<tr><td>%1&nbsp;</td><td>%2</td></tr>"
    338338                             "<tr><td>%3&nbsp;</td><td>%4</td></tr>"
     
    346346void UIGlobalSettingsLanguage::prepare()
    347347{
    348     prepareWidgets();
    349 
    350348    /* Prepare cache: */
    351349    m_pCache = new UISettingsCacheGlobalLanguage;
    352350    AssertPtrReturnVoid(m_pCache);
    353351
    354     /* Layout created in the .ui file. */
    355     {
    356         /* Tree-widget created in the .ui file. */
    357         AssertPtrReturnVoid(m_pLanguageTree);
    358         {
    359             /* Configure tree-widget: */
    360             m_pLanguageTree->header()->hide();
    361             m_pLanguageTree->hideColumn(1);
    362             m_pLanguageTree->hideColumn(2);
    363             m_pLanguageTree->hideColumn(3);
    364             m_pLanguageTree->setMinimumHeight(150);
    365             connect(m_pLanguageTree, &QITreeWidget::painted,
    366                     this, &UIGlobalSettingsLanguage::sltHandleItemPainting);
    367             connect(m_pLanguageTree, &QITreeWidget::currentItemChanged,
    368                     this, &UIGlobalSettingsLanguage::sltHandleCurrentItemChange);
    369         }
    370 
    371         /* Rich-text label created in the .ui file. */
    372         AssertPtrReturnVoid(m_pLanguageInfo);
    373         {
    374             /* Configure rich-text label: */
    375             m_pLanguageInfo->setWordWrapMode(QTextOption::WordWrap);
    376             m_pLanguageInfo->setMinimumHeight(QFontMetrics(m_pLanguageInfo->font(), m_pLanguageInfo).height() * 5);
    377         }
    378     }
     352    /* Prepare everything: */
     353    prepareWidgets();
     354    prepareConnection();
    379355
    380356    /* Apply language settings: */
     
    384360void UIGlobalSettingsLanguage::prepareWidgets()
    385361{
    386     if (objectName().isEmpty())
    387         setObjectName(QStringLiteral("UIGlobalSettingsLanguage"));
    388     QGridLayout *pMainLayout = new QGridLayout(this);
    389     pMainLayout->setContentsMargins(0, 0, 0, 0);
    390     pMainLayout->setObjectName(QStringLiteral("pMainLayout"));
    391     m_pLanguageLabel = new QILabelSeparator();
    392     m_pLanguageLabel->setObjectName(QStringLiteral("m_pLanguageLabel"));
    393     pMainLayout->addWidget(m_pLanguageLabel, 0, 0, 1, 1);
    394 
    395     m_pLanguageTree = new QITreeWidget();
    396     m_pLanguageTree->setObjectName(QStringLiteral("m_pLanguageTree"));
    397     m_pLanguageTree->setRootIsDecorated(false);
    398     pMainLayout->addWidget(m_pLanguageTree, 1, 0, 1, 1);
    399 
    400     m_pLanguageInfo = new QIRichTextLabel();
    401     m_pLanguageInfo->setObjectName(QStringLiteral("m_pLanguageInfo"));
    402 
    403     pMainLayout->addWidget(m_pLanguageInfo, 2, 0, 1, 1);
    404     m_pLanguageLabel->setBuddy(m_pLanguageTree);
     362    /* Prepare main layout: */
     363    QGridLayout *pLayoutMain = new QGridLayout(this);
     364    if (pLayoutMain)
     365    {
     366        pLayoutMain->setContentsMargins(0, 0, 0, 0);
     367
     368        /* Prepare separator: */
     369        m_pLabelSeparator = new QILabelSeparator(this);
     370        if (m_pLabelSeparator)
     371            pLayoutMain->addWidget(m_pLabelSeparator, 0, 0);
     372        /* Prepare tree-widget: */
     373        m_pTreeWidget = new QITreeWidget(this);
     374        if (m_pTreeWidget)
     375        {
     376            if (m_pLabelSeparator)
     377                m_pLabelSeparator->setBuddy(m_pTreeWidget);
     378            m_pTreeWidget->header()->hide();
     379            m_pTreeWidget->setColumnCount(4);
     380            m_pTreeWidget->hideColumn(1);
     381            m_pTreeWidget->hideColumn(2);
     382            m_pTreeWidget->hideColumn(3);
     383            m_pTreeWidget->setRootIsDecorated(false);
     384
     385            pLayoutMain->addWidget(m_pTreeWidget, 1, 0);
     386        }
     387
     388        /* Prepare info label: */
     389        m_pLabelInfo = new QIRichTextLabel(this);
     390        if (m_pLabelInfo)
     391        {
     392            m_pLabelInfo->setWordWrapMode(QTextOption::WordWrap);
     393            m_pLabelInfo->setMinimumHeight(QFontMetrics(m_pLabelInfo->font(), m_pLabelInfo).height() * 5);
     394
     395            pLayoutMain->addWidget(m_pLabelInfo, 2, 0);
     396        }
     397    }
     398}
     399
     400void UIGlobalSettingsLanguage::prepareConnection()
     401{
     402    connect(m_pTreeWidget, &QITreeWidget::painted,
     403            this, &UIGlobalSettingsLanguage::sltHandleItemPainting);
     404    connect(m_pTreeWidget, &QITreeWidget::currentItemChanged,
     405            this, &UIGlobalSettingsLanguage::sltHandleCurrentItemChange);
    405406}
    406407
     
    415416{
    416417    /* Clear languages tree: */
    417     m_pLanguageTree->clear();
     418    m_pTreeWidget->clear();
    418419
    419420    /* Load languages tree: */
     
    429430    QTranslator translator;
    430431    /* Add the default language: */
    431     new UILanguageItem(m_pLanguageTree);
     432    new UILanguageItem(m_pTreeWidget);
    432433    /* Add the built-in language: */
    433     new UILanguageItem(m_pLanguageTree, translator, UICommon::vboxBuiltInLanguageName(), true /* built-in */);
     434    new UILanguageItem(m_pTreeWidget, translator, UICommon::vboxBuiltInLanguageName(), true /* built-in */);
    434435    /* Add all existing languages */
    435436    for (QStringList::Iterator it = files.begin(); it != files.end(); ++it)
     
    450451            continue;
    451452
    452         new UILanguageItem(m_pLanguageTree, translator, regExp.cap(1));
     453        new UILanguageItem(m_pTreeWidget, translator, regExp.cap(1));
    453454    }
    454455
    455456    /* Adjust selector list: */
    456     m_pLanguageTree->resizeColumnToContents(0);
     457    m_pTreeWidget->resizeColumnToContents(0);
    457458
    458459    /* Search for necessary language: */
    459     QList<QTreeWidgetItem*> itemsList = m_pLanguageTree->findItems(strLanguageId, Qt::MatchExactly, 1);
     460    QList<QTreeWidgetItem*> itemsList = m_pTreeWidget->findItems(strLanguageId, Qt::MatchExactly, 1);
    460461    QTreeWidgetItem *pItem = itemsList.isEmpty() ? 0 : itemsList[0];
    461462    if (!pItem)
    462463    {
    463464        /* Add an pItem for an invalid language to represent it in the list: */
    464         pItem = new UILanguageItem(m_pLanguageTree, strLanguageId);
    465         m_pLanguageTree->resizeColumnToContents(0);
     465        pItem = new UILanguageItem(m_pTreeWidget, strLanguageId);
     466        m_pTreeWidget->resizeColumnToContents(0);
    466467    }
    467468    Assert(pItem);
    468469    if (pItem)
    469         m_pLanguageTree->setCurrentItem(pItem);
    470 
    471     m_pLanguageTree->sortItems(0, Qt::AscendingOrder);
    472     m_pLanguageTree->scrollToItem(pItem);
     470        m_pTreeWidget->setCurrentItem(pItem);
     471
     472    m_pTreeWidget->sortItems(0, Qt::AscendingOrder);
     473    m_pTreeWidget->scrollToItem(pItem);
    473474}
    474475
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/global/UIGlobalSettingsLanguage.h

    r85822 r85990  
    8383    /** Prepares widgets. */
    8484    void prepareWidgets();
     85    /** Prepares connections. */
     86    void prepareConnection();
    8587    /** Cleanups all. */
    8688    void cleanup();
     
    9395
    9496    /** Holds whether the page is polished. */
    95     bool m_fPolished;
     97    bool  m_fPolished;
    9698
    9799    /** Holds the page data cache instance. */
     
    100102    /** @name Widgets
    101103     * @{ */
    102        QITreeWidget *m_pLanguageTree;
    103        QILabelSeparator *m_pLanguageLabel;
    104        QIRichTextLabel *m_pLanguageInfo;
     104        /** Holds the tree-widget instance. */
     105        QITreeWidget     *m_pTreeWidget;
     106        /** Holds the separator label instance. */
     107        QILabelSeparator *m_pLabelSeparator;
     108        /** Holds the info label instance. */
     109        QIRichTextLabel  *m_pLabelInfo;
    105110    /** @} */
    106111};
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