QVariant UIGSelectorItemMachine::data(int iKey) const
{
    /* Provide other members with required data: */
    switch (iKey)
    {
        /* Layout hints: */
        case MachineItemData_MachineItemMargin: return 4;
        case MachineItemData_MachineItemMajorSpacing: return 10;
        case MachineItemData_MachineItemMinorSpacing: return 4;
        case MachineItemData_MachineItemTextSpacing: return 2;
        /* Fonts: */
        case MachineItemData_MachineNameFont:
        {
            QFont machineNameFont = qApp->font();
            machineNameFont.setPointSize(machineNameFont.pointSize() + 1);
            machineNameFont.setWeight(QFont::Bold);
            return machineNameFont;
        }
        case MachineItemData_SnapshotNameFont:
        {
            QFont snapshotStateFont = qApp->font();
            snapshotStateFont.setPointSize(snapshotStateFont.pointSize() + 1);
            return snapshotStateFont;
        }
        case MachineItemData_MachineStateTextFont:
        {
            QFont machineStateFont = qApp->font();
            machineStateFont.setPointSize(machineStateFont.pointSize() + 1);
            return machineStateFont;
        }
        /* Sizes: */
        case MachineItemData_MachinePixmapSize: return QSizeF(32, 32);
        case MachineItemData_MachineNameSize:
        {
            QFontMetrics fm(data(MachineItemData_MachineNameFont).value<QFont>());
            return QSize(fm.width(data(MachineItemData_MachineName).toString()), fm.height());
        }
        case MachineItemData_SnapshotNameSize:
        {
            QFontMetrics fm(data(MachineItemData_SnapshotNameFont).value<QFont>());
            return QSize(fm.width(QString("(%1)").arg(data(MachineItemData_SnapshotName).toString())), fm.height());
        }
        case MachineItemData_MachineStatePixmapSize: return QSizeF(16, 16);
        case MachineItemData_MachineStateTextSize:
        {
            QFontMetrics fm(data(MachineItemData_MachineStateTextFont).value<QFont>());
            return QSize(fm.width(data(MachineItemData_MachineStateText).toString()), fm.height());
        }
        /* Pixmaps: */
        case MachineItemData_MachinePixmap: return osIcon();
        case MachineItemData_MachineStatePixmap: return machineStateIcon();
        /* Texts: */
        case MachineItemData_MachineName: return name();
        case MachineItemData_SnapshotName: return snapshotName();
        case MachineItemData_MachineStateText: return gpConverter->toString(data(MachineItemData_MachineState).value<KMachineState>());
        /* Other values: */
        case MachineItemData_MachineId: return id();
        case MachineItemData_MachineOSTypeId: return osTypeId();
        case MachineItemData_MachineState: return QVariant::fromValue(machineState());
        /* Default: */
        default: break;
    }
    return QVariant();
}
QVariant UIGChooserItemMachine::data(int iKey) const
{
    /* Provide other members with required data: */
    switch (iKey)
    {
        /* Layout hints: */
        case MachineItemData_Margin: return 5;
        case MachineItemData_MajorSpacing: return 10;
        case MachineItemData_MinorSpacing: return 4;
        case MachineItemData_TextSpacing: return 0;

        /* Pixmaps: */
        case MachineItemData_Pixmap: return osIcon();
        case MachineItemData_StatePixmap: return machineStateIcon();
        case MachineItemData_SettingsButtonPixmap: return UIIconPool::iconSet(":/settings_16px.png");
        case MachineItemData_StartButtonPixmap: return UIIconPool::iconSet(":/start_16px.png");
        case MachineItemData_PauseButtonPixmap: return UIIconPool::iconSet(":/pause_16px.png");
        case MachineItemData_CloseButtonPixmap: return UIIconPool::iconSet(":/exit_16px.png");

        /* Fonts: */
        case MachineItemData_NameFont:
        {
            QFont machineNameFont = qApp->font();
            machineNameFont.setWeight(QFont::Bold);
            return machineNameFont;
        }
        case MachineItemData_SnapshotNameFont:
        {
            QFont snapshotStateFont = qApp->font();
            return snapshotStateFont;
        }
        case MachineItemData_StateTextFont:
        {
            QFont machineStateFont = qApp->font();
            return machineStateFont;
        }

        /* Texts: */
        case MachineItemData_Name:
        {
            return compressText(data(MachineItemData_NameFont).value<QFont>(), model()->paintDevice(),
                                name(), data(MachineItemData_MaximumNameWidth).toInt());
        }
        case MachineItemData_SnapshotName:
        {
            QPaintDevice *pPaintDevice = model()->paintDevice();
            int iBracketWidth = QFontMetrics(data(MachineItemData_SnapshotNameFont).value<QFont>(),
                                             pPaintDevice).width("()");
            QString strCompressedName = compressText(data(MachineItemData_SnapshotNameFont).value<QFont>(),
                                                     pPaintDevice, snapshotName(),
                                                     data(MachineItemData_MaximumSnapshotNameWidth).toInt() - iBracketWidth);
            return QString("(%1)").arg(strCompressedName);
        }
        case MachineItemData_StateText: return machineStateName();

        /* Sizes: */
        case MachineItemData_PixmapSize: return osIcon().availableSizes().at(0);
        case MachineItemData_StatePixmapSize: return machineStateIcon().availableSizes().at(0);

        case MachineItemData_NameSize:
        {
            QFontMetrics fm(data(MachineItemData_NameFont).value<QFont>(), model()->paintDevice());
            return QSize(fm.width(data(MachineItemData_Name).toString()) + 2, fm.height());
        }
        case MachineItemData_MinimumNameWidth:
        {
            QFont font = data(MachineItemData_NameFont).value<QFont>();
            QPaintDevice *pPaintDevice = model()->paintDevice();
            return QFontMetrics(font, pPaintDevice).width(compressText(font, pPaintDevice,
                                                                       name(), textWidth(font, pPaintDevice, 15)));
        }
        case MachineItemData_MaximumNameWidth:
        {
            return data(MachineItemData_FirstRowMaximumWidth).toInt() -
                   data(MachineItemData_MinimumSnapshotNameWidth).toInt();
        }

        case MachineItemData_SnapshotNameSize:
        {
            QFontMetrics fm(data(MachineItemData_SnapshotNameFont).value<QFont>(), model()->paintDevice());
            return QSize(fm.width(data(MachineItemData_SnapshotName).toString()) + 2, fm.height());
        }
        case MachineItemData_MinimumSnapshotNameWidth:
        {
            if (snapshotName().isEmpty())
                return 0;
            QFontMetrics fm(data(MachineItemData_SnapshotNameFont).value<QFont>(), model()->paintDevice());
            int iBracketWidth = fm.width("()");
            int iActualTextWidth = fm.width(snapshotName());
            int iMinimumTextWidth = fm.width("...");
            return iBracketWidth + qMin(iActualTextWidth, iMinimumTextWidth);
        }
        case MachineItemData_MaximumSnapshotNameWidth:
        {
            return data(MachineItemData_FirstRowMaximumWidth).toInt() -
                   data(MachineItemData_NameSize).toSize().width();
        }

        case MachineItemData_FirstRowMaximumWidth:
        {
            /* Prepare variables: */
            int iMargin = data(MachineItemData_Margin).toInt();
            int iPixmapWidth = data(MachineItemData_PixmapSize).toSize().width();
            int iMachineItemMajorSpacing = data(MachineItemData_MajorSpacing).toInt();
            int iMachineItemMinorSpacing = data(MachineItemData_MinorSpacing).toInt();
            int iToolBarWidth = data(MachineItemData_ToolBarSize).toSize().width();
            int iMaximumWidth = (int)geometry().width() - 2 * iMargin -
                                                          iPixmapWidth -
                                                          iMachineItemMajorSpacing;
            if (!snapshotName().isEmpty())
                iMaximumWidth -= iMachineItemMinorSpacing;
            if (m_pToolBar)
                iMaximumWidth -= (iToolBarWidth + iMachineItemMajorSpacing);
            return iMaximumWidth;
        }
        case MachineItemData_StateTextSize:
        {
            QFontMetrics fm(data(MachineItemData_StateTextFont).value<QFont>(), model()->paintDevice());
            return QSize(fm.width(data(MachineItemData_StateText).toString()) + 2, fm.height());
        }
        case MachineItemData_ToolBarSize:
        {
            return m_pToolBar ? m_pToolBar->minimumSizeHint().toSize() : QSize(0, 0);
        }
        /* Default: */
        default: break;
    }
    return QVariant();
}