QIArrowButtonSwitch.cpp revision 57bad04ee49aecc036182a51108288dae1957782
4be39ac606cc80de5b28e745a94b099557387ff7vboxsync/* $Id$ */
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync/** @file
57bad04ee49aecc036182a51108288dae1957782vboxsync * VBox Qt GUI - QIArrowButtonSwitch class implementation.
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync */
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync/*
57bad04ee49aecc036182a51108288dae1957782vboxsync * Copyright (C) 2006-2014 Oracle Corporation
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync *
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync * available from http://www.virtualbox.org. This file is free software;
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync * you can redistribute it and/or modify it under the terms of the GNU
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync * General Public License (GPL) as published by the Free Software
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync */
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync
57bad04ee49aecc036182a51108288dae1957782vboxsync/* Qt includes: */
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync#include <QKeyEvent>
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync
57bad04ee49aecc036182a51108288dae1957782vboxsync/* GUI includes: */
57bad04ee49aecc036182a51108288dae1957782vboxsync#include "QIArrowButtonSwitch.h"
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync
57bad04ee49aecc036182a51108288dae1957782vboxsyncQIArrowButtonSwitch::QIArrowButtonSwitch(QWidget *pParent /* = 0 */)
57bad04ee49aecc036182a51108288dae1957782vboxsync : QIRichToolButton(pParent)
57bad04ee49aecc036182a51108288dae1957782vboxsync , m_buttonState(ButtonState_Collapsed)
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync{
57bad04ee49aecc036182a51108288dae1957782vboxsync /* Update icon: */
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync updateIcon();
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync}
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync
57bad04ee49aecc036182a51108288dae1957782vboxsyncvoid QIArrowButtonSwitch::setIconForButtonState(QIArrowButtonSwitch::ButtonState buttonState, const QIcon &icon)
07ec2adeeaae2d8fea3a5913ffd262a67a893ce4vboxsync{
57bad04ee49aecc036182a51108288dae1957782vboxsync /* Assign icon: */
57bad04ee49aecc036182a51108288dae1957782vboxsync m_icons[buttonState] = icon;
57bad04ee49aecc036182a51108288dae1957782vboxsync /* Update icon: */
07ec2adeeaae2d8fea3a5913ffd262a67a893ce4vboxsync updateIcon();
07ec2adeeaae2d8fea3a5913ffd262a67a893ce4vboxsync}
07ec2adeeaae2d8fea3a5913ffd262a67a893ce4vboxsync
57bad04ee49aecc036182a51108288dae1957782vboxsyncvoid QIArrowButtonSwitch::sltButtonClicked()
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync{
57bad04ee49aecc036182a51108288dae1957782vboxsync /* Toggle button-state: */
57bad04ee49aecc036182a51108288dae1957782vboxsync m_buttonState = m_buttonState == ButtonState_Collapsed ?
57bad04ee49aecc036182a51108288dae1957782vboxsync ButtonState_Expanded : ButtonState_Collapsed;
57bad04ee49aecc036182a51108288dae1957782vboxsync /* Update icon: */
57bad04ee49aecc036182a51108288dae1957782vboxsync updateIcon();
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync}
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync
57bad04ee49aecc036182a51108288dae1957782vboxsyncvoid QIArrowButtonSwitch::keyPressEvent(QKeyEvent *pEvent)
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync{
57bad04ee49aecc036182a51108288dae1957782vboxsync /* Handle different keys: */
57bad04ee49aecc036182a51108288dae1957782vboxsync switch (pEvent->key())
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync {
57bad04ee49aecc036182a51108288dae1957782vboxsync /* Animate-click for the Space key: */
57bad04ee49aecc036182a51108288dae1957782vboxsync case Qt::Key_Minus: if (m_buttonState == ButtonState_Expanded) return animateClick(); break;
57bad04ee49aecc036182a51108288dae1957782vboxsync case Qt::Key_Plus: if (m_buttonState == ButtonState_Collapsed) return animateClick(); break;
57bad04ee49aecc036182a51108288dae1957782vboxsync default: break;
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync }
57bad04ee49aecc036182a51108288dae1957782vboxsync /* Call to base-class: */
57bad04ee49aecc036182a51108288dae1957782vboxsync QIRichToolButton::keyPressEvent(pEvent);
57bad04ee49aecc036182a51108288dae1957782vboxsync}
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync
57bad04ee49aecc036182a51108288dae1957782vboxsyncvoid QIArrowButtonSwitch::updateIcon()
57bad04ee49aecc036182a51108288dae1957782vboxsync{
57bad04ee49aecc036182a51108288dae1957782vboxsync setIcon(m_icons.value(m_buttonState));
ad13c20995d0a1aafbfbd35b2d698ef2ff5fbeefvboxsync}
4be39ac606cc80de5b28e745a94b099557387ff7vboxsync