VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/include/VBoxUtils.h@ 20554

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

FE/Qt-OSX: Make the handling of Darwin tasks more generic for Carbon & Cocoa. Disable settings window animation on Cocoa.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.3 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#include <iprt/types.h>
27
28/* Qt includes */
29#include <QMouseEvent>
30#include <QWidget>
31#include <QTextBrowser>
32
33/**
34 * Simple class that filters out all key presses and releases
35 * got while the Alt key is pressed. For some very strange reason,
36 * QLineEdit accepts those combinations that are not used as accelerators,
37 * and inserts the corresponding characters to the entry field.
38 */
39class QIAltKeyFilter : protected QObject
40{
41 Q_OBJECT;
42
43public:
44
45 QIAltKeyFilter (QObject *aParent) :QObject (aParent) {}
46
47 void watchOn (QObject *aObject) { aObject->installEventFilter (this); }
48
49protected:
50
51 bool eventFilter (QObject * /* aObject */, QEvent *aEvent)
52 {
53 if (aEvent->type() == QEvent::KeyPress || aEvent->type() == QEvent::KeyRelease)
54 {
55 QKeyEvent *event = static_cast<QKeyEvent *> (aEvent);
56 if (event->modifiers() & Qt::AltModifier)
57 return true;
58 }
59 return false;
60 }
61};
62
63/**
64 * Simple class which simulates focus-proxy rule redirecting widget
65 * assigned shortcut to desired widget.
66 */
67class QIFocusProxy : protected QObject
68{
69 Q_OBJECT;
70
71public:
72
73 QIFocusProxy (QWidget *aFrom, QWidget *aTo)
74 : QObject (aFrom), mFrom (aFrom), mTo (aTo)
75 {
76 mFrom->installEventFilter (this);
77 }
78
79protected:
80
81 bool eventFilter (QObject *aObject, QEvent *aEvent)
82 {
83 if (aObject == mFrom && aEvent->type() == QEvent::Shortcut)
84 {
85 mTo->setFocus();
86 return true;
87 }
88 return QObject::eventFilter (aObject, aEvent);
89 }
90
91 QWidget *mFrom;
92 QWidget *mTo;
93};
94
95/**
96 * QTextEdit reimplementation to feat some extended requirements.
97 */
98class QRichTextEdit : public QTextEdit
99{
100 Q_OBJECT;
101
102public:
103
104 QRichTextEdit (QWidget *aParent) : QTextEdit (aParent) {}
105
106 void setViewportMargins (int aLeft, int aTop, int aRight, int aBottom)
107 {
108 QTextEdit::setViewportMargins (aLeft, aTop, aRight, aBottom);
109 }
110};
111
112/**
113 * QTextBrowser reimplementation to feat some extended requirements.
114 */
115class QRichTextBrowser : public QTextBrowser
116{
117 Q_OBJECT;
118
119public:
120
121 QRichTextBrowser (QWidget *aParent) : QTextBrowser (aParent) {}
122
123 void setViewportMargins (int aLeft, int aTop, int aRight, int aBottom)
124 {
125 QTextBrowser::setViewportMargins (aLeft, aTop, aRight, aBottom);
126 }
127};
128
129#ifdef Q_WS_MAC
130# include "VBoxUtils-darwin.h"
131#endif /* Q_WS_MAC */
132
133#endif // !___VBoxUtils_h___
134
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