QIStateIndicator.cpp revision ad27e1d5e48ca41245120c331cc88b50464813ce
/* $Id$ */
/** @file
*
* VBox frontends: Qt GUI ("VirtualBox"):
* VirtualBox Qt extensions: QIStateIndicator class implementation
*/
/*
* Copyright (C) 2006-2007 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.
*/
#include "QIStateIndicator.h"
/* Qt includes */
#include <QPainter>
#ifdef Q_WS_MAC
# include <QContextMenuEvent>
#endif
/** @clas QIStateIndicator
*
* The QIStateIndicator class is a simple class that can visually indicate
* the state of some thing, as described by the state property.
*/
, mState(0)
, mSize(0, 0)
{
}
/**
* Constructs a new QIStateIndicator instance. This instance is useless
* until icons are specified for necessary states.
*
* @param aState
* the initial indicator state
*/
// : QFrame (aParent, aName, aFlags | Qt::WStaticContents | Qt::WMouseNoMask)
{
/* we will precompose the pixmap background using the widget background in
* drawContents(), so try to set the correct background origin for the
* case when a pixmap is used as a widget background. */
// if (aParent)
// setBackgroundOrigin (aParent->backgroundOrigin());
}
{
}
{
return mSize;
}
{
}
/**
* Sets an icon for the specified state. The first icon set by this method
* defines the preferred size of this indicator. All other icons will be
* scaled to fit this size.
*
* @note If this widget is constructed with the WNoAutoErase flag, then all
* transparent areas of the new state icon are filled with the widget
* background color or pixmap (as taken from the widget palette), to provide
* flicker free state redraws in one single operation (which is useful for
* indicators that frequently change their state).
*/
{
/* Here we just set the original pixmap. All actual work from the @note
* above takes place in #drawContents(). */
}
{
repaint();
}
{
drawContents (&painter);
}
{
if (icon)
}
#ifdef Q_WS_MAC
/**
* Make the left button also show the context menu to make things
* simpler for users with single mouse button mice (laptops++).
*/
{
/* Do this for the left mouse button event only, cause in the case of the
* right mouse button it could happen that the context menu event is
* triggered twice. Also this isn't necessary for the middle mouse button
* which would be some kind of overstated. */
{
if (qme.isAccepted())
else
}else
}
#endif /* Q_WS_MAC */
{
emit mouseDoubleClicked (this, e);
}
{
emit contextMenuRequested (this, e);
}