VirtualBox

Changeset 30062 in vbox for trunk


Ignore:
Timestamp:
Jun 7, 2010 9:41:33 AM (15 years ago)
Author:
vboxsync
Message:

FE/Qt4: use the application global pixmap cache

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

Legend:

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

    r30022 r30062  
    2929#include <QFileInfo>
    3030#include <QLinearGradient>
     31#include <QPixmapCache>
    3132
    3233#if defined (Q_WS_MAC)
     
    581582            break;
    582583        }
     584        case OSTypeIdRole:
     585        {
     586            v = m_VMItemList.at(aIndex.row())->osTypeId();
     587            break;
     588        }
    583589        case UIVMItemPtrRole:
    584590        {
    585591            v = qVariantFromValue(m_VMItemList.at(aIndex.row()));
     592            break;
    586593        }
    587594    }
     
    743750
    744751QSize UIVMItemPainter::sizeHint(const QStyleOptionViewItem &aOption,
    745                                    const QModelIndex &aIndex) const
     752                                const QModelIndex &aIndex) const
    746753{
    747754    /* Get the size of every item */
     
    759766}
    760767
    761 void UIVMItemPainter::paint(QPainter *aPainter, const QStyleOptionViewItem &aOption,
    762                                const QModelIndex &aIndex) const
    763 {
    764     QStyleOptionViewItem option(aOption);
    765     /* Highlight background if an item is selected in any case.
    766      * (Fix for selector in the windows style.) */
    767     option.showDecorationSelected = true;
    768 
    769     /* Start drawing with the background */
    770     drawBackground(aPainter, option, aIndex);
    771 
    772     /* Blend the content */
    773     blendContent(aPainter, option, aIndex);
    774 
    775     /* Draw a focus rectangle when necessary */
    776     drawFocus(aPainter, option, option.rect);
     768void UIVMItemPainter::paint(QPainter *pPainter, const QStyleOptionViewItem &option,
     769                            const QModelIndex &index) const
     770{
     771    /* Generate the key used in the pixmap cache. Needs to be composed with all
     772     * values which might be changed. */
     773    QString key = QString("vbox:%1:%2:%3:%4:%5:%6")
     774        .arg(index.data(Qt::DisplayRole).toString())
     775        .arg(index.data(UIVMItemModel::OSTypeIdRole).toString())
     776        .arg(index.data(UIVMItemModel::SnapShotDisplayRole).toString())
     777        .arg(index.data(UIVMItemModel::SessionStateDisplayRole).toString())
     778        .arg(option.state)
     779        .arg(option.rect.width());
     780
     781    /* Check if the pixmap already exists in the cache. */
     782    QPixmap pixmap;
     783    if (!QPixmapCache::find(key, pixmap))
     784    {
     785        /* If not, generate a new one */
     786        QStyleOptionViewItem tmpOption(option);
     787        /* Highlight background if an item is selected in any case.
     788         * (Fix for selector in the windows style.) */
     789        tmpOption.showDecorationSelected = true;
     790
     791        /* Create a temporary pixmap and painter to work on.*/
     792        QPixmap tmpPixmap(option.rect.size());
     793        tmpPixmap.fill(Qt::transparent);
     794        QPainter tmpPainter(&tmpPixmap);
     795
     796        /* Normally we operate on a painter which is in the size of the list
     797         * view widget. Here we process one item only, so shift all the stuff
     798         * out of the view. It will be translated back in the following
     799         * methods. */
     800        tmpPainter.translate(-option.rect.x(), -option.rect.y());
     801
     802        /* Start drawing with the background */
     803        drawBackground(&tmpPainter, tmpOption, index);
     804
     805        /* Blend the content */
     806        blendContent(&tmpPainter, tmpOption, index);
     807
     808        /* Draw a focus rectangle when necessary */
     809        drawFocus(&tmpPainter, tmpOption, tmpOption.rect);
     810
     811        /* Finish drawing */
     812        tmpPainter.end();
     813
     814        pixmap = tmpPixmap;
     815        /* Fill the  cache */
     816        QPixmapCache::insert(key, tmpPixmap);
     817    }
     818    pPainter->drawPixmap(option.rect, pixmap);
    777819}
    778820
  • trunk/src/VBox/Frontends/VirtualBox/src/UIVMListView.h

    r30022 r30062  
    4040    QString name() const { return m_strName; }
    4141    QIcon osIcon() const { return m_fAccessible ? vboxGlobal().vmGuestOSTypeIcon(m_strOSTypeId) : QPixmap(":/os_other.png"); }
     42    QString osTypeId() const { return m_strOSTypeId; }
    4243    QString id() const { return m_strId; }
    4344
     
    9697           SessionStateDecorationRole,
    9798           SessionStateFontRole,
     99           OSTypeIdRole,
    98100           UIVMItemPtrRole };
    99101
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