VirtualBox

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

Last change on this file since 17147 was 17126, checked in by vboxsync, 16 years ago

FE/Qt-OSX: Make the handling of Darwin tasks more generic for Carbon & Cocoa. Disable settings window animation on Cocoa.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.8 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# ifdef QT_MAC_USE_COCOA
81 /** @todo Carbon -> Cocoa */
82# else /* !QT_MAC_USE_COCOA */
83 WindowRef window = ::darwinToNativeWindow (this);
84 EventHandlerUPP eventHandler = ::NewEventHandlerUPP (VBoxToolBar::macEventFilter);
85 EventTypeSpec eventTypes[2];
86 eventTypes[0].eventClass = kEventClassMouse;
87 eventTypes[0].eventKind = kEventMouseDown;
88 eventTypes[1].eventClass = kEventClassMouse;
89 eventTypes[1].eventKind = kEventMouseUp;
90 InstallWindowEventHandler (window, eventHandler,
91 RT_ELEMENTS (eventTypes), eventTypes,
92 NULL, NULL);
93# endif /* !QT_MAC_USE_COCOA */
94 }
95#endif /* Q_WS_MAC */
96 }
97
98#if defined(Q_WS_MAC) && !defined(QT_MAC_USE_COCOA)
99 static pascal OSStatus macEventFilter (EventHandlerCallRef aNextHandler,
100 EventRef aEvent, void * /* aUserData */)
101 {
102 UInt32 eclass = GetEventClass (aEvent);
103 if (eclass == kEventClassMouse)
104 {
105 WindowPartCode partCode;
106 GetEventParameter (aEvent, kEventParamWindowPartCode, typeWindowPartCode, NULL, sizeof (WindowPartCode), NULL, &partCode);
107 UInt32 ekind = GetEventKind (aEvent);
108 if (partCode == 15 ||
109 partCode == 4)
110 if(ekind == kEventMouseDown || ekind == kEventMouseUp)
111 {
112 EventMouseButton button = 0;
113 GetEventParameter (aEvent, kEventParamMouseButton, typeMouseButton, NULL, sizeof (button), NULL, &button);
114 if (button != kEventMouseButtonPrimary)
115 return noErr;
116 }
117 }
118 return CallNextEventHandler (aNextHandler, aEvent);
119 }
120#endif /* Q_WS_MAC && !QT_MAC_USE_COCOA */
121
122 void setShowToolBarButton (bool aShow)
123 {
124#ifdef Q_WS_MAC
125 ::darwinSetShowsToolbarButton (this, aShow);
126#else /* Q_WS_MAC */
127 NOREF (aShow);
128#endif /* !Q_WS_MAC */
129 }
130
131 void setUsesTextLabel (bool enable)
132 {
133 Qt::ToolButtonStyle tbs = Qt::ToolButtonTextUnderIcon;
134 if (!enable)
135 tbs = Qt::ToolButtonIconOnly;
136
137 if (mMainWindow)
138 mMainWindow->setToolButtonStyle (tbs);
139 else
140 setToolButtonStyle (tbs);
141 }
142
143private:
144
145 QMainWindow *mMainWindow;
146};
147
148#endif // !___VBoxToolBar_h___
149
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