VirtualBox

Changeset 43984 in vbox for trunk


Ignore:
Timestamp:
Nov 28, 2012 2:24:00 PM (12 years ago)
Author:
vboxsync
Message:

FE/Qt: VM group UI: Details-view: Caching pixmaps, fonts and header sizes.

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

Legend:

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

    r43982 r43984  
    1919
    2020/* Qt includes: */
    21 #include <QApplication>
    2221#include <QGraphicsView>
    2322#include <QStateMachine>
     
    4140    , m_type(type)
    4241    , m_iCornerRadius(10)
     42    , m_iMinimumHeaderWidth(0)
     43    , m_iMinimumHeaderHeight(0)
    4344    , m_fClosed(!fOpened)
    4445    , m_pButton(0)
     
    9394    /* Prepare variables: */
    9495    int iMargin = data(ElementData_Margin).toInt();
    95     int iHeaderWidth = data(ElementData_HeaderSize).toSize().width();
    9696    int iTextWidth = data(ElementData_TextWidth).toInt();
    97 
    98     /* Calculating proposed width: */
    9997    int iProposedWidth = 0;
    10098
    10199    /* Maximum width: */
    102     iProposedWidth = qMax(iHeaderWidth, iTextWidth);
     100    iProposedWidth = qMax(m_iMinimumHeaderWidth, iTextWidth);
    103101
    104102    /* And 4 margins: 2 left and 2 right: */
     
    161159        case ElementData_Margin: return 5;
    162160        case ElementData_Spacing: return 10;
    163         /* Pixmaps: */
    164         case ElementData_Pixmap: return m_icon;
    165         /* Fonts: */
    166         case ElementData_NameFont:
    167         {
    168             QFont nameFont = qApp->font();
    169             nameFont.setWeight(QFont::Bold);
    170             return nameFont;
    171         }
    172         case ElementData_TextFont:
    173         {
    174             QFont textFont = qApp->font();
    175             return textFont;
    176         }
    177         /* Sizes: */
    178         case ElementData_PixmapSize:
    179             return m_icon.isNull() ? QSize(0, 0) : m_icon.availableSizes().at(0);
    180         case ElementData_NameSize:
    181         {
    182             QFontMetrics fm(data(ElementData_NameFont).value<QFont>(), model()->paintDevice());
    183             return QSize(fm.width(m_strName), fm.height());
    184         }
    185         case ElementData_ButtonSize: return m_pButton->minimumSizeHint();
    186         case ElementData_HeaderSize:
    187         {
    188             /* Prepare variables: */
    189             int iMargin = data(ElementData_Margin).toInt();
    190             int iSpacing = data(ElementData_Spacing).toInt();
    191             QSize pixmapSize = data(ElementData_PixmapSize).toSize();
    192             QSize nameSize = data(ElementData_NameSize).toSize();
    193             QSize buttonSize = data(ElementData_ButtonSize).toSize();
    194             /* Header width: */
    195             int iHeaderWidth = iMargin + pixmapSize.width() + iSpacing +
    196                                nameSize.width() + iSpacing + buttonSize.width();
    197             /* Header height: */
    198             int iHeaderHeight = qMax(pixmapSize.height(), nameSize.height());
    199             iHeaderHeight = qMax(iHeaderHeight, buttonSize.height());
    200             /* Return value: */
    201             return QSize(iHeaderWidth, iHeaderHeight);
    202         }
    203161        case ElementData_TextWidth:
    204162        {
     
    206164            int iSpacing = data(ElementData_Spacing).toInt();
    207165            int iMinimumTextColumnWidth = data(ElementData_MinimumTextColumnWidth).toInt();
    208             QFontMetrics fm(data(ElementData_TextFont).value<QFont>(), model()->paintDevice());
     166            QFontMetrics fm(m_textFont, model()->paintDevice());
    209167
    210168            /* Search for the maximum line widths: */
     
    251209            int iMinimumTextColumnWidth = data(ElementData_MinimumTextColumnWidth).toInt();
    252210            int iMaximumTextWidth = (int)geometry().width() - 3 * iMargin - iSpacing;
    253             QFont textFont = data(ElementData_TextFont).value<QFont>();
    254211            QPaintDevice *pPaintDevice = model()->paintDevice();
    255             QFontMetrics fm(textFont, pPaintDevice);
     212            QFontMetrics fm(m_textFont, pPaintDevice);
    256213
    257214            /* Search for the maximum line widths: */
     
    296253                {
    297254                    bool fRightColumnPresent = !line.second.isEmpty();
    298                     QTextLayout *pTextLayout = prepareTextLayout(textFont, pPaintDevice,
     255                    QTextLayout *pTextLayout = prepareTextLayout(m_textFont, pPaintDevice,
    299256                                                                 fRightColumnPresent ? line.first + ":" : line.first,
    300257                                                                 iLeftColumnWidth, iLeftColumnHeight);
     
    306263                if (!line.second.isEmpty())
    307264                {
    308                     QTextLayout *pTextLayout = prepareTextLayout(textFont, pPaintDevice, line.second,
     265                    QTextLayout *pTextLayout = prepareTextLayout(m_textFont, pPaintDevice, line.second,
    309266                                                                 iRightColumnWidth, iRightColumnHeight);
    310267                    delete pTextLayout;
     
    325282}
    326283
     284void UIGDetailsElement::updateMinimumHeaderWidth()
     285{
     286    /* Prepare variables: */
     287    int iSpacing = data(ElementData_Spacing).toInt();
     288
     289    /* Update minimum-header-width: */
     290    m_iMinimumHeaderWidth = m_pixmapSize.width() +
     291                            iSpacing + m_nameSize.width() +
     292                            iSpacing + m_buttonSize.width();
     293}
     294
     295void UIGDetailsElement::updateMinimumHeaderHeight()
     296{
     297    /* Update minimum-header-height: */
     298    m_iMinimumHeaderHeight = qMax(m_pixmapSize.height(), m_nameSize.height());
     299    m_iMinimumHeaderHeight = qMax(m_iMinimumHeaderHeight, m_buttonSize.height());
     300}
     301
    327302void UIGDetailsElement::setIcon(const QIcon &icon)
    328303{
    329     m_icon = icon;
     304    /* Cache icon: */
     305    m_pixmapSize = icon.isNull() ? QSize(0, 0) : icon.availableSizes().first();
     306    m_pixmap = icon.pixmap(m_pixmapSize);
     307
     308    /* Update linked values: */
     309    updateMinimumHeaderWidth();
     310    updateMinimumHeaderHeight();
    330311}
    331312
    332313void UIGDetailsElement::setName(const QString &strName)
    333314{
     315    /* Cache name: */
    334316    m_strName = strName;
     317    QFontMetrics fm(m_nameFont, model()->paintDevice());
     318    m_nameSize = QSize(fm.width(m_strName), fm.height());
     319
     320    /* Update linked values: */
     321    updateMinimumHeaderWidth();
     322    updateMinimumHeaderHeight();
    335323}
    336324
     
    392380void UIGDetailsElement::prepareElement()
    393381{
     382    /* Initialization: */
     383    m_nameFont = font();
     384    m_nameFont.setWeight(QFont::Bold);
     385    m_textFont = font();
     386
    394387    /* Create highlight machine: */
    395388    m_pHighlightMachine = new QStateMachine(this);
     
    435428    connect(m_pButton, SIGNAL(sigRotationStart()), this, SLOT(sltElementToggleStart()));
    436429    connect(m_pButton, SIGNAL(sigRotationFinish(bool)), this, SLOT(sltElementToggleFinish(bool)));
     430    m_buttonSize = m_pButton->minimumSizeHint().toSize();
    437431}
    438432
     
    445439    QSize size = geometry().size().toSize();
    446440    int iMargin = data(ElementData_Margin).toInt();
    447     QSize buttonSize = data(ElementData_ButtonSize).toSize();
    448     int iButtonWidth = buttonSize.width();
    449     int iButtonHeight = buttonSize.height();
    450     int iFullHeaderHeight = data(ElementData_HeaderSize).toSize().height();
     441    int iButtonWidth = m_buttonSize.width();
     442    int iButtonHeight = m_buttonSize.height();
    451443
    452444    /* Layout button: */
    453445    int iButtonX = size.width() - 2 * iMargin - iButtonWidth;
    454     int iButtonY = iButtonHeight == iFullHeaderHeight ? iMargin :
    455                    iMargin + (iFullHeaderHeight - iButtonHeight) / 2;
     446    int iButtonY = iButtonHeight == m_iMinimumHeaderHeight ? iMargin :
     447                   iMargin + (m_iMinimumHeaderHeight - iButtonHeight) / 2;
    456448    m_pButton->setPos(iButtonX, iButtonY);
    457449}
     
    471463    /* Prepare variables: */
    472464    int iMargin = data(ElementData_Margin).toInt();
    473     int iHeaderHeight = data(ElementData_HeaderSize).toSize().height();
    474465    int iTextHeight = data(ElementData_TextHeight).toInt();
    475 
    476     /* Calculating proposed height: */
    477466    int iProposedHeight = 0;
    478467
     
    481470
    482471    /* Header height: */
    483     iProposedHeight += iHeaderHeight;
     472    iProposedHeight += m_iMinimumHeaderHeight;
    484473
    485474    /* Element is opened? */
     
    495484        iProposedHeight += m_iAdditionalHeight;
    496485
    497     /* Return result: */
     486    /* Return value: */
    498487    return iProposedHeight;
    499488}
     
    538527    int iMargin = data(ElementData_Margin).toInt();
    539528    int iSpacing = data(ElementData_Spacing).toInt();
    540     QSize pixmapSize = data(ElementData_PixmapSize).toSize();
    541     QSize nameSize = data(ElementData_NameSize).toSize();
    542     int iHeaderHeight = data(ElementData_HeaderSize).toSize().height();
    543529
    544530    /* Calculate attributes: */
    545     int iPixmapHeight = pixmapSize.height();
    546     int iNameHeight = nameSize.height();
     531    int iPixmapHeight = m_pixmapSize.height();
     532    int iNameHeight = m_nameSize.height();
    547533    int iMaximumHeight = qMax(iPixmapHeight, iNameHeight);
    548534
     
    560546                pPainter,
    561547                /* Rectangle to paint in: */
    562                 QRect(QPoint(iMachinePixmapX, iMachinePixmapY), pixmapSize),
     548                QRect(QPoint(iMachinePixmapX, iMachinePixmapY), m_pixmapSize),
    563549                /* Pixmap to paint: */
    564                 data(ElementData_Pixmap).value<QIcon>().pixmap(pixmapSize));
     550                m_pixmap);
    565551
    566552    /* Paint name: */
    567553    int iMachineNameX = iMachinePixmapX +
    568                         pixmapSize.width() +
     554                        m_pixmapSize.width() +
    569555                        iSpacing;
    570556    int iMachineNameY = iNameHeight == iMaximumHeight ?
     
    573559              pPainter,
    574560              /* Rectangle to paint in: */
    575               QRect(QPoint(iMachineNameX, iMachineNameY), nameSize),
     561              QRect(QPoint(iMachineNameX, iMachineNameY), m_nameSize),
    576562              /* Font to paint text: */
    577               data(ElementData_NameFont).value<QFont>(),
     563              m_nameFont,
    578564              /* Text to paint: */
    579565              m_strName,
     
    591577        int iMinimumTextColumnWidth = data(ElementData_MinimumTextColumnWidth).toInt();
    592578        int iMaximumTextWidth = geometry().width() - 3 * iMargin - iSpacing;
    593         QFont textFont = data(ElementData_TextFont).value<QFont>();
    594579        QPaintDevice *pPaintDevice = model()->paintDevice();
    595         QFontMetrics fm(textFont, pPaintDevice);
     580        QFontMetrics fm(m_textFont, pPaintDevice);
    596581
    597582        /* Search for the maximum line widths: */
     
    629614        /* Where to paint? */
    630615        int iMachineTextX = iMachinePixmapX;
    631         int iMachineTextY = iMargin + iHeaderHeight + 2 * iMargin;
     616        int iMachineTextY = iMargin + m_iMinimumHeaderHeight + 2 * iMargin;
    632617
    633618        /* For each the line: */
     
    639624            {
    640625                bool fRightColumnPresent = !line.second.isEmpty();
    641                 QTextLayout *pTextLayout = prepareTextLayout(textFont, pPaintDevice,
     626                QTextLayout *pTextLayout = prepareTextLayout(m_textFont, pPaintDevice,
    642627                                                             fRightColumnPresent ? line.first + ":" : line.first,
    643628                                                             iLeftColumnWidth, iLeftColumnHeight);
     
    650635            if (!line.second.isEmpty())
    651636            {
    652                 QTextLayout *pTextLayout = prepareTextLayout(textFont, pPaintDevice,
     637                QTextLayout *pTextLayout = prepareTextLayout(m_textFont, pPaintDevice,
    653638                                                             line.second, iRightColumnWidth, iRightColumnHeight);
    654639                pTextLayout->draw(pPainter, QPointF(iMachineTextX + iLeftColumnWidth + iSpacing, iMachineTextY));
     
    672657    /* Prepare variables: */
    673658    int iMargin = data(ElementData_Margin).toInt();
    674     int iHeaderContentHeight = data(ElementData_HeaderSize).toSize().height();
    675     int iHeaderHeight = 2 * iMargin + iHeaderContentHeight;
     659    int iHeaderHeight = 2 * iMargin + m_iMinimumHeaderHeight;
    676660    QRect optionRect = pOption->rect;
    677661    QRect fullRect = !m_fAnimationRunning ? optionRect :
     
    792776    int iMargin = data(ElementData_Margin).toInt();
    793777    int iSpacing = data(ElementData_Spacing).toInt();
    794     int iPixmapWidth = data(ElementData_PixmapSize).toSize().width();
    795     QSize nameSize = data(ElementData_NameSize).toSize();
    796     int iNameHeight = nameSize.height();
    797     int iHeaderHeight = data(ElementData_HeaderSize).toSize().height();
    798     int iMachineNameX = 2 * iMargin + iPixmapWidth + iSpacing;
    799     int iMachineNameY = iNameHeight == iHeaderHeight ?
    800                         iMargin : iMargin + (iHeaderHeight - iNameHeight) / 2;
     778    int iNameHeight = m_nameSize.height();
     779    int iMachineNameX = 2 * iMargin + m_pixmapSize.width() + iSpacing;
     780    int iMachineNameY = iNameHeight == m_iMinimumHeaderHeight ?
     781                        iMargin : iMargin + (m_iMinimumHeaderHeight - iNameHeight) / 2;
    801782
    802783    /* Simulate hyperlink hovering: */
    803784    QPoint point = pEvent->pos().toPoint();
    804     bool fNameHovered = QRect(QPoint(iMachineNameX, iMachineNameY), nameSize).contains(point);
     785    bool fNameHovered = QRect(QPoint(iMachineNameX, iMachineNameY), m_nameSize).contains(point);
    805786    if (m_fNameHoveringAccessible && m_fNameHovered != fNameHovered)
    806787    {
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/details/UIGDetailsElement.h

    r43982 r43984  
    109109        ElementData_Margin,
    110110        ElementData_Spacing,
    111         /* Pixmaps: */
    112         ElementData_Pixmap,
    113         /* Fonts: */
    114         ElementData_NameFont,
    115         ElementData_TextFont,
    116111        /* Sizes: */
    117         ElementData_PixmapSize,
    118         ElementData_NameSize,
    119         ElementData_ButtonSize,
    120         ElementData_HeaderSize,
    121112        ElementData_TextWidth,
    122113        ElementData_TextHeight,
     
    127118    QVariant data(int iKey) const;
    128119
     120    /* Helpers: Update stuff: */
     121    void updateMinimumHeaderWidth();
     122    void updateMinimumHeaderHeight();
     123
    129124    /* API: Icon stuff: */
    130125    void setIcon(const QIcon &icon);
     
    141136
    142137    /* Helpers: Layout stuff: */
     138    int minimumHeaderWidth() const { return m_iMinimumHeaderWidth; }
     139    int minimumHeaderHeight() const { return m_iMinimumHeaderHeight; }
    143140    void updateLayout();
    144141
     
    196193    UIGDetailsSet *m_pSet;
    197194    DetailsElementType m_type;
    198     QIcon m_icon;
     195    QPixmap m_pixmap;
    199196    QString m_strName;
    200197    UITextTable m_text;
    201198    int m_iCornerRadius;
     199    QFont m_nameFont;
     200    QFont m_textFont;
     201    QSize m_pixmapSize;
     202    QSize m_nameSize;
     203    QSize m_buttonSize;
     204    int m_iMinimumHeaderWidth;
     205    int m_iMinimumHeaderHeight;
    202206
    203207    /* Variables: Toggle stuff: */
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/details/UIGDetailsElements.cpp

    r43982 r43984  
    169169    /* Prepare variables: */
    170170    int iMargin = data(ElementData_Margin).toInt();
    171     int iHeaderHeight = data(ElementData_HeaderSize).toSize().height();
    172171    /* Prepare layout: */
    173172    QGraphicsLinearLayout *pLayout = new QGraphicsLinearLayout;
    174     pLayout->setContentsMargins(iMargin, 2 * iMargin + iHeaderHeight, iMargin, iMargin);
     173    pLayout->setContentsMargins(iMargin, 2 * iMargin + minimumHeaderHeight(), iMargin, iMargin);
    175174    setLayout(pLayout);
    176175
     
    185184    /* Prepare variables: */
    186185    int iMargin = data(ElementData_Margin).toInt();
    187     int iHeaderWidth = data(ElementData_HeaderSize).toSize().width();
    188186
    189187    /* Calculating proposed width: */
     
    191189
    192190    /* Maximum between header width and preview width: */
    193     iProposedWidth += qMax(iHeaderWidth, m_pPreview->minimumSizeHint().toSize().width());
     191    iProposedWidth += qMax(minimumHeaderWidth(), m_pPreview->minimumSizeHint().toSize().width());
    194192
    195193    /* Two margins: */
     
    204202    /* Prepare variables: */
    205203    int iMargin = data(ElementData_Margin).toInt();
    206     int iHeaderHeight = data(ElementData_HeaderSize).toSize().height();
    207204
    208205    /* Calculating proposed height: */
     
    213210
    214211    /* Header height: */
    215     iProposedHeight += iHeaderHeight;
     212    iProposedHeight += minimumHeaderHeight();
    216213
    217214    /* Element is opened? */
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