From 4c9be94bc86b869a5bf5f917a8bad1d62630c0a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorbj=C3=B8rn=20Lindeijer?= Date: Wed, 4 Sep 2019 11:16:34 +0200 Subject: [PATCH] Added Ctrl+Space as shortcut to trigger object types dropdown Normally the object types dropdown appears when you start to type, but by pressing Ctrl+Space you can now trigger the dropdown also without typing something, in which case you see the full list of object types. Even better would be to replace the QLineEdit/QCompleter combo with an editable combo box. --- src/tiled/varianteditorfactory.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/tiled/varianteditorfactory.cpp b/src/tiled/varianteditorfactory.cpp index 81c270056f..3ff7b8d596 100644 --- a/src/tiled/varianteditorfactory.cpp +++ b/src/tiled/varianteditorfactory.cpp @@ -30,6 +30,7 @@ #include #include +#include #include #include "qtcompat_p.h" @@ -149,12 +150,19 @@ QWidget *VariantEditorFactory::createEditor(QtVariantPropertyManager *manager, if (type == QVariant::String) { // Add support for "suggestions" attribute that adds a QCompleter to the QLineEdit - QVariant suggestions = manager->attributeValue(property, QLatin1String("suggestions")); - if (!suggestions.toStringList().isEmpty()) { + QStringList suggestions = manager->attributeValue(property, QLatin1String("suggestions")).toStringList(); + if (!suggestions.isEmpty()) { if (QLineEdit *lineEdit = qobject_cast(editor)) { - QCompleter *completer = new QCompleter(suggestions.toStringList(), lineEdit); + QCompleter *completer = new QCompleter(suggestions, lineEdit); completer->setCaseSensitivity(Qt::CaseInsensitive); lineEdit->setCompleter(completer); + + QShortcut *completionShortcut = new QShortcut(tr("Ctrl+Space"), lineEdit); + completionShortcut->setContext(Qt::WidgetShortcut); + connect(completionShortcut, &QShortcut::activated, lineEdit, [=] { + completer->setCompletionPrefix(lineEdit->text().left(lineEdit->cursorPosition())); + completer->complete(); + }); } } }