UIMiniToolBar.cpp revision 015ab419ebadda91ca674a865a53d0b9c86e5f1a
/* $Id$ */
/** @file
*
* VBox frontends: Qt GUI ("VirtualBox"):
* UIMiniToolBar class declaration & implementation. This is the toolbar shown on fullscreen mode.
*/
/*
* Copyright (C) 2009-2011 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
/* Local includes */
#include "UIIconPool.h"
#include "VBoxGlobal.h"
#include "UIMiniToolBar.h"
/* Global includes */
#include <QCursor>
#include <QDesktopWidget>
#include <QLabel>
#include <QMenu>
#include <QPaintEvent>
#include <QPainter>
#include <QPolygon>
#include <QRect>
#include <QRegion>
#include <QTimer>
#include <QToolButton>
/* Mini-toolbar constructor */
, m_pAutoHideAction(0)
, m_pDisplayLabel(0)
, m_pMinimizeAction(0)
, m_pRestoreAction(0)
, m_pCloseAction(0)
, m_fPolished(false)
, m_fSeamless(false)
, m_fSlideToScreen(true)
, m_fHideAfterSlide(false)
, m_iAutoHideCounter(0)
, m_iPositionX(0)
, m_iPositionY(0)
, m_pInsertPosition(0)
, m_fAnimated(true)
, m_iScrollDelay(10)
, m_iAutoScrollDelay(100)
, m_iAutoHideTotalCounter(10)
{
/* Check parent widget presence: */
/* Toolbar options: */
setVisible(false);
/* Add pushpin: */
m_pAutoHideAction = new QAction(this);
m_pAutoHideAction->setCheckable(true);
/* Left menu margin: */
/* Right menu margin: */
/* Left label margin: */
/* Insert a label for VM Name: */
m_pDisplayLabel = new QLabel(this);
/* Right label margin: */
/* Minimize action: */
m_pMinimizeAction = new QAction(this);
/* Exit action: */
m_pRestoreAction = new QAction(this);
/* Close action: */
m_pCloseAction = new QAction(this);
/* Event-filter for parent widget to control resize: */
pParent->installEventFilter(this);
/* Enable mouse-tracking for this & children allowing to get mouse-move events: */
}
/* Appends passed menus into internal menu-list */
{
{
{
pButton->setAutoRaise(true);
}
}
return *this;
}
/* Seamless mode setter */
{
}
/* Update the display text, usually the VM Name */
{
/* If text was really changed: */
{
/* Update toolbar label: */
/* Reinitialize: */
initialize();
/* Update toolbar if its not hidden: */
if (!isHidden())
updateDisplay(!m_fAutoHide, false);
}
}
/* Is auto-hide feature enabled? */
bool UIMiniToolBar::isAutoHide() const
{
return m_fAutoHide;
}
{
m_iAutoHideCounter = 0;
if (fShow)
{
if (isHidden())
moveToBase();
if (m_fAnimated)
{
if (fSetHideFlag)
{
m_fHideAfterSlide = false;
m_fSlideToScreen = true;
}
if (m_fActive)
show();
}
else if (m_fActive)
show();
if (m_fAutoHide)
else
}
else
{
if (m_fAnimated)
{
if (fSetHideFlag)
{
m_fHideAfterSlide = true;
m_fSlideToScreen = false;
}
}
else
hide();
if (m_fAutoHide)
else
}
}
/* Parent widget event-filter */
{
/* If parent widget was resized: */
{
/* Update toolbar position: */
moveToBase();
return true;
}
/* Base-class event-filter: */
}
/* Mouse-move event processor */
{
/* Activate sliding animation on mouse move: */
if (!m_fHideAfterSlide)
{
m_fSlideToScreen = true;
}
/* Base-class mouse-move event processing: */
}
/* Timer event processor
* Handles auto hide feature of the toolbar */
{
{
/* Due to X11 async nature, this timer-event could come before parent
* VM window become visible, we should ignore those timer-events: */
return;
/* Update tool-bar position: */
QRect screen = m_fSeamless ? vboxGlobal().availableGeometry(QApplication::desktop()->screenNumber(window())) :
switch (m_alignment)
{
case AlignTop:
{
{
if (m_fHideAfterSlide)
{
m_fHideAfterSlide = false;
hide();
}
return;
}
break;
}
case AlignBottom:
{
{
if (m_fHideAfterSlide)
{
m_fHideAfterSlide = false;
hide();
}
return;
}
break;
}
default:
break;
}
}
{
{
{
m_fSlideToScreen = false;
}
}
else
m_iAutoHideCounter = 0;
}
else
}
/* Show event processor */
{
if (!m_fPolished)
{
/* Tool-bar spacings: */
/* Title spacings: */
/* Initialize: */
initialize();
m_fPolished = true;
}
/* Base-class show event processing: */
}
/* Show event processor */
{
/* Paint background */
painter.fillRect(pEvent->rect(), QApplication::palette().color(QPalette::Active, QPalette::Window));
/* Base-class paint event processing: */
}
/* Toggle push-pin */
{
m_fAutoHide = !fOn;
updateDisplay(!m_fAutoHide, false);
}
/* Initialize mini-toolbar */
void UIMiniToolBar::initialize()
{
/* Resize to sizehint: */
/* Update geometry: */
moveToBase();
}
/* Move mini-toolbar to the base location */
void UIMiniToolBar::moveToBase()
{
QRect screen = m_fSeamless ? vboxGlobal().availableGeometry(QApplication::desktop()->screenNumber(window())) :
switch (m_alignment)
{
case AlignTop:
{
break;
}
case AlignBottom:
{
break;
}
default:
{
m_iPositionY = 0;
break;
}
}
}
{
if (m_pDisplayLabel)
}