Skip to content

Commit

Permalink
Added Ctrl+Space as shortcut to trigger object types dropdown
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bjorn committed Sep 4, 2019
1 parent f009e9f commit 4c9be94
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/tiled/varianteditorfactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

#include <QCompleter>
#include <QHBoxLayout>
#include <QShortcut>
#include <QToolButton>

#include "qtcompat_p.h"
Expand Down Expand Up @@ -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<QLineEdit*>(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();
});
}
}
}
Expand Down

0 comments on commit 4c9be94

Please # to comment.