UIWarningPane.cpp revision 1548538a86bdf3de84605db9c0ae03e000a55c6f
235d3bea31bdca1dd7f555821eacfd0dd36bd6f5vboxsync/* $Id$ */
235d3bea31bdca1dd7f555821eacfd0dd36bd6f5vboxsync/** @file
235d3bea31bdca1dd7f555821eacfd0dd36bd6f5vboxsync *
235d3bea31bdca1dd7f555821eacfd0dd36bd6f5vboxsync * VBox frontends: Qt4 GUI ("VirtualBox"):
235d3bea31bdca1dd7f555821eacfd0dd36bd6f5vboxsync * UIWarningPane class implementation
235d3bea31bdca1dd7f555821eacfd0dd36bd6f5vboxsync */
235d3bea31bdca1dd7f555821eacfd0dd36bd6f5vboxsync
235d3bea31bdca1dd7f555821eacfd0dd36bd6f5vboxsync/*
235d3bea31bdca1dd7f555821eacfd0dd36bd6f5vboxsync * Copyright (C) 2009-2013 Oracle Corporation
235d3bea31bdca1dd7f555821eacfd0dd36bd6f5vboxsync *
235d3bea31bdca1dd7f555821eacfd0dd36bd6f5vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
235d3bea31bdca1dd7f555821eacfd0dd36bd6f5vboxsync * available from http://www.virtualbox.org. This file is free software;
235d3bea31bdca1dd7f555821eacfd0dd36bd6f5vboxsync * you can redistribute it and/or modify it under the terms of the GNU
235d3bea31bdca1dd7f555821eacfd0dd36bd6f5vboxsync * General Public License (GPL) as published by the Free Software
235d3bea31bdca1dd7f555821eacfd0dd36bd6f5vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
235d3bea31bdca1dd7f555821eacfd0dd36bd6f5vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
235d3bea31bdca1dd7f555821eacfd0dd36bd6f5vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
235d3bea31bdca1dd7f555821eacfd0dd36bd6f5vboxsync */
235d3bea31bdca1dd7f555821eacfd0dd36bd6f5vboxsync
235d3bea31bdca1dd7f555821eacfd0dd36bd6f5vboxsync/* Qt includes: */
235d3bea31bdca1dd7f555821eacfd0dd36bd6f5vboxsync#include <QHBoxLayout>
235d3bea31bdca1dd7f555821eacfd0dd36bd6f5vboxsync#include <QLabel>
1548538a86bdf3de84605db9c0ae03e000a55c6fvboxsync#include <QEvent>
235d3bea31bdca1dd7f555821eacfd0dd36bd6f5vboxsync
235d3bea31bdca1dd7f555821eacfd0dd36bd6f5vboxsync/* GUI includes: */
235d3bea31bdca1dd7f555821eacfd0dd36bd6f5vboxsync#include "UIWarningPane.h"
235d3bea31bdca1dd7f555821eacfd0dd36bd6f5vboxsync
235d3bea31bdca1dd7f555821eacfd0dd36bd6f5vboxsyncUIWarningPane::UIWarningPane(QWidget *pParent)
235d3bea31bdca1dd7f555821eacfd0dd36bd6f5vboxsync : QWidget(pParent)
235d3bea31bdca1dd7f555821eacfd0dd36bd6f5vboxsync , m_pLabelIcon(0)
235d3bea31bdca1dd7f555821eacfd0dd36bd6f5vboxsync , m_pLabelText(0)
1548538a86bdf3de84605db9c0ae03e000a55c6fvboxsync , m_fHovered(false)
235d3bea31bdca1dd7f555821eacfd0dd36bd6f5vboxsync{
235d3bea31bdca1dd7f555821eacfd0dd36bd6f5vboxsync /* Prepare: */
235d3bea31bdca1dd7f555821eacfd0dd36bd6f5vboxsync prepare();
235d3bea31bdca1dd7f555821eacfd0dd36bd6f5vboxsync}
235d3bea31bdca1dd7f555821eacfd0dd36bd6f5vboxsync
235d3bea31bdca1dd7f555821eacfd0dd36bd6f5vboxsyncvoid UIWarningPane::setWarningPixmap(const QPixmap &pixmap)
235d3bea31bdca1dd7f555821eacfd0dd36bd6f5vboxsync{
235d3bea31bdca1dd7f555821eacfd0dd36bd6f5vboxsync m_pLabelIcon->setPixmap(pixmap);
235d3bea31bdca1dd7f555821eacfd0dd36bd6f5vboxsync}
235d3bea31bdca1dd7f555821eacfd0dd36bd6f5vboxsync
235d3bea31bdca1dd7f555821eacfd0dd36bd6f5vboxsyncvoid UIWarningPane::setWarningText(const QString &strText)
235d3bea31bdca1dd7f555821eacfd0dd36bd6f5vboxsync{
235d3bea31bdca1dd7f555821eacfd0dd36bd6f5vboxsync m_pLabelText->setText(strText);
235d3bea31bdca1dd7f555821eacfd0dd36bd6f5vboxsync}
235d3bea31bdca1dd7f555821eacfd0dd36bd6f5vboxsync
235d3bea31bdca1dd7f555821eacfd0dd36bd6f5vboxsyncvoid UIWarningPane::prepare()
235d3bea31bdca1dd7f555821eacfd0dd36bd6f5vboxsync{
235d3bea31bdca1dd7f555821eacfd0dd36bd6f5vboxsync /* Prepare content: */
235d3bea31bdca1dd7f555821eacfd0dd36bd6f5vboxsync prepareContent();
235d3bea31bdca1dd7f555821eacfd0dd36bd6f5vboxsync}
235d3bea31bdca1dd7f555821eacfd0dd36bd6f5vboxsync
235d3bea31bdca1dd7f555821eacfd0dd36bd6f5vboxsyncvoid UIWarningPane::prepareContent()
235d3bea31bdca1dd7f555821eacfd0dd36bd6f5vboxsync{
1548538a86bdf3de84605db9c0ae03e000a55c6fvboxsync /* Configure self: */
1548538a86bdf3de84605db9c0ae03e000a55c6fvboxsync setMouseTracking(true);
1548538a86bdf3de84605db9c0ae03e000a55c6fvboxsync installEventFilter(this);
235d3bea31bdca1dd7f555821eacfd0dd36bd6f5vboxsync /* Create layout: */
235d3bea31bdca1dd7f555821eacfd0dd36bd6f5vboxsync QHBoxLayout *pLayout = new QHBoxLayout(this);
235d3bea31bdca1dd7f555821eacfd0dd36bd6f5vboxsync {
235d3bea31bdca1dd7f555821eacfd0dd36bd6f5vboxsync /* Configure layout: */
235d3bea31bdca1dd7f555821eacfd0dd36bd6f5vboxsync pLayout->setContentsMargins(0, 0, 0, 0);
235d3bea31bdca1dd7f555821eacfd0dd36bd6f5vboxsync /* Create icon label: */
235d3bea31bdca1dd7f555821eacfd0dd36bd6f5vboxsync m_pLabelIcon = new QLabel;
1548538a86bdf3de84605db9c0ae03e000a55c6fvboxsync {
1548538a86bdf3de84605db9c0ae03e000a55c6fvboxsync /* Configure icon label: */
1548538a86bdf3de84605db9c0ae03e000a55c6fvboxsync m_pLabelIcon->setMouseTracking(true);
1548538a86bdf3de84605db9c0ae03e000a55c6fvboxsync m_pLabelIcon->installEventFilter(this);
1548538a86bdf3de84605db9c0ae03e000a55c6fvboxsync }
235d3bea31bdca1dd7f555821eacfd0dd36bd6f5vboxsync /* Create text label: */
235d3bea31bdca1dd7f555821eacfd0dd36bd6f5vboxsync m_pLabelText = new QLabel;
1548538a86bdf3de84605db9c0ae03e000a55c6fvboxsync {
1548538a86bdf3de84605db9c0ae03e000a55c6fvboxsync /* Configure text label: */
1548538a86bdf3de84605db9c0ae03e000a55c6fvboxsync m_pLabelText->setMouseTracking(true);
1548538a86bdf3de84605db9c0ae03e000a55c6fvboxsync m_pLabelText->installEventFilter(this);
1548538a86bdf3de84605db9c0ae03e000a55c6fvboxsync }
235d3bea31bdca1dd7f555821eacfd0dd36bd6f5vboxsync /* Add widgets into layout: */
235d3bea31bdca1dd7f555821eacfd0dd36bd6f5vboxsync pLayout->addWidget(m_pLabelIcon);
235d3bea31bdca1dd7f555821eacfd0dd36bd6f5vboxsync pLayout->addWidget(m_pLabelText);
235d3bea31bdca1dd7f555821eacfd0dd36bd6f5vboxsync }
235d3bea31bdca1dd7f555821eacfd0dd36bd6f5vboxsync}
235d3bea31bdca1dd7f555821eacfd0dd36bd6f5vboxsync
1548538a86bdf3de84605db9c0ae03e000a55c6fvboxsyncbool UIWarningPane::eventFilter(QObject *pWatched, QEvent *pEvent)
1548538a86bdf3de84605db9c0ae03e000a55c6fvboxsync{
1548538a86bdf3de84605db9c0ae03e000a55c6fvboxsync /* Depending on event-type: */
1548538a86bdf3de84605db9c0ae03e000a55c6fvboxsync switch (pEvent->type())
1548538a86bdf3de84605db9c0ae03e000a55c6fvboxsync {
1548538a86bdf3de84605db9c0ae03e000a55c6fvboxsync /* Anything is hovered: */
1548538a86bdf3de84605db9c0ae03e000a55c6fvboxsync case QEvent::MouseMove:
1548538a86bdf3de84605db9c0ae03e000a55c6fvboxsync {
1548538a86bdf3de84605db9c0ae03e000a55c6fvboxsync /* Hover warning-pane if not yet hovered: */
1548538a86bdf3de84605db9c0ae03e000a55c6fvboxsync if (!m_fHovered)
1548538a86bdf3de84605db9c0ae03e000a55c6fvboxsync {
1548538a86bdf3de84605db9c0ae03e000a55c6fvboxsync m_fHovered = true;
1548538a86bdf3de84605db9c0ae03e000a55c6fvboxsync emit sigHoverEnter();
1548538a86bdf3de84605db9c0ae03e000a55c6fvboxsync }
1548538a86bdf3de84605db9c0ae03e000a55c6fvboxsync break;
1548538a86bdf3de84605db9c0ae03e000a55c6fvboxsync }
1548538a86bdf3de84605db9c0ae03e000a55c6fvboxsync /* Warning-pane is unhovered: */
1548538a86bdf3de84605db9c0ae03e000a55c6fvboxsync case QEvent::Leave:
1548538a86bdf3de84605db9c0ae03e000a55c6fvboxsync {
1548538a86bdf3de84605db9c0ae03e000a55c6fvboxsync /* Unhover warning-pane if hovered: */
1548538a86bdf3de84605db9c0ae03e000a55c6fvboxsync if (pWatched == this && m_fHovered)
1548538a86bdf3de84605db9c0ae03e000a55c6fvboxsync {
1548538a86bdf3de84605db9c0ae03e000a55c6fvboxsync m_fHovered = false;
1548538a86bdf3de84605db9c0ae03e000a55c6fvboxsync emit sigHoverLeave();
1548538a86bdf3de84605db9c0ae03e000a55c6fvboxsync }
1548538a86bdf3de84605db9c0ae03e000a55c6fvboxsync break;
1548538a86bdf3de84605db9c0ae03e000a55c6fvboxsync }
1548538a86bdf3de84605db9c0ae03e000a55c6fvboxsync /* Default case: */
1548538a86bdf3de84605db9c0ae03e000a55c6fvboxsync default: break;
1548538a86bdf3de84605db9c0ae03e000a55c6fvboxsync }
1548538a86bdf3de84605db9c0ae03e000a55c6fvboxsync /* Call to base-class: */
1548538a86bdf3de84605db9c0ae03e000a55c6fvboxsync return QWidget::eventFilter(pWatched, pEvent);
1548538a86bdf3de84605db9c0ae03e000a55c6fvboxsync}
1548538a86bdf3de84605db9c0ae03e000a55c6fvboxsync