3
* VBox frontends: Qt GUI ("VirtualBox"):
4
* VBoxToolBar class declaration & implementation
8
* Copyright (C) 2006-2007 Sun Microsystems, Inc.
10
* This file is part of VirtualBox Open Source Edition (OSE), as
11
* available from http://www.virtualbox.org. This file is free software;
12
* you can redistribute it and/or modify it under the terms of the GNU
13
* General Public License (GPL) as published by the Free Software
14
* Foundation, in version 2 as it comes in the "COPYING" file of the
15
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
16
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
18
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
19
* Clara, CA 95054 USA or visit http://www.sun.com if you need
20
* additional information or have any questions.
23
#ifndef ___VBoxToolBar_h___
24
#define ___VBoxToolBar_h___
26
#include <QGlobalStatic> /* for Q_WS_MAC */
28
#include "VBoxUtils.h"
33
#include <QMainWindow>
36
/* Note: This styles are available on _all_ platforms. */
37
#include <QCleanlooksStyle>
38
#include <QWindowsStyle>
41
* The VBoxToolBar class is a simple QToolBar reimplementation to disable
42
* its built-in context menu and add some default behavior we need.
44
class VBoxToolBar : public QToolBar
49
VBoxToolBar (QWidget *aParent)
51
, mMainWindow (qobject_cast <QMainWindow*> (aParent))
56
/* Remove that ugly frame panel around the toolbar.
57
* Doing that currently for Cleanlooks & Windows styles. */
58
if (qobject_cast <QCleanlooksStyle*> (QToolBar::style()) ||
59
qobject_cast <QWindowsStyle*> (QToolBar::style()))
60
setStyleSheet ("QToolBar { border: 0px none black; }");
63
layout()->setContentsMargins (0, 0, 0, 0);;
65
setContextMenuPolicy (Qt::NoContextMenu);
73
mMainWindow->setUnifiedTitleAndToolBarOnMac (true);
74
#ifndef QT_MAC_USE_COCOA
75
WindowRef window = ::darwinToNativeWindow (this);
76
EventHandlerUPP eventHandler = ::NewEventHandlerUPP (VBoxToolBar::macEventFilter);
77
EventTypeSpec eventTypes[2];
78
eventTypes[0].eventClass = kEventClassMouse;
79
eventTypes[0].eventKind = kEventMouseDown;
80
eventTypes[1].eventClass = kEventClassMouse;
81
eventTypes[1].eventKind = kEventMouseUp;
82
InstallWindowEventHandler (window, eventHandler,
83
RT_ELEMENTS (eventTypes), eventTypes,
85
#endif /* !QT_MAC_USE_COCOA */
89
#ifndef QT_MAC_USE_COCOA
90
static pascal OSStatus macEventFilter (EventHandlerCallRef aNextHandler,
91
EventRef aEvent, void * /* aUserData */)
93
UInt32 eclass = GetEventClass (aEvent);
94
if (eclass == kEventClassMouse)
96
WindowPartCode partCode;
97
GetEventParameter (aEvent, kEventParamWindowPartCode, typeWindowPartCode, NULL, sizeof (WindowPartCode), NULL, &partCode);
98
UInt32 ekind = GetEventKind (aEvent);
101
if(ekind == kEventMouseDown || ekind == kEventMouseUp)
103
EventMouseButton button = 0;
104
GetEventParameter (aEvent, kEventParamMouseButton, typeMouseButton, NULL, sizeof (button), NULL, &button);
105
if (button != kEventMouseButtonPrimary)
109
return CallNextEventHandler (aNextHandler, aEvent);
111
#endif /* !QT_MAC_USE_COCOA */
113
void setShowToolBarButton (bool aShow)
115
::darwinSetShowsToolbarButton (this, aShow);
117
#endif /* Q_WS_MAC */
119
void setUsesTextLabel (bool aEnable)
121
Qt::ToolButtonStyle tbs = Qt::ToolButtonTextUnderIcon;
123
tbs = Qt::ToolButtonIconOnly;
126
mMainWindow->setToolButtonStyle (tbs);
128
setToolButtonStyle (tbs);
133
QMainWindow *mMainWindow;
136
#endif // !___VBoxToolBar_h___