VirtualBox

Changeset 104585 in vbox


Ignore:
Timestamp:
May 13, 2024 11:37:59 AM (7 months ago)
Author:
vboxsync
Message:

FE/Qt: bugref:10450: Get rid of pre-5.11 code related to QFontMetrics.

Location:
trunk/src/VBox/Frontends/VirtualBox/src
Files:
32 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/activity/overview/UIVMActivityOverviewWidget.cpp

    r104393 r104585  
    21062106        int iColumnTitleWidth = m_columnTitles.value(i, QString()).length();
    21072107        int iMax = iColumnStringWidth > iColumnTitleWidth ? iColumnStringWidth : iColumnTitleWidth;
    2108 #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
    2109         columnWidthsInPixels[i] = iMax * fontMetrics.horizontalAdvance('x') +
    2110 #else
    2111         columnWidthsInPixels[i] = iMax * fontMetrics.width('x') +
    2112 #endif
    2113             QApplication::style()->pixelMetric(QStyle::PM_LayoutLeftMargin) +
    2114             QApplication::style()->pixelMetric(QStyle::PM_LayoutRightMargin) +
    2115             m_iSortIndicatorWidth;
     2108        columnWidthsInPixels[i] = iMax * fontMetrics.horizontalAdvance('x')
     2109                                + QApplication::style()->pixelMetric(QStyle::PM_LayoutLeftMargin)
     2110                                + QApplication::style()->pixelMetric(QStyle::PM_LayoutRightMargin)
     2111                                + m_iSortIndicatorWidth;
    21162112    }
    21172113    m_pTableView->setMinimumColumnWidths(columnWidthsInPixels);
  • trunk/src/VBox/Frontends/VirtualBox/src/activity/vmactivity/UIVMActivityMonitor.cpp

    r104498 r104585  
    660660        else
    661661            strAxisText = QString::number(iTotalSeconds - iTimeIndex);
    662 #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
    663         int iTextWidth = fontMetrics.horizontalAdvance(strAxisText);
    664 #else
    665         int iTextWidth = fontMetrics.width(strAxisText);
    666 #endif
    667         int iTextX = m_lineChartRect.left() + i * m_lineChartRect.width() / (float) (iXSubAxisCount + 1);
     662        const int iTextWidth = fontMetrics.horizontalAdvance(strAxisText);
     663        const int iTextX = m_lineChartRect.left() + i * m_lineChartRect.width() / (float) (iXSubAxisCount + 1);
    668664        if (i == 0)
    669665        {
     
    816812        font.setPixelSize(iFontSize);
    817813        --iFontSize;
    818 #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
    819814    } while (QFontMetrics(font).horizontalAdvance(m_strGAWarning) >= 0.8 * m_lineChartRect.width());
    820 #else
    821     } while (QFontMetrics(font).width(m_strGAWarning) >= 0.8 * m_lineChartRect.width());
    822 #endif
    823815    font.setBold(true);
    824816    painter.setFont(font);
     
    12331225        if (pLabel)
    12341226        {
    1235             QFontMetrics labelFontMetric(pLabel->font());
    1236 #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
    1237             int iWidth = m_iMaximumLabelLength * labelFontMetric.horizontalAdvance('X');
    1238 #else
    1239             int iWidth = m_iMaximumLabelLength * labelFontMetric.width('X');
    1240 #endif
     1227            const QFontMetrics labelFontMetric(pLabel->font());
     1228            const int iWidth = m_iMaximumLabelLength * labelFontMetric.horizontalAdvance('X');
    12411229            foreach (QLabel *pInfoLabel, m_infoLabels)
    12421230                pInfoLabel->setFixedWidth(iWidth);
  • trunk/src/VBox/Frontends/VirtualBox/src/extensions/QILabel.cpp

    r103362 r104585  
    335335            const QString strFlat = removeHtmlTags(QString(strWork).remove(strCompact));
    336336            /* What size will the text have without the compact text: */
    337 #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
    338337            const int iFlatWidth = fm.horizontalAdvance(strFlat);
    339 #else
    340             const int iFlatWidth = fm.width(strFlat);
    341 #endif
    342338            /* Create the shortened text: */
    343339            const QString strNew = fm.elidedText(strElide, toTextElideMode(strElideMode), width() - (2 * HOR_PADDING) - iFlatWidth);
  • trunk/src/VBox/Frontends/VirtualBox/src/extensions/QILineEdit.cpp

    r104575 r104585  
    188188    // The margins are based on qlineedit.cpp of Qt.
    189189    // Maybe they where changed at some time in the future.
    190 #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
    191190    QSize sc(fontMetrics().horizontalAdvance(strText) + 2 * 2,
    192191             fontMetrics().xHeight()                  + 2 * 1);
    193 #else
    194     QSize sc(fontMetrics().width(strText) + 2 * 2,
    195              fontMetrics().xHeight()     + 2 * 1);
    196 #endif
    197192    const QSize sa = style()->sizeFromContents(QStyle::CT_LineEdit, &sof, sc, this);
    198193
  • trunk/src/VBox/Frontends/VirtualBox/src/extradata/UIExtraDataManager.cpp

    r104450 r104585  
    335335
    336336    /* Calculate width: */
    337     const int iWidth = m_iMargin +
    338                        pixmapSize.width() +
    339                        2 * m_iSpacing +
    340 #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
    341                        qMax(fm.horizontalAdvance(index.data(Field_Name).toString()),
    342                             fm.horizontalAdvance(index.data(Field_ID).toString())) +
    343 #else
    344                        qMax(fm.width(index.data(Field_Name).toString()),
    345                             fm.width(index.data(Field_ID).toString())) +
    346 #endif
    347                        m_iMargin;
     337    const int iWidth = m_iMargin
     338                     + pixmapSize.width()
     339                     + 2 * m_iSpacing
     340                     + qMax(fm.horizontalAdvance(index.data(Field_Name).toString()),
     341                            fm.horizontalAdvance(index.data(Field_ID).toString()))
     342                     + m_iMargin;
    348343    /* Calculate height: */
    349     const int iHeight = m_iMargin +
    350                         qMax(pixmapSize.height(),
    351                              fm.height() + m_iSpacing + fm.height()) +
    352                         m_iMargin;
     344    const int iHeight = m_iMargin
     345                      + qMax(pixmapSize.height(),
     346                             fm.height() + m_iSpacing + fm.height())
     347                      + m_iMargin;
    353348
    354349    /* Return result: */
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UICommon.cpp

    r104358 r104585  
    25082508    const int iSpinBoxEditFieldWidth = rect.width();
    25092509    const int iSpinBoxDelta = qMax(0, iSpinBoxWidth - iSpinBoxEditFieldWidth);
    2510     QFontMetrics metrics(pSpinBox->font(), pSpinBox);
     2510    const QFontMetrics metrics(pSpinBox->font(), pSpinBox);
    25112511    const QString strDummy(cCount, '0');
    2512 #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
    25132512    const int iTextWidth = metrics.horizontalAdvance(strDummy);
    2514 #else
    2515     const int iTextWidth = metrics.width(strDummy);
    2516 #endif
    25172513
    25182514    /* Tune spin-box minimum-width: */
  • trunk/src/VBox/Frontends/VirtualBox/src/helpbrowser/UIHelpViewer.cpp

    r104576 r104585  
    345345    AssertReturnVoid(pLayout && m_pSearchLineEdit);
    346346    setFocusProxy(m_pSearchLineEdit);
    347     QFontMetrics fontMetric(m_pSearchLineEdit->font());
    348 #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
     347    const QFontMetrics fontMetric(m_pSearchLineEdit->font());
    349348    setMinimumSize(40 * fontMetric.horizontalAdvance("x"),
    350349                   fontMetric.height() +
    351350                   qApp->style()->pixelMetric(QStyle::PM_LayoutBottomMargin) +
    352351                   qApp->style()->pixelMetric(QStyle::PM_LayoutTopMargin));
    353 
    354 #else
    355     setMinimumSize(40 * fontMetric.width("x"),
    356                    fontMetric.height() +
    357                    qApp->style()->pixelMetric(QStyle::PM_LayoutBottomMargin) +
    358                    qApp->style()->pixelMetric(QStyle::PM_LayoutTopMargin));
    359 #endif
    360352    connect(m_pSearchLineEdit, &UISearchLineEdit::textChanged,
    361353            this, &UIFindInPageWidget::sigSearchTextChanged);
  • trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogPage.cpp

    r103940 r104585  
    173173
    174174    /* Compute a width for 132 characters plus scrollbar and frame width: */
    175 #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
    176     int iDefaultWidth = m_pTextEdit->fontMetrics().horizontalAdvance(QChar('x')) * 132 +
    177 #else
    178     int iDefaultWidth = m_pTextEdit->fontMetrics().width(QChar('x')) * 132 +
    179 #endif
    180                         m_pTextEdit->verticalScrollBar()->width() +
    181                         m_pTextEdit->frameWidth() * 2;
     175    const int iDefaultWidth = m_pTextEdit->fontMetrics().horizontalAdvance(QChar('x')) * 132
     176                            + m_pTextEdit->verticalScrollBar()->width()
     177                            + m_pTextEdit->frameWidth() * 2;
    182178
    183179    return iDefaultWidth;
  • trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerFilterWidget.cpp

    r103977 r104585  
    121121    setContextMenuPolicy(Qt::NoContextMenu);
    122122    createButtons();
    123     /** Try to guess the width of the space between filter terms so that remove button
    124         we display when a term is selected does not hide the next/previous word: */
    125 #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
    126     int spaceWidth = fontMetrics().horizontalAdvance(' ');
    127 #else
    128     int spaceWidth = fontMetrics().width(' ');
    129 #endif
    130     if (spaceWidth != 0)
    131         m_iTrailingSpaceCount = (m_iRemoveTermButtonSize / spaceWidth) + 1;
     123    /* Try to guess the width of the space between filter terms so that remove button
     124     * we display when a term is selected does not hide the next/previous word: */
     125    const int iSpaceWidth = fontMetrics().horizontalAdvance(' ');
     126    if (iSpaceWidth != 0)
     127        m_iTrailingSpaceCount = (m_iRemoveTermButtonSize / iSpaceWidth) + 1;
    132128}
    133129
     
    164160    if (!m_pClearAllButton || !m_pRemoveTermButton)
    165161        createButtons();
    166     int clearButtonSize = height();
    167 
    168     int deltaHeight = 0.5 * (height() - m_pClearAllButton->height());
     162    const int iClearButtonSize = height();
     163
     164    const int iDeltaHeight = 0.5 * (height() - m_pClearAllButton->height());
    169165#ifdef VBOX_WS_MAC
    170     m_pClearAllButton->setGeometry(width() - clearButtonSize - 2, deltaHeight, clearButtonSize, clearButtonSize);
     166    m_pClearAllButton->setGeometry(width() - iClearButtonSize - 2, iDeltaHeight, iClearButtonSize, iClearButtonSize);
    171167#else
    172     m_pClearAllButton->setGeometry(width() - clearButtonSize - 1, deltaHeight, clearButtonSize, clearButtonSize);
     168    m_pClearAllButton->setGeometry(width() - iClearButtonSize - 1, iDeltaHeight, iClearButtonSize, iClearButtonSize);
    173169#endif
    174170
     
    177173    if (hasSelectedText())
    178174    {
    179         //int deltaHeight = 0.5 * (height() - m_pClearAllButton->height());
    180175        m_pRemoveTermButton->show();
    181         int buttonSize = m_iRemoveTermButtonSize;
    182 #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
    183         int charWidth = fontMetrics().horizontalAdvance('x');
     176        const int iButtonSize = m_iRemoveTermButtonSize;
     177        const int iCharWidth = fontMetrics().horizontalAdvance('x');
     178#ifdef VBOX_WS_MAC
     179        int iButtonLeft = cursorRect().left() + 1;
    184180#else
    185         int charWidth = fontMetrics().width('x');
     181        int iButtonLeft = cursorRect().right() - 0.9 * iCharWidth;
    186182#endif
    187 #ifdef VBOX_WS_MAC
    188         int buttonLeft = cursorRect().left() + 1;
    189 #else
    190         int buttonLeft = cursorRect().right() - 0.9 * charWidth;
    191 #endif
    192         /* If buttonLeft is in far right of the line edit, move the
     183        /* If iButtonLeft is in far right of the line edit, move the
    193184           button to left side of the selected word: */
    194         if (buttonLeft + buttonSize  >=  width() - clearButtonSize)
    195         {
    196             int selectionWidth = charWidth * selectedText().length();
    197             buttonLeft -= (selectionWidth + buttonSize);
    198         }
    199         m_pRemoveTermButton->setGeometry(buttonLeft, deltaHeight, buttonSize, buttonSize);
     185        if (iButtonLeft + iButtonSize  >=  width() - iClearButtonSize)
     186        {
     187            const int iSelectionWidth = iCharWidth * selectedText().length();
     188            iButtonLeft -= (iSelectionWidth + iButtonSize);
     189        }
     190        m_pRemoveTermButton->setGeometry(iButtonLeft, iDeltaHeight, iButtonSize, iButtonSize);
    200191    }
    201192    else
  • trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerTextEdit.cpp

    r103988 r104585  
    356356        return 0;
    357357
    358     int digits = 1;
    359     int max = qMax(1, blockCount());
    360     while (max >= 10) {
    361         max /= 10;
    362         ++digits;
    363     }
    364 
    365 #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
    366     int space = 3 + fontMetrics().horizontalAdvance(QLatin1Char('9')) * digits;
    367 #else
    368     int space = 3 + fontMetrics().width(QLatin1Char('9')) * digits;
    369 #endif
    370 
    371     return space;
     358    int iDigits = 1;
     359    int iMax = qMax(1, blockCount());
     360    while (iMax >= 10) {
     361        iMax /= 10;
     362        ++iDigits;
     363    }
     364
     365    return 3 + fontMetrics().horizontalAdvance(QLatin1Char('9')) * iDigits;
    372366}
    373367
  • trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerWidget.cpp

    r104393 r104585  
    242242        return 0;
    243243    /* Compute a width for 132 characters plus scrollbar and frame width: */
    244 #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
    245     int iDefaultWidth = pBrowser->fontMetrics().horizontalAdvance(QChar('x')) * 132 +
    246 #else
    247     int iDefaultWidth = pBrowser->fontMetrics().width(QChar('x')) * 132 +
    248 #endif
    249                         pBrowser->verticalScrollBar()->width() +
    250                         pBrowser->frameWidth() * 2;
     244    const int iDefaultWidth = pBrowser->fontMetrics().horizontalAdvance(QChar('x')) * 132
     245                            + pBrowser->verticalScrollBar()->width()
     246                            + pBrowser->frameWidth() * 2;
    251247
    252248    return iDefaultWidth;
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserItem.cpp

    r104251 r104585  
    585585
    586586    /* Return text size, based on font-metrics: */
    587     QFontMetrics fm(font, pPaintDevice);
    588 #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
     587    const QFontMetrics fm(font, pPaintDevice);
    589588    return QSize(fm.horizontalAdvance(strText), fm.height());
    590 #else
    591     return QSize(fm.width(strText), fm.height());
    592 #endif
    593589}
    594590
     
    597593{
    598594    /* Return text width: */
    599     QFontMetrics fm(font, pPaintDevice);
     595    const QFontMetrics fm(font, pPaintDevice);
    600596    QString strString;
    601597    strString.fill('_', iCount);
    602 #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
    603598    return fm.horizontalAdvance(strString);
    604 #else
    605     return fm.width(strString);
    606 #endif
    607599}
    608600
     
    615607
    616608    /* Check if passed text fits maximum width: */
    617     QFontMetrics fm(font, pPaintDevice);
    618 #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
     609    const QFontMetrics fm(font, pPaintDevice);
    619610    if (fm.horizontalAdvance(strText) <= iWidth)
    620 #else
    621     if (fm.width(strText) <= iWidth)
    622 #endif
    623611        return strText;
    624612
    625613    /* Truncate otherwise: */
    626     QString strEllipsis = QString("...");
    627 #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
    628     int iEllipsisWidth = fm.horizontalAdvance(strEllipsis + " ");
     614    const QString strEllipsis = QString("...");
     615    const int iEllipsisWidth = fm.horizontalAdvance(strEllipsis + " ");
    629616    while (!strText.isEmpty() && fm.horizontalAdvance(strText) + iEllipsisWidth > iWidth)
    630617        strText.truncate(strText.size() - 1);
    631 #else
    632     int iEllipsisWidth = fm.width(strEllipsis + " ");
    633     while (!strText.isEmpty() && fm.width(strText) + iEllipsisWidth > iWidth)
    634         strText.truncate(strText.size() - 1);
    635 #endif
    636618    return strText + strEllipsis;
    637619}
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserItemGlobal.cpp

    r104313 r104585  
    516516    QPaintDevice *pPaintDevice = model()->paintDevice();
    517517    const QFontMetrics fm(m_nameFont, pPaintDevice);
    518 #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
    519518    const int iMinimumNameWidth = fm.horizontalAdvance(compressText(m_nameFont, pPaintDevice, name(),
    520519                                                                    textWidth(m_nameFont, pPaintDevice, 15)));
    521 #else
    522     const int iMinimumNameWidth = fm.width(compressText(m_nameFont, pPaintDevice, name(), textWidth(m_nameFont, pPaintDevice, 15)));
    523 #endif
    524520
    525521    /* Is there something changed? */
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserItemGroup.cpp

    r104313 r104585  
    15621562
    15631563    /* Prepare variables: */
    1564     int iHeaderSpacing = data(GroupItemData_HeaderSpacing).toInt();
     1564    const int iHeaderSpacing = data(GroupItemData_HeaderSpacing).toInt();
    15651565
    15661566    /* Calculate minimum visible name size: */
    15671567    QPaintDevice *pPaintDevice = model()->paintDevice();
    1568     QFontMetrics fm(m_nameFont, pPaintDevice);
    1569     int iMaximumNameWidth = textWidth(m_nameFont, pPaintDevice, 20);
    1570     QString strCompressedName = compressText(m_nameFont, pPaintDevice, name(), iMaximumNameWidth);
    1571 #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
    1572     int iMinimumNameWidth = fm.horizontalAdvance(strCompressedName);
    1573 #else
    1574     int iMinimumNameWidth = fm.width(strCompressedName);
    1575 #endif
    1576     int iMinimumNameHeight = fm.height();
     1568    const QFontMetrics fm(m_nameFont, pPaintDevice);
     1569    const int iMaximumNameWidth = textWidth(m_nameFont, pPaintDevice, 20);
     1570    const QString strCompressedName = compressText(m_nameFont, pPaintDevice, name(), iMaximumNameWidth);
     1571    const int iMinimumNameWidth = fm.horizontalAdvance(strCompressedName);
     1572    const int iMinimumNameHeight = fm.height();
    15771573
    15781574    /* Calculate minimum width: */
     
    16111607
    16121608    /* Calculate new minimum header size: */
    1613     QSize minimumHeaderSize = QSize(iHeaderWidth, iHeaderHeight);
     1609    const QSize minimumHeaderSize = QSize(iHeaderWidth, iHeaderHeight);
    16141610
    16151611    /* Is there something changed? */
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserItemMachine.cpp

    r104313 r104585  
    776776    /* Calculate new minimum name width: */
    777777    QPaintDevice *pPaintDevice = model()->paintDevice();
    778     QFontMetrics fm(m_nameFont, pPaintDevice);
    779 #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
    780     int iMinimumNameWidth = fm.horizontalAdvance(compressText(m_nameFont, pPaintDevice, name(),
    781                                                               textWidth(m_nameFont, pPaintDevice, 15)));
    782 #else
    783     int iMinimumNameWidth = fm.width(compressText(m_nameFont, pPaintDevice, name(), textWidth(m_nameFont, pPaintDevice, 15)));
    784 #endif
     778    const QFontMetrics fm(m_nameFont, pPaintDevice);
     779    const int iMinimumNameWidth = fm.horizontalAdvance(compressText(m_nameFont, pPaintDevice, name(),
     780                                                                    textWidth(m_nameFont, pPaintDevice, 15)));
    785781
    786782    /* Is there something changed? */
     
    801797        && !cache()->toLocal()->snapshotName().isEmpty())
    802798    {
    803         QFontMetrics fm(m_snapshotNameFont, model()->paintDevice());
    804 #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
    805         int iBracketWidth = fm.horizontalAdvance("()"); /* bracket width */
    806         int iActualTextWidth = fm.horizontalAdvance(cache()->toLocal()->snapshotName()); /* snapshot-name width */
    807         int iMinimumTextWidth = fm.horizontalAdvance("..."); /* ellipsis width */
    808 #else
    809         int iBracketWidth = fm.width("()"); /* bracket width */
    810         int iActualTextWidth = fm.width(cache()->toLocal()->snapshotName()); /* snapshot-name width */
    811         int iMinimumTextWidth = fm.width("..."); /* ellipsis width */
    812 #endif
     799        const QFontMetrics fm(m_snapshotNameFont, model()->paintDevice());
     800        const int iBracketWidth = fm.horizontalAdvance("()"); /* bracket width */
     801        const int iActualTextWidth = fm.horizontalAdvance(cache()->toLocal()->snapshotName()); /* snapshot-name width */
     802        const int iMinimumTextWidth = fm.horizontalAdvance("..."); /* ellipsis width */
    813803        iMinimumSnapshotNameWidth = iBracketWidth + qMin(iActualTextWidth, iMinimumTextWidth);
    814804    }
     
    897887
    898888    /* Calculate new visible snapshot-name: */
    899 #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
    900     int iBracketWidth = QFontMetrics(m_snapshotNameFont, pPaintDevice).horizontalAdvance("()");
    901 #else
    902     int iBracketWidth = QFontMetrics(m_snapshotNameFont, pPaintDevice).width("()");
    903 #endif
     889    const int iBracketWidth = QFontMetrics(m_snapshotNameFont, pPaintDevice).horizontalAdvance("()");
    904890    QString strVisibleSnapshotName = compressText(m_snapshotNameFont, pPaintDevice, cache()->toLocal()->snapshotName(),
    905891                                                  m_iMaximumSnapshotNameWidth - iBracketWidth);
    906892    strVisibleSnapshotName = QString("(%1)").arg(strVisibleSnapshotName);
    907     QSize visibleSnapshotNameSize = textSize(m_snapshotNameFont, pPaintDevice, strVisibleSnapshotName);
     893    const QSize visibleSnapshotNameSize = textSize(m_snapshotNameFont, pPaintDevice, strVisibleSnapshotName);
    908894
    909895    /* Update linked values: */
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/details/UIDetailsElement.cpp

    r104393 r104585  
    360360    /* Cache name: */
    361361    m_strName = strName;
    362     QFontMetrics fm(m_nameFont, model()->paintDevice());
    363 #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
     362    const QFontMetrics fm(m_nameFont, model()->paintDevice());
    364363    m_nameSize = QSize(fm.horizontalAdvance(m_strName), fm.height());
    365 #else
    366     m_nameSize = QSize(fm.width(m_strName), fm.height());
    367 #endif
    368364
    369365    /* Update linked values: */
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/tools/UIToolsItem.cpp

    r101560 r104585  
    645645    const int iWidthOf15Letters = textWidthMonospace(m_nameFont, pPaintDevice, 15);
    646646    const QString strNameCompressedTo15Letters = compressText(m_nameFont, pPaintDevice, m_strName, iWidthOf15Letters);
    647 #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
    648647    const QSize minimumNameSize = QSize(fm.horizontalAdvance(strNameCompressedTo15Letters), fm.height());
    649 #else
    650     const QSize minimumNameSize = QSize(fm.width(strNameCompressedTo15Letters), fm.height());
    651 #endif
    652648
    653649    /* Update linked values: */
     
    700696{
    701697    /* Return text width, based on font-metrics: */
    702     QFontMetrics fm(font, pPaintDevice);
     698    const QFontMetrics fm(font, pPaintDevice);
    703699    QString strString;
    704700    strString.fill('_', iCount);
    705 #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
    706701    return fm.horizontalAdvance(strString);
    707 #else
    708     return fm.width(strString);
    709 #endif
    710702}
    711703
     
    718710
    719711    /* Check if passed text already fits maximum width: */
    720     QFontMetrics fm(font, pPaintDevice);
    721 #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
     712    const QFontMetrics fm(font, pPaintDevice);
    722713    if (fm.horizontalAdvance(strText) <= iWidth)
    723 #else
    724     if (fm.width(strText) <= iWidth)
    725 #endif
    726714        return strText;
    727715
    728716    /* Truncate otherwise: */
    729     QString strEllipsis = QString("...");
    730 #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
    731     int iEllipsisWidth = fm.horizontalAdvance(strEllipsis + " ");
     717    const QString strEllipsis = QString("...");
     718    const int iEllipsisWidth = fm.horizontalAdvance(strEllipsis + " ");
    732719    while (!strText.isEmpty() && fm.horizontalAdvance(strText) + iEllipsisWidth > iWidth)
    733720        strText.truncate(strText.size() - 1);
    734 #else
    735     int iEllipsisWidth = fm.width(strEllipsis + " ");
    736     while (!strText.isEmpty() && fm.width(strText) + iEllipsisWidth > iWidth)
    737         strText.truncate(strText.size() - 1);
    738 #endif
    739721    return strText + strEllipsis;
    740722}
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/UIInformationConfiguration.cpp

    r104530 r104585  
    244244                                               const QFontMetrics &fontMetrics, int &iMaxColumn1Length)
    245245{
    246     int iRow = m_pTableWidget->rowCount();
     246    const int iRow = m_pTableWidget->rowCount();
    247247    m_pTableWidget->insertRow(iRow);
    248248    m_pTableWidget->setRowHeight(iRow, fontMetrics.height() + m_iRowTopMargin + m_iRowBottomMargin);
    249 #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
    250249    iMaxColumn1Length = qMax(iMaxColumn1Length, fontMetrics.horizontalAdvance(strText1));
    251 #else
    252     iMaxColumn1Length = qMax(iMaxColumn1Length, fontMetrics.width(strText1));
    253 #endif
    254250    m_pTableWidget->setItem(iRow, 1, new QITableWidgetItem(strText1));
    255251    m_pTableWidget->setItem(iRow, 2, new QITableWidgetItem(strText2));
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/UIInformationRuntime.cpp

    r104530 r104585  
    221221            strLongest = strLabel;
    222222    }
    223     QFontMetrics fontMetrics(font());
    224 #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
     223    const QFontMetrics fontMetrics(font());
    225224    setColumnWidth(0, 1.5 * fontMetrics.horizontalAdvance(*strLongest));
    226 #else
    227     setColumnWidth(0, 1.5 * fontMetrics.width(*strLongest));
    228 #endif
    229225
    230226    /* Make the API calls and populate the table: */
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/editors/UISerialSettingsEditor.cpp

    r104313 r104585  
    364364                    if (m_pLabelIRQ)
    365365                        m_pLabelIRQ->setBuddy(m_pLineEditIRQ);
    366 #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
    367366                    m_pLineEditIRQ->setFixedWidth(m_pLineEditIRQ->fontMetrics().horizontalAdvance("8888"));
    368 #else
    369                     m_pLineEditIRQ->setFixedWidth(m_pLineEditIRQ->fontMetrics().width("8888"));
    370 #endif
    371367                    m_pLineEditIRQ->setValidator(new QIULongValidator(0, 255, this));
    372368                    pLayoutPortSettings->addWidget(m_pLineEditIRQ, 0, 3);
     
    382378                    if (m_pLabelIOAddress)
    383379                        m_pLabelIOAddress->setBuddy(m_pLineEditIOAddress);
    384 #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
    385380                    m_pLineEditIOAddress->setFixedWidth(m_pLineEditIOAddress->fontMetrics().horizontalAdvance("8888888"));
    386 #else
    387                     m_pLineEditIOAddress->setFixedWidth(m_pLineEditIOAddress->fontMetrics().width("8888888"));
    388 #endif
    389381                    m_pLineEditIOAddress->setValidator(new QIULongValidator(0, 0xFFFF, this));
    390382                    pLayoutPortSettings->addWidget(m_pLineEditIOAddress, 0, 5);
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/editors/UISharedFoldersEditor.cpp

    r104313 r104585  
    186186        return;
    187187    const QFontMetrics fm = treeWidget()->fontMetrics();
    188 #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
    189188    const int iOldSize = fm.horizontalAdvance(strOneString);
    190 #else
    191     const int iOldSize = fm.width(strOneString);
    192 #endif
    193189    const int iItemIndent = parentItem() ? treeWidget()->indentation() * 2 : treeWidget()->indentation();
    194 #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
    195190    int iIndentSize = fm.horizontalAdvance(" ... ");
    196 #else
    197     int iIndentSize = fm.width(" ... ");
    198 #endif
    199191    if (iColumn == 0)
    200192        iIndentSize += iItemIndent;
     
    208200    do
    209201    {
    210 #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
    211202        iTextWidth = fm.horizontalAdvance(strOneString);
    212 #else
    213         iTextWidth = fm.width(strOneString);
    214 #endif
    215203        if (   iTextWidth
    216204            && iTextWidth + iIndentSize > cWidth)
     
    256244    if (iPosition || m_enmFormat == FormatType_EllipsisFile)
    257245        strOneString.insert(iPosition, "...");
    258 #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
    259246    const int iNewSize = fm.horizontalAdvance(strOneString);
    260 #else
    261     const int iNewSize = fm.width(strOneString);
    262 #endif
    263247    setText(iColumn, iNewSize < iOldSize ? strOneString : m_fields.at(iColumn));
    264248    setToolTip(iColumn, text(iColumn) == getText(iColumn) ? QString() : getText(iColumn));
    265249
    266250    /* Calculate item's size-hint: */
    267 #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
    268251    setSizeHint(iColumn, QSize(fm.horizontalAdvance(QString("  %1  ").arg(getText(iColumn))), fm.height()));
    269 #else
    270     setSizeHint(iColumn, QSize(fm.width(QString("  %1  ").arg(getText(iColumn))), fm.height()));
    271 #endif
    272252}
    273253
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/editors/UIStorageSettingsEditor.cpp

    r104313 r104585  
    27912791    QFont font = pModel->data(index, Qt::FontRole).value<QFont>();
    27922792    QFontMetrics fm(font);
    2793 #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
    27942793    while ((strShortText.size() > 1) && (fm.horizontalAdvance(strShortText) + fm.horizontalAdvance("...") > iTextWidth))
    2795 #else
    2796     while ((strShortText.size() > 1) && (fm.width(strShortText) + fm.width("...") > iTextWidth))
    2797 #endif
    27982794        strShortText.truncate(strShortText.size() - 1);
    27992795    if (strShortText != strText)
  • trunk/src/VBox/Frontends/VirtualBox/src/softkeyboard/UISoftKeyboard.cpp

    r104358 r104585  
    21072107             painterFont.setBold(true);
    21082108             painter.setFont(painterFont);
    2109              QFontMetrics fontMetrics = painter.fontMetrics();
    2110 #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
    2111              int iMargin = 0.25 * fontMetrics.horizontalAdvance('X');
    2112 #else
    2113              int iMargin = 0.25 * fontMetrics.width('X');
    2114 #endif
     2109             const QFontMetrics fontMetrics = painter.fontMetrics();
     2110             const int iMargin = 0.25 * fontMetrics.horizontalAdvance('X');
    21152111
    21162112             int iTopWidth = 0;
     
    21252121#endif
    21262122             foreach (const QString &strPart, strList)
    2127 #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
    21282123                 iTopWidth = qMax(iTopWidth, fontMetrics.horizontalAdvance(strPart));
    2129 #else
    2130                  iTopWidth = qMax(iTopWidth, fontMetrics.width(strPart));
    2131 #endif
    21322124             strList.clear();
    21332125#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
     
    21412133             int iBottomWidth = 0;
    21422134             foreach (const QString &strPart, strList)
    2143 #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
    21442135                 iBottomWidth = qMax(iBottomWidth, fontMetrics.horizontalAdvance(strPart));
    2145 #else
    2146                  iBottomWidth = qMax(iBottomWidth, fontMetrics.width(strPart));
    2147 #endif
    21482136             int iTextWidth =  2 * iMargin + qMax(iTopWidth, iBottomWidth);
    21492137             int iTextHeight = 0;
     
    21702158     }
    21712159
    2172      QFontMetrics fontMetrics = painter.fontMetrics();
    2173 #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
    2174      int iMargin = 0.25 * fontMetrics.horizontalAdvance('X');
    2175 #else
    2176      int iMargin = 0.25 * fontMetrics.width('X');
    2177 #endif
     2160     const QFontMetrics fontMetrics = painter.fontMetrics();
     2161     const int iMargin = 0.25 * fontMetrics.horizontalAdvance('X');
    21782162     QRect textRect;
    21792163     if (key.keyboardRegion() == KeyboardRegion_MultimediaKeys)
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIFilePathSelector.cpp

    r104358 r104585  
    498498        return strFullText;
    499499
    500 #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
    501     int iOldSize = fontMetrics().horizontalAdvance(strFullText);
    502     int iIndentSize = fontMetrics().horizontalAdvance("x...x");
    503 #else
    504     int iOldSize = fontMetrics().width(strFullText);
    505     int iIndentSize = fontMetrics().width("x...x");
    506 #endif
     500    const int iOldSize = fontMetrics().horizontalAdvance(strFullText);
     501    const int iIndentSize = fontMetrics().horizontalAdvance("x...x");
    507502
    508503    /* Compress text: */
     
    512507    int iTextWidth = 0;
    513508    do {
    514 #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
    515509        iTextWidth = fontMetrics().horizontalAdvance(strFullText);
    516 #else
    517         iTextWidth = fontMetrics().width(strFullText);
    518 #endif
    519510        if (iTextWidth + iIndentSize > iWidth)
    520511        {
     
    538529
    539530    strFullText.insert(iPosition, "...");
    540 #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
    541     int newSize = fontMetrics().horizontalAdvance(strFullText);
    542 #else
    543     int newSize = fontMetrics().width(strFullText);
    544 #endif
     531    const int newSize = fontMetrics().horizontalAdvance(strFullText);
    545532
    546533    return newSize < iOldSize ? strFullText : fullPath(false);
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIFileTableNavigationWidget.cpp

    r103711 r104585  
    166166        if (i < folderList.size() - 1)
    167167        {
    168 #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
    169168            iWidth += fontMetrics().horizontalAdvance(" > ");
    170 #else
    171             iWidth += fontMetrics().width(" > ");
    172 #endif
    173169            strWord.append("<b> > </b>");
    174170        }
    175 #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
    176171        iWidth += fontMetrics().horizontalAdvance(strFolder);
    177 #else
    178         iWidth += fontMetrics().width(strFolder);
    179 #endif
    180172
    181173        if (iWidth < width())
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIPortForwardingTable.cpp

    r104358 r104585  
    774774                case UIPortForwardingDataType_GuestIp:
    775775                {
    776                     QFontMetrics fm = qobject_cast<QWidget*>(parent())->fontMetrics();
    777 #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
     776                    const QFontMetrics fm = qobject_cast<QWidget*>(parent())->fontMetrics();
    778777                    return QSize(fm.horizontalAdvance(" 888.888.888.888 "), fm.height());
    779 #else
    780                     return QSize(fm.width(" 888.888.888.888 "), fm.height());
    781 #endif
    782778                }
    783779                default: return QVariant();
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UISearchLineEdit.cpp

    r98103 r104585  
    5757    /* Draw the total match count and the current scrolled item's index on the right hand side of the line edit: */
    5858    QPainter painter(this);
    59     QFont pfont = font();
    60     QString strText = QString("%1/%2").arg(QString::number(m_iScrollToIndex + 1)).arg(QString::number(m_iMatchCount));
    61 #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
    62     QSize textSize(QApplication::fontMetrics().horizontalAdvance(strText),
    63                    QApplication::fontMetrics().height());
    64 #else
    65     QSize textSize(QApplication::fontMetrics().width(strText),
    66                    QApplication::fontMetrics().height());
    67 #endif
     59    const QFont pfont = font();
     60    const QString strText = QString("%1/%2").arg(QString::number(m_iScrollToIndex + 1)).arg(QString::number(m_iMatchCount));
     61    const QSize textSize(QApplication::fontMetrics().horizontalAdvance(strText),
     62                         QApplication::fontMetrics().height());
    6863
    6964    /* Dont draw anything if we dont have enough space: */
    7065    if (textSize.width() > 0.5 * width())
    7166        return;
    72     int iTopMargin = (height() - textSize.height()) / 2;
    73     int iRightMargin = iTopMargin;
     67    const int iTopMargin = (height() - textSize.height()) / 2;
     68    const int iRightMargin = iTopMargin;
    7469
    7570    QColor fontColor(Qt::black);
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/graphics/UIGraphicsTextPane.cpp

    r103795 r104585  
    206206    foreach (const UITextTableLine &line, m_text)
    207207    {
    208         bool fRightColumnPresent = !line.string2().isEmpty();
     208        const bool fRightColumnPresent = !line.string2().isEmpty();
    209209        if (fRightColumnPresent)
    210210            fSingleColumnText = false;
    211         QString strLeftLine = fRightColumnPresent ? line.string1() + ":" : line.string1();
    212         QString strRightLine = line.string2();
    213 #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
     211        const QString strLeftLine = fRightColumnPresent ? line.string1() + ":" : line.string1();
     212        const QString strRightLine = line.string2();
    214213        iMaximumLeftColumnWidth = qMax(iMaximumLeftColumnWidth, fm.horizontalAdvance(strLeftLine));
    215214        iMaximumRightColumnWidth = qMax(iMaximumRightColumnWidth, fm.horizontalAdvance(strRightLine));
    216 #else
    217         iMaximumLeftColumnWidth = qMax(iMaximumLeftColumnWidth, fm.width(strLeftLine));
    218         iMaximumRightColumnWidth = qMax(iMaximumRightColumnWidth, fm.width(strRightLine));
    219 #endif
    220215    }
    221216    iMaximumLeftColumnWidth += 1;
     
    521516                QRect symbolRect = QRect(layoutPosition.x() + linePosition.x() + iSymbolX,
    522517                                         layoutPosition.y() + linePosition.y(),
    523 #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
    524518                                         fm.horizontalAdvance(strLayoutText[iTextPosition]) + 1,
    525 #else
    526                                          fm.width(strLayoutText[iTextPosition]) + 1,
    527 #endif
    528519                                         fm.height());
    529520                formatRegion += symbolRect;
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/addcloudvm/UIWizardAddCloudVMPageSource.cpp

    r104568 r104585  
    357357                 * horizontally and 8 lines vertically: */
    358358                const QFontMetrics fm(m_pSourceInstanceList->font());
    359 #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
    360359                const int iFontWidth = fm.horizontalAdvance('x');
    361 #else
    362                 const int iFontWidth = fm.width('x');
    363 #endif
    364360                const int iTotalWidth = 50 * iFontWidth;
    365361                const int iFontHeight = fm.height();
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/importappliance/UIWizardImportAppPageExpert.cpp

    r104559 r104585  
    227227                                    m_pProfileInstanceLabel->setBuddy(m_pProfileInstanceLabel);
    228228                                    const QFontMetrics fm(m_pProfileInstanceList->font());
    229 #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
    230229                                    const int iFontWidth = fm.horizontalAdvance('x');
    231 #else
    232                                     const int iFontWidth = fm.width('x');
    233 #endif
    234230                                    const int iTotalWidth = 50 * iFontWidth;
    235231                                    const int iFontHeight = fm.height();
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/importappliance/UIWizardImportAppPageSource.cpp

    r104559 r104585  
    588588                        m_pProfileInstanceLabel->setBuddy(m_pProfileInstanceLabel);
    589589                        const QFontMetrics fm(m_pProfileInstanceList->font());
    590 #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
    591590                        const int iFontWidth = fm.horizontalAdvance('x');
    592 #else
    593                         const int iFontWidth = fm.width('x');
    594 #endif
    595591                        const int iTotalWidth = 50 * iFontWidth;
    596592                        const int iFontHeight = fm.height();
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/newcloudvm/UIWizardNewCloudVMPageSource.cpp

    r104566 r104585  
    415415                     * horizontally and 8 lines vertically: */
    416416                    const QFontMetrics fm(m_pSourceImageList->font());
    417 #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
    418417                    const int iFontWidth = fm.horizontalAdvance('x');
    419 #else
    420                     const int iFontWidth = fm.width('x');
    421 #endif
    422418                    const int iTotalWidth = 50 * iFontWidth;
    423419                    const int iFontHeight = fm.height();
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