[0] More...
#include <textedit.h>
Public Member Functions | |
TextEdit (QWidget *parent=0) | |
~TextEdit () | |
void | setCompleter (QCompleter *c) |
QCompleter * | completer () const |
Protected Member Functions | |
void | keyPressEvent (QKeyEvent *e) |
void | focusInEvent (QFocusEvent *e) |
[0]
Definition at line 14 of file textedit.h.
TextEdit::TextEdit | ( | QWidget * | parent = 0 ) |
Definition at line 12 of file textedit.cpp.
: QTextEdit(parent), c(0) { }
TextEdit::~TextEdit | ( | ) |
Definition at line 18 of file textedit.cpp.
{ }
QCompleter * TextEdit::completer | ( | ) | const |
void TextEdit::focusInEvent | ( | QFocusEvent * | e ) | [protected] |
Definition at line 63 of file textedit.cpp.
{ if (c) c->setWidget(this); QTextEdit::focusInEvent(e); }
void TextEdit::keyPressEvent | ( | QKeyEvent * | e ) | [protected] |
Definition at line 70 of file textedit.cpp.
{ if (c && c->popup()->isVisible()) { // The following keys are forwarded by the completer to the widget switch (e->key()) { case Qt::Key_Enter: case Qt::Key_Return: case Qt::Key_Escape: case Qt::Key_Tab: case Qt::Key_Backtab: e->ignore(); return; // let the completer do default behavior default: break; } } bool isShortcut = ((e->modifiers() & Qt::ControlModifier) && e->key() == Qt::Key_E); // CTRL+E if (!c || !isShortcut) // do not process the shortcut when we have a completer QTextEdit::keyPressEvent(e); //-------------------------------------------------------------------------------- const bool ctrlOrShift = e->modifiers() & (Qt::ControlModifier | Qt::ShiftModifier); if (!c || (ctrlOrShift && e->text().isEmpty())) return; static QString eow("~!@#$%^&*()_+{}|:\"<>?,./;'[]\\-="); // end of word bool hasModifier = (e->modifiers() != Qt::NoModifier) && !ctrlOrShift; QString completionPrefix = textUnderCursor(); if (!isShortcut && (hasModifier || e->text().isEmpty()|| completionPrefix.length() < 1 || eow.contains(e->text().right(1)))) { c->popup()->hide(); return; } if (completionPrefix != c->completionPrefix()) { c->setCompletionPrefix(completionPrefix); c->popup()->setCurrentIndex(c->completionModel()->index(0, 0)); } QRect cr = cursorRect(); cr.setWidth(c->popup()->sizeHintForColumn(0) + c->popup()->verticalScrollBar()->sizeHint().width()); c->complete(cr); // popup it up! }
void TextEdit::setCompleter | ( | QCompleter * | c ) |
Definition at line 22 of file textedit.cpp.
References completer().
{ if (c) QObject::disconnect(c, 0, this, 0); c = completer; if (!c) return; c->setWidget(this); c->setCompletionMode(QCompleter::PopupCompletion); c->setCaseSensitivity(Qt::CaseInsensitive); QObject::connect(c, SIGNAL(activated(QString)), this, SLOT(insertCompletion(QString))); }