VirtualBox

Changeset 66657 in vbox for trunk


Ignore:
Timestamp:
Apr 24, 2017 5:10:56 PM (8 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:6911: Rework general icon pool API to provide dynamical icons as well, not just static pixmaps.

Location:
trunk/src/VBox/Frontends/VirtualBox/src
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/extradata/UIExtraDataManager.cpp

    r66593 r66657  
    412412    /* If proper machine ID passed => return corresponding pixmap/size: */
    413413    if (index.data(Field_ID).toString() != UIExtraDataManager::GlobalID)
    414         pixmap = vboxGlobal().vmGuestOSTypeIcon(index.data(Field_OsTypeID).toString(), &pixmapSize);
     414        pixmap = vboxGlobal().vmGuestOSTypePixmapDefault(index.data(Field_OsTypeID).toString(), &pixmapSize);
    415415    else
    416416    {
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIIconPool.cpp

    r66229 r66657  
    55
    66/*
    7  * Copyright (C) 2010-2016 Oracle Corporation
     7 * Copyright (C) 2010-2017 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2222/* Qt includes: */
    2323# include <QApplication>
     24# include <QStyle>
    2425# include <QWidget>
    25 # include <QStyle>
    2626
    2727/* GUI includes: */
     
    355355}
    356356
    357 QPixmap UIIconPoolGeneral::guestOSTypeIcon(const QString &strOSTypeID, QSize *pLogicalSize /* = 0 */) const
    358 {
    359     /* Prepare fallback pixmap: */
    360     static QPixmap nullPixmap;
     357QIcon UIIconPoolGeneral::guestOSTypeIcon(const QString &strOSTypeID) const
     358{
     359    /* Prepare fallback icon: */
     360    static QPixmap nullIcon;
    361361
    362362    /* If we do NOT have that 'guest OS type' icon cached already: */
     
    368368        /* Assign fallback icon if we do NOT have that 'guest OS type' known: */
    369369        else
    370             m_guestOSTypeIcons[strOSTypeID] = iconSet(nullPixmap);
     370            m_guestOSTypeIcons[strOSTypeID] = iconSet(nullIcon);
    371371    }
    372372
     
    375375    AssertMsgReturn(!icon.isNull(),
    376376                    ("Undefined icon for type '%s'.", strOSTypeID.toLatin1().constData()),
    377                     nullPixmap);
    378 
    379     /* Retrieve available sizes for that icon: */
    380     const QList<QSize> availableSizes = icon.availableSizes();
    381     AssertMsgReturn(!availableSizes.isEmpty(),
    382                     ("Undefined icon for type '%s'.", strOSTypeID.toLatin1().constData()),
    383                     nullPixmap);
    384 
    385     /* Determine desired icon size: */
    386     const QStyle *pStyle = QApplication::style();
    387     const int iIconMetric = pStyle->pixelMetric(QStyle::PM_LargeIconSize);
    388     const QSize iconSize = QSize(iIconMetric, iIconMetric);
    389 
    390     /* Pass up logical size if necessary: */
    391     if (pLogicalSize)
    392         *pLogicalSize = iconSize;
    393 
    394     /* Return pixmap of first available size: */
    395     return icon.pixmap(iconSize);
    396 }
    397 
    398 QPixmap UIIconPoolGeneral::guestOSTypePixmap(const QString &strOSTypeID, const QSize &physicalSize) const
    399 {
    400     /* Prepare fallback pixmap: */
    401     static QPixmap nullPixmap;
    402 
    403     /* If we do NOT have that 'guest OS type' pixmap cached already: */
    404     if (!m_guestOSTypePixmaps.contains(strOSTypeID))
     377                    nullIcon);
     378
     379    /* Return icon: */
     380    return icon;
     381}
     382
     383QPixmap UIIconPoolGeneral::guestOSTypePixmap(const QString &strOSTypeID, const QSize &size) const
     384{
     385    /* Acquire icon: */
     386    const QIcon icon = guestOSTypeIcon(strOSTypeID);
     387
     388    /* Prepare pixmap: */
     389    QPixmap pixmap;
     390
     391    /* Check whether we have valid icon: */
     392    if (!icon.isNull())
    405393    {
    406         /* Compose proper pixmap if we have that 'guest OS type' known: */
    407         if (m_guestOSTypeIconNames.contains(strOSTypeID))
    408             m_guestOSTypePixmaps[strOSTypeID] = QPixmap(m_guestOSTypeIconNames[strOSTypeID]);
    409         /* Assign fallback pixmap if we do NOT have that 'guest OS type' known: */
    410         else
    411             m_guestOSTypePixmaps[strOSTypeID] = nullPixmap;
     394        /* Get pixmap of requested size: */
     395        pixmap = icon.pixmap(size);
     396        /* And even scale it if size is not valid: */
     397        if (pixmap.size() != size)
     398            pixmap = pixmap.scaled(size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
    412399    }
    413400
    414     /* Retrieve corresponding pixmap: */
    415     const QPixmap &pixmap = m_guestOSTypePixmaps.value(strOSTypeID);
    416     AssertMsgReturn(!pixmap.isNull(),
    417                     ("Undefined pixmap for type '%s'.", strOSTypeID.toLatin1().constData()),
    418                     nullPixmap);
    419 
    420     /* Return pixmap of the requested size: */
    421     return pixmap.size() == physicalSize ? pixmap : pixmap.scaled(physicalSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
    422 }
    423 
    424 QPixmap UIIconPoolGeneral::guestOSTypePixmapHiDPI(const QString &strOSTypeID, const QSize &physicalSize) const
    425 {
    426     /* Prepare fallback pixmap: */
    427     static QPixmap nullPixmap;
    428 
    429     /* If we do NOT have that 'guest OS type' pixmap cached already: */
    430     if (!m_guestOSTypePixmapsHiDPI.contains(strOSTypeID))
     401    /* Return pixmap: */
     402    return pixmap;
     403}
     404
     405QPixmap UIIconPoolGeneral::guestOSTypePixmapDefault(const QString &strOSTypeID, QSize *pLogicalSize /* = 0 */) const
     406{
     407    /* Acquire icon: */
     408    const QIcon icon = guestOSTypeIcon(strOSTypeID);
     409
     410    /* Prepare pixmap: */
     411    QPixmap pixmap;
     412
     413    /* Check whether we have valid icon: */
     414    if (!icon.isNull())
    431415    {
    432         /* Compose proper pixmap if we have that 'guest OS type' known: */
    433         if (m_guestOSTypeIconNames.contains(strOSTypeID))
    434         {
    435             /* Get name: */
    436             const QString strName =  m_guestOSTypeIconNames.value(strOSTypeID);
    437             /* Parse name to prefix and suffix: */
    438             const QString strPrefix = strName.section('.', 0, -2);
    439             const QString strSuffix = strName.section('.', -1, -1);
    440             /* Prepare HiDPI pixmap on the basis of values above: */
    441             const QPixmap pixmapHiDPI(strPrefix + "_hidpi." + strSuffix);
    442             /* Remember HiDPI pixmap: */
    443             m_guestOSTypePixmapsHiDPI[strOSTypeID] = pixmapHiDPI;
    444         }
    445         /* Assign fallback pixmap if we do NOT have that 'guest OS type' known: */
    446         else
    447             m_guestOSTypePixmapsHiDPI[strOSTypeID] = nullPixmap;
     416        /* Determine desired icon size: */
     417        const int iIconMetric = QApplication::style()->pixelMetric(QStyle::PM_LargeIconSize);
     418        const QSize iconSize = QSize(iIconMetric, iIconMetric);
     419
     420        /* Pass up logical size if necessary: */
     421        if (pLogicalSize)
     422            *pLogicalSize = iconSize;
     423
     424        /* Get pixmap of requested size: */
     425        pixmap = icon.pixmap(iconSize);
    448426    }
    449427
    450     /* Retrieve corresponding pixmap: */
    451     const QPixmap &pixmap = m_guestOSTypePixmapsHiDPI.value(strOSTypeID);
    452     AssertMsgReturn(!pixmap.isNull(),
    453                     ("Undefined pixmap for type '%s'.", strOSTypeID.toLatin1().constData()),
    454                     nullPixmap);
    455 
    456     /* Return pixmap of the requested size: */
    457     return pixmap.size() == physicalSize ? pixmap : pixmap.scaled(physicalSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
    458 }
    459 
     428    /* Return pixmap: */
     429    return pixmap;
     430}
     431
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIIconPool.h

    r64715 r66657  
    55
    66/*
    7  * Copyright (C) 2010-2016 Oracle Corporation
     7 * Copyright (C) 2010-2017 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2323#include <QPixmap>
    2424#include <QHash>
     25
    2526
    2627/** Interface which provides GUI with static API
     
    103104    UIIconPoolGeneral();
    104105
     106    /** Returns icon corresponding to passed @a strOSTypeID. */
     107    QIcon guestOSTypeIcon(const QString &strOSTypeID) const;
     108    /** Returns pixmap corresponding to passed @a strOSTypeID and @a size. */
     109    QPixmap guestOSTypePixmap(const QString &strOSTypeID, const QSize &size) const;
    105110    /** Returns pixmap corresponding to passed @a strOSTypeID.
    106111      * In case if non-null @a pLogicalSize pointer provided, it will be updated properly. */
    107     QPixmap guestOSTypeIcon(const QString &strOSTypeID, QSize *pLogicalSize = 0) const;
    108 
    109     /** Returns pixmap corresponding to passed @a strOSTypeID and @a physicalSize. */
    110     QPixmap guestOSTypePixmap(const QString &strOSTypeID, const QSize &physicalSize) const;
    111     /** Returns HiDPI pixmap corresponding to passed @a strOSTypeID and @a physicalSize. */
    112     QPixmap guestOSTypePixmapHiDPI(const QString &strOSTypeID, const QSize &physicalSize) const;
     112    QPixmap guestOSTypePixmapDefault(const QString &strOSTypeID, QSize *pLogicalSize = 0) const;
    113113
    114114private:
     
    118118    /** Guest OS type icons cache. */
    119119    mutable QHash<QString, QIcon> m_guestOSTypeIcons;
    120     /** Holds the guest OS type pixmaps cache. */
    121     mutable QHash<QString, QPixmap> m_guestOSTypePixmaps;
    122     /** Holds the guest OS type HiDPI pixmaps cache. */
    123     mutable QHash<QString, QPixmap> m_guestOSTypePixmapsHiDPI;
    124120};
    125121
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.cpp

    r66593 r66657  
    558558}
    559559
    560 QPixmap VBoxGlobal::vmGuestOSTypeIcon(const QString &strOSTypeID, QSize *pLogicalSize /* = 0 */) const
     560QIcon VBoxGlobal::vmGuestOSTypeIcon(const QString &strOSTypeID) const
     561{
     562    /* Prepare fallback icon: */
     563    static QIcon nullIcon;
     564
     565    /* Make sure general icon-pool initialized: */
     566    AssertReturn(m_pIconPool, nullIcon);
     567
     568    /* Redirect to general icon-pool: */
     569    return m_pIconPool->guestOSTypeIcon(strOSTypeID);
     570}
     571
     572QPixmap VBoxGlobal::vmGuestOSTypePixmap(const QString &strOSTypeID, const QSize &size) const
    561573{
    562574    /* Prepare fallback pixmap: */
     
    567579
    568580    /* Redirect to general icon-pool: */
    569     return m_pIconPool->guestOSTypeIcon(strOSTypeID, pLogicalSize);
    570 }
    571 
    572 QPixmap VBoxGlobal::vmGuestOSTypePixmap(const QString &strOSTypeID, const QSize &physicalSize) const
     581    return m_pIconPool->guestOSTypePixmap(strOSTypeID, size);
     582}
     583
     584QPixmap VBoxGlobal::vmGuestOSTypePixmapDefault(const QString &strOSTypeID, QSize *pLogicalSize /* = 0 */) const
    573585{
    574586    /* Prepare fallback pixmap: */
     
    579591
    580592    /* Redirect to general icon-pool: */
    581     return m_pIconPool->guestOSTypePixmap(strOSTypeID, physicalSize);
    582 }
    583 
    584 QPixmap VBoxGlobal::vmGuestOSTypePixmapHiDPI(const QString &strOSTypeID, const QSize &physicalSize) const
    585 {
    586     /* Prepare fallback pixmap: */
    587     static QPixmap nullPixmap;
    588 
    589     /* Make sure general icon-pool initialized: */
    590     AssertReturn(m_pIconPool, nullPixmap);
    591 
    592     /* Redirect to general icon-pool: */
    593     return m_pIconPool->guestOSTypePixmapHiDPI(strOSTypeID, physicalSize);
     593    return m_pIconPool->guestOSTypePixmapDefault(strOSTypeID, pLogicalSize);
    594594}
    595595
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.h

    r66593 r66657  
    222222    QList <CGuestOSType> vmGuestOSTypeList (const QString &aFamilyId) const;
    223223
     224    /** Returns pixmap corresponding to passed @a strOSTypeID. */
     225    QIcon vmGuestOSTypeIcon(const QString &strOSTypeID) const;
     226    /** Returns pixmap corresponding to passed @a strOSTypeID and @a size. */
     227    QPixmap vmGuestOSTypePixmap(const QString &strOSTypeID, const QSize &size) const;
    224228    /** Returns pixmap corresponding to passed @a strOSTypeID.
    225229      * In case if non-null @a pLogicalSize pointer provided, it will be updated properly. */
    226     QPixmap vmGuestOSTypeIcon(const QString &strOSTypeID, QSize *pLogicalSize = 0) const;
    227 
    228     /** Returns pixmap corresponding to passed @a strOSTypeID and @a physicalSize. */
    229     QPixmap vmGuestOSTypePixmap(const QString &strOSTypeID, const QSize &physicalSize) const;
    230     /** Returns HiDPI pixmap corresponding to passed @a strOSTypeID and @a physicalSize. */
    231     QPixmap vmGuestOSTypePixmapHiDPI(const QString &strOSTypeID, const QSize &physicalSize) const;
     230    QPixmap vmGuestOSTypePixmapDefault(const QString &strOSTypeID, QSize *pLogicalSize = 0) const;
    232231
    233232    CGuestOSType vmGuestOSType (const QString &aTypeId,
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.cpp

    r66628 r66657  
    12761276# endif /* QT_VERSION >= 0x050000 */
    12771277
    1278     /* Now the dock icon preview */
    1279     QString osTypeId = guest().GetOSTypeId();
    1280     m_pDockIconPreview = new UIDockIconPreview(uisession(), vboxGlobal().vmGuestOSTypePixmapHiDPI(osTypeId, QSize(42, 42)));
     1278    /* Now the dock icon preview: */
     1279    const QPixmap pixmap = vboxGlobal().vmGuestOSTypePixmap(guest().GetOSTypeId(), QSize(42, 42));
     1280    m_pDockIconPreview = new UIDockIconPreview(uisession(), pixmap);
    12811281
    12821282    /* Should the dock-icon be updated at runtime? */
     
    15541554
    15551555    /* Assign corresponding icon: */
    1556     QString strTypeId = machine().GetOSTypeId();
    1557     pDlg->mLbIcon->setPixmap(vboxGlobal().vmGuestOSTypeIcon(strTypeId));
     1556    const QPixmap pixmap = vboxGlobal().vmGuestOSTypePixmapDefault(guest().GetOSTypeId());
     1557    pDlg->mLbIcon->setPixmap(pixmap);
    15581558
    15591559    /* Search for the max available filter index: */
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIVMCloseDialog.cpp

    r66656 r66657  
    318318
    319319    /* Assign pixmap: */
    320     setPixmap(vboxGlobal().vmGuestOSTypeIcon(m_machine.GetOSTypeId()));
     320    setPixmap(vboxGlobal().vmGuestOSTypePixmapDefault(m_machine.GetOSTypeId()));
    321321
    322322    /* Check which close-actions are resticted: */
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/UISnapshotPane.cpp

    r65232 r66657  
    903903
    904904            // TODO: Assign corresponding icon through sub-dialog API: */
    905             pDlg->mLbIcon->setPixmap(vboxGlobal().vmGuestOSTypeIcon(m_comMachine.GetOSTypeId()));
     905            const QPixmap pixmap = vboxGlobal().vmGuestOSTypePixmapDefault(m_comMachine.GetOSTypeId());
     906            pDlg->mLbIcon->setPixmap(pixmap);
    906907
    907908            /* Search for the max available snapshot index: */
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/UIVMItem.cpp

    r63321 r66657  
    155155QPixmap UIVMItem::osPixmap(QSize *pLogicalSize /* = 0 */) const
    156156{
    157     return m_fAccessible ? vboxGlobal().vmGuestOSTypeIcon(m_strOSTypeId, pLogicalSize) :
    158                            vboxGlobal().vmGuestOSTypeIcon("Other", pLogicalSize);
     157    return m_fAccessible ? vboxGlobal().vmGuestOSTypePixmapDefault(m_strOSTypeId, pLogicalSize) :
     158                           vboxGlobal().vmGuestOSTypePixmapDefault("Other", pLogicalSize);
    159159}
    160160
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIApplianceEditorWidget.cpp

    r66532 r66657  
    522522                const QStyle *pStyle = QApplication::style();
    523523                const int iIconMetric = pStyle->pixelMetric(QStyle::PM_SmallIconSize);
    524                 value = vboxGlobal().vmGuestOSTypeIcon(m_strConfigValue).scaledToHeight(iIconMetric, Qt::SmoothTransformation);
     524                value = vboxGlobal().vmGuestOSTypePixmapDefault(m_strConfigValue).scaledToHeight(iIconMetric, Qt::SmoothTransformation);
    525525            }
    526526            break;
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UINameAndSystemEditor.cpp

    r60878 r66657  
    354354    m_type = vboxGlobal().vmGuestOSType(m_pComboType->itemData(iIndex, TypeID).toString(),
    355355                                        m_pComboFamily->itemData(m_pComboFamily->currentIndex(), TypeID).toString());
    356     m_pIconType->setPixmap(vboxGlobal().vmGuestOSTypeIcon(m_type.GetId()));
     356    m_pIconType->setPixmap(vboxGlobal().vmGuestOSTypePixmapDefault(m_type.GetId()));
    357357
    358358    /* Save the most recently used item: */
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/VBoxOSTypeSelectorButton.cpp

    r62493 r66657  
    5858    /* Looks ugly on the Mac */
    5959#ifndef VBOX_WS_MAC
    60     setIcon (vboxGlobal().vmGuestOSTypeIcon (type.GetId()));
     60    setIcon (vboxGlobal().vmGuestOSTypePixmapDefault (type.GetId()));
    6161#endif /* VBOX_WS_MAC */
    6262    setText (type.GetDescription());
     
    8484        foreach (const CGuestOSType& type, types)
    8585        {
    86             QAction *a = subMenu->addAction (vboxGlobal().vmGuestOSTypeIcon (type.GetId()), type.GetDescription());
     86            QAction *a = subMenu->addAction (vboxGlobal().vmGuestOSTypePixmapDefault (type.GetId()), type.GetDescription());
    8787            connect(a, SIGNAL (triggered()),
    8888                    mSignalMapper, SLOT(map()));
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/exportappliance/UIWizardExportAppPageBasic1.cpp

    r62493 r66657  
    5656        if (machine.GetAccessible())
    5757        {
    58             pixIcon = vboxGlobal().vmGuestOSTypeIcon(machine.GetOSTypeId()).scaled(iIconMetric, iIconMetric, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
     58            pixIcon = vboxGlobal().vmGuestOSTypePixmapDefault(machine.GetOSTypeId()).scaled(iIconMetric, iIconMetric, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
    5959            strName = machine.GetName();
    6060            strUuid = machine.GetId();
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