VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/include/VBoxToolBar.h@ 19149

Last change on this file since 19149 was 17349, checked in by vboxsync, 16 years ago

FE/Qt4-OSX: more Cocoa clean up

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.7 KB
Line 
1/** @file
2 *
3 * VBox frontends: Qt GUI ("VirtualBox"):
4 * VBoxToolBar class declaration & implementation
5 */
6
7/*
8 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
9 *
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.
17 *
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.
21 */
22
23#ifndef ___VBoxToolBar_h___
24#define ___VBoxToolBar_h___
25
26
27#ifdef Q_WS_MAC
28# include "VBoxUtils.h"
29#endif
30
31/* Qt includes */
32#include <QToolBar>
33#include <QMainWindow>
34
35/* Note: This styles are available on _all_ platforms. */
36#include <QCleanlooksStyle>
37#include <QWindowsStyle>
38
39/**
40 * The VBoxToolBar class is a simple QToolBar reimplementation to disable
41 * its built-in context menu and add some default behavior we need.
42 */
43class VBoxToolBar : public QToolBar
44{
45
46public:
47
48 VBoxToolBar (QWidget *aParent)
49 : QToolBar (aParent)
50 , mMainWindow (qobject_cast<QMainWindow*> (aParent))
51 {
52 setFloatable (false);
53 setMovable (false);
54 if (layout())
55 layout()->setContentsMargins (0, 0, 0, 0);;
56
57 setContextMenuPolicy (Qt::NoContextMenu);
58
59 /* Remove that ugly frame panel around the toolbar. */
60 /* I'm not sure if we should do this generally on linux for that mass
61 * of KDE styles. But maybe some of them are based on CleanLooks so
62 * they are looking ok also. */
63 QStyle *style = NULL;
64 if (!style)
65 /* Check for cleanlooks style */
66 style = qobject_cast<QCleanlooksStyle*> (QToolBar::style());
67 if (!style)
68 /* Check for windows style */
69 style = qobject_cast<QWindowsStyle*> (QToolBar::style());
70 if (style)
71 setStyleSheet ("QToolBar { border: 0px none black; }");
72 }
73
74 void setMacToolbar ()
75 {
76#ifdef Q_WS_MAC
77 if (mMainWindow)
78 {
79 mMainWindow->setUnifiedTitleAndToolBarOnMac (true);
80# ifndef QT_MAC_USE_COCOA
81 WindowRef window = ::darwinToNativeWindow (this);
82 EventHandlerUPP eventHandler = ::NewEventHandlerUPP (VBoxToolBar::macEventFilter);
83 EventTypeSpec eventTypes[2];
84 eventTypes[0].eventClass = kEventClassMouse;
85 eventTypes[0].eventKind = kEventMouseDown;
86 eventTypes[1].eventClass = kEventClassMouse;
87 eventTypes[1].eventKind = kEventMouseUp;
88 InstallWindowEventHandler (window, eventHandler,
89 RT_ELEMENTS (eventTypes), eventTypes,
90 NULL, NULL);
91# endif /* !QT_MAC_USE_COCOA */
92 }
93#endif /* Q_WS_MAC */
94 }
95
96#if defined(Q_WS_MAC) && !defined(QT_MAC_USE_COCOA)
97 static pascal OSStatus macEventFilter (EventHandlerCallRef aNextHandler,
98 EventRef aEvent, void * /* aUserData */)
99 {
100 UInt32 eclass = GetEventClass (aEvent);
101 if (eclass == kEventClassMouse)
102 {
103 WindowPartCode partCode;
104 GetEventParameter (aEvent, kEventParamWindowPartCode, typeWindowPartCode, NULL, sizeof (WindowPartCode), NULL, &partCode);
105 UInt32 ekind = GetEventKind (aEvent);
106 if (partCode == 15 ||
107 partCode == 4)
108 if(ekind == kEventMouseDown || ekind == kEventMouseUp)
109 {
110 EventMouseButton button = 0;
111 GetEventParameter (aEvent, kEventParamMouseButton, typeMouseButton, NULL, sizeof (button), NULL, &button);
112 if (button != kEventMouseButtonPrimary)
113 return noErr;
114 }
115 }
116 return CallNextEventHandler (aNextHandler, aEvent);
117 }
118#endif /* Q_WS_MAC && !QT_MAC_USE_COCOA */
119
120 void setShowToolBarButton (bool aShow)
121 {
122#ifdef Q_WS_MAC
123 ::darwinSetShowsToolbarButton (this, aShow);
124#else /* Q_WS_MAC */
125 NOREF (aShow);
126#endif /* !Q_WS_MAC */
127 }
128
129 void setUsesTextLabel (bool enable)
130 {
131 Qt::ToolButtonStyle tbs = Qt::ToolButtonTextUnderIcon;
132 if (!enable)
133 tbs = Qt::ToolButtonIconOnly;
134
135 if (mMainWindow)
136 mMainWindow->setToolButtonStyle (tbs);
137 else
138 setToolButtonStyle (tbs);
139 }
140
141private:
142
143 QMainWindow *mMainWindow;
144};
145
146#endif // !___VBoxToolBar_h___
147
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