Make QKeyMapper::possibleKeys() return list of QKeyCombinations
Having the explicit type instead of the opaque int makes it clearer what we're dealing with. Task-number: QTBUG-116873 Change-Id: I19e42ed329e15ab25a958602ecfb99b1c9d52a99 Reviewed-by: Liang Qi <liang.qi@qt.io>
This commit is contained in:
parent
8af35d27e8
commit
f8f5e2c122
@ -35,21 +35,17 @@ QKeyMapper::~QKeyMapper()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<int> QKeyMapper::possibleKeys(const QKeyEvent *e)
|
QList<QKeyCombination> QKeyMapper::possibleKeys(const QKeyEvent *e)
|
||||||
{
|
{
|
||||||
QList<int> result;
|
|
||||||
|
|
||||||
const auto *platformIntegration = QGuiApplicationPrivate::platformIntegration();
|
const auto *platformIntegration = QGuiApplicationPrivate::platformIntegration();
|
||||||
const auto *platformKeyMapper = platformIntegration->keyMapper();
|
const auto *platformKeyMapper = platformIntegration->keyMapper();
|
||||||
const auto keyCombinations = platformKeyMapper->possibleKeyCombinations(e);
|
QList<QKeyCombination> result = platformKeyMapper->possibleKeyCombinations(e);
|
||||||
for (auto keyCombination : keyCombinations)
|
|
||||||
result << keyCombination.toCombined();
|
|
||||||
|
|
||||||
if (result.isEmpty()) {
|
if (result.isEmpty()) {
|
||||||
if (e->key() && (e->key() != Qt::Key_unknown))
|
if (e->key() && (e->key() != Qt::Key_unknown))
|
||||||
result << e->keyCombination().toCombined();
|
result << e->keyCombination();
|
||||||
else if (!e->text().isEmpty())
|
else if (!e->text().isEmpty())
|
||||||
result << int(e->text().at(0).unicode() + (int)e->modifiers());
|
result << (Qt::Key(e->text().at(0).unicode()) | e->modifiers());
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
@ -33,7 +33,7 @@ public:
|
|||||||
~QKeyMapper();
|
~QKeyMapper();
|
||||||
|
|
||||||
static QKeyMapper *instance();
|
static QKeyMapper *instance();
|
||||||
static QList<int> possibleKeys(const QKeyEvent *e);
|
static QList<QKeyCombination> possibleKeys(const QKeyEvent *e);
|
||||||
|
|
||||||
QT_DECLARE_NATIVE_INTERFACE_ACCESSOR(QKeyMapper)
|
QT_DECLARE_NATIVE_INTERFACE_ACCESSOR(QKeyMapper)
|
||||||
|
|
||||||
|
@ -493,7 +493,7 @@ void QShortcutMap::clearSequence(QList<QKeySequence> &ksl)
|
|||||||
void QShortcutMap::createNewSequences(QKeyEvent *e, QList<QKeySequence> &ksl, int ignoredModifiers)
|
void QShortcutMap::createNewSequences(QKeyEvent *e, QList<QKeySequence> &ksl, int ignoredModifiers)
|
||||||
{
|
{
|
||||||
Q_D(QShortcutMap);
|
Q_D(QShortcutMap);
|
||||||
QList<int> possibleKeys = QKeyMapper::possibleKeys(e);
|
QList<QKeyCombination> possibleKeys = QKeyMapper::possibleKeys(e);
|
||||||
qCDebug(lcShortcutMap) << "Creating new sequences for" << e
|
qCDebug(lcShortcutMap) << "Creating new sequences for" << e
|
||||||
<< "with ignoredModifiers=" << Qt::KeyboardModifiers(ignoredModifiers);
|
<< "with ignoredModifiers=" << Qt::KeyboardModifiers(ignoredModifiers);
|
||||||
int pkTotal = possibleKeys.size();
|
int pkTotal = possibleKeys.size();
|
||||||
@ -522,7 +522,8 @@ void QShortcutMap::createNewSequences(QKeyEvent *e, QList<QKeySequence> &ksl, in
|
|||||||
curKsl.setKey(QKeyCombination::fromCombined(0), 2);
|
curKsl.setKey(QKeyCombination::fromCombined(0), 2);
|
||||||
curKsl.setKey(QKeyCombination::fromCombined(0), 3);
|
curKsl.setKey(QKeyCombination::fromCombined(0), 3);
|
||||||
}
|
}
|
||||||
curKsl.setKey(QKeyCombination::fromCombined(possibleKeys.at(pkNum) & ~ignoredModifiers), index);
|
const int key = possibleKeys.at(pkNum).toCombined();
|
||||||
|
curKsl.setKey(QKeyCombination::fromCombined(key & ~ignoredModifiers), index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -344,22 +344,23 @@ void QKeySequenceEdit::keyPressEvent(QKeyEvent *e)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
if (e->modifiers() & Qt::ShiftModifier) {
|
if (e->modifiers() & Qt::ShiftModifier) {
|
||||||
const QList<int> possibleKeys = QKeyMapper::possibleKeys(e);
|
const QList<QKeyCombination> possibleKeys = QKeyMapper::possibleKeys(e);
|
||||||
int pkTotal = possibleKeys.size();
|
int pkTotal = possibleKeys.size();
|
||||||
if (!pkTotal)
|
if (!pkTotal)
|
||||||
return;
|
return;
|
||||||
bool found = false;
|
bool found = false;
|
||||||
for (int i = 0; i < possibleKeys.size(); ++i) {
|
for (int i = 0; i < possibleKeys.size(); ++i) {
|
||||||
if (possibleKeys.at(i) - nextKey == int(e->modifiers())
|
const int key = possibleKeys.at(i).toCombined();
|
||||||
|| (possibleKeys.at(i) == nextKey && e->modifiers() == Qt::ShiftModifier)) {
|
if (key - nextKey == int(e->modifiers())
|
||||||
nextKey = possibleKeys.at(i);
|
|| (key == nextKey && e->modifiers() == Qt::ShiftModifier)) {
|
||||||
|
nextKey = key;
|
||||||
found = true;
|
found = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Use as fallback
|
// Use as fallback
|
||||||
if (!found)
|
if (!found)
|
||||||
nextKey = possibleKeys.first();
|
nextKey = possibleKeys.first().toCombined();
|
||||||
} else {
|
} else {
|
||||||
nextKey |= d->translateModifiers(e->modifiers(), e->text());
|
nextKey |= d->translateModifiers(e->modifiers(), e->text());
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user