[26715] | 1 | /* $Id: UISpecialControls.cpp 104358 2024-04-18 05:33:40Z vboxsync $ */
|
---|
| 2 | /** @file
|
---|
[71577] | 3 | * VBox Qt GUI - UISpecialControls implementation.
|
---|
[26715] | 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[98103] | 7 | * Copyright (C) 2009-2023 Oracle and/or its affiliates.
|
---|
[26715] | 8 | *
|
---|
[96407] | 9 | * This file is part of VirtualBox base platform packages, as
|
---|
| 10 | * available from https://www.virtualbox.org.
|
---|
| 11 | *
|
---|
| 12 | * This program is free software; you can redistribute it and/or
|
---|
| 13 | * modify it under the terms of the GNU General Public License
|
---|
| 14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
| 15 | * License.
|
---|
| 16 | *
|
---|
| 17 | * This program is distributed in the hope that it will be useful, but
|
---|
| 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
| 20 | * General Public License for more details.
|
---|
| 21 | *
|
---|
| 22 | * You should have received a copy of the GNU General Public License
|
---|
| 23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
| 24 | *
|
---|
| 25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
[26715] | 26 | */
|
---|
| 27 |
|
---|
[71577] | 28 | /* Qt includes: */
|
---|
[76606] | 29 | #include <QHBoxLayout>
|
---|
| 30 | #ifndef VBOX_DARWIN_USE_NATIVE_CONTROLS
|
---|
| 31 | # include <QBitmap>
|
---|
| 32 | # include <QMouseEvent>
|
---|
| 33 | # include <QPainter>
|
---|
| 34 | # include <QSignalMapper>
|
---|
| 35 | #endif
|
---|
[71577] | 36 |
|
---|
| 37 | /* GUI includes: */
|
---|
[76606] | 38 | #include "UIIconPool.h"
|
---|
[103578] | 39 | #include "UIShortcutPool.h"
|
---|
[76606] | 40 | #include "UISpecialControls.h"
|
---|
[104358] | 41 | #include "UITranslationEventListener.h"
|
---|
[25178] | 42 |
|
---|
| 43 | #ifdef VBOX_DARWIN_USE_NATIVE_CONTROLS
|
---|
| 44 |
|
---|
[71577] | 45 |
|
---|
| 46 | /*********************************************************************************************************************************
|
---|
| 47 | * Class UIMiniCancelButton implementation. *
|
---|
| 48 | *********************************************************************************************************************************/
|
---|
| 49 |
|
---|
[30356] | 50 | UIMiniCancelButton::UIMiniCancelButton(QWidget *pParent /* = 0 */)
|
---|
[71577] | 51 | : QAbstractButton(pParent)
|
---|
[25178] | 52 | {
|
---|
[30356] | 53 | setShortcut(QKeySequence(Qt::Key_Escape));
|
---|
[54055] | 54 | m_pButton = new UICocoaButton(this, UICocoaButton::CancelButton);
|
---|
[71577] | 55 | connect(m_pButton, SIGNAL(clicked()), this, SIGNAL(clicked()));
|
---|
[30356] | 56 | setFixedSize(m_pButton->size());
|
---|
[104358] | 57 | connect(&translationEventListener(), &UITranslationEventListener::sigRetranslateUI,
|
---|
| 58 | this, &UIMiniCancelButton::sltRetranslateUI);
|
---|
[25178] | 59 | }
|
---|
| 60 |
|
---|
[71577] | 61 | void UIMiniCancelButton::resizeEvent(QResizeEvent *)
|
---|
[27401] | 62 | {
|
---|
[30356] | 63 | m_pButton->resize(size());
|
---|
[27401] | 64 | }
|
---|
| 65 |
|
---|
[27690] | 66 |
|
---|
[71577] | 67 | /*********************************************************************************************************************************
|
---|
| 68 | * Class UIHelpButton implementation. *
|
---|
| 69 | *********************************************************************************************************************************/
|
---|
[27690] | 70 |
|
---|
[30356] | 71 | UIHelpButton::UIHelpButton(QWidget *pParent /* = 0 */)
|
---|
[71577] | 72 | : QPushButton(pParent)
|
---|
[25178] | 73 | {
|
---|
[103578] | 74 | setShortcut(UIShortcutPool::standardSequence(QKeySequence::HelpContents));
|
---|
[54055] | 75 | m_pButton = new UICocoaButton(this, UICocoaButton::HelpButton);
|
---|
[71577] | 76 | connect(m_pButton, SIGNAL(clicked()), this, SIGNAL(clicked()));
|
---|
[30356] | 77 | setFixedSize(m_pButton->size());
|
---|
[25178] | 78 | }
|
---|
| 79 |
|
---|
[30356] | 80 |
|
---|
[71577] | 81 | #else /* !VBOX_DARWIN_USE_NATIVE_CONTROLS */
|
---|
[30356] | 82 |
|
---|
[25178] | 83 |
|
---|
[71577] | 84 | /*********************************************************************************************************************************
|
---|
| 85 | * Class UIMiniCancelButton implementation. *
|
---|
| 86 | *********************************************************************************************************************************/
|
---|
[25178] | 87 |
|
---|
[54539] | 88 | UIMiniCancelButton::UIMiniCancelButton(QWidget *pParent /* = 0 */)
|
---|
[104358] | 89 | : QIToolButton(pParent)
|
---|
[25178] | 90 | {
|
---|
[30356] | 91 | setAutoRaise(true);
|
---|
| 92 | setFocusPolicy(Qt::TabFocus);
|
---|
| 93 | setShortcut(QKeySequence(Qt::Key_Escape));
|
---|
[50931] | 94 | setIcon(UIIconPool::defaultIcon(UIIconPool::UIDefaultIconType_DialogCancel));
|
---|
[25178] | 95 | }
|
---|
| 96 |
|
---|
[71577] | 97 |
|
---|
| 98 | /*********************************************************************************************************************************
|
---|
| 99 | * Class UIHelpButton implementation. *
|
---|
| 100 | *********************************************************************************************************************************/
|
---|
| 101 |
|
---|
[25178] | 102 | /* From: src/gui/styles/qmacstyle_mac.cpp */
|
---|
| 103 | static const int PushButtonLeftOffset = 6;
|
---|
| 104 | static const int PushButtonTopOffset = 4;
|
---|
| 105 | static const int PushButtonRightOffset = 12;
|
---|
| 106 | static const int PushButtonBottomOffset = 4;
|
---|
| 107 |
|
---|
[54539] | 108 | UIHelpButton::UIHelpButton(QWidget *pParent /* = 0 */)
|
---|
[104358] | 109 | : QPushButton(pParent)
|
---|
[25178] | 110 | {
|
---|
[71577] | 111 | # ifdef VBOX_WS_MAC
|
---|
[30356] | 112 | m_pButtonPressed = false;
|
---|
[83367] | 113 | m_pNormalPixmap = new QPixmap(":/help_button_normal_mac_24px.png");
|
---|
| 114 | m_pPressedPixmap = new QPixmap(":/help_button_pressed_mac_24px.png");
|
---|
[30356] | 115 | m_size = m_pNormalPixmap->size();
|
---|
| 116 | m_pMask = new QImage(m_pNormalPixmap->mask().toImage());
|
---|
| 117 | m_BRect = QRect(PushButtonLeftOffset,
|
---|
[25178] | 118 | PushButtonTopOffset,
|
---|
[30356] | 119 | m_size.width(),
|
---|
| 120 | m_size.height());
|
---|
[71577] | 121 | # endif /* VBOX_WS_MAC */
|
---|
| 122 |
|
---|
| 123 | /* Apply language settings: */
|
---|
[104358] | 124 | sltRetranslateUI();
|
---|
| 125 | connect(&translationEventListener(), &UITranslationEventListener::sigRetranslateUI,
|
---|
| 126 | this, &UIHelpButton::sltRetranslateUI);
|
---|
[25178] | 127 | }
|
---|
| 128 |
|
---|
[30356] | 129 | void UIHelpButton::initFrom(QPushButton *pOther)
|
---|
[25178] | 130 | {
|
---|
[71577] | 131 | /* Copy settings from pOther: */
|
---|
[30356] | 132 | setIcon(pOther->icon());
|
---|
| 133 | setText(pOther->text());
|
---|
| 134 | setShortcut(pOther->shortcut());
|
---|
| 135 | setFlat(pOther->isFlat());
|
---|
| 136 | setAutoDefault(pOther->autoDefault());
|
---|
| 137 | setDefault(pOther->isDefault());
|
---|
[71577] | 138 |
|
---|
| 139 | /* Apply language settings: */
|
---|
[104358] | 140 | sltRetranslateUI();
|
---|
[25178] | 141 | }
|
---|
| 142 |
|
---|
[104358] | 143 | void UIHelpButton::sltRetranslateUI()
|
---|
[25178] | 144 | {
|
---|
[30356] | 145 | QPushButton::setText(tr("&Help"));
|
---|
[25178] | 146 | if (QPushButton::shortcut().isEmpty())
|
---|
[103578] | 147 | QPushButton::setShortcut(UIShortcutPool::standardSequence(QKeySequence::HelpContents));
|
---|
[25178] | 148 | }
|
---|
| 149 |
|
---|
[71577] | 150 | # ifdef VBOX_WS_MAC
|
---|
[30356] | 151 | UIHelpButton::~UIHelpButton()
|
---|
[25178] | 152 | {
|
---|
[30356] | 153 | delete m_pNormalPixmap;
|
---|
| 154 | delete m_pPressedPixmap;
|
---|
| 155 | delete m_pMask;
|
---|
[25178] | 156 | }
|
---|
| 157 |
|
---|
[30356] | 158 | QSize UIHelpButton::sizeHint() const
|
---|
[25178] | 159 | {
|
---|
[30356] | 160 | return QSize(m_size.width() + PushButtonLeftOffset + PushButtonRightOffset,
|
---|
| 161 | m_size.height() + PushButtonTopOffset + PushButtonBottomOffset);
|
---|
[25178] | 162 | }
|
---|
| 163 |
|
---|
[71577] | 164 | void UIHelpButton::paintEvent(QPaintEvent *)
|
---|
[25178] | 165 | {
|
---|
[30356] | 166 | QPainter painter(this);
|
---|
| 167 | painter.drawPixmap(PushButtonLeftOffset, PushButtonTopOffset, m_pButtonPressed ? *m_pPressedPixmap: *m_pNormalPixmap);
|
---|
[25178] | 168 | }
|
---|
| 169 |
|
---|
[71577] | 170 | bool UIHelpButton::hitButton(const QPoint &position) const
|
---|
[25178] | 171 | {
|
---|
[71577] | 172 | if (m_BRect.contains(position))
|
---|
| 173 | return m_pMask->pixel(position.x() - PushButtonLeftOffset,
|
---|
| 174 | position.y() - PushButtonTopOffset) == 0xff000000;
|
---|
[25178] | 175 | else
|
---|
| 176 | return false;
|
---|
| 177 | }
|
---|
| 178 |
|
---|
[30356] | 179 | void UIHelpButton::mousePressEvent(QMouseEvent *pEvent)
|
---|
[25178] | 180 | {
|
---|
[100344] | 181 | if (hitButton(pEvent->position().toPoint()))
|
---|
[30356] | 182 | m_pButtonPressed = true;
|
---|
| 183 | QPushButton::mousePressEvent(pEvent);
|
---|
[25178] | 184 | update();
|
---|
| 185 | }
|
---|
| 186 |
|
---|
[30356] | 187 | void UIHelpButton::mouseReleaseEvent(QMouseEvent *pEvent)
|
---|
[25178] | 188 | {
|
---|
[30356] | 189 | QPushButton::mouseReleaseEvent(pEvent);
|
---|
| 190 | m_pButtonPressed = false;
|
---|
[25178] | 191 | update();
|
---|
| 192 | }
|
---|
| 193 |
|
---|
[71577] | 194 | void UIHelpButton::leaveEvent(QEvent *pEvent)
|
---|
[25178] | 195 | {
|
---|
[30356] | 196 | QPushButton::leaveEvent(pEvent);
|
---|
| 197 | m_pButtonPressed = false;
|
---|
[25178] | 198 | update();
|
---|
| 199 | }
|
---|
[71577] | 200 | # endif /* VBOX_WS_MAC */
|
---|
[25178] | 201 |
|
---|
| 202 |
|
---|
[71577] | 203 | #endif /* !VBOX_DARWIN_USE_NATIVE_CONTROLS */
|
---|