Index: trunk/src/VBox/Frontends/VirtualBox/src/manager/details/UIMachinePreview.cpp
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/manager/details/UIMachinePreview.cpp	(revision 79859)
+++ trunk/src/VBox/Frontends/VirtualBox/src/manager/details/UIMachinePreview.cpp	(revision 79860)
@@ -46,97 +46,16 @@
     , m_dRatio((double)QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize) / 16)
     , m_iMargin(0)
-    , m_preset(AspectRatioPreset_16x9)
+    , m_enmPreset(AspectRatioPreset_16x9)
     , m_pPreviewImg(0)
 {
-    /* Create session instance: */
-    m_session.createInstance(CLSID_Session);
-
-    /* Cache aspect-ratio preset settings: */
-    const QIcon empty16x10 = UIIconPool::iconSet(":/preview_empty_16to10_242x167px.png");
-    const QIcon empty16x9 = UIIconPool::iconSet(":/preview_empty_16to9_242x155px.png");
-    const QIcon empty4x3 = UIIconPool::iconSet(":/preview_empty_4to3_242x192px.png");
-    const QIcon full16x10 = UIIconPool::iconSet(":/preview_full_16to10_242x167px.png");
-    const QIcon full16x9 = UIIconPool::iconSet(":/preview_full_16to9_242x155px.png");
-    const QIcon full4x3 = UIIconPool::iconSet(":/preview_full_4to3_242x192px.png");
-
-    // WORKAROUND:
-    // Since we don't have x3 and x4 HiDPI icons yet,
-    // and we hadn't enabled automatic up-scaling for now,
-    // we have to make sure m_dRatio is within possible bounds.
-    const QList<QSize> sizes = empty16x10.availableSizes();
-    if (sizes.size() >= 2)
-        m_dRatio = qMin(m_dRatio, (double)sizes.last().width() / sizes.first().width());
-
-    m_sizes.insert(AspectRatioPreset_16x10, QSize(242 * m_dRatio, 167 * m_dRatio));
-    m_sizes.insert(AspectRatioPreset_16x9, QSize(242 * m_dRatio, 155 * m_dRatio));
-    m_sizes.insert(AspectRatioPreset_4x3, QSize(242 * m_dRatio, 192 * m_dRatio));
-    m_ratios.insert(AspectRatioPreset_16x10, (double)16/10);
-    m_ratios.insert(AspectRatioPreset_16x9, (double)16/9);
-    m_ratios.insert(AspectRatioPreset_4x3, (double)4/3);
-    m_emptyPixmaps.insert(AspectRatioPreset_16x10, new QPixmap(empty16x10.pixmap(m_sizes.value(AspectRatioPreset_16x10))));
-    m_emptyPixmaps.insert(AspectRatioPreset_16x9, new QPixmap(empty16x9.pixmap(m_sizes.value(AspectRatioPreset_16x9))));
-    m_emptyPixmaps.insert(AspectRatioPreset_4x3, new QPixmap(empty4x3.pixmap(m_sizes.value(AspectRatioPreset_4x3))));
-    m_fullPixmaps.insert(AspectRatioPreset_16x10, new QPixmap(full16x10.pixmap(m_sizes.value(AspectRatioPreset_16x10))));
-    m_fullPixmaps.insert(AspectRatioPreset_16x9, new QPixmap(full16x9.pixmap(m_sizes.value(AspectRatioPreset_16x9))));
-    m_fullPixmaps.insert(AspectRatioPreset_4x3, new QPixmap(full4x3.pixmap(m_sizes.value(AspectRatioPreset_4x3))));
-
-    /* Setup contents (depends on presets above!): */
-    setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
-
-    /* Create the context menu: */
-    m_pUpdateTimerMenu = new QMenu;
-    QActionGroup *pUpdateTimeG = new QActionGroup(this);
-    pUpdateTimeG->setExclusive(true);
-    for(int i = 0; i < PreviewUpdateIntervalType_Max; ++i)
-    {
-        QAction *pUpdateTime = new QAction(pUpdateTimeG);
-        pUpdateTime->setData(i);
-        pUpdateTime->setCheckable(true);
-        pUpdateTimeG->addAction(pUpdateTime);
-        m_pUpdateTimerMenu->addAction(pUpdateTime);
-        m_actions[static_cast<PreviewUpdateIntervalType>(i)] = pUpdateTime;
-    }
-    m_pUpdateTimerMenu->insertSeparator(m_actions[static_cast<PreviewUpdateIntervalType>(PreviewUpdateIntervalType_500ms)]);
-
-    /* Initialize with the new update interval: */
-    setUpdateInterval(gEDataManager->selectorWindowPreviewUpdateInterval(), false);
-
-    /* Setup connections: */
-    connect(m_pUpdateTimer, SIGNAL(timeout()), this, SLOT(sltRecreatePreview()));
-    connect(gVBoxEvents, SIGNAL(sigMachineStateChange(QUuid, KMachineState)),
-            this, SLOT(sltMachineStateChange(QUuid)));
-
-    /* Retranslate the UI */
-    retranslateUi();
+    prepare();
 }
 
 UIMachinePreview::~UIMachinePreview()
 {
-    /* Close any open session: */
-    if (m_session.GetState() == KSessionState_Locked)
-        m_session.UnlockMachine();
-
-    /* Destroy background images: */
-    foreach (const AspectRatioPreset &preset, m_emptyPixmaps.keys())
-    {
-        delete m_emptyPixmaps.value(preset);
-        m_emptyPixmaps.remove(preset);
-    }
-    foreach (const AspectRatioPreset &preset, m_fullPixmaps.keys())
-    {
-        delete m_fullPixmaps.value(preset);
-        m_fullPixmaps.remove(preset);
-    }
-
-    /* Destroy preview image: */
-    if (m_pPreviewImg)
-        delete m_pPreviewImg;
-
-    /* Destroy update timer: */
-    if (m_pUpdateTimerMenu)
-        delete m_pUpdateTimerMenu;
-}
-
-void UIMachinePreview::setMachine(const CMachine& machine)
+    cleanup();
+}
+
+void UIMachinePreview::setMachine(const CMachine& comMachine)
 {
     /* Pause: */
@@ -144,10 +63,10 @@
 
     /* Assign new machine: */
-    m_machine = machine;
+    m_comMachine = comMachine;
 
     /* Fetch machine data: */
     m_strPreviewName = tr("No preview");
-    if (!m_machine.isNull())
-        m_strPreviewName = m_machine.GetAccessible() ? m_machine.GetName() :
+    if (!m_comMachine.isNull())
+        m_strPreviewName = m_comMachine.GetAccessible() ? m_comMachine.GetName() :
                            QApplication::translate("UIVMListView", "Inaccessible");
 
@@ -158,5 +77,127 @@
 CMachine UIMachinePreview::machine() const
 {
-    return m_machine;
+    return m_comMachine;
+}
+
+void UIMachinePreview::retranslateUi()
+{
+    /* Translate actions: */
+    m_actions.value(PreviewUpdateIntervalType_Disabled)->setText(tr("Update disabled"));
+    m_actions.value(PreviewUpdateIntervalType_500ms)->setText(tr("Every 0.5 s"));
+    m_actions.value(PreviewUpdateIntervalType_1000ms)->setText(tr("Every 1 s"));
+    m_actions.value(PreviewUpdateIntervalType_2000ms)->setText(tr("Every 2 s"));
+    m_actions.value(PreviewUpdateIntervalType_5000ms)->setText(tr("Every 5 s"));
+    m_actions.value(PreviewUpdateIntervalType_10000ms)->setText(tr("Every 10 s"));
+}
+
+void UIMachinePreview::resizeEvent(QGraphicsSceneResizeEvent *pEvent)
+{
+    recalculatePreviewRectangle();
+    sltRecreatePreview();
+
+    /* Call to base-class: */
+    QIGraphicsWidget::resizeEvent(pEvent);
+}
+
+void UIMachinePreview::showEvent(QShowEvent *pEvent)
+{
+    restart();
+
+    /* Call to base-class: */
+    QIGraphicsWidget::showEvent(pEvent);
+}
+
+void UIMachinePreview::hideEvent(QHideEvent *pEvent)
+{
+    stop();
+
+    /* Call to base-class: */
+    QIGraphicsWidget::hideEvent(pEvent);
+}
+
+void UIMachinePreview::contextMenuEvent(QGraphicsSceneContextMenuEvent *pEvent)
+{
+    QAction *pReturn = m_pUpdateTimerMenu->exec(pEvent->screenPos(), 0);
+    if (pReturn)
+    {
+        PreviewUpdateIntervalType enmInterval = static_cast<PreviewUpdateIntervalType>(pReturn->data().toInt());
+        setUpdateInterval(enmInterval, true);
+        restart();
+    }
+}
+
+void UIMachinePreview::paint(QPainter *pPainter, const QStyleOptionGraphicsItem*, QWidget*)
+{
+    /* Where should the content go: */
+    QRect cr = contentsRect().toRect();
+    if (!cr.isValid())
+        return;
+
+    /* If there is a preview image available: */
+    if (m_pPreviewImg)
+    {
+        /* Draw empty monitor frame: */
+        pPainter->drawPixmap(cr.x() + m_iMargin, cr.y() + m_iMargin, *m_emptyPixmaps.value(m_enmPreset));
+
+        /* Move image to viewport center: */
+        QRect imageRect(QPoint(0, 0), m_pPreviewImg->size());
+        imageRect.moveCenter(m_vRect.center());
+
+#ifdef VBOX_WS_MAC
+        /* Set composition-mode to opaque: */
+        pPainter->setCompositionMode(QPainter::CompositionMode_Source);
+        /* Replace translucent background with black one: */
+        pPainter->fillRect(imageRect, QColor(Qt::black));
+        /* Return default composition-mode back: */
+        pPainter->setCompositionMode(QPainter::CompositionMode_SourceAtop);
+#endif /* VBOX_WS_MAC */
+
+        /* Draw preview image: */
+        pPainter->drawImage(imageRect.topLeft(), *m_pPreviewImg);
+    }
+    else
+    {
+        /* Draw full monitor frame: */
+        pPainter->drawPixmap(cr.x() + m_iMargin, cr.y() + m_iMargin, *m_fullPixmaps.value(m_enmPreset));
+
+        /* Paint preview name: */
+        QFont font = pPainter->font();
+        font.setBold(true);
+        int fFlags = Qt::AlignCenter | Qt::TextWordWrap;
+        float h = m_vRect.size().height() * .2;
+        QRect r;
+        /* Make a little magic to find out if the given text fits into our rectangle.
+         * Decrease the font pixel size as long as it doesn't fit. */
+        int cMax = 30;
+        do
+        {
+            h = h * .8;
+            font.setPixelSize((int)h);
+            pPainter->setFont(font);
+            r = pPainter->boundingRect(m_vRect, fFlags, m_strPreviewName);
+        }
+        while ((r.height() > m_vRect.height() || r.width() > m_vRect.width()) && cMax-- != 0);
+        pPainter->setPen(Qt::white);
+        pPainter->drawText(m_vRect, fFlags, m_strPreviewName);
+    }
+}
+
+QSizeF UIMachinePreview::sizeHint(Qt::SizeHint enmWhich, const QSizeF &constraint /* = QSizeF() */) const
+{
+    if (enmWhich == Qt::MinimumSize)
+    {
+        AssertReturn(m_emptyPixmaps.contains(m_enmPreset),
+                     QIGraphicsWidget::sizeHint(enmWhich, constraint));
+        QSize size = m_sizes.value(m_enmPreset);
+        if (m_iMargin != 0)
+        {
+            size.setWidth(size.width() - 2 * m_iMargin);
+            size.setHeight(size.height() - 2 * m_iMargin);
+        }
+        return size;
+    }
+
+    /* Call to base-class: */
+    return QIGraphicsWidget::sizeHint(enmWhich, constraint);
 }
 
@@ -164,5 +205,5 @@
 {
     /* Make sure its the event for our machine: */
-    if (m_machine.isNull() || m_machine.GetId() != uId)
+    if (m_comMachine.isNull() || m_comMachine.GetId() != uId)
         return;
 
@@ -185,8 +226,8 @@
 
     /* Fetch actual machine-state: */
-    const KMachineState machineState = m_machine.isNull() ? KMachineState_Null : m_machine.GetState();
+    const KMachineState enmMachineState = m_comMachine.isNull() ? KMachineState_Null : m_comMachine.GetState();
 
     /* We are creating preview only for assigned and accessible VMs: */
-    if (!m_machine.isNull() && machineState != KMachineState_Null &&
+    if (!m_comMachine.isNull() && enmMachineState != KMachineState_Null &&
         m_vRect.width() > 0 && m_vRect.height() > 0)
     {
@@ -195,5 +236,5 @@
 
         /* Use 10x9 as the aspect-ratio preset by default: */
-        AspectRatioPreset preset = AspectRatioPreset_16x9;
+        AspectRatioPreset enmPreset = AspectRatioPreset_16x9;
 
         /* Preview update enabled? */
@@ -201,5 +242,5 @@
         {
             /* Depending on machine state: */
-            switch (machineState)
+            switch (enmMachineState)
             {
                 /* If machine is in SAVED/RESTORING state: */
@@ -209,8 +250,8 @@
                     /* Use the screenshot from saved-state if possible: */
                     ULONG uGuestWidth = 0, uGuestHeight = 0;
-                    QVector<BYTE> screenData = m_machine.ReadSavedScreenshotToArray(0, KBitmapFormat_PNG, uGuestWidth, uGuestHeight);
+                    QVector<BYTE> screenData = m_comMachine.ReadSavedScreenshotToArray(0, KBitmapFormat_PNG, uGuestWidth, uGuestHeight);
 
                     /* Make sure screen-data is OK: */
-                    if (!m_machine.isOk() || screenData.isEmpty())
+                    if (!m_comMachine.isOk() || screenData.isEmpty())
                         break;
 
@@ -220,5 +261,5 @@
                         const double dAspectRatio = (double)uGuestWidth / uGuestHeight;
                         /* Look for the best aspect-ratio preset: */
-                        preset = bestAspectRatioPreset(dAspectRatio, m_ratios);
+                        enmPreset = bestAspectRatioPreset(dAspectRatio, m_ratios);
                     }
 
@@ -239,10 +280,10 @@
                 {
                     /* Make sure session state is Locked: */
-                    if (m_session.GetState() != KSessionState_Locked)
+                    if (m_comSession.GetState() != KSessionState_Locked)
                         break;
 
                     /* Make sure console is OK: */
-                    CConsole console = m_session.GetConsole();
-                    if (!m_session.isOk() || console.isNull())
+                    CConsole console = m_comSession.GetConsole();
+                    if (!m_comSession.isOk() || console.isNull())
                         break;
                     /* Make sure display is OK: */
@@ -261,5 +302,5 @@
                         const double dAspectRatio = (double)uGuestWidth / uGuestHeight;
                         /* Look for the best aspect-ratio preset: */
-                        preset = bestAspectRatioPreset(dAspectRatio, m_ratios);
+                        enmPreset = bestAspectRatioPreset(dAspectRatio, m_ratios);
                     }
 
@@ -289,5 +330,5 @@
                     image.detach();
                     /* Dim image to give it required look for PAUSED state: */
-                    if (machineState == KMachineState_Paused)
+                    if (enmMachineState == KMachineState_Paused)
                         dimImage(image);
                     break;
@@ -308,8 +349,8 @@
 
         /* If preset changed: */
-        if (m_preset != preset)
+        if (m_enmPreset != enmPreset)
         {
             /* Save new preset: */
-            m_preset = preset;
+            m_enmPreset = enmPreset;
             /* And update geometry: */
             updateGeometry();
@@ -322,115 +363,93 @@
 }
 
-void UIMachinePreview::resizeEvent(QGraphicsSceneResizeEvent *pEvent)
-{
-    recalculatePreviewRectangle();
-    sltRecreatePreview();
-    QIGraphicsWidget::resizeEvent(pEvent);
-}
-
-void UIMachinePreview::showEvent(QShowEvent *pEvent)
-{
-    restart();
-    QIGraphicsWidget::showEvent(pEvent);
-}
-
-void UIMachinePreview::hideEvent(QHideEvent *pEvent)
-{
-    stop();
-    QIGraphicsWidget::hideEvent(pEvent);
-}
-
-void UIMachinePreview::contextMenuEvent(QGraphicsSceneContextMenuEvent *pEvent)
-{
-    QAction *pReturn = m_pUpdateTimerMenu->exec(pEvent->screenPos(), 0);
-    if (pReturn)
-    {
-        PreviewUpdateIntervalType interval = static_cast<PreviewUpdateIntervalType>(pReturn->data().toInt());
-        setUpdateInterval(interval, true);
-        restart();
-    }
-}
-
-void UIMachinePreview::retranslateUi()
-{
-    m_actions.value(PreviewUpdateIntervalType_Disabled)->setText(tr("Update disabled"));
-    m_actions.value(PreviewUpdateIntervalType_500ms)->setText(tr("Every 0.5 s"));
-    m_actions.value(PreviewUpdateIntervalType_1000ms)->setText(tr("Every 1 s"));
-    m_actions.value(PreviewUpdateIntervalType_2000ms)->setText(tr("Every 2 s"));
-    m_actions.value(PreviewUpdateIntervalType_5000ms)->setText(tr("Every 5 s"));
-    m_actions.value(PreviewUpdateIntervalType_10000ms)->setText(tr("Every 10 s"));
-}
-
-QSizeF UIMachinePreview::sizeHint(Qt::SizeHint which, const QSizeF &constraint /* = QSizeF() */) const
-{
-    if (which == Qt::MinimumSize)
-    {
-        AssertReturn(m_emptyPixmaps.contains(m_preset),
-                     QIGraphicsWidget::sizeHint(which, constraint));
-        QSize size = m_sizes.value(m_preset);
-        if (m_iMargin != 0)
-        {
-            size.setWidth(size.width() - 2 * m_iMargin);
-            size.setHeight(size.height() - 2 * m_iMargin);
-        }
-        return size;
-    }
-    return QIGraphicsWidget::sizeHint(which, constraint);
-}
-
-void UIMachinePreview::paint(QPainter *pPainter, const QStyleOptionGraphicsItem*, QWidget*)
-{
-    /* Where should the content go: */
-    QRect cr = contentsRect().toRect();
-    if (!cr.isValid())
-        return;
-
-    /* If there is a preview image available: */
+void UIMachinePreview::prepare()
+{
+    /* Create session instance: */
+    m_comSession.createInstance(CLSID_Session);
+
+    /* Cache aspect-ratio preset settings: */
+    const QIcon empty16x10 = UIIconPool::iconSet(":/preview_empty_16to10_242x167px.png");
+    const QIcon empty16x9 = UIIconPool::iconSet(":/preview_empty_16to9_242x155px.png");
+    const QIcon empty4x3 = UIIconPool::iconSet(":/preview_empty_4to3_242x192px.png");
+    const QIcon full16x10 = UIIconPool::iconSet(":/preview_full_16to10_242x167px.png");
+    const QIcon full16x9 = UIIconPool::iconSet(":/preview_full_16to9_242x155px.png");
+    const QIcon full4x3 = UIIconPool::iconSet(":/preview_full_4to3_242x192px.png");
+
+    // WORKAROUND:
+    // Since we don't have x3 and x4 HiDPI icons yet,
+    // and we hadn't enabled automatic up-scaling for now,
+    // we have to make sure m_dRatio is within possible bounds.
+    const QList<QSize> sizes = empty16x10.availableSizes();
+    if (sizes.size() >= 2)
+        m_dRatio = qMin(m_dRatio, (double)sizes.last().width() / sizes.first().width());
+
+    m_sizes.insert(AspectRatioPreset_16x10, QSize(242 * m_dRatio, 167 * m_dRatio));
+    m_sizes.insert(AspectRatioPreset_16x9, QSize(242 * m_dRatio, 155 * m_dRatio));
+    m_sizes.insert(AspectRatioPreset_4x3, QSize(242 * m_dRatio, 192 * m_dRatio));
+    m_ratios.insert(AspectRatioPreset_16x10, (double)16/10);
+    m_ratios.insert(AspectRatioPreset_16x9, (double)16/9);
+    m_ratios.insert(AspectRatioPreset_4x3, (double)4/3);
+    m_emptyPixmaps.insert(AspectRatioPreset_16x10, new QPixmap(empty16x10.pixmap(m_sizes.value(AspectRatioPreset_16x10))));
+    m_emptyPixmaps.insert(AspectRatioPreset_16x9, new QPixmap(empty16x9.pixmap(m_sizes.value(AspectRatioPreset_16x9))));
+    m_emptyPixmaps.insert(AspectRatioPreset_4x3, new QPixmap(empty4x3.pixmap(m_sizes.value(AspectRatioPreset_4x3))));
+    m_fullPixmaps.insert(AspectRatioPreset_16x10, new QPixmap(full16x10.pixmap(m_sizes.value(AspectRatioPreset_16x10))));
+    m_fullPixmaps.insert(AspectRatioPreset_16x9, new QPixmap(full16x9.pixmap(m_sizes.value(AspectRatioPreset_16x9))));
+    m_fullPixmaps.insert(AspectRatioPreset_4x3, new QPixmap(full4x3.pixmap(m_sizes.value(AspectRatioPreset_4x3))));
+
+    /* Setup contents (depends on presets above!): */
+    setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
+
+    /* Create the context menu: */
+    m_pUpdateTimerMenu = new QMenu;
+    QActionGroup *pUpdateTimeG = new QActionGroup(this);
+    pUpdateTimeG->setExclusive(true);
+    for(int i = 0; i < PreviewUpdateIntervalType_Max; ++i)
+    {
+        QAction *pUpdateTime = new QAction(pUpdateTimeG);
+        pUpdateTime->setData(i);
+        pUpdateTime->setCheckable(true);
+        pUpdateTimeG->addAction(pUpdateTime);
+        m_pUpdateTimerMenu->addAction(pUpdateTime);
+        m_actions[static_cast<PreviewUpdateIntervalType>(i)] = pUpdateTime;
+    }
+    m_pUpdateTimerMenu->insertSeparator(m_actions[static_cast<PreviewUpdateIntervalType>(PreviewUpdateIntervalType_500ms)]);
+
+    /* Initialize with the new update interval: */
+    setUpdateInterval(gEDataManager->selectorWindowPreviewUpdateInterval(), false);
+
+    /* Setup connections: */
+    connect(m_pUpdateTimer, SIGNAL(timeout()), this, SLOT(sltRecreatePreview()));
+    connect(gVBoxEvents, SIGNAL(sigMachineStateChange(QUuid, KMachineState)),
+            this, SLOT(sltMachineStateChange(QUuid)));
+
+    /* Retranslate the UI */
+    retranslateUi();
+}
+
+void UIMachinePreview::cleanup()
+{
+    /* Close any open session: */
+    if (m_comSession.GetState() == KSessionState_Locked)
+        m_comSession.UnlockMachine();
+
+    /* Destroy background images: */
+    foreach (const AspectRatioPreset &enmPreset, m_emptyPixmaps.keys())
+    {
+        delete m_emptyPixmaps.value(enmPreset);
+        m_emptyPixmaps.remove(enmPreset);
+    }
+    foreach (const AspectRatioPreset &enmPreset, m_fullPixmaps.keys())
+    {
+        delete m_fullPixmaps.value(enmPreset);
+        m_fullPixmaps.remove(enmPreset);
+    }
+
+    /* Destroy preview image: */
     if (m_pPreviewImg)
-    {
-        /* Draw empty monitor frame: */
-        pPainter->drawPixmap(cr.x() + m_iMargin, cr.y() + m_iMargin, *m_emptyPixmaps.value(m_preset));
-
-        /* Move image to viewport center: */
-        QRect imageRect(QPoint(0, 0), m_pPreviewImg->size());
-        imageRect.moveCenter(m_vRect.center());
-
-#ifdef VBOX_WS_MAC
-        /* Set composition-mode to opaque: */
-        pPainter->setCompositionMode(QPainter::CompositionMode_Source);
-        /* Replace translucent background with black one: */
-        pPainter->fillRect(imageRect, QColor(Qt::black));
-        /* Return default composition-mode back: */
-        pPainter->setCompositionMode(QPainter::CompositionMode_SourceAtop);
-#endif /* VBOX_WS_MAC */
-
-        /* Draw preview image: */
-        pPainter->drawImage(imageRect.topLeft(), *m_pPreviewImg);
-    }
-    else
-    {
-        /* Draw full monitor frame: */
-        pPainter->drawPixmap(cr.x() + m_iMargin, cr.y() + m_iMargin, *m_fullPixmaps.value(m_preset));
-
-        /* Paint preview name: */
-        QFont font = pPainter->font();
-        font.setBold(true);
-        int fFlags = Qt::AlignCenter | Qt::TextWordWrap;
-        float h = m_vRect.size().height() * .2;
-        QRect r;
-        /* Make a little magic to find out if the given text fits into our rectangle.
-         * Decrease the font pixel size as long as it doesn't fit. */
-        int cMax = 30;
-        do
-        {
-            h = h * .8;
-            font.setPixelSize((int)h);
-            pPainter->setFont(font);
-            r = pPainter->boundingRect(m_vRect, fFlags, m_strPreviewName);
-        }
-        while ((r.height() > m_vRect.height() || r.width() > m_vRect.width()) && cMax-- != 0);
-        pPainter->setPen(Qt::white);
-        pPainter->drawText(m_vRect, fFlags, m_strPreviewName);
-    }
+        delete m_pPreviewImg;
+
+    /* Destroy update timer: */
+    if (m_pUpdateTimerMenu)
+        delete m_pUpdateTimerMenu;
 }
 
@@ -476,14 +495,14 @@
 {
     /* Fetch the latest machine-state: */
-    KMachineState machineState = m_machine.isNull() ? KMachineState_Null : m_machine.GetState();
+    KMachineState enmMachineState = m_comMachine.isNull() ? KMachineState_Null : m_comMachine.GetState();
 
     /* Reopen session if necessary: */
-    if (m_session.GetState() == KSessionState_Locked)
-        m_session.UnlockMachine();
-    if (!m_machine.isNull())
+    if (m_comSession.GetState() == KSessionState_Locked)
+        m_comSession.UnlockMachine();
+    if (!m_comMachine.isNull())
     {
         /* Lock the session for the current machine: */
-        if (machineState == KMachineState_Running || machineState == KMachineState_Paused)
-            m_machine.LockMachine(m_session, KLockType_Shared);
+        if (enmMachineState == KMachineState_Running || enmMachineState == KMachineState_Paused)
+            m_comMachine.LockMachine(m_comSession, KLockType_Shared);
     }
 
@@ -492,7 +511,7 @@
 
     /* Start the timer if necessary: */
-    if (!m_machine.isNull())
-    {
-        if (m_pUpdateTimer->interval() > 0 && machineState == KMachineState_Running)
+    if (!m_comMachine.isNull())
+    {
+        if (m_pUpdateTimer->interval() > 0 && enmMachineState == KMachineState_Running)
             m_pUpdateTimer->start();
     }
@@ -507,5 +526,5 @@
 /* static */
 UIMachinePreview::AspectRatioPreset UIMachinePreview::bestAspectRatioPreset(const double dAspectRatio,
-                                                                              const QMap<AspectRatioPreset, double> &ratios)
+                                                                            const QMap<AspectRatioPreset, double> &ratios)
 {
     /* Use 16x9 preset as the 'best' by 'default': */
@@ -568,3 +587,2 @@
     return QSize(iWidth, iHeight);
 }
-
Index: trunk/src/VBox/Frontends/VirtualBox/src/manager/details/UIMachinePreview.h
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/manager/details/UIMachinePreview.h	(revision 79859)
+++ trunk/src/VBox/Frontends/VirtualBox/src/manager/details/UIMachinePreview.h	(revision 79860)
@@ -32,6 +32,6 @@
 /* COM includes: */
 #include "COMEnums.h"
+#include "CMachine.h"
 #include "CSession.h"
-#include "CMachine.h"
 
 /* Forward declarations: */
@@ -42,5 +42,5 @@
 class QTimer;
 
-/* Preview window class: */
+/** QIGraphicsWidget sub-class used as VM Preview widget inside Details pane. */
 class UIMachinePreview : public QIWithRetranslateUI4<QIGraphicsWidget>
 {
@@ -49,28 +49,77 @@
 signals:
 
-    /** Notifies about size-hint changes. */
-    void sigSizeHintChanged();
+    /** @name Layout stuff.
+      * @{ */
+        /** Notifies about size-hint changes. */
+        void sigSizeHintChanged();
+    /** @} */
 
 public:
 
-    /* Graphics-item type: */
+    /** RTTI item type. */
     enum { Type = UIDetailsItemType_Preview };
-    int type() const { return Type; }
-
-    /* Constructor/destructor: */
+
+    /** Constructs preview element, passing pParent to the base-class. */
     UIMachinePreview(QIGraphicsWidget *pParent);
-    ~UIMachinePreview();
-
-    /* API: Machine stuff: */
-    void setMachine(const CMachine& machine);
-    CMachine machine() const;
+    /** Destructs preview element. */
+    virtual ~UIMachinePreview() /* override */;
+
+    /** @name Item stuff.
+      * @{ */
+        /** Defines @a comMachine to make preview for. */
+        void setMachine(const CMachine &comMachine);
+        /** Retuirns machine we do preview for. */
+        CMachine machine() const;
+    /** @} */
+
+protected:
+
+    /** @name Event-handling stuff.
+      * @{ */
+        /** Handles translation event. */
+        virtual void retranslateUi() /* override */;
+
+        /** Handles resize @a pEvent. */
+        virtual void resizeEvent(QGraphicsSceneResizeEvent *pEvent) /* override */;
+
+        /** Handles show @a pEvent. */
+        virtual void showEvent(QShowEvent *pEvent) /* override */;
+        /** Handles hide @a pEvent. */
+        virtual void hideEvent(QHideEvent *pEvent) /* override */;
+
+        /** Handles context-menu @a pEvent. */
+        virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent *pEvent) /* override */;
+
+        /** Performs painting using passed @a pPainter, @a pOptions and optionally specified @a pWidget. */
+        virtual void paint(QPainter *pPainter, const QStyleOptionGraphicsItem *pOptions, QWidget *pWidget = 0) /* override */;
+    /** @} */
+
+    /** @name Item stuff.
+      * @{ */
+        /** Returns RTTI item type. */
+        virtual int type() const /* override */ { return Type; }
+    /** @} */
+
+    /** @name Layout stuff.
+      * @{ */
+        /** Returns size-hint.
+          * @param  enmWhich    Brings size-hint type.
+          * @param  constraint  Brings size constraint. */
+        virtual QSizeF sizeHint(Qt::SizeHint enmWhich, const QSizeF &constraint = QSizeF()) const /* override */;
+    /** @} */
 
 private slots:
 
-    /* Handler: Global-event listener stuff: */
-    void sltMachineStateChange(const QUuid &uId);
-
-    /* Handler: Preview recreator: */
-    void sltRecreatePreview();
+    /** @name Event-handling stuff.
+      * @{ */
+        /** Handles machine-state change for item with @a uId. */
+        void sltMachineStateChange(const QUuid &uId);
+    /** @} */
+
+    /** @name Item stuff.
+      * @{ */
+        /** Handles request to recreate preview. */
+        void sltRecreatePreview();
+    /** @} */
 
 private:
@@ -84,24 +133,26 @@
     };
 
-    /* Helpers: Event handlers: */
-    void resizeEvent(QGraphicsSceneResizeEvent *pEvent);
-    void showEvent(QShowEvent *pEvent);
-    void hideEvent(QHideEvent *pEvent);
-    void contextMenuEvent(QGraphicsSceneContextMenuEvent *pEvent);
-
-    /* Helpers: Translate stuff; */
-    void retranslateUi();
-
-    /* Helpers: Layout stuff: */
-    QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const;
-
-    /* Helpers: Paint stuff: */
-    void paint(QPainter *pPainter, const QStyleOptionGraphicsItem *pOption, QWidget *pWidget = 0);
-
-    /* Helpers: Update stuff: */
-    void setUpdateInterval(PreviewUpdateIntervalType interval, bool fSave);
-    void recalculatePreviewRectangle();
-    void restart();
-    void stop();
+    /** @name Prepare/cleanup cascade.
+      * @{ */
+        /** Prepares all. */
+        void prepare();
+
+        /** Cleanups all. */
+        void cleanup();
+    /** @} */
+
+    /** @name Item stuff.
+      * @{ */
+        /** Define update @a enmInterval, @a fSave it if requested. */
+        void setUpdateInterval(PreviewUpdateIntervalType enmInterval, bool fSave);
+
+        /** Recalculates preview rectangle. */
+        void recalculatePreviewRectangle();
+
+        /** Restarts preview uppdate routine. */
+        void restart();
+        /** Stops preview uppdate routine. */
+        void stop();
+    /** @} */
 
     /** Looks for the best aspect-ratio preset for the passed @a dAspectRatio among all the passed @a ratios. */
@@ -110,22 +161,48 @@
     static QSize imageAspectRatioSize(const QSize &hostSize, const QSize &guestSize);
 
-    /* Variables: */
-    CSession m_session;
-    CMachine m_machine;
-    QTimer *m_pUpdateTimer;
-    QMenu *m_pUpdateTimerMenu;
-    QHash<PreviewUpdateIntervalType, QAction*> m_actions;
-    double m_dRatio;
-    const int m_iMargin;
-    QRect m_vRect;
-    AspectRatioPreset m_preset;
-    QMap<AspectRatioPreset, QSize> m_sizes;
-    QMap<AspectRatioPreset, double> m_ratios;
-    QMap<AspectRatioPreset, QPixmap*> m_emptyPixmaps;
-    QMap<AspectRatioPreset, QPixmap*> m_fullPixmaps;
-    QImage *m_pPreviewImg;
-    QString m_strPreviewName;
+    /** @name Item stuff.
+      * @{ */
+        /** Holds the session reference. */
+        CSession  m_comSession;
+        /** Holds the machine reference. */
+        CMachine  m_comMachine;
+
+        /** Holds the update timer instance. */
+        QTimer                                     *m_pUpdateTimer;
+        /** Holds the update timer menu instance. */
+        QMenu                                      *m_pUpdateTimerMenu;
+        /** Holds the update timer menu action list. */
+        QHash<PreviewUpdateIntervalType, QAction*>  m_actions;
+    /** @} */
+
+    /** @name Layout stuff.
+      * @{ */
+        /** Holds the aspect-ratio of the preview. */
+        double     m_dRatio;
+        /** Holds the layout margin. */
+        const int  m_iMargin;
+        /** Holds the viewport rectangle. */
+        QRect      m_vRect;
+
+        /** Holds the current aspect-ratio preset. */
+        AspectRatioPreset                  m_enmPreset;
+        /** Holds the aspect-ratio preset sizes. */
+        QMap<AspectRatioPreset, QSize>     m_sizes;
+        /** Holds the aspect-ratio preset ratios. */
+        QMap<AspectRatioPreset, double>    m_ratios;
+        /** Holds the aspect-ratio preset empty pixmaps. */
+        QMap<AspectRatioPreset, QPixmap*>  m_emptyPixmaps;
+        /** Holds the aspect-ratio preset filled pixmaps. */
+        QMap<AspectRatioPreset, QPixmap*>  m_fullPixmaps;
+    /** @} */
+
+    /** @name Painting stuff.
+      * @{ */
+        /** Holds the preview image instance. */
+        QImage  *m_pPreviewImg;
+        /** Holds the preview name. */
+        QString  m_strPreviewName;
+    /** @} */
 };
 
 #endif /* !FEQT_INCLUDED_SRC_manager_details_UIMachinePreview_h */
-
