VirtualBox

Changeset 43784 in vbox


Ignore:
Timestamp:
Oct 31, 2012 1:37:54 PM (12 years ago)
Author:
vboxsync
Message:

FE/Qt: VM group UI: Cache visible name for group-item.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser/UIGChooserItemGroup.cpp

    r43783 r43784  
    226226}
    227227
     228void UIGChooserItemGroup::sltHandleGeometryChange()
     229{
     230    /* Which is new geometry? */
     231    QRectF newGeometry = geometry();
     232
     233    /* Should we update visible name? */
     234    if (m_previousGeometry.width() != newGeometry.width())
     235        recacheVisibleName();
     236
     237    /* Remember new geometry: */
     238    m_previousGeometry = newGeometry;
     239}
     240
    228241void UIGChooserItemGroup::sltNameEditingFinished()
    229242{
     
    251264    /* Set new name / update model: */
    252265    m_strName = strNewName;
     266    recacheVisibleName();
    253267    model()->saveGroupSettings();
    254268}
     
    328342        case GroupItemData_MinorSpacing: return 3;
    329343        /* Texts: */
    330         case GroupItemData_Name:
    331         {
    332             /* Prepare variables: */
    333             int iHorizontalMargin = data(GroupItemData_HorizonalMargin).toInt();
    334             int iMajorSpacing = data(GroupItemData_MajorSpacing).toInt();
    335             int iToggleButtonWidth = data(GroupItemData_ToggleButtonSize).toSize().width();
    336             int iEnterButtonWidth = data(GroupItemData_EnterButtonSize).toSize().width();
    337             int iExitButtonWidth = data(GroupItemData_ExitButtonSize).toSize().width();
    338             int iGroupPixmapWidth = data(GroupItemData_GroupPixmapSize).toSize().width();
    339             int iMachinePixmapWidth = data(GroupItemData_MachinePixmapSize).toSize().width();
    340             int iGroupCountTextWidth = data(GroupItemData_GroupCountTextSize).toSize().width();
    341             int iMachineCountTextWidth = data(GroupItemData_MachineCountTextSize).toSize().width();
    342             int iMaximumWidth = (int)geometry().width();
    343             QString strGroupCountText = data(GroupItemData_GroupCountText).toString();
    344             QString strMachineCountText = data(GroupItemData_MachineCountText).toString();
    345 
    346             /* Calculate name width: */
    347             iMaximumWidth -= 2 * iHorizontalMargin;
    348             if (isRoot())
    349                 iMaximumWidth -= (iExitButtonWidth + iMajorSpacing);
    350             else
    351             {
    352                 iMaximumWidth -= (iToggleButtonWidth + iMajorSpacing);
    353                 if (isHovered())
    354                     iMaximumWidth -= (iEnterButtonWidth + iMajorSpacing);
    355             }
    356             if (isHovered() && !strGroupCountText.isEmpty())
    357                 iMaximumWidth -= (iGroupPixmapWidth + iGroupCountTextWidth);
    358             if (isHovered() && !strMachineCountText.isEmpty())
    359                 iMaximumWidth -= (iMachinePixmapWidth + iMachineCountTextWidth);
    360             return compressText(m_nameFont, model()->paintDevice(), m_strName, iMaximumWidth);
    361         }
     344        case GroupItemData_Name: return m_strVisibleName;
    362345        case GroupItemData_GroupCountText: return m_groupItems.isEmpty() ? QString() : QString::number(m_groupItems.size());
    363346        case GroupItemData_MachineCountText: return m_machineItems.isEmpty() ? QString() : QString::number(m_machineItems.size());
     
    479462    m_machinesPixmap = QPixmap(":/machine_16px.png");
    480463
     464    /* Geometry change handler: */
     465    connect(this, SIGNAL(geometryChanged()), this, SLOT(sltHandleGeometryChange()));
     466
    481467    /* Non root item only: */
    482468    if (!isRoot())
     
    523509    foreach (UIGChooserItem *pMachineItem, pFrom->items(UIGChooserItemType_Machine))
    524510        new UIGChooserItemMachine(pTo, pMachineItem->toMachineItem());
     511}
     512
     513void UIGChooserItemGroup::recacheVisibleName()
     514{
     515    /* Prepare variables: */
     516    int iHorizontalMargin = data(GroupItemData_HorizonalMargin).toInt();
     517    int iMajorSpacing = data(GroupItemData_MajorSpacing).toInt();
     518    int iToggleButtonWidth = data(GroupItemData_ToggleButtonSize).toSize().width();
     519    int iEnterButtonWidth = data(GroupItemData_EnterButtonSize).toSize().width();
     520    int iExitButtonWidth = data(GroupItemData_ExitButtonSize).toSize().width();
     521    int iGroupPixmapWidth = data(GroupItemData_GroupPixmapSize).toSize().width();
     522    int iMachinePixmapWidth = data(GroupItemData_MachinePixmapSize).toSize().width();
     523    int iGroupCountTextWidth = data(GroupItemData_GroupCountTextSize).toSize().width();
     524    int iMachineCountTextWidth = data(GroupItemData_MachineCountTextSize).toSize().width();
     525    int iMaximumWidth = geometry().width();
     526
     527    /* Calculate name width: */
     528    iMaximumWidth -= 2 * iHorizontalMargin;
     529    if (isRoot())
     530    {
     531        iMaximumWidth -= (iExitButtonWidth + iMajorSpacing);
     532    }
     533    else
     534    {
     535        iMaximumWidth -= (iToggleButtonWidth + iMajorSpacing);
     536        if (isHovered())
     537            iMaximumWidth -= iEnterButtonWidth;
     538    }
     539    if (isHovered())
     540    {
     541        iMaximumWidth -= iMajorSpacing;
     542        if (iGroupCountTextWidth != 0)
     543            iMaximumWidth -= (iGroupPixmapWidth + iGroupCountTextWidth);
     544        if (iMachineCountTextWidth != 0)
     545            iMaximumWidth -= (iMachinePixmapWidth + iMachineCountTextWidth);
     546    }
     547
     548    /* Recache name: */
     549    m_strVisibleName = compressText(m_nameFont, model()->paintDevice(), m_strName, iMaximumWidth);
     550    update();
    525551}
    526552
     
    12731299void UIGChooserItemGroup::hoverMoveEvent(QGraphicsSceneHoverEvent *pEvent)
    12741300{
     1301    /* Skip if hovered: */
     1302    if (isHovered())
     1303        return;
     1304
    12751305    /* Prepare variables: */
    12761306    QPoint pos = pEvent->pos().toPoint();
     
    12781308    int iHeaderHeight = data(GroupItemData_FullHeaderSize).toSize().height();
    12791309    int iFullHeaderHeight = 2 * iMargin + iHeaderHeight;
    1280     /* Check if group should be highlighted: */
    1281     if ((pos.y() < iFullHeaderHeight) && !isHovered())
    1282     {
    1283         setHovered(true);
    1284         emit sigHoverEnter();
    1285     }
     1310    /* Skip if hovered part out of the header: */
     1311    if (pos.y() >= iFullHeaderHeight)
     1312        return;
     1313
     1314    /* Call to base-class: */
     1315    UIGChooserItem::hoverMoveEvent(pEvent);
     1316
     1317    /* Update visible name: */
     1318    recacheVisibleName();
     1319}
     1320
     1321void UIGChooserItemGroup::hoverLeaveEvent(QGraphicsSceneHoverEvent *pEvent)
     1322{
     1323    /* Skip if not hovered: */
     1324    if (!isHovered())
     1325        return;
     1326
     1327    /* Call to base-class: */
     1328    UIGChooserItem::hoverLeaveEvent(pEvent);
     1329
     1330    /* Update visible name: */
     1331    recacheVisibleName();
    12861332}
    12871333
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser/UIGChooserItemGroup.h

    r43783 r43784  
    8383
    8484private slots:
     85
     86    /* Handler: Geometry change stuff: */
     87    void sltHandleGeometryChange();
    8588
    8689    /* Handler: Name editing stuff: */
     
    129132    static void copyContent(UIGChooserItemGroup *pFrom, UIGChooserItemGroup *pTo);
    130133
     134    /* Helper: Recache stuff: */
     135    void recacheVisibleName();
     136
    131137    /* Helper: Translate stuff: */
    132138    void retranslateUi();
     
    173179    /* Helper: Event handling stuff: */
    174180    void hoverMoveEvent(QGraphicsSceneHoverEvent *pEvent);
     181    void hoverLeaveEvent(QGraphicsSceneHoverEvent *pEvent);
    175182
    176183    /* Helpers: Paint stuff: */
     
    204211    int m_iBlackoutDarkness;
    205212    /* Cached values: */
     213    QRectF m_previousGeometry;
     214    QString m_strVisibleName;
    206215    QFont m_nameFont;
    207216    QFont m_infoFont;
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