VirtualBox

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

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

FE/Qt4-OSX: Enable a resize animation on the settings dialog if a new settings
page is selected.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.1 KB
Line 
1/** @file
2 *
3 * VBox frontends: Qt GUI ("VirtualBox"):
4 * Declarations of utility classes and functions
5 */
6
7/*
8 * Copyright (C) 2006-2008 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 __VBoxUtils_h__
24#define __VBoxUtils_h__
25
26/* Qt includes */
27#include <QMouseEvent>
28#include <QWidget>
29
30/**
31 * Simple class that filters out all key presses and releases
32 * got while the Alt key is pressed. For some very strange reason,
33 * QLineEdit accepts those combinations that are not used as accelerators,
34 * and inserts the corresponding characters to the entry field.
35 */
36class QIAltKeyFilter : protected QObject
37{
38 Q_OBJECT;
39
40public:
41
42 QIAltKeyFilter (QObject *aParent) :QObject (aParent) {}
43
44 void watchOn (QObject *aObject) { aObject->installEventFilter (this); }
45
46protected:
47
48 bool eventFilter (QObject * /* aObject */, QEvent *aEvent)
49 {
50 if (aEvent->type() == QEvent::KeyPress || aEvent->type() == QEvent::KeyRelease)
51 {
52 QKeyEvent *event = static_cast<QKeyEvent *> (aEvent);
53 if (event->modifiers() & Qt::AltModifier)
54 return true;
55 }
56 return false;
57 }
58};
59
60/**
61 * Simple class which simulates focus-proxy rule redirecting widget
62 * assigned shortcut to desired widget.
63 */
64class QIFocusProxy : protected QObject
65{
66 Q_OBJECT;
67
68public:
69
70 QIFocusProxy (QWidget *aFrom, QWidget *aTo)
71 : QObject (aFrom), mFrom (aFrom), mTo (aTo)
72 {
73 mFrom->installEventFilter (this);
74 }
75
76protected:
77
78 bool eventFilter (QObject *aObject, QEvent *aEvent)
79 {
80 if (aObject == mFrom && aEvent->type() == QEvent::Shortcut)
81 {
82 mTo->setFocus();
83 return true;
84 }
85 return QObject::eventFilter (aObject, aEvent);
86 }
87
88 QWidget *mFrom;
89 QWidget *mTo;
90};
91
92#ifdef Q_WS_MAC
93# undef PAGE_SIZE
94# undef PAGE_SHIFT
95# include <Carbon/Carbon.h>
96
97/* Asserts if a != noErr and prints the error code */
98#define AssertCarbonOSStatus(a) AssertMsg ((a) == noErr, ("Carbon OSStatus: %d\n", static_cast<int> (a)))
99
100class QImage;
101class QPixmap;
102class QToolBar;
103class VBoxFrameBuffer;
104
105/* Converting stuff */
106CGImageRef darwinToCGImageRef (const QImage *aImage);
107CGImageRef darwinToCGImageRef (const QPixmap *aPixmap);
108CGImageRef darwinToCGImageRef (const char *aSource);
109
110/**
111 * Returns a reference to the HIView of the QWidget.
112 *
113 * @returns HIViewRef of the QWidget.
114 * @param aWidget Pointer to the QWidget
115 */
116inline HIViewRef darwinToHIViewRef (QWidget *aWidget)
117{
118 return HIViewRef(aWidget->winId());
119}
120
121/**
122 * Returns a reference to the Window of the HIView.
123 *
124 * @returns WindowRef of the HIView.
125 * @param aViewRef Reference to the HIView
126 */
127inline WindowRef darwinToWindowRef (HIViewRef aViewRef)
128{
129 return reinterpret_cast<WindowRef> (HIViewGetWindow(aViewRef));
130}
131
132/**
133 * Returns a reference to the Window of the QWidget.
134 *
135 * @returns WindowRef of the QWidget.
136 * @param aWidget Pointer to the QWidget
137 */
138inline WindowRef darwinToWindowRef (QWidget *aWidget)
139{
140 return ::darwinToWindowRef (::darwinToHIViewRef (aWidget));
141}
142
143/**
144 * Returns a reference to the CGContext of the QWidget.
145 *
146 * @returns CGContextRef of the QWidget.
147 * @param aWidget Pointer to the QWidget
148 */
149inline CGContextRef darwinToCGContextRef (QWidget *aWidget)
150{
151 return static_cast<CGContext *> (aWidget->macCGHandle());
152}
153
154/**
155 * Converts a QRect to a HIRect.
156 *
157 * @returns HIRect for the converted QRect.
158 * @param aRect the QRect to convert
159 */
160inline HIRect darwinToHIRect (const QRect &aRect)
161{
162 return CGRectMake (aRect.x(), aRect.y(), aRect.width(), aRect.height());
163}
164
165void darwinSetShowToolBarButton (QToolBar *aToolBar, bool aShow);
166
167void darwinWindowAnimateResize (QWidget *aWidget, const QRect &aTarget);
168
169/* Proxy icon creation */
170QPixmap darwinCreateDragPixmap (const QPixmap& aPixmap, const QString &aText);
171
172/* Special routines for the dock handling */
173CGImageRef darwinCreateDockBadge (const char *aSource);
174void darwinUpdateDockPreview (CGImageRef aVMImage, CGImageRef aOverlayImage, CGImageRef aStateImage = NULL);
175void darwinUpdateDockPreview (VBoxFrameBuffer *aFrameBuffer, CGImageRef aOverlayImage);
176
177/* Icons in the menu of an mac application are unusual. */
178void darwinDisableIconsInMenus();
179
180/* Experimental region handler for the seamless mode */
181OSStatus darwinRegionHandler (EventHandlerCallRef aInHandlerCallRef, EventRef aInEvent, void *aInUserData);
182
183# ifdef DEBUG
184void darwinDebugPrintEvent (const char *aPrefix, EventRef aEvent);
185# endif
186#endif /* Q_WS_MAC */
187
188#endif // __VBoxUtils_h__
189
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