VirtualBox

Changeset 50846 in vbox


Ignore:
Timestamp:
Mar 21, 2014 4:08:02 PM (11 years ago)
Author:
vboxsync
Message:

FE/Qt: UIGraphicsTextPane: Minimum size-hint caching optimization.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/widgets/graphics
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/graphics/UIGraphicsTextPane.cpp

    r50845 r50846  
    3030    , m_iSpacing(10)
    3131    , m_iMinimumTextColumnWidth(100)
     32    , m_fMinimumSizeHintInvalidated(true)
    3233    , m_iMinimumTextWidth(0)
    3334    , m_iMinimumTextHeight(0)
     
    6364    }
    6465
    65     /* Update minimum text size-hint: */
     66    /* Update minimum size-hint: */
    6667    updateMinimumTextWidthHint();
    6768    updateMinimumTextHeightHint();
     69    updateGeometry();
    6870}
    6971
    7072void UIGraphicsTextPane::updateGeometry()
    7173{
     74    /* Discard cached minimum size-hint: */
     75    m_fMinimumSizeHintInvalidated = true;
     76
    7277    /* Call to base-class to notify layout if any: */
    7378    QIGraphicsWidget::updateGeometry();
     
    121126    /* Remember new value: */
    122127    m_iMinimumTextWidth = iMinimumTextWidth;
    123 
    124     /* Notify listeners: */
    125     updateGeometry();
    126128}
    127129
     
    198200    /* Remember new value: */
    199201    m_iMinimumTextHeight = iMinimumTextHeight;
    200 
    201     /* Notify listeners: */
     202}
     203
     204QSizeF UIGraphicsTextPane::sizeHint(Qt::SizeHint which, const QSizeF &constraint /* = QSizeF() */) const
     205{
     206    /* For minimum size-hint: */
     207    if (which == Qt::MinimumSize)
     208    {
     209        /* If minimum size-hint invalidated: */
     210        if (m_fMinimumSizeHintInvalidated)
     211        {
     212            /* Recache minimum size-hint: */
     213            m_minimumSizeHint = QSizeF(2 * m_iMargin + m_iMinimumTextWidth,
     214                                       2 * m_iMargin + m_iMinimumTextHeight);
     215            m_fMinimumSizeHintInvalidated = false;
     216        }
     217        /* Return cached minimum size-hint: */
     218        return m_minimumSizeHint;
     219    }
     220    /* Call to base-class for other size-hints: */
     221    return QIGraphicsWidget::sizeHint(which, constraint);
     222}
     223
     224void UIGraphicsTextPane::resizeEvent(QGraphicsSceneResizeEvent*)
     225{
     226    /* Update minimum height-hint: */
     227    updateMinimumTextHeightHint();
    202228    updateGeometry();
    203 }
    204 
    205 QSizeF UIGraphicsTextPane::sizeHint(Qt::SizeHint which, const QSizeF &constraint /* = QSizeF() */) const
    206 {
    207     /* Calculate minimum size-hint: */
    208     if (which == Qt::MinimumSize)
    209     {
    210         int iWidth = 2 * m_iMargin + m_iMinimumTextWidth;
    211         int iHeight = 2 * m_iMargin + m_iMinimumTextHeight;
    212         return QSize(iWidth, iHeight);
    213     }
    214     /* Call to base-class: */
    215     return QIGraphicsWidget::sizeHint(which, constraint);
    216 }
    217 
    218 void UIGraphicsTextPane::resizeEvent(QGraphicsSceneResizeEvent*)
    219 {
    220     /* Update minimum text height-hint: */
    221     updateMinimumTextHeightHint();
    222229}
    223230
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/graphics/UIGraphicsTextPane.h

    r50845 r50846  
    8282    const int m_iMinimumTextColumnWidth;
    8383
     84    /** Minimum size-hint invalidation flag. */
     85    mutable bool m_fMinimumSizeHintInvalidated;
     86    /** Minimum size-hint cache. */
     87    mutable QSizeF m_minimumSizeHint;
    8488    /** Minimum text-width. */
    8589    int m_iMinimumTextWidth;
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