desktop: improve composition on TagWidgets

The TagWidgets hook into the textChanged() signal to invoke
the word-completer. However, that signal is also emitted for
composition-keys, making composition impossible if the completer
decides that it should show some entries.

Instead, hook into the inputMethodEvent() function, where one
can test whether a real character was input.

Also, don't hook into cursorPositionChanged(), since that led
to an uncanny cascade of reparse() calls when editing text.

The UI experience is still rough as sometimes the completer
popup steals the focus and hinders further entry.

Also, this doesn't fix the location field, which is its own class.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2022-08-13 10:40:28 +02:00 committed by Dirk Hohndel
parent 21eb108cfd
commit 803727395b
2 changed files with 14 additions and 9 deletions

View file

@ -7,9 +7,6 @@
TagWidget::TagWidget(QWidget *parent) : GroupedLineEdit(parent), m_completer(NULL), lastFinishedTag(false)
{
connect(this, SIGNAL(cursorPositionChanged()), this, SLOT(reparse()));
connect(this, SIGNAL(textChanged()), this, SLOT(reparse()));
QColor textColor = palette().color(QPalette::Text);
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
float h, s, l, a;
@ -39,8 +36,8 @@ void TagWidget::setCompleter(QCompleter *completer)
{
m_completer = completer;
m_completer->setWidget(this);
connect(m_completer, SIGNAL(activated(QString)), this, SLOT(completionSelected(QString)));
connect(m_completer, SIGNAL(highlighted(QString)), this, SLOT(completionHighlighted(QString)));
connect(m_completer, QOverload<const QString &>::of(&QCompleter::activated), this, &TagWidget::completionSelected);
connect(m_completer, QOverload<const QString &>::of(&QCompleter::highlighted), this, &TagWidget::completionHighlighted);
}
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
@ -92,6 +89,13 @@ void TagWidget::highlight()
}
}
void TagWidget::inputMethodEvent(QInputMethodEvent *e)
{
GroupedLineEdit::inputMethodEvent(e);
if (!e->commitString().isEmpty())
reparse();
}
void TagWidget::reparse()
{
highlight();
@ -196,6 +200,7 @@ void TagWidget::keyPressEvent(QKeyEvent *e)
keyPressEvent(&fakeEvent);
} else {
GroupedLineEdit::keyPressEvent(e);
reparse();
}
lastFinishedTag = finishedTag;
}

View file

@ -18,20 +18,20 @@ public:
void clear();
void setCursorPosition(int position);
void wheelEvent(QWheelEvent *event);
public
private
slots:
void reparse();
void completionSelected(const QString &text);
void completionHighlighted(const QString &text);
protected:
private:
void keyPressEvent(QKeyEvent *e) override;
void dragEnterEvent(QDragEnterEvent *e) override;
void dragLeaveEvent(QDragLeaveEvent *e) override;
void dragMoveEvent(QDragMoveEvent *e) override;
void dropEvent(QDropEvent *e) override;
private:
void focusOutEvent(QFocusEvent *ev) override;
void inputMethodEvent(QInputMethodEvent *e) override;
void reparse();
QCompleter *m_completer;
bool lastFinishedTag;
};