Commit 02470b35 authored by Hugues Delorme's avatar Hugues Delorme Committed by Tobias Hunger
Browse files

Utils: add property CompletingTextEdit::completionLengthThreshold



Change-Id: If68e981511e4c3df3766a2c5040bba8688f6928d
Reviewed-by: default avatarTobias Hunger <tobias.hunger@nokia.com>
parent e054dc54
......@@ -59,7 +59,10 @@ public:
void insertCompletion(const QString &completion);
QString textUnderCursor() const;
bool acceptsCompletionPrefix(const QString &prefix) const;
QCompleter *m_completer;
int m_completionLengthThreshold;
private:
CompletingTextEdit *m_backPointer;
......@@ -67,6 +70,7 @@ private:
CompletingTextEditPrivate::CompletingTextEditPrivate(CompletingTextEdit *textEdit)
: m_completer(0),
m_completionLengthThreshold(3),
m_backPointer(textEdit)
{
}
......@@ -90,6 +94,11 @@ QString CompletingTextEditPrivate::textUnderCursor() const
return tc.selectedText();
}
bool CompletingTextEditPrivate::acceptsCompletionPrefix(const QString &prefix) const
{
return prefix.length() >= m_completionLengthThreshold;
}
CompletingTextEdit::CompletingTextEdit(QWidget *parent)
: QTextEdit(parent),
d(new CompletingTextEditPrivate(this))
......@@ -121,6 +130,16 @@ QCompleter *CompletingTextEdit::completer() const
return d->m_completer;
}
int CompletingTextEdit::completionLengthThreshold() const
{
return d->m_completionLengthThreshold;
}
void CompletingTextEdit::setCompletionLengthThreshold(int len)
{
d->m_completionLengthThreshold = len;
}
void CompletingTextEdit::keyPressEvent(QKeyEvent *e)
{
if (completer() && completer()->popup()->isVisible()) {
......@@ -150,8 +169,8 @@ void CompletingTextEdit::keyPressEvent(QKeyEvent *e)
const QString newCompletionPrefix = d->textUnderCursor();
const QChar lastChar = e->text().isEmpty() ? QChar() : e->text().right(1).at(0);
if (!isShortcut && (hasModifier || e->text().isEmpty() || newCompletionPrefix.length() < 3
|| isEndOfWordChar(lastChar))) {
if (!isShortcut && (hasModifier || e->text().isEmpty() || isEndOfWordChar(lastChar)
|| !d->acceptsCompletionPrefix(newCompletionPrefix))) {
completer()->popup()->hide();
return;
}
......
......@@ -46,6 +46,8 @@ namespace Utils {
class QTCREATOR_UTILS_EXPORT CompletingTextEdit : public QTextEdit
{
Q_OBJECT
Q_PROPERTY(int completionLengthThreshold
READ completionLengthThreshold WRITE setCompletionLengthThreshold)
public:
CompletingTextEdit(QWidget *parent = 0);
......@@ -54,6 +56,9 @@ public:
void setCompleter(QCompleter *c);
QCompleter *completer() const;
int completionLengthThreshold() const;
void setCompletionLengthThreshold(int len);
protected:
void keyPressEvent(QKeyEvent *e);
void focusInEvent(QFocusEvent *e);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment