VirtualBox

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

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

Fe/Qt4: Reforming Information Dialog's margins according VM details.

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