VirtualBox

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

Last change on this file since 43138 was 35634, checked in by vboxsync, 13 years ago

FE/Qt4: allow free configurable key shortcuts in the selector and machine window

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.0 KB
Line 
1/** @file
2 *
3 * VBox frontends: Qt GUI ("VirtualBox"):
4 * UIShortcuts class declarations
5 */
6
7/*
8 * Copyright (C) 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 __UIShortcuts_h__
20#define __UIShortcuts_h__
21
22#include "VBoxGlobal.h"
23
24/* Qt includes */
25#include <QHash>
26
27class UIKeySequence
28{
29public:
30 UIKeySequence() {}
31
32 UIKeySequence(const QString &strId, const QString strKeySeq = "")
33 : m_strId(strId)
34 , m_strDefKeySeq(strKeySeq)
35 , m_strCurKeySeq(strKeySeq) {}
36
37 UIKeySequence(const QString &strId, QKeySequence::StandardKey seq)
38 : m_strId(strId)
39 {
40 QKeySequence ks(seq);
41 m_strDefKeySeq = m_strCurKeySeq = ks.toString();
42 }
43
44 QString id() const
45 {
46 return m_strId;
47 }
48
49 QString defaultKeySequence() const
50 {
51 return m_strDefKeySeq;
52 }
53
54 void setKeySequence(const QString& strKeySeq)
55 {
56 m_strCurKeySeq = strKeySeq;
57 }
58
59 QString keySequence() const
60 {
61 return m_strCurKeySeq;
62 }
63
64private:
65 /* Private member vars */
66 QString m_strId;
67 QString m_strDefKeySeq;
68 QString m_strCurKeySeq;
69};
70
71template <class T>
72class UIShortcuts
73{
74public:
75 static T *instance()
76 {
77 if (!m_pInstance)
78 m_pInstance = new T();
79 return m_pInstance;
80 }
81
82 static void destroy()
83 {
84 if (m_pInstance)
85 {
86 delete m_pInstance;
87 m_pInstance = 0;
88 }
89 }
90
91 QString shortcut(int type) const
92 {
93 return m_Shortcuts[type].keySequence();
94 }
95
96 QKeySequence keySequence(int type) const
97 {
98 return QKeySequence(m_Shortcuts[type].keySequence());
99 }
100
101protected:
102
103 UIShortcuts() {}
104
105 void loadExtraData(const QString &strKey, int cSize)
106 {
107 QStringList newKeys = vboxGlobal().virtualBox().GetExtraDataStringList(strKey);
108 for (int i = 0; i < newKeys.size(); ++i)
109 {
110 const QString &s = newKeys.at(i);
111 int w = s.indexOf('=');
112 if (w < 0)
113 continue;
114 QString id = s.left(w);
115 QString value = s.right(s.length() - w - 1);
116 for (int a = 0; a < cSize; ++a)
117 if (m_Shortcuts[a].id().compare(id, Qt::CaseInsensitive) == 0)
118 {
119 if (value.compare("None", Qt::CaseInsensitive) == 0)
120 m_Shortcuts[a].setKeySequence("");
121 else
122 m_Shortcuts[a].setKeySequence(value);
123 }
124 }
125 }
126
127 static T *m_pInstance;
128 QHash<int, UIKeySequence> m_Shortcuts;
129};
130
131#endif /* __UIShortcuts_h__ */
132
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use