VirtualBox

Changeset 66662 in vbox for trunk/src/VBox/Frontends


Ignore:
Timestamp:
Apr 24, 2017 5:55:47 PM (8 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
115035
Message:

FE/Qt: bugref:6911: Support for new-style user machine icon configuration.

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

Legend:

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

    r66657 r66662  
    2222/* Qt includes: */
    2323# include <QApplication>
     24# include <QFile>
    2425# include <QStyle>
    2526# include <QWidget>
     
    2728/* GUI includes: */
    2829# include "UIIconPool.h"
     30# include "UIExtraDataManager.h"
     31
     32/* COM includes: */
     33# include "COMEnums.h"
     34# include "CMachine.h"
    2935
    3036/* Other VBox includes: */
     
    355361}
    356362
     363QIcon UIIconPoolGeneral::userMachineIcon(const CMachine &comMachine) const
     364{
     365    /* Get machine ID: */
     366    const QString strMachineId = comMachine.GetId();
     367    AssertReturn(comMachine.isOk(), QPixmap());
     368
     369    /* Prepare icon: */
     370    QIcon icon;
     371
     372    /* 1. First, load icon from IMachine extra-data: */
     373    if (icon.isNull())
     374        foreach (const QString &strIconName, gEDataManager->machineWindowIconNames(strMachineId))
     375            if (!strIconName.isEmpty() && QFile::exists(strIconName))
     376                icon.addFile(strIconName);
     377
     378    /* 2. Otherwise, load icon from IMachine interface itself: */
     379    if (icon.isNull())
     380    {
     381        const QVector<BYTE> byteVector = comMachine.GetIcon();
     382        AssertReturn(comMachine.isOk(), QPixmap());
     383        const QByteArray byteArray = QByteArray::fromRawData(reinterpret_cast<const char*>(byteVector.constData()), byteVector.size());
     384        const QImage image = QImage::fromData(byteArray);
     385        if (!image.isNull())
     386        {
     387            QPixmap pixmap = QPixmap::fromImage(image);
     388            const int iMinimumLength = qMin(pixmap.width(), pixmap.height());
     389            if (pixmap.width() != iMinimumLength || pixmap.height() != iMinimumLength)
     390                pixmap = pixmap.scaled(QSize(iMinimumLength, iMinimumLength), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
     391            icon.addPixmap(pixmap);
     392        }
     393    }
     394
     395    /* Return icon: */
     396    return icon;
     397}
     398
     399QPixmap UIIconPoolGeneral::userMachinePixmap(const CMachine &comMachine, const QSize &size) const
     400{
     401    /* Acquire icon: */
     402    const QIcon icon = userMachineIcon(comMachine);
     403
     404    /* Prepare pixmap: */
     405    QPixmap pixmap;
     406
     407    /* Check whether we have valid icon: */
     408    if (!icon.isNull())
     409    {
     410        /* Get pixmap of requested size: */
     411        pixmap = icon.pixmap(size);
     412        /* And even scale it if size is not valid: */
     413        if (pixmap.size() != size)
     414            pixmap = pixmap.scaled(size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
     415    }
     416
     417    /* Return pixmap: */
     418    return pixmap;
     419}
     420
     421QPixmap UIIconPoolGeneral::userMachinePixmapDefault(const CMachine &comMachine, QSize *pLogicalSize /* = 0 */) const
     422{
     423    /* Acquire icon: */
     424    const QIcon icon = userMachineIcon(comMachine);
     425
     426    /* Prepare pixmap: */
     427    QPixmap pixmap;
     428
     429    /* Check whether we have valid icon: */
     430    if (!icon.isNull())
     431    {
     432        /* Determine desired icon size: */
     433        const int iIconMetric = QApplication::style()->pixelMetric(QStyle::PM_LargeIconSize);
     434        const QSize iconSize = QSize(iIconMetric, iIconMetric);
     435
     436        /* Pass up logical size if necessary: */
     437        if (pLogicalSize)
     438            *pLogicalSize = iconSize;
     439
     440        /* Get pixmap of requested size: */
     441        pixmap = icon.pixmap(iconSize);
     442    }
     443
     444    /* Return pixmap: */
     445    return pixmap;
     446}
     447
    357448QIcon UIIconPoolGeneral::guestOSTypeIcon(const QString &strOSTypeID) const
    358449{
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIIconPool.h

    r66657 r66662  
    2323#include <QPixmap>
    2424#include <QHash>
     25
     26/* Forward declarations: */
     27class CMachine;
    2528
    2629
     
    104107    UIIconPoolGeneral();
    105108
     109    /** Returns icon defined for a passed @a comMachine. */
     110    QIcon userMachineIcon(const CMachine &comMachine) const;
     111    /** Returns pixmap of a passed @a size defined for a passed @a comMachine. */
     112    QPixmap userMachinePixmap(const CMachine &comMachine, const QSize &size) const;
     113    /** Returns pixmap defined for a passed @a comMachine.
     114      * In case if non-null @a pLogicalSize pointer provided, it will be updated properly. */
     115    QPixmap userMachinePixmapDefault(const CMachine &comMachine, QSize *pLogicalSize = 0) const;
     116
    106117    /** Returns icon corresponding to passed @a strOSTypeID. */
    107118    QIcon guestOSTypeIcon(const QString &strOSTypeID) const;
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.cpp

    r66657 r66662  
    558558}
    559559
     560QIcon VBoxGlobal::vmUserIcon(const CMachine &comMachine) 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->userMachineIcon(comMachine);
     570}
     571
     572QPixmap VBoxGlobal::vmUserPixmap(const CMachine &comMachine, const QSize &size) const
     573{
     574    /* Prepare fallback pixmap: */
     575    static QPixmap nullPixmap;
     576
     577    /* Make sure general icon-pool initialized: */
     578    AssertReturn(m_pIconPool, nullPixmap);
     579
     580    /* Redirect to general icon-pool: */
     581    return m_pIconPool->userMachinePixmap(comMachine, size);
     582}
     583
     584QPixmap VBoxGlobal::vmUserPixmapDefault(const CMachine &comMachine, QSize *pLogicalSize /* = 0 */) 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->userMachinePixmapDefault(comMachine, pLogicalSize);
     594}
     595
    560596QIcon VBoxGlobal::vmGuestOSTypeIcon(const QString &strOSTypeID) const
    561597{
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.h

    r66657 r66662  
    221221    QList <CGuestOSType> vmGuestOSFamilyList() const;
    222222    QList <CGuestOSType> vmGuestOSTypeList (const QString &aFamilyId) const;
     223
     224    /** Returns icon defined for a passed @a comMachine. */
     225    QIcon vmUserIcon(const CMachine &comMachine) const;
     226    /** Returns pixmap of a passed @a size defined for a passed @a comMachine. */
     227    QPixmap vmUserPixmap(const CMachine &comMachine, const QSize &size) const;
     228    /** Returns pixmap defined for a passed @a comMachine.
     229      * In case if non-null @a pLogicalSize pointer provided, it will be updated properly. */
     230    QPixmap vmUserPixmapDefault(const CMachine &comMachine, QSize *pLogicalSize = 0) const;
    223231
    224232    /** Returns pixmap corresponding to passed @a strOSTypeID. */
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.cpp

    r66660 r66662  
    12771277
    12781278    /* Now the dock icon preview: */
    1279     const QPixmap pixmap = vboxGlobal().vmGuestOSTypePixmap(guest().GetOSTypeId(), QSize(42, 42));
     1279    QPixmap pixmap = vboxGlobal().vmUserPixmap(machine(), QSize(42, 42));
     1280    if (pixmap.isNull())
     1281        pixmap = vboxGlobal().vmGuestOSTypePixmap(guest().GetOSTypeId(), QSize(42, 42));
    12801282    m_pDockIconPreview = new UIDockIconPreview(uisession(), pixmap);
    12811283
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.cpp

    r66661 r66662  
    12891289        /* Prepare machine-window icon: */
    12901290        {
    1291             QIcon icon;
    1292             /* Load user machine-window icon: */
    1293             foreach (const QString &strIconName, gEDataManager->machineWindowIconNames(strMachineID))
    1294                 if (!strIconName.isEmpty() && QFile::exists(strIconName))
    1295                     icon.addFile(strIconName);
     1291            /* Acquire user machine-window icon: */
     1292            QIcon icon = vboxGlobal().vmUserIcon(machine());
    12961293            /* Use the OS type icon if user one was not set: */
    12971294            if (icon.isNull())
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/UISnapshotPane.cpp

    r66657 r66662  
    903903
    904904            // TODO: Assign corresponding icon through sub-dialog API: */
    905             const QPixmap pixmap = vboxGlobal().vmGuestOSTypePixmapDefault(m_comMachine.GetOSTypeId());
     905            QPixmap pixmap = vboxGlobal().vmUserPixmapDefault(m_comMachine);
     906            if (pixmap.isNull())
     907                pixmap = vboxGlobal().vmGuestOSTypePixmapDefault(m_comMachine.GetOSTypeId());
    906908            pDlg->mLbIcon->setPixmap(pixmap);
    907909
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/UIVMItem.cpp

    r66659 r66662  
    237237        m_cSnaphot = m_machine.GetSnapshotCount();
    238238
    239         m_pixmap = vboxGlobal().vmGuestOSTypePixmapDefault(m_strOSTypeId, &m_logicalPixmapSize);
     239        m_pixmap = vboxGlobal().vmUserPixmapDefault(m_machine, &m_logicalPixmapSize);
     240        if (m_pixmap.isNull())
     241            m_pixmap = vboxGlobal().vmGuestOSTypePixmapDefault(m_strOSTypeId, &m_logicalPixmapSize);
    240242
    241243        if (   m_machineState == KMachineState_PoweredOff
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/exportappliance/UIWizardExportAppPageBasic1.cpp

    r66658 r66662  
    5656        if (machine.GetAccessible())
    5757        {
    58             pixIcon = vboxGlobal().vmGuestOSTypePixmapDefault(machine.GetOSTypeId());
     58            pixIcon = vboxGlobal().vmUserPixmapDefault(machine);
     59            if (pixIcon.isNull())
     60                pixIcon = vboxGlobal().vmGuestOSTypePixmapDefault(machine.GetOSTypeId());
    5961            strName = machine.GetName();
    6062            strUuid = machine.GetId();
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