QIArrowButtonSwitch.cpp revision 4be39ac606cc80de5b28e745a94b099557387ff7
5432N/A/* $Id$ */
5432N/A/** @file
5432N/A *
5432N/A * VBox frontends: Qt GUI ("VirtualBox"):
5432N/A * VirtualBox Qt extensions: QIArrowButtonSwitch class implementation
5432N/A */
5432N/A
5432N/A/*
5432N/A * Copyright (C) 2006-2008 Sun Microsystems, Inc.
5432N/A *
5432N/A * This file is part of VirtualBox Open Source Edition (OSE), as
5432N/A * available from http://www.virtualbox.org. This file is free software;
5432N/A * you can redistribute it and/or modify it under the terms of the GNU
5432N/A * General Public License (GPL) as published by the Free Software
5432N/A * Foundation, in version 2 as it comes in the "COPYING" file of the
5432N/A * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
5432N/A * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
5432N/A *
5432N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
5432N/A * Clara, CA 95054 USA or visit http://www.sun.com if you need
5432N/A * additional information or have any questions.
5432N/A */
5432N/A
5432N/A/* VBox includes */
5432N/A#include "VBoxGlobal.h"
6510N/A#include "QIArrowButtonSwitch.h"
6510N/A
6510N/A/* Qt includes */
5432N/A#include <QKeyEvent>
5432N/A
5432N/A
6510N/A/** @class QIArrowButtonSwitch
5432N/A *
6510N/A * The QIArrowButtonSwitch class is an arrow tool-botton with text-label,
6510N/A * used as collaps/expand switch in QIMessageBox class.
6510N/A *
5432N/A */
6510N/A
5432N/AQIArrowButtonSwitch::QIArrowButtonSwitch (QWidget *aParent)
5432N/A : QIRichToolButton (aParent)
6510N/A , mIsExpanded (false)
5432N/A{
5432N/A updateIcon();
6510N/A}
5432N/A
5432N/AQIArrowButtonSwitch::QIArrowButtonSwitch (const QString &aName, QWidget *aParent)
5432N/A : QIRichToolButton (aName, aParent)
5432N/A , mIsExpanded (false)
5432N/A{
6510N/A updateIcon();
5432N/A}
5432N/A
5432N/Avoid QIArrowButtonSwitch::buttonClicked()
5432N/A{
5432N/A mIsExpanded = !mIsExpanded;
5432N/A updateIcon();
5432N/A QIRichToolButton::buttonClicked();
5432N/A}
5432N/A
5432N/Avoid QIArrowButtonSwitch::updateIcon()
5456N/A{
5456N/A mButton->setIcon (VBoxGlobal::iconSet (mIsExpanded ?
5456N/A ":/arrow_down_10px.png" : ":/arrow_right_10px.png"));
6510N/A}
6510N/A
6510N/Abool QIArrowButtonSwitch::eventFilter (QObject *aObject, QEvent *aEvent)
5456N/A{
5456N/A /* Process only QIArrowButtonSwitch or children */
6510N/A if (!(aObject == this || children().contains (aObject)))
6510N/A return QIRichToolButton::eventFilter (aObject, aEvent);
6510N/A
6510N/A /* Process keyboard events */
5680N/A if (aEvent->type() == QEvent::KeyPress)
5432N/A {
5432N/A QKeyEvent *kEvent = static_cast <QKeyEvent*> (aEvent);
5432N/A if ((mIsExpanded && kEvent->key() == Qt::Key_Minus) ||
5432N/A (!mIsExpanded && kEvent->key() == Qt::Key_Plus))
6510N/A animateClick();
5432N/A }
6510N/A
6510N/A /* Default one handler */
6510N/A return QIRichToolButton::eventFilter (aObject, aEvent);
5680N/A}
5680N/A
5432N/A