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 *platformKeyMapper = platformIntegration->keyMapper();
|
||||
const auto keyCombinations = platformKeyMapper->possibleKeyCombinations(e);
|
||||
for (auto keyCombination : keyCombinations)
|
||||
result << keyCombination.toCombined();
|
||||
QList<QKeyCombination> result = platformKeyMapper->possibleKeyCombinations(e);
|
||||
|
||||
if (result.isEmpty()) {
|
||||
if (e->key() && (e->key() != Qt::Key_unknown))
|
||||
result << e->keyCombination().toCombined();
|
||||
result << e->keyCombination();
|
||||
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;
|
||||
|
@ -33,7 +33,7 @@ public:
|
||||
~QKeyMapper();
|
||||
|
||||
static QKeyMapper *instance();
|
||||
static QList<int> possibleKeys(const QKeyEvent *e);
|
||||
static QList<QKeyCombination> possibleKeys(const QKeyEvent *e);
|
||||
|
||||
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)
|
||||
{
|
||||
Q_D(QShortcutMap);
|
||||
QList<int> possibleKeys = QKeyMapper::possibleKeys(e);
|
||||
QList<QKeyCombination> possibleKeys = QKeyMapper::possibleKeys(e);
|
||||
qCDebug(lcShortcutMap) << "Creating new sequences for" << e
|
||||
<< "with ignoredModifiers=" << Qt::KeyboardModifiers(ignoredModifiers);
|
||||
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), 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;
|
||||
|
||||
if (e->modifiers() & Qt::ShiftModifier) {
|
||||
const QList<int> possibleKeys = QKeyMapper::possibleKeys(e);
|
||||
const QList<QKeyCombination> possibleKeys = QKeyMapper::possibleKeys(e);
|
||||
int pkTotal = possibleKeys.size();
|
||||
if (!pkTotal)
|
||||
return;
|
||||
bool found = false;
|
||||
for (int i = 0; i < possibleKeys.size(); ++i) {
|
||||
if (possibleKeys.at(i) - nextKey == int(e->modifiers())
|
||||
|| (possibleKeys.at(i) == nextKey && e->modifiers() == Qt::ShiftModifier)) {
|
||||
nextKey = possibleKeys.at(i);
|
||||
const int key = possibleKeys.at(i).toCombined();
|
||||
if (key - nextKey == int(e->modifiers())
|
||||
|| (key == nextKey && e->modifiers() == Qt::ShiftModifier)) {
|
||||
nextKey = key;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Use as fallback
|
||||
if (!found)
|
||||
nextKey = possibleKeys.first();
|
||||
nextKey = possibleKeys.first().toCombined();
|
||||
} else {
|
||||
nextKey |= d->translateModifiers(e->modifiers(), e->text());
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user