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