VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/widgets/UISpecialControls.cpp@ 103977

Last change on this file since 103977 was 103578, checked in by vboxsync, 9 months ago

FE/Qt: UIShortcutPool: macOS no more support CMD+? as the default one help Contents shortcut; Let's use another one like CMD+/ (which is same just with Shift modifier released, because CMD+Shift+? now used for system-wide help Search menu).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.6 KB
Line 
1/* $Id: UISpecialControls.cpp 103578 2024-02-26 17:29:33Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UISpecialControls implementation.
4 */
5
6/*
7 * Copyright (C) 2009-2023 Oracle and/or its affiliates.
8 *
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
26 */
27
28/* Qt includes: */
29#include <QHBoxLayout>
30#ifndef VBOX_DARWIN_USE_NATIVE_CONTROLS
31# include <QBitmap>
32# include <QMouseEvent>
33# include <QPainter>
34# include <QSignalMapper>
35#endif
36
37/* GUI includes: */
38#include "UIIconPool.h"
39#include "UIShortcutPool.h"
40#include "UISpecialControls.h"
41
42
43#ifdef VBOX_DARWIN_USE_NATIVE_CONTROLS
44
45
46/*********************************************************************************************************************************
47* Class UIMiniCancelButton implementation. *
48*********************************************************************************************************************************/
49
50UIMiniCancelButton::UIMiniCancelButton(QWidget *pParent /* = 0 */)
51 : QAbstractButton(pParent)
52{
53 setShortcut(QKeySequence(Qt::Key_Escape));
54 m_pButton = new UICocoaButton(this, UICocoaButton::CancelButton);
55 connect(m_pButton, SIGNAL(clicked()), this, SIGNAL(clicked()));
56 setFixedSize(m_pButton->size());
57}
58
59void UIMiniCancelButton::resizeEvent(QResizeEvent *)
60{
61 m_pButton->resize(size());
62}
63
64
65/*********************************************************************************************************************************
66* Class UIHelpButton implementation. *
67*********************************************************************************************************************************/
68
69UIHelpButton::UIHelpButton(QWidget *pParent /* = 0 */)
70 : QPushButton(pParent)
71{
72 setShortcut(UIShortcutPool::standardSequence(QKeySequence::HelpContents));
73 m_pButton = new UICocoaButton(this, UICocoaButton::HelpButton);
74 connect(m_pButton, SIGNAL(clicked()), this, SIGNAL(clicked()));
75 setFixedSize(m_pButton->size());
76}
77
78
79#else /* !VBOX_DARWIN_USE_NATIVE_CONTROLS */
80
81
82/*********************************************************************************************************************************
83* Class UIMiniCancelButton implementation. *
84*********************************************************************************************************************************/
85
86UIMiniCancelButton::UIMiniCancelButton(QWidget *pParent /* = 0 */)
87 : QIWithRetranslateUI<QIToolButton>(pParent)
88{
89 setAutoRaise(true);
90 setFocusPolicy(Qt::TabFocus);
91 setShortcut(QKeySequence(Qt::Key_Escape));
92 setIcon(UIIconPool::defaultIcon(UIIconPool::UIDefaultIconType_DialogCancel));
93}
94
95
96/*********************************************************************************************************************************
97* Class UIHelpButton implementation. *
98*********************************************************************************************************************************/
99
100/* From: src/gui/styles/qmacstyle_mac.cpp */
101static const int PushButtonLeftOffset = 6;
102static const int PushButtonTopOffset = 4;
103static const int PushButtonRightOffset = 12;
104static const int PushButtonBottomOffset = 4;
105
106UIHelpButton::UIHelpButton(QWidget *pParent /* = 0 */)
107 : QIWithRetranslateUI<QPushButton>(pParent)
108{
109# ifdef VBOX_WS_MAC
110 m_pButtonPressed = false;
111 m_pNormalPixmap = new QPixmap(":/help_button_normal_mac_24px.png");
112 m_pPressedPixmap = new QPixmap(":/help_button_pressed_mac_24px.png");
113 m_size = m_pNormalPixmap->size();
114 m_pMask = new QImage(m_pNormalPixmap->mask().toImage());
115 m_BRect = QRect(PushButtonLeftOffset,
116 PushButtonTopOffset,
117 m_size.width(),
118 m_size.height());
119# endif /* VBOX_WS_MAC */
120
121 /* Apply language settings: */
122 retranslateUi();
123}
124
125void UIHelpButton::initFrom(QPushButton *pOther)
126{
127 /* Copy settings from pOther: */
128 setIcon(pOther->icon());
129 setText(pOther->text());
130 setShortcut(pOther->shortcut());
131 setFlat(pOther->isFlat());
132 setAutoDefault(pOther->autoDefault());
133 setDefault(pOther->isDefault());
134
135 /* Apply language settings: */
136 retranslateUi();
137}
138
139void UIHelpButton::retranslateUi()
140{
141 QPushButton::setText(tr("&Help"));
142 if (QPushButton::shortcut().isEmpty())
143 QPushButton::setShortcut(UIShortcutPool::standardSequence(QKeySequence::HelpContents));
144}
145
146# ifdef VBOX_WS_MAC
147UIHelpButton::~UIHelpButton()
148{
149 delete m_pNormalPixmap;
150 delete m_pPressedPixmap;
151 delete m_pMask;
152}
153
154QSize UIHelpButton::sizeHint() const
155{
156 return QSize(m_size.width() + PushButtonLeftOffset + PushButtonRightOffset,
157 m_size.height() + PushButtonTopOffset + PushButtonBottomOffset);
158}
159
160void UIHelpButton::paintEvent(QPaintEvent *)
161{
162 QPainter painter(this);
163 painter.drawPixmap(PushButtonLeftOffset, PushButtonTopOffset, m_pButtonPressed ? *m_pPressedPixmap: *m_pNormalPixmap);
164}
165
166bool UIHelpButton::hitButton(const QPoint &position) const
167{
168 if (m_BRect.contains(position))
169 return m_pMask->pixel(position.x() - PushButtonLeftOffset,
170 position.y() - PushButtonTopOffset) == 0xff000000;
171 else
172 return false;
173}
174
175void UIHelpButton::mousePressEvent(QMouseEvent *pEvent)
176{
177 if (hitButton(pEvent->position().toPoint()))
178 m_pButtonPressed = true;
179 QPushButton::mousePressEvent(pEvent);
180 update();
181}
182
183void UIHelpButton::mouseReleaseEvent(QMouseEvent *pEvent)
184{
185 QPushButton::mouseReleaseEvent(pEvent);
186 m_pButtonPressed = false;
187 update();
188}
189
190void UIHelpButton::leaveEvent(QEvent *pEvent)
191{
192 QPushButton::leaveEvent(pEvent);
193 m_pButtonPressed = false;
194 update();
195}
196# endif /* VBOX_WS_MAC */
197
198
199#endif /* !VBOX_DARWIN_USE_NATIVE_CONTROLS */
200
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette