1 | /* $Id: QIArrowButtonSwitch.cpp 76606 2019-01-02 05:40:39Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - Qt extensions: QIArrowButtonSwitch class implementation.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2019 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | /* Qt includes: */
|
---|
19 | #include <QKeyEvent>
|
---|
20 |
|
---|
21 | /* GUI includes: */
|
---|
22 | #include "QIArrowButtonSwitch.h"
|
---|
23 |
|
---|
24 |
|
---|
25 | QIArrowButtonSwitch::QIArrowButtonSwitch(QWidget *pParent /* = 0 */)
|
---|
26 | : QIRichToolButton(pParent)
|
---|
27 | , m_fExpanded(false)
|
---|
28 | {
|
---|
29 | /* Update icon: */
|
---|
30 | updateIcon();
|
---|
31 | }
|
---|
32 |
|
---|
33 | void QIArrowButtonSwitch::setIcons(const QIcon &iconCollapsed, const QIcon &iconExpanded)
|
---|
34 | {
|
---|
35 | /* Assign icons: */
|
---|
36 | m_iconCollapsed = iconCollapsed;
|
---|
37 | m_iconExpanded = iconExpanded;
|
---|
38 | /* Update icon: */
|
---|
39 | updateIcon();
|
---|
40 | }
|
---|
41 |
|
---|
42 | void QIArrowButtonSwitch::setExpanded(bool fExpanded)
|
---|
43 | {
|
---|
44 | /* Set button state: */
|
---|
45 | m_fExpanded = fExpanded;
|
---|
46 | /* Update icon: */
|
---|
47 | updateIcon();
|
---|
48 | }
|
---|
49 |
|
---|
50 | void QIArrowButtonSwitch::sltButtonClicked()
|
---|
51 | {
|
---|
52 | /* Toggle button state: */
|
---|
53 | m_fExpanded = !m_fExpanded;
|
---|
54 | /* Update icon: */
|
---|
55 | updateIcon();
|
---|
56 | }
|
---|
57 |
|
---|
58 | void QIArrowButtonSwitch::keyPressEvent(QKeyEvent *pEvent)
|
---|
59 | {
|
---|
60 | /* Handle different keys: */
|
---|
61 | switch (pEvent->key())
|
---|
62 | {
|
---|
63 | /* Animate-click for the Space key: */
|
---|
64 | case Qt::Key_Minus: if (m_fExpanded) return animateClick(); break;
|
---|
65 | case Qt::Key_Plus: if (!m_fExpanded) return animateClick(); break;
|
---|
66 | default: break;
|
---|
67 | }
|
---|
68 | /* Call to base-class: */
|
---|
69 | QIRichToolButton::keyPressEvent(pEvent);
|
---|
70 | }
|
---|