VirtualBox

Changeset 101590 in vbox


Ignore:
Timestamp:
Oct 25, 2023 12:54:48 PM (19 months ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
159671
Message:

FE/Qt: bugref:10535. Overlay icons rather than pixmaps to have the arch. text on window title icons etc.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/globals
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIIconPool.cpp

    r101575 r101590  
    554554}
    555555
     556/* static */
     557QIcon UIIconPoolGeneral::overlayedIconSet(const QString &strGuestOSTypeId,
     558                                          const QString &strNormal,
     559                                          const QString &strDisabled /* = QString() */,
     560                                          const QString &strActive /* = QString() */)
     561{
     562    /* Prepare fallback icon: */
     563    static QIcon nullIcon;
     564
     565    /* Prepare icon: */
     566    QIcon icon;
     567
     568    /* Add 'normal' pixmap: */
     569    AssertReturn(!strNormal.isEmpty(), nullIcon);
     570    addNameAndOverlay(icon, strNormal, strGuestOSTypeId, QIcon::Normal);
     571
     572    /* Add 'disabled' pixmap (if any): */
     573    if (!strDisabled.isEmpty())
     574        addNameAndOverlay(icon, strDisabled, strGuestOSTypeId, QIcon::Disabled);
     575
     576    /* Add 'active' pixmap (if any): */
     577    if (!strActive.isEmpty())
     578        addNameAndOverlay(icon, strActive, strGuestOSTypeId, QIcon::Active);
     579
     580    /* Return icon: */
     581    return icon;
     582}
     583
     584/* static */
     585void UIIconPoolGeneral::addNameAndOverlay(QIcon &icon, const QString &strName, const QString &strGuestOSTypeId,
     586                                QIcon::Mode mode /* = QIcon::Normal */, QIcon::State state /* = QIcon::Off */ )
     587{
     588    /* Prepare pixmap on the basis of passed value: */
     589    QPixmap pixmap(strName);
     590    overlayArchitectureTextOnPixmap(determineOSArchString(strGuestOSTypeId), pixmap);
     591    /* Add pixmap: */
     592    icon.addPixmap(pixmap, mode, state);
     593
     594    /* Parse name to prefix and suffix: */
     595    QString strPrefix = strName.section('.', 0, -2);
     596    QString strSuffix = strName.section('.', -1, -1);
     597    /* Prepare HiDPI pixmaps: */
     598    const QStringList aPixmapNames = QStringList() << (strPrefix + "_x2." + strSuffix)
     599                                                   << (strPrefix + "_x3." + strSuffix)
     600                                                   << (strPrefix + "_x4." + strSuffix);
     601    foreach (const QString &strPixmapName, aPixmapNames)
     602    {
     603        QPixmap pixmapHiDPI(strPixmapName);
     604        if (!pixmapHiDPI.isNull())
     605        {
     606            overlayArchitectureTextOnPixmap(determineOSArchString(strGuestOSTypeId), pixmapHiDPI);
     607            icon.addPixmap(pixmapHiDPI, mode, state);
     608        }
     609    }
     610}
     611
    556612QIcon UIIconPoolGeneral::userMachineIcon(const CMachine &comMachine) const
    557613{
     
    654710        /* Compose proper icon if we have that 'guest OS type' known: */
    655711        if (m_guestOSTypeIconNames.contains(strOSTypeID))
    656             m_guestOSTypeIcons[strOSTypeID] = iconSet(m_guestOSTypeIconNames[strOSTypeID]);
     712            m_guestOSTypeIcons[strOSTypeID] = overlayedIconSet(strOSTypeID, m_guestOSTypeIconNames[strOSTypeID]);
    657713        /* Assign fallback icon if we do NOT have that 'guest OS type' registered: */
    658714        else if (!strOSTypeID.isNull())
    659             m_guestOSTypeIcons[strOSTypeID] = iconSet(m_guestOSTypeIconNames[GUEST_OS_ID_STR_X86("Other")]);
     715            m_guestOSTypeIcons[strOSTypeID] = overlayedIconSet(strOSTypeID, m_guestOSTypeIconNames[GUEST_OS_ID_STR_X86("Other")]);
    660716        /* Assign fallback icon if we do NOT have that 'guest OS type' known: */
    661717        else
     
    720776    }
    721777
    722     overlayArchitectureTextOnPixmap(determineOSArchString(strOSTypeID), pixmap);
    723778    /* Return pixmap: */
    724779    return pixmap;
    725780}
    726781
    727 QString UIIconPoolGeneral::determineOSArchString(const QString &osTypeId) const
     782/* static */
     783QString UIIconPoolGeneral::determineOSArchString(const QString &osTypeId)
    728784{
    729785    if (osTypeId.contains("_x64") || osTypeId.contains("_64"))
     
    736792}
    737793
    738 void UIIconPoolGeneral::overlayArchitectureTextOnPixmap(const QString &strArch, QPixmap &pixmap) const
     794/* static */
     795void UIIconPoolGeneral::overlayArchitectureTextOnPixmap(const QString &strArch, QPixmap &pixmap)
    739796{
    740797#if 0
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIIconPool.h

    r101508 r101590  
    160160private:
    161161
     162    /** Creates icon from passed pixmap names for
     163      * @a strNormal, @a strDisabled and @a strActive icon states. Utilizes addNameAndOverlay to overlay pixmaps. */
     164    static QIcon overlayedIconSet(const QString &strGuestOSTypeId,
     165                                  const QString &strNormal,
     166                                  const QString &strDisabled = QString(),
     167                                  const QString &strActive = QString());
     168    /* Just like UIIconPool::addName add resources to icon but additionally overlays corresponding text wrt. strGuestOSTypeId. */
     169    static void addNameAndOverlay(QIcon &icon, const QString &strName, const QString &strGuestOSTypeId,
     170                        QIcon::Mode mode = QIcon::Normal, QIcon::State state = QIcon::Off);
     171
    162172    /** Constructs general icon-pool. */
    163173    UIIconPoolGeneral();
     
    165175    virtual ~UIIconPoolGeneral() /* override final */;
    166176    /** Overlay text @p strArch on top of @p pixmap. */
    167     void overlayArchitectureTextOnPixmap(const QString &strArch, QPixmap &pixmap) const;
     177    static void overlayArchitectureTextOnPixmap(const QString &strArch, QPixmap &pixmap);
    168178    /** Returns the architecture text we overlay on guest OS type id icon.*/
    169     QString determineOSArchString(const QString &osTypeId) const;
     179    static QString determineOSArchString(const QString &osTypeId);
    170180    /** Holds the singleton instance. */
    171181    static UIIconPoolGeneral *s_pInstance;
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