subsurface/desktop-widgets/tagwidget.h
Berthold Stoeger 803727395b 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>
2022-08-13 11:19:37 -07:00

39 lines
1 KiB
C++

// SPDX-License-Identifier: GPL-2.0
#ifndef TAGWIDGET_H
#define TAGWIDGET_H
#include "groupedlineedit.h"
#include <QPair>
class QCompleter;
class TagWidget : public GroupedLineEdit {
Q_OBJECT
public:
explicit TagWidget(QWidget *parent = 0);
void setCompleter(QCompleter *completer);
QPair<int, int> getCursorTagPosition();
void highlight();
void setText(const QString &text);
void clear();
void setCursorPosition(int position);
void wheelEvent(QWheelEvent *event);
private
slots:
void completionSelected(const QString &text);
void completionHighlighted(const QString &text);
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;
void focusOutEvent(QFocusEvent *ev) override;
void inputMethodEvent(QInputMethodEvent *e) override;
void reparse();
QCompleter *m_completer;
bool lastFinishedTag;
};
#endif // TAGWIDGET_H