VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox4/include/VBoxToolBar.h@ 10631

Last change on this file since 10631 was 10519, checked in by vboxsync, 16 years ago

FE/Qt4-OSX: Try to fix the big/white window if the user clicks on a unified
toolbar with the right mouse key.

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