Qt 4.8
qkeymapper.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 
43 #include "qapplication.h"
44 
45 #include <private/qobject_p.h>
46 #include "qkeymapper_p.h"
47 #include <qwidget.h>
48 
50 
63  : QObject(*new QKeyMapperPrivate, 0)
64 {
65 }
66 
71 {
72 }
73 
75 {
76  QList<int> result;
77 
78  if (!e->nativeScanCode()) {
79  if (e->key() && (e->key() != Qt::Key_unknown))
80  result << int(e->key() + e->modifiers());
81  else if (!e->text().isEmpty())
82  result << int(e->text().at(0).unicode() + e->modifiers());
83  return result;
84  }
85 
86  return instance()->d_func()->possibleKeys(e);
87 }
88 
89 extern bool qt_sendSpontaneousEvent(QObject *receiver, QEvent *event); // in qapplication_*.cpp
91 {
92  instance()->d_func()->clearMappings();
93 
94  // inform all toplevel widgets of the change
97  for (int i = 0; i < list.size(); ++i) {
98  QWidget *w = list.at(i);
100  }
101 }
102 
103 Q_GLOBAL_STATIC(QKeyMapper, keymapper)
109 {
110  return keymapper();
111 }
112 
114 {
115  return QKeyMapper::instance()->d_func();
116 }
117 
The QKeyEvent class describes a key event.
Definition: qevent.h:224
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
ushort unicode() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qchar.h:251
quint32 nativeScanCode() const
Returns the native scan code of the key event.
Definition: qevent.cpp:872
~QKeyMapper()
Destroys the key mapper.
Definition: qkeymapper.cpp:70
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
virtual bool event(QEvent *)
This virtual function receives events to an object and should return true if the event e was recogniz...
Definition: qobject.cpp:1200
Qt::KeyboardModifiers modifiers() const
Returns the keyboard modifier flags that existed immediately after the event occurred.
Definition: qevent.cpp:999
static QList< int > possibleKeys(QKeyEvent *e)
Definition: qkeymapper.cpp:74
int key() const
Returns the code of the key that was pressed or released.
Definition: qevent.h:231
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
#define Q_GLOBAL_STATIC(TYPE, NAME)
Declares a global static variable with the given type and name.
Definition: qglobal.h:1968
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
static QKeyMapper * instance()
Returns the pointer to the single instance of QKeyMapper in the application.
Definition: qkeymapper.cpp:108
static QWidgetList topLevelWidgets()
Returns a list of the top-level widgets (windows) in the application.
QString text() const
Returns the Unicode text that this key generated.
Definition: qevent.h:236
static void changeKeyboard()
Definition: qkeymapper.cpp:90
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
friend QKeyMapperPrivate * qt_keymapper_private()
Definition: qkeymapper.cpp:113
bool qt_sendSpontaneousEvent(QObject *receiver, QEvent *event)
QKeyMapper()
Constructs a new key mapper.
Definition: qkeymapper.cpp:62