VirtualBox

Changeset 43989 in vbox


Ignore:
Timestamp:
Nov 28, 2012 4:20:48 PM (12 years ago)
Author:
vboxsync
Message:

FE/Qt: VM group UI: Details-view: Move some common code into appropriate place, reuse it.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/details
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/details/UIGDetailsElement.cpp

    r43987 r43989  
    9292}
    9393
    94 int UIGDetailsElement::minimumWidthHint() const
    95 {
    96     /* Prepare variables: */
    97     int iMargin = data(ElementData_Margin).toInt();
    98     int iProposedWidth = 0;
    99 
    100     /* Maximum width: */
    101     iProposedWidth = qMax(m_iMinimumHeaderWidth, m_iMinimumTextWidth);
    102 
    103     /* And 4 margins: 2 left and 2 right: */
    104     iProposedWidth += 4 * iMargin;
    105 
    106     /* Return result: */
    107     return iProposedWidth;
    108 }
    109 
    110 int UIGDetailsElement::minimumHeightHint() const
    111 {
    112     return minimumHeightHint(m_fClosed);
    113 }
    114 
    11594void UIGDetailsElement::updateHoverAccessibility()
    11695{
     
    352331}
    353332
    354 int UIGDetailsElement::minimumHeightHint(bool fClosed) const
     333int UIGDetailsElement::minimumWidthHint() const
    355334{
    356335    /* Prepare variables: */
    357336    int iMargin = data(ElementData_Margin).toInt();
    358     int iProposedHeight = 0;
     337    int iMinimumWidthHint = 0;
     338
     339    /* Maximum width: */
     340    iMinimumWidthHint = qMax(m_iMinimumHeaderWidth, m_iMinimumTextWidth);
     341
     342    /* And 4 margins: 2 left and 2 right: */
     343    iMinimumWidthHint += 4 * iMargin;
     344
     345    /* Return result: */
     346    return iMinimumWidthHint;
     347}
     348
     349int UIGDetailsElement::minimumHeightHint(bool fClosed) const
     350{
     351    /* Prepare variables: */
     352    int iMargin = data(ElementData_Margin).toInt();
     353    int iMinimumHeightHint = 0;
    359354
    360355    /* Two margins: */
    361     iProposedHeight += 2 * iMargin;
     356    iMinimumHeightHint += 2 * iMargin;
    362357
    363358    /* Header height: */
    364     iProposedHeight += m_iMinimumHeaderHeight;
     359    iMinimumHeightHint += m_iMinimumHeaderHeight;
    365360
    366361    /* Element is opened? */
     
    369364        /* Add text height: */
    370365        if (!m_text.isEmpty())
    371             iProposedHeight += 2 * iMargin + m_iMinimumTextHeight;
     366            iMinimumHeightHint += 2 * iMargin + m_iMinimumTextHeight;
    372367    }
    373368
    374369    /* Additional height during animation: */
    375370    if (m_fAnimationRunning)
    376         iProposedHeight += m_iAdditionalHeight;
     371        iMinimumHeightHint += m_iAdditionalHeight;
    377372
    378373    /* Return value: */
    379     return iProposedHeight;
    380 }
    381 
    382 QSizeF UIGDetailsElement::sizeHint(Qt::SizeHint which, const QSizeF &constraint /* = QSizeF() */) const
    383 {
    384     /* If Qt::MinimumSize requested: */
    385     if (which == Qt::MinimumSize || which == Qt::PreferredSize)
    386     {
    387         /* Return wrappers: */
    388         return QSizeF(minimumWidthHint(), minimumHeightHint());
    389     }
    390 
    391     /* Call to base-class: */
    392     return UIGDetailsItem::sizeHint(which, constraint);
     374    return iMinimumHeightHint;
     375}
     376
     377int UIGDetailsElement::minimumHeightHint() const
     378{
     379    return minimumHeightHint(m_fClosed);
    393380}
    394381
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/details/UIGDetailsElement.h

    r43987 r43989  
    8383    void open(bool fAnimated = true);
    8484
    85     /* API: Layout stuff: */
    86     virtual int minimumWidthHint() const;
    87     virtual int minimumHeightHint() const;
    88 
    8985    /* API: Update stuff: */
    9086    void updateHoverAccessibility();
     
    137133    int minimumHeaderWidth() const { return m_iMinimumHeaderWidth; }
    138134    int minimumHeaderHeight() const { return m_iMinimumHeaderHeight; }
     135    int minimumWidthHint() const;
    139136    virtual int minimumHeightHint(bool fClosed) const;
    140     QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const;
     137    int minimumHeightHint() const;
    141138    void updateLayout();
    142139
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/details/UIGDetailsGroup.cpp

    r43988 r43989  
    231231    /* Take into account all the sets: */
    232232    foreach (UIGDetailsItem *pItem, items())
    233         if (UIGDetailsSet *pSet = pItem->toSet())
    234             iMinimumWidthHint = qMax(iMinimumWidthHint, pSet->minimumWidthHint());
     233        iMinimumWidthHint = qMax(iMinimumWidthHint, pItem->minimumWidthHint());
    235234
    236235    /* And two margins finally: */
    237236    iMinimumWidthHint += 2 * iMargin;
    238237
    239     /* Return value: */
     238    /* Return result: */
    240239    return iMinimumWidthHint;
    241240}
     
    250249    /* Take into account all the sets: */
    251250    foreach (UIGDetailsItem *pItem, items())
    252         if (UIGDetailsSet *pSet = pItem->toSet())
    253             iMinimumHeightHint += (pSet->minimumHeightHint() + iSpacing);
     251        iMinimumHeightHint += (pItem->minimumHeightHint() + iSpacing);
    254252
    255253    /* Minus last spacing: */
     
    259257    iMinimumHeightHint += 2 * iMargin;
    260258
    261     /* Return value: */
     259    /* Return result: */
    262260    return iMinimumHeightHint;
    263261}
    264262
    265 QSizeF UIGDetailsGroup::sizeHint(Qt::SizeHint which, const QSizeF &constraint /* = QSizeF() */) const
    266 {
    267     /* If Qt::MinimumSize requested: */
    268     if (which == Qt::MinimumSize || which == Qt::PreferredSize)
    269     {
    270         /* Return wrappers: */
    271         return QSizeF(minimumWidthHint(), minimumHeightHint());
    272     }
    273 
    274     /* Call to base-class: */
    275     return UIGDetailsItem::sizeHint(which, constraint);
    276 }
    277 
    278263void UIGDetailsGroup::updateLayout()
    279264{
     265    /* Update size-hints for all the items: */
     266    foreach (UIGDetailsItem *pItem, items())
     267        pItem->updateSizeHint();
     268    /* Update size-hint for this item: */
     269    updateSizeHint();
     270
    280271    /* Prepare variables: */
    281272    int iMargin = data(GroupData_Margin).toInt();
     
    287278    foreach (UIGDetailsItem *pItem, items())
    288279    {
    289         /* Get particular set: */
    290         UIGDetailsSet *pSet = pItem->toSet();
    291280        /* Move set: */
    292281        pItem->setPos(iMargin, iVerticalIndent);
    293282        /* Resize set: */
    294283        int iWidth = iMaximumWidth;
    295         pItem->resize(iWidth, pSet->minimumHeightHint());
     284        pItem->resize(iWidth, pItem->minimumHeightHint());
    296285        /* Layout set content: */
    297286        pItem->updateLayout();
    298287        /* Advance indent: */
    299         iVerticalIndent += (pSet->minimumHeightHint() + iSpacing);
    300     }
    301 }
    302 
     288        iVerticalIndent += (pItem->minimumHeightHint() + iSpacing);
     289    }
     290}
     291
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/details/UIGDetailsGroup.h

    r43988 r43989  
    8787    int minimumWidthHint() const;
    8888    int minimumHeightHint() const;
    89     QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const;
    9089    void updateLayout();
    9190
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/details/UIGDetailsItem.cpp

    r43982 r43989  
    8787}
    8888
     89QSizeF UIGDetailsItem::sizeHint(Qt::SizeHint which, const QSizeF &constraint /* = QSizeF() */) const
     90{
     91    /* If Qt::MinimumSize or Qt::PreferredSize requested: */
     92    if (which == Qt::MinimumSize || which == Qt::PreferredSize)
     93        /* Return wrappers: */
     94        return QSizeF(minimumWidthHint(), minimumHeightHint());
     95    /* Call to base-class: */
     96    return QIGraphicsWidget::sizeHint(which, constraint);
     97}
     98
    8999/* static */
    90100void UIGDetailsItem::configurePainterShape(QPainter *pPainter,
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/details/UIGDetailsItem.h

    r43885 r43989  
    7272    /* API: Layout stuff: */
    7373    void updateSizeHint();
     74    virtual int minimumWidthHint() const = 0;
     75    virtual int minimumHeightHint() const = 0;
     76    QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const;
    7477    virtual void updateLayout() = 0;
    7578
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/details/UIGDetailsSet.cpp

    r43987 r43989  
    260260    int iMargin = data(SetData_Margin).toInt();
    261261    int iSpacing = data(SetData_Spacing).toInt();
    262     int iProposedWidth = 0;
    263 
    264     /* Layout all the elements: */
     262    int iMinimumWidthHint = 0;
     263
     264    /* Take into account all the elements: */
    265265    foreach (UIGDetailsItem *pItem, items())
    266266    {
    267         /* Get particular element: */
     267        /* Skip hidden: */
     268        if (!pItem->isVisible())
     269            continue;
     270
     271        /* For each particular element: */
    268272        UIGDetailsElement *pElement = pItem->toElement();
    269         if (!pElement->isVisible())
    270             continue;
    271 
    272         /* For each particular element: */
    273273        switch (pElement->elementType())
    274274        {
     
    287287            case DetailsElementType_Description:
    288288            {
    289                 iProposedWidth = qMax(iProposedWidth, pElement->minimumWidthHint());
     289                iMinimumWidthHint = qMax(iMinimumWidthHint, pItem->minimumWidthHint());
    290290                break;
    291291            }
    292292            case DetailsElementType_Preview:
    293293            {
    294                 UIGDetailsElement *pGeneralElement = element(DetailsElementType_General);
    295                 UIGDetailsElement *pSystemElement = element(DetailsElementType_System);
    296                 int iGeneralElementWidth = pGeneralElement ? pGeneralElement->minimumWidthHint() : 0;
    297                 int iSystemElementWidth = pSystemElement ? pSystemElement->minimumWidthHint() : 0;
     294                UIGDetailsItem *pGeneralItem = element(DetailsElementType_General);
     295                UIGDetailsItem *pSystemItem = element(DetailsElementType_System);
     296                int iGeneralElementWidth = pGeneralItem ? pGeneralItem->minimumWidthHint() : 0;
     297                int iSystemElementWidth = pSystemItem ? pSystemItem->minimumWidthHint() : 0;
    298298                int iFirstColumnWidth = qMax(iGeneralElementWidth, iSystemElementWidth);
    299                 iProposedWidth = qMax(iProposedWidth, iFirstColumnWidth + iSpacing + pElement->minimumWidthHint());
     299                iMinimumWidthHint = qMax(iMinimumWidthHint, iFirstColumnWidth + iSpacing + pItem->minimumWidthHint());
    300300                break;
    301301            }
     
    303303    }
    304304
    305     /* Two margins finally: */
    306     iProposedWidth += 2 * iMargin;
     305    /* And two margins finally: */
     306    iMinimumWidthHint += 2 * iMargin;
    307307
    308308    /* Return result: */
    309     return iProposedWidth;
     309    return iMinimumWidthHint;
    310310}
    311311
     
    315315    int iMargin = data(SetData_Margin).toInt();
    316316    int iSpacing = data(SetData_Spacing).toInt();
    317     int iProposedHeight = 0;
    318 
    319     /* Layout all the elements: */
     317    int iMinimumHeightHint = 0;
     318
     319    /* Take into account all the elements: */
    320320    foreach (UIGDetailsItem *pItem, items())
    321321    {
    322         /* Get particular element: */
     322        /* Skip hidden: */
     323        if (!pItem->isVisible())
     324            continue;
     325
     326        /* For each particular element: */
    323327        UIGDetailsElement *pElement = pItem->toElement();
    324         if (!pElement->isVisible())
    325             continue;
    326 
    327         /* For each particular element: */
    328328        switch (pElement->elementType())
    329329        {
     
    342342            case DetailsElementType_Description:
    343343            {
    344                 iProposedHeight += (pElement->minimumHeightHint() + iSpacing);
     344                iMinimumHeightHint += (pItem->minimumHeightHint() + iSpacing);
    345345                break;
    346346            }
    347347            case DetailsElementType_Preview:
    348348            {
    349                 iProposedHeight = qMax(iProposedHeight, pElement->minimumHeightHint() + iSpacing);
     349                iMinimumHeightHint = qMax(iMinimumHeightHint, pItem->minimumHeightHint() + iSpacing);
    350350                break;
    351351            }
     
    354354
    355355    /* Minus last spacing: */
    356     iProposedHeight -= iSpacing;
    357 
    358     /* Two margins finally: */
    359     iProposedHeight += 2 * iMargin;
     356    iMinimumHeightHint -= iSpacing;
     357
     358    /* And two margins finally: */
     359    iMinimumHeightHint += 2 * iMargin;
    360360
    361361    /* Return result: */
    362     return iProposedHeight;
    363 }
    364 
    365 QSizeF UIGDetailsSet::sizeHint(Qt::SizeHint which, const QSizeF &constraint /* = QSizeF() */) const
    366 {
    367     /* If Qt::MinimumSize requested: */
    368     if (which == Qt::MinimumSize || which == Qt::PreferredSize)
    369     {
    370         /* Return wrappers: */
    371         return QSizeF(minimumWidthHint(), minimumHeightHint());
    372     }
    373 
    374     /* Call to base-class: */
    375     return UIGDetailsItem::sizeHint(which, constraint);
     362    return iMinimumHeightHint;
    376363}
    377364
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/details/UIGDetailsSet.h

    r43988 r43989  
    9898    int minimumWidthHint() const;
    9999    int minimumHeightHint() const;
    100     QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const;
    101100    void updateLayout();
    102101
     
    117116    QString m_strSetId;
    118117    QStringList m_settings;
    119 
    120     /* Friends: */
    121     friend class UIGDetailsGroup;
    122118};
    123119
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