VirtualBox

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

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

FE/Qt4: Removed last Qt3 bits. If some of this classes is needed later again we have to look at subversion.

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