Qt 4.8
Public Functions | Static Public Functions | Public Variables | Static Public Variables | List of all members
QKeySequencePrivate Class Reference

#include <qkeysequence_p.h>

Public Functions

 QKeySequencePrivate ()
 
 QKeySequencePrivate (const QKeySequencePrivate &copy)
 

Static Public Functions

static int decodeString (const QString &keyStr, QKeySequence::SequenceFormat format)
 
static QString encodeString (int key, QKeySequence::SequenceFormat format)
 

Public Variables

int key [4]
 
QAtomicInt ref
 

Static Public Variables

static const QKeyBinding keyBindings []
 
static const uint numberOfKeyBindings = sizeof(QKeySequencePrivate::keyBindings)/(sizeof(QKeyBinding))
 

Detailed Description

Definition at line 69 of file qkeysequence_p.h.

Constructors and Destructors

◆ QKeySequencePrivate() [1/2]

QKeySequencePrivate::QKeySequencePrivate ( )
inline

Definition at line 72 of file qkeysequence_p.h.

73  {
74  ref = 1;
75  key[0] = key[1] = key[2] = key[3] = 0;
76  }

◆ QKeySequencePrivate() [2/2]

QKeySequencePrivate::QKeySequencePrivate ( const QKeySequencePrivate copy)
inline

Definition at line 77 of file qkeysequence_p.h.

78  {
79  ref = 1;
80  key[0] = copy.key[0];
81  key[1] = copy.key[1];
82  key[2] = copy.key[2];
83  key[3] = copy.key[3];
84  }

Functions

◆ decodeString()

int QKeySequencePrivate::decodeString ( const QString keyStr,
QKeySequence::SequenceFormat  format 
)
static

Definition at line 1221 of file qkeysequence.cpp.

Referenced by QKeySequence::assign(), and QKeySequence::decodeString().

1222 {
1223  int ret = 0;
1224  QString accel = str.toLower();
1225  bool nativeText = (format == QKeySequence::NativeText);
1226 
1227  QList<QModifKeyName> *gmodifs;
1228  if (nativeText) {
1229  gmodifs = globalModifs();
1230  if (gmodifs->isEmpty()) {
1231 #ifdef Q_WS_MAC
1232  const bool dontSwap = qApp->testAttribute(Qt::AA_MacDontSwapCtrlAndMeta);
1233  if (dontSwap)
1234  *gmodifs << QModifKeyName(Qt::META, QChar(kCommandUnicode));
1235  else
1236  *gmodifs << QModifKeyName(Qt::CTRL, QChar(kCommandUnicode));
1237  *gmodifs << QModifKeyName(Qt::ALT, QChar(kOptionUnicode));
1238  if (dontSwap)
1239  *gmodifs << QModifKeyName(Qt::CTRL, QChar(kControlUnicode));
1240  else
1241  *gmodifs << QModifKeyName(Qt::META, QChar(kControlUnicode));
1242  *gmodifs << QModifKeyName(Qt::SHIFT, QChar(kShiftUnicode));
1243 #endif
1244  *gmodifs << QModifKeyName(Qt::CTRL, QLatin1String("ctrl+"))
1245  << QModifKeyName(Qt::SHIFT, QLatin1String("shift+"))
1246  << QModifKeyName(Qt::ALT, QLatin1String("alt+"))
1247  << QModifKeyName(Qt::META, QLatin1String("meta+"));
1248  }
1249  } else {
1250  gmodifs = globalPortableModifs();
1251  if (gmodifs->isEmpty()) {
1252  *gmodifs << QModifKeyName(Qt::CTRL, QLatin1String("ctrl+"))
1253  << QModifKeyName(Qt::SHIFT, QLatin1String("shift+"))
1254  << QModifKeyName(Qt::ALT, QLatin1String("alt+"))
1255  << QModifKeyName(Qt::META, QLatin1String("meta+"));
1256  }
1257  }
1258  if (!gmodifs) return ret;
1259 
1260 
1261  QList<QModifKeyName> modifs;
1262  if (nativeText) {
1263  modifs << QModifKeyName(Qt::CTRL, QShortcut::tr("Ctrl").toLower().append(QLatin1Char('+')))
1264  << QModifKeyName(Qt::SHIFT, QShortcut::tr("Shift").toLower().append(QLatin1Char('+')))
1265  << QModifKeyName(Qt::ALT, QShortcut::tr("Alt").toLower().append(QLatin1Char('+')))
1266  << QModifKeyName(Qt::META, QShortcut::tr("Meta").toLower().append(QLatin1Char('+')));
1267  }
1268  modifs += *gmodifs; // Test non-translated ones last
1269 
1270  QString sl = accel;
1271 #ifdef Q_WS_MAC
1272  for (int i = 0; i < modifs.size(); ++i) {
1273  const QModifKeyName &mkf = modifs.at(i);
1274  if (sl.contains(mkf.name)) {
1275  ret |= mkf.qt_key;
1276  accel.remove(mkf.name);
1277  sl = accel;
1278  }
1279  }
1280 #else
1281  int i = 0;
1282  int lastI = 0;
1283  while ((i = sl.indexOf(QLatin1Char('+'), i + 1)) != -1) {
1284  const QString sub = sl.mid(lastI, i - lastI + 1);
1285  // Just shortcut the check here if we only have one character.
1286  // Rational: A modifier will contain the name AND +, so longer than 1, a length of 1 is just
1287  // the remaining part of the shortcut (ei. The 'C' in "Ctrl+C"), so no need to check that.
1288  if (sub.length() > 1) {
1289  for (int j = 0; j < modifs.size(); ++j) {
1290  const QModifKeyName &mkf = modifs.at(j);
1291  if (sub == mkf.name) {
1292  ret |= mkf.qt_key;
1293  break; // Shortcut, since if we find an other it would/should just be a dup
1294  }
1295  }
1296  }
1297  lastI = i + 1;
1298  }
1299 #endif
1300 
1301  int p = accel.lastIndexOf(QLatin1Char('+'), str.length() - 2); // -2 so that Ctrl++ works
1302  if(p > 0)
1303  accel = accel.mid(p + 1);
1304 
1305  int fnum = 0;
1306  if (accel.length() == 1) {
1307 #ifdef Q_WS_MAC
1308  int qtKey = qtkeyForMacSymbol(accel[0]);
1309  if (qtKey != -1) {
1310  ret |= qtKey;
1311  } else
1312 #endif
1313  {
1314  ret |= accel[0].toUpper().unicode();
1315  }
1316  } else if (accel[0] == QLatin1Char('f') && (fnum = accel.mid(1).toInt()) && (fnum >= 1) && (fnum <= 35)) {
1317  ret |= Qt::Key_F1 + fnum - 1;
1318  } else {
1319  // For NativeText, check the traslation table first,
1320  // if we don't find anything then try it out with just the untranlated stuff.
1321  // PortableText will only try the untranlated table.
1322  bool found = false;
1323  for (int tran = 0; tran < 2; ++tran) {
1324  if (!nativeText)
1325  ++tran;
1326  for (int i = 0; keyname[i].name; ++i) {
1327  QString keyName(tran == 0
1328  ? QShortcut::tr(keyname[i].name)
1329  : QString::fromLatin1(keyname[i].name));
1330  if (accel == keyName.toLower()) {
1331  ret |= keyname[i].key;
1332  found = true;
1333  break;
1334  }
1335  }
1336  if (found)
1337  break;
1338  }
1339  }
1340  return ret;
1341 }
QBool contains(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.h:904
static QString keyName(const QString &rKey)
static const struct @203 keyname[]
int toInt(bool *ok=0, int base=10) const
Returns the string converted to an int using base base, which is 10 by default and must be between 2 ...
Definition: qstring.cpp:6090
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
QString toUpper() const Q_REQUIRED_RESULT
Returns an uppercase copy of the string.
Definition: qstring.cpp:5483
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
const QChar * unicode() const
Returns a &#39;\0&#39;-terminated Unicode representation of the string.
Definition: qstring.h:706
#define qApp
const char * name
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:2838
QString mid(int position, int n=-1) const Q_REQUIRED_RESULT
Returns a string that contains n characters of this string, starting at the specified position index...
Definition: qstring.cpp:3706
int lastIndexOf(QChar c, int from=-1, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:3000
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
QString toLower() const Q_REQUIRED_RESULT
Returns a lowercase copy of the string.
Definition: qstring.cpp:5389
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
static int qtkeyForMacSymbol(const QChar ch)
static QString qtKey(CFStringRef cfkey)
QString & remove(int i, int len)
Removes n characters from the string, starting at the given position index, and returns a reference t...
Definition: qstring.cpp:1867
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ encodeString()

QString QKeySequencePrivate::encodeString ( int  key,
QKeySequence::SequenceFormat  format 
)
static

Definition at line 1361 of file qkeysequence.cpp.

Referenced by QKeySequence::encodeString(), and QKeySequence::toString().

1362 {
1363  bool nativeText = (format == QKeySequence::NativeText);
1364  QString s;
1365 #if defined(Q_WS_MAC)
1366  if (nativeText) {
1367  // On Mac OS X the order (by default) is Meta, Alt, Shift, Control.
1368  // If the AA_MacDontSwapCtrlAndMeta is enabled, then the order
1369  // is Ctrl, Alt, Shift, Meta. The macSymbolForQtKey does this swap
1370  // for us, which means that we have to adjust our order here.
1371  // The upshot is a lot more infrastructure to keep the number of
1372  // if tests down and the code relatively clean.
1373  static const int ModifierOrder[] = { Qt::META, Qt::ALT, Qt::SHIFT, Qt::CTRL, 0 };
1374  static const int QtKeyOrder[] = { Qt::Key_Meta, Qt::Key_Alt, Qt::Key_Shift, Qt::Key_Control, 0 };
1375  static const int DontSwapModifierOrder[] = { Qt::CTRL, Qt::ALT, Qt::SHIFT, Qt::META, 0 };
1376  static const int DontSwapQtKeyOrder[] = { Qt::Key_Control, Qt::Key_Alt, Qt::Key_Shift, Qt::Key_Meta, 0 };
1377  const int *modifierOrder;
1378  const int *qtkeyOrder;
1379  if (qApp->testAttribute(Qt::AA_MacDontSwapCtrlAndMeta)) {
1380  modifierOrder = DontSwapModifierOrder;
1381  qtkeyOrder = DontSwapQtKeyOrder;
1382  } else {
1383  modifierOrder = ModifierOrder;
1384  qtkeyOrder = QtKeyOrder;
1385  }
1386 
1387  for (int i = 0; modifierOrder[i] != 0; ++i) {
1388  if (key & modifierOrder[i])
1389  s += qt_macSymbolForQtKey(qtkeyOrder[i]);
1390  }
1391  } else
1392 #endif
1393  {
1394  // On other systems the order is Meta, Control, Alt, Shift
1395  if ((key & Qt::META) == Qt::META)
1396  s = nativeText ? QShortcut::tr("Meta") : QString::fromLatin1("Meta");
1397  if ((key & Qt::CTRL) == Qt::CTRL)
1398  addKey(s, nativeText ? QShortcut::tr("Ctrl") : QString::fromLatin1("Ctrl"), format);
1399  if ((key & Qt::ALT) == Qt::ALT)
1400  addKey(s, nativeText ? QShortcut::tr("Alt") : QString::fromLatin1("Alt"), format);
1401  if ((key & Qt::SHIFT) == Qt::SHIFT)
1402  addKey(s, nativeText ? QShortcut::tr("Shift") : QString::fromLatin1("Shift"), format);
1403  }
1404 
1405 
1407  QString p;
1408 
1409  if (key && key < Qt::Key_Escape && key != Qt::Key_Space) {
1411  p = QChar(ushort(key)).toUpper();
1412  } else {
1414  p += QChar(QChar::lowSurrogate(key));
1415  }
1416  } else if (key >= Qt::Key_F1 && key <= Qt::Key_F35) {
1417  p = nativeText ? QShortcut::tr("F%1").arg(key - Qt::Key_F1 + 1)
1418  : QString::fromLatin1("F%1").arg(key - Qt::Key_F1 + 1);
1419  } else if (key) {
1420  int i=0;
1421 #if defined(Q_WS_MAC)
1422  if (nativeText) {
1424  if (!ch.isNull())
1425  p = ch;
1426  else
1427  goto NonSymbol;
1428  } else
1429 #endif
1430  {
1431 #ifdef Q_WS_MAC
1432 NonSymbol:
1433 #endif
1434  while (keyname[i].name) {
1435  if (key == keyname[i].key) {
1436  p = nativeText ? QShortcut::tr(keyname[i].name)
1437  : QString::fromLatin1(keyname[i].name);
1438  break;
1439  }
1440  ++i;
1441  }
1442  // If we can't find the actual translatable keyname,
1443  // fall back on the unicode representation of it...
1444  // Or else characters like Qt::Key_aring may not get displayed
1445  // (Really depends on you locale)
1446  if (!keyname[i].name) {
1447  if (!QChar::requiresSurrogates(key)) {
1448  p = QChar(ushort(key)).toUpper();
1449  } else {
1450  p += QChar(QChar::highSurrogate(key));
1451  p += QChar(QChar::lowSurrogate(key));
1452  }
1453  }
1454  }
1455  }
1456 
1457 #ifdef Q_WS_MAC
1458  if (nativeText)
1459  s += p;
1460  else
1461 #endif
1462  addKey(s, p, format);
1463  return s;
1464 }
static const struct @203 keyname[]
bool isNull() const
Returns true if the character is the Unicode character 0x0000 (&#39;\0&#39;); otherwise returns false...
Definition: qchar.h:262
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
static ushort highSurrogate(uint ucs4)
Returns the high surrogate value of a ucs4 code point.
Definition: qchar.h:303
static ushort lowSurrogate(uint ucs4)
Returns the low surrogate value of a ucs4 code point.
Definition: qchar.h:306
static void addKey(QString &str, const QString &theKey, QKeySequence::SequenceFormat format)
static bool requiresSurrogates(uint ucs4)
Returns true if the UCS-4-encoded character specified by ucs4 can be split into the high and low part...
Definition: qchar.h:294
#define qApp
const char * name
QChar toUpper() const
Returns the uppercase equivalent if the character is lowercase or titlecase; otherwise returns the ch...
Definition: qchar.cpp:1287
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
Definition: qstring.cpp:7186
unsigned short ushort
Definition: qglobal.h:995
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
QChar qt_macSymbolForQtKey(int key)

Properties

◆ key

int QKeySequencePrivate::key[4]

◆ keyBindings

const QKeyBinding QKeySequencePrivate::keyBindings
static

Definition at line 90 of file qkeysequence_p.h.

Referenced by QKeyEvent::matches().

◆ numberOfKeyBindings

const uint QKeySequencePrivate::numberOfKeyBindings = sizeof(QKeySequencePrivate::keyBindings)/(sizeof(QKeyBinding))
static

Definition at line 91 of file qkeysequence_p.h.

Referenced by QKeySequence::keyBindings(), and QKeyEvent::matches().

◆ ref

QAtomicInt QKeySequencePrivate::ref

The documentation for this class was generated from the following files: