VirtualBox

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

Last change on this file since 35740 was 30694, checked in by vboxsync, 14 years ago

FE/Qt4: UITexturedSegmentedButton for non OSX

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.6 KB
Line 
1/* $Id: UISpecialControls.cpp 30694 2010-07-07 09:24:18Z vboxsync $ */
2/** @file
3 *
4 * VBox frontends: Qt GUI ("VirtualBox"):
5 * VBoxSpecialButtons implementation
6 */
7
8/*
9 * Copyright (C) 2009-2010 Oracle Corporation
10 *
11 * This file is part of VirtualBox Open Source Edition (OSE), as
12 * available from http://www.virtualbox.org. This file is free software;
13 * you can redistribute it and/or modify it under the terms of the GNU
14 * General Public License (GPL) as published by the Free Software
15 * Foundation, in version 2 as it comes in the "COPYING" file of the
16 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
17 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
18 */
19
20/* VBox includes */
21#include "UIIconPool.h"
22#include "UISpecialControls.h"
23
24/* Global includes */
25#include <QHBoxLayout>
26
27#ifdef VBOX_DARWIN_USE_NATIVE_CONTROLS
28
29/********************************************************************************
30 *
31 * A mini cancel button in the native Cocoa version.
32 *
33 ********************************************************************************/
34UIMiniCancelButton::UIMiniCancelButton(QWidget *pParent /* = 0 */)
35 : QAbstractButton(pParent)
36{
37 setShortcut(QKeySequence(Qt::Key_Escape));
38 m_pButton = new UICocoaButton(UICocoaButton::CancelButton, this);
39 connect(m_pButton, SIGNAL(clicked()),
40 this, SIGNAL(clicked()));
41 setFixedSize(m_pButton->size());
42}
43
44void UIMiniCancelButton::resizeEvent(QResizeEvent * /* pEvent */)
45{
46 m_pButton->resize(size());
47}
48
49/********************************************************************************
50 *
51 * A rest button in the native Cocoa version.
52 *
53 ********************************************************************************/
54UIResetButton::UIResetButton(QWidget *pParent /* = 0 */)
55 : QAbstractButton(pParent)
56{
57 m_pButton = new UICocoaButton(UICocoaButton::ResetButton, this);
58 connect(m_pButton, SIGNAL(clicked()),
59 this, SIGNAL(clicked()));
60 setFixedSize(m_pButton->size());
61}
62
63void UIResetButton::resizeEvent(QResizeEvent * /* pEvent */)
64{
65 m_pButton->resize(size());
66}
67
68/********************************************************************************
69 *
70 * A help button in the native Cocoa version.
71 *
72 ********************************************************************************/
73UIHelpButton::UIHelpButton(QWidget *pParent /* = 0 */)
74 : QPushButton(pParent)
75{
76 setShortcut(QKeySequence(QKeySequence::HelpContents));
77 m_pButton = new UICocoaButton(UICocoaButton::HelpButton, this);
78 connect(m_pButton, SIGNAL(clicked()),
79 this, SIGNAL(clicked()));
80 setFixedSize(m_pButton->size());
81}
82
83/********************************************************************************
84 *
85 * A segmented button in the native Cocoa version.
86 *
87 ********************************************************************************/
88UIRoundRectSegmentedButton::UIRoundRectSegmentedButton(int cCount, QWidget *pParent /* = 0 */)
89 : UICocoaSegmentedButton(cCount, UICocoaSegmentedButton::RoundRectSegment, pParent)
90{
91}
92
93UITexturedSegmentedButton::UITexturedSegmentedButton(int cCount, QWidget *pParent /* = 0 */)
94 : UICocoaSegmentedButton(cCount, UICocoaSegmentedButton::TexturedRoundedSegment, pParent)
95{
96}
97
98/********************************************************************************
99 *
100 * A search field in the native Cocoa version.
101 *
102 ********************************************************************************/
103UISearchField::UISearchField(QWidget *pParent /* = 0 */)
104 : UICocoaSearchField(pParent)
105{
106}
107
108#else /* VBOX_DARWIN_USE_NATIVE_CONTROLS */
109
110/* Qt includes */
111#include <QPainter>
112#include <QBitmap>
113#include <QMouseEvent>
114#include <QSignalMapper>
115
116/********************************************************************************
117 *
118 * A mini cancel button for the other OS's.
119 *
120 ********************************************************************************/
121UIMiniCancelButton::UIMiniCancelButton(QWidget *pParent /* = 0 */)
122 : QIWithRetranslateUI<QIToolButton>(pParent)
123{
124 setAutoRaise(true);
125 setFocusPolicy(Qt::TabFocus);
126 setShortcut(QKeySequence(Qt::Key_Escape));
127 setIcon(UIIconPool::defaultIcon(UIIconPool::DialogCancelIcon));
128}
129
130void UIMiniCancelButton::removeBorder()
131{
132 setStyleSheet("QToolButton { border: 0px }");
133}
134
135/********************************************************************************
136 *
137 * A help button for the other OS's.
138 *
139 ********************************************************************************/
140/* From: src/gui/styles/qmacstyle_mac.cpp */
141static const int PushButtonLeftOffset = 6;
142static const int PushButtonTopOffset = 4;
143static const int PushButtonRightOffset = 12;
144static const int PushButtonBottomOffset = 4;
145
146UIHelpButton::UIHelpButton(QWidget *pParent /* = 0 */)
147 : QIWithRetranslateUI<QPushButton>(pParent)
148{
149#ifdef Q_WS_MAC
150 m_pButtonPressed = false;
151 m_pNormalPixmap = new QPixmap(":/help_button_normal_mac_22px.png");
152 m_pPressedPixmap = new QPixmap(":/help_button_pressed_mac_22px.png");
153 m_size = m_pNormalPixmap->size();
154 m_pMask = new QImage(m_pNormalPixmap->mask().toImage());
155 m_BRect = QRect(PushButtonLeftOffset,
156 PushButtonTopOffset,
157 m_size.width(),
158 m_size.height());
159#endif /* Q_WS_MAC */
160 /* Applying language settings */
161 retranslateUi();
162}
163
164void UIHelpButton::initFrom(QPushButton *pOther)
165{
166 setIcon(pOther->icon());
167 setText(pOther->text());
168 setShortcut(pOther->shortcut());
169 setFlat(pOther->isFlat());
170 setAutoDefault(pOther->autoDefault());
171 setDefault(pOther->isDefault());
172 /* Applying language settings */
173 retranslateUi();
174}
175
176void UIHelpButton::retranslateUi()
177{
178 QPushButton::setText(tr("&Help"));
179 if (QPushButton::shortcut().isEmpty())
180 QPushButton::setShortcut(QKeySequence::HelpContents);
181}
182
183#ifdef Q_WS_MAC
184UIHelpButton::~UIHelpButton()
185{
186 delete m_pNormalPixmap;
187 delete m_pPressedPixmap;
188 delete m_pMask;
189}
190
191QSize UIHelpButton::sizeHint() const
192{
193 return QSize(m_size.width() + PushButtonLeftOffset + PushButtonRightOffset,
194 m_size.height() + PushButtonTopOffset + PushButtonBottomOffset);
195}
196
197void UIHelpButton::paintEvent(QPaintEvent * /* pEvent */)
198{
199 QPainter painter(this);
200 painter.drawPixmap(PushButtonLeftOffset, PushButtonTopOffset, m_pButtonPressed ? *m_pPressedPixmap: *m_pNormalPixmap);
201}
202
203bool UIHelpButton::hitButton(const QPoint &pos) const
204{
205 if (m_BRect.contains(pos))
206 return m_pMask->pixel(pos.x() - PushButtonLeftOffset,
207 pos.y() - PushButtonTopOffset) == 0xff000000;
208 else
209 return false;
210}
211
212void UIHelpButton::mousePressEvent(QMouseEvent *pEvent)
213{
214 if (hitButton(pEvent->pos()))
215 m_pButtonPressed = true;
216 QPushButton::mousePressEvent(pEvent);
217 update();
218}
219
220void UIHelpButton::mouseReleaseEvent(QMouseEvent *pEvent)
221{
222 QPushButton::mouseReleaseEvent(pEvent);
223 m_pButtonPressed = false;
224 update();
225}
226
227void UIHelpButton::leaveEvent(QEvent * pEvent)
228{
229 QPushButton::leaveEvent(pEvent);
230 m_pButtonPressed = false;
231 update();
232}
233#endif /* Q_WS_MAC */
234
235/********************************************************************************
236 *
237 * A segmented button for the other OS's.
238 *
239 ********************************************************************************/
240UIRoundRectSegmentedButton::UIRoundRectSegmentedButton(int aCount, QWidget *pParent /* = 0 */)
241 : QWidget(pParent)
242{
243 m_pSignalMapper = new QSignalMapper(this);
244
245 QHBoxLayout *layout = new QHBoxLayout(this);
246 for (int i=0; i < aCount; ++i)
247 {
248 QIToolButton *button = new QIToolButton(this);
249 button->setAutoRaise(true);
250 button->setFocusPolicy(Qt::TabFocus);
251 button->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
252 m_pButtons.append(button);
253 layout->addWidget(button);
254 connect(button, SIGNAL(clicked()),
255 m_pSignalMapper, SLOT(map()));
256 m_pSignalMapper->setMapping(button, i);
257 }
258 connect(m_pSignalMapper, SIGNAL(mapped(int)),
259 this, SIGNAL(clicked(int)));
260
261}
262
263UIRoundRectSegmentedButton::~UIRoundRectSegmentedButton()
264{
265 delete m_pSignalMapper;
266 qDeleteAll(m_pButtons);
267}
268
269void UIRoundRectSegmentedButton::setTitle(int iSegment, const QString &aTitle)
270{
271 m_pButtons.at(iSegment)->setText(aTitle);
272}
273
274void UIRoundRectSegmentedButton::setToolTip(int iSegment, const QString &strTip)
275{
276 m_pButtons.at(iSegment)->setToolTip(strTip);
277}
278
279void UIRoundRectSegmentedButton::setIcon(int iSegment, const QIcon &icon)
280{
281 m_pButtons.at(iSegment)->setIcon(icon);
282}
283
284void UIRoundRectSegmentedButton::setEnabled(int iSegment, bool fEnabled)
285{
286 m_pButtons.at(iSegment)->setEnabled(fEnabled);
287}
288
289void UIRoundRectSegmentedButton::animateClick(int iSegment)
290{
291 m_pButtons.at(iSegment)->animateClick();
292}
293
294UITexturedSegmentedButton::UITexturedSegmentedButton(int cCount, QWidget *pParent /* = 0 */)
295 : UIRoundRectSegmentedButton(cCount, pParent)
296{
297 for (int i=0; i < m_pButtons.size(); ++i)
298 {
299 m_pButtons.at(i)->setAutoExclusive(true);
300 m_pButtons.at(i)->setCheckable(true);
301 }
302}
303
304/********************************************************************************
305 *
306 * A search field for the other OS's.
307 *
308 ********************************************************************************/
309UISearchField::UISearchField(QWidget *pParent /* = 0 */)
310 : QLineEdit(pParent)
311{
312 m_baseBrush = palette().base();
313}
314
315void UISearchField::markError()
316{
317 QPalette pal = palette();
318 QColor c(Qt::red);
319 c.setAlphaF(0.3);
320 pal.setBrush(QPalette::Base, c);
321 setPalette(pal);
322}
323
324void UISearchField::unmarkError()
325{
326 QPalette pal = palette();
327 pal.setBrush(QPalette::Base, m_baseBrush);
328 setPalette(pal);
329}
330
331#endif /* VBOX_DARWIN_USE_NATIVE_CONTROLS */
332
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use