VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxUtils.h@ 43138

Last change on this file since 43138 was 39488, checked in by vboxsync, 12 years ago

FE/Qt: Moving VBoxVersion into the separate file.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.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-2011 Oracle Corporation
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
19#ifndef ___VBoxUtils_h___
20#define ___VBoxUtils_h___
21
22#include <iprt/types.h>
23
24/* Qt includes */
25#include <QMouseEvent>
26#include <QWidget>
27#include <QTextBrowser>
28
29/**
30 * Simple class that filters out all key presses and releases
31 * got while the Alt key is pressed. For some very strange reason,
32 * QLineEdit accepts those combinations that are not used as accelerators,
33 * and inserts the corresponding characters to the entry field.
34 */
35class QIAltKeyFilter : protected QObject
36{
37 Q_OBJECT;
38
39public:
40
41 QIAltKeyFilter (QObject *aParent) :QObject (aParent) {}
42
43 void watchOn (QObject *aObject) { aObject->installEventFilter (this); }
44
45protected:
46
47 bool eventFilter (QObject * /* aObject */, QEvent *aEvent)
48 {
49 if (aEvent->type() == QEvent::KeyPress || aEvent->type() == QEvent::KeyRelease)
50 {
51 QKeyEvent *pEvent = static_cast<QKeyEvent *> (aEvent);
52 if (pEvent->modifiers() & Qt::AltModifier)
53 return true;
54 }
55 return false;
56 }
57};
58
59/**
60 * Simple class which simulates focus-proxy rule redirecting widget
61 * assigned shortcut to desired widget.
62 */
63class QIFocusProxy : protected QObject
64{
65 Q_OBJECT;
66
67public:
68
69 QIFocusProxy (QWidget *aFrom, QWidget *aTo)
70 : QObject (aFrom), mFrom (aFrom), mTo (aTo)
71 {
72 mFrom->installEventFilter (this);
73 }
74
75protected:
76
77 bool eventFilter (QObject *aObject, QEvent *aEvent)
78 {
79 if (aObject == mFrom && aEvent->type() == QEvent::Shortcut)
80 {
81 mTo->setFocus();
82 return true;
83 }
84 return QObject::eventFilter (aObject, aEvent);
85 }
86
87 QWidget *mFrom;
88 QWidget *mTo;
89};
90
91/**
92 * QTextEdit reimplementation to feat some extended requirements.
93 */
94class QRichTextEdit : public QTextEdit
95{
96 Q_OBJECT;
97
98public:
99
100 QRichTextEdit (QWidget *aParent) : QTextEdit (aParent) {}
101
102 void setViewportMargins (int aLeft, int aTop, int aRight, int aBottom)
103 {
104 QTextEdit::setViewportMargins (aLeft, aTop, aRight, aBottom);
105 }
106};
107
108/**
109 * QTextBrowser reimplementation to feat some extended requirements.
110 */
111class QRichTextBrowser : public QTextBrowser
112{
113 Q_OBJECT;
114
115public:
116
117 QRichTextBrowser (QWidget *aParent) : QTextBrowser (aParent) {}
118
119 void setViewportMargins (int aLeft, int aTop, int aRight, int aBottom)
120 {
121 QTextBrowser::setViewportMargins (aLeft, aTop, aRight, aBottom);
122 }
123};
124
125class UIProxyManager
126{
127public:
128
129 UIProxyManager(const QString &strProxySettings = QString())
130 : m_fProxyEnabled(false), m_fAuthEnabled(false)
131 {
132 /* Parse settings: */
133 if (!strProxySettings.isEmpty())
134 {
135 QStringList proxySettings = strProxySettings.split(",");
136 if (proxySettings.size() > 0)
137 m_fProxyEnabled = proxySettings[0] == "proxyEnabled";
138 if (proxySettings.size() > 1)
139 m_strProxyHost = proxySettings[1];
140 if (proxySettings.size() > 2)
141 m_strProxyPort = proxySettings[2];
142 if (proxySettings.size() > 3)
143 m_fAuthEnabled = proxySettings[3] == "authEnabled";
144 if (proxySettings.size() > 4)
145 m_strAuthLogin = proxySettings[4];
146 if (proxySettings.size() > 5)
147 m_strAuthPassword = proxySettings[5];
148 }
149 }
150
151 QString toString() const
152 {
153 /* Serialize settings: */
154 QString strResult;
155 if (m_fProxyEnabled || !m_strProxyHost.isEmpty() || !m_strProxyPort.isEmpty() ||
156 m_fAuthEnabled || !m_strAuthLogin.isEmpty() || !m_strAuthPassword.isEmpty())
157 {
158 QStringList proxySettings;
159 proxySettings << QString(m_fProxyEnabled ? "proxyEnabled" : "proxyDisabled");
160 proxySettings << m_strProxyHost;
161 proxySettings << m_strProxyPort;
162 proxySettings << QString(m_fAuthEnabled ? "authEnabled" : "authDisabled");
163 proxySettings << m_strAuthLogin;
164 proxySettings << m_strAuthPassword;
165 strResult = proxySettings.join(",");
166 }
167 return strResult;
168 }
169
170 /* Proxy attribute getters: */
171 bool proxyEnabled() const { return m_fProxyEnabled; }
172 const QString& proxyHost() const { return m_strProxyHost; }
173 const QString& proxyPort() const { return m_strProxyPort; }
174 bool authEnabled() const { return m_fAuthEnabled; }
175 const QString& authLogin() const { return m_strAuthLogin; }
176 const QString& authPassword() const { return m_strAuthPassword; }
177
178 /* Proxy attribute setters: */
179 void setProxyEnabled(bool fProxyEnabled) { m_fProxyEnabled = fProxyEnabled; }
180 void setProxyHost(const QString &strProxyHost) { m_strProxyHost = strProxyHost; }
181 void setProxyPort(const QString &strProxyPort) { m_strProxyPort = strProxyPort; }
182 void setAuthEnabled(bool fAuthEnabled) { m_fAuthEnabled = fAuthEnabled; }
183 void setAuthLogin(const QString &strAuthLogin) { m_strAuthLogin = strAuthLogin; }
184 void setAuthPassword(const QString &strAuthPassword) { m_strAuthPassword = strAuthPassword; }
185
186private:
187
188 /* Proxy attribute variables: */
189 bool m_fProxyEnabled;
190 QString m_strProxyHost;
191 QString m_strProxyPort;
192 bool m_fAuthEnabled;
193 QString m_strAuthLogin;
194 QString m_strAuthPassword;
195};
196
197#ifdef Q_WS_MAC
198# include "VBoxUtils-darwin.h"
199#endif /* Q_WS_MAC */
200
201#endif // !___VBoxUtils_h___
202
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use