UIVMPreviewWindow.cpp revision 194a8ad893b721dfc22ac5f955671f09db015a3f
8c3d541c7ee7442f570b22eca3d82808b35b0385vboxsync * VBox frontends: Qt GUI ("VirtualBox"):
8c3d541c7ee7442f570b22eca3d82808b35b0385vboxsync * UIPreviewWindow class implementation
8c3d541c7ee7442f570b22eca3d82808b35b0385vboxsync * Copyright (C) 2010 Oracle Corporation
8c3d541c7ee7442f570b22eca3d82808b35b0385vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
8c3d541c7ee7442f570b22eca3d82808b35b0385vboxsync * available from http://www.virtualbox.org. This file is free software;
8c3d541c7ee7442f570b22eca3d82808b35b0385vboxsync * you can redistribute it and/or modify it under the terms of the GNU
8c3d541c7ee7442f570b22eca3d82808b35b0385vboxsync * General Public License (GPL) as published by the Free Software
8c3d541c7ee7442f570b22eca3d82808b35b0385vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
8c3d541c7ee7442f570b22eca3d82808b35b0385vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
8c3d541c7ee7442f570b22eca3d82808b35b0385vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
8c3d541c7ee7442f570b22eca3d82808b35b0385vboxsync/* Local includes */
8c3d541c7ee7442f570b22eca3d82808b35b0385vboxsync/* Global includes */
8c3d541c7ee7442f570b22eca3d82808b35b0385vboxsyncUIVMPreviewWindow::UIVMPreviewWindow(QWidget *pParent)
8c3d541c7ee7442f570b22eca3d82808b35b0385vboxsync setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
8c3d541c7ee7442f570b22eca3d82808b35b0385vboxsync /* Connect the update timer */
8c3d541c7ee7442f570b22eca3d82808b35b0385vboxsync /* Connect the machine state event */
8c3d541c7ee7442f570b22eca3d82808b35b0385vboxsync connect(gVBoxEvents, SIGNAL(sigMachineStateChange(QString, KMachineState)),
8c3d541c7ee7442f570b22eca3d82808b35b0385vboxsync this, SLOT(sltMachineStateChange(QString, KMachineState)));
8c3d541c7ee7442f570b22eca3d82808b35b0385vboxsync /* Create the context menu */
8c3d541c7ee7442f570b22eca3d82808b35b0385vboxsync QActionGroup *pUpdateTimeG = new QActionGroup(this);
8c3d541c7ee7442f570b22eca3d82808b35b0385vboxsync for(int i = 0; i < UpdateEnd; ++i)
8c3d541c7ee7442f570b22eca3d82808b35b0385vboxsync m_actions[static_cast<UpdateInterval>(i)] = pUpdateTime;
8c3d541c7ee7442f570b22eca3d82808b35b0385vboxsync m_pUpdateTimerMenu->insertSeparator(m_actions[static_cast<UpdateInterval>(Update1Sec)]);
8c3d541c7ee7442f570b22eca3d82808b35b0385vboxsync /* Default value */
8c3d541c7ee7442f570b22eca3d82808b35b0385vboxsync QString strInterval = vboxGlobal().virtualBox().GetExtraData(VBoxDefs::GUI_PreviewUpdate);
8c3d541c7ee7442f570b22eca3d82808b35b0385vboxsync /* Initialize with the new update interval */
8c3d541c7ee7442f570b22eca3d82808b35b0385vboxsync /* Retranslate the UI */
8c3d541c7ee7442f570b22eca3d82808b35b0385vboxsyncvoid UIVMPreviewWindow::setMachine(const CMachine& machine)
8c3d541c7ee7442f570b22eca3d82808b35b0385vboxsync m_actions.value(UpdateDisabled)->setText(tr("Update Disabled"));
8c3d541c7ee7442f570b22eca3d82808b35b0385vboxsync m_actions.value(Update1Sec)->setText(tr("Every 1 s"));
8c3d541c7ee7442f570b22eca3d82808b35b0385vboxsync m_actions.value(Update2Sec)->setText(tr("Every 2 s"));
8c3d541c7ee7442f570b22eca3d82808b35b0385vboxsync m_actions.value(Update5Sec)->setText(tr("Every 5 s"));
8c3d541c7ee7442f570b22eca3d82808b35b0385vboxsync m_actions.value(Update10Sec)->setText(tr("Every 10 s"));
8c3d541c7ee7442f570b22eca3d82808b35b0385vboxsyncvoid UIVMPreviewWindow::resizeEvent(QResizeEvent *pEvent)
8c3d541c7ee7442f570b22eca3d82808b35b0385vboxsyncvoid UIVMPreviewWindow::showEvent(QShowEvent *pEvent)
8c3d541c7ee7442f570b22eca3d82808b35b0385vboxsync /* Make sure there is some valid preview image when shown. */
8c3d541c7ee7442f570b22eca3d82808b35b0385vboxsyncvoid UIVMPreviewWindow::hideEvent(QHideEvent *pEvent)
8c3d541c7ee7442f570b22eca3d82808b35b0385vboxsync /* Stop the update time when we aren't visible */
8c3d541c7ee7442f570b22eca3d82808b35b0385vboxsyncvoid UIVMPreviewWindow::paintEvent(QPaintEvent *pEvent)
8c3d541c7ee7442f570b22eca3d82808b35b0385vboxsync /* Enable clipping */
8c3d541c7ee7442f570b22eca3d82808b35b0385vboxsync /* Where should the content go */
8c3d541c7ee7442f570b22eca3d82808b35b0385vboxsync /* Draw the background with the monitor and the shadow */
8c3d541c7ee7442f570b22eca3d82808b35b0385vboxsync// painter.setPen(Qt::red);
8c3d541c7ee7442f570b22eca3d82808b35b0385vboxsync// painter.drawRect(cr.adjusted(0, 0, -1, -1));
8c3d541c7ee7442f570b22eca3d82808b35b0385vboxsync /* If there is a preview image available, use it. */
8c3d541c7ee7442f570b22eca3d82808b35b0385vboxsync /* Paint the name in the center of the monitor */
8c3d541c7ee7442f570b22eca3d82808b35b0385vboxsync /* Make a little magic to find out if the given text fits into
8c3d541c7ee7442f570b22eca3d82808b35b0385vboxsync * our rectangle. Decrease the font pixel size as long as it
8c3d541c7ee7442f570b22eca3d82808b35b0385vboxsync * doesn't fit. */
8c3d541c7ee7442f570b22eca3d82808b35b0385vboxsync h = h * .8;
8c3d541c7ee7442f570b22eca3d82808b35b0385vboxsync r = painter.boundingRect(m_vRect, fFlags, strName);
8c3d541c7ee7442f570b22eca3d82808b35b0385vboxsync && cMax-- != 0);
8c3d541c7ee7442f570b22eca3d82808b35b0385vboxsync /* Draw the glossy overlay last */
8c3d541c7ee7442f570b22eca3d82808b35b0385vboxsync painter.drawImage(m_vRect.x(), m_vRect.y(), *m_pGlossyImg);
8c3d541c7ee7442f570b22eca3d82808b35b0385vboxsyncvoid UIVMPreviewWindow::contextMenuEvent(QContextMenuEvent *pEvent)
8c3d541c7ee7442f570b22eca3d82808b35b0385vboxsync QAction *pReturn = m_pUpdateTimerMenu->exec(pEvent->globalPos(), 0);
8c3d541c7ee7442f570b22eca3d82808b35b0385vboxsync UpdateInterval interval = static_cast<UpdateInterval>(pReturn->data().toInt());
restart();
if (!isVisible())
if (m_pPreviewImg)
delete m_pPreviewImg;
m_pPreviewImg = 0;
bool fDone = false;
fDone = true;
// display.TakeScreenShot(0, shot.bits(), shot.width(), shot.height());
uint32_t e = d[i];
fDone = true;
if (fDone)
update();
switch (interval)
case UpdateDisabled:
if (fSave)
case Update1Sec:
if (fSave)
case Update2Sec:
if (fSave)
case Update5Sec:
if (fSave)
case Update10Sec:
if (fSave)
case UpdateEnd: break;
pW.drawRoundedRect(QRect(QPoint(0, 0), cr.size()).adjusted(10, 10, -10, -10), m_vMargin, m_vMargin);
if (m_pbgImage)
delete m_pbgImage;
if (m_pGlossyImg)
delete m_pGlossyImg;
update();