VirtualBox

Changeset 105994 in vbox for trunk


Ignore:
Timestamp:
Sep 10, 2024 2:34:51 AM (3 months ago)
Author:
vboxsync
Message:

FE/Qt: bugref:10513: Fixing minimum size-hint for Basic/Expert mode switch; That should solve the bug with text exceeding button geometry while choosing language other than English.

File:
1 edited

Legend:

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

    r105105 r105994  
    8989    QString text1() const { return m_strText1; }
    9090    /** Defines @a strText1. */
    91     void setText1(const QString &strText1) { m_strText1 = strText1; }
     91    void setText1(const QString &strText1);
    9292    /** Returns text 2. */
    9393    QString text2() const { return m_strText2; }
    9494    /** Defines @a strText2. */
    95     void setText2(const QString &strText2) { m_strText2 = strText2; }
     95    void setText2(const QString &strText2);
    9696
    9797protected:
     
    102102    /** Handles paint @a pEvent. */
    103103    virtual void paintEvent(QPaintEvent *pEvent) RT_OVERRIDE;
     104
     105    /** Calculates and returns minimum size-hint. */
     106    virtual QSize minimumSizeHint() const RT_OVERRIDE;
    104107
    105108private:
     
    262265{
    263266    setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
     267}
     268
     269void UIModeCheckBox::setText1(const QString &strText1)
     270{
     271    m_strText1 = strText1;
     272    updateGeometry();
     273}
     274
     275void UIModeCheckBox::setText2(const QString &strText2)
     276{
     277    m_strText2 = strText2;
     278    updateGeometry();
    264279}
    265280
     
    348363    painter.restore();
    349364
    350     /* Prepare text1/text2: */
     365    /* Prepare text stuff: */
    351366    const QFont fnt = font();
    352367    const QFontMetrics fm(fnt);
    353368    const QColor foreground1 = suitableForegroundColor(pal, backColor1);
    354     const QString strName1 = text1();
    355     const QPoint point1 = QPoint(contentRect.left() + 5 /** @todo justify! */,
     369    const QColor foreground2 = suitableForegroundColor(pal, backColor2);
     370    /* Calculate text1 position: */
     371    const int iMaxSpace1 = contentRect.width() / 2 - 2 * fm.height();
     372    const int iTextSize1 = fm.horizontalAdvance(m_strText1);
     373    const int iIndent1 = iMaxSpace1 > iTextSize1 ? (iMaxSpace1 - iTextSize1) / 2 : 0;
     374    const QPoint point1 = QPoint(contentRect.left() + 5 /* margin */ + iIndent1,
    356375                                 contentRect.height() / 2 + fm.ascent() / 2 - 1 /* base line */);
    357     const QColor foreground2 = suitableForegroundColor(pal, backColor2);
    358     const QString strName2 = text2();
    359     const QPoint point2 = QPoint(contentRect.width() / 2 + 1 + 5 /** @todo justify! */,
     376    /* Calculate text2 position: */
     377    const int iMaxSpace2 = contentRect.width() / 2 - 2 * fm.height();
     378    const int iTextSize2 = fm.horizontalAdvance(m_strText2);
     379    const int iIndent2 = iMaxSpace2 > iTextSize2 ? (iMaxSpace2 - iTextSize2) / 2 : 0;
     380    const QPoint point2 = QPoint(contentRect.width() / 2 + iIndent2,
    360381                                 contentRect.height() / 2 + fm.ascent() / 2 - 1 /* base line */);
    361382
     
    364385    painter.setFont(fnt);
    365386    painter.setPen(foreground1);
    366     painter.drawText(point1, strName1);
     387    painter.drawText(point1, text1());
    367388    painter.setPen(foreground2);
    368     painter.drawText(point2, strName2);
     389    painter.drawText(point2, text2());
    369390    painter.restore();
     391}
     392
     393QSize UIModeCheckBox::minimumSizeHint() const
     394{
     395    /* Acquire metrics: */
     396    const QFontMetrics fm(font());
     397
     398    /* Looking for a max text size among those two: */
     399    int iMaxLength = 0;
     400    iMaxLength = qMax(iMaxLength, fm.horizontalAdvance(m_strText1));
     401    iMaxLength = qMax(iMaxLength, fm.horizontalAdvance(m_strText2));
     402
     403    /* Composing result: */
     404    QSize result(  5               /* left margin */
     405                 + iMaxLength + 2  /* padding */
     406                 + 2 * fm.height() /* spacing */
     407                 + iMaxLength + 2  /* padding */
     408                 + 2 * fm.height() /* right marging */,
     409                   2 * fm.height() /* vertical hint */);
     410    //printf("UIModeCheckBox::minimumSizeHint(%dx%d)\n",
     411    //       result.width(), result.height());
     412    return result;
    370413}
    371414
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