VirtualBox

Changeset 107981 in vbox for trunk


Ignore:
Timestamp:
Jan 29, 2025 12:29:24 PM (3 months ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
167244
Message:

FE/Qt: bugref:10814: VBox Manager / Tools pane: Get rid of stuff related to tool item name compression; It was blindly copy-pasted years ago from chooser item prototype.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/manager/tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/tools/UIToolsItem.cpp

    r107980 r107981  
    207207    , m_iPreviousMinimumWidthHint(0)
    208208    , m_iPreviousMinimumHeightHint(0)
    209     , m_iMaximumNameWidth(0)
    210209{
    211210    prepare();
     
    231230        /* Update linked values: */
    232231        m_strName = strName;
    233         updateMinimumNameSize();
    234         updateVisibleName();
     232        updateNameSize();
    235233    }
    236234}
     
    293291    int iToolsItemWidth = m_pixmapSize.width();
    294292    if (model()->tools()->isPopup())
    295         iToolsItemWidth += iSpacing + m_minimumNameSize.width();
     293        iToolsItemWidth += iSpacing + m_nameSize.width();
    296294    iProposedWidth += iToolsItemWidth;
    297295
     
    312310    /* And Tools-item content to take into account: */
    313311    int iToolsItemHeight = qMax(m_pixmapSize.height(),
    314                                 m_minimumNameSize.height());
     312                                m_nameSize.height());
    315313    iProposedHeight += iToolsItemHeight;
    316314
     
    335333    /* Update pixmap: */
    336334    updatePixmap();
    337 }
    338 
    339 void UIToolsItem::resizeEvent(QGraphicsSceneResizeEvent *pEvent)
    340 {
    341     /* Call to base-class: */
    342     QIGraphicsWidget::resizeEvent(pEvent);
    343 
    344     /* What is the new geometry? */
    345     const QRectF newGeometry = geometry();
    346 
    347     /* Should we update visible name? */
    348     if (previousGeometry().width() != newGeometry.width())
    349         updateMaximumNameWidth();
    350 
    351     /* Remember the new geometry: */
    352     setPreviousGeometry(newGeometry);
    353335}
    354336
     
    455437    /* Init: */
    456438    updatePixmap();
    457     updateMinimumNameSize();
    458     updateVisibleName();
     439    updateNameSize();
    459440}
    460441
     
    588569    {
    589570        m_pixmapSize = pixmapSize;
    590         updateMaximumNameWidth();
    591571        updateGeometry();
    592572    }
     
    598578}
    599579
    600 void UIToolsItem::updateMinimumNameSize()
     580void UIToolsItem::updateNameSize()
    601581{
    602582    /* Prepare variables: */
    603583    QPaintDevice *pPaintDevice = model()->paintDevice();
    604584
    605     /* Calculate new minimum name size: */
     585    /* Calculate new name size: */
    606586    const QFontMetrics fm(m_nameFont, pPaintDevice);
    607     const int iWidthOf15Letters = textWidthMonospace(m_nameFont, pPaintDevice, 15);
    608     const QString strNameCompressedTo15Letters = compressText(m_nameFont, pPaintDevice, m_strName, iWidthOf15Letters);
    609     const QSize minimumNameSize = QSize(fm.horizontalAdvance(strNameCompressedTo15Letters), fm.height());
     587    const QSize nameSize = QSize(fm.horizontalAdvance(m_strName), fm.height());
    610588
    611589    /* Update linked values: */
    612     if (m_minimumNameSize != minimumNameSize)
    613     {
    614         m_minimumNameSize = minimumNameSize;
     590    if (m_nameSize != nameSize)
     591    {
     592        m_nameSize = nameSize;
    615593        updateGeometry();
    616594    }
    617 }
    618 
    619 void UIToolsItem::updateMaximumNameWidth()
    620 {
    621     /* Prepare variables: */
    622     const int iMargin = data(ToolsItemData_Margin).toInt();
    623     const int iSpacing = data(ToolsItemData_Spacing).toInt();
    624 
    625     /* Calculate new maximum name width: */
    626     int iMaximumNameWidth = (int)geometry().width();
    627     iMaximumNameWidth -= iMargin; /* left margin */
    628     iMaximumNameWidth -= m_pixmapSize.width(); /* pixmap width */
    629     iMaximumNameWidth -= iSpacing; /* spacing between pixmap and name(s) */
    630     iMaximumNameWidth -= iMargin; /* right margin */
    631 
    632     /* Update linked values: */
    633     if (m_iMaximumNameWidth != iMaximumNameWidth)
    634     {
    635         m_iMaximumNameWidth = iMaximumNameWidth;
    636         updateVisibleName();
    637     }
    638 }
    639 
    640 void UIToolsItem::updateVisibleName()
    641 {
    642     /* Prepare variables: */
    643     QPaintDevice *pPaintDevice = model()->paintDevice();
    644 
    645     /* Calculate new visible name: */
    646     const QString strVisibleName = compressText(m_nameFont, pPaintDevice, m_strName, m_iMaximumNameWidth);
    647 
    648     /* Update linked values: */
    649     if (m_strVisibleName != strVisibleName)
    650     {
    651         m_strVisibleName = strVisibleName;
    652         update();
    653     }
    654 }
    655 
    656 /* static */
    657 int UIToolsItem::textWidthMonospace(const QFont &font, QPaintDevice *pPaintDevice, int iCount)
    658 {
    659     /* Return text width, based on font-metrics: */
    660     const QFontMetrics fm(font, pPaintDevice);
    661     QString strString;
    662     strString.fill('_', iCount);
    663     return fm.horizontalAdvance(strString);
    664 }
    665 
    666 /* static */
    667 QString UIToolsItem::compressText(const QFont &font, QPaintDevice *pPaintDevice, QString strText, int iWidth)
    668 {
    669     /* Check if passed text is empty: */
    670     if (strText.isEmpty())
    671         return strText;
    672 
    673     /* Check if passed text already fits maximum width: */
    674     const QFontMetrics fm(font, pPaintDevice);
    675     if (fm.horizontalAdvance(strText) <= iWidth)
    676         return strText;
    677 
    678     /* Truncate otherwise: */
    679     const QString strEllipsis = QString("...");
    680     const int iEllipsisWidth = fm.horizontalAdvance(strEllipsis + " ");
    681     while (!strText.isEmpty() && fm.horizontalAdvance(strText) + iEllipsisWidth > iWidth)
    682         strText.truncate(strText.size() - 1);
    683     return strText + strEllipsis;
    684595}
    685596
     
    895806        /* Prepare variables: */
    896807        int iNameX = iMargin + m_pixmapSize.width() + iSpacing;
    897         int iNameY = (iFullHeight - m_minimumNameSize.height()) / 2;
     808        int iNameY = (iFullHeight - m_nameSize.height()) / 2;
    898809        /* Paint name: */
    899810        if (model()->tools()->isPopup())
     
    907818                      model()->paintDevice(),
    908819                      /* Text to paint: */
    909                       m_strVisibleName);
     820                      m_strName);
    910821    }
    911822}
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/tools/UIToolsItem.h

    r107980 r107981  
    143143        virtual void showEvent(QShowEvent *pEvent) RT_OVERRIDE;
    144144
    145         /** Handles resize @a pEvent. */
    146         virtual void resizeEvent(QGraphicsSceneResizeEvent *pEvent) RT_OVERRIDE;
    147 
    148145        /** Handles hover enter @a event. */
    149146        virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *pEvent) RT_OVERRIDE;
     
    209206    /** @name Layout stuff.
    210207      * @{ */
    211         /** Defines previous @a geometry. */
    212         void setPreviousGeometry(const QRectF &geometry) { m_previousGeometry = geometry; }
    213         /** Returns previous geometry. */
    214         const QRectF &previousGeometry() const { return m_previousGeometry; }
    215 
    216208        /** Updates pixmap. */
    217209        void updatePixmap();
    218         /** Updates minimum name size. */
    219         void updateMinimumNameSize();
    220         /** Updates maximum name width. */
    221         void updateMaximumNameWidth();
    222         /** Updates visible name. */
    223         void updateVisibleName();
    224 
    225         /** Returns monospace text width of line containing @a iCount of chars calculated on the basis of certain @a font and @a pPaintDevice. */
    226         static int textWidthMonospace(const QFont &font, QPaintDevice *pPaintDevice, int iCount);
    227         /** Compresses @a strText to @a iWidth on the basis of certain @a font and @a pPaintDevice. */
    228         static QString compressText(const QFont &font, QPaintDevice *pPaintDevice, QString strText, int iWidth);
     210        /** Updates name size. */
     211        void updateNameSize();
    229212    /** @} */
    230213
     
    271254        /** Holds the item name font. */
    272255        QFont    m_nameFont;
    273         /** Holds the item visible name. */
    274         QString  m_strVisibleName;
    275256
    276257        /** Holds whether item is hovered. */
     
    307288    /** @name Layout stuff.
    308289      * @{ */
    309         /** Holds previous geometry. */
    310         QRectF  m_previousGeometry;
    311 
    312290        /** Holds previous minimum width hint. */
    313291        int  m_iPreviousMinimumWidthHint;
     
    317295        /** Holds the pixmap size. */
    318296        QSize  m_pixmapSize;
    319         /** Holds minimum name size. */
    320         QSize  m_minimumNameSize;
    321 
    322         /** Holds maximum name width. */
    323         int  m_iMaximumNameWidth;
     297        /** Holds the name size. */
     298        QSize  m_nameSize;
    324299    /** @} */
    325300};
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette