VirtualBox

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

Last change on this file since 10219 was 10165, checked in by vboxsync, 17 years ago

Fe/Qt4: Get rid of warning concerning Q_OBJECT.

  • 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 * 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 VBoxFrameBuffer;
103
104/* Converting stuff */
105CGImageRef darwinToCGImageRef (const QImage *aImage);
106CGImageRef darwinToCGImageRef (const QPixmap *aPixmap);
107CGImageRef darwinToCGImageRef (const char *aSource);
108
109/**
110 * Returns a reference to the HIView of the QWidget.
111 *
112 * @returns HIViewRef of the QWidget.
113 * @param aWidget Pointer to the QWidget
114 */
115inline HIViewRef darwinToHIViewRef (QWidget *aWidget)
116{
117 return HIViewRef(aWidget->winId());
118}
119
120/**
121 * Returns a reference to the Window of the HIView.
122 *
123 * @returns WindowRef of the HIView.
124 * @param aViewRef Reference to the HIView
125 */
126inline WindowRef darwinToWindowRef (HIViewRef aViewRef)
127{
128 return reinterpret_cast<WindowRef> (HIViewGetWindow(aViewRef));
129}
130
131/**
132 * Returns a reference to the Window of the QWidget.
133 *
134 * @returns WindowRef of the QWidget.
135 * @param aWidget Pointer to the QWidget
136 */
137inline WindowRef darwinToWindowRef (QWidget *aWidget)
138{
139 return ::darwinToWindowRef (::darwinToHIViewRef (aWidget));
140}
141
142/**
143 * Returns a reference to the CGContext of the QWidget.
144 *
145 * @returns CGContextRef of the QWidget.
146 * @param aWidget Pointer to the QWidget
147 */
148inline CGContextRef darwinToCGContextRef (QWidget *aWidget)
149{
150 return static_cast<CGContext *> (aWidget->macCGHandle());
151}
152
153/**
154 * Converts a QRect to a HIRect.
155 *
156 * @returns HIRect for the converted QRect.
157 * @param aRect the QRect to convert
158 */
159inline HIRect darwinToHIRect (const QRect &aRect)
160{
161 return CGRectMake (aRect.x(), aRect.y(), aRect.width(), aRect.height());
162}
163
164/* Proxy icon creation */
165QPixmap darwinCreateDragPixmap (const QPixmap& aPixmap, const QString &aText);
166
167/* Special routines for the dock handling */
168CGImageRef darwinCreateDockBadge (const char *aSource);
169void darwinUpdateDockPreview (CGImageRef aVMImage, CGImageRef aOverlayImage, CGImageRef aStateImage = NULL);
170void darwinUpdateDockPreview (VBoxFrameBuffer *aFrameBuffer, CGImageRef aOverlayImage);
171
172/* Icons in the menu of an mac application are unusual. */
173void darwinDisableIconsInMenus();
174
175/* Experimental region handler for the seamless mode */
176OSStatus darwinRegionHandler (EventHandlerCallRef aInHandlerCallRef, EventRef aInEvent, void *aInUserData);
177
178# ifdef DEBUG
179void darwinDebugPrintEvent (const char *aPrefix, EventRef aEvent);
180# endif
181#endif /* Q_WS_MAC */
182
183#endif // __VBoxUtils_h__
184
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette