📄 qkeysequence.cpp
字号:
lastI = i + 1; }#endif int p = accel.lastIndexOf(QLatin1Char('+'), str.length() - 2); // -2 so that Ctrl++ works if(p > 0) accel = accel.mid(p + 1); int fnum = 0; if (accel.length() == 1) { ret |= accel[0].toUpper().unicode(); } else if (accel[0] == QLatin1Char('f') && (fnum = accel.mid(1).toInt()) && (fnum >= 1) && (fnum <= 35)) { ret |= Qt::Key_F1 + fnum - 1; } else { // For NativeText, check the traslation table first, // if we don't find anything then try it out with just the untranlated stuff. // PortableText will only try the untranlated table. bool found = false; for (int tran = 0; tran < 2; ++tran) { if (!nativeText) ++tran; for (int i = 0; keyname[i].name; ++i) { QString keyName(tran == 0 ? QShortcut::tr(keyname[i].name) : QString::fromLatin1(keyname[i].name)); if (accel == keyName.toLower()) { ret |= keyname[i].key; found = true; break; } } if (found) break; } } return ret;}/*! Creates a shortcut string for \a key. For example, Qt::CTRL+Qt::Key_O gives "Ctrl+O". The strings, "Ctrl", "Shift", etc. are translated (using QObject::tr()) in the "QShortcut" context. */QString QKeySequence::encodeString(int key){ return QKeySequencePrivate::encodeString(key, NativeText);}static inline void addKey(QString &str, const QString &theKey, QKeySequence::SequenceFormat format){ if (!str.isEmpty()) str += (format == QKeySequence::NativeText) ? QShortcut::tr("+") : QString::fromLatin1("+"); str += theKey;}QString QKeySequencePrivate::encodeString(int key, QKeySequence::SequenceFormat format){ bool nativeText = (format == QKeySequence::NativeText); QString s;#if defined(Q_WS_MAC) if (nativeText) { // On MAC the order is Meta, Alt, Shift, Control. if ((key & Qt::META) == Qt::META) s += QMAC_META; if ((key & Qt::ALT) == Qt::ALT) s += QMAC_ALT; if ((key & Qt::SHIFT) == Qt::SHIFT) s += QMAC_SHIFT; if ((key & Qt::CTRL) == Qt::CTRL) s += QMAC_CTRL; } else#endif { // On other systems the order is Meta, Control, Alt, Shift if ((key & Qt::META) == Qt::META) s = nativeText ? QShortcut::tr("Meta") : QString::fromLatin1("Meta"); if ((key & Qt::CTRL) == Qt::CTRL) addKey(s, nativeText ? QShortcut::tr("Ctrl") : QString::fromLatin1("Ctrl"), format); if ((key & Qt::ALT) == Qt::ALT) addKey(s, nativeText ? QShortcut::tr("Alt") : QString::fromLatin1("Alt"), format); if ((key & Qt::SHIFT) == Qt::SHIFT) addKey(s, nativeText ? QShortcut::tr("Shift") : QString::fromLatin1("Shift"), format); } key &= ~(Qt::ShiftModifier | Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier); QString p; if (key && key < Qt::Key_Escape && key != Qt::Key_Space) { if (key < 0x10000) { p = QChar(key & 0xffff).toUpper(); } else { p = QChar((key-0x10000)/0x400+0xd800); p += QChar((key-0x10000)%400+0xdc00); } } else if (key >= Qt::Key_F1 && key <= Qt::Key_F35) { p = nativeText ? QShortcut::tr("F%1").arg(key - Qt::Key_F1 + 1) : QString::fromLatin1("F%1").arg(key - Qt::Key_F1 + 1); } else if (key) { int i=0; while (keyname[i].name) { if (key == keyname[i].key) { p = nativeText ? QShortcut::tr(keyname[i].name) : QString::fromLatin1(keyname[i].name); break; } ++i; } // If we can't find the actual translatable keyname, // fall back on the unicode representation of it... // Or else characters like Qt::Key_aring may not get displayed // (Really depends on you locale) if (!keyname[i].name) { if (key < 0x10000) { p = QChar(key & 0xffff).toUpper(); } else { p = QChar((key-0x10000)/0x400+0xd800); p += QChar((key-0x10000)%400+0xdc00); } } }#ifdef Q_WS_MAC if (nativeText) s += p; else#endif addKey(s, p, format); return s;}/*! Matches the sequence with \a seq. Returns ExactMatch if successful, PartialMatch if \a seq matches incompletely, and NoMatch if the sequences have nothing in common. Returns NoMatch if \a seq is shorter.*/QKeySequence::SequenceMatch QKeySequence::matches(const QKeySequence &seq) const{ uint userN = count(), seqN = seq.count(); if (userN > seqN) return NoMatch; // If equal in length, we have a potential ExactMatch sequence, // else we already know it can only be partial. SequenceMatch match = (userN == seqN ? ExactMatch : PartialMatch); for (uint i = 0; i < userN; ++i) { int userKey = (*this)[i], sequenceKey = seq[i]; if (userKey != sequenceKey) return NoMatch; } return match;}/*! \obsolete Use toString() instead. Returns the key sequence as a QString. This is equivalent to calling toString(QKeySequence::NativeText). Note that the result is not platform independent.*/QKeySequence::operator QString() const{ return QKeySequence::toString(QKeySequence::NativeText);}/*! Returns the key sequence as a QVariant*/QKeySequence::operator QVariant() const{ return QVariant(QVariant::KeySequence, this);}/*! \obsolete For backward compatibility: returns the first keycode as integer. If the key sequence is empty, 0 is returned. */QKeySequence::operator int () const{ if (1 <= count()) return d->key[0]; return 0;}/*! Returns a reference to the element at position \a index in the key sequence. This can only be used to read an element. */int QKeySequence::operator[](uint index) const{ Q_ASSERT_X(index < 4, "QKeySequence::operator[]", "index out of range"); return d->key[index];}/*! Assignment operator. Assigns the \a other key sequence to this object. */QKeySequence &QKeySequence::operator=(const QKeySequence &other){ qAtomicAssign(d, other.d); return *this;}/*! \fn bool QKeySequence::operator!=(const QKeySequence &other) const Returns true if this key sequence is not equal to the \a other key sequence; otherwise returns false.*//*! Returns true if this key sequence is equal to the \a other key sequence; otherwise returns false. */bool QKeySequence::operator==(const QKeySequence &other) const{ return (d->key[0] == other.d->key[0] && d->key[1] == other.d->key[1] && d->key[2] == other.d->key[2] && d->key[3] == other.d->key[3]);}/*! Provides an arbitrary comparison of this key sequence and \a other key sequence. All that is guaranteed is that the operator returns false if bot
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -